Skip to content

Commit c6563d0

Browse files
authored
Merge pull request #1416 from Northeastern-Electric-Racing/#1287-rework-vendor-and-account-code-form-submit-error
#1287: Vender and Account Code Forms Enabled Submit Buttons
2 parents e63dd88 + fc05ce8 commit c6563d0

4 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/frontend/src/components/NERFormModal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ const NERFormModal = ({
2828
*/
2929
const onSubmitWrapper = async (data: any) => {
3030
await onFormSubmit(data);
31-
reset({ confirmDone: false });
31+
reset();
3232
};
3333

3434
return (
3535
<NERModal
3636
open={open}
37-
onHide={onHide}
37+
onHide={() => {
38+
onHide();
39+
reset();
40+
}}
3841
formId={formId}
3942
title={title}
4043
cancelText={cancelText ? cancelText : 'Cancel'}
4144
submitText={submitText ? submitText : 'Submit'}
4245
disabled={disabled}
4346
showCloseButton={showCloseButton}
4447
>
45-
<form id={formId} onSubmit={handleUseFormSubmit(onSubmitWrapper)}>
48+
<form id={formId} onSubmit={handleUseFormSubmit(onSubmitWrapper)} noValidate>
4649
{children}
4750
</form>
4851
</NERModal>

src/frontend/src/pages/AdminToolsPage/FinanceConfig/AccountCodeFormModal.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { ExpenseType } from 'shared';
22
import { ExpenseTypePayload } from '../../../hooks/finance.hooks';
33
import { Controller, useForm } from 'react-hook-form';
44
import NERFormModal from '../../../components/NERFormModal';
5-
import { Checkbox, FormControl, FormLabel } from '@mui/material';
5+
import { Checkbox, FormControl, FormLabel, FormHelperText } from '@mui/material';
66
import ReactHookTextField from '../../../components/ReactHookTextField';
77
import { useToast } from '../../../hooks/toasts.hooks';
88
import * as yup from 'yup';
99
import { yupResolver } from '@hookform/resolvers/yup';
1010

1111
const 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
});
@@ -26,10 +26,9 @@ const AccountCodeFormModal = ({ showModal, handleClose, defaultValues, onSubmit
2626
const {
2727
handleSubmit,
2828
control,
29-
formState: { isValid },
30-
reset
29+
reset,
30+
formState: { errors }
3131
} = useForm({
32-
mode: 'onChange',
3332
resolver: yupResolver(schema),
3433
defaultValues: {
3534
code: defaultValues?.code,
@@ -54,20 +53,21 @@ const AccountCodeFormModal = ({ showModal, handleClose, defaultValues, onSubmit
5453
open={showModal}
5554
onHide={handleClose}
5655
title={!!defaultValues ? 'Edit Account Code' : 'Create Account Code'}
57-
reset={reset}
56+
reset={() => reset({ name: '', code: undefined, allowed: false })}
5857
handleUseFormSubmit={handleSubmit}
5958
onFormSubmit={onFormSubmit}
6059
formId={!!defaultValues ? 'edit-vendor-form' : 'create-vendor-form'}
61-
disabled={!isValid}
6260
showCloseButton
6361
>
6462
<FormControl fullWidth>
6563
<FormLabel>Account Name</FormLabel>
6664
<ReactHookTextField name="name" control={control} fullWidth />
65+
<FormHelperText error>{errors.name?.message}</FormHelperText>
6766
</FormControl>
6867
<FormControl fullWidth>
6968
<FormLabel>Account Code</FormLabel>
7069
<ReactHookTextField name="code" control={control} fullWidth />
70+
<FormHelperText error>{errors.code?.message}</FormHelperText>
7171
</FormControl>
7272
<FormControl>
7373
<FormLabel>Allowed?</FormLabel>

src/frontend/src/pages/AdminToolsPage/FinanceConfig/AccountCodesTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ const AccountCodesTable = () => {
4949
{clickedAccountCode && (
5050
<EditAccountCodeModal
5151
showModal={showEditModal}
52-
handleClose={() => setShowEditModal(false)}
52+
handleClose={() => {
53+
setShowEditModal(false);
54+
setClickedAccountCode(undefined);
55+
}}
5356
accountCode={clickedAccountCode}
5457
/>
5558
)}

src/frontend/src/pages/AdminToolsPage/FinanceConfig/CreateVendorModal.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useForm } from 'react-hook-form';
22
import NERFormModal from '../../../components/NERFormModal';
3-
import { FormControl, FormLabel } from '@mui/material';
3+
import { FormControl, FormLabel, FormHelperText } from '@mui/material';
44
import ReactHookTextField from '../../../components/ReactHookTextField';
55
import { useCreateVendor } from '../../../hooks/finance.hooks';
66
import { useToast } from '../../../hooks/toasts.hooks';
@@ -10,7 +10,7 @@ import * as yup from 'yup';
1010
import { yupResolver } from '@hookform/resolvers/yup';
1111

1212
const schema = yup.object().shape({
13-
name: yup.string().required('Account Name is Required')
13+
name: yup.string().required('Vendor Name is Required')
1414
});
1515

1616
interface NewVendorProps {
@@ -36,10 +36,9 @@ const CreateVendorModal = ({ showModal, handleClose }: NewVendorProps) => {
3636
const {
3737
handleSubmit,
3838
control,
39-
formState: { isValid },
40-
reset
39+
reset,
40+
formState: { errors }
4141
} = useForm({
42-
mode: 'onChange',
4342
resolver: yupResolver(schema),
4443
defaultValues: {
4544
name: ''
@@ -54,16 +53,16 @@ const CreateVendorModal = ({ showModal, handleClose }: NewVendorProps) => {
5453
open={showModal}
5554
onHide={handleClose}
5655
title="New Vendor"
57-
reset={reset}
56+
reset={() => reset({ name: '' })}
5857
handleUseFormSubmit={handleSubmit}
5958
onFormSubmit={onSubmit}
6059
formId="new-vendor-form"
61-
disabled={!isValid}
6260
showCloseButton
6361
>
6462
<FormControl>
6563
<FormLabel>Vendor Name</FormLabel>
6664
<ReactHookTextField name="name" control={control} sx={{ width: 1 }} />
65+
<FormHelperText error>{errors.name?.message}</FormHelperText>
6766
</FormControl>
6867
</NERFormModal>
6968
);

0 commit comments

Comments
 (0)