Skip to content

Commit f055542

Browse files
committed
#1583 everything except the form
1 parent c994f8a commit f055542

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,13 @@ export const useReportRefund = () => {
426426
);
427427
};
428428

429-
export const useEditRefund = (reimbursementId: string) => {
429+
export const useEditRefund = () => {
430430
const queryClient = useQueryClient();
431431

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]);
432+
return useMutation<Reimbursement, Error, { refundId: string; refundAmount: number; dateReceived: string }>(
433+
['reimbursement', 'edit'],
434+
async (formData: { refundId: string; refundAmount: number; dateReceived: string }) => {
435+
const { data } = await editRefund(formData.refundId, formData.refundAmount, formData.dateReceived);
437436
return data;
438437
},
439438
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface ReportRefundInputs {
3333
newAccountCreditAmount: number;
3434
}
3535

36-
const ReportRefundModal: React.FC<ReportRefundProps> = ({ modalShow, handleClose }: ReportRefundProps) => {
36+
const RefundModal: React.FC<ReportRefundProps> = ({ modalShow, handleClose }: ReportRefundProps) => {
3737
const toast = useToast();
3838
const { isLoading, mutateAsync } = useReportRefund();
3939

@@ -110,4 +110,4 @@ const ReportRefundModal: React.FC<ReportRefundProps> = ({ modalShow, handleClose
110110
);
111111
};
112112

113-
export default ReportRefundModal;
113+
export default RefundModal;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import LoadingIndicator from '../../components/LoadingIndicator';
2424
import PageLayout from '../../components/PageLayout';
2525
import { useHistory } from 'react-router-dom';
2626
import { routes } from '../../utils/routes';
27-
import ReportRefundModal from './FinanceComponents/ReportRefundModal';
27+
import RefundModal from './FinanceComponents/ReportRefundModal';
2828
import GenerateReceiptsModal from './FinanceComponents/GenerateReceiptsModal';
2929
import PendingAdvisorModal from './FinanceComponents/PendingAdvisorListModal';
3030
import { isAdmin, isGuest } from 'shared';
@@ -176,7 +176,7 @@ const FinancePage = () => {
176176
onHide={() => setShowTotalAmountSpent(false)}
177177
/>
178178
)}
179-
<ReportRefundModal modalShow={accountCreditModalShow} handleClose={() => setAccountCreditModalShow(false)} />
179+
<RefundModal modalShow={accountCreditModalShow} handleClose={() => setAccountCreditModalShow(false)} />
180180
<GenerateReceiptsModal
181181
open={showGenerateReceipts}
182182
setOpen={setShowGenerateReceipts}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
useTheme
1414
} from '@mui/material';
1515
import { useState } from 'react';
16-
import { useAllReimbursements, useCurrentUserReimbursements } from '../../hooks/finance.hooks';
16+
import { useAllReimbursements, useCurrentUserReimbursements, useEditRefund } from '../../hooks/finance.hooks';
1717
import ErrorPage from '../ErrorPage';
1818
import LoadingIndicator from '../../components/LoadingIndicator';
1919
import { Reimbursement, ReimbursementRequest, isAdmin } from 'shared';
@@ -24,7 +24,7 @@ import FinanceTabs from './FinanceComponents/FinanceTabs';
2424
import { getRefundRowData } from '../../utils/reimbursement-request.utils';
2525

2626
type Order = 'asc' | 'desc'; // ascending or descending
27-
type OrderBy = keyof { date: Date; amount: number };
27+
type OrderBy = 'amount' | 'date';
2828

2929
const RefundHeader = ({ header, data }: { header: string; data: string }) => {
3030
return (
@@ -107,6 +107,14 @@ const Refunds = ({ userReimbursementRequests, allReimbursementRequests }: Refund
107107
} = useAllReimbursements();
108108
const theme = useTheme();
109109

110+
const { mutateAsync } = useEditRefund();
111+
112+
const onClick = (refundId: string) => {
113+
mutateAsync({ refundId, refundAmount: 0, dateReceived: new Date().toISOString() });
114+
};
115+
116+
const editModalRefundId = useState<string | null>();
117+
110118
const canViewAllReimbursementRequests = user.isFinance || isAdmin(user.role);
111119
if (canViewAllReimbursementRequests && allReimbursementsIsError)
112120
return <ErrorPage message={allReimbursementsError?.message} />;
@@ -202,7 +210,7 @@ const Refunds = ({ userReimbursementRequests, allReimbursementRequests }: Refund
202210
key={`${row.date}-$${row.amount}-${index}`}
203211
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
204212
>
205-
<TableCell align="center">{datePipe(row.date)}</TableCell>
213+
<TableCell onClick={() => onClick(row.id)}>{datePipe(row.date)}</TableCell>
206214
<TableCell align="center">{centsToDollar(row.amount)}</TableCell>
207215
{tabValue === 1 && <TableCell align="center">{fullNamePipe(row.recipient)}</TableCell>}
208216
</TableRow>

src/frontend/src/utils/reimbursement-request.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const imageFileUrl = (googleFileId: string) => `https://drive.google.com/
166166
export const imageDownloadUrl = (googleFileId: string) => `https://drive.google.com/uc?export=download&id=${googleFileId}`;
167167

168168
export const getRefundRowData = (refund: Reimbursement) => {
169-
return { date: refund.dateCreated, amount: refund.amount, recipient: refund.userSubmitted };
169+
return { date: refund.dateCreated, amount: refund.amount, recipient: refund.userSubmitted, id: refund.reimbursementId };
170170
};
171171

172172
export const createReimbursementRequestRowData = (reimbursementRequest: ReimbursementRequest): ReimbursementRequestRow => {

0 commit comments

Comments
 (0)