import { useForm } from '@inertiajs/react'; import { useEffect } from 'react'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Spinner } from '@/components/ui/spinner'; import { MARKER_COLORS } from '@/lib/marker-colors'; import { cn } from '@/lib/utils'; import { store, update } from '@/routes/markers'; import type { Marker } from '@/types/planner'; type Props = { open: boolean; onOpenChange: (open: boolean) => void; marker: Marker | null; }; export function MarkerDialog({ open, onOpenChange, marker }: Props) { const form = useForm({ name: marker?.name ?? '', color: marker?.color ?? MARKER_COLORS[0], }); useEffect(() => { if (open) { form.setData({ name: marker?.name ?? '', color: marker?.color ?? MARKER_COLORS[0], }); form.clearErrors(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [open, marker]); const submit = (e: React.FormEvent) => { e.preventDefault(); const options = { preserveScroll: true, only: ['markers'], onSuccess: () => onOpenChange(false), }; if (marker) { form.patch(update.url(marker.id), options); } else { form.post(store().url, options); } }; return ( {marker ? 'Изменить маркер' : 'Новый маркер'} Маркер — это цвет и имя человека, которым вы отмечаете отпуска.
form.setData('name', e.target.value) } placeholder="Например: Анна" maxLength={50} required autoFocus data-test="marker-name-input" />
{MARKER_COLORS.map((color) => (
); }