From 35b3384dac19a5252b5867a2b3089cbebe5f8e3a Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Mon, 1 Dec 2025 11:39:34 +0530 Subject: [PATCH 1/3] At the time of Update in Purchase Automatically hit the sumit without click. --- src/components/purchase/ManagePurchase.jsx | 87 +++++++++++----------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/src/components/purchase/ManagePurchase.jsx b/src/components/purchase/ManagePurchase.jsx index 262238bf..89c1b1b3 100644 --- a/src/components/purchase/ManagePurchase.jsx +++ b/src/components/purchase/ManagePurchase.jsx @@ -127,8 +127,6 @@ const ManagePurchase = ({ onClose, purchaseId }) => { const onSubmit = useCallback( (formData) => { - if (activeTab !== 2) return; - if (purchaseId) { const payload = generatePatchOps(formData); updatePurchase({ purchaseId, payload }); @@ -136,7 +134,7 @@ const ManagePurchase = ({ onClose, purchaseId }) => { CreateInvoice(formData); } }, - [activeTab, purchaseId, generatePatchOps, updatePurchase, CreateInvoice] + [purchaseId, generatePatchOps, updatePurchase, CreateInvoice] ); return (
@@ -184,50 +182,53 @@ const ManagePurchase = ({ onClose, purchaseId }) => { {/* --- Form Content --- */}
-
{ - if (activeTab !== 2) { - e.preventDefault(); - e.stopPropagation(); - } - }} - onSubmit={purchaseOrder.handleSubmit(onSubmit)} - > - {stepsConfig[activeTab].component} + {activeTab !== 2 && ( +
+ {stepsConfig[activeTab].component} - {/* Buttons */} -
- +
+ -
- {activeTab < stepsConfig.length - 1 ? ( - - ) : ( - - )} +
- + )} + {activeTab === 2 && ( +
+ {stepsConfig[2].component} + +
+ + + +
+
+ )}
From 311c74587ad01a0184d01dd1119ea05bc4e87beb Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Mon, 1 Dec 2025 15:03:13 +0530 Subject: [PATCH 2/3] Adding Delete and Restore functionality in Purchase Invoice --- src/components/purchase/PurchaseList.jsx | 286 +++++++++++++---------- src/hooks/usePurchase.jsx | 27 +++ src/pages/purchase/PurchasePage.jsx | 19 +- src/repositories/PurchaseRepository.jsx | 3 + 4 files changed, 216 insertions(+), 119 deletions(-) diff --git a/src/components/purchase/PurchaseList.jsx b/src/components/purchase/PurchaseList.jsx index 39ed3352..f5ac3c0e 100644 --- a/src/components/purchase/PurchaseList.jsx +++ b/src/components/purchase/PurchaseList.jsx @@ -1,21 +1,28 @@ import React, { useState } from "react"; -import { usePurchasesList } from "../../hooks/usePurchase"; +import { useDeletePurchaseInvoice, usePurchasesList } from "../../hooks/usePurchase"; import { ITEMS_PER_PAGE } from "../../utils/constants"; import Pagination from "../common/Pagination"; import { PurchaseColumn } from "./Purchasetable"; import { SpinnerLoader } from "../common/Loader"; import { useDebounce } from "../../utils/appUtils"; import { usePurchaseContext } from "../../pages/purchase/PurchasePage"; +import ConfirmModal from "../common/ConfirmModal"; -const PurchaseList = ({ searchString }) => { +const PurchaseList = ({ searchString, isActive }) => { const { setViewPurchase, setManagePurchase, setChallan } = usePurchaseContext(); const [currentPage, setCurrentPage] = useState(1); + const { mutate: DeletePurchaseInvoice, isPending } = useDeletePurchaseInvoice(); + const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false); + const [deletingId, setDeletingId] = useState(null); + + const debounceSearch = useDebounce(searchString, 300); const { data, isLoading } = usePurchasesList( ITEMS_PER_PAGE, currentPage, - true, + // true, + !isActive, {}, debounceSearch ); @@ -28,129 +35,172 @@ const PurchaseList = ({ searchString }) => { const visibleColumns = PurchaseColumn.filter((col) => !col.hidden); + const handleDeleteRestore = (id) => { + DeletePurchaseInvoice( + { id, isActive: isActive }, // delete if active, restore if deleted + { + onSettled: () => { + setDeletingId(null); + setIsDeleteModalOpen(false); + }, + } + ); + }; + + return ( -
-
- - - - {visibleColumns.map((col) => ( - - ))} - - - - - - {/* LOADING */} - {isLoading && ( + <> + {IsDeleteModalOpen && ( + setIsDeleteModalOpen(false)} + loading={isPending} + paramData={deletingId} + /> + )} +
+
+
-
{col.label}
-
Action
+ - + {visibleColumns.map((col) => ( + + ))} + - )} - {!isLoading && data?.data?.length === 0 && ( - - - - )} + - {!isLoading && - data?.data?.map((item, index) => ( - - {visibleColumns.map((col) => ( - - ))} - + {/* LOADING */} + {isLoading && ( + + - ))} - -
-
- -
-
+
{col.label}
+
Action
- No Data Found -
- {col.render ? col.render(item) : item[col.key] || "NA"} - -
+
+
-
+ )} - {data?.data?.length > 0 && ( - - )} -
+ {!isLoading && data?.data?.length === 0 && ( + + + No Data Found + + + )} + + + {!isLoading && + data?.data?.map((item, index) => ( + + {visibleColumns.map((col) => ( + + {col.render ? col.render(item) : item[col.key] || "NA"} + + ))} + + + + + ))} + + +
+ + {data?.data?.length > 0 && ( + + )} +
+ ); }; diff --git a/src/hooks/usePurchase.jsx b/src/hooks/usePurchase.jsx index 7dcbde45..405700d1 100644 --- a/src/hooks/usePurchase.jsx +++ b/src/hooks/usePurchase.jsx @@ -120,3 +120,30 @@ export const useAddDeliverChallan = (onSuccessCallback) => { }, }); }; + + +export const useDeletePurchaseInvoice = () => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async ({ id, isActive }) => + await PurchaseRepository.deletePurchase(id, isActive), + + onSuccess: (_, variable) => { + queryClient.invalidateQueries({ queryKey: ["purchase_list"] }); + showToast( + `Purchase Invoice ${variable.isActive ? "restored" : "deleted"} successfully`, + "success" + ); + }, + + onError: (error) => { + showToast( + error?.response?.data?.message || + error.message || + "Failed to delete branch", + "error" + ); + }, + }); +}; diff --git a/src/pages/purchase/PurchasePage.jsx b/src/pages/purchase/PurchasePage.jsx index a2a0e37c..785f434e 100644 --- a/src/pages/purchase/PurchasePage.jsx +++ b/src/pages/purchase/PurchasePage.jsx @@ -19,6 +19,8 @@ export const usePurchaseContext = () => { }; const PurchasePage = () => { const [searchText, setSearchText] = useState(""); + const [showDelete, setShowDelete] = useState(false); + const [showInactive, setShowInactive] = useState(false); const [addChallan, setChallan] = useState({ isOpen: false, purchaseId: null, @@ -61,6 +63,21 @@ const PurchasePage = () => { aria-controls="DataTables_Table_0" /> +
+ setShowInactive(!showInactive)} + /> + +