diff --git a/src/components/master/CreateActivity.jsx b/src/components/master/CreateActivity.jsx index 62cca207..d64bf361 100644 --- a/src/components/master/CreateActivity.jsx +++ b/src/components/master/CreateActivity.jsx @@ -10,11 +10,19 @@ import showToast from "../../services/toastService"; const schema = z.object({ activityName: z.string().min(1, { message: "Activity Name is required" }), - unitOfMeasurement: z.string().min(1, { message: "Unit of Measurement is required" }), + unitOfMeasurement: z + .string() + .min(1, { message: "Unit of Measurement is required" }), + serviceId: z.string().min(1, { message: "A service selection is required." }), + actitvityGroupId: z + .string() + .min(1, { message: "A activity group selection is required." }), checkList: z .array( z.object({ - description: z.string().min(1, { message: "descriptionlist item cannot be empty" }), + description: z + .string() + .min(1, { message: "description list item cannot be empty" }), isMandatory: z.boolean().default(false), id: z.any().default(null), }) @@ -24,6 +32,12 @@ const schema = z.object({ const CreateActivity = ({ onClose }) => { const [isLoading, setIsLoading] = useState(false); + const [services, setServices] = useState(getCachedData("Services")); + const [selectedService, setSelectedService] = useState(null); + const [activityGroups, setActivityGroups] = useState( + getCachedData("Activity Group") + ); + const [activityGroupList, setActivityGroupList] = useState(null); const { register, @@ -41,10 +55,11 @@ const CreateActivity = ({ onClose }) => { activityName: "", unitOfMeasurement: "", checkList: [], + serviceId: "", + actitvityGroupId: "", }, }); - const { fields: checkListItems, append, @@ -59,15 +74,21 @@ const CreateActivity = ({ onClose }) => { setIsLoading(true); MasterRespository.createActivity(data) - .then( ( resp ) => - { - + .then((resp) => { const cachedData = getCachedData("Activity"); - const updatedData = [ ...cachedData, resp?.data ]; + const updatedData = [...cachedData, resp?.data]; cacheData("Activity", updatedData); showToast("Activity Successfully Added.", "success"); setIsLoading(false); - handleClose() + reset({ + activityName: "", + unitOfMeasurement: "", + checkList: [], + serviceId: "", + actitvityGroupId: "", + }); + setSelectedService(null) + // handleClose(); }) .catch((error) => { showToast(error.message, "error"); @@ -75,7 +96,6 @@ const CreateActivity = ({ onClose }) => { }); }; - const addChecklistItem = () => { const values = getValues("checkList"); const lastIndex = checkListItems.length - 1; @@ -97,11 +117,33 @@ const CreateActivity = ({ onClose }) => { }); }; + const handleServicesChange = (e) => { + const { value } = e.target; + const service = services.find((b) => b.id === String(value)); + const selectedActivityGroups = activityGroups.filter( + (ag) => ag.serviceId == service.id + ); + setSelectedService(service.id); + setActivityGroupList(selectedActivityGroups); + reset((prev) => ({ + ...prev, + serviceId: String(value), + })); + }; + + const handleActivityGroupsChange = (e) => { + const { value } = e.target; + const service = services.find((b) => b.id === String(value)); + reset((prev) => ({ + ...prev, + actitvityGroupId: String(value), + })); + }; + const removeChecklistItem = (index) => { remove(index); }; - const handleChecklistChange = (index, value) => { setValue(`checkList.${index}`, value); }; @@ -111,132 +153,230 @@ const CreateActivity = ({ onClose }) => { onClose(); }; - - // for tooltip useEffect(() => { - const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')); + if (!services) { + MasterRespository.getServices().then((res) => { + setServices(res?.data); + cacheData("Services", res?.data); + }); + } + if (!activityGroups) { + MasterRespository.getActivityGroups().then((res) => { + setActivityGroups(res?.data); + cacheData("Activity Group", res?.data); + }); + } + const tooltipTriggerList = Array.from( + document.querySelectorAll('[data-bs-toggle="tooltip"]') + ); tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); }, []); return (
{/*
Create Activity
*/}
-
- - - {errors.activityName && ( -

{errors.activityName.message}

- )} -
- -
- - - {errors.unitOfMeasurement && ( -

{errors.unitOfMeasurement.message}

- )} -
- -
-

{checkListItems.length > 0 ? "Check List" : "Add Check List" }

- {checkListItems.length > 0 && ( - - - - - - - - - - {checkListItems.map((item, index) => ( - - - - - + {/* Services */} +
+ +
-
- Name - - Is Mandatory - Action
- - - handleChecklistChange(index, e.target.value) - } - /> - {errors.checkList?.[index]?.description && ( - - {errors.checkList[index]?.description?.message} - - )} - - - - -
+ + {services?.filter((service) => service?.name).length === 0 && ( + + )} + + {errors.serviceId && ( +

{errors.serviceId.message}

)} -
-
- - -
+ {selectedService && ( + <> + {/* Actitvity Name */} +
+ + + {errors.activityName && ( +

{errors.activityName.message}

+ )} +
+ {/* Unit of Mesurement */} +
+ + + {errors.unitOfMeasurement && ( +

+ {errors.unitOfMeasurement.message} +

+ )} +
+ + {/* Actitvity Group */} +
+ + + {errors.actitvityGroupId && ( +

{errors.actitvityGroupId.message}

+ )} +
+ +
+

+ {checkListItems.length > 0 ? "Check List" : "Add Check List"} +

+ {checkListItems.length > 0 && ( + + + + + + + + + + {checkListItems.map((item, index) => ( + + + + + + ))} + +
+ Name + + Is Mandatory + Action
+ + + handleChecklistChange(index, e.target.value) + } + /> + {errors.checkList?.[index]?.description && ( + + {errors.checkList[index]?.description?.message} + + )} + + + + +
+ )} + +
+ +
+ + +
+ + )}
); diff --git a/src/components/master/CreateActivityGroup.jsx b/src/components/master/CreateActivityGroup.jsx new file mode 100644 index 00000000..4f254e87 --- /dev/null +++ b/src/components/master/CreateActivityGroup.jsx @@ -0,0 +1,174 @@ +import React, { useEffect, useState } from "react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { MasterRespository } from "../../repositories/MastersRepository"; +import { clearApiCacheKey } from "../../slices/apiCacheSlice"; +import { getCachedData, cacheData } from "../../slices/apiDataManager"; +import showToast from "../../services/toastService"; + +const schema = z.object({ + name: z.string().min(1, { message: "Service Name is required" }), + description: z + .string() + .min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), + serviceId: z.string().min(1, { message: "A service selection is required." }), +}); + +const CreateActivityGroup = ({ onClose }) => { + const [isLoading, setIsLoading] = useState(false); + const [services, setServices] = useState(getCachedData("Services")); + + + const { + register, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: "", + description: "", + serviceId: "", + }, + }); + + const handleServicesChange = (e) => { + const { value } = e.target; + const service = services.find((b) => b.id === String(value)); + reset((prev) => ({ + ...prev, + serviceId: String(value), + })); + }; + + const onSubmit = (data) => { + setIsLoading(true); + const result = { + name: data.name, + description: data.description, + serviceId: data.serviceId, + }; + + MasterRespository.createActivityGroup(result) + .then((resp) => { + setIsLoading(false); + resetForm(); + const cachedData = getCachedData("Activity Group"); + const updatedData = [...cachedData, resp?.data]; + cacheData("Activity Group", updatedData); + showToast("Activity Group Added successfully.", "success"); + + onClose(); + }) + .catch((error) => { + showToast(error.message, "error"); + setIsLoading(false); + }); + }; + const resetForm = () => { + reset({ + name: "", + description: "", + serviceId: "", + }); + setDescriptionLength(0); + }; + + useEffect(() => { + if (!services) { + MasterRespository.getServices().then((res) => { + setServices(res?.data); + cacheData("Services", res?.data); + }); + } + return () => resetForm(); + }, []); + const [descriptionLength, setDescriptionLength] = useState(0); + const maxDescriptionLength = 255; + return ( + <> +
+ {/*
+ +
*/} +
+ + + {errors.name &&

{errors.name.message}

} +
+
+ + + {errors.serviceId && ( +

{errors.serviceId.message}

+ )} +
+
+ + +
+ {maxDescriptionLength - descriptionLength} characters left +
+ {errors.description && ( +

{errors.description.message}

+ )} +
+
+ + +
+
+ + ); +}; + +export default CreateActivityGroup; diff --git a/src/components/master/CreateServices.jsx b/src/components/master/CreateServices.jsx new file mode 100644 index 00000000..673d77f1 --- /dev/null +++ b/src/components/master/CreateServices.jsx @@ -0,0 +1,123 @@ +import React, { useEffect,useState } from 'react' +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { MasterRespository } from '../../repositories/MastersRepository'; +import { clearApiCacheKey } from '../../slices/apiCacheSlice'; +import { getCachedData,cacheData } from '../../slices/apiDataManager'; +import showToast from '../../services/toastService'; + + +const schema = z.object({ + name: z.string().min(1, { message: "Service Name is required" }), + description: z.string().min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), +}); + +const CreateServices = ({onClose}) => { + + const[isLoading,setIsLoading] = useState(false) + const { + register, + handleSubmit, + formState: { errors },reset + + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: "", + description: "", + + }, + }); + + const onSubmit = (data) => { + setIsLoading(true) + const result = { + name: data.name, + description: data.description, + }; + + MasterRespository.createService(result).then((resp)=>{ + setIsLoading(false) + resetForm() + const cachedData = getCachedData("Services"); + const updatedData = [...cachedData, resp?.data]; + cacheData("Services", updatedData); + showToast("Service Added successfully.", "success"); + + onClose() + }).catch((error)=>{ + showToast(error.message, "error"); + setIsLoading(false) + }) + + + }; + const resetForm = () => { + reset({ + name: "", + description: "" + }); + setDescriptionLength(0); + } + + useEffect(()=>{ + return ()=>resetForm() + },[]) + + const [descriptionLength, setDescriptionLength] = useState(0); + const maxDescriptionLength = 255; + return (<> +
+ {/*
+ +
*/} +
+ + + {errors.name &&

{errors.name.message}

} +
+
+ + +
+ {maxDescriptionLength - descriptionLength} characters left +
+ {errors.description && ( +

{errors.description.message}

+ )} +
+ +
+ + +
+ +
+ + + ) +} + +export default CreateServices; \ No newline at end of file diff --git a/src/components/master/EditActivity.jsx b/src/components/master/EditActivity.jsx index 503bf8c0..a601bf07 100644 --- a/src/components/master/EditActivity.jsx +++ b/src/components/master/EditActivity.jsx @@ -2,28 +2,38 @@ import React, { useEffect, useState } from "react"; import { useForm, useFieldArray } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; -import {MasterRespository} from "../../repositories/MastersRepository"; +import { MasterRespository } from "../../repositories/MastersRepository"; import showToast from "../../services/toastService"; -import {getCachedData,cacheData} from "../../slices/apiDataManager"; - +import { getCachedData, cacheData } from "../../slices/apiDataManager"; const schema = z.object({ activityName: z.string().min(1, { message: "Activity name is required" }), unitOfMeasurement: z.string().min(1, { message: "Measurement is required" }), + serviceId: z.string().min(1, { message: "A service selection is required." }), + actitvityGroupId: z + .string() + .min(1, { message: "A activity group selection is required." }), checkList: z .array( z.object({ id: z.any().default(null), - description: z.string().min(1, { message: "Checklist item cannot be empty" }), + description: z + .string() + .min(1, { message: "Checklist item cannot be empty" }), isMandatory: z.boolean().default(false), }) ) .optional(), }); - const UpdateActivity = ({ activityData, onClose }) => { const [isLoading, setIsLoading] = useState(false); + const [services, setServices] = useState(getCachedData("Services")); + const [selectedService, setSelectedService] = useState(null); + const [activityGroups, setActivityGroups] = useState( + getCachedData("Activity Group") + ); + const [activityGroupList, setActivityGroupList] = useState(null); const { register, @@ -35,26 +45,80 @@ const UpdateActivity = ({ activityData, onClose }) => { clearErrors, getValues, formState: { errors }, + watch, } = useForm({ resolver: zodResolver(schema), defaultValues: { - id:activityData.id, - activityName: activityData.activityName, - unitOfMeasurement: activityData.unitOfMeasurement, - checkLists: activityData.checkLists || [], + id: activityData.id, + serviceId: activityData.serviceId || "", + actitvityGroupId: activityData.actitvityGroupId || "", + activityName: activityData.activityName, + unitOfMeasurement: activityData.unitOfMeasurement, + checkLists: activityData.checkLists || [], }, }); - const { fields: checkListItems, append, remove } = useFieldArray({ + const selectedServiceId = watch("serviceId"); + const [selectedActitvityGroupId, setSelectedActitvityGroupId] = useState( + watch("actitvityGroupId") + ); + + const { + fields: checkListItems, + append, + remove, + } = useFieldArray({ control, name: "checkList", }); // Load initial data useEffect(() => { + if (!services) { + MasterRespository.getServices().then((res) => { + setServices(res?.data); + cacheData("Services", res?.data); + }); + } + if (!activityGroups) { + MasterRespository.getActivityGroups().then((res) => { + setActivityGroups(res?.data); + const selectedActivityGroups = res?.data.filter( + (item) => item.serviceId == selectedServiceId + ); + setActivityGroupList(selectedActivityGroups); + cacheData("Activity Group", res?.data); + const isExist = selectedActivityGroups.some( + (item) => item.id === String(watch("actitvityGroupId")) + ); + + if (!isExist) { + reset((prev) => ({ + ...prev, + actitvityGroupId: "", + })); + } + }); + } else { + const selectedActivityGroups = activityGroups.filter( + (item) => item.serviceId == selectedServiceId + ); + setActivityGroupList(selectedActivityGroups); + const isExist = selectedActivityGroups.some( + (item) => item.id === String(watch("actitvityGroupId")) + ); + if (!isExist) { + reset((prev) => ({ + ...prev, + actitvityGroupId: "", + })); + } + } if (activityData) { - reset( { - id:activityData.id, + reset({ + id: activityData.id, + serviceId: activityData.serviceId || "", + actitvityGroupId: activityData.actitvityGroupId || "", activityName: activityData.activityName, unitOfMeasurement: activityData.unitOfMeasurement, checkList: activityData.checkLists || [], @@ -62,42 +126,66 @@ const UpdateActivity = ({ activityData, onClose }) => { } }, [activityData]); - + const handleServicesChange = (e) => { + const { value } = e.target; + const service = services.find((b) => b.id === String(value)); + const selectedActivityGroups = activityGroups.filter( + (ag) => ag.serviceId == service.id + ); + setSelectedService(service.id); + setActivityGroupList(selectedActivityGroups); + reset((prev) => ({ + ...prev, + serviceId: String(value), + })); + }; + + const handleActivityGroupsChange = (e) => { + const { value } = e.target; + setValue("actitvityGroupId", String(value)); + // reset((prev) => ({ + // ...prev, + // actitvityGroupId: String(value), + // })); + setSelectedActitvityGroupId(String(value)); + }; + const handleChecklistChange = (index, value) => { setValue(`checkList.${index}`, value); }; // Submit handler - const onSubmit = async(data) => { + const onSubmit = async (data) => { setIsLoading(true); - - const Activity = {...data, id:activityData.id} - try - { - const response = await MasterRespository.updateActivity( activityData?.id, Activity ); + + const Activity = { ...data, id: activityData.id }; + try { + const response = await MasterRespository.updateActivity( + activityData?.id, + Activity + ); const updatedActivity = response.data; - const cachedData = getCachedData("Activity") - + const cachedData = getCachedData("Activity"); + if (cachedData) { const updatedActivities = cachedData.map((activity) => - activity.id === updatedActivity.id ? { ...activity, ...updatedActivity } : activity + activity.id === updatedActivity.id + ? { ...activity, ...updatedActivity } + : activity ); - - cacheData( "Activity", updatedActivities ); - onClose() + + cacheData("Activity", updatedActivities); + onClose(); } - setIsLoading( false ) + setIsLoading(false); showToast("Activity Successfully Updated", "success"); - } catch ( err ) - { - setIsLoading( false ) + } catch (err) { + setIsLoading(false); showToast("error.message", "error"); } }; - - // Add new checklist item const addChecklistItem = () => { const values = getValues("checkList"); @@ -122,12 +210,13 @@ const UpdateActivity = ({ activityData, onClose }) => { remove(index); }; - - // for tooltip - useEffect(() => { - const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')); - tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); - }, []); + // for tooltip + useEffect(() => { + const tooltipTriggerList = Array.from( + document.querySelectorAll('[data-bs-toggle="tooltip"]') + ); + tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); + }, []); return (
@@ -135,11 +224,13 @@ const UpdateActivity = ({ activityData, onClose }) => {
{/* Activity Name */}
- + {errors.activityName && (
{errors.activityName.message}
@@ -148,93 +239,188 @@ const UpdateActivity = ({ activityData, onClose }) => { {/* Unit of Measurement */}
- + {errors.unitOfMeasurement && ( -
{errors.unitOfMeasurement.message}
+
+ {errors.unitOfMeasurement.message} +
+ )} +
+ + {/* Services */} +
+ + {activityData.serviceId != null ? ( + + ) : ( + + )} + {errors.serviceId && ( +

{errors.serviceId.message}

+ )} +
+ + {/* Actitvity Group */} +
+ + + {errors.actitvityGroupId && ( +

{errors.actitvityGroupId.message}

)}
{/* Checklist */}
-

{checkListItems.length > 0 ? "Check List" : "Add Check List"}

+

+ {checkListItems.length > 0 ? "Check List" : "Add Check List"} +

{checkListItems.length > 0 && ( - - - - - - - - - - {checkListItems.map((item, index) => ( - - - - - - ))} - -
- Name - - Is Mandatory - Action
- - - handleChecklistChange(index, e.target.value) - } - /> - {errors.checkList?.[index]?.description && ( - - {errors.checkList[index]?.description?.message} - - )} - - - - -
+ + + + + + + + + + {checkListItems.map((item, index) => ( + + + + + + ))} + +
+ Name + + Is Mandatory + Action
+ + + handleChecklistChange(index, e.target.value) + } + /> + {errors.checkList?.[index]?.description && ( + + {errors.checkList[index]?.description?.message} + + )} + + + + +
)} -
diff --git a/src/components/master/EditActivityGroup.jsx b/src/components/master/EditActivityGroup.jsx new file mode 100644 index 00000000..8ff4bc10 --- /dev/null +++ b/src/components/master/EditActivityGroup.jsx @@ -0,0 +1,187 @@ +import React, { useEffect, useState } from "react"; +import { useForm, Controller } from "react-hook-form"; +import { set, z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { MasterRespository } from "../../repositories/MastersRepository"; +import { cacheData, getCachedData } from "../../slices/apiDataManager"; +import showToast from "../../services/toastService"; + +const schema = z.object({ + name: z.string().min(1, { message: "Service Name is required" }), + description: z + .string() + .min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), + serviceId: z.string().min(1, { message: "A service selection is required." }), +}); + +const EditActivityGroup = ({ data, onClose }) => { + const [isLoading, setIsLoading] = useState(false); + const [services, setServices] = useState(getCachedData("Services")); + const [formData, setFormData] = useState({ + name: data?.name || "", + description: data?.description || "", + serviceId: data.serviceId || "", + }); + const { + register, + handleSubmit, + formState: { errors }, + reset, + watch, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: data?.name || "", + description: data?.description || "", + serviceId: data.serviceId || "", + }, + }); + const selectedServiceId = watch("serviceId"); + const selectedName = watch("name"); + const selectedDescription = watch("description"); + + // const handleServicesChange = (e) => { + // const { value } = e.target; + // const service = services.find((b) => b.id === String(value)); + // reset((prev) => ({ + // ...prev, + // serviceId: String(value), + // })); + // }; + + const onSubmit = (formdata) => { + setIsLoading(true); + const result = { + id: data?.id, + name: formdata?.name, + description: formdata.description, + serviceId: formdata?.serviceId, + }; + + MasterRespository.updateActivityGroup(data?.id, result) + .then((resp) => { + setIsLoading(false); + showToast("Activity Group Update successfully.", "success"); + const cachedData = getCachedData("Activity Group"); + if (cachedData) { + const updatedData = cachedData.map((service) => + service.id === data?.id ? { ...service, ...resp.data } : service + ); + cacheData("Activity Group", updatedData); + } + + onClose(); + }) + .catch((error) => { + showToast(error.message, "error"); + setIsLoading(false); + }); + }; + + useEffect(() => { + if (!services) { + MasterRespository.getServices().then((res) => { + setServices(res?.data); + cacheData("Services", res?.data); + }); + } + reset({ + name: data?.name, + description: data?.description, + serviceId: data?.serviceId, + }); + setDescriptionLength(data?.description?.length || 0); + }, [data, reset]); + + const [descriptionLength, setDescriptionLength] = useState( + data?.description?.length || 0 + ); + const maxDescriptionLength = 255; + + return ( + <> + + {/*
+ +
*/} +
+ + + {errors.name &&

{errors.name.message}

} +
+
+ + + {errors.serviceId && ( +

{errors.serviceId.message}

+ )} +
+
+ + +
+ {maxDescriptionLength - descriptionLength} characters left +
+ {errors.description && ( +

{errors.description.message}

+ )} +
+ +
+ + +
+ + + ); +}; + +export default EditActivityGroup; diff --git a/src/components/master/EditServices.jsx b/src/components/master/EditServices.jsx new file mode 100644 index 00000000..8fbf4b65 --- /dev/null +++ b/src/components/master/EditServices.jsx @@ -0,0 +1,135 @@ +import React, { useEffect, useState } from "react"; +import { useForm, Controller } from "react-hook-form"; +import { set, z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { MasterRespository } from "../../repositories/MastersRepository"; +import { cacheData, getCachedData } from "../../slices/apiDataManager"; +import showToast from "../../services/toastService"; + +const schema = z.object({ + name: z.string().min(1, { message: "Service Name is required" }), + description: z + .string() + .min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), +}); + +const EditServices = ({ data, onClose }) => { + const [isLoading, setIsLoading] = useState(false); + const { + register, + handleSubmit, + formState: { errors }, + reset, + watch, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: data?.name || "", + description: data?.description || "", + }, + }); + + const selectedName = watch("name") + const selectedDescription = watch("description") + + const onSubmit = (formdata) => { + setIsLoading(true); + const result = { + id: data?.id, + name: formdata?.name, + description: formdata.description, + }; + + MasterRespository.updateService(data?.id, result) + .then((resp) => { + setIsLoading(false); + showToast("Service Update successfully.", "success"); + const cachedData = getCachedData("Services"); + if (cachedData) { + const updatedData = cachedData.map((service) => + service.id === data?.id ? { ...service, ...resp.data } : service + ); + cacheData("Services", updatedData); + } + + onClose(); + }) + .catch((error) => { + showToast(error.message, "error"); + setIsLoading(false); + }); + }; + + useEffect(() => { + reset({ + name: data?.name, + description: data?.description, + }); + setDescriptionLength(data?.description?.length || 0); + }, [data, reset]); + + const [descriptionLength, setDescriptionLength] = useState( + data?.description?.length || 0 + ); + const maxDescriptionLength = 255; + + return ( + <> +
+ {/*
+ +
*/} +
+ + + {errors.name &&

{errors.name.message}

} +
+
+ + +
+ {maxDescriptionLength - descriptionLength} characters left +
+ {errors.description && ( +

{errors.description.message}

+ )} +
+ +
+ + +
+
+ + ); +}; + +export default EditServices; diff --git a/src/components/master/MasterModal.jsx b/src/components/master/MasterModal.jsx index b3da6dd9..c65a75c0 100644 --- a/src/components/master/MasterModal.jsx +++ b/src/components/master/MasterModal.jsx @@ -17,6 +17,10 @@ import CreateCategory from "./CreateContactCategory"; import CreateContactTag from "./CreateContactTag"; import EditContactCategory from "./EditContactCategory"; import EditContactTag from "./EditContactTag"; +import CreateServices from "./CreateServices"; +import EditServices from "./EditServices"; +import CreateActivityGroup from "./CreateActivityGroup"; +import EditActivityGroup from "./EditActivityGroup"; const MasterModal = ({ modaldata, closeModal }) => { @@ -118,6 +122,18 @@ const MasterModal = ({ modaldata, closeModal }) => { {modaldata.modalType === "Edit-Job Role" && ( )} + {modaldata.modalType === "Services" && ( + + )} + {modaldata.modalType === "Edit-Services" && ( + + )} + {modaldata.modalType === "Activity Group" && ( + + )} + {modaldata.modalType === "Edit-Activity Group" && ( + + )} {modaldata.modalType === "Activity" && ( )} diff --git a/src/data/masters.js b/src/data/masters.js index e94de7a3..f635aa40 100644 --- a/src/data/masters.js +++ b/src/data/masters.js @@ -1,5 +1,5 @@ // 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: "Services"}, {id: 4, name: "Activity Group"}, {id: 5, name: "Activity"},{id: 6, name:"Work Category"},{id:7,name:"Contact Category"},{id:8,name:"Contact Tag"}] // ------------------- export const dailyTask = [ diff --git a/src/hooks/masterHook/useMaster.js b/src/hooks/masterHook/useMaster.js index a5c43a51..e79e8cf0 100644 --- a/src/hooks/masterHook/useMaster.js +++ b/src/hooks/masterHook/useMaster.js @@ -43,6 +43,14 @@ const useMaster = (isMa) => { response = await MasterRespository.getJobRole(); response = response.data break; + case "Services": + response = await MasterRespository.getServices(); + response = response.data + break; + case "Activity Group": + response = await MasterRespository.getActivityGroups(); + response = response.data + break; case "Activity": response = await MasterRespository.getActivites(); response = response.data diff --git a/src/pages/master/MasterTable.jsx b/src/pages/master/MasterTable.jsx index 0126b339..f199ea98 100644 --- a/src/pages/master/MasterTable.jsx +++ b/src/pages/master/MasterTable.jsx @@ -16,6 +16,11 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => { "tenantId", "checkLists", "isSystem", + "isActive", + "serviceId", + "servicesName", + "actitvityGroupId", + "activityGroupName" ]; const safeData = Array.isArray(data) ? data : []; diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index a2557574..5d818e09 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -30,15 +30,24 @@ export const MasterRespository = { getJobRole :()=>api.get("/api/roles/jobrole"), updateJobRole: ( id, data ) => api.put( `/api/roles/jobrole/${ id }`, data ), + getServices: () => api.get("api/master/services"), + createService: (data) => api.post("api/master/service", data), + updateService: (id, data) => api.put(`api/master/service/${id}`, data), + + getActivityGroups: () => api.get("api/master/activity-groups"), + createActivityGroup: (data) => api.post("api/master/activity-group", data), + updateActivityGroup: (id, data) => api.put(`api/master/activity-group/${id}`, data), getActivites: () => api.get( 'api/master/activities' ), createActivity: (data) => api.post( 'api/master/activity',data ), - updateActivity:(id,data) =>api.post(`api/master/activity/edit/${id}`,data), + updateActivity:(id,data) =>api.put(`api/master/activity/${id}`,data), getIndustries: () => api.get( 'api/master/industries' ), // delete "Job Role": ( id ) => api.delete( `/api/roles/jobrole/${ id }` ), - "Activity": ( id ) => api.delete( `/api/master/activity/delete/${ id }` ), + "Services": (id) => api.delete(`/api/master/service/${id}`), + "Activity Group": (id) => api.delete(`/api/master/activity-group/${id}`), + "Activity": ( id ) => api.delete( `/api/master/activity/${ id }` ), "Application Role":(id)=>api.delete(`/api/roles/${id}`), "Work Category": ( id ) => api.delete( `api/master/work-category/${ id }` ), "Contact Category": ( id ) => api.delete( `/api/master/contact-category` ),