119 lines
5.0 KiB
TypeScript
119 lines
5.0 KiB
TypeScript
import { store } from '@/actions/App/Http/Controllers/Settings/LabelController';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@/components/ui/dialog';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@/components/ui/select';
|
|
import { getLabelColorClasses, LABEL_COLORS } from '@/types/label';
|
|
import { Form } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
|
|
export function CreateLabelDialog({ onSuccess }: { onSuccess?: () => void }) {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button>Create Label</Button>
|
|
</DialogTrigger>
|
|
<DialogContent hasKeyboard className="sm:max-w-[425px]">
|
|
<DialogHeader>
|
|
<DialogTitle>Create Label</DialogTitle>
|
|
<DialogDescription>
|
|
Add a new label to tag your transactions.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<Form
|
|
{...store.form()}
|
|
onSuccess={() => {
|
|
setOpen(false);
|
|
onSuccess?.();
|
|
}}
|
|
className="space-y-4"
|
|
>
|
|
{({ errors, processing }) => (
|
|
<>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="name">Name</Label>
|
|
<Input
|
|
id="name"
|
|
name="name"
|
|
placeholder="Label name"
|
|
required
|
|
/>
|
|
{errors.name && (
|
|
<p className="text-sm text-red-500">
|
|
{errors.name}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="color">Color</Label>
|
|
<Select name="color" required>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="Select a color" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{LABEL_COLORS.map((color) => {
|
|
const colorClasses =
|
|
getLabelColorClasses(color);
|
|
return (
|
|
<SelectItem
|
|
key={color}
|
|
value={color}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<Badge
|
|
className={`${colorClasses.bg} ${colorClasses.text}`}
|
|
>
|
|
{color}
|
|
</Badge>
|
|
</div>
|
|
</SelectItem>
|
|
);
|
|
})}
|
|
</SelectContent>
|
|
</Select>
|
|
{errors.color && (
|
|
<p className="text-sm text-red-500">
|
|
{errors.color}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex justify-end gap-2">
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() => setOpen(false)}
|
|
disabled={processing}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" disabled={processing}>
|
|
{processing ? 'Creating...' : 'Create'}
|
|
</Button>
|
|
</div>
|
|
</>
|
|
)}
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|