Skip to content

Commit c994f8a

Browse files
committed
#1583 made hook
1 parent d4b7943 commit c994f8a

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/backend/src/services/reimbursement-requests.services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export default class ReimbursementRequestService {
334334
* @param amount The new amount of the reimbursement
335335
* @param dateCreated The new date the reimbursement was created
336336
* @param organizationId The organization the user is currently in
337-
* @returns The updatd reimbursement
337+
* @returns The updated reimbursement
338338
*/
339339
static async editReimbursement(
340340
reimbursementId: string,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ export const reportRefund = (amount: number, dateReceived: string) => {
302302
return axios.post(apiUrls.financeReportRefund(), { amount, dateReceived });
303303
};
304304

305+
/**
306+
* Edits a refund in the database
307+
*
308+
* @param id the reimbursement id
309+
* @param amount the new amount reimbursed being reported
310+
* @param dateReceived the new date the refund was received
311+
* @returns the updated reimbursement
312+
*/
313+
export const editRefund = (id: string, amount: number, dateReceived: string) => {
314+
return axios.post(apiUrls.financeEditRefund(id), { amount, dateReceived });
315+
};
316+
305317
/**
306318
* Edits an expense type in the database
307319
* @param id id of the expense type

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
createAccountCode,
2929
createVendor,
3030
editVendor,
31-
getAllAccountCodes
31+
getAllAccountCodes,
32+
editRefund
3233
} from '../apis/finance.api';
3334
import {
3435
ClubAccount,
@@ -425,6 +426,24 @@ export const useReportRefund = () => {
425426
);
426427
};
427428

429+
export const useEditRefund = (reimbursementId: string) => {
430+
const queryClient = useQueryClient();
431+
432+
return useMutation<Reimbursement, Error, { refundAmount: number; dateReceived: string }>(
433+
['reimbursement', 'edit', reimbursementId],
434+
async (formData: { refundAmount: number; dateReceived: string }) => {
435+
const { data } = await editRefund(reimbursementId, formData.refundAmount, formData.dateReceived);
436+
queryClient.invalidateQueries(['reimbursement', reimbursementId]);
437+
return data;
438+
},
439+
{
440+
onSuccess: () => {
441+
queryClient.invalidateQueries(['reimbursement']);
442+
}
443+
}
444+
);
445+
};
446+
428447
/**
429448
* Custom react hook to update a reimbursement request's SABO number
430449
*

src/frontend/src/utils/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const financeGetUserReimbursementRequest = () => `${financeEndpoints()}/current-
109109
const financeGetUserReimbursements = () => `${financeEndpoints()}/reimbursements/current-user`;
110110
const financeGetAllReimbursements = () => `${financeEndpoints()}/reimbursements`;
111111
const financeReportRefund = () => `${financeEndpoints()}/reimburse`;
112+
const financeEditRefund = (id: string) => `${financeReportRefund()}/${id}/edit`;
112113
const financeSetSaboNumber = (id: string) => `${financeEndpoints()}/${id}/set-sabo-number`;
113114
const financeDeleteReimbursement = (id: string) => `${financeEndpoints()}/${id}/delete`;
114115
const financeMarkAsDelivered = (id: string) => `${financeEndpoints()}/${id}/delivered`;
@@ -250,6 +251,7 @@ export const apiUrls = {
250251
financeGetUserReimbursements,
251252
financeGetAllReimbursements,
252253
financeReportRefund,
254+
financeEditRefund,
253255
financeSetSaboNumber,
254256
financeImageById,
255257
financeDeleteReimbursement,

0 commit comments

Comments
 (0)