2025-03-26 13:00:33 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2025-03-26 05:48:23 +00:00
|
|
|
import RenameInput from "../../../ui/inputs/RenameInput";
|
|
|
|
import Vector3Input from "../customInput/Vector3Input";
|
feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management
- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
2025-04-22 08:58:29 +00:00
|
|
|
import { useSelectedZoneStore } from "../../../../store/visualization/useZoneStore";
|
2025-04-29 12:49:03 +00:00
|
|
|
import {
|
|
|
|
useEditPosition,
|
|
|
|
usezonePosition,
|
|
|
|
useZones,
|
|
|
|
usezoneTarget,
|
|
|
|
} from "../../../../store/store";
|
2025-04-21 06:23:42 +00:00
|
|
|
import { zoneCameraUpdate } from "../../../../services/visulization/zone/zoneCameraUpdation";
|
2025-03-26 05:48:23 +00:00
|
|
|
|
2025-03-26 06:52:04 +00:00
|
|
|
const ZoneProperties: React.FC = () => {
|
2025-03-27 06:58:17 +00:00
|
|
|
const { Edit, setEdit } = useEditPosition();
|
2025-03-26 13:00:33 +00:00
|
|
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
2025-03-27 06:58:17 +00:00
|
|
|
const { zonePosition, setZonePosition } = usezonePosition();
|
|
|
|
const { zoneTarget, setZoneTarget } = usezoneTarget();
|
2025-04-09 13:06:25 +00:00
|
|
|
const { zones, setZones } = useZones();
|
2025-03-27 06:58:17 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2025-04-29 12:49:03 +00:00
|
|
|
setZonePosition(selectedZone.zoneViewPortPosition);
|
|
|
|
setZoneTarget(selectedZone.zoneViewPortTarget);
|
|
|
|
}, [selectedZone?.zoneViewPortPosition, selectedZone?.zoneViewPortTarget]);
|
2025-03-26 06:52:04 +00:00
|
|
|
|
2025-03-29 13:51:20 +00:00
|
|
|
async function handleSetView() {
|
|
|
|
try {
|
|
|
|
const email = localStorage.getItem("email") || "";
|
|
|
|
const organization = email?.split("@")[1]?.split(".")[0];
|
2025-03-31 13:50:03 +00:00
|
|
|
|
2025-03-29 13:51:20 +00:00
|
|
|
let zonesdata = {
|
|
|
|
zoneId: selectedZone.zoneId,
|
|
|
|
viewPortposition: zonePosition,
|
2025-04-29 12:49:03 +00:00
|
|
|
viewPortCenter: zoneTarget,
|
2025-03-29 13:51:20 +00:00
|
|
|
};
|
2025-03-31 13:50:03 +00:00
|
|
|
|
2025-03-29 13:51:20 +00:00
|
|
|
let response = await zoneCameraUpdate(zonesdata, organization);
|
2025-04-07 12:29:52 +00:00
|
|
|
if (response.message === "updated successfully") {
|
|
|
|
setEdit(false);
|
|
|
|
} else {
|
2025-04-11 12:22:07 +00:00
|
|
|
// console.log(response);
|
2025-04-07 12:29:52 +00:00
|
|
|
}
|
2025-04-29 12:49:03 +00:00
|
|
|
} catch (error) {}
|
2025-03-26 06:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleEditView() {
|
2025-04-29 12:49:03 +00:00
|
|
|
setEdit(!Edit); // This will toggle the `Edit` state correctly
|
2025-03-26 06:52:04 +00:00
|
|
|
}
|
2025-03-26 13:00:33 +00:00
|
|
|
|
2025-04-09 13:06:25 +00:00
|
|
|
async function handleZoneNameChange(newName: string) {
|
|
|
|
const email = localStorage.getItem("email") || "";
|
|
|
|
const organization = email?.split("@")[1]?.split(".")[0];
|
|
|
|
const zonesdata = {
|
|
|
|
zoneId: selectedZone.zoneId,
|
2025-04-29 12:49:03 +00:00
|
|
|
zoneName: newName,
|
2025-04-09 13:06:25 +00:00
|
|
|
};
|
|
|
|
// Call your API to update the zone
|
|
|
|
let response = await zoneCameraUpdate(zonesdata, organization);
|
2025-04-29 12:49:03 +00:00
|
|
|
console.log("response: ", response);
|
2025-04-09 13:06:25 +00:00
|
|
|
if (response.message === "updated successfully") {
|
|
|
|
setZones((prevZones: any[]) =>
|
|
|
|
prevZones.map((zone) =>
|
|
|
|
zone.zoneId === selectedZone.zoneId
|
|
|
|
? { ...zone, zoneName: newName }
|
|
|
|
: zone
|
|
|
|
)
|
|
|
|
);
|
2025-04-15 12:58:37 +00:00
|
|
|
} else {
|
2025-04-11 12:22:07 +00:00
|
|
|
// console.log(response?.message);
|
2025-04-09 13:06:25 +00:00
|
|
|
}
|
2025-03-27 06:58:17 +00:00
|
|
|
}
|
2025-04-29 12:49:03 +00:00
|
|
|
function handleVectorChange(
|
|
|
|
key: "zoneViewPortTarget" | "zoneViewPortPosition",
|
|
|
|
newValue: [number, number, number]
|
|
|
|
) {
|
2025-03-27 06:58:17 +00:00
|
|
|
setSelectedZone((prev) => ({ ...prev, [key]: newValue }));
|
|
|
|
}
|
2025-04-15 12:58:37 +00:00
|
|
|
const checkZoneNameDuplicate = (name: string) => {
|
|
|
|
return zones.some(
|
|
|
|
(zone: any) =>
|
|
|
|
zone.zoneName.trim().toLowerCase() === name.trim().toLowerCase() &&
|
|
|
|
zone.zoneId !== selectedZone.zoneId
|
|
|
|
);
|
|
|
|
};
|
2025-03-26 06:52:04 +00:00
|
|
|
|
2025-03-26 05:48:23 +00:00
|
|
|
return (
|
|
|
|
<div className="zone-properties-container">
|
2025-04-29 12:49:03 +00:00
|
|
|
<section>
|
|
|
|
<div className="header">
|
|
|
|
<RenameInput
|
|
|
|
value={selectedZone.zoneName}
|
|
|
|
onRename={handleZoneNameChange}
|
|
|
|
checkDuplicate={checkZoneNameDuplicate}
|
|
|
|
/>
|
|
|
|
<div className="button" onClick={handleEditView}>
|
|
|
|
{Edit ? "Cancel" : "Edit"}
|
|
|
|
</div>
|
2025-03-26 06:52:04 +00:00
|
|
|
</div>
|
2025-04-29 12:49:03 +00:00
|
|
|
<Vector3Input
|
|
|
|
onChange={(value) => handleVectorChange("zoneViewPortTarget", value)}
|
|
|
|
header="Viewport Target"
|
|
|
|
value={zoneTarget as [number, number, number]}
|
|
|
|
disabled={!Edit}
|
|
|
|
/>
|
|
|
|
<Vector3Input
|
|
|
|
onChange={(value) =>
|
|
|
|
handleVectorChange("zoneViewPortPosition", value)
|
|
|
|
}
|
|
|
|
header="Viewport Position"
|
|
|
|
value={zonePosition as [number, number, number]}
|
|
|
|
disabled={!Edit}
|
|
|
|
/>
|
2025-03-27 06:58:17 +00:00
|
|
|
|
2025-04-29 12:49:03 +00:00
|
|
|
{Edit && (
|
|
|
|
<div className="button-save" onClick={handleSetView}>
|
|
|
|
Set View
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</section>
|
2025-03-26 05:48:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ZoneProperties;
|