integrated create Task api and handling data caching updated for task.
This commit is contained in:
parent
10d6f96ea7
commit
93c95e007a
@ -37,9 +37,14 @@ const BuildingModel = ({
|
|||||||
} else if (editingBuilding) {
|
} else if (editingBuilding) {
|
||||||
setFormData({ ...editingBuilding, projectId: project.id });
|
setFormData({ ...editingBuilding, projectId: project.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
setValue("name",null)
|
||||||
|
}
|
||||||
}, [clearTrigger, onClearComplete, editingBuilding, project.id]);
|
}, [clearTrigger, onClearComplete, editingBuilding, project.id]);
|
||||||
|
|
||||||
const { register, handleSubmit, formState: { errors }, setValue } = useForm({
|
const { register, handleSubmit, formState: { errors }, setValue,reset,getValues} = useForm({
|
||||||
resolver: zodResolver(buildingSchema),
|
resolver: zodResolver(buildingSchema),
|
||||||
defaultValues: formData, // Set default values from formData state
|
defaultValues: formData, // Set default values from formData state
|
||||||
});
|
});
|
||||||
@ -59,7 +64,11 @@ const BuildingModel = ({
|
|||||||
|
|
||||||
const onSubmitHandler = async( data ) =>
|
const onSubmitHandler = async( data ) =>
|
||||||
{
|
{
|
||||||
onSubmit({ ...data, projectId: project.id });
|
onSubmit( {...data, projectId: project.id} );
|
||||||
|
reset( {
|
||||||
|
name: null,
|
||||||
|
description:null
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -116,7 +125,7 @@ const BuildingModel = ({
|
|||||||
|
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
<button type="submit" className="btn btn-primary me-3">
|
<button type="submit" className="btn btn-primary me-3">
|
||||||
{formData.id ? "Edit Building" : "Add Building"}
|
{ ( formData.id && getValues("name")) ? "Edit Building" : "Add Building"}
|
||||||
</button>
|
</button>
|
||||||
<button type="reset" className="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close" onClick={onClose}>
|
<button type="reset" className="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close" onClick={onClose}>
|
||||||
Cancel
|
Cancel
|
||||||
|
|||||||
@ -1,9 +1,22 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// Define Zod validation schema
|
||||||
|
const taskSchema = z.object({
|
||||||
|
buildingID: z.string().min(1, "Building is required"),
|
||||||
|
floorId: z.string().min(1, "Floor is required"),
|
||||||
|
workAreaId: z.number().min(1, "Work Area is required"),
|
||||||
|
activityID: z.number().min(1, "Activity is required"),
|
||||||
|
plannedWork: z.number().min(1, "Planned Work must be greater than 0"),
|
||||||
|
completedWork: z.number().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
const defaultModel = {
|
const defaultModel = {
|
||||||
id: "0",
|
id: "0",
|
||||||
workAreaId: 0,
|
workAreaId: 0,
|
||||||
activityId: 0,
|
activityID: 0,
|
||||||
plannedWork: 0,
|
plannedWork: 0,
|
||||||
completedWork: 0,
|
completedWork: 0,
|
||||||
};
|
};
|
||||||
@ -14,46 +27,27 @@ const TaskModel = ({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
clearTrigger,
|
clearTrigger,
|
||||||
onClearComplete,
|
onClearComplete,
|
||||||
} ) =>
|
}) => {
|
||||||
{
|
|
||||||
|
|
||||||
const [formData, setFormData] = useState(defaultModel);
|
const [formData, setFormData] = useState(defaultModel);
|
||||||
const [selectedBuilding, setSelectedBuilding] = useState(null);
|
const [selectedBuilding, setSelectedBuilding] = useState(null);
|
||||||
const [selectedFloor, setSelectedFloor] = useState(null);
|
const [selectedFloor, setSelectedFloor] = useState(null);
|
||||||
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
|
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
|
||||||
const [selectedActivity, setSelectedActivity] = useState(null);
|
const [selectedActivity, setSelectedActivity] = useState(null);
|
||||||
|
|
||||||
//if (floor && floor.id) setFormData(floor);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const { register, handleSubmit, formState: { errors },reset } = useForm({
|
||||||
if (selectedBuilding) {
|
resolver: zodResolver(taskSchema),
|
||||||
let building = project.buildings.find(
|
defaultValues: formData,
|
||||||
(b) => b.id === selectedBuilding.id
|
});
|
||||||
);
|
|
||||||
setSelectedBuilding(building);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedFloor) {
|
|
||||||
let floor = selectedBuilding.floors.find(
|
|
||||||
(b) => b.id === Number(selectedFloor.id)
|
|
||||||
);
|
|
||||||
setSelectedFloor(floor);
|
|
||||||
}
|
|
||||||
if (selectedWorkArea) {
|
|
||||||
formData.workAreaId = selectedWorkArea.id;
|
|
||||||
}
|
|
||||||
}, [project]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (clearTrigger) {
|
if (clearTrigger) {
|
||||||
let model = defaultModel;
|
|
||||||
model.floorId = selectedFloor.id;
|
|
||||||
setFormData(defaultModel);
|
setFormData(defaultModel);
|
||||||
onClearComplete();
|
onClearComplete();
|
||||||
}
|
}
|
||||||
}, [clearTrigger, onClearComplete]);
|
}, [clearTrigger, onClearComplete]);
|
||||||
|
|
||||||
// Handle input change
|
// Handle input changes
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
const activity = activities.find((b) => b.id === Number(value));
|
const activity = activities.find((b) => b.id === Number(value));
|
||||||
@ -64,29 +58,15 @@ const TaskModel = ({
|
|||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const activity = activities.find((b) => b.id === Number(value));
|
const activity = activities.find((b) => b.id === Number(value));
|
||||||
|
|
||||||
setFormData({ ...formData, ["activityId"]: value });
|
setFormData({ ...formData, ["activityID"]: value });
|
||||||
setSelectedActivity(activity);
|
setSelectedActivity(activity);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleWorkAreaChange = (e) => {
|
const handleWorkAreaChange = (e) => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const workArea = selectedFloor.workAreas.find(
|
const workArea = selectedFloor.workAreas.find((b) => b.id === Number(value));
|
||||||
(b) => b.id === Number(value)
|
|
||||||
);
|
|
||||||
setSelectedWorkArea(workArea);
|
setSelectedWorkArea(workArea);
|
||||||
setSelectedActivity(null);
|
|
||||||
setFormData({ ...formData, ["workAreaId"]: value });
|
setFormData({ ...formData, ["workAreaId"]: value });
|
||||||
// if (workArea) {
|
|
||||||
// setFormData({
|
|
||||||
// id: workArea.id,
|
|
||||||
// floorId: workArea.floorId,
|
|
||||||
// areaName: workArea.areaName,
|
|
||||||
// });
|
|
||||||
// } else
|
|
||||||
// setFormData({
|
|
||||||
// id: "0",
|
|
||||||
// floorId: selectedFloor.id,
|
|
||||||
// areaName: "",
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFloorChange = (e) => {
|
const handleFloorChange = (e) => {
|
||||||
@ -97,7 +77,8 @@ const TaskModel = ({
|
|||||||
setSelectedActivity(null);
|
setSelectedActivity(null);
|
||||||
setFormData(defaultModel);
|
setFormData(defaultModel);
|
||||||
};
|
};
|
||||||
const handleBuildigChange = (e) => {
|
|
||||||
|
const handleBuildingChange = (e) => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const building = project.buildings.find((b) => b.id === Number(value));
|
const building = project.buildings.find((b) => b.id === Number(value));
|
||||||
setSelectedBuilding(building);
|
setSelectedBuilding(building);
|
||||||
@ -107,14 +88,37 @@ const TaskModel = ({
|
|||||||
setFormData(defaultModel);
|
setFormData(defaultModel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle form submission
|
const onSubmitForm = ( data ) =>
|
||||||
const handleSubmit = (e) => {
|
{
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
// onSubmit( formData ); // Pass the updated data to the parent
|
|
||||||
console.log(formData)
|
onSubmit( data );
|
||||||
|
setSelectedActivity(null),
|
||||||
|
selectedWorkArea(null)
|
||||||
|
reset( {
|
||||||
|
plannedWork: 0,
|
||||||
|
completedWork:0
|
||||||
|
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect( () =>
|
||||||
|
{
|
||||||
|
() =>{
|
||||||
|
resetVlaue ()
|
||||||
|
}
|
||||||
|
},[])
|
||||||
|
const resetVlaue = () =>
|
||||||
|
{
|
||||||
|
setSelectedBuilding( null )
|
||||||
|
setSelectedFloor( null )
|
||||||
|
setSelectedWorkArea( null )
|
||||||
|
setSelectedActivity(null)
|
||||||
|
reset( {
|
||||||
|
plannedWork: 0,
|
||||||
|
completedWork:0
|
||||||
|
})
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
@ -129,18 +133,19 @@ const TaskModel = ({
|
|||||||
<div className="text-center mb-1">
|
<div className="text-center mb-1">
|
||||||
<h5 className="mb-1">Manage Task</h5>
|
<h5 className="mb-1">Manage Task</h5>
|
||||||
</div>
|
</div>
|
||||||
<form className="row g-2" onSubmit={handleSubmit}>
|
<form className="row g-2" onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
|
{/* Select Building */}
|
||||||
<div className="col-6 col-md-6">
|
<div className="col-6 col-md-6">
|
||||||
<label className="form-label" htmlFor="name">
|
<label className="form-label" htmlFor="name">
|
||||||
Select Building
|
Select Building
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
id="buildingId"
|
id="buildingID"
|
||||||
name="buildingId"
|
name="buildingID"
|
||||||
className="select2 form-select form-select-sm"
|
className="select2 form-select form-select-sm"
|
||||||
aria-label="Default select example"
|
aria-label="Default select example"
|
||||||
onChange={handleBuildigChange}
|
{...register("buildingID")}
|
||||||
value={formData.buildingId}
|
onChange={(e) => handleBuildingChange(e)}
|
||||||
>
|
>
|
||||||
<option value="0">Select Building</option>
|
<option value="0">Select Building</option>
|
||||||
{project.buildings.map((building) => (
|
{project.buildings.map((building) => (
|
||||||
@ -149,9 +154,11 @@ const TaskModel = ({
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.buildingID && <p className="danger-text">{errors.buildingID.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{selectedBuilding && selectedBuilding.id != "0" && (
|
{/* Select Floor */}
|
||||||
|
{selectedBuilding && selectedBuilding.id !== "0" && (
|
||||||
<div className="col-6 col-md-6">
|
<div className="col-6 col-md-6">
|
||||||
<label className="form-label" htmlFor="floorId">
|
<label className="form-label" htmlFor="floorId">
|
||||||
Select Floor
|
Select Floor
|
||||||
@ -161,19 +168,21 @@ const TaskModel = ({
|
|||||||
name="floorId"
|
name="floorId"
|
||||||
className="select2 form-select form-select-sm"
|
className="select2 form-select form-select-sm"
|
||||||
aria-label="Default select example"
|
aria-label="Default select example"
|
||||||
onChange={handleFloorChange}
|
{...register("floorId")}
|
||||||
value={formData.floorId}
|
onChange={(e) => handleFloorChange(e)}
|
||||||
>
|
>
|
||||||
<option value="0">Select Floor</option>
|
<option value="0">Select Floor</option>
|
||||||
{selectedBuilding.floors.map((floor) => (
|
{selectedBuilding.floors.map((floor) => (
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
{floor.floorName} - ({floor.workAreas.length} Work
|
{floor.floorName} - ({floor.workAreas.length} Work Areas)
|
||||||
Areas)
|
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.floorId && <p className="danger-text">{errors.floorId.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Select Work Area */}
|
||||||
{selectedFloor && (
|
{selectedFloor && (
|
||||||
<div className="col-12 col-md-12">
|
<div className="col-12 col-md-12">
|
||||||
<label className="form-label" htmlFor="workAreaId">
|
<label className="form-label" htmlFor="workAreaId">
|
||||||
@ -184,8 +193,8 @@ const TaskModel = ({
|
|||||||
name="workAreaId"
|
name="workAreaId"
|
||||||
className="select2 form-select form-select-sm"
|
className="select2 form-select form-select-sm"
|
||||||
aria-label="Default select example"
|
aria-label="Default select example"
|
||||||
onChange={handleWorkAreaChange}
|
{...register("workAreaId",{valueAsNumber:true})}
|
||||||
value={formData.workAreaId}
|
onChange={(e) => handleWorkAreaChange(e)}
|
||||||
>
|
>
|
||||||
<option value="0">Select Work Area</option>
|
<option value="0">Select Work Area</option>
|
||||||
{selectedFloor.workAreas.map((workArea) => (
|
{selectedFloor.workAreas.map((workArea) => (
|
||||||
@ -194,20 +203,23 @@ const TaskModel = ({
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.workAreaId && <p className="danger-text">{errors.workAreaId.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Select Activity */}
|
||||||
{selectedWorkArea && (
|
{selectedWorkArea && (
|
||||||
<div className="col-12 col-md-12">
|
<div className="col-12 col-md-12">
|
||||||
<label className="form-label" htmlFor="activityId">
|
<label className="form-label" htmlFor="activityID">
|
||||||
Select Activity
|
Select Activity
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
id="activityId"
|
id="activityID"
|
||||||
name="activityId"
|
name="activityID"
|
||||||
className="select2 form-select form-select-sm"
|
className="select2 form-select form-select-sm"
|
||||||
aria-label="Default select example"
|
aria-label="Default select example"
|
||||||
onChange={handleActivityChange}
|
{...register("activityID",{valueAsNumber:true})}
|
||||||
value={formData.activityId}
|
onChange={(e) => handleActivityChange(e)}
|
||||||
>
|
>
|
||||||
<option value="0">Select Activity</option>
|
<option value="0">Select Activity</option>
|
||||||
{activities.map((activity) => (
|
{activities.map((activity) => (
|
||||||
@ -216,75 +228,67 @@ const TaskModel = ({
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
{errors.activityID && <p className="danger-text">{errors.activityID.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Planned Work */}
|
||||||
{selectedActivity && (
|
{selectedActivity && (
|
||||||
<div className="col-5 col-md-5">
|
<div className="col-5 col-md-5">
|
||||||
{" "}
|
|
||||||
<label className="form-label" htmlFor="plannedWork">
|
<label className="form-label" htmlFor="plannedWork">
|
||||||
{formData.id != "0" ? "Modify " : "Enter "} Planned Work
|
{formData.id !== "0" ? "Modify " : "Enter "} Planned Work
|
||||||
</label>
|
</label>
|
||||||
<div className="input-group">
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
{...register("plannedWork", { valueAsNumber: true })}
|
||||||
|
type="number"
|
||||||
id="plannedWork"
|
id="plannedWork"
|
||||||
name="plannedWork"
|
name="plannedWork"
|
||||||
className="form-control form-control-sm me-2"
|
className="form-control form-control-sm me-2"
|
||||||
placeholder="Task"
|
placeholder="Planned Work"
|
||||||
onChange={handleChange}
|
|
||||||
value={formData.plannedWork}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
{errors.plannedWork && <p className="danger-text">{errors.plannedWork.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Completed Work */}
|
||||||
{selectedActivity && (
|
{selectedActivity && (
|
||||||
<div className="col-5 col-md-5">
|
<div className="col-5 col-md-5">
|
||||||
{" "}
|
|
||||||
<label className="form-label" htmlFor="completedWork">
|
<label className="form-label" htmlFor="completedWork">
|
||||||
{formData.id != "0" ? "Modify " : "Enter "} Completed Work
|
{formData.id !== "0" ? "Modify " : "Enter "} Completed Work
|
||||||
</label>
|
</label>
|
||||||
<div className="input-group">
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
{...register("completedWork", { valueAsNumber: true })}
|
||||||
|
type="number"
|
||||||
id="completedWork"
|
id="completedWork"
|
||||||
name="completedWork"
|
name="completedWork"
|
||||||
className="form-control form-control-sm me-2"
|
className="form-control form-control-sm me-2"
|
||||||
placeholder="Completed Work"
|
placeholder="Completed Work"
|
||||||
onChange={handleChange}
|
|
||||||
value={formData.completedWork}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
{errors.completedWork && <p className="danger-text">{errors.completedWork.message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Unit */}
|
||||||
{selectedActivity && (
|
{selectedActivity && (
|
||||||
<div className="col-2 col-md-2">
|
<div className="col-2 col-md-2">
|
||||||
{" "}
|
|
||||||
<label className="form-label" htmlFor="unit">
|
<label className="form-label" htmlFor="unit">
|
||||||
Unit
|
Unit
|
||||||
</label>
|
</label>
|
||||||
<div className="input-group">
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="unit"
|
|
||||||
disabled
|
disabled
|
||||||
|
id="unit"
|
||||||
name="unit"
|
name="unit"
|
||||||
className="form-control form-control-sm me-2"
|
className="form-control form-control-sm me-2"
|
||||||
placeholder="Unit"
|
value={selectedActivity?.unitOfMeasurement || ""}
|
||||||
onChange={handleChange}
|
|
||||||
value={selectedActivity.unitOfMeasurement}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
{selectedActivity && (
|
|
||||||
<button type="submit" className="btn btn-primary me-3">
|
<button type="submit" className="btn btn-primary me-3">
|
||||||
{formData.id != "0" && formData.id != ""
|
{formData.id !== "0" && formData.id !== "" ? "Edit Task" : "Add Task"}
|
||||||
? "Edit Task"
|
|
||||||
: "Add Task"}
|
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
<button
|
<button
|
||||||
type="reset"
|
type="reset"
|
||||||
className="btn btn-label-secondary"
|
className="btn btn-label-secondary"
|
||||||
@ -293,6 +297,7 @@ const TaskModel = ({
|
|||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
import React from "react";
|
import React,{useEffect} from "react";
|
||||||
import WorkItem from "./WorkItem";
|
import WorkItem from "./WorkItem";
|
||||||
|
|
||||||
const WorkArea = ({ workArea, floor,forBuilding }) => {
|
const WorkArea = ( {workArea, floor, forBuilding} ) =>
|
||||||
|
{
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
}, [workArea]);
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={workArea.id}>
|
<React.Fragment key={workArea.id}>
|
||||||
<tr>
|
<tr>
|
||||||
@ -25,16 +29,28 @@ const WorkArea = ({ workArea, floor,forBuilding }) => {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Activity</th>
|
<th>Activity</th>
|
||||||
<th>Planned</th>
|
{/* for mobile view */}
|
||||||
<th>Completed</th>
|
<th className="d-sm-none d-sm-table-cell">Status</th>
|
||||||
|
{/* for greather than mobile view ************* */}
|
||||||
|
<th className="d-none d-md-table-cell">Planned</th>
|
||||||
|
<th className="d-none d-md-table-cell">Completed</th>
|
||||||
|
{/* ************************** */}
|
||||||
<th>Progress</th>
|
<th>Progress</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0">
|
<tbody className="table-border-bottom-0">
|
||||||
{workArea.workItems.map((workItem) => (
|
{workArea?.workItems && workArea.workItems.length > 0 ? (
|
||||||
<WorkItem key={workItem.workItemId} workItem={workItem} forBuilding={forBuilding} forFloor={floor} forWorkArea={workArea} />
|
workArea.workItems.map((workItem) => (
|
||||||
))}
|
<WorkItem key={workItem.workItemId} workItem={workItem} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan="4" className="text-center">
|
||||||
|
No Data
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
@ -42,5 +58,5 @@ const WorkArea = ({ workArea, floor,forBuilding }) => {
|
|||||||
) : null}
|
) : null}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default WorkArea;
|
export default WorkArea;
|
||||||
@ -1,15 +1,15 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState,useEffect } from "react";
|
||||||
import { useModal } from "../../../ModalContext";
|
import { useModal } from "../../../ModalContext";
|
||||||
import AssignRoleModel from "../AssignRole";
|
import AssignRoleModel from "../AssignRole";
|
||||||
import {useParams} from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import GlobalModel from "../../common/GlobalModel";
|
import GlobalModel from "../../common/GlobalModel";
|
||||||
|
|
||||||
const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
|
const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
||||||
const {projectId} = useParams()
|
const { projectId } = useParams();
|
||||||
const [ itemName, setItemName ] = useState( '' );
|
const [ itemName, setItemName ] = useState( "" );
|
||||||
|
const [NewWorkItem,setNewWorkItem] = useState()
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const openModal = () => setIsModalOpen(true);
|
const openModal = () => setIsModalOpen(true);
|
||||||
const closeModal = () => setIsModalOpen(false);
|
const closeModal = () => setIsModalOpen(false);
|
||||||
const getProgress = (planned, completed) => {
|
const getProgress = (planned, completed) => {
|
||||||
@ -17,8 +17,8 @@ const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAssignTask = () => {
|
const handleAssignTask = () => {
|
||||||
console.log("Item Created:", itemName);
|
|
||||||
setItemName('');
|
setItemName("");
|
||||||
};
|
};
|
||||||
|
|
||||||
// const showCreateItemModal = (modalData) => {
|
// const showCreateItemModal = (modalData) => {
|
||||||
@ -28,51 +28,79 @@ const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
|
|||||||
// );
|
// );
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
setNewWorkItem(workItem)
|
||||||
|
}, [workItem]); // This hook will run whenever the workItem prop changes
|
||||||
|
|
||||||
let assigndata = {
|
let assigndata = {
|
||||||
building: forBuilding,
|
building: forBuilding,
|
||||||
floor: forFloor,
|
floor: forFloor,
|
||||||
workArea: forWorkArea,
|
workArea: forWorkArea,
|
||||||
workItem
|
workItem,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const hasWorkItem = NewWorkItem && NewWorkItem
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<GlobalModel isOpen={isModalOpen}
|
<GlobalModel
|
||||||
closeModal={closeModal} dialogClass="modal-dialog-centered" role="document" size="lg" >
|
isOpen={isModalOpen}
|
||||||
|
closeModal={closeModal}
|
||||||
|
dialogClass="modal-dialog-centered"
|
||||||
|
role="document"
|
||||||
|
size="lg"
|
||||||
|
>
|
||||||
<AssignRoleModel assignData={assigndata} onClose={closeModal} />
|
<AssignRoleModel assignData={assigndata} onClose={closeModal} />
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="text-start table-cell-small">
|
<td className="text-start table-cell-small">
|
||||||
<i className="bx bx-right-arrow-alt"></i>
|
<i className="bx bx-right-arrow-alt"></i>
|
||||||
<span className="fw-medium">
|
<span className="fw-medium">
|
||||||
{workItem.workItem.activityMaster
|
{hasWorkItem ? ( NewWorkItem?.workItem?.activityMaster?.activityName || workItem.activityMaster?.activityName ) :"NA"
|
||||||
? workItem.workItem.activityMaster.activityName
|
}
|
||||||
: "NA"}
|
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center">
|
{/* for mobile view */}
|
||||||
{workItem.workItem ? workItem.workItem.plannedWork : "NA"}
|
<td className="text-center d-sm-none d-sm-table-cell">
|
||||||
|
{hasWorkItem ? (NewWorkItem?.workItem?.completedWork || workItem?.completedWork) :"NA" }/{" "}
|
||||||
|
{ hasWorkItem ? (NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork) : "NA"}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center">
|
{/* for greather than mobile view ************* */}
|
||||||
{workItem.workItem ? workItem.workItem.completedWork : "NA"}
|
<td className="text-center d-none d-md-table-cell">
|
||||||
|
{hasWorkItem ? (NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork): "NA"}
|
||||||
</td>
|
</td>
|
||||||
|
<td className="text-center d-none d-md-table-cell">
|
||||||
|
{hasWorkItem ? (NewWorkItem?.workItem?.completedWork || workItem?.completedWork) : "NA"}
|
||||||
|
</td>
|
||||||
|
{/* ************************************************ */}
|
||||||
<td className="text-center" style={{ width: "15%" }}>
|
<td className="text-center" style={{ width: "15%" }}>
|
||||||
<div className="progress p-0">
|
<div className="progress p-0">
|
||||||
<div
|
<div
|
||||||
className="progress-bar"
|
className="progress-bar"
|
||||||
role="progressbar"
|
role="progressbar"
|
||||||
style={{
|
style={{
|
||||||
width: getProgress(workItem.workItem.plannedWork, workItem.workItem.completedWork),
|
width: getProgress(
|
||||||
|
(NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork),
|
||||||
|
(NewWorkItem?.workItem?.completedWork || workItem?.completedWork)
|
||||||
|
),
|
||||||
height: "10px",
|
height: "10px",
|
||||||
}}
|
}}
|
||||||
aria-valuenow={workItem.workItem ? workItem.workItem.completedWork : 0}
|
aria-valuenow={
|
||||||
|
hasWorkItem ? (NewWorkItem?.workItem?.completedWork || workItem?.completedWork) : 0
|
||||||
|
}
|
||||||
aria-valuemin="0"
|
aria-valuemin="0"
|
||||||
aria-valuemax={workItem.workItem ? workItem.workItem.plannedWork : 0}
|
aria-valuemax={
|
||||||
|
hasWorkItem ? (NewWorkItem?.workItem?.plannedWork || workItem?.plannedWork) : 0
|
||||||
|
}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
{/* for greather than mobile view */}
|
||||||
|
<td className="d-none d-md-table-cell">
|
||||||
<div className="dropdown">
|
<div className="dropdown">
|
||||||
{!projectId && ( <button
|
{!projectId && (
|
||||||
|
<button
|
||||||
aria-label="Modify"
|
aria-label="Modify"
|
||||||
type="button"
|
type="button"
|
||||||
className="btn p-0"
|
className="btn p-0"
|
||||||
@ -81,7 +109,8 @@ const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
|
|||||||
onClick={openModal}
|
onClick={openModal}
|
||||||
>
|
>
|
||||||
<span className="badge bg-label-primary me-1">Assign</span>
|
<span className="badge bg-label-primary me-1">Assign</span>
|
||||||
</button>)}
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
aria-label="Modify"
|
aria-label="Modify"
|
||||||
type="button"
|
type="button"
|
||||||
@ -98,6 +127,29 @@ const WorkItem = ( {workItem, forBuilding, forFloor, forWorkArea} ) =>{
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
{/* for mobile view */}
|
||||||
|
<td className="text-end d-sm-none d-sm-table-cell">
|
||||||
|
<div className="d-flex align-items-center justify-content-center ">
|
||||||
|
<a
|
||||||
|
className={`btn btn-icon dropdown-toggle hide-arrow`}
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
>
|
||||||
|
<i className="bx bx-dots-vertical-rounded bx-md"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div className="dropdown-menu dropdown-menu-end m-0">
|
||||||
|
{" "}
|
||||||
|
<a className="dropdown-item">
|
||||||
|
{" "}
|
||||||
|
<i className="bx bxs-edit me-2 text-primary"></i>Edit
|
||||||
|
</a>
|
||||||
|
<a className="dropdown-item">
|
||||||
|
{" "}
|
||||||
|
<i className="bx bx-trash me-1 text-danger"></i>Delete
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -134,7 +134,7 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
// Handle the work area data
|
// Handle the work area data
|
||||||
else if ( entity.workArea )
|
else if ( entity.workArea )
|
||||||
{
|
{
|
||||||
debugger
|
|
||||||
|
|
||||||
let buildingId = infraObject[0].workArea.buildingId
|
let buildingId = infraObject[0].workArea.buildingId
|
||||||
|
|
||||||
@ -172,38 +172,6 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
setProject(updatedProject)
|
setProject(updatedProject)
|
||||||
}
|
}
|
||||||
// Handle the task (workItem) data
|
// Handle the task (workItem) data
|
||||||
else if (entity.workItem) {
|
|
||||||
const { buildingId, floorId, workAreaId, name, description } = entity.workItem;
|
|
||||||
const updatedBuildings = updatedProject.buildings.map((building) =>
|
|
||||||
building.id === buildingId
|
|
||||||
? {
|
|
||||||
...building,
|
|
||||||
floors: building.floors.map((floor) =>
|
|
||||||
floor.id === floorId
|
|
||||||
? {
|
|
||||||
...floor,
|
|
||||||
workAreas: floor.workAreas.map((workArea) =>
|
|
||||||
workArea.id === workAreaId
|
|
||||||
? {
|
|
||||||
...workArea,
|
|
||||||
tasks: workArea.tasks.map((task) =>
|
|
||||||
task.id === entity.workItem.id ? { ...task, name, description } : task
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: workArea
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: floor
|
|
||||||
),
|
|
||||||
}
|
|
||||||
: building
|
|
||||||
);
|
|
||||||
|
|
||||||
updatedProject.buildings = updatedBuildings;
|
|
||||||
|
|
||||||
|
|
||||||
cacheData("projectInfo", { projectId: updatedProject.id, data: updatedProject });
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
else {
|
||||||
console.error("Unsupported data type for submitData", entity);
|
console.error("Unsupported data type for submitData", entity);
|
||||||
@ -277,15 +245,56 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTaskModelFormSubmit = (updatedModel) => {
|
const handleTaskModelFormSubmit = ( updatedModel ) =>
|
||||||
|
{
|
||||||
if (updatedModel.id == "") updatedModel.id = 0;
|
if (updatedModel.id == "") updatedModel.id = 0;
|
||||||
|
const updatedProject = { ...project };
|
||||||
|
|
||||||
ProjectRepository.manageProjectTasks([updatedModel])
|
ProjectRepository.manageProjectTasks([updatedModel])
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
onDataChange("task-change");
|
onDataChange("task-change");
|
||||||
showToast("Details updated successfully.", "success");
|
showToast("Details updated successfully.", "success");
|
||||||
setClearFormTrigger(true);
|
// setClearFormTrigger( true );
|
||||||
|
|
||||||
|
|
||||||
|
if (response?.data[0]) {
|
||||||
|
const { workItemId,workItem} = response.data[0];
|
||||||
|
const updatedBuildings = updatedProject.buildings.map((building) =>
|
||||||
|
building.id == updatedModel.buildingID
|
||||||
|
? {
|
||||||
|
...building,
|
||||||
|
floors: building.floors.map((floor) =>
|
||||||
|
floor.id == updatedModel.floorId
|
||||||
|
? {
|
||||||
|
...floor,
|
||||||
|
workAreas: floor.workAreas.map((workArea) =>
|
||||||
|
workArea.id === workItem?.workAreaId
|
||||||
|
? {
|
||||||
|
...workArea,
|
||||||
|
workItems: workArea.workItems.some((existingItem) => existingItem.workItemId === workItem.workItemId)
|
||||||
|
? workArea.workItems // If the workItemId already exists, keep the current workItems
|
||||||
|
: [...workArea.workItems, workItem],
|
||||||
|
}
|
||||||
|
: workArea
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: floor
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: building
|
||||||
|
);
|
||||||
|
|
||||||
|
updatedProject.buildings = updatedBuildings;
|
||||||
|
|
||||||
|
|
||||||
|
cacheData( "projectInfo", {projectId: updatedProject.id, data: updatedProject} );
|
||||||
|
setProject(updatedProject)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
showToast(error.message, "error");
|
showToast(error.message, "error");
|
||||||
@ -456,7 +465,7 @@ const ProjectInfra = ({ data, activityMaster, onDataChange,eachSiteEngineer }) =
|
|||||||
onClick={() => openTaskModel()}
|
onClick={() => openTaskModel()}
|
||||||
>
|
>
|
||||||
<i className="bx bx-plus-circle me-2"></i>
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
Manage Tasks
|
Create Tasks
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ const ProjectRepository = {
|
|||||||
manageProjectAllocation: ( data ) => api.post( "/api/project/allocation", data ),
|
manageProjectAllocation: ( data ) => api.post( "/api/project/allocation", data ),
|
||||||
|
|
||||||
manageProjectInfra: (data) => api.post("/api/project/manage-infra", data),
|
manageProjectInfra: (data) => api.post("/api/project/manage-infra", data),
|
||||||
manageProjectTasks: (data) => api.post("/api/project/manage-infra", data),
|
manageProjectTasks: (data) => api.post("/api/project/task", data),
|
||||||
|
|
||||||
updateProject: (id, data) => api.put(`/api/project/update/${id}`, data),
|
updateProject: (id, data) => api.put(`/api/project/update/${id}`, data),
|
||||||
deleteProject: (id) => api.delete(`/projects/${id}`),
|
deleteProject: (id) => api.delete(`/projects/${id}`),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user