diff --git a/src/components/master/CreateActivity.jsx b/src/components/master/CreateActivity.jsx index bb366c9c..79f8ec3b 100644 --- a/src/components/master/CreateActivity.jsx +++ b/src/components/master/CreateActivity.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect,useCallback } from "react"; +import React, { useState, useEffect, useCallback } from "react"; import { useFieldArray, useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -7,7 +7,7 @@ import { MasterRespository } from "../../repositories/MastersRepository"; import { clearApiCacheKey } from "../../slices/apiCacheSlice"; import { getCachedData, cacheData } from "../../slices/apiDataManager"; import showToast from "../../services/toastService"; -import {useCreateActivity} from "../../hooks/masterHook/useMaster"; +import { useCreateActivity } from "../../hooks/masterHook/useMaster"; const schema = z.object({ activityName: z.string().min(1, { message: "Activity Name is required" }), @@ -24,74 +24,74 @@ const schema = z.object({ }); const CreateActivity = ({ onClose }) => { -const maxDescriptionLength = 255; -const { mutate: createActivity, isPending: isLoading } = useCreateActivity(() => onClose?.()); + const maxDescriptionLength = 255; + const { mutate: createActivity, isPending: isLoading } = useCreateActivity(() => onClose?.()); -const { - register, - handleSubmit, - control, - setValue, - clearErrors, - setError, - getValues, - reset, - formState: { errors }, -} = useForm({ - resolver: zodResolver(schema), - defaultValues: { - activityName: "", - unitOfMeasurement: "", - checkList: [], - }, -}); + const { + register, + handleSubmit, + control, + setValue, + clearErrors, + setError, + getValues, + reset, + formState: { errors }, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + activityName: "", + unitOfMeasurement: "", + checkList: [], + }, + }); -const { - fields: checkListItems, - append, - remove, -} = useFieldArray({ - control, - name: "checkList", -}); + const { + fields: checkListItems, + append, + remove, + } = useFieldArray({ + control, + name: "checkList", + }); -const addChecklistItem = useCallback(() => { - const values = getValues("checkList"); - const lastIndex = checkListItems.length - 1; + const addChecklistItem = useCallback(() => { + const values = getValues("checkList"); + const lastIndex = checkListItems.length - 1; - if ( - checkListItems.length > 0 && - (!values?.[lastIndex] || values[lastIndex].description.trim() === "") - ) { - setError(`checkList.${lastIndex}.description`, { - type: "manual", - message: "Please fill this checklist item before adding another.", - }); - return; - } + if ( + checkListItems.length > 0 && + (!values?.[lastIndex] || values[lastIndex].description.trim() === "") + ) { + setError(`checkList.${lastIndex}.description`, { + type: "manual", + message: "Please fill this checklist item before adding another.", + }); + return; + } - clearErrors(`checkList.${lastIndex}.description`); - append({ id: null, description: "", isMandatory: false }); -}, [checkListItems, getValues, append, setError, clearErrors]); + clearErrors(`checkList.${lastIndex}.description`); + append({ id: null, description: "", isMandatory: false }); + }, [checkListItems, getValues, append, setError, clearErrors]); -const removeChecklistItem = useCallback((index) => { - remove(index); -}, [remove]); + const removeChecklistItem = useCallback((index) => { + remove(index); + }, [remove]); -const handleChecklistChange = useCallback((index, value) => { - setValue(`checkList.${index}`, value); -}, [setValue]); + const handleChecklistChange = useCallback((index, value) => { + setValue(`checkList.${index}`, value); + }, [setValue]); -const onSubmit = (formData) => { - createActivity(formData); -}; + const onSubmit = (formData) => { + createActivity(formData); + }; // const onSubmit = (data) => { // setIsLoading(true); // MasterRespository.createActivity(data) // .then( ( resp ) => // { - + // const cachedData = getCachedData("Activity"); // const updatedData = [ ...cachedData, resp?.data ]; // cacheData("Activity", updatedData); @@ -104,15 +104,15 @@ const onSubmit = (formData) => { // setIsLoading(false); // }); // }; -const handleClose = useCallback(() => { - reset(); - onClose(); -}, [reset, onClose]); + const handleClose = useCallback(() => { + reset(); + onClose(); + }, [reset, onClose]); -useEffect(() => { - const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')); - tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); -}, []); + useEffect(() => { + const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')); + tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); + }, []); return (
diff --git a/src/components/master/CreateContactCategory.jsx b/src/components/master/CreateContactCategory.jsx index e5923c91..14707a76 100644 --- a/src/components/master/CreateContactCategory.jsx +++ b/src/components/master/CreateContactCategory.jsx @@ -1,43 +1,43 @@ -import React, { useEffect,useState } from 'react' +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 { getCachedData, cacheData } from '../../slices/apiDataManager'; import showToast from '../../services/toastService'; -import {useCreateContactCategory} from '../../hooks/masterHook/useMaster'; +import { useCreateContactCategory } from '../../hooks/masterHook/useMaster'; 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" }), + .max(255, { message: "Description cannot exceed 255 characters" }), }); -const CreateContactCategory = ({onClose}) => { +const CreateContactCategory = ({ onClose }) => { -const { - register, - handleSubmit, - formState: { errors }, - reset, -} = useForm({ - resolver: zodResolver(schema), - defaultValues: { - name: "", - description: "", - }, -}); + const { + register, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + name: "", + description: "", + }, + }); -const [descriptionLength, setDescriptionLength] = useState(0); -const maxDescriptionLength = 255; + const [descriptionLength, setDescriptionLength] = useState(0); + const maxDescriptionLength = 255; -const { mutate: createContactCategory, isPending: isLoading } = useCreateContactCategory(() => onClose?.()); + const { mutate: createContactCategory, isPending: isLoading } = useCreateContactCategory(() => onClose?.()); -const onSubmit = (payload) => { - createContactCategory(payload); -}; + const onSubmit = (payload) => { + createContactCategory(payload); + }; // const onSubmit = (data) => { // setIsLoading(true) // MasterRespository.createContactCategory(data).then((resp)=>{ @@ -54,27 +54,27 @@ const onSubmit = (payload) => { // setIsLoading(false) // }) // }; -const resetForm = () => { - reset({ name: "", description: "" }); - setDescriptionLength(0); -}; + const resetForm = () => { + reset({ name: "", description: "" }); + setDescriptionLength(0); + }; + + useEffect(() => { + return () => resetForm(); + }, []); -useEffect(() => { - return () => resetForm(); -}, []); - return (<> -