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