import * as Yup from 'yup'; import { useMemo } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; // @mui import LoadingButton from '@mui/lab/LoadingButton'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Dialog from '@mui/material/Dialog'; import MenuItem from '@mui/material/MenuItem'; import DialogTitle from '@mui/material/DialogTitle'; import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; // types import { Employee, employeeSchema } from 'src/schemas'; // components import { useSnackbar } from 'src/components/snackbar'; import FormProvider, { RHFSelect, RHFTextField } from 'src/components/hook-form'; // ---------------------------------------------------------------------- type Props = { open: boolean; onClose: VoidFunction; currentEmployee?: Employee; }; export const EMPLOYEE_STATUS_OPTIONS = [ { value: 'active', label: 'Active' }, { value: 'inactive', label: 'Inactive' }, ]; export default function EmployeeQuickEditForm({ currentEmployee, open, onClose }: Props) { const { enqueueSnackbar } = useSnackbar(); const defaultValues = useMemo( () => ({ name: currentEmployee?.name || '', email: currentEmployee?.email || '', status: currentEmployee?.status || 'active', project: currentEmployee?.project || '', iban: currentEmployee?.iban || '', }), [currentEmployee] ); const methods = useForm({ resolver: zodResolver(employeeSchema), defaultValues, }); const { reset, handleSubmit, formState: { isSubmitting }, } = methods; const onSubmit = handleSubmit(async (data) => { try { await new Promise((resolve) => setTimeout(resolve, 500)); reset(); onClose(); enqueueSnackbar('Update success!'); } catch (error) { console.error(error); } }); return ( Quick Update {EMPLOYEE_STATUS_OPTIONS.map((status) => ( {status.label} ))} Update ); }