-
+
+
-
-
-
diff --git a/src/components/master/EditActivity.jsx b/src/components/master/EditActivity.jsx
index 61fcccf0..43816f4c 100644
--- a/src/components/master/EditActivity.jsx
+++ b/src/components/master/EditActivity.jsx
@@ -2,10 +2,11 @@ import React, { useEffect, useState } from "react";
import { useForm, useFieldArray } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
-import {MasterRespository} from "../../repositories/MastersRepository";
+import { MasterRespository } from "../../repositories/MastersRepository";
import showToast from "../../services/toastService";
-import {getCachedData,cacheData} from "../../slices/apiDataManager";
-import {useUpdateActivity} from "../../hooks/masterHook/useMaster";
+import { getCachedData, cacheData } from "../../slices/apiDataManager";
+import { useUpdateActivity } from "../../hooks/masterHook/useMaster";
+import Label from "../common/Label";
const schema = z.object({
@@ -26,88 +27,88 @@ const schema = z.object({
const UpdateActivity = ({ activityData, onClose }) => {
const { mutate: updateActivity, isPending: isLoading } = useUpdateActivity(() => onClose?.());
-const {
- register,
- handleSubmit,
- control,
- setValue,
- reset,
- setError,
- clearErrors,
- getValues,
- formState: { errors },
-} = useForm({
- resolver: zodResolver(schema),
- defaultValues: {
- id: activityData?.id,
- activityName: activityData?.activityName,
- unitOfMeasurement: activityData?.unitOfMeasurement,
- checkList: activityData?.checkLists || [],
- },
-});
+ const {
+ register,
+ handleSubmit,
+ control,
+ setValue,
+ reset,
+ setError,
+ clearErrors,
+ getValues,
+ formState: { errors },
+ } = useForm({
+ resolver: zodResolver(schema),
+ defaultValues: {
+ id: activityData?.id,
+ activityName: activityData?.activityName,
+ unitOfMeasurement: activityData?.unitOfMeasurement,
+ checkList: activityData?.checkLists || [],
+ },
+ });
-const { fields: checkListItems, append, remove } = useFieldArray({
- control,
- name: "checkList",
-});
+ const { fields: checkListItems, append, remove } = useFieldArray({
+ control,
+ name: "checkList",
+ });
-useEffect(() => {
- if (activityData) {
- reset({
- id: activityData.id,
- activityName: activityData.activityName,
- unitOfMeasurement: activityData.unitOfMeasurement,
- checkList: activityData.checkLists || [],
- });
- }
-}, [activityData, reset]);
+ useEffect(() => {
+ if (activityData) {
+ reset({
+ id: activityData.id,
+ activityName: activityData.activityName,
+ unitOfMeasurement: activityData.unitOfMeasurement,
+ checkList: activityData.checkLists || [],
+ });
+ }
+ }, [activityData, reset]);
-const addChecklistItem = () => {
- const values = getValues("checkList");
- const lastIndex = checkListItems.length - 1;
+ const addChecklistItem = () => {
+ 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 });
-};
-
-const removeChecklistItem = (index) => {
- remove(index);
-};
-
-const handleChecklistChange = (index, value) => {
- setValue(`checkList.${index}`, value);
-};
-
-const onSubmit = (formData) => {
- const payload = { ...formData, id: activityData.id };
- updateActivity({ id: activityData.id, payload });
+ clearErrors(`checkList.${lastIndex}.description`);
+ append({ id: null, description: "", isMandatory: false });
};
-// const onSubmit = async(data) => {
+
+ const removeChecklistItem = (index) => {
+ remove(index);
+ };
+
+ const handleChecklistChange = (index, value) => {
+ setValue(`checkList.${index}`, value);
+ };
+
+ const onSubmit = (formData) => {
+ const payload = { ...formData, id: activityData.id };
+ updateActivity({ id: activityData.id, payload });
+ };
+ // const onSubmit = async(data) => {
// setIsLoading(true);
-
+
// const Activity = {...data, id:activityData.id}
// try
// {
// const response = await MasterRespository.updateActivity( activityData?.id, Activity );
// const updatedActivity = response.data;
// const cachedData = getCachedData("Activity")
-
+
// if (cachedData) {
// const updatedActivities = cachedData.map((activity) =>
// activity.id === updatedActivity.id ? { ...activity, ...updatedActivity } : activity
// );
-
+
// cacheData( "Activity", updatedActivities );
// onClose()
// }
@@ -121,18 +122,18 @@ const onSubmit = (formData) => {
// }
// };
-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 (