Compare commits
No commits in common. "d8df89137038164edf6f3ca04f876ca998bbe84c" and "9a4c5df14f34d13b8e628420610fcf1ae4e84818" have entirely different histories.
d8df891370
...
9a4c5df14f
@ -1,114 +0,0 @@
|
|||||||
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: "Tag name is required" }),
|
|
||||||
description: z.string().min(1, { message: "Description is required" })
|
|
||||||
.max(255, { message: "Description cannot exceed 255 characters" }),
|
|
||||||
});
|
|
||||||
|
|
||||||
const CreateContactTag = ({onClose}) => {
|
|
||||||
|
|
||||||
const[isLoading,setIsLoading] = useState(false)
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors },reset
|
|
||||||
|
|
||||||
} = useForm({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: {
|
|
||||||
name: "",
|
|
||||||
description: "",
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
|
||||||
setIsLoading(true)
|
|
||||||
MasterRespository.createContactTag(data).then((resp)=>{
|
|
||||||
setIsLoading(false)
|
|
||||||
resetForm()
|
|
||||||
debugger
|
|
||||||
const cachedData = getCachedData("Contact Tag");
|
|
||||||
const updatedData = [...cachedData, resp?.data];
|
|
||||||
cacheData("Contact Tag", updatedData);
|
|
||||||
showToast("Contact Tag Added successfully.", "success");
|
|
||||||
console.log(getCachedData("Contact Tag"))
|
|
||||||
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 CreateContactTag;
|
|
||||||
@ -14,7 +14,6 @@ import showToast from "../../services/toastService";
|
|||||||
import CreateWorkCategory from "./CreateWorkCategory";
|
import CreateWorkCategory from "./CreateWorkCategory";
|
||||||
import EditWorkCategory from "./EditWorkCategory";
|
import EditWorkCategory from "./EditWorkCategory";
|
||||||
import CreateCategory from "./CreateContactCategory";
|
import CreateCategory from "./CreateContactCategory";
|
||||||
import CreateContactTag from "./CreateContactTag";
|
|
||||||
|
|
||||||
|
|
||||||
const MasterModal = ({ modaldata, closeModal }) => {
|
const MasterModal = ({ modaldata, closeModal }) => {
|
||||||
@ -132,9 +131,6 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
|||||||
{modaldata.modalType === "Contact Category" && (
|
{modaldata.modalType === "Contact Category" && (
|
||||||
<CreateCategory data={modaldata.item} onClose={closeModal} />
|
<CreateCategory data={modaldata.item} onClose={closeModal} />
|
||||||
)}
|
)}
|
||||||
{modaldata.modalType === "Contact Tag" && (
|
|
||||||
<CreateContactTag data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// it important ------
|
// 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: "Activity"},{id: 4, name:"Work Category"},{id:5,name:"Contact Category"}]
|
||||||
// -------------------
|
// -------------------
|
||||||
|
|
||||||
export const dailyTask = [
|
export const dailyTask = [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user