import { useStore } from '@tanstack/react-form'; import { useAppForm, Form } from '@/components/form'; import { createAdminLocationInput, useCreateAdminLocation } from '@/api/admin/locations/queries'; import { Dialog } from '@/components/elements/dialog'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import Button from '@/components/elements/Button'; import { NewButton } from '@/components/elements/NewButton'; type CreateLocationDialogProps = { open: boolean; onClose: () => void; }; function CreateLocationDialog({ open, onClose }: CreateLocationDialogProps) { const createLocation = useCreateAdminLocation(); const form = useAppForm({ defaultValues: { short: '', long: '' }, onSubmit: async ({ value }) => { try { await createLocation.mutateAsync(createAdminLocationInput(value)); onClose(); } catch { // Error toast is handled by the mutation. } }, }); const isSubmitting = useStore(form.store, (state) => state.isSubmitting); return (
value.length < 1 ? 'A short code must be provided.' : value.length <= 60 ? undefined : 'A short code must not exceed 60 characters.', }} > {(field) => ( )}
value.length <= 191 ? undefined : 'The description must not exceed 191 characters.', }} > {(field) => ( )}
Create Location
); } export default function CreateLocationButton() { return ( New location}> {({ open, onClose }) => } ); }