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 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 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" && ( diff --git a/src/pages/Directory/DirectoryPageHeader.jsx b/src/pages/Directory/DirectoryPageHeader.jsx index 6662fd05..bb9ae418 100644 --- a/src/pages/Directory/DirectoryPageHeader.jsx +++ b/src/pages/Directory/DirectoryPageHeader.jsx @@ -233,3 +233,206 @@ const DirectoryPageHeader = ({ }; export default DirectoryPageHeader; + +import React from "react"; + +const DirectoryPageHeader = ({ + searchText, + setSearchText, + setIsActive, + listView, + setListView, + filteredBuckets, + tempSelectedBucketIds, + handleTempBucketChange, + filteredCategories, + tempSelectedCategoryIds, + handleTempCategoryChange, + clearFilter, + applyFilter, + loading, + IsActive, + setIsOpenModal, + setOpenBucketModal +}) => { + return ( + <> +
+ +
+
+
+ setSearchText(e.target.value)} + /> +
+ + +
+
+
+ + +
    +
    +

    + Filter by +

    + + {/* Bucket Filter */} +
    +

    Buckets

    +
    + {filteredBuckets.map(({ id, name }) => ( +
    + handleTempBucketChange(id)} + /> + +
    + ))} +
    +
    +
    + {/* Category Filter */} +
    +

    Categories

    +
    + {filteredCategories.map(({ id, name }) => ( +
    + handleTempCategoryChange(id)} + /> + +
    + ))} +
    +
    + +
    + + +
    +
    +
+
+
+
+
+ + +
+
+
+ +
+ + ); +}; + +export default DirectoryPageHeader; diff --git a/src/repositories/MastersRepository.jsx b/src/repositories/MastersRepository.jsx index 7a4ab1f0..4e94babb 100644 --- a/src/repositories/MastersRepository.jsx +++ b/src/repositories/MastersRepository.jsx @@ -41,7 +41,7 @@ export const MasterRespository = { "Activity": ( id ) => api.delete( `/api/master/activity/delete/${ 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` ), + "Contact Category": ( id ) => api.delete( `/api/master/contact-category/${id}` ), "Conatct Tag" :(id)=>api.delete("/api/master/contact-tag"), getWorkCategory:() => api.get(`/api/master/work-categories`), @@ -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 ),