Replace toggle group with invoice configuration
This commit is contained in:
+33
-22
@@ -4,8 +4,7 @@ import { useEffect, useState } from 'react'
|
|||||||
import { HugeiconsIcon } from '@hugeicons/react'
|
import { HugeiconsIcon } from '@hugeicons/react'
|
||||||
import { ReceiptDollarIcon } from '@hugeicons/core-free-icons'
|
import { ReceiptDollarIcon } from '@hugeicons/core-free-icons'
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
|
||||||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
|
import { Switch } from '@/components/ui/switch'
|
||||||
import { FieldDescription } from '@/components/ui/field'
|
|
||||||
import { toast } from '@/components/ui/toast'
|
import { toast } from '@/components/ui/toast'
|
||||||
import {
|
import {
|
||||||
invoiceCreationMode as invoiceCreationModeApi,
|
invoiceCreationMode as invoiceCreationModeApi,
|
||||||
@@ -14,15 +13,11 @@ import {
|
|||||||
} from '@/lib/api/index'
|
} from '@/lib/api/index'
|
||||||
import type { InvoiceCreationMode } from '@/lib/api/sys-config'
|
import type { InvoiceCreationMode } from '@/lib/api/sys-config'
|
||||||
|
|
||||||
const MODE_LABELS: Record<InvoiceCreationMode, string> = {
|
// What each toggle stands for. Both end the same way: edit the draft, print, finalize.
|
||||||
ModeA: 'Auto on confirm',
|
const POSITIONS: { mode: InvoiceCreationMode; label: string; meaning: string; steps: string[] }[] = [
|
||||||
ModeB: 'Separate step',
|
{ mode: 'ModeA', label: 'Auto', meaning: 'Confirming a PO also creates its draft invoice.', steps: ['Confirm PO', 'Draft created'] },
|
||||||
}
|
{ mode: 'ModeB', label: 'Manual', meaning: 'Confirm first, then create the invoice yourself.', steps: ['Confirm PO', 'Create invoice'] },
|
||||||
|
]
|
||||||
const MODE_HINTS: Record<InvoiceCreationMode, string> = {
|
|
||||||
ModeA: 'Confirming a Shop PO immediately creates a draft invoice.',
|
|
||||||
ModeB: 'Confirmation and invoice creation are two distinct actions.',
|
|
||||||
}
|
|
||||||
|
|
||||||
export function InvoiceCreationModeCard() {
|
export function InvoiceCreationModeCard() {
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
@@ -66,18 +61,34 @@ export function InvoiceCreationModeCard() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-2.5">
|
<CardContent className="flex flex-col gap-3">
|
||||||
<ToggleGroup
|
{POSITIONS.map((p) => {
|
||||||
variant="outline"
|
const active = p.mode === mode
|
||||||
value={[mode]}
|
return (
|
||||||
onValueChange={(v: string[]) => v[0] && save(v[0] as InvoiceCreationMode)}
|
<div
|
||||||
disabled={pending}
|
key={p.mode}
|
||||||
className="w-full"
|
className={`flex items-center justify-between gap-3 rounded-xl border px-3 py-2.5 ${
|
||||||
|
active ? 'border-primary/40 bg-muted' : 'border-border/60'
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<ToggleGroupItem value="ModeA" className="flex-1">{MODE_LABELS.ModeA}</ToggleGroupItem>
|
<label htmlFor={`invoice-creation-${p.mode}`} className="flex flex-col gap-0.5">
|
||||||
<ToggleGroupItem value="ModeB" className="flex-1">{MODE_LABELS.ModeB}</ToggleGroupItem>
|
<span className="text-sm font-medium">{p.label}</span>
|
||||||
</ToggleGroup>
|
<span className="text-xs leading-relaxed text-muted-foreground">{p.meaning}</span>
|
||||||
<FieldDescription className="text-xs leading-relaxed">{MODE_HINTS[mode]}</FieldDescription>
|
</label>
|
||||||
|
{/* One mode is always on: turning one on turns the other off; the active one cannot be switched off. */}
|
||||||
|
<Switch
|
||||||
|
id={`invoice-creation-${p.mode}`}
|
||||||
|
checked={active}
|
||||||
|
disabled={pending || active}
|
||||||
|
onCheckedChange={(v) => v && save(p.mode)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{[...(POSITIONS.find((p) => p.mode === mode)?.steps ?? []), 'Edit draft', 'Print', 'Finalize'].join(' → ')}
|
||||||
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user