Compare commits
No commits in common. "7d5d26272827799b1a7118a6265b3695d96e26aa" and "18e4b91754225cb58f24723bdf0e3f9f31e0bbb7" have entirely different histories.
7d5d262728
...
18e4b91754
@ -5,7 +5,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||||||
import ProjectRepository from "../../../repositories/ProjectRepository";
|
import ProjectRepository from "../../../repositories/ProjectRepository";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
import { useProjectDetails } from "../../../hooks/useProjects";
|
||||||
import { getCachedData } from "../../../slices/apiDataManager";
|
import {getCachedData} from "../../../slices/apiDataManager";
|
||||||
import showToast from "../../../services/toastService";
|
import showToast from "../../../services/toastService";
|
||||||
|
|
||||||
// Zod validation schema
|
// Zod validation schema
|
||||||
@ -29,8 +29,8 @@ const BuildingModel = ({
|
|||||||
const selectedProject = useSelector(
|
const selectedProject = useSelector(
|
||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
);
|
);
|
||||||
const [buildings, setBuildings] = useState([]);
|
const [buildings ,setBuildings] = useState([])
|
||||||
const projects_Details = getCachedData("projectInfo");
|
const projects_Details = getCachedData("projectInfo")
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
id: "",
|
id: "",
|
||||||
name: "",
|
name: "",
|
||||||
@ -80,21 +80,24 @@ const BuildingModel = ({
|
|||||||
|
|
||||||
const onSubmitHandler = async (data) => {
|
const onSubmitHandler = async (data) => {
|
||||||
onSubmit({ ...data, projectId: project.id });
|
onSubmit({ ...data, projectId: project.id });
|
||||||
reset({
|
reset( {
|
||||||
Id: "0",
|
Id:"0",
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
});
|
} );
|
||||||
if (data.Id !== "0") {
|
if ( data.Id !== "0" )
|
||||||
showToast("Building updated successfully.", "success");
|
{
|
||||||
} else {
|
showToast( "Building updated successfully.", "success" );
|
||||||
showToast("Building created successfully.", "success");
|
} else
|
||||||
|
{
|
||||||
|
showToast( "Building created successfully.", "success" );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect( () =>
|
||||||
setBuildings(projects_Details.data?.buildings);
|
{
|
||||||
}, [projects_Details]);
|
setBuildings(projects_Details.data?.buildings)
|
||||||
|
},[projects_Details])
|
||||||
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">
|
||||||
@ -119,24 +122,16 @@ const BuildingModel = ({
|
|||||||
handleBuildingChange(e);
|
handleBuildingChange(e);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
<option value="0">Add New Building</option>
|
<option value="0">Add New Building</option>
|
||||||
|
|
||||||
{project?.buildings?.length > 0 ? (
|
{project &&
|
||||||
project.buildings
|
project?.buildings?.length > 0 &&
|
||||||
.filter((building) => building?.name)
|
project?.buildings.map((building) => (
|
||||||
.sort((a, b) => {
|
|
||||||
const nameA = a.name || "";
|
|
||||||
const nameB = b.name || "";
|
|
||||||
return nameA?.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
.map((building) => (
|
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
))
|
))}
|
||||||
) : (
|
|
||||||
<option disabled>No buildings found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.Id && (
|
{errors.Id && (
|
||||||
<span className="danger-text">{errors.Id.message}</span>
|
<span className="danger-text">{errors.Id.message}</span>
|
||||||
|
|||||||
@ -135,23 +135,16 @@ const FloorModel = ({
|
|||||||
onChange={handleBuildigChange}
|
onChange={handleBuildigChange}
|
||||||
>
|
>
|
||||||
<option value="0">Select Building</option>
|
<option value="0">Select Building</option>
|
||||||
{buildings?.length > 0 &&
|
{buildings &&
|
||||||
|
buildings?.length > 0 &&
|
||||||
buildings
|
buildings
|
||||||
.filter((building) => building?.name)
|
?.slice()
|
||||||
.sort((a, b) => {
|
?.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
const nameA = a.name || "";
|
?.map((building) => (
|
||||||
const nameB = b.name || "";
|
|
||||||
return nameA?.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
.map((building) => (
|
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{buildings?.length === 0 && (
|
|
||||||
<option disabled>No buildings found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.buildingId && (
|
{errors.buildingId && (
|
||||||
<p className="text-danger">{errors.buildingId.message}</p>
|
<p className="text-danger">{errors.buildingId.message}</p>
|
||||||
@ -176,23 +169,14 @@ const FloorModel = ({
|
|||||||
) )} */}
|
) )} */}
|
||||||
|
|
||||||
{selectedBuilding &&
|
{selectedBuilding &&
|
||||||
selectedBuilding.floors?.length > 0 &&
|
selectedBuilding.floors.length > 0 &&
|
||||||
[...selectedBuilding.floors]
|
[...selectedBuilding.floors]
|
||||||
.filter((floor) => floor?.floorName)
|
?.sort((a, b) => a.floorName.localeCompare(b.floorName))
|
||||||
.sort((a, b) => {
|
?.map((floor) => (
|
||||||
const nameA = a.floorName || "";
|
|
||||||
const nameB = b.floorName || "";
|
|
||||||
return nameA?.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
.map((floor) => (
|
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
{floor.floorName}
|
{floor.floorName}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{selectedBuilding?.floors?.length === 0 && (
|
|
||||||
<option disabled>No floors found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.id && (
|
{errors.id && (
|
||||||
<p className="text-danger">{errors.id.message}</p>
|
<p className="text-danger">{errors.id.message}</p>
|
||||||
|
|||||||
@ -40,19 +40,24 @@ const TaskModel = ({
|
|||||||
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
|
const [selectedWorkArea, setSelectedWorkArea] = useState(null);
|
||||||
const [selectedActivity, setSelectedActivity] = useState(null);
|
const [selectedActivity, setSelectedActivity] = useState(null);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [activityData, setActivityData] = useState([]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
reset,
|
reset,
|
||||||
setValue,
|
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(taskSchema),
|
resolver: zodResolver(taskSchema),
|
||||||
defaultValues: defaultModel,
|
defaultValues: defaultModel,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (clearTrigger) {
|
||||||
|
resetForm();
|
||||||
|
onClearComplete();
|
||||||
|
}
|
||||||
|
}, [clearTrigger, onClearComplete]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Activity"));
|
dispatch(changeMaster("Activity"));
|
||||||
resetForm();
|
resetForm();
|
||||||
@ -99,7 +104,7 @@ const TaskModel = ({
|
|||||||
|
|
||||||
const handleActivityChange = (e) => {
|
const handleActivityChange = (e) => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
const activity = activityData.find((b) => b.id === Number(value));
|
const activity = activities.find((b) => b.id === Number(value));
|
||||||
setSelectedActivity(activity);
|
setSelectedActivity(activity);
|
||||||
reset((prev) => ({
|
reset((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@ -110,9 +115,14 @@ const TaskModel = ({
|
|||||||
const onSubmitForm = async (data) => {
|
const onSubmitForm = async (data) => {
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
await onSubmit(data);
|
await onSubmit(data);
|
||||||
setValue("plannedWork", 0);
|
reset({
|
||||||
setValue("completedWork", 0);
|
buildingID: data.buildingID,
|
||||||
dispatch(changeMaster("Activity"));
|
floorId: data.floorId,
|
||||||
|
workAreaId: data.workAreaId,
|
||||||
|
activityID: data.activityID,
|
||||||
|
plannedWork: 0,
|
||||||
|
completedWork: 0,
|
||||||
|
});
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -125,11 +135,6 @@ const TaskModel = ({
|
|||||||
reset(defaultModel);
|
reset(defaultModel);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (activities && activities.length > 0) {
|
|
||||||
setActivityData(activities);
|
|
||||||
}
|
|
||||||
}, [activities]);
|
|
||||||
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">
|
||||||
@ -158,18 +163,13 @@ const TaskModel = ({
|
|||||||
>
|
>
|
||||||
<option value="0">Select Building</option>
|
<option value="0">Select Building</option>
|
||||||
{project.buildings
|
{project.buildings
|
||||||
?.filter((building) => building?.name) // Ensure valid name
|
?.slice()
|
||||||
?.sort((a, b) => a.name?.localeCompare(b.name))
|
?.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
?.map((building) => (
|
?.map((building) => (
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{project.buildings?.filter((building) => building?.name)
|
|
||||||
.length === 0 && (
|
|
||||||
<option disabled>No buildings found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.buildingID && (
|
{errors.buildingID && (
|
||||||
<p className="danger-text">{errors.buildingID.message}</p>
|
<p className="danger-text">{errors.buildingID.message}</p>
|
||||||
@ -190,10 +190,7 @@ const TaskModel = ({
|
|||||||
>
|
>
|
||||||
<option value="0">Select Floor</option>
|
<option value="0">Select Floor</option>
|
||||||
{selectedBuilding.floors
|
{selectedBuilding.floors
|
||||||
?.filter(
|
?.slice()
|
||||||
(floor) =>
|
|
||||||
floor?.floorName && Array.isArray(floor.workAreas)
|
|
||||||
)
|
|
||||||
?.sort((a, b) => a.floorName.localeCompare(b.floorName))
|
?.sort((a, b) => a.floorName.localeCompare(b.floorName))
|
||||||
?.map((floor) => (
|
?.map((floor) => (
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
@ -201,11 +198,6 @@ const TaskModel = ({
|
|||||||
Areas)
|
Areas)
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{selectedBuilding.floors?.filter(
|
|
||||||
(floor) =>
|
|
||||||
floor?.floorName && Array.isArray(floor.workAreas)
|
|
||||||
).length === 0 && <option disabled>No floors found</option>}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.floorId && (
|
{errors.floorId && (
|
||||||
<p className="danger-text">{errors.floorId.message}</p>
|
<p className="danger-text">{errors.floorId.message}</p>
|
||||||
@ -227,19 +219,13 @@ const TaskModel = ({
|
|||||||
>
|
>
|
||||||
<option value="0">Select Work Area</option>
|
<option value="0">Select Work Area</option>
|
||||||
{selectedFloor.workAreas
|
{selectedFloor.workAreas
|
||||||
?.filter((workArea) => workArea?.areaName)
|
?.slice()
|
||||||
?.sort((a, b) => a.areaName.localeCompare(b.areaName))
|
?.sort((a, b) => a.areaName.localeCompare(b.areaName))
|
||||||
?.map((workArea) => (
|
?.map((workArea) => (
|
||||||
<option key={workArea.id} value={workArea.id}>
|
<option key={workArea.id} value={workArea.id}>
|
||||||
{workArea.areaName}
|
{workArea.areaName}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{selectedFloor.workAreas?.filter(
|
|
||||||
(workArea) => workArea?.areaName
|
|
||||||
).length === 0 && (
|
|
||||||
<option disabled>No work areas found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.workAreaId && (
|
{errors.workAreaId && (
|
||||||
<p className="danger-text">{errors.workAreaId.message}</p>
|
<p className="danger-text">{errors.workAreaId.message}</p>
|
||||||
@ -260,27 +246,17 @@ const TaskModel = ({
|
|||||||
onChange={handleActivityChange}
|
onChange={handleActivityChange}
|
||||||
>
|
>
|
||||||
<option value="0">Select Activity</option>
|
<option value="0">Select Activity</option>
|
||||||
{activityData && activityData.length > 0 ? (
|
{activities
|
||||||
activityData
|
|
||||||
?.slice()
|
?.slice()
|
||||||
?.sort((a, b) => {
|
?.sort((a, b) =>
|
||||||
const nameA = a?.activityName || "";
|
a.activityName.localeCompare(b.activityName)
|
||||||
const nameB = b?.activityName || "";
|
)
|
||||||
return nameA.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
?.map((activity) => (
|
?.map((activity) => (
|
||||||
<option key={activity.id} value={activity.id}>
|
<option key={activity.id} value={activity.id}>
|
||||||
{activity.name ||
|
{activity.activityName}
|
||||||
activity.activityName ||
|
|
||||||
activity.title ||
|
|
||||||
`Unnamed (id: ${activity.id})`}
|
|
||||||
</option>
|
</option>
|
||||||
))
|
))}
|
||||||
) : (
|
|
||||||
<option disabled>No activities available</option> // Fallback if activities are empty
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
{errors.activityID && (
|
{errors.activityID && (
|
||||||
<p className="danger-text">{errors.activityID.message}</p>
|
<p className="danger-text">{errors.activityID.message}</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -158,22 +158,13 @@ const WorkAreaModel = ({
|
|||||||
>
|
>
|
||||||
<option value="0">Select Building</option>
|
<option value="0">Select Building</option>
|
||||||
{project?.buildings
|
{project?.buildings
|
||||||
?.filter((building) => building?.name)
|
?.slice()
|
||||||
?.sort((a, b) => {
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
const nameA = a.name || "";
|
.map((building) => (
|
||||||
const nameB = b.name || "";
|
|
||||||
return nameA?.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
?.map((building) => (
|
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
{building.name}
|
{building.name}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{project?.buildings?.filter((building) => building?.name)
|
|
||||||
.length === 0 && (
|
|
||||||
<option disabled>No buildings found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.buildingId && <span>{errors.buildingId.message}</span>}
|
{errors.buildingId && <span>{errors.buildingId.message}</span>}
|
||||||
</div>
|
</div>
|
||||||
@ -193,21 +184,13 @@ const WorkAreaModel = ({
|
|||||||
>
|
>
|
||||||
<option value="0">Select Floor</option>
|
<option value="0">Select Floor</option>
|
||||||
{selectedBuilding.floors
|
{selectedBuilding.floors
|
||||||
?.filter((floor) => floor?.floorName)
|
?.slice()
|
||||||
?.sort((a, b) => {
|
.sort((a, b) => a.floorName.localeCompare(b.floorName))
|
||||||
const nameA = a.floorName || "";
|
.map((floor) => (
|
||||||
const nameB = b.floorName || "";
|
|
||||||
return nameA.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
?.map((floor) => (
|
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
{floor.floorName}
|
{floor.floorName}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{selectedBuilding.floors?.filter(
|
|
||||||
(floor) => floor?.floorName
|
|
||||||
).length === 0 && <option disabled>No floors found</option>}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.floorId && <span>{errors.floorId.message}</span>}
|
{errors.floorId && <span>{errors.floorId.message}</span>}
|
||||||
</div>
|
</div>
|
||||||
@ -226,24 +209,11 @@ const WorkAreaModel = ({
|
|||||||
onChange={handleWorkAreaChange}
|
onChange={handleWorkAreaChange}
|
||||||
>
|
>
|
||||||
<option value="0">Create New Work Area</option>
|
<option value="0">Create New Work Area</option>
|
||||||
{selectedFloor?.workAreas
|
{selectedFloor?.workAreas?.map((workArea) => (
|
||||||
?.filter((workArea) => workArea?.areaName)
|
|
||||||
?.sort((a, b) => {
|
|
||||||
const nameA = a.areaName || "";
|
|
||||||
const nameB = b.areaName || "";
|
|
||||||
return nameA.localeCompare(nameB);
|
|
||||||
})
|
|
||||||
?.map((workArea) => (
|
|
||||||
<option key={workArea.id} value={workArea.id}>
|
<option key={workArea.id} value={workArea.id}>
|
||||||
{workArea.areaName}
|
{workArea.areaName}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{selectedFloor?.workAreas?.filter(
|
|
||||||
(workArea) => workArea?.areaName
|
|
||||||
).length === 0 && (
|
|
||||||
<option disabled>No work areas found</option>
|
|
||||||
)}
|
|
||||||
</select>
|
</select>
|
||||||
{errors.id && <span>{errors.id.message}</span>}
|
{errors.id && <span>{errors.id.message}</span>}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user