From 8229a44a74ed7baf077980e0c1e3ba64ad638934 Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Wed, 5 Nov 2025 23:04:27 +0530 Subject: [PATCH] added advance transaction records --- .../AdvancePayment/AdvancePaymentList.jsx | 102 ++++++++++++------ src/components/common/Loader.jsx | 2 +- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/src/components/AdvancePayment/AdvancePaymentList.jsx b/src/components/AdvancePayment/AdvancePaymentList.jsx index a1bf31a7..0f975ab5 100644 --- a/src/components/AdvancePayment/AdvancePaymentList.jsx +++ b/src/components/AdvancePayment/AdvancePaymentList.jsx @@ -2,16 +2,53 @@ import React from "react"; import { useExpenseTransactions } from "../../hooks/useExpense"; import Error from "../common/Error"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; +import Loader, { SpinnerLoader } from "../common/Loader"; const AdvancePaymentList = ({ employeeId }) => { - const { data, isError, isLoading, error } = - useExpenseTransactions(employeeId); + const { data, isError, isLoading, error, isFetching } = + useExpenseTransactions(employeeId, { enabled: !!employeeId }); - const records = data?.json || []; + // Handle no employee selected + if (!employeeId) { + return ( +
+

Please select an employee

+
+ ); + } + + // Handle loading state + if (isLoading || isFetching) { + return ( +
+ +
+ ); + } + + // Handle error state + if (isError) { + return ( +
+ {error?.status === 404 ? ( + "No advance payment transactions found." + ) : ( + + )} +
+ ); + } + + const records = Array.isArray(data) ? data : []; let currentBalance = 0; - - const rowsWithBalance = data?.map((r) => { + const rowsWithBalance = records.map((r) => { const isCredit = r.amount > 0; const credit = isCredit ? r.amount : 0; const debit = !isCredit ? Math.abs(r.amount) : 0; @@ -19,8 +56,8 @@ const AdvancePaymentList = ({ employeeId }) => { return { id: r.id, - description: r.title, - projectName: r.project?.name, + description: r.title || "-", + projectName: r.project?.name || "-", createdAt: r.createdAt, credit, debit, @@ -33,41 +70,44 @@ const AdvancePaymentList = ({ employeeId }) => { { key: "credit", label: ( - - Credit () - + <> + Credit + ), align: "text-end", }, { key: "debit", label: ( - - Debit () - + <> + Debit + ), align: "text-end", }, { key: "balance", label: ( - + <> Balance - + ), align: "text-end fw-bold", }, ]; - if (isLoading) return
Loading...
; - if (isError){ - return
{error.status === 404 ? "No advance payment transactions found." : }
- }; + // Handle empty records + if (rowsWithBalance.length === 0) { + return ( +
+ No advance payment records found. +
+ ); + } return ( -
-
- {employeeId ? ( +
+
{columns.map((col) => ( @@ -78,17 +118,16 @@ const AdvancePaymentList = ({ employeeId }) => { - {rowsWithBalance?.map((row) => ( + {rowsWithBalance.map((row) => ( {columns.map((col) => ( -
{["balance", "credit", "debit"].includes(col.key) ? ( - row[col.key].toLocaleString("en-IN", { - style: "currency", - currency: "INR", - }) + + {row[col.key].toLocaleString("en-IN")} + ) : ( -
+
{formatUTCToLocalTime(row.createdAt)} @@ -114,12 +153,7 @@ const AdvancePaymentList = ({ employeeId }) => {
):( -
-

Please Select Employee

-
- )} -
+
); }; diff --git a/src/components/common/Loader.jsx b/src/components/common/Loader.jsx index 53c90486..7caaa324 100644 --- a/src/components/common/Loader.jsx +++ b/src/components/common/Loader.jsx @@ -26,7 +26,7 @@ export const SpinnerLoader = ()=>{
Loading...
-

Loading attendance data...

+

Loading data... Please wait

) } \ No newline at end of file