From 695369cbf872fbb54bbebb5be4b5028f6c166520 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 17:26:20 +0530 Subject: [PATCH 1/3] modified url endpoint --- src/repositories/MastersRepository.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index 7a4ab1f0..549736f8 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -50,7 +50,7 @@ export const MasterRespository = { getContactCategory: () => api.get( `/api/master/contact-categories` ), createContactCategory: (data ) => api.post( `/api/master/contact-category`, data ), - updateContactCategory: ( id, data ) => api.post( `/api/master/contact-category/${ id }`, data ), + updateContactCategory: ( id, data ) => api.post( `/api/master/contact-category/edit/${ id }`, data ), getContactTag: () => api.get( `/api/master/contact-tags` ), createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ), From 36b09747b01a01c78185ca38ecd37e685edf2aca Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 17:27:03 +0530 Subject: [PATCH 2/3] created new component for update contact category --- src/components/master/EditContactCategory.jsx | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/components/master/EditContactCategory.jsx diff --git a/src/components/master/EditContactCategory.jsx b/src/components/master/EditContactCategory.jsx new file mode 100644 index 00000000..331802d6 --- /dev/null +++ b/src/components/master/EditContactCategory.jsx @@ -0,0 +1,126 @@ +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: "Category name is required" }), + description: z.string().min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), +}); + +const EditContactCategory= ({data,onClose}) => { + + const[isLoading,setIsLoading] = useState(false) + const { + register, + handleSubmit, + formState: { errors },reset + + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: data?.name || "", + description:data?.description || "", + + }, + }); + + const onSubmit = (formdata) => { + setIsLoading(true) + const result = { + id:data?.id, + name: formdata?.name, + description: formdata.description, + }; + + + + MasterRespository.updateContactCategory(data?.id,result).then((resp)=>{ + setIsLoading(false) + showToast("Contact Category Updated successfully.", "success"); + const cachedData = getCachedData("Contact Category"); + if (cachedData) { + + const updatedData = cachedData.map((category) => + category.id === data?.id ? { ...category, ...resp.data } : category + ); + cacheData("Contact Category", updatedData); + } + + onClose() + }).catch((error)=>{ + showToast(error?.response?.data?.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 EditContactCategory; \ No newline at end of file From 1cdaefbec4b74e67331a06efff80f2ffd0a6aa7c Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 17:27:47 +0530 Subject: [PATCH 3/3] added EditcontactCatgorry component in modal for update --- src/components/master/MasterModal.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/master/MasterModal.jsx b/src/components/master/MasterModal.jsx index d7e32142..c65372da 100644 --- a/src/components/master/MasterModal.jsx +++ b/src/components/master/MasterModal.jsx @@ -15,6 +15,7 @@ import CreateWorkCategory from "./CreateWorkCategory"; import EditWorkCategory from "./EditWorkCategory"; import CreateCategory from "./CreateContactCategory"; import CreateContactTag from "./CreateContactTag"; +import EditContactCategory from "./EditContactCategory"; const MasterModal = ({ modaldata, closeModal }) => { @@ -131,6 +132,9 @@ const MasterModal = ({ modaldata, closeModal }) => { )} {modaldata.modalType === "Contact Category" && ( + )} + {modaldata.modalType === "Edit-Contact Category" && ( + )} {modaldata.modalType === "Contact Tag" && (