@@ -2,14 +2,14 @@ import { ExpenseType } from 'shared';
22import { ExpenseTypePayload } from '../../../hooks/finance.hooks' ;
33import { Controller , useForm } from 'react-hook-form' ;
44import NERFormModal from '../../../components/NERFormModal' ;
5- import { Checkbox , FormControl , FormLabel } from '@mui/material' ;
5+ import { Checkbox , FormControl , FormLabel , FormHelperText } from '@mui/material' ;
66import ReactHookTextField from '../../../components/ReactHookTextField' ;
77import { useToast } from '../../../hooks/toasts.hooks' ;
88import * as yup from 'yup' ;
99import { yupResolver } from '@hookform/resolvers/yup' ;
1010
1111const schema = yup . object ( ) . shape ( {
12- code : yup . number ( ) . required ( 'Account Code is Required' ) ,
12+ code : yup . number ( ) . typeError ( 'Account Code must be a number' ) . required ( 'Account Code is Required' ) ,
1313 name : yup . string ( ) . required ( 'Account Name is Required' ) ,
1414 allowed : yup . boolean ( ) . required ( 'Allowed is Required' )
1515} ) ;
@@ -23,8 +23,12 @@ interface AccountCodeFormModalProps {
2323
2424const AccountCodeFormModal = ( { showModal, handleClose, defaultValues, onSubmit } : AccountCodeFormModalProps ) => {
2525 const toast = useToast ( ) ;
26- const { handleSubmit, control, reset } = useForm ( {
27- mode : 'onChange' ,
26+ const {
27+ handleSubmit,
28+ control,
29+ reset,
30+ formState : { errors }
31+ } = useForm ( {
2832 resolver : yupResolver ( schema ) ,
2933 defaultValues : {
3034 code : defaultValues ?. code ,
@@ -58,10 +62,12 @@ const AccountCodeFormModal = ({ showModal, handleClose, defaultValues, onSubmit
5862 < FormControl fullWidth >
5963 < FormLabel > Account Name</ FormLabel >
6064 < ReactHookTextField name = "name" control = { control } fullWidth />
65+ < FormHelperText error > { errors . name ?. message } </ FormHelperText >
6166 </ FormControl >
6267 < FormControl fullWidth >
6368 < FormLabel > Account Code</ FormLabel >
6469 < ReactHookTextField name = "code" control = { control } fullWidth />
70+ < FormHelperText error > { errors . code ?. message } </ FormHelperText >
6571 </ FormControl >
6672 < FormControl >
6773 < FormLabel > Allowed?</ FormLabel >
0 commit comments