import { Button, Group, Modal, NumberInput, Select, TextInput, type ModalBaseProps, } from "@mantine/core"; import { t } from "@/config/i18n"; import { DatePickerInput } from "@mantine/dates"; import { IconCancel, IconEdit, IconPlus } from "@tabler/icons-react"; import { useGetProductors, useGetUsers } from "@/services/api"; import { useForm } from "@mantine/form"; import { useMemo } from "react"; import type { Form, FormInputs } from "@/services/resources/forms"; export type FormModalProps = ModalBaseProps & { currentForm?: Form; handleSubmit: (form: FormInputs, id?: number) => void; }; export default function FormModal({ opened, onClose, currentForm, handleSubmit }: FormModalProps) { const { data: productors } = useGetProductors(); const { data: users } = useGetUsers(); const form = useForm({ initialValues: { name: currentForm?.name ?? "", season: currentForm?.season ?? "", start: currentForm?.start ?? null, end: currentForm?.end ?? null, productor_id: currentForm?.productor?.id.toString() ?? "", referer_id: currentForm?.referer?.id.toString() ?? "", minimum_shipment_value: currentForm?.minimum_shipment_value ?? null, }, validate: { name: (value) => !value ? `${t("a name", { capfirst: true })} ${t("is required")}` : null, season: (value) => !value ? `${t("a season", { capfirst: true })} ${t("is required")}` : null, start: (value) => !value ? `${t("a start date", { capfirst: true })} ${t("is required")}` : null, end: (value) => !value ? `${t("a end date", { capfirst: true })} ${t("is required")}` : null, productor_id: (value) => !value ? `${t("a productor", { capfirst: true })} ${t("is required")}` : null, referer_id: (value) => !value ? `${t("a referer", { capfirst: true })} ${t("is required")}` : null, }, }); const usersSelect = useMemo(() => { return users?.map((user) => ({ value: String(user.id), label: `${user.name}`, })); }, [users]); const productorsSelect = useMemo(() => { return productors?.map((prod) => ({ value: String(prod.id), label: `${prod.name}`, })); }, [productors]); return ( ); }