@@ -279,6 +292,45 @@ const EditActivityModal = ({
)}
+
{/* Planned Work */}
{/* {ISselectedActivity && ( */}
diff --git a/src/components/Project/Infrastructure/TaskModel.jsx b/src/components/Project/Infrastructure/TaskModel.jsx
index 43cb1c5b..087a731e 100644
--- a/src/components/Project/Infrastructure/TaskModel.jsx
+++ b/src/components/Project/Infrastructure/TaskModel.jsx
@@ -2,23 +2,28 @@ import React, { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
-import {useActivitiesMaster} from "../../../hooks/masterHook/useMaster";
+import {
+ useActivitiesMaster,
+ useWorkCategoriesMaster,
+} from "../../../hooks/masterHook/useMaster";
const taskSchema = z.object({
buildingID: z.string().min(1, "Building is required"),
floorId: z.string().min(1, "Floor is required"),
workAreaId: z.string().min(1, "Work Area is required"),
activityID: z.string().min(1, "Activity is required"),
+ workCategoryId: z.string().min(1, "Work Category is required"),
plannedWork: z.number().min(1, "Planned Work must be greater than 0"),
completedWork: z.number().min(0, "Completed Work must be greater than 0"),
});
const defaultModel = {
id: null,
- buildingID:"0",
+ buildingID: "0",
floorId: "0",
workAreaId: "0",
activityID: null,
+ workCategoryId: "",
plannedWork: 0,
completedWork: 0,
};
@@ -30,15 +35,18 @@ const TaskModel = ({
onClearComplete,
onClose,
}) => {
-
const [formData, setFormData] = useState(defaultModel);
const [selectedBuilding, setSelectedBuilding] = useState(null);
const [selectedFloor, setSelectedFloor] = useState(null);
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
const [selectedActivity, setSelectedActivity] = useState(null);
+ const [selectedCategory, setSelectedCategory] = useState(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const [activityData, setActivityData] = useState([]);
- const {activities, loading, error} = useActivitiesMaster();
+ const [categoryData, setCategoryData] = useState([]);
+ const { activities, loading, error } = useActivitiesMaster();
+ const { categories, categoryLoading, categoryError } =
+ useWorkCategoriesMaster();
const {
register,
@@ -79,6 +87,7 @@ const TaskModel = ({
floorId: value,
workAreaId: 0,
activityID: 0,
+ workCategoryId: categoryData?.[0]?.id?.toString() ?? "",
}));
};
@@ -104,13 +113,24 @@ const TaskModel = ({
}));
};
- const onSubmitForm = async ( data ) =>
- {
+ const handleCategoryChange = (e) => {
+ const { value } = e.target;
+ const category = categoryData.find((b) => b.id === String(value));
+ setSelectedCategory(category);
+ reset((prev) => ({
+ ...prev,
+ workCategoryId: String(value),
+ }));
+ };
+
+ const onSubmitForm = async (data) => {
+ console.log(data);
setIsSubmitting(true);
await onSubmit(data);
setValue("plannedWork", 0);
- setValue( "completedWork", 0 );
- setValue("activityID",0)
+ setValue("completedWork", 0);
+ setValue("activityID", 0);
+ setValue("workCategoryId", categoryData?.[0]?.id?.toString() ?? "");
setIsSubmitting(false);
};
@@ -120,15 +140,32 @@ const TaskModel = ({
setSelectedFloor(null);
setSelectedWorkArea(null);
setSelectedActivity(null);
+ setSelectedCategory(categoryData?.[0]?.id?.toString() ?? "");
reset(defaultModel);
};
useEffect(() => {
if (!loading && Array.isArray(activities) && activities.length > 0) {
-
setActivityData(activities);
}
}, [activities, loading]);
+
+ useEffect(() => {
+ if (
+ !categoryLoading &&
+ Array.isArray(categories) &&
+ categories.length > 0
+ ) {
+ const newCategories = categories?.slice()?.sort((a, b) => {
+ const nameA = a?.name || "";
+ const nameB = b?.name || "";
+ return nameA.localeCompare(nameB);
+ });
+ setCategoryData(newCategories);
+ setSelectedCategory(newCategories[0])
+ }
+ }, [categories, categoryLoading]);
+
return (
@@ -247,9 +284,7 @@ const TaskModel = ({
{selectedWorkArea && (
-
+
{errors.activityID && (
@@ -287,7 +319,38 @@ const TaskModel = ({
)}
- {selectedActivity && (
+ {selectedWorkArea && (
+
+
+
+
+ {errors.workCategoryId && (
+
+ {errors.workCategoryId.message}
+
+ )}
+
+ )}
+
+ {selectedActivity && selectedCategory && (
)}
- {selectedActivity && (
+ {selectedActivity && selectedCategory && (