@@ -10,7 +10,7 @@ import ReactHookTextField from '../../../components/ReactHookTextField';
1010import { useToast } from '../../../hooks/toasts.hooks' ;
1111
1212const schema = yup . object ( ) . shape ( {
13- refundAmount : yup
13+ amount : yup
1414 . number ( )
1515 . required ( 'Refund amount is required' )
1616 . positive ( 'Refund amount must be positive' )
@@ -37,8 +37,7 @@ interface RefundModalProps {
3737}
3838
3939export interface RefundModalInputs {
40- refundId ?: string ;
41- refundAmount : string ; // this allows us to display default value with 2 decimal places - the type is enforced and casted via the input field and form schema
40+ amount : string ; // this allows us to display default value with 2 decimal places - the type is enforced and casted via the input field and form schema
4241 dateReceived : Date ;
4342}
4443
@@ -61,21 +60,20 @@ const RefundModal: React.FC<RefundModalProps> = ({
6160 } = useForm ( {
6261 resolver : yupResolver ( schema ) ,
6362 defaultValues : defaultValues ?? {
64- refundAmount : '0' ,
63+ amount : '0' ,
6564 dateReceived : new Date ( )
6665 } ,
6766 mode : 'onChange'
6867 } ) ;
6968
70- const handleConfirm = async ( data : { refundAmount : number ; dateReceived : Date } ) => {
71- handleClose ( ) ;
69+ const handleConfirm = async ( data : { amount : number ; dateReceived : Date } ) => {
7270 try {
7371 await mutateAsync ( {
74- refundId : defaultValues ?. refundId ,
75- refundAmount : Math . round ( data . refundAmount * 100 ) ,
72+ amount : Math . round ( data . amount * 100 ) ,
7673 dateReceived : data . dateReceived . toISOString ( )
7774 } ) ;
7875 toast . success ( defaultValues ? 'Account credit updated successfully' : 'New account credit reported successfully' ) ;
76+ handleClose ( ) ;
7977 } catch ( error : unknown ) {
8078 if ( error instanceof Error ) {
8179 toast . error ( error . message ) ;
@@ -92,20 +90,20 @@ const RefundModal: React.FC<RefundModalProps> = ({
9290 handleUseFormSubmit = { handleSubmit }
9391 onFormSubmit = { handleConfirm }
9492 formId = "reimbursement-form"
95- disabled = { ! isValid || ( defaultValues && defaultValues . refundAmount === watch ( 'refundAmount ' ) ) }
93+ disabled = { ! isValid || ( defaultValues && defaultValues . amount === watch ( 'amount ' ) ) }
9694 >
9795 { isLoading ? (
9896 < LoadingIndicator />
9997 ) : (
10098 < FormControl >
10199 < FormLabel > Amount</ FormLabel >
102100 < ReactHookTextField
103- name = "refundAmount "
101+ name = "amount "
104102 type = "number"
105103 control = { control }
106104 sx = { { width : 1 } }
107105 startAdornment = { < AttachMoneyIcon /> }
108- errorMessage = { errors . refundAmount }
106+ errorMessage = { errors . amount }
109107 />
110108
111109 < FormLabel sx = { { paddingTop : 2 } } > Date Received</ FormLabel >
0 commit comments