diff --git a/public/assets/img/orglogo.png b/public/assets/img/orglogo.png new file mode 100644 index 00000000..51ce9299 Binary files /dev/null and b/public/assets/img/orglogo.png differ diff --git a/src/components/Employee/DemoTable.jsx b/src/components/Employee/DemoTable.jsx deleted file mode 100644 index 1d645cc3..00000000 --- a/src/components/Employee/DemoTable.jsx +++ /dev/null @@ -1,172 +0,0 @@ -import React from "react"; - -const DemoTable = () => { - return ( -
-
-
-
- - - - - - - - - - - - - - -
idNameEmailDateSalaryStatusAction
-
-
-
-
-
- New Record -
- -
-
-
-
- -
- - - - -
-
-
- -
- - - - -
-
-
- -
- - - - -
-
- You can use letters, numbers & periods -
-
-
- -
- - - - -
-
-
- -
- - - - -
-
-
- - -
-
-
-
- -
- -
- -
-
- -
-
- ); -}; - -export default DemoTable; diff --git a/src/components/Employee/EmployeeList.jsx b/src/components/Employee/EmployeeList.jsx deleted file mode 100644 index 5a79c6ce..00000000 --- a/src/components/Employee/EmployeeList.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const EmployeeList = () => { - return
EmployeeList
; -}; - -export default EmployeeList; \ No newline at end of file diff --git a/src/components/Employee/EmployeeSchema.jsx b/src/components/Employee/EmployeeSchema.jsx new file mode 100644 index 00000000..ba540ef4 --- /dev/null +++ b/src/components/Employee/EmployeeSchema.jsx @@ -0,0 +1,124 @@ +import { z } from "zod" + + +const mobileNumberRegex = /^[0-9]\d{9}$/; + +export const employeeSchema = + z.object({ + firstName: z.string().min(1, { message: "First Name is required" }), + middleName: z.string().optional(), + lastName: z.string().min(1, { message: "Last Name is required" }), + email: z + .string() + .max(80, "Email cannot exceed 80 characters") + .optional() + .refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), { + message: "Invalid email format", + }) + .refine( + (val) => { + if (!val) return true; + const [local, domain] = val.split("@"); + return ( + val.length <= 320 && local?.length <= 64 && domain?.length <= 255 + ); + }, + { + message: "Email local or domain part is too long", + } + ), + currentAddress: z + .string() + .min(1, { message: "Current Address is required" }) + .max(500, { message: "Address cannot exceed 500 characters" }), + birthDate: z + .string() + .min(1, { message: "Birth Date is required" }) + .refine( + (date, ctx) => { + return new Date(date) <= new Date(); + }, + { + message: "Birth date cannot be in the future", + } + ), + joiningDate: z + .string() + .min(1, { message: "Joining Date is required" }) + .refine( + (date, ctx) => { + return new Date(date) <= new Date(); + }, + { + message: "Joining date cannot be in the future", + } + ), + emergencyPhoneNumber: z + .string() + .min(1, { message: "Phone Number is required" }) + .regex(mobileNumberRegex, { message: "Invalid phone number " }), + emergencyContactPerson: z + .string() + .min(1, { message: "Emergency Contact Person is required" }) + .regex(/^[A-Za-z\s]+$/, { + message: "Emergency Contact Person must contain only letters", + }), + aadharNumber: z + .string() + .optional() + .refine((val) => !val || /^\d{12}$/.test(val), { + message: "Aadhar card must be exactly 12 digits long", + }), + gender: z + .string() + .min(1, { message: "Gender is required" }) + .refine((val) => val !== "Select Gender", { + message: "Please select a gender", + }), + panNumber: z + .string() + .optional() + .refine((val) => !val || /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/.test(val), { + message: "Invalid PAN number", + }), + permanentAddress: z + .string() + .min(1, { message: "Permanent Address is required" }) + .max(500, { message: "Address cannot exceed 500 characters" }), + phoneNumber: z + .string() + .min(1, { message: "Phone Number is required" }) + .regex(mobileNumberRegex, { message: "Invalid phone number " }), + jobRoleId: z.string().min(1, { message: "Role is required" }), + organizationId:z.string().min(1,{message:"Organization is required"}), + hasApplicationAccess:z.boolean().default(false), + }).refine((data) => { + if (data.hasApplicationAccess) { + return data.email && data.email.trim() !== ""; + } + return true; +}, { + message: "Email is required when employee has access", + path: ["email"], +}); + + +export const defatEmployeeObj = { + firstName: "", + middleName: "", + lastName: "", + email: "", + currentAddress: "", + birthDate: "", + joiningDate: "", + emergencyPhoneNumber: "", + emergencyContactPerson: "", + aadharNumber: "", + gender: "", + panNumber: "", + permanentAddress: "", + phoneNumber: "", + jobRoleId: null, + organizationId:"", + hasApplicationAccess:false + } \ No newline at end of file diff --git a/src/components/Employee/ManageEmployee.jsx b/src/components/Employee/ManageEmployee.jsx index 81a4c4d2..f57ca994 100644 --- a/src/components/Employee/ManageEmployee.jsx +++ b/src/components/Employee/ManageEmployee.jsx @@ -1,36 +1,37 @@ import React, { useEffect, useState } from "react"; -import showToast from "../../services/toastService"; -import EmployeeRepository from "../../repositories/EmployeeRepository"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { z } from "zod"; + import useMaster from "../../hooks/masterHook/useMaster"; import { useDispatch } from "react-redux"; import { changeMaster } from "../../slices/localVariablesSlice"; import { Link, useNavigate, useParams } from "react-router-dom"; import { formatDate } from "../../utils/dateUtils"; -import { useEmployeeProfile, useUpdateEmployee } from "../../hooks/useEmployees"; import { - cacheData, - clearCacheKey, - getCachedData, -} from "../../slices/apiDataManager"; -import { clearApiCacheKey } from "../../slices/apiCacheSlice"; -import { useMutation } from "@tanstack/react-query"; + useEmployeeProfile, + useUpdateEmployee, +} from "../../hooks/useEmployees"; + import Label from "../common/Label"; import DatePicker from "../common/DatePicker"; - -const mobileNumberRegex = /^[0-9]\d{9}$/; +import { defatEmployeeObj, employeeSchema } from "./EmployeeSchema"; +import { useOrganizationsList } from "../../hooks/useOrganization"; +import { ITEMS_PER_PAGE } from "../../utils/constants"; const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { const dispatch = useDispatch(); const { mutate: updateEmployee, isPending } = useUpdateEmployee(); - + const { + data: organzationList, + isLoading, + isError, + error: EempError, + } = useOrganizationsList(ITEMS_PER_PAGE, 1, true); const { employee, error, loading: empLoading, - refetch + refetch, } = useEmployeeProfile(employeeId); useEffect(() => { @@ -38,6 +39,7 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { }, [employeeId]); const [disabledEmail, setDisabledEmail] = useState(false); + const { data: job_role, loading } = useMaster(); const [isloading, setLoading] = useState(false); const navigation = useNavigate(); @@ -45,98 +47,9 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { const [currentAddressLength, setCurrentAddressLength] = useState(0); const [permanentAddressLength, setPermanentAddressLength] = useState(0); - const userSchema = z.object({ - ...(employeeId ? { id: z.string().optional() } : {}), - firstName: z.string().min(1, { message: "First Name is required" }), - middleName: z.string().optional(), - lastName: z.string().min(1, { message: "Last Name is required" }), - email: z - .string() - .max(80, "Email cannot exceed 80 characters") - .optional() - .refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), { - message: "Invalid email format", - }) - .refine( - (val) => { - if (!val) return true; - const [local, domain] = val.split("@"); - return ( - val.length <= 320 && local?.length <= 64 && domain?.length <= 255 - ); - }, - { - message: "Email local or domain part is too long", - } - ), - currentAddress: z - .string() - .min(1, { message: "Current Address is required" }) - .max(500, { message: "Address cannot exceed 500 characters" }), - birthDate: z - .string() - .min(1, { message: "Birth Date is required" }) - .refine( - (date, ctx) => { - return new Date(date) <= new Date(); - }, - { - message: "Birth date cannot be in the future", - } - ), - joiningDate: z - .string() - .min(1, { message: "Joining Date is required" }) - .refine( - (date, ctx) => { - return new Date(date) <= new Date(); - }, - { - message: "Joining date cannot be in the future", - } - ), - emergencyPhoneNumber: z - .string() - .min(1, { message: "Phone Number is required" }) - .regex(mobileNumberRegex, { message: "Invalid phone number " }), - emergencyContactPerson: z - .string() - .min(1, { message: "Emergency Contact Person is required" }) - .regex(/^[A-Za-z\s]+$/, { - message: "Emergency Contact Person must contain only letters", - }), - aadharNumber: z - .string() - .optional() - .refine((val) => !val || /^\d{12}$/.test(val), { - message: "Aadhar card must be exactly 12 digits long", - }), - gender: z - .string() - .min(1, { message: "Gender is required" }) - .refine((val) => val !== "Select Gender", { - message: "Please select a gender", - }), - panNumber: z - .string() - .optional() - .refine((val) => !val || /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/.test(val), { - message: "Invalid PAN number", - }), - permanentAddress: z - .string() - .min(1, { message: "Permanent Address is required" }) - .max(500, { message: "Address cannot exceed 500 characters" }), - phoneNumber: z - .string() - .min(1, { message: "Phone Number is required" }) - .regex(mobileNumberRegex, { message: "Invalid phone number " }), - jobRoleId: z.string().min(1, { message: "Role is required" }), - }); - useEffect(() => { - refetch() - }, []) + refetch(); + }, []); const { register, @@ -147,25 +60,8 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { reset, getValues, } = useForm({ - resolver: zodResolver(userSchema), - defaultValues: { - id: currentEmployee?.id || null, - firstName: currentEmployee?.firstName || "", - middleName: currentEmployee?.middleName || "", - lastName: currentEmployee?.lastName || "", - email: currentEmployee?.email || "", - currentAddress: currentEmployee?.currentAddress || "", - birthDate: formatDate(currentEmployee?.birthDate) || "", - joiningDate: formatDate(currentEmployee?.joiningDate) || "", - emergencyPhoneNumber: currentEmployee?.emergencyPhoneNumber || "", - emergencyContactPerson: currentEmployee?.emergencyContactPerson || "", - aadharNumber: currentEmployee?.aadharNumber || "", - gender: currentEmployee?.gender || "", - panNumber: currentEmployee?.panNumber || "", - permanentAddress: currentEmployee?.permanentAddress || "", - phoneNumber: currentEmployee?.phoneNumber || "", - jobRoleId: currentEmployee?.jobRoleId.toString() || null, - }, + resolver: zodResolver(employeeSchema), + defaultValues: defatEmployeeObj, mode: "onChange", }); @@ -176,7 +72,13 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { data.email = null; } - updateEmployee({ ...data, IsAllEmployee }, { + const payload = { ...data, IsAllEmployee }; + + if (employeeId) { + payload.id = employeeId; + } + + updateEmployee(payload, { onSuccess: () => { reset(); onClosed(); @@ -184,7 +86,6 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { }); }; - useEffect(() => { if (!loading && !error && employee) { setCurrentEmployee(employee); @@ -195,37 +96,47 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { reset( currentEmployee ? { - id: currentEmployee.id || null, - firstName: currentEmployee.firstName || "", - middleName: currentEmployee.middleName || "", - lastName: currentEmployee.lastName || "", - email: currentEmployee.email || "", - currentAddress: currentEmployee.currentAddress || "", - birthDate: formatDate(currentEmployee.birthDate) || "", - joiningDate: formatDate(currentEmployee.joiningDate) || "", - emergencyPhoneNumber: currentEmployee.emergencyPhoneNumber || "", - emergencyContactPerson: - currentEmployee.emergencyContactPerson || "", - aadharNumber: currentEmployee.aadharNumber || "", - gender: currentEmployee.gender || "", - panNumber: currentEmployee.panNumber || "", - permanentAddress: currentEmployee.permanentAddress || "", - phoneNumber: currentEmployee.phoneNumber || "", - jobRoleId: currentEmployee.jobRoleId?.toString() || "", - } + id: currentEmployee.id || null, + firstName: currentEmployee.firstName || "", + middleName: currentEmployee.middleName || "", + lastName: currentEmployee.lastName || "", + email: currentEmployee.email || "", + currentAddress: currentEmployee.currentAddress || "", + birthDate: formatDate(currentEmployee.birthDate) || "", + joiningDate: formatDate(currentEmployee.joiningDate) || "", + emergencyPhoneNumber: currentEmployee.emergencyPhoneNumber || "", + emergencyContactPerson: + currentEmployee.emergencyContactPerson || "", + aadharNumber: currentEmployee.aadharNumber || "", + gender: currentEmployee.gender || "", + panNumber: currentEmployee.panNumber || "", + permanentAddress: currentEmployee.permanentAddress || "", + phoneNumber: currentEmployee.phoneNumber || "", + jobRoleId: currentEmployee.jobRoleId?.toString() || "", + organizationId: currentEmployee.organizationId || "", + hasApplicationAccess: currentEmployee.hasApplicationAccess || false, + } : {} ); setCurrentAddressLength(currentEmployee?.currentAddress?.length || 0); setPermanentAddressLength(currentEmployee?.permanentAddress?.length || 0); }, [currentEmployee, reset]); + const hasAccessAplication = watch("hasApplicationAccess"); return ( <>
-

{employee ? "Update Employee" : "Create Employee"}

+
+

+ {" "} + {employee ? "Update Employee" : "Create Employee"} +

{" "} +
- + { }} /> {errors.firstName && ( -
+
{errors.firstName.message}
)} @@ -267,14 +181,18 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => { }} /> {errors.middleName && ( -
+
{errors.middleName.message}
)}
-
- + { }} /> {errors.lastName && ( -
+
{errors.lastName.message}
)}
-
-
Email
+ { )}
- + {
- +
- - {" "} - {500 - currentAddressLength} characters left - + {500 - currentAddressLength} characters left
{errors.currentAddress && (
{ }} >
- - {500 - permanentAddressLength} characters left - + {500 - permanentAddressLength} characters left
{errors.permanentAddress && (
{ )}
+ + {/* -------------- */} +
+
+ +
+ +
+ {errors.organizationId && ( +
+ {errors.organizationId.message} +
+ )} +
+ +
+ +
+
+ + {/* --------------- */}
{" "}
@@ -488,7 +469,9 @@ const ManageEmployee = ({ employeeId, onClosed, IsAllEmployee }) => {
- +
-
-
- )} -
- -
- ); }; diff --git a/src/components/Organization/AssignOrg.jsx b/src/components/Organization/AssignOrg.jsx index e30a417c..d0886a62 100644 --- a/src/components/Organization/AssignOrg.jsx +++ b/src/components/Organization/AssignOrg.jsx @@ -93,8 +93,15 @@ const AssignOrg = ({ setStep }) => {
{/* Organization Info Display */}
-
-
{orgData.name}
+
+
+ logo

{orgData.name}

+
- +
Organization Info
{/* Contact Info */}
@@ -114,7 +121,7 @@ const AssignOrg = ({ setStep }) => { className="form-label me-2 mb-0 fw-semibold" style={{ minWidth: "130px" }} > - Contact Person : + Contact Person :
{orgData.contactPerson}
@@ -125,7 +132,7 @@ const AssignOrg = ({ setStep }) => { className="form-label me-2 mb-0 fw-semibold" style={{ minWidth: "130px" }} > - Contact Number : + Contact Number :
{orgData.contactNumber}
@@ -136,7 +143,7 @@ const AssignOrg = ({ setStep }) => { className="form-label me-2 mb-0 fw-semibold" style={{ minWidth: "130px" }} > - Email Address : + Email Address :
{orgData.email}
@@ -147,7 +154,8 @@ const AssignOrg = ({ setStep }) => { className="form-label me-2 mb-0 fw-semibold" style={{ maxWidth: "130px" }} > - Service provider Id (SPRID) : + + Service Provider Id (SPRID) :
{orgData.sprid}
@@ -158,7 +166,7 @@ const AssignOrg = ({ setStep }) => { className="form-label me-1 mb-0 fw-semibold" style={{ minWidth: "130px" }} > - Address : + Address :
{orgData.address}
@@ -233,11 +241,11 @@ const AssignOrg = ({ setStep }) => {
diff --git a/src/components/Organization/ManagOrg.jsx b/src/components/Organization/ManagOrg.jsx index 0f4aa49e..cd27ff9b 100644 --- a/src/components/Organization/ManagOrg.jsx +++ b/src/components/Organization/ManagOrg.jsx @@ -2,6 +2,7 @@ import React, { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { useCreateOrganization, + useOrganization, useOrganizationModal, useUpdateOrganization, } from "../../hooks/useOrganization"; @@ -18,6 +19,7 @@ const ManagOrg = () => { const { data: service, isLoading } = useGlobalServices(); const { flowType, orgData, startStep, onOpen, onClose, prevStep } = useOrganizationModal(); + const {data:organization,isLoading:organizationLoading,isError,error} = useOrganization(orgData?.id); const method = useForm({ resolver: zodResolver(organizationSchema), @@ -45,7 +47,7 @@ const ManagOrg = () => { onOpen({ startStep: 1 }); onClose(); }); - +console.log(organization) // Prefill form if editing useEffect(() => { if (orgData) { diff --git a/src/components/Organization/OrgPickerFromSPId.jsx b/src/components/Organization/OrgPickerFromSPId.jsx index 0a46778c..69774947 100644 --- a/src/components/Organization/OrgPickerFromSPId.jsx +++ b/src/components/Organization/OrgPickerFromSPId.jsx @@ -78,7 +78,7 @@ const OrgPickerFromSPId = ({ title, placeholder }) => {
logo { const { isOpen, orgData, startStep, onOpen, onClose, onToggle } = @@ -53,7 +54,7 @@ const OrganizationModal = () => { }; const RenderTitle = useMemo(() => { - if (orgData) { + if (orgData && startStep === 3 ) { return "Assign Organization"; } @@ -70,8 +71,11 @@ const OrganizationModal = () => { if (startStep === 3) { return "Assign Organization"; } + if(startStep === 5){ + return "Organization Details" + } - return "Manage Organization"; + return `${orgData ? "Update":"Create"} Organization`; }, [startStep, orgData]); const contentBody = ( @@ -94,6 +98,9 @@ const OrganizationModal = () => { {/* ---------- STEP 3: Add New Organization ---------- */} {startStep === 4 && } + + {/* ---------- STEP 3: View Organization ---------- */} + {startStep === 5 && }
); diff --git a/src/components/Organization/OrganizationSkeleton.jsx b/src/components/Organization/OrganizationSkeleton.jsx index bdb5feff..841815dc 100644 --- a/src/components/Organization/OrganizationSkeleton.jsx +++ b/src/components/Organization/OrganizationSkeleton.jsx @@ -42,3 +42,82 @@ export const OrgCardSkeleton = () => {
); }; + + +export const OrgDetailsSkeleton = () => { + return ( +
+ {/* Header */} +
+
+ {/* Logo + Name */} +
+ + +
+ + {/* Status Badge */} + +
+
+ + {/* Section Title */} +
+ +
+ + {/* Contact Person */} +
+
+ + +
+
+ + {/* Contact Number */} +
+
+ + +
+
+ + {/* Email */} +
+
+ + +
+
+ + {/* SPRID */} +
+
+ + +
+
+ + {/* Employees */} +
+
+ + +
+
+ + {/* Address */} +
+
+ + +
+
+ + {/* Section Title 2 */} +
+ +
+
+ ); +}; diff --git a/src/components/Organization/OrganizationsList.jsx b/src/components/Organization/OrganizationsList.jsx index b7ea28e5..6e170a2f 100644 --- a/src/components/Organization/OrganizationsList.jsx +++ b/src/components/Organization/OrganizationsList.jsx @@ -129,7 +129,7 @@ const OrganizationsList = ({searchText}) => { ))}
- + onOpen({startStep:5,orgData:org.id,flowType:"view"})}> onOpen({startStep:4,orgData:org,flowType:"edit"})}>
diff --git a/src/components/Organization/ViewOrganization.jsx b/src/components/Organization/ViewOrganization.jsx new file mode 100644 index 00000000..74c898b1 --- /dev/null +++ b/src/components/Organization/ViewOrganization.jsx @@ -0,0 +1,103 @@ +import React from "react"; +import { useOrganization } from "../../hooks/useOrganization"; +import { OrgDetailsSkeleton } from "./OrganizationSkeleton"; + +const VieworgDataanization = ({ orgId }) => { + const { data, isLoading, isError, error } = useOrganization(orgId); + if (isLoading) return ; + if (isError) return
{error.message}
; + return ( +
+ {/* Header */} +
+
+
+ logo

{data?.data?.name}

+
+
+ {data?.data.isActive ? "Active":"In-Active"} +
+
+
+
Organization Info
+ {/* Contact Info */} +
+
+ +
{data?.data?.contactPerson}
+
+
+
+
+ +
{data?.data?.contactNumber}
+
+
+
+
+ +
{data?.data?.email}
+
+
+
+
+ +
{data?.data?.sprid}
+
+
+ +
+
+ +
{data?.data?.activeEmployeeCount}
+
+
+
+
+ +
{data?.data?.address}
+
+
+
Projects And Services
+
+ ) +}; + +export default VieworgDataanization; diff --git a/src/components/common/DatePicker.jsx b/src/components/common/DatePicker.jsx index acb9007f..6b73dc36 100644 --- a/src/components/common/DatePicker.jsx +++ b/src/components/common/DatePicker.jsx @@ -1,14 +1,13 @@ import { useEffect, useRef } from "react"; import { useController } from "react-hook-form"; - const DatePicker = ({ name, control, placeholder = "DD-MM-YYYY", className = "", allowText = false, - maxDate, // removed default new Date() + maxDate, minDate, ...rest }) => { @@ -22,43 +21,43 @@ const DatePicker = ({ }); useEffect(() => { - if (inputRef.current) { - flatpickr(inputRef.current, { - dateFormat: "d-m-Y", - allowInput: allowText, - defaultDate: value - ? flatpickr.parseDate(value, "Y-m-d") - : null, - maxDate: maxDate ?? undefined, // only applied if passed - minDate: minDate ? new Date(minDate.split("T")[0]) : undefined, - onChange: function (selectedDates) { - if (selectedDates.length > 0) { - // store in YYYY-MM-DD - const formatted = flatpickr.formatDate(selectedDates[0], "Y-m-d"); - onChange(formatted); - } else { - onChange(""); - } - }, - ...rest - }); - } + if (!inputRef.current) return; + + const fp = flatpickr(inputRef.current, { + dateFormat: "d-m-Y", + allowInput: allowText, + defaultDate: value ? new Date(value) : null, // safely convert to Date + maxDate: maxDate ? new Date(maxDate) : undefined, + minDate: minDate ? new Date(minDate) : undefined, + onChange: (selectedDates) => { + if (selectedDates.length > 0) { + onChange(flatpickr.formatDate(selectedDates[0], "Y-m-d")); + } else { + onChange(""); + } + }, + ...rest + }); + + return () => { + fp.destroy(); // clean up on unmount + }; }, [inputRef, value, allowText, maxDate, minDate, rest, onChange]); + const displayValue = value ? flatpickr.formatDate(new Date(value), "d-m-Y") : ""; + return ( -
+
{ + if (allowText) { + onChange(e.target.value); // allow manual typing if enabled + } + }} ref={(el) => { inputRef.current = el; ref(el); @@ -70,7 +69,7 @@ const DatePicker = ({ { - if (inputRef.current && inputRef.current._flatpickr) { + if (inputRef.current?._flatpickr) { inputRef.current._flatpickr.open(); } }} diff --git a/src/hooks/useEmployees.js b/src/hooks/useEmployees.js index 58a12e5a..477b18f7 100644 --- a/src/hooks/useEmployees.js +++ b/src/hooks/useEmployees.js @@ -221,7 +221,7 @@ export const useUpdateEmployee = () => { mutationFn: (employeeData) => EmployeeRepository.manageEmployee(employeeData), onSuccess: (_, variables) => { - const id = variables.id || variables.employeeId; + const id = variables?.id || variables?.employeeId; const isAllEmployee = variables.IsAllEmployee; // Cache invalidation diff --git a/src/hooks/useOrganization.js b/src/hooks/useOrganization.js index d6c93693..2248f7bc 100644 --- a/src/hooks/useOrganization.js +++ b/src/hooks/useOrganization.js @@ -37,6 +37,13 @@ export const useOrganizationModal = () => { // ================================Query============================================================= +export const useOrganization=(id)=>{ +return useQuery({ + queryKey:["organization",id], + queryFn:async()=> await OrganizationRepository.getOrganizaion(id), + enabled:!!id +}) +} export const useOrganizationBySPRID = (sprid) => { return useQuery({ queryKey: ["organization by", sprid], @@ -167,11 +174,11 @@ export const useAssignOrgToTenant = (onSuccessCallback) => { export const useUpdateOrganization = () => { const useClient = useQueryClient(); return useMutation({ - mutationFn: async (payload) => - await OrganizationRepository.assignOrganizationToProject(payload), + mutationFn: async ({orgId,payload}) => + await OrganizationRepository.updateOrganizaion(orgId,payload), onSuccess: (_, variables) => { - // useClient.invalidateQueries({ queryKey: ["organizationList"] }); - showToast("Organization successfully", "success"); + useClient.invalidateQueries({ queryKey: ["organizationList"] }); + showToast("Organization Updated successfully", "success"); if (onSuccessCallback) onSuccessCallback(); }, onError: (error) => { diff --git a/src/pages/employee/EmployeeList.jsx b/src/pages/employee/EmployeeList.jsx index b0f10a75..fc77ba1c 100644 --- a/src/pages/employee/EmployeeList.jsx +++ b/src/pages/employee/EmployeeList.jsx @@ -751,7 +751,6 @@ const EmployeeList = () => {
) : ( - //
diff --git a/src/repositories/OrganizationRespository.jsx b/src/repositories/OrganizationRespository.jsx index 28bbf3ce..818cdb59 100644 --- a/src/repositories/OrganizationRespository.jsx +++ b/src/repositories/OrganizationRespository.jsx @@ -2,6 +2,8 @@ import { api } from "../utils/axiosClient"; const OrganizationRepository = { createOrganization: (data) => api.post("/api/Organization/create", data), + updateOrganizaion:(id,data)=>api.put(`/api/Organization/edit/${id}`), + getOrganizaion:(id)=>api.get(`/api/Organization/details/${id}`), getOrganizationList: (pageSize, pageNumber, active, sprid, searchString) => { return api.get( `/api/Organization/list?pageSize=${pageSize}&pageNumber=${pageNumber}&active=${active}&${