diff --git a/src/components/RecurringExpense/ViewRecurringExpense.jsx b/src/components/RecurringExpense/ViewRecurringExpense.jsx index e1187867..305c843c 100644 --- a/src/components/RecurringExpense/ViewRecurringExpense.jsx +++ b/src/components/RecurringExpense/ViewRecurringExpense.jsx @@ -1,14 +1,307 @@ import React from 'react' +import { useRecurringExpenseDetail } from '../../hooks/useExpense'; +import { formatUTCToLocalTime } from '../../utils/dateUtils'; +import { formatFigure, getColorNameFromHex } from '../../utils/appUtils'; +import Avatar from '../common/Avatar'; +import { FREQUENCY_FOR_RECURRING } from '../../utils/constants'; +import { ExpenseDetailsSkeleton } from '../Expenses/ExpenseSkeleton'; + +const ViewRecurringExpense = ({ RecurringId }) => { + const { data, isLoading, isError, error, isFetching } = useRecurringExpenseDetail(RecurringId); + + const statusColorMap = { + "da462422-13b2-45cc-a175-910a225f6fc8": "primary", // Active + "306856fb-5655-42eb-bf8b-808bb5e84725": "success", // Completed + "3ec864d2-8bf5-42fb-ba70-5090301dd816": "danger", // De-Activated + "8bfc9346-e092-4a80-acbf-515ae1ef6868": "warning", // Paused + }; + if (isLoading) return ; -const ViewRecurringExpense = () => { return ( -
-
Detail Recurring
-
-

Under the Working!

+ +
+
+
Recurring Payment Details
-
+
+ {/*
*/} +
+ + {/* Row 1 Recurring Id and Status */} + +
+ {data?.recurringPaymentUID} + + {data?.status?.name || "N/A"} + +
+ + {/* Row 2 Category*/} + +
+
+ +
{data?.expenseCategory?.name || "N/A"}
+
+
+ + + + {/* Row 3 Amount and Project */} + +
+
+ +
+ {data?.amount != null + ? `${data?.currency?.symbol ?? "¥"} ${Number(data.amount).toFixed(2)} ${data?.currency?.currencyCode ?? "CN"}` + : "N/A"} +
+
+
+ +
+
+ +
{data?.project?.name || "N/A"}
+
+
+ + {/* Row 4 Created At and Title*/} + +
+
+ + {/*
+ {formatUTCToLocalTime(data?.createdAt, true)} +
*/} + +
+ {data?.createdAt + ? formatUTCToLocalTime(data.createdAt, true) + : "N/A"} +
+
+
+ +
+
+ +
{data?.title || "N/A"}
+
+
+ + {/* Row 5 Payee and Notify*/} + +
+
+ +
{data?.payee || "N/A"}
+
+
+ +
+
+ + +
+ {data?.notifyTo?.length > 0 + ? data.notifyTo.map((user, index) => ( + + {user.email} + {index < data.notifyTo.length - 1 && ", "} + + )) + : "N/A"} +
+
+
+ + {/* Row 6 Strike Date*/} + +
+
+ + {/*
+ {formatUTCToLocalTime(data?.strikeDate)} +
*/} +
+ {data?.strikeDate + ? formatUTCToLocalTime(data.strikeDate, true) + : "N/A"} +
+
+
+ + {/* Row 7 Frequency and Buffer Days*/} + +
+
+ +
+ {data?.frequency !== undefined + ? FREQUENCY_FOR_RECURRING[data.frequency] + : "N/A"} +
+
+
+ +
+
+ +
{data?.paymentBufferDays || "N/A"}
+
+
+ + {/* Row 8 Updated At and Number of Iteration*/} + +
+
+ +
+ {data?.updatedAt + ? formatUTCToLocalTime(data.updatedAt, true) + : "N/A"} +
+
+
+ +
+
+ +
{data?.numberOfIteration || "N/A"}
+
+
+ + + {/* Row 9 Created By and Updated By*/} + +
+
+ + + + {`${data?.createdBy?.firstName ?? ""} ${data?.createdBy?.lastName ?? ""}`.trim() || "N/A"} + +
+
+
+
+ + + {data?.updatedBy ? ( + <> + + + {`${data.updatedBy.firstName ?? ""} ${data.updatedBy.lastName ?? ""}`.trim() || "N/A"} + + + ) : ( + N/A + )} +
+
+ + {/* Row 10 Description */} + +
+ +
+ {data?.description || "N/A"} +
+
+
+ {/*
*/} +
+ ) } -export default ViewRecurringExpense +export default ViewRecurringExpense \ No newline at end of file diff --git a/src/hooks/useExpense.js b/src/hooks/useExpense.js index 464247b2..259dd79f 100644 --- a/src/hooks/useExpense.js +++ b/src/hooks/useExpense.js @@ -500,13 +500,13 @@ export const useRecurringExpenseList = ( }); }; -export const useRecurringExpenseDetail =(RequestId)=>{ +export const useRecurringExpenseDetail =(RecurringId)=>{ return useQuery({ - queryKey:['recurringExpense',RequestId], + queryKey:['recurringExpense',RecurringId], queryFn:async()=>{ - const resp = await ExpenseRepository.GetRecurringExpense(RequestId); + const resp = await ExpenseRepository.GetRecurringExpense(RecurringId); return resp.data; }, - enabled:!!RequestId + enabled:!!RecurringId }) } diff --git a/src/pages/RecurringExpense/RecurringExpensePage.jsx b/src/pages/RecurringExpense/RecurringExpensePage.jsx index 61e935f4..7af3ec44 100644 --- a/src/pages/RecurringExpense/RecurringExpensePage.jsx +++ b/src/pages/RecurringExpense/RecurringExpensePage.jsx @@ -151,22 +151,12 @@ const RecurringExpensePage = () => { closeModal={() => setViewRecurring({ IsOpen: null, recurringId: null }) } - recurringId={viewRecurring.recurringId} + RecurringId={viewRecurring.recurringId} /> - + )} - {/* {ViewRequest.view && ( - setVieRequest({ requestId: null, view: false })} - > - - - )} */}