Compare commits
No commits in common. "58837cef0c563598bb30b850c5a838fc48605e16" and "92b1531b75ed383d762d88e0b3ea141403e567dc" have entirely different histories.
58837cef0c
...
92b1531b75
@ -32,8 +32,9 @@ const EditActivityModal = ({
|
|||||||
building,
|
building,
|
||||||
floor,
|
floor,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
} ) =>
|
||||||
|
{
|
||||||
|
|
||||||
const { activities, loading: loadingActivities } = useActivitiesMaster();
|
const { activities, loading: loadingActivities } = useActivitiesMaster();
|
||||||
const { categories, loading: loadingCategories } = useWorkCategoriesMaster();
|
const { categories, loading: loadingCategories } = useWorkCategoriesMaster();
|
||||||
const [selectedActivity, setSelectedActivity] = useState(null);
|
const [selectedActivity, setSelectedActivity] = useState(null);
|
||||||
@ -56,12 +57,13 @@ const EditActivityModal = ({
|
|||||||
comment: "",
|
comment: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { mutate: UpdateTask, isPending } = useManageTask({
|
const { mutate: UpdateTask, isPending } = useManageTask({
|
||||||
onSuccessCallback: (response) => {
|
onSuccessCallback: (response) =>
|
||||||
showToast(response?.message, "success")
|
{
|
||||||
onClose()
|
showToast( response?.message, "success" )
|
||||||
}
|
onClose()
|
||||||
});
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -80,33 +82,34 @@ const EditActivityModal = ({
|
|||||||
[categories]
|
[categories]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!workItem) return;
|
if (!workItem) return;
|
||||||
console.log(workItem)
|
console.log(workItem)
|
||||||
reset({
|
reset({
|
||||||
activityID: String(
|
activityID: String(
|
||||||
workItem?.workItem?.activityId || workItem?.activityMaster?.id
|
workItem?.workItem?.activityId || workItem?.activityMaster?.id
|
||||||
),
|
),
|
||||||
workCategoryId: String(
|
workCategoryId: String(
|
||||||
workItem?.workItem?.workCategoryId || workItem?.workCategoryMaster?.id
|
workItem?.workItem?.workCategoryId || workItem?.workCategoryMaster?.id
|
||||||
),
|
),
|
||||||
plannedWork:
|
plannedWork:
|
||||||
workItem?.workItem?.plannedWork || workItem?.plannedWork || 0,
|
workItem?.workItem?.plannedWork || workItem?.plannedWork || 0,
|
||||||
completedWork:
|
completedWork:
|
||||||
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
||||||
comment: workItem?.workItem?.description || workItem?.description || "",
|
comment: workItem?.workItem?.description || workItem?.description || "",
|
||||||
});
|
});
|
||||||
}, [workItem?.id, selectedActivity]);
|
}, [workItem?.id,selectedActivity]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selected = activities?.find((a) => a.id === activityID);
|
const selected = activities?.find((a) => a.id === activityID);
|
||||||
setSelectedActivity(selected || null);
|
setSelectedActivity( selected || null );
|
||||||
}, [activityID, activities]);
|
}, [activityID, activities]);
|
||||||
|
|
||||||
const onSubmitForm = (data) => {
|
const onSubmitForm = (data) =>
|
||||||
const payload = {
|
{
|
||||||
|
const payload = {
|
||||||
...data,
|
...data,
|
||||||
id: workItem?.workItem?.id ?? workItem?.id,
|
id: workItem?.workItem?.id ?? workItem?.id,
|
||||||
buildingID: building?.id,
|
buildingID: building?.id,
|
||||||
@ -122,9 +125,9 @@ const EditActivityModal = ({
|
|||||||
buildingId: building?.id,
|
buildingId: building?.id,
|
||||||
floorId: floor?.id,
|
floorId: floor?.id,
|
||||||
workAreaId: workArea?.id,
|
workAreaId: workArea?.id,
|
||||||
previousCompletedWork: completedTask
|
previousCompletedWork:completedTask
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<form className="row g-2 p-2 p-md-1" onSubmit={handleSubmit(onSubmitForm)}>
|
<form className="row g-2 p-2 p-md-1" onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<div className="text-center mb-1">
|
<div className="text-center mb-1">
|
||||||
@ -159,26 +162,14 @@ const EditActivityModal = ({
|
|||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 text-start">
|
|
||||||
<label className="form-label">Select Service</label>
|
|
||||||
<input
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
value={
|
|
||||||
workItem?.activityMaster?.activityGroupMaster?.service?.name || ""
|
|
||||||
}
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 text-start">
|
||||||
<label className="form-label">Select Activity</label>
|
<label className="form-label">Select Activity</label>
|
||||||
<select
|
<select
|
||||||
{...register("activityID")}
|
{...register("activityID")}
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
disabled
|
|
||||||
>
|
>
|
||||||
<option >Select Activity</option>
|
<option disabled>Select Activity</option>
|
||||||
{loadingActivities ? (
|
{loadingActivities ? (
|
||||||
<option>Loading...</option>
|
<option>Loading...</option>
|
||||||
) : (
|
) : (
|
||||||
@ -273,7 +264,7 @@ const EditActivityModal = ({
|
|||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
>
|
>
|
||||||
{isPending ? "Please Wait..." : "Edit Task"}
|
{isPending ? "Please Wait..." : "Edit Task"}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3,12 +3,10 @@ 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, useProjectAssignedServices } from "../../../hooks/useProjects";
|
||||||
import showToast from "../../../services/toastService";
|
import showToast from "../../../services/toastService";
|
||||||
import Label from "../../common/Label";
|
import Label from "../../common/Label";
|
||||||
import { useSelectedProject } from "../../../slices/apiDataManager";
|
import { useSelectedProject } from "../../../slices/apiDataManager";
|
||||||
@ -17,8 +15,6 @@ 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"),
|
||||||
serviceId: z.string().min(1, "Service 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"),
|
||||||
@ -31,8 +27,6 @@ const defaultModel = {
|
|||||||
buildingID: "",
|
buildingID: "",
|
||||||
floorId: "",
|
floorId: "",
|
||||||
workAreaId: "",
|
workAreaId: "",
|
||||||
serviceId: "",
|
|
||||||
activityGroupId: "",
|
|
||||||
activityID: "",
|
activityID: "",
|
||||||
workCategoryId: "",
|
workCategoryId: "",
|
||||||
plannedWork: 0,
|
plannedWork: 0,
|
||||||
@ -41,42 +35,18 @@ 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();
|
||||||
|
|
||||||
const { data: assignedServices, isLoading: servicesLoading } = useProjectAssignedServices(projectId);
|
const { data: assignedServices, isLoading: servicesLoading } = useProjectAssignedServices(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)
|
|
||||||
|
|
||||||
const [selectedOrg, setSelectedOrg] = useState("");
|
|
||||||
const handleServiceChange = (e) => {
|
const handleServiceChange = (e) => {
|
||||||
const value = e.target.value;
|
setSelectedService(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,
|
||||||
@ -218,18 +188,15 @@ 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 Service</Label>
|
<Label className="form-label">Select Services</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"
|
||||||
{...register("serviceId")}
|
aria-label="Select Service"
|
||||||
value={selectedService}
|
value={selectedService}
|
||||||
// onChange={handleServiceChange}
|
onChange={handleServiceChange}
|
||||||
onChange={(e) => {
|
|
||||||
handleServiceChange(e);
|
|
||||||
setValue("serviceId", e.target.value);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<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}>
|
||||||
@ -237,45 +204,34 @@ const TaskModel = ({ project, onSubmit, onClose }) => {
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.buildingID && (
|
||||||
|
<p className="danger-text">{errors.buildingID.message}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Activity Group (Organization) Selection */}
|
|
||||||
{selectedService && (
|
|
||||||
<div className="col-12 text-start">
|
|
||||||
<Label className="form-label" required>Select Activity Group</Label>
|
|
||||||
<select
|
|
||||||
className="form-select form-select-sm"
|
|
||||||
{...register("activityGroupId")}
|
|
||||||
value={selectedGroup}
|
|
||||||
onChange={handleGroupChange}
|
|
||||||
>
|
|
||||||
<option value="">Select Group</option>
|
|
||||||
{groupsLoading && <option>Loading...</option>}
|
|
||||||
{groups?.map((g) => (
|
|
||||||
<option key={g.id} value={g.id}>{g.name}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
{errors.activityGroupId && <p className="danger-text">{errors.activityGroupId.message}</p>}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
|
|
||||||
{/* Activity Selection */}
|
{/* Activity Selection */}
|
||||||
{selectedGroup && (
|
{selectedWorkArea && (
|
||||||
<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 className="form-select form-select-sm" {...register("activityID")}>
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
{...register("activityID")}
|
||||||
|
>
|
||||||
<option value="">Select Activity</option>
|
<option value="">Select Activity</option>
|
||||||
{activitiesLoading && <option>Loading...</option>}
|
{activityData.map((a) => (
|
||||||
{activities?.map((a) => (
|
<option key={a.id} value={a.id}>
|
||||||
<option key={a.id} value={a.id}>{a.activityName}</option>
|
{a.activityName}
|
||||||
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{errors.activityID && <p className="danger-text">{errors.activityID.message}</p>}
|
{errors.activityID && (
|
||||||
|
<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>
|
||||||
|
|||||||
@ -103,12 +103,8 @@ export const useAssignOrgToProject = (onSuccessCallback) => {
|
|||||||
mutationFn: async (payload) =>
|
mutationFn: async (payload) =>
|
||||||
await OrganizationRepository.assignOrganizationToProject(payload),
|
await OrganizationRepository.assignOrganizationToProject(payload),
|
||||||
onSuccess: (_, variables) => {
|
onSuccess: (_, variables) => {
|
||||||
const {projectId} = variables
|
|
||||||
useClient.invalidateQueries({
|
useClient.invalidateQueries({
|
||||||
queryKey: ["projectAssignedOrganiztions"],
|
queryKey: ["projectAssignedOrganiztions"],
|
||||||
});
|
|
||||||
useClient.invalidateQueries({
|
|
||||||
queryKey: ["projectAssignedOrganization", projectId],
|
|
||||||
});
|
});
|
||||||
showToast("Organization successfully", "success");
|
showToast("Organization successfully", "success");
|
||||||
if (onSuccessCallback) onSuccessCallback();
|
if (onSuccessCallback) onSuccessCallback();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user