Compare commits
No commits in common. "79e38f6cd502857cafbcb25f5c20accae1b18ef2" and "889b5ab06936ff669ec2952fc30bf35f675a1f46" have entirely different histories.
79e38f6cd5
...
889b5ab069
@ -1,126 +0,0 @@
|
|||||||
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 (<>
|
|
||||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
|
||||||
<div className="col-12 col-md-12">
|
|
||||||
<label className="form-label">Tag Name</label>
|
|
||||||
<input type="text"
|
|
||||||
{...register("name")}
|
|
||||||
className={`form-control ${errors.name ? 'is-invalids' : ''}`}
|
|
||||||
/>
|
|
||||||
{errors.name && <p className="text-danger">{errors.name.message}</p>}
|
|
||||||
</div>
|
|
||||||
<div className="col-12 col-md-12">
|
|
||||||
<label className="form-label" htmlFor="description">Description</label>
|
|
||||||
<textarea
|
|
||||||
rows="3"
|
|
||||||
{...register("description")}
|
|
||||||
className={`form-control ${errors.description ? 'is-invalids' : ''}`}
|
|
||||||
onChange={(e) => {
|
|
||||||
setDescriptionLength(e.target.value.length);
|
|
||||||
register("description").onChange(e);
|
|
||||||
}}
|
|
||||||
></textarea>
|
|
||||||
<div className="text-end small text-muted">
|
|
||||||
{maxDescriptionLength - descriptionLength} characters left
|
|
||||||
</div>
|
|
||||||
{errors.description && (
|
|
||||||
<p className="text-danger">{errors.description.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="col-12 text-center">
|
|
||||||
<button type="submit" className="btn btn-sm btn-primary me-3">
|
|
||||||
{isLoading? "Please Wait...":"Submit"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="reset"
|
|
||||||
className="btn btn-sm btn-label-secondary "
|
|
||||||
data-bs-dismiss="modal"
|
|
||||||
aria-label="Close"
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EditContactTag;
|
|
||||||
@ -15,7 +15,6 @@ import CreateWorkCategory from "./CreateWorkCategory";
|
|||||||
import EditWorkCategory from "./EditWorkCategory";
|
import EditWorkCategory from "./EditWorkCategory";
|
||||||
import CreateCategory from "./CreateContactCategory";
|
import CreateCategory from "./CreateContactCategory";
|
||||||
import CreateContactTag from "./CreateContactTag";
|
import CreateContactTag from "./CreateContactTag";
|
||||||
import EditContactTag from "./EditContactTag";
|
|
||||||
|
|
||||||
|
|
||||||
const MasterModal = ({ modaldata, closeModal }) => {
|
const MasterModal = ({ modaldata, closeModal }) => {
|
||||||
@ -24,6 +23,7 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
|||||||
const handleSelectedMasterDeleted = async () =>
|
const handleSelectedMasterDeleted = async () =>
|
||||||
{
|
{
|
||||||
const deleteFn = MasterRespository[modaldata.masterType];
|
const deleteFn = MasterRespository[modaldata.masterType];
|
||||||
|
|
||||||
if (!deleteFn) {
|
if (!deleteFn) {
|
||||||
showToast(`No delete strategy defined for master type`,"error");
|
showToast(`No delete strategy defined for master type`,"error");
|
||||||
return false;
|
return false;
|
||||||
@ -135,9 +135,6 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
|||||||
{modaldata.modalType === "Contact Tag" && (
|
{modaldata.modalType === "Contact Tag" && (
|
||||||
<CreateContactTag data={modaldata.item} onClose={closeModal} />
|
<CreateContactTag data={modaldata.item} onClose={closeModal} />
|
||||||
)}
|
)}
|
||||||
{modaldata.modalType === "Edit-Contact Tag" && (
|
|
||||||
<EditContactTag data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export const MasterRespository = {
|
|||||||
"Application Role":(id)=>api.delete(`/api/roles/${id}`),
|
"Application Role":(id)=>api.delete(`/api/roles/${id}`),
|
||||||
"Work Category": ( id ) => api.delete( `api/master/work-category/${ 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` ),
|
||||||
"Contact Tag" :(id)=>api.delete(`/api/master/contact-tag/${id}`),
|
"Conatct Tag" :(id)=>api.delete("/api/master/contact-tag"),
|
||||||
|
|
||||||
getWorkCategory:() => api.get(`/api/master/work-categories`),
|
getWorkCategory:() => api.get(`/api/master/work-categories`),
|
||||||
createWorkCategory: (data) => api.post(`/api/master/work-category`,data),
|
createWorkCategory: (data) => api.post(`/api/master/work-category`,data),
|
||||||
@ -54,6 +54,6 @@ export const MasterRespository = {
|
|||||||
|
|
||||||
getContactTag: () => api.get( `/api/master/contact-tags` ),
|
getContactTag: () => api.get( `/api/master/contact-tags` ),
|
||||||
createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ),
|
createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ),
|
||||||
updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/edit/${ id }`, data )
|
updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/${ id }`, data )
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user