diff --git a/src/components/Dashboard/Activity.jsx b/src/components/Dashboard/Activity.jsx index a1f9c5fc..78483ed5 100644 --- a/src/components/Dashboard/Activity.jsx +++ b/src/components/Dashboard/Activity.jsx @@ -1,194 +1,194 @@ -import React, { useState, useEffect } from "react"; -import LineChart from "../Charts/LineChart"; -import { useProjects } from "../../hooks/useProjects"; -import { useDashboard_ActivityData } from "../../hooks/useDashboard_Data"; -import ApexChart from "../Charts/Circlechart"; +// import React, { useState, useEffect } from "react"; +// import LineChart from "../Charts/LineChart"; +// import { useProjects } from "../../hooks/useProjects"; +// import { useDashboard_ActivityData } from "../../hooks/useDashboard_Data"; +// import ApexChart from "../Charts/Circlechart"; -const LOCAL_STORAGE_PROJECT_KEY = "selectedActivityProjectId"; +// const LOCAL_STORAGE_PROJECT_KEY = "selectedActivityProjectId"; -const Activity = () => { - const { projects } = useProjects(); - const today = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD - const [selectedDate, setSelectedDate] = useState(today); - const storedProjectId = localStorage.getItem(LOCAL_STORAGE_PROJECT_KEY); - const initialProjectId = storedProjectId || "all"; - const [selectedProjectId, setSelectedProjectId] = useState(initialProjectId); - const [displayedProjectName, setDisplayedProjectName] = useState("Select Project"); - const [activeTab, setActiveTab] = useState("all"); +// const Activity = () => { +// const { projects } = useProjects(); +// const today = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD +// const [selectedDate, setSelectedDate] = useState(today); +// const storedProjectId = localStorage.getItem(LOCAL_STORAGE_PROJECT_KEY); +// const initialProjectId = storedProjectId || "all"; +// const [selectedProjectId, setSelectedProjectId] = useState(initialProjectId); +// const [displayedProjectName, setDisplayedProjectName] = useState("Select Project"); +// const [activeTab, setActiveTab] = useState("all"); - const { dashboard_Activitydata: ActivityData, isLoading, error: isError } = - useDashboard_ActivityData(selectedDate, selectedProjectId); +// const { dashboard_Activitydata: ActivityData, isLoading, error: isError } = +// useDashboard_ActivityData(selectedDate, selectedProjectId); - useEffect(() => { - if (selectedProjectId === "all") { - setDisplayedProjectName("All Projects"); - } else if (projects) { - const foundProject = projects.find((p) => p.id === selectedProjectId); - setDisplayedProjectName(foundProject ? foundProject.name : "Select Project"); - } else { - setDisplayedProjectName("Select Project"); - } +// useEffect(() => { +// if (selectedProjectId === "all") { +// setDisplayedProjectName("All Projects"); +// } else if (projects) { +// const foundProject = projects.find((p) => p.id === selectedProjectId); +// setDisplayedProjectName(foundProject ? foundProject.name : "Select Project"); +// } else { +// setDisplayedProjectName("Select Project"); +// } - localStorage.setItem(LOCAL_STORAGE_PROJECT_KEY, selectedProjectId); - }, [selectedProjectId, projects]); +// localStorage.setItem(LOCAL_STORAGE_PROJECT_KEY, selectedProjectId); +// }, [selectedProjectId, projects]); - const handleProjectSelect = (projectId) => { - setSelectedProjectId(projectId); - }; +// const handleProjectSelect = (projectId) => { +// setSelectedProjectId(projectId); +// }; - const handleDateChange = (e) => { - setSelectedDate(e.target.value); - }; +// const handleDateChange = (e) => { +// setSelectedDate(e.target.value); +// }; - return ( -
-
-
-
-
Activity
-

Activity Progress Chart

-
+// return ( +//
+//
+//
+//
+//
Activity
+//

Activity Progress Chart

+//
-
- -
    -
  • - -
  • - {projects?.map((project) => ( -
  • - -
  • - ))} -
-
-
-
+//
+// +//
    +//
  • +// +//
  • +// {projects?.map((project) => ( +//
  • +// +//
  • +// ))} +//
+//
+//
+//
- {/* ✅ Date Picker Aligned Left with Padding */} -
-
- -
-
+// {/* ✅ Date Picker Aligned Left with Padding */} +//
+//
+// +//
+//
- {/* Tabs */} - +// {/* Tabs */} +// -
- {activeTab === "all" && ( -
-
- {isLoading ? ( -

Loading activity data...

- ) : isError ? ( -

No data available.

- ) : ( - ActivityData && ( - <> -
- Allocated Task -
-

- {ActivityData.totalCompletedWork?.toLocaleString()}/ - {ActivityData.totalPlannedWork?.toLocaleString()} -

- Completed / Assigned -
- -
- - ) - )} -
+//
+// {activeTab === "all" && ( +//
+//
+// {isLoading ? ( +//

Loading activity data...

+// ) : isError ? ( +//

No data available.

+// ) : ( +// ActivityData && ( +// <> +//
+// Allocated Task +//
+//

+// {ActivityData.totalCompletedWork?.toLocaleString()}/ +// {ActivityData.totalPlannedWork?.toLocaleString()} +//

+// Completed / Assigned +//
+// +//
+// +// ) +// )} +//
-
- {!isLoading && !isError && ActivityData && ( - <> -
- Activities -
-

- {ActivityData.totalCompletedWork?.toLocaleString()}/ - {ActivityData.totalPlannedWork?.toLocaleString()} -

- Pending / Assigned -
- -
- - )} -
-
- )} +//
+// {!isLoading && !isError && ActivityData && ( +// <> +//
+// Activities +//
+//

+// {ActivityData.totalCompletedWork?.toLocaleString()}/ +// {ActivityData.totalPlannedWork?.toLocaleString()} +//

