From 144817aef60043371436d2e4d9371386122b318e Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 16:00:23 +0530 Subject: [PATCH 1/3] added new component for Edit contact Tag --- src/components/master/EditContactTag.jsx | 126 +++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/components/master/EditContactTag.jsx diff --git a/src/components/master/EditContactTag.jsx b/src/components/master/EditContactTag.jsx new file mode 100644 index 00000000..1c0f71d1 --- /dev/null +++ b/src/components/master/EditContactTag.jsx @@ -0,0 +1,126 @@ +import React,{useState,useEffect} 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: "Tag name is required" }), + description: z.string().min(1, { message: "Description is required" }) + .max(255, { message: "Description cannot exceed 255 characters" }), +}); + +const EditContactTag= ({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.updateContactTag(data?.id,result).then((resp)=>{ + setIsLoading(false) + showToast("Contact Tag Updated successfully.", "success"); + const cachedData = getCachedData("Contact Tag"); + if (cachedData) { + + const updatedData = cachedData.map((category) => + category.id === data?.id ? { ...category, ...resp.data } : category + ); + cacheData("Contact Tag", 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 EditContactTag; \ No newline at end of file -- 2.43.0 From 3593e7d46caa561498aa3fcef97d98b782e7b8c5 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 16:02:16 +0530 Subject: [PATCH 2/3] added new modal for edit contact tag and delete contact tag --- src/components/master/MasterModal.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/master/MasterModal.jsx b/src/components/master/MasterModal.jsx index d7e32142..fc8209fe 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 EditContactTag from "./EditContactTag"; const MasterModal = ({ modaldata, closeModal }) => { @@ -23,7 +24,6 @@ const MasterModal = ({ modaldata, closeModal }) => { const handleSelectedMasterDeleted = async () => { const deleteFn = MasterRespository[modaldata.masterType]; - if (!deleteFn) { showToast(`No delete strategy defined for master type`,"error"); return false; @@ -135,6 +135,9 @@ const MasterModal = ({ modaldata, closeModal }) => { {modaldata.modalType === "Contact Tag" && ( )} + {modaldata.modalType === "Edit-Contact Tag" && ( + + )} -- 2.43.0 From 79e38f6cd502857cafbcb25f5c20accae1b18ef2 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sat, 24 May 2025 16:02:46 +0530 Subject: [PATCH 3/3] modified url for delete and update contact tag --- src/repositories/MastersRepository.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index 7a4ab1f0..30af194b 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -42,7 +42,7 @@ export const MasterRespository = { "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` ), - "Conatct Tag" :(id)=>api.delete("/api/master/contact-tag"), + "Contact Tag" :(id)=>api.delete(`/api/master/contact-tag/${id}`), getWorkCategory:() => api.get(`/api/master/work-categories`), createWorkCategory: (data) => api.post(`/api/master/work-category`,data), @@ -54,6 +54,6 @@ export const MasterRespository = { getContactTag: () => api.get( `/api/master/contact-tags` ), createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ), - updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/${ id }`, data ) + updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/edit/${ id }`, data ) } \ No newline at end of file -- 2.43.0