Files
juwan-frontend/app/(dashboard)/dashboard/shop/rules/page.tsx
T
zetaloop 4d8877f588 fix(pages): adapt all pages to backend-aligned types
Replace removed fields with available data sources throughout UI:
- order pages: use service.title instead of consumer/player names
- chat: look up sender from session.participants, remove readonly
- community: simplify post cards, keep pinned icon
- post detail: keep pinned/linkedOrderId display
- shop rules: use string commissionValue
- dashboard: parse string amounts for income display
- dispute/review: remove initiator/avatar references
2026-04-23 21:15:28 +08:00

170 lines
6.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Switch } from "@/components/ui/switch"
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
import type { Shop } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
import { useShopStore } from "@/store/shops"
import { Save } from "lucide-react"
import { useState } from "react"
export default function ShopRulesPage() {
const userId = useAuthStore((state) => state.user?.id)
const shops = useShopStore((state) => state.shops)
const shop = resolveOwnerShop(userId, shops)
const updateShop = useShopStore((state) => state.updateShop)
if (!shop) {
return <div className="text-sm text-muted-foreground"></div>
}
return <ShopRulesForm key={shop.id} shop={shop} updateShop={updateShop} />
}
function ShopRulesForm({
shop,
updateShop,
}: {
shop: Shop
updateShop: (shopId: string, patch: Partial<Omit<Shop, "id" | "owner">>) => void
}) {
const [commissionType, setCommissionType] = useState<Shop["commissionType"]>(shop.commissionType)
const [commissionValue, setCommissionValue] = useState(shop.commissionValue)
const [allowMultiShop, setAllowMultiShop] = useState(shop.allowMultiShop)
const [allowIndependentOrders, setAllowIndependentOrders] = useState(shop.allowIndependentOrders)
const [dispatchMode, setDispatchMode] = useState<Shop["dispatchMode"]>(shop.dispatchMode)
const handleSave = () => {
updateShop(shop.id, {
commissionType,
commissionValue,
allowMultiShop,
allowIndependentOrders,
dispatchMode,
})
}
return (
<div className="container mx-auto max-w-4xl px-4 py-8 space-y-8">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold"></h1>
<Button onClick={handleSave}>
<Save className="mr-2 h-4 w-4" />
</Button>
</div>
<div className="grid gap-6">
<Card className="hover:shadow-card-hover">
<CardHeader>
<CardTitle className="text-base"></CardTitle>
</CardHeader>
<CardContent className="space-y-6">
<div className="flex items-center justify-between space-x-2">
<Label htmlFor="allow-multi-shop" className="flex flex-col space-y-1">
<span></span>
<span className="font-normal text-sm text-muted-foreground">
</span>
</Label>
<Switch
id="allow-multi-shop"
checked={allowMultiShop}
onCheckedChange={setAllowMultiShop}
/>
</div>
<div className="flex items-center justify-between space-x-2">
<Label htmlFor="allow-independent" className="flex flex-col space-y-1">
<span></span>
<span className="font-normal text-sm text-muted-foreground">
</span>
</Label>
<Switch
id="allow-independent"
checked={allowIndependentOrders}
onCheckedChange={setAllowIndependentOrders}
/>
</div>
</CardContent>
</Card>
<Card className="hover:shadow-card-hover">
<CardHeader>
<CardTitle className="text-base"></CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label></Label>
<Select
value={dispatchMode}
onValueChange={(v) => setDispatchMode(v as Shop["dispatchMode"])}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="manual"></SelectItem>
<SelectItem value="auto"></SelectItem>
</SelectContent>
</Select>
<p className="text-sm text-muted-foreground">
</p>
</div>
</CardContent>
</Card>
<Card className="hover:shadow-card-hover">
<CardHeader>
<CardTitle className="text-base"></CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-2">
<Label></Label>
<Select
value={commissionType}
onValueChange={(v) => setCommissionType(v as Shop["commissionType"])}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="fixed"></SelectItem>
<SelectItem value="percentage"></SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label></Label>
<div className="relative">
<Input
type="number"
value={commissionValue}
onChange={(e) => setCommissionValue(e.target.value)}
/>
<div className="absolute right-3 top-2.5 text-sm text-muted-foreground">
{commissionType === "percentage" ? "%" : "元"}
</div>
</div>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
)
}