Adding View functionality in Add challan.

This commit is contained in:
Kartik Sharma 2025-12-12 18:11:38 +05:30
parent bb743d2bb0
commit deba5dfa01

View File

@ -2,10 +2,17 @@ import React from "react";
import { useDeliverChallane } from "../../hooks/usePurchase"; import { useDeliverChallane } from "../../hooks/usePurchase";
import { SpinnerLoader } from "../common/Loader"; import { SpinnerLoader } from "../common/Loader";
import { formatUTCToLocalTime } from "../../utils/dateUtils"; import { formatUTCToLocalTime } from "../../utils/dateUtils";
import { FileView } from "../Expenses/Filelist"; import { FileView } from "../Expenses/Filelist"; // Assuming FileView is the component showing the file icon/name
import { usePurchaseContext } from "../../pages/purchase/PurchasePage";
import { getIconByFileType } from "../../utils/appUtils";
// Assuming you have an Error component imported somewhere else
// import Error from "../common/Error";
const DeliverChallanList = ({ purchaseId, viewDocuments }) => { const DeliverChallanList = ({ purchaseId, viewDocuments }) => {
const { setDocumentView } = usePurchaseContext();
const { data, isLoading, isError, error } = useDeliverChallane(purchaseId); const { data, isLoading, isError, error } = useDeliverChallane(purchaseId);
if (isLoading) { if (isLoading) {
return ( return (
<div className="d-flex justify-content-center align-items-center text-center vh-50"> <div className="d-flex justify-content-center align-items-center text-center vh-50">
@ -17,10 +24,12 @@ const DeliverChallanList = ({ purchaseId, viewDocuments }) => {
if (isError) { if (isError) {
return ( return (
<div className="py-3"> <div className="py-3">
{/* Assuming Error component is used here */}
<Error error={error} /> <Error error={error} />
</div> </div>
); );
} }
if (!isLoading && data.length === 0) if (!isLoading && data.length === 0)
return ( return (
<div className="d-flex justify-content-center align-items-center text-center vh-50"> <div className="d-flex justify-content-center align-items-center text-center vh-50">
@ -55,8 +64,29 @@ const DeliverChallanList = ({ purchaseId, viewDocuments }) => {
{item.description || "-"} {item.description || "-"}
</p> </p>
{/* Check if attachment exists and open document view on click */}
{item.attachment?.preSignedUrl && ( {item.attachment?.preSignedUrl && (
<FileView file={item.attachment} viewFile={viewDocuments} /> <div
className="d-flex align-items-center cusor-pointer mt-2"
onClick={() => {
setDocumentView({
IsOpen: true,
Images: [item.attachment],
});
}}
>
{/* Replicating the display style used in ViewExpense for single file attachment */}
<i
className={`bx ${getIconByFileType(item.attachment.contentType)}`}
style={{ fontSize: "30px" }}
></i>
<small
className="text-start text-tiny text-truncate w-100 ms-1"
title={item.attachment.fileName}
>
{item.attachment.fileName}
</small>
</div>
)} )}
</div> </div>
</div> </div>
@ -65,4 +95,4 @@ const DeliverChallanList = ({ purchaseId, viewDocuments }) => {
); );
}; };
export default DeliverChallanList; export default DeliverChallanList;