From 037359cdfc2c3b8efc9546a9e9d9f4c9a721d7b6 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Sat, 19 Jul 2025 23:03:43 +0530 Subject: [PATCH 01/31] add Expense Type master with API integration and table config --- src/data/masters.js | 294 +++++++++++++------------ src/hooks/masterHook/useMaster.js | 209 +----------------- src/pages/master/MasterTable.jsx | 2 + src/repositories/MastersRepository.jsx | 4 +- 4 files changed, 155 insertions(+), 354 deletions(-) diff --git a/src/data/masters.js b/src/data/masters.js index e94de7a3..04218090 100644 --- a/src/data/masters.js +++ b/src/data/masters.js @@ -1,153 +1,155 @@ // it important ------ -export const mastersList = [ {id: 1, name: "Application Role"}, {id: 2, name: "Job Role"}, {id: 3, name: "Activity"},{id: 4, name:"Work Category"},{id:5,name:"Contact Category"},{id:6,name:"Contact Tag"}] +export const mastersList = [ + { id: 1, name: "Application Role" }, + { id: 2, name: "Job Role" }, + { id: 3, name: "Activity" }, + { id: 4, name: "Work Category" }, + { id: 5, name: "Contact Category" }, + { id: 6, name: "Contact Tag" }, + { id: 7, name: "Expense Type" }, +]; // ------------------- -export const dailyTask = [ - { - id:1, - project:{ - projectName:"Project Name1", - building:"buildName1", - floor:"floorName1", - workArea:"workarea1" - }, - target:80, - employees:[ - { - id:1, - name:"Vishal Patil", - role:"helper" - }, - { - id:202, - name:"Vishal Patil", - role:"helper" - }, - { - id:101, - name:"Kushal Patil", - role:"Engineer" - } - ] - - }, - { - id:2, - project:{ - projectName:"Project Name1", - building:"buildName1", - floor:"floorName1", - workArea:"workarea1" - }, - target:90, - employees:[ - { - id:1, - name:"Vishal Patil", - role:"welder" - }, - { - id:202, - name:"Vishal Patil", - role:"welder" - }, - { - id:101, - name:"Kushal Patil", - role:"Site Engineer" - } - ] - - } -] - - - -export const jobRoles =[ - { - id:1, - name:"Project Manager" - }, - { - id:2, - name:"Software Developer" - }, - { - id:3, - name:"Estimation Engineer" - }, - { - id:4, - name:"Designer" - }, - { - id:5, - name:"Site Engineer" - } -] - -export const employee =[ - { - id:1, - FirtsName:"Pramod", - LastName:"Mahajan", - JobRoleId:2, - }, - { - id:2, - FirtsName:"Akahsy", - LastName:"Patil", - JobRoleId:1, - }, - { - id:3, - FirtsName:"janvi", - LastName:"Potdar", - JobRoleId:3, - }, - { - id:4, - FirtsName:"Aboli", - LastName:"Patil", - JobRoleId:2, - }, - { - id:5, - FirtsName:"Shubham", - LastName:"Tamboli", - JobRoleId:1, - }, - { - id:6, - FirtsName:"Alwin", - LastName:"Joy", - JobRoleId:4, - }, - { - id:7, - FirtsName:"John", - LastName:"kwel", - JobRoleId:4, - }, - { - id:8, - FirtsName:"Gita", - LastName:"shaha", - JobRoleId:1, - },{ - id:9, - FirtsName:"Pratik", - LastName:"Joshi", - JobRoleId:5, - }, - { - id:10, - FirtsName:"Nikil", - LastName:"Patil", - JobRoleId:5, - } -] +// export const dailyTask = [ +// { +// id:1, +// project:{ +// projectName:"Project Name1", +// building:"buildName1", +// floor:"floorName1", +// workArea:"workarea1" +// }, +// target:80, +// employees:[ +// { +// id:1, +// name:"Vishal Patil", +// role:"helper" +// }, +// { +// id:202, +// name:"Vishal Patil", +// role:"helper" +// }, +// { +// id:101, +// name:"Kushal Patil", +// role:"Engineer" +// } +// ] +// }, +// { +// id:2, +// project:{ +// projectName:"Project Name1", +// building:"buildName1", +// floor:"floorName1", +// workArea:"workarea1" +// }, +// target:90, +// employees:[ +// { +// id:1, +// name:"Vishal Patil", +// role:"welder" +// }, +// { +// id:202, +// name:"Vishal Patil", +// role:"welder" +// }, +// { +// id:101, +// name:"Kushal Patil", +// role:"Site Engineer" +// } +// ] +// } +// ] +// export const jobRoles =[ +// { +// id:1, +// name:"Project Manager" +// }, +// { +// id:2, +// name:"Software Developer" +// }, +// { +// id:3, +// name:"Estimation Engineer" +// }, +// { +// id:4, +// name:"Designer" +// }, +// { +// id:5, +// name:"Site Engineer" +// } +// ] +// export const employee =[ +// { +// id:1, +// FirtsName:"Pramod", +// LastName:"Mahajan", +// JobRoleId:2, +// }, +// { +// id:2, +// FirtsName:"Akahsy", +// LastName:"Patil", +// JobRoleId:1, +// }, +// { +// id:3, +// FirtsName:"janvi", +// LastName:"Potdar", +// JobRoleId:3, +// }, +// { +// id:4, +// FirtsName:"Aboli", +// LastName:"Patil", +// JobRoleId:2, +// }, +// { +// id:5, +// FirtsName:"Shubham", +// LastName:"Tamboli", +// JobRoleId:1, +// }, +// { +// id:6, +// FirtsName:"Alwin", +// LastName:"Joy", +// JobRoleId:4, +// }, +// { +// id:7, +// FirtsName:"John", +// LastName:"kwel", +// JobRoleId:4, +// }, +// { +// id:8, +// FirtsName:"Gita", +// LastName:"shaha", +// JobRoleId:1, +// },{ +// id:9, +// FirtsName:"Pratik", +// LastName:"Joshi", +// JobRoleId:5, +// }, +// { +// id:10, +// FirtsName:"Nikil", +// LastName:"Patil", +// JobRoleId:5, +// } +// ] diff --git a/src/hooks/masterHook/useMaster.js b/src/hooks/masterHook/useMaster.js index 20caff62..69d9d3ca 100644 --- a/src/hooks/masterHook/useMaster.js +++ b/src/hooks/masterHook/useMaster.js @@ -12,213 +12,6 @@ import showToast from "../../services/toastService"; -// const useMaster = () => { - -// const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster); -// const [data, setData] = useState([]); -// const [loading, setLoading] = useState(true); -// const [error, setError] = useState(""); -// useEffect(() => { -// const fetchData = async () => { -// if (!selectedMaster) return; -// setLoading(true); -// try { -// const cachedData = getCachedData(selectedMaster); -// if (cachedData) { - -// setData(cachedData); - -// } else { -// let response; -// switch (selectedMaster) { -// case "Application Role": -// response = await MasterRespository.getRoles(); -// response = response.data; -// break; -// case "Job Role": -// response = await MasterRespository.getJobRole(); -// response = response.data -// break; -// case "Activity": -// response = await MasterRespository.getActivites(); -// response = response.data -// break; -// case "Work Category": -// response = await MasterRespository.getWorkCategory(); -// response = response.data -// break; -// case "Contact Category": -// response = await MasterRespository.getContactCategory(); -// response = response.data -// break; -// case "Contact Tag": -// response = await MasterRespository.getContactTag(); -// response = response.data -// break; -// case "Status": -// response = [{description: null,featurePermission: null,id: "02dd4761-363c-49ed-8851-3d2489a3e98d",status:"status 1"},{description: null,featurePermission: null,id: "03dy9761-363c-49ed-8851-3d2489a3e98d",status:"status 2"},{description: null,featurePermission: null,id: "03dy7761-263c-49ed-8851-3d2489a3e98d",status:"Status 3"}]; -// break; -// default: -// response = []; -// } - -// if (response) { -// setData(response); -// cacheData(selectedMaster, response); -// } -// } -// } catch (err) { -// setError("Failed to fetch data."); -// } finally { -// setLoading(false); -// } -// }; - -// if ( selectedMaster ) -// { - -// fetchData(); -// } - -// }, [selectedMaster]); - - - -// return { data, loading, error } -// }; - - - - -// export const useActivitiesMaster = () => -// { -// const [ activities, setActivites ] = useState( [] ) -// const [ loading, setloading ] = useState( false ); -// const [ error, setError ] = useState() -// const fetchActivities =async () => { -// setloading(true); -// try { -// const response = await MasterRespository.getActivites(); -// setActivites(response.data); -// cacheData( "ActivityMaster", response.data ); -// setloading(false); -// } catch (err) { -// setError(err); -// setloading(false); -// } -// } -// useEffect( () => -// { -// const cacheddata = getCachedData( "ActivityMaster" ); -// if ( !cacheddata ) -// { -// fetchActivities() -// } else -// { -// setActivites(cacheddata); -// } -// }, [] ) - -// return {activities,loading,error} -// } - -// export const useWorkCategoriesMaster = () => -// { -// const [ categories, setCategories ] = useState( [] ) -// const [ categoryLoading, setloading ] = useState( false ); -// const [ categoryError, setError ] = useState( "" ) - -// const fetchCategories =async () => { -// const cacheddata = getCachedData("Work Category"); - -// if (!cacheddata) { -// setloading(true); -// try { -// const response = await MasterRespository.getWorkCategory(); -// setCategories(response.data); -// cacheData("Work Category", response.data); -// } catch (err) { -// setError(err); -// console.log(err); -// } finally { -// setloading(false); -// } -// } else { -// setCategories(cacheddata); -// } -// } -// useEffect( () => -// { -// fetchCategories() -// }, [] ) - -// return {categories,categoryLoading,categoryError} -// } - -// export const useContactCategory = () => -// { -// const [ contactCategory, setContactCategory ] = useState( [] ) -// const [ loading, setLoading ] = useState( false ) -// const [ Error, setError ] = useState() - -// const fetchConatctCategory = async() => -// { -// const cache_Category = getCachedData( "Contact Category" ); -// if ( !cache_Category ) -// { -// try -// { -// let resp = await MasterRespository.getContactCategory(); -// setContactCategory( resp.data ); -// cacheData("Contact Category",resp.data) -// } catch ( error ) -// { -// setError(error) -// } -// } else -// { -// setContactCategory(cache_Category) -// } -// } - -// useEffect( () => -// { -// fetchConatctCategory() -// }, [] ) -// return { contactCategory,loading,Error} -// } -// export const useContactTags = () => { -// const [contactTags, setContactTags] = useState([]); -// const [loading, setLoading] = useState(false); -// const [error, setError] = useState(null); - -// useEffect(() => { -// const fetchContactTag = async () => { -// const cache_Tags = getCachedData("Contact Tag"); - -// if (!cache_Tags) { -// setLoading(true); -// try { -// const resp = await MasterRespository.getContactTag(); -// setContactTags(resp.data); -// cacheData("Contact Tag", resp.data); -// } catch (err) { -// setError(err); -// } finally { -// setLoading(false); -// } -// } else { -// setContactTags(cache_Tags); -// } -// }; - -// fetchContactTag(); -// }, []); - -// return { contactTags, loading, error }; -// }; - -// Separate matser------------- export const useActivitiesMaster = () => { @@ -316,6 +109,8 @@ const fetchMasterData = async (masterType) => { return (await MasterRespository.getContactCategory()).data; case "Contact Tag": return (await MasterRespository.getContactTag()).data; + case "Expense Type": + return (await MasterRespository.getExpenseType()).data; case "Status": return [ { diff --git a/src/pages/master/MasterTable.jsx b/src/pages/master/MasterTable.jsx index 0126b339..5b0e7e63 100644 --- a/src/pages/master/MasterTable.jsx +++ b/src/pages/master/MasterTable.jsx @@ -16,6 +16,8 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => { "tenantId", "checkLists", "isSystem", + "isActive", + "noOfPersonsRequired" ]; const safeData = Array.isArray(data) ? data : []; diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index aebfc157..9689853f 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -56,6 +56,8 @@ export const MasterRespository = { createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ), updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/edit/${ id }`, data ), - getAuditStatus:()=>api.get('/api/Master/work-status') + getAuditStatus:()=>api.get('/api/Master/work-status'), + + getExpenseType:()=>api.get('/api/Master/expenses-types') } \ No newline at end of file From 4427d719801c1bd31d17eaf5b2ee021986722625 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Sat, 19 Jul 2025 23:37:09 +0530 Subject: [PATCH 02/31] added Payment Mode master with API integration and table config for get list --- src/data/masters.js | 3 ++- src/hooks/masterHook/useMaster.js | 2 ++ src/repositories/MastersRepository.jsx | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/data/masters.js b/src/data/masters.js index 04218090..60f36b38 100644 --- a/src/data/masters.js +++ b/src/data/masters.js @@ -6,7 +6,8 @@ export const mastersList = [ { id: 4, name: "Work Category" }, { id: 5, name: "Contact Category" }, { id: 6, name: "Contact Tag" }, - { id: 7, name: "Expense Type" }, + { id: 7, name: "Expense Type" }, + { id: 8, name: "Payment Mode" }, ]; // ------------------- diff --git a/src/hooks/masterHook/useMaster.js b/src/hooks/masterHook/useMaster.js index 69d9d3ca..9e3ec2ee 100644 --- a/src/hooks/masterHook/useMaster.js +++ b/src/hooks/masterHook/useMaster.js @@ -111,6 +111,8 @@ const fetchMasterData = async (masterType) => { return (await MasterRespository.getContactTag()).data; case "Expense Type": return (await MasterRespository.getExpenseType()).data; + case "Payment Mode": + return (await MasterRespository.getPaymentMode()).data; case "Status": return [ { diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index 9689853f..165e0a04 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -58,6 +58,9 @@ export const MasterRespository = { getAuditStatus:()=>api.get('/api/Master/work-status'), - getExpenseType:()=>api.get('/api/Master/expenses-types') + getExpenseType:()=>api.get('/api/Master/expenses-types'), + + + getPaymentMode:()=>api.get('/api/Master/payment-modes') } \ No newline at end of file From e379f0e348c6dddb946a05ddc3e9cffdf58b0d6e Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 21 Jul 2025 10:43:09 +0530 Subject: [PATCH 03/31] refactored code for optimze --- src/components/master/MasterModal.jsx | 147 +++++++++----------------- 1 file changed, 49 insertions(+), 98 deletions(-) diff --git a/src/components/master/MasterModal.jsx b/src/components/master/MasterModal.jsx index 52e22114..13ca0e7c 100644 --- a/src/components/master/MasterModal.jsx +++ b/src/components/master/MasterModal.jsx @@ -1,5 +1,4 @@ import React, { useState, useEffect } from "react"; - import CreateRole from "./CreateRole"; import DeleteMaster from "./DeleteMaster"; import EditRole from "./EditRole"; @@ -19,66 +18,41 @@ import EditContactCategory from "./EditContactCategory"; import EditContactTag from "./EditContactTag"; import { useDeleteMasterItem } from "../../hooks/masterHook/useMaster"; + const MasterModal = ({ modaldata, closeModal }) => { const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const { mutate: deleteMasterItem, isPending } = useDeleteMasterItem(); - // const handleSelectedMasterDeleted = async () => - // { - // debugger - // const deleteFn = MasterRespository[modaldata.masterType]; - // if (!deleteFn) { - // showToast(`No delete strategy defined for master type`,"error"); - // return false; - // } - // try - // { - // const response = await deleteFn( modaldata?.item?.id ); - // const selected_cachedData = getCachedData( modaldata?.masterType ); - // const updated_master = selected_cachedData?.filter(item => item.id !== modaldata?.item.id); - // cacheData( modaldata?.masterType, updated_master ) - - // showToast(`${modaldata?.masterType} is deleted successfully`, "success"); - // handleCloseDeleteModal() - - // } catch ( error ) - // { - // const message = error.response.data.message || error.message || "Error occured api during call" - // showToast(message, "success"); - // } - // } - const handleSelectedMasterDeleted = () => { - if (!modaldata?.masterType || !modaldata?.item?.id) { + const { masterType, item, validateFn } = modaldata || {}; + if (!masterType || !item?.id) { showToast("Missing master type or item", "error"); return; } + deleteMasterItem( - { - masterType: modaldata.masterType, - item: modaldata.item, - validateFn: modaldata.validateFn, // optional - }, - { - onSuccess: () => { - handleCloseDeleteModal(); - }, - } + { masterType, item, validateFn }, + { onSuccess: handleCloseDeleteModal } ); }; + const handleCloseDeleteModal = () => { + setIsDeleteModalOpen(false); + closeModal(); + }; + useEffect(() => { if (modaldata?.modalType === "delete") { setIsDeleteModalOpen(true); } }, [modaldata]); - const handleCloseDeleteModal = () => { - setIsDeleteModalOpen(false); + if (!modaldata?.modalType) { closeModal(); - }; + return null; + } - if (modaldata?.modalType === "delete" && isDeleteModalOpen) { + if (modaldata.modalType === "delete" && isDeleteModalOpen) { return (
{
); } + + const renderModalContent = () => { + const { modalType, item, masterType } = modaldata; + + const modalComponents = { + "Application Role": , + "Edit-Application Role": , + "Job Role": , + "Edit-Job Role": , + "Activity": , + "Edit-Activity": , + "Work Category": , + "Edit-Work Category": , + "Contact Category": , + "Edit-Contact Category": , + "Contact Tag": , + "Edit-Contact Tag": , + }; + + return modalComponents[modalType] || null; + }; + + const isLargeModal = ["Application Role", "Edit-Application Role"].includes( + modaldata.modalType + ); + return (