Added Activity Group, and implemented sorting for Service, Activity Group, and Activities.
This commit is contained in:
parent
e69efe61cb
commit
ae9c4833b3
@ -3,7 +3,9 @@ import { useForm } from "react-hook-form";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import {
|
import {
|
||||||
|
useActivitiesByGroups,
|
||||||
useActivitiesMaster,
|
useActivitiesMaster,
|
||||||
|
useGroups,
|
||||||
useWorkCategoriesMaster,
|
useWorkCategoriesMaster,
|
||||||
} from "../../../hooks/masterHook/useMaster";
|
} from "../../../hooks/masterHook/useMaster";
|
||||||
import { useManageTask, useProjectAssignedOrganizations, useProjectAssignedServices } from "../../../hooks/useProjects";
|
import { useManageTask, useProjectAssignedOrganizations, useProjectAssignedServices } from "../../../hooks/useProjects";
|
||||||
@ -15,6 +17,7 @@ const taskSchema = z.object({
|
|||||||
buildingID: z.string().min(1, "Building is required"),
|
buildingID: z.string().min(1, "Building is required"),
|
||||||
floorId: z.string().min(1, "Floor is required"),
|
floorId: z.string().min(1, "Floor is required"),
|
||||||
workAreaId: z.string().min(1, "Work Area is required"),
|
workAreaId: z.string().min(1, "Work Area is required"),
|
||||||
|
activityGroupId: z.string().min(1, "Activity Group is required"),
|
||||||
activityID: z.string().min(1, "Activity is required"),
|
activityID: z.string().min(1, "Activity is required"),
|
||||||
workCategoryId: z.string().min(1, "Work Category is required"),
|
workCategoryId: z.string().min(1, "Work Category is required"),
|
||||||
plannedWork: z.number().min(1, "Planned Work must be greater than 0"),
|
plannedWork: z.number().min(1, "Planned Work must be greater than 0"),
|
||||||
@ -27,6 +30,7 @@ const defaultModel = {
|
|||||||
buildingID: "",
|
buildingID: "",
|
||||||
floorId: "",
|
floorId: "",
|
||||||
workAreaId: "",
|
workAreaId: "",
|
||||||
|
activityGroupId: "",
|
||||||
activityID: "",
|
activityID: "",
|
||||||
workCategoryId: "",
|
workCategoryId: "",
|
||||||
plannedWork: 0,
|
plannedWork: 0,
|
||||||
@ -35,7 +39,7 @@ const defaultModel = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TaskModel = ({ project, onSubmit, onClose }) => {
|
const TaskModel = ({ project, onSubmit, onClose }) => {
|
||||||
const { activities, loading: activityLoading } = useActivitiesMaster();
|
// const { activities, loading: activityLoading } = useActivitiesMaster();
|
||||||
const { categories, categoryLoading } = useWorkCategoriesMaster();
|
const { categories, categoryLoading } = useWorkCategoriesMaster();
|
||||||
|
|
||||||
const projectId = useSelectedProject();
|
const projectId = useSelectedProject();
|
||||||
@ -43,19 +47,34 @@ const TaskModel = ({ project, onSubmit, onClose }) => {
|
|||||||
const { data: assignedServices, isLoading: servicesLoading } = useProjectAssignedServices(projectId);
|
const { data: assignedServices, isLoading: servicesLoading } = useProjectAssignedServices(projectId);
|
||||||
const { data: assignedOrganizations, isLoading: orgLoading } = useProjectAssignedOrganizations(projectId);
|
const { data: assignedOrganizations, isLoading: orgLoading } = useProjectAssignedOrganizations(projectId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [selectedService, setSelectedService] = useState("");
|
const [selectedService, setSelectedService] = useState("");
|
||||||
|
const [selectedGroup, setSelectedGroup] = useState("");
|
||||||
|
const { data: groupsResponse, isLoading: groupsLoading } = useGroups(selectedService);
|
||||||
|
const groups = groupsResponse?.data ?? [];
|
||||||
|
|
||||||
|
const { data: activitiesResponse, isLoading: activitiesLoading } = useActivitiesByGroups(selectedGroup);
|
||||||
|
const activities = activitiesResponse?.data ?? [];
|
||||||
// Fetch Assigned Organizations (Activity Groups)
|
// Fetch Assigned Organizations (Activity Groups)
|
||||||
|
|
||||||
const [selectedOrg, setSelectedOrg] = useState("");
|
const [selectedOrg, setSelectedOrg] = useState("");
|
||||||
|
|
||||||
const handleOrgChange = (e) => {
|
|
||||||
setSelectedOrg(e.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const handleServiceChange = (e) => {
|
const handleServiceChange = (e) => {
|
||||||
setSelectedService(e.target.value);
|
const value = e.target.value;
|
||||||
|
setSelectedService(value);
|
||||||
|
setSelectedGroup("");
|
||||||
|
setValue("activityGroupId", "");
|
||||||
|
setValue("activityID", "");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGroupChange = (e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
setSelectedGroup(value);
|
||||||
|
setValue("activityGroupId", value);
|
||||||
|
setValue("activityID", "");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -197,15 +216,13 @@ const TaskModel = ({ project, onSubmit, onClose }) => {
|
|||||||
{/* Services Selection */}
|
{/* Services Selection */}
|
||||||
{selectedWorkArea && (
|
{selectedWorkArea && (
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 text-start">
|
||||||
<Label className="form-label" required>Select Services</Label>
|
<Label className="form-label" required>Select Service</Label>
|
||||||
<select
|
<select
|
||||||
name="DataTables_Table_0_length"
|
|
||||||
aria-controls="DataTables_Table_0"
|
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
aria-label="Select Service"
|
|
||||||
value={selectedService}
|
value={selectedService}
|
||||||
onChange={handleServiceChange}
|
onChange={handleServiceChange}
|
||||||
>
|
>
|
||||||
|
<option value="">Select Service</option>
|
||||||
{servicesLoading && <option>Loading...</option>}
|
{servicesLoading && <option>Loading...</option>}
|
||||||
{assignedServices?.map((service) => (
|
{assignedServices?.map((service) => (
|
||||||
<option key={service.id} value={service.id}>
|
<option key={service.id} value={service.id}>
|
||||||
@ -213,9 +230,6 @@ const TaskModel = ({ project, onSubmit, onClose }) => {
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{errors.buildingID && (
|
|
||||||
<p className="danger-text">{errors.buildingID.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -225,43 +239,36 @@ const TaskModel = ({ project, onSubmit, onClose }) => {
|
|||||||
<Label className="form-label" required>Select Activity Group</Label>
|
<Label className="form-label" required>Select Activity Group</Label>
|
||||||
<select
|
<select
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
value={selectedOrg}
|
{...register("activityGroupId")}
|
||||||
onChange={handleOrgChange}
|
value={selectedGroup}
|
||||||
|
onChange={handleGroupChange}
|
||||||
>
|
>
|
||||||
<option value="">Select Activity Group</option>
|
<option value="">Select Group</option>
|
||||||
{orgLoading && <option>Loading...</option>}
|
{groupsLoading && <option>Loading...</option>}
|
||||||
{assignedOrganizations?.map((org) => (
|
{groups?.map((g) => (
|
||||||
<option key={org.id} value={org.id}>
|
<option key={g.id} value={g.id}>{g.name}</option>
|
||||||
{org.name}
|
|
||||||
</option>
|
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.activityGroupId && <p className="danger-text">{errors.activityGroupId.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{/* Activity Selection */}
|
{/* Activity Selection */}
|
||||||
{selectedOrg && (
|
{selectedGroup && (
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 text-start">
|
||||||
<Label className="form-label" required>Select Activity</Label>
|
<Label className="form-label" required>Select Activity</Label>
|
||||||
<select
|
<select className="form-select form-select-sm" {...register("activityID")}>
|
||||||
className="form-select form-select-sm"
|
|
||||||
{...register("activityID")}
|
|
||||||
>
|
|
||||||
<option value="">Select Activity</option>
|
<option value="">Select Activity</option>
|
||||||
{activityData.map((a) => (
|
{activitiesLoading && <option>Loading...</option>}
|
||||||
<option key={a.id} value={a.id}>
|
{activities?.map((a) => (
|
||||||
{a.activityName}
|
<option key={a.id} value={a.id}>{a.activityName}</option>
|
||||||
</option>
|
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{errors.activityID && (
|
{errors.activityID && <p className="danger-text">{errors.activityID.message}</p>}
|
||||||
<p className="danger-text">{errors.activityID.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{selectedWorkArea && (
|
{selectedWorkArea && (
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 text-start">
|
||||||
<label className="form-label">Select Work Category</label>
|
<label className="form-label">Select Work Category</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user