+// Pending / Assigned +//
+// +//
+// +// )} +//
+//
+// )} - {activeTab === "logs" && ( -
- - - - - - - - - {[{ - activity: "Code Review / Remote", - assignedToday: 3, - completed: 2 - }].map((log, index) => ( - - - - - ))} - -
Activity / LocationAssigned / Completed
{log.activity}{log.assignedToday} / {log.completed}
-
- )} -
-
- ); -}; +// {activeTab === "logs" && ( +//
+// +// +// +// +// +// +// +// +// {[{ +// activity: "Code Review / Remote", +// assignedToday: 3, +// completed: 2 +// }].map((log, index) => ( +// +// +// +// +// ))} +// +//
Activity / LocationAssigned / Completed
{log.activity}{log.assignedToday} / {log.completed}
+//
+// )} +//
+//
+// ); +// }; -export default Activity; +// export default Activity; diff --git a/src/components/Expenses/ExpenseFilterPanel.jsx b/src/components/Expenses/ExpenseFilterPanel.jsx index 5e415821..99e821af 100644 --- a/src/components/Expenses/ExpenseFilterPanel.jsx +++ b/src/components/Expenses/ExpenseFilterPanel.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState,useMemo } from "react"; +import React, { useEffect, useState, useMemo } from "react"; import { FormProvider, useForm, Controller } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { defaultFilter, SearchSchema } from "./ExpenseSchema"; @@ -16,8 +16,11 @@ import { ExpenseFilterSkeleton } from "./ExpenseSkeleton"; import { useLocation } from "react-router-dom"; const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { - const selectedProjectId = useSelector((store) => store.localVariables.projectId); - const { data, isLoading,isError,error,isFetching , isFetched} = useExpenseFilter(); + const selectedProjectId = useSelector( + (store) => store.localVariables.projectId + ); + const { data, isLoading, isError, error, isFetching, isFetched } = + useExpenseFilter(); const groupByList = useMemo(() => { return [ @@ -27,11 +30,10 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { { id: "project", name: "Project" }, { id: "paymentMode", name: "Payment Mode" }, { id: "expensesType", name: "Expense Type" }, - { id: "createdAt", name: "Submitted Date" } + { id: "createdAt", name: "Submitted Date" }, ].sort((a, b) => a.name.localeCompare(b.name)); }, []); - const [selectedGroup, setSelectedGroup] = useState(groupByList[0]); const [resetKey, setResetKey] = useState(0); @@ -40,7 +42,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { defaultValues: defaultFilter, }); - const { control, register, handleSubmit, reset, watch } = methods; + const { control, handleSubmit, reset, setValue, watch } = methods; const isTransactionDate = watch("isTransactionDate"); const closePanel = () => { @@ -78,28 +80,37 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { }, [location]); if (isLoading || isFetching) return ; - if(isError && isFetched) return
Something went wrong Here- {error.message}
+ if (isError && isFetched) + return
Something went wrong Here- {error.message}
; return ( <> -
- -
- + +
+ +
-
- + {
- + { )} {/* Buttons: Always visible */} -
+
diff --git a/src/components/Organization/ManagOrg.jsx b/src/components/Organization/ManagOrg.jsx index 8ac9f677..0f4aa49e 100644 --- a/src/components/Organization/ManagOrg.jsx +++ b/src/components/Organization/ManagOrg.jsx @@ -146,6 +146,7 @@ const ManagOrg = () => { required valueKey="id" options={service?.data || []} + required = {true} /> {errors.serviceIds && ( {errors.serviceIds.message} diff --git a/src/components/Organization/OrgPickerFromSPId.jsx b/src/components/Organization/OrgPickerFromSPId.jsx index e0bdced0..0a46778c 100644 --- a/src/components/Organization/OrgPickerFromSPId.jsx +++ b/src/components/Organization/OrgPickerFromSPId.jsx @@ -84,10 +84,7 @@ const OrgPickerFromSPId = ({ title, placeholder }) => { height={50} />
-
onOpen({ startStep: 3, orgData: org })} - > +
{org.name}
{ Address:
{org.address}
+
+ {" "} + +
))} diff --git a/src/components/Organization/OrgPickerfromTenant.jsx b/src/components/Organization/OrgPickerfromTenant.jsx index 5471df2b..7d39fa60 100644 --- a/src/components/Organization/OrgPickerfromTenant.jsx +++ b/src/components/Organization/OrgPickerfromTenant.jsx @@ -85,7 +85,7 @@ const OrgPickerfromTenant = ({ title }) => { {isLoading ? (
Loading....
) : data && data?.data?.length > 0 ? ( -
+
@@ -99,28 +99,41 @@ const OrgPickerfromTenant = ({ title }) => { - - {Array.isArray(data.data) && data.data.length > 0 - ? data.data.map((row, i) => ( - - {contactList.map((col) => ( - - ))} - - - )) - : null} -
- {col.getValue(row)} - - -
+ +
+ + + {Array.isArray(data.data) && data.data.length > 0 + ? data.data.map((row, i) => ( + + {contactList.map((col) => ( + + ))} + + + )) + : null} + +
+ {col.getValue(row)} + +
+ +
+
+
) : null}
diff --git a/src/components/Organization/OrganizationModal.jsx b/src/components/Organization/OrganizationModal.jsx index da742427..7361c41f 100644 --- a/src/components/Organization/OrganizationModal.jsx +++ b/src/components/Organization/OrganizationModal.jsx @@ -60,7 +60,7 @@ const OrganizationModal = () => { if (startStep === 1) { return orgData && orgData !== null ? "Add Organization" - : "Choose Organization1"; + : "Choose Organization"; } if (startStep === 2) { diff --git a/src/components/Organization/OrganizationsList.jsx b/src/components/Organization/OrganizationsList.jsx index d5243e87..b7ea28e5 100644 --- a/src/components/Organization/OrganizationsList.jsx +++ b/src/components/Organization/OrganizationsList.jsx @@ -93,7 +93,7 @@ const OrganizationsList = ({searchText}) => { if (isError) return
{error?.message || "Something went wrong"}
; return ( -
+
diff --git a/src/components/Project/ProjectCard.jsx b/src/components/Project/ProjectCard.jsx index eded7324..d1abf8ac 100644 --- a/src/components/Project/ProjectCard.jsx +++ b/src/components/Project/ProjectCard.jsx @@ -14,34 +14,34 @@ import { getProjectStatusName, } from "../../utils/projectStatus"; import GlobalModel from "../common/GlobalModel"; - import { useDispatch } from "react-redux"; +import { useDispatch } from "react-redux"; import { setProjectId } from "../../slices/localVariablesSlice"; const ProjectCard = ({ projectData, recall }) => { - const [ projectInfo, setProjectInfo ] = useState( projectData ); - const { projects_Details, loading, error, refetch } = useProjectDetails( - projectInfo?.id,false + const [projectInfo, setProjectInfo] = useState(projectData); + const { projects_Details, loading, error, refetch } = useProjectDetails( + projectInfo?.id, false ); const [showModal, setShowModal] = useState(false); - const dispatch = useDispatch() + const dispatch = useDispatch() const navigate = useNavigate(); const ManageProject = useHasUserPermission(MANAGE_PROJECT); const { - mutate: updateProject, - isPending, - isSuccess, - isError, - } = useUpdateProject({ - onSuccessCallback: () => { - setShowModal(false); - }, - }) + mutate: updateProject, + isPending, + isSuccess, + isError, + } = useUpdateProject({ + onSuccessCallback: () => { + setShowModal(false); + }, + }) - useEffect(()=>{ + useEffect(() => { setProjectInfo(projectData); - }, [ projectData ] ) + }, [projectData]) - const handleShow = async () => { + const handleShow = async () => { try { const { data } = await refetch(); setShowModal(true); @@ -63,22 +63,26 @@ const ProjectCard = ({ projectData, recall }) => { dispatch(setProjectId(projectInfo.id)) navigate(`/projects/details`); }; + const handleViewActivities = () => { + dispatch(setProjectId(projectInfo.id)) + navigate(`/activities/records?project=${projectInfo.id}`); + }; const handleFormSubmit = (updatedProject) => { - if (projectInfo?.id) { - updateProject({ - projectId: projectInfo.id, - updatedData: updatedProject, - }); - } -}; + if (projectInfo?.id) { + updateProject({ + projectId: projectInfo.id, + updatedData: updatedProject, + }); + } + }; return ( <> - + {showModal && projects_Details && ( - {
+ > {projectInfo.shortName ? projectInfo.shortName : projectInfo.name} @@ -120,23 +124,23 @@ const ProjectCard = ({ projectData, recall }) => { data-bs-toggle="dropdown" aria-expanded="false" > - {loading ? ( -
- Loading... -
- ) : ( - - )} + {loading ? ( +
+ Loading... +
+ ) : ( + + )}
- {contactList.map((col) => ( + {orgList.map((col) => ( @@ -72,7 +82,7 @@ const ProjectAssignedOrgs = () => { {Array.isArray(data) && data.length > 0 ? ( data.map((row, i) => ( - {contactList.map((col) => ( + {orgList.map((col) => ( @@ -82,7 +92,7 @@ const ProjectAssignedOrgs = () => { ) : (
{col.label}
{col.getValue(row)}
Not Assigned yet diff --git a/src/components/Project/ProjectOrganizations.jsx b/src/components/Project/ProjectOrganizations.jsx index d18a9375..b5a91fa6 100644 --- a/src/components/Project/ProjectOrganizations.jsx +++ b/src/components/Project/ProjectOrganizations.jsx @@ -7,12 +7,12 @@ const ProjectOrganizations = () => { const { onOpen, startStep, flowType } = useOrganizationModal(); const selectedProject = useSelectedProject(); return ( -
+
+ +
+
+ + ); +}; + +export default ManageActivity; diff --git a/src/components/master/Services/ManageGroup.jsx b/src/components/master/Services/ManageGroup.jsx new file mode 100644 index 00000000..04342777 --- /dev/null +++ b/src/components/master/Services/ManageGroup.jsx @@ -0,0 +1,110 @@ +import { useForm } from "react-hook-form"; +import { + useCreateActivityGroup, + useUpdateActivityGroup, +} from "../../../hooks/masterHook/useMaster"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { ActivityGroupSchema } from "./ServicesSchema"; +import Label from "../../common/Label"; +import { useEffect } from "react"; + +const ManageGroup = ({ group = null, whichService = null, close }) => { + const { + register, + handleSubmit, + reset, + formState: { errors }, + } = useForm({ + resolver: zodResolver(ActivityGroupSchema), + defaultValues: { name: "", description: "" }, + }); + const { mutate: createGroup, isPending: isCreating } = useCreateActivityGroup( + () => close() + ); + const { mutate: UpdateGroup, isPending: isUpdating } = useUpdateActivityGroup( + () => close() + ); + + useEffect(() => { + if (group) { + reset({ + name: group.name || " ", + description: group.description || "", + }); + } + }, [group, reset]); + const onSubmit = (formdata) => { + if (group) { + let payload = { + ...formdata, + serviceId: whichService, + id: group.id, + }; + UpdateGroup({ id: group.id, payload: payload }); + } else { + let payload = { + ...formdata, + serviceId: whichService, + }; + + createGroup(payload); + } + }; + + let isPending = isCreating || isUpdating; + return ( +
+
+ + + {errors.name && ( +

{errors.name.message}

+ )} +
+
+ + + + {errors.description && ( +

{errors.description.message}

+ )} +
+ +
+ + +
+
+ ); +}; + +export default ManageGroup; diff --git a/src/components/master/Services/ServicesGroups.jsx b/src/components/master/Services/ServicesGroups.jsx new file mode 100644 index 00000000..b4262351 --- /dev/null +++ b/src/components/master/Services/ServicesGroups.jsx @@ -0,0 +1,263 @@ +import { useState } from "react"; +import { + useActivitiesByGroups, + useGroups, +} from "../../../hooks/masterHook/useMaster"; +import ManageGroup from "./ManageGroup"; +import ManageActivity from "./ManageActivity"; +import { useMasterContext } from "../../../pages/master/MasterPage"; +const ServiceGroups = ({ service }) => { + const [openService, setOpenService] = useState(true); + const [activeGroupId, setActiveGroupId] = useState(null); // track selected group + const {setDeleletingServiceItem} =useMasterContext() + const [isManageGroup, setManageGroup] = useState({ + isOpen: false, + group: null, + serviceId: null, + }); + const [isManageActivity, setManageActivity] = useState({ + isOpen: false, + activity: null, // activity is either a single activity for editing or null for creating new activity + groupId: null, // groupId for managing activities in specific groups + }); + + // Fetch groups and activities data + const { data: groups, isLoading } = useGroups(service?.id); // Fetch groups for the service + const { data: activities, isLoading: actLoading } = + useActivitiesByGroups(activeGroupId); // Fetch activities based on activeGroupId + + if (isLoading) return
Loading groups...
; // Show loading state while groups are being fetched + + // Handle toggling of group to view activities + const toggleGroup = (groupId) => { + setActiveGroupId((prev) => (prev === groupId ? null : groupId)); // If the same group is clicked again, close it + }; + + return ( + +
+ +

Manage Service

+
+
+ {/* Service Header */} +
+

{service.name}

+ +
+ + {/* Groups Section */} +
+ {/* Show ManageGroup for creating a new group */} + {isManageGroup.isOpen && isManageGroup.group === null ? ( + + setManageGroup({ + isOpen: false, + group: null, + serviceId: service.id, + }) + } + /> + ) : ( +
+
+ + {groups?.data?.map((group) => { + const isOpen = activeGroupId === group.id; + + return ( +
+
+ {/* Show group toggle button only if ManageGroup is not open */} +
+ {!isManageGroup.isOpen && ( + toggleGroup(group.id)} + className="text-end cursor-pointer" + data-bs-toggle="collapse" + data-bs-target={`#accordionGroup${group.id}`} + aria-expanded={isOpen} + aria-controls={`accordionGroup${group.id}`} + > + + + )} +

{group.name}

+
+
+
+ {/* Create New Activity */} + { + setManageActivity({ + isOpen: true, + activity: null, // Indicating new activity creation + groupId: group.id, // Set the groupId for the new activity + }); + }} + /> + {/* Edit Group */} + + setManageGroup({ + isOpen: true, + group: group, // Group selected for Editing + serviceId: service.id, + }) + } + /> + {/* Delete Group */} + setDeleletingServiceItem({isOpen:true,ItemId:group.id,whichItem:"group"})} /> +
+
+
+ + {/* Only show ManageGroup for the specific group if it's open */} + {isManageGroup.isOpen && + isManageGroup.group?.id === group.id ? ( + + setManageGroup({ + isOpen: false, + group: null, + serviceId: null, + }) + } + /> + ) : isManageActivity.isOpen && + isManageActivity.groupId === group.id ? ( + { + setManageActivity({ + isOpen: false, + activity: null, + groupId: null, + }); + }} + /> + ) : ( +
+
+ {isOpen && actLoading && ( +

+ Loading activities... +

+ )} + + {isOpen && activities?.data?.length > 0 ? ( +
+ {/* Header Row */} +
+ + Activity Name + + + Unit of Measurement + + + Action + +
+ + {/* Map through activities */} + {activities.data.map((activity) => ( +
+ {/* Activity Name Column */} +
+ {activity.activityName} +
+ + {/* Unit of Measurement Column */} +
+ {activity.unitOfMeasurement} +
+ + {/* Action Column */} +
+ {/* Edit Activity */} + { + setManageActivity({ + isOpen: true, + activity: activity, // Pass the specific activity for editing + groupId: group.id, // Set groupId for the specific activity + }); + }} + /> + {/* Delete Activity */} + setDeleletingServiceItem({isOpen:true,ItemId:activity.id,whichItem:"activity"})} + /> +
+
+ ))} +
+ ) : ( + isOpen && ( +

+ No activities found +

+ ) + )} +
+
+ )} +
+ ); + })} +
+ )} +
+
+
+
+ ); +}; + +export default ServiceGroups; diff --git a/src/components/master/Services/ServicesSchema.js b/src/components/master/Services/ServicesSchema.js index ceaa8bf5..72f28e50 100644 --- a/src/components/master/Services/ServicesSchema.js +++ b/src/components/master/Services/ServicesSchema.js @@ -6,4 +6,12 @@ const schema = z.object({ .string() .min(1, { message: "Description is required" }) .max(255, { message: "Description cannot exceed 255 characters" }), +}); + +export const ActivityGroupSchema = z.object({ + name: z.string().min(1, { message: "Group Name is required" }), + description: z + .string() + .min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), }); \ No newline at end of file diff --git a/src/hooks/masterHook/useMaster.js b/src/hooks/masterHook/useMaster.js index 6e589efe..5b31f79a 100644 --- a/src/hooks/masterHook/useMaster.js +++ b/src/hooks/masterHook/useMaster.js @@ -1,52 +1,77 @@ -import {useState,useEffect, useCallback} from "react" +import { useState, useEffect, useCallback } from "react"; import { MasterRespository } from "../../repositories/MastersRepository"; -import { cacheData,getCachedData } from "../../slices/apiDataManager"; +import { cacheData, getCachedData } from "../../slices/apiDataManager"; import { useSelector } from "react-redux"; -import {useMutation, useQueries, useQuery, useQueryClient} from "@tanstack/react-query"; +import { + useMutation, + useQueries, + useQuery, + useQueryClient, +} from "@tanstack/react-query"; import showToast from "../../services/toastService"; - - - - -export const useServices = ()=>{ +export const useServices = () => { return useQuery({ - queryKey:["services"], - queryFn:async()=> await MasterRespository.getMasterServices() - }) -} -export const useGlobalServices = ()=>{ - return useQuery({ - queryKey:["globalServices"], - queryFn:async()=> await MasterRespository.getGlobalServices() - }) -} + queryKey: ["services"], + queryFn: async () => await MasterRespository.getMasterServices(), + }); +}; -export const useMasterMenu = ()=>{ +export const useGroups = (serviceId) => { return useQuery({ - queryKey:["MasterMenu"], - queryFn:async()=> { + queryKey: ["groups", serviceId], + queryFn: async () => await MasterRespository.getActivityGrops(serviceId), + enabled: !!serviceId, + }); +}; +export const useActivitiesByGroups = (groupId) => { + return useQuery({ + queryKey: ["activties", groupId], + queryFn: async () => await MasterRespository.getActivitesByGroup(groupId), + + enabled: !!groupId, + + }); +}; +export const useGlobalServices = () => { + return useQuery({ + queryKey: ["globalServices"], + queryFn: async () => await MasterRespository.getGlobalServices(), + }); +}; + +export const useMasterMenu = () => { + return useQuery({ + queryKey: ["MasterMenu"], + queryFn: async () => { const resp = await MasterRespository.getMasterMenus(); - return resp.data - } - }) -} + return resp.data; + }, + }); +}; -export const useActivitiesMaster = () => -{ - const { data:activities=[],isLoading:loading,error} = useQuery( { - queryKey: [ "ActivityMaster" ], - queryFn: async() => - { +export const useActivitiesMaster = () => { + const { + data: activities = [], + isLoading: loading, + error, + } = useQuery({ + queryKey: ["ActivityMaster"], + queryFn: async () => { const response = await MasterRespository.getActivites(); - return response.data + return response.data; }, - onError: (error) => { - showToast(error?.response?.data?.message || error.message || "Failed to fetch ActivityMasters", "error"); + onError: (error) => { + showToast( + error?.response?.data?.message || + error.message || + "Failed to fetch ActivityMasters", + "error" + ); }, - } ) - return {activities,loading,error} -} + }); + return { activities, loading, error }; +}; export const useWorkCategoriesMaster = () => { const { data: categories = [], @@ -71,22 +96,28 @@ export const useWorkCategoriesMaster = () => { return { categories, categoryLoading, categoryError }; }; - -export const useContactCategory = () => -{ - const {data:contactCategory=[],isLoading:loading,error:Error } = useQuery( { - queryKey: [ "Contact Category" ], - queryFn: async () => - { +export const useContactCategory = () => { + const { + data: contactCategory = [], + isLoading: loading, + error: Error, + } = useQuery({ + queryKey: ["Contact Category"], + queryFn: async () => { let resp = await MasterRespository.getContactCategory(); - return resp.data + return resp.data; }, - onError: (error) => { - showToast(error?.response?.data?.message || error.message || "Failed to fetch Contact categories", "error"); + onError: (error) => { + showToast( + error?.response?.data?.message || + error.message || + "Failed to fetch Contact categories", + "error" + ); }, - } ) - return { contactCategory,loading,Error} -} + }); + return { contactCategory, loading, Error }; +}; export const useContactTags = () => { const { @@ -112,16 +143,15 @@ export const useContactTags = () => { return { contactTags, loading, error }; }; - -export const useExpenseType =()=>{ -const { +export const useExpenseType = () => { + const { data: ExpenseTypes = [], isLoading: loading, error, } = useQuery({ queryKey: ["Expense Type"], queryFn: async () => { - const res = await MasterRespository.getExpenseType() + const res = await MasterRespository.getExpenseType(); return res.data; }, onError: (error) => { @@ -135,16 +165,16 @@ const { }); return { ExpenseTypes, loading, error }; -} -export const usePaymentMode =()=>{ -const { +}; +export const usePaymentMode = () => { + const { data: PaymentModes = [], isLoading: loading, error, } = useQuery({ queryKey: ["Payment Mode"], queryFn: async () => { - const res = await MasterRespository.getPaymentMode() + const res = await MasterRespository.getPaymentMode(); return res.data; }, onError: (error) => { @@ -158,16 +188,16 @@ const { }); return { PaymentModes, loading, error }; -} -export const useExpenseStatus =()=>{ -const { +}; +export const useExpenseStatus = () => { + const { data: ExpenseStatus = [], isLoading: loading, error, } = useQuery({ queryKey: ["Expense Status"], queryFn: async () => { - const res = await MasterRespository.getExpenseStatus() + const res = await MasterRespository.getExpenseStatus(); return res.data; }, onError: (error) => { @@ -181,20 +211,20 @@ const { }); return { ExpenseStatus, loading, error }; -} -export const useDocumentTypes =(category)=>{ -const { +}; +export const useDocumentTypes = (category) => { + const { data: DocumentTypes = [], error, isError, - isLoading + isLoading, } = useQuery({ - queryKey: ["Document Type",category], + queryKey: ["Document Type", category], queryFn: async () => { - const res = await MasterRespository.getDocumentTypes(category) + const res = await MasterRespository.getDocumentTypes(category); return res.data; }, - enabled:!!category, + enabled: !!category, onError: (error) => { showToast( error?.response?.data?.message || @@ -206,20 +236,20 @@ const { }); return { DocumentTypes, isError, isLoading, error }; -} -export const useDocumentCategories =(EntityType)=>{ -const { +}; +export const useDocumentCategories = (EntityType) => { + const { data: DocumentCategories = [], error, isError, - isLoading + isLoading, } = useQuery({ - queryKey: ["Document Category",EntityType], + queryKey: ["Document Category", EntityType], queryFn: async () => { - const res = await MasterRespository.getDocumentCategories(EntityType) + const res = await MasterRespository.getDocumentCategories(EntityType); return res.data; }, - enabled:!!EntityType, + enabled: !!EntityType, onError: (error) => { showToast( error?.response?.data?.message || @@ -231,13 +261,13 @@ const { }); return { DocumentCategories, isError, isLoading, error }; -} -export const useOrganizationType =()=>{ +}; +export const useOrganizationType = () => { return useQuery({ - queryKey:["orgType"], - queryFn:async()=>await MasterRespository.getOrganizationType() - }) -} + queryKey: ["orgType"], + queryFn: async () => await MasterRespository.getOrganizationType(), + }); +}; // ===Application Masters Query================================================= const fetchMasterData = async (masterType) => { @@ -248,7 +278,7 @@ const fetchMasterData = async (masterType) => { return (await MasterRespository.getJobRole()).data; case "Activity": return (await MasterRespository.getActivites()).data; - case "Services": + case "Services": return (await MasterRespository.getService()).data; case "Work Category": return (await MasterRespository.getWorkCategory()).data; @@ -293,8 +323,13 @@ const fetchMasterData = async (masterType) => { }; const useMaster = () => { - const selectedMaster = useSelector((store) => store.localVariables.selectedMaster); - const queryFn = useCallback(() => fetchMasterData(selectedMaster), [selectedMaster]); + const selectedMaster = useSelector( + (store) => store.localVariables.selectedMaster + ); + const queryFn = useCallback( + () => fetchMasterData(selectedMaster), + [selectedMaster] + ); const { data = [], isLoading, @@ -303,11 +338,16 @@ const useMaster = () => { queryKey: ["masterData", selectedMaster], queryFn, enabled: !!selectedMaster, - staleTime: 1000 * 60 * 10, + staleTime: 1000 * 60 * 10, refetchOnWindowFocus: false, onError: (error) => { - showToast(error?.response?.data?.message || error.message || `Failed to fetch ${selectedMaster} Maseter`, "error"); - }, + showToast( + error?.response?.data?.message || + error.message || + `Failed to fetch ${selectedMaster} Maseter`, + "error" + ); + }, }); return { data, loading: isLoading, error }; @@ -353,7 +393,7 @@ export const useCreateJobRole = (onSuccessCallback) => { onSuccess: (data) => { showToast("JobRole added successfully.", "success"); - queryClient.invalidateQueries({queryKey:["masterData", "Job Role"]}); + queryClient.invalidateQueries({ queryKey: ["masterData", "Job Role"] }); if (onSuccessCallback) onSuccessCallback(data); }, @@ -365,350 +405,275 @@ export const useCreateJobRole = (onSuccessCallback) => { // Application Role------------------------------------------- -export const useCreateApplicationRole = (onSuccessCallback) => -{ +export const useCreateApplicationRole = (onSuccessCallback) => { const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { - const resp = await MasterRespository.createRole( payload ); + return useMutation({ + mutationFn: async (payload) => { + const resp = await MasterRespository.createRole(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Application Role" ]} ) - showToast( "Application Role added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Application Role"], + }); + showToast("Application Role added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; -export const useUpdateApplicationRole = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); +export const useUpdateApplicationRole = (onSuccessCallback) => { + const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {id, payload} ) => - { - const response = await MasterRespository.updateRoles(id,payload); + mutationFn: async ({ id, payload }) => { + const response = await MasterRespository.updateRoles(id, payload); return response.data; }, onSuccess: (data, variables) => { - queryClient.invalidateQueries({ queryKey: ["masterData", "Application Role"], }); showToast("Application Role updated successfully.", "success"); - + if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { showToast(error.message || "Something went wrong", "error"); }, }); -} +}; -// Activity------------------------------ -export const useCreateActivity = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); - - return useMutation( { - mutationFn: async ( payload ) => - { - const resp = await MasterRespository.createActivity(payload); - return resp.data; - }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Activity" ]} ) - showToast( "Activity added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) - }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} - -export const useUpdateActivity = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); - - return useMutation({ - mutationFn: async ( {id, payload} ) => - { - const response = await MasterRespository.updateActivity(id,payload); - return response.data; - }, - onSuccess: (data, variables) => { - - queryClient.invalidateQueries({ - queryKey: ["masterData", "Activity"], - }); - showToast("Activity updated successfully.", "success"); - - if (onSuccessCallback) onSuccessCallback(data); - }, - onError: (error) => { - showToast(error.message || "Something went wrong", "error"); - }, - }); -} //-----Create work Category------------------------------- -export const useCreateWorkCategory = (onSuccessCallback) => -{ +export const useCreateWorkCategory = (onSuccessCallback) => { const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createWorkCategory(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries({queryKey: [ "masterData", "Work Category" ]} ) - showToast( "Work Category added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Work Category"], + }); + showToast("Work Category added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; -export const useUpdateWorkCategory = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); +export const useUpdateWorkCategory = (onSuccessCallback) => { + const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {id, payload} ) => - { - const response = await MasterRespository.updateWorkCategory(id,payload); + mutationFn: async ({ id, payload }) => { + const response = await MasterRespository.updateWorkCategory(id, payload); return response.data; }, onSuccess: (data, variables) => { - queryClient.invalidateQueries({ queryKey: ["masterData", "Work Category"], }); showToast("Work Category updated successfully.", "success"); - + if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { showToast(error.message || "Something went wrong", "error"); }, }); -} +}; //-- Contact Category--------------------------- - -export const useCreateContactCategory = (onSuccessCallback) => -{ +export const useCreateContactCategory = (onSuccessCallback) => { const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createContactCategory(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Category" ]} ) - showToast( "Contact Category added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Contact Category"], + }); + showToast("Contact Category added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; - -export const useUpdateContactCategory = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); +export const useUpdateContactCategory = (onSuccessCallback) => { + const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {id, payload} ) => - { - const response = await MasterRespository.updateContactCategory(id,payload); + mutationFn: async ({ id, payload }) => { + const response = await MasterRespository.updateContactCategory( + id, + payload + ); return response.data; }, onSuccess: (data, variables) => { - queryClient.invalidateQueries({ queryKey: ["masterData", "Contact Category"], }); showToast("Contact Category updated successfully.", "success"); - + if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { showToast(error.message || "Something went wrong", "error"); }, }); -} +}; // ---------Contact Tag------------------- -export const useCreateContactTag = (onSuccessCallback) => -{ +export const useCreateContactTag = (onSuccessCallback) => { const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createContactTag(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Tag" ]} ) - showToast( "Contact Tag added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Contact Tag"], + }); + showToast("Contact Tag added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; - -export const useUpdateContactTag = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); +export const useUpdateContactTag = (onSuccessCallback) => { + const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {id, payload} ) => - { - debugger - const response = await MasterRespository.updateContactTag(id,payload); + mutationFn: async ({ id, payload }) => { + debugger; + const response = await MasterRespository.updateContactTag(id, payload); return response.data; }, onSuccess: (data, variables) => { - queryClient.invalidateQueries({ queryKey: ["masterData", "Contact Tag"], }); showToast("Contact Tag updated successfully.", "success"); - + if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { showToast(error.message || "Something went wrong", "error"); }, }); -} +}; // ----------------------Expense Type------------------ -export const useCreateExpenseType = (onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useCreateExpenseType = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createExpenseType(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Type" ]} ) - showToast( "Expense Type added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Expense Type"], + }); + showToast("Expense Type added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} -export const useUpdateExpenseType = (onSuccessCallback) => -{ - const queryClient = useQueryClient(); + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; +export const useUpdateExpenseType = (onSuccessCallback) => { + const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {id, payload} ) => - { - const response = await MasterRespository.updateExpenseType(id,payload); + mutationFn: async ({ id, payload }) => { + const response = await MasterRespository.updateExpenseType(id, payload); return response.data; }, onSuccess: (data, variables) => { - queryClient.invalidateQueries({ queryKey: ["masterData", "Expense Type"], }); showToast("Expense Type updated successfully.", "success"); - + if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { showToast(error.message || "Something went wrong", "error"); }, }); -} +}; // -----------------Payment Mode ------------- -export const useCreatePaymentMode = (onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useCreatePaymentMode = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createPaymentMode(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} ) - showToast( "Payment Mode added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Payment Mode"], + }); + showToast("Payment Mode added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; -export const useUpdatePaymentMode = (onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useUpdatePaymentMode = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( {id,payload} ) => - { - const resp = await MasterRespository.updatePaymentMode(id,payload); + return useMutation({ + mutationFn: async ({ id, payload }) => { + const resp = await MasterRespository.updatePaymentMode(id, payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} ) - showToast( "Payment Mode Updated successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Payment Mode"], + }); + showToast("Payment Mode Updated successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} - + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; // Services------------------------------- @@ -739,27 +704,26 @@ export const useCreateService = (onSuccessCallback) => { return useMutation({ mutationFn: async (payload) => { - debugger; + debugger; const resp = await MasterRespository.createService(payload); - debugger; + debugger; return resp.data; }, onSuccess: (data) => { - debugger; + debugger; queryClient.invalidateQueries({ queryKey: ["masterData", "Services"] }); showToast(data?.message || "Service added successfully", "success"); - if (onSuccessCallback) onSuccessCallback(data?.data); + if (onSuccessCallback) onSuccessCallback(data?.data); }, onError: (error) => { - debugger; - showToast(error.message || "Something went wrong", "error"); + debugger; + showToast( error?.response?.data?.message || error?.message || "Something went wrong", "error"); }, }); }; - export const useUpdateService = (onSuccessCallback) => { const queryClient = useQueryClient(); @@ -778,159 +742,244 @@ export const useUpdateService = (onSuccessCallback) => { if (onSuccessCallback) onSuccessCallback(data); }, onError: (error) => { - showToast(error?.message || "Something went wrong", "error"); + showToast(error?.response?.data?.message || error?.message || "Something went wrong", "error"); }, }); }; +export const useCreateActivityGroup = (onSuccessCallback) => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async (payload) => { + const response = await MasterRespository.createActivityGroup(payload); + return response; + }, + onSuccess: (data, variables) => { + queryClient.invalidateQueries({ + queryKey: ["groups"], + }); + debugger + showToast( data?.message || + data?.response?.data?.message || "Activity Group created successfully.", + "success" + ); + + if (onSuccessCallback) onSuccessCallback(data); + }, + onError: (error) => { + showToast(error?.response?.data?.message || error?.message || "Something went wrong", "error"); + }, + }); +}; +export const useUpdateActivityGroup = (onSuccessCallback) => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async ({id,payload}) => { + const response = await MasterRespository.updateActivityGrop(id,payload); + return response; + }, + onSuccess: (data, variables) => { + queryClient.invalidateQueries({ + queryKey: ["groups"], + }); + + showToast( + data?.message || + data?.response?.data?.message|| "Activity Group Updated successfully.", + "success" + ); + + if (onSuccessCallback) onSuccessCallback(data); + }, + onError: (error) => { + showToast(error?.message || "Something went wrong", "error"); + }, + }); +}; +// Activity------------------------------ +export const useCreateActivity = (onSuccessCallback) => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async (payload) => { + const resp = await MasterRespository.createActivity(payload); + return resp.data; + }, + onSuccess: (data) => { + queryClient.invalidateQueries({ queryKey: ["activties"] }); + showToast("Activity added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); + }, + onError: (error) => { + showToast(error?.response?.data?.message || error?.message || "Something went wrong", "error"); + }, + }); +}; + +export const useUpdateActivity = (onSuccessCallback) => { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async ({ id, payload }) => { + const response = await MasterRespository.updateActivity(id, payload); + return response.data; + }, + onSuccess: (data, variables) => { + queryClient.invalidateQueries({ + queryKey: ["activties"], + }); + showToast("Activity updated successfully.", "success"); + + if (onSuccessCallback) onSuccessCallback(data); + }, + onError: (error) => { + showToast(error?.response?.data?.message || error?.message || "Something went wrong", "error"); + }, + }); +}; // -------------------Expense Status---------------------------------- -export const useCreateExpenseStatus =(onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useCreateExpenseStatus = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createExpenseStatus(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Status" ]} ) - showToast( "Expense Status added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Expense Status"], + }); + showToast("Expense Status added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} -export const useUpdateExpenseStatus = (onSuccessCallback)=>{ - const queryClient = useQueryClient(); + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; +export const useUpdateExpenseStatus = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( {id,payload} ) => - { - const resp = await MasterRespository.updateExepnseStatus(id,payload); + return useMutation({ + mutationFn: async ({ id, payload }) => { + const resp = await MasterRespository.updateExepnseStatus(id, payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Status" ]} ) - showToast( "Expense Status Updated successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Expense Status"], + }); + showToast("Expense Status Updated successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} - - + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; // --------------------Document-Category-------------------------------- -export const useCreateDocumentCatgory =(onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useCreateDocumentCatgory = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createDocumenyCategory(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Document Category" ]} ) - queryClient.invalidateQueries( {queryKey:[ "Document Category" ]} ) - showToast( "Document Category added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Document Category"], + }); + queryClient.invalidateQueries({ queryKey: ["Document Category"] }); + showToast("Document Category added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; -export const useUpdateDocumentCategory =(onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useUpdateDocumentCategory = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( {id,payload} ) => - { - const resp = await MasterRespository.updateDocumentCategory(id,payload); + return useMutation({ + mutationFn: async ({ id, payload }) => { + const resp = await MasterRespository.updateDocumentCategory(id, payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Document Category" ]} ) - queryClient.invalidateQueries( {queryKey:[ "Document Category" ]} ) - showToast( "Document Category Updated successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Document Category"], + }); + queryClient.invalidateQueries({ queryKey: ["Document Category"] }); + showToast("Document Category Updated successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; // ------------------------------Document-Type----------------------------------- -export const useCreateDocumentType =(onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useCreateDocumentType = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( payload ) => - { + return useMutation({ + mutationFn: async (payload) => { const resp = await MasterRespository.createDocumentType(payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Document Type" ]} ) - showToast( "Document Type added successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Document Type"], + }); + showToast("Document Type added successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; -export const useUpdateDocumentType =(onSuccessCallback)=>{ - const queryClient = useQueryClient(); +export const useUpdateDocumentType = (onSuccessCallback) => { + const queryClient = useQueryClient(); - return useMutation( { - mutationFn: async ( {id,payload} ) => - { - const resp = await MasterRespository.updateDocumentType(id,payload); + return useMutation({ + mutationFn: async ({ id, payload }) => { + const resp = await MasterRespository.updateDocumentType(id, payload); return resp.data; }, - onSuccess: ( data ) => - { - queryClient.invalidateQueries( {queryKey:[ "masterData", "Document Type" ]} ) - showToast( "Document Type Updated successfully", "success" ); - if(onSuccessCallback) onSuccessCallback(data) + onSuccess: (data) => { + queryClient.invalidateQueries({ + queryKey: ["masterData", "Document Type"], + }); + showToast("Document Type Updated successfully", "success"); + if (onSuccessCallback) onSuccessCallback(data); }, - onError: ( error ) => - { - showToast(error.message || "Something went wrong", "error"); - } - }) -} + onError: (error) => { + showToast(error.message || "Something went wrong", "error"); + }, + }); +}; // -Delete Master -------- export const useDeleteMasterItem = () => { const queryClient = useQueryClient(); return useMutation({ - mutationFn: async ( {masterType, item} ) => - { + mutationFn: async ({ masterType, item }) => { const deleteFn = MasterRespository[masterType]; if (!deleteFn) { - throw new Error(`No delete strategy defined for master type: ${masterType}`); + throw new Error( + `No delete strategy defined for master type: ${masterType}` + ); } await deleteFn(item.id); @@ -945,8 +994,55 @@ export const useDeleteMasterItem = () => { onError: (error) => { const message = - error?.response?.data?.message || error?.message || "Error occurred during deletion"; + error?.response?.data?.message || + error?.message || + "Error occurred during deletion"; showToast(message, "error"); }, }); -}; \ No newline at end of file +}; + + +export const useDeleteServiceGroup =()=>{ + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async (id)=>await MasterRespository.deleteActivityGroup(id), + onSuccess: ({_,variable}) => { + + queryClient.invalidateQueries({ queryKey: ["groups"] }); + + showToast(`Group deleted successfully.`, "success"); + }, + + onError: (error) => { + const message = + error?.response?.data?.message || + error?.message || + "Error occurred during deletion"; + showToast(message, "error"); + }, + }); +} +export const useDeleteActivity =()=>{ + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: async (id)=>await MasterRespository.deleteActivity(id), + onSuccess: ({_,variable}) => { + + + queryClient.invalidateQueries({ queryKey: ["activties"] }); + + showToast(`Acivity deleted successfully.`, "success"); + }, + + onError: (error) => { + const message = + error?.response?.data?.message || + error?.message || + "Error occurred during deletion"; + showToast(message, "error"); + }, + }); +} diff --git a/src/pages/Activities/AttendancePage.jsx b/src/pages/Activities/AttendancePage.jsx index 142cab4b..4cd5956a 100644 --- a/src/pages/Activities/AttendancePage.jsx +++ b/src/pages/Activities/AttendancePage.jsx @@ -174,27 +174,25 @@ const AttendancePage = () => { {/* Search + Organization filter */}
{/* Organization Dropdown */} - {organizations?.length > 1 && ( - - )} + {/* Search Input */} { />
+
diff --git a/src/pages/Organization/OrganizationPage.jsx b/src/pages/Organization/OrganizationPage.jsx index e010a76d..25cdd36f 100644 --- a/src/pages/Organization/OrganizationPage.jsx +++ b/src/pages/Organization/OrganizationPage.jsx @@ -32,7 +32,7 @@ const OrganizationPage = () => {
- + ); }; diff --git a/src/pages/master/MasterTable.jsx b/src/pages/master/MasterTable.jsx index b2285842..8facfdb7 100644 --- a/src/pages/master/MasterTable.jsx +++ b/src/pages/master/MasterTable.jsx @@ -158,6 +158,21 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => { ) : ( <> + {selectedMaster === "Services" && ( + + )} +
{ + onClick={() => { dispatch(setProjectId(projectInfo.id)) navigate(`/projects/details`) }} @@ -168,7 +174,7 @@ const ProjectListView = ({ projectData, recall }) => { navigate(`/projects/details`)} + onClick={handleViewProject} > View details @@ -182,9 +188,7 @@ const ProjectListView = ({ projectData, recall }) => {
  • - navigate(`/activities/records?project=${projectInfo.id}`) - } + onClick={handleViewActivities} > diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index a69d3562..3e9fac8f 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -32,11 +32,11 @@ export const MasterRespository = { getActivites: () => api.get("api/master/activities"), createActivity: (data) => api.post("api/master/activity", data), -//Services + //Services getService: () => api.get("api/master/service/list"), createService: (data) => api.post("api/master/service/create", data), updateService: (id, data) => api.put(`api/master/service/edit/${id}`, data), - "Services": (id) => api.delete(`/api/master/service/delete/${id}`), + Services: (id) => api.delete(`/api/master/service/delete/${id}`), updateActivity: (id, data) => api.post(`api/master/activity/edit/${id}`, data), @@ -114,10 +114,20 @@ export const MasterRespository = { updateDocumentType: (id, data) => api.put(`/api/Master/document-type/edit/${id}`, data), + getGlobalServices: () => api.get("/api/Master/global-service/list"), + getMasterServices: () => api.get("/api/Master/service/list"), + getActivityGrops: (serviceId) => + api.get(`/api/Master/activity-group/list?serviceId=${serviceId}`), + createActivityGroup: (data) => + api.post(`/api/Master/activity-group/create`, data), + updateActivityGrop: (serviceId, data) => + api.put(`/api/Master/activity-group/edit/${serviceId}`, data), + getActivitesByGroup: (activityGroupId) => + api.get(`api/master/activities?activityGroupId=${activityGroupId}`), + deleteActivityGroup:(id)=>api.delete(`/api/Master/activity-group/delete/${id}`), - getGlobalServices:()=>api.get("/api/Master/global-service/list"), - getMasterServices:()=>api.get("/api/Master/service/list"), + deleteActivity:(id)=>api.delete(`/api/Master/activity/delete/${id}`), - getOrganizationType:()=>api.get('/api/Master/organization-type/list') + getOrganizationType: () => api.get("/api/Master/organization-type/list"), };