import React, { useState } from "react"; import { useCollections } from "../../hooks/useCollections"; import { ITEMS_PER_PAGE } from "../../utils/constants"; import { formatFigure, localToUtc, useDebounce } from "../../utils/appUtils"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; import Pagination from "../common/Pagination"; const CollectionList = ({ fromDate, toDate, isPending, searchString }) => { const [currentPage, setCurrentPage] = useState(1); const searchDebounce = useDebounce(searchString, 500); const { data, isLoading, isError, error } = useCollections( ITEMS_PER_PAGE, currentPage, localToUtc(fromDate), localToUtc(toDate), isPending, true, searchDebounce ); const paginate = (page) => { if (page >= 1 && page <= (data?.totalPages ?? 1)) { setCurrentPage(page); } }; const collectionColumns = [ { key: "invoiceDate", label: "Invoice Date", getValue: (col) => ( {formatUTCToLocalTime(col.invoiceDate)} ), align: "text-start", }, { key: "invoiceId", label: "Invoice Id", getValue: (col) => ( {col?.invoiceNumber ?? "-"} ), align: "text-start", }, { key: "project", label: "Project", getValue: (col) => ( {col?.project?.name ?? "-"} ), align: "text-start", }, { key: "submittedDate", label: "Submitted Date", getValue: (col) => ( {formatUTCToLocalTime(col.createdAt)} ), align: "text-start", }, { key: "expectedSubmittedDate", label: "Expected Payment Date", getValue: (col) => ( {formatUTCToLocalTime(col.exceptedPaymentDate) ?? "-"} ), align: "text-start", }, { key: "amount", label: "Amount", getValue: (col) => ( {formatFigure(col?.basicAmount, { type: "currency", currency: "INR" }) ?? 0} ), align: "text-end", }, { key: "balance", label: "Balance", getValue: (col) => ( {formatFigure(col?.balanceAmount, { type: "currency", currency: "INR" }) ?? 0} ), align: "text-end", }, ]; if (isLoading) return

Loading...

; if (isError) return

{error.message}

; return (
{collectionColumns.map((col) => ( ))} {Array.isArray(data?.data) && data.data.length > 0 ? ( data.data.map((row, i) => ( {collectionColumns.map((col) => ( ))} )) ) : ( )}
{col.label} Action
{col.getValue(row)}
No Collections Found
{data?.data?.length > 0 && (
)}
); }; export default CollectionList;