Skip to content

Commit 7f0748b

Browse files
committed
#1583 added pointer and removed any type
1 parent f8f4a8a commit 7f0748b

5 files changed

Lines changed: 29 additions & 27 deletions

File tree

src/frontend/src/apis/finance.api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
CreateReimbursementRequestPayload,
77
EditReimbursementRequestPayload,
88
EditVendorPayload,
9-
AccountCodePayload
9+
AccountCodePayload,
10+
RefundPayload
1011
} from '../hooks/finance.hooks';
1112
import axios from '../utils/axios';
1213
import { apiUrls } from '../utils/urls';
@@ -306,12 +307,11 @@ export const reportRefund = (amount: number, dateReceived: string) => {
306307
* Edits a refund in the database
307308
*
308309
* @param id the reimbursement id
309-
* @param amount the new amount reimbursed being reported
310-
* @param dateReceived the new date the refund was received
310+
* @param formData the amount and date to edit the refund with
311311
* @returns the updated reimbursement
312312
*/
313-
export const editRefund = (id: string, amount: number, dateReceived: string) => {
314-
return axios.post(apiUrls.financeEditRefund(id), { amount, dateReceived });
313+
export const editRefund = (id: string, formData: RefundPayload) => {
314+
return axios.post(apiUrls.financeEditRefund(id), formData);
315315
};
316316

317317
/**

src/frontend/src/hooks/finance.hooks.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export interface EditVendorPayload {
7777
name: string;
7878
}
7979

80+
export interface RefundPayload {
81+
amount: number;
82+
dateReceived: string;
83+
}
84+
8085
/**
8186
* Custom React Hook to upload a new picture.
8287
*/
@@ -416,10 +421,10 @@ export const useSendPendingAdvisorList = () => {
416421
*/
417422
export const useReportRefund = () => {
418423
const queryClient = useQueryClient();
419-
return useMutation<Reimbursement, Error, { refundAmount: number; dateReceived: string }>(
424+
return useMutation<Reimbursement, Error, { amount: number; dateReceived: string }>(
420425
['reimbursement'],
421-
async (formData: { refundAmount: number; dateReceived: string }) => {
422-
const { data } = await reportRefund(formData.refundAmount, formData.dateReceived);
426+
async (formData: { amount: number; dateReceived: string }) => {
427+
const { data } = await reportRefund(formData.amount, formData.dateReceived);
423428
queryClient.invalidateQueries(['reimbursement']);
424429
return data;
425430
}
@@ -430,13 +435,13 @@ export const useReportRefund = () => {
430435
* Custom react hook to edit a refund
431436
* @returns the edited refund
432437
*/
433-
export const useEditRefund = () => {
438+
export const useEditRefund = (id: string) => {
434439
const queryClient = useQueryClient();
435440

436-
return useMutation<Reimbursement, Error, { refundId: string; refundAmount: number; dateReceived: string }>(
441+
return useMutation<Reimbursement, Error, { amount: number; dateReceived: string }>(
437442
['reimbursement', 'edit'],
438-
async (formData: { refundId: string; refundAmount: number; dateReceived: string }) => {
439-
const { data } = await editRefund(formData.refundId, formData.refundAmount, formData.dateReceived);
443+
async (formData: { amount: number; dateReceived: string }) => {
444+
const { data } = await editRefund(id, formData);
440445
return data;
441446
},
442447
{

src/frontend/src/pages/FinancePage/FinanceComponents/EditRefundModal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ interface EditRefundModalProps {
88
}
99

1010
const EditRefundModal: React.FC<EditRefundModalProps> = ({ refund, handleClose }: EditRefundModalProps) => {
11-
const { mutateAsync, isLoading } = useEditRefund();
11+
const { mutateAsync, isLoading } = useEditRefund(refund!.reimbursementId);
1212

1313
const defaultValues: RefundModalInputs | undefined = refund && {
14-
refundId: refund.reimbursementId,
15-
refundAmount: (refund.amount / 100).toFixed(2),
14+
amount: (refund.amount / 100).toFixed(2),
1615
dateReceived: new Date(refund.dateCreated)
1716
};
1817

src/frontend/src/pages/FinancePage/FinanceComponents/RefundModal.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ReactHookTextField from '../../../components/ReactHookTextField';
1010
import { useToast } from '../../../hooks/toasts.hooks';
1111

1212
const 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

3939
export 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>

src/frontend/src/pages/FinancePage/RefundsSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const Refunds = ({ userReimbursementRequests, allReimbursementRequests }: Refund
205205
{rows.map((row, index) => (
206206
<TableRow
207207
key={`${row.date}-$${row.amount}-${index}`}
208-
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
208+
sx={{ '&:last-child td, &:last-child th': { border: 0 }, cursor: 'pointer' }}
209209
onClick={() => {
210210
setEditModalRefund({
211211
reimbursementId: row.id,

0 commit comments

Comments
 (0)