diff --git a/app/src/components/layout/sidebarRight/SideBarRight.tsx b/app/src/components/layout/sidebarRight/SideBarRight.tsx index a29d930..737271e 100644 --- a/app/src/components/layout/sidebarRight/SideBarRight.tsx +++ b/app/src/components/layout/sidebarRight/SideBarRight.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import Header from "./Header"; -import useModuleStore from "../../../store/useModuleStore"; +import useModuleStore, { useSubModuleStore } from "../../../store/useModuleStore"; import { AnalysisIcon, MechanicsIcon, @@ -14,15 +14,17 @@ import GlobalProperties from "./properties/GlobalProperties"; import AsstePropertiies from "./properties/AssetProperties"; import Analysis from "./analysis/Analysis"; import Simulations from "./simulation/Simulations"; +import { useSelectedActionSphere } from "../../../store/store"; const SideBarRight: React.FC = () => { const { activeModule } = useModuleStore(); - const [activeList, setActiveList] = useState("properties"); + const { selectedActionSphere } = useSelectedActionSphere(); + const { subModule, setSubModule } = useSubModuleStore(); const { toggleUI } = useToggleStore(); - // Reset activeList whenever activeModule changes + // Reset subModule whenever activeModule changes useEffect(() => { - setActiveList("properties"); + setSubModule("properties"); }, [activeModule]); return ( @@ -31,38 +33,34 @@ const SideBarRight: React.FC = () => { {toggleUI && (
setActiveList("properties")} + className={`sidebar-action-list ${subModule === "properties" ? "active" : "" + }`} + onClick={() => setSubModule("properties")} > - +
{activeModule === "simulation" && ( <>
setActiveList("mechanics")} + className={`sidebar-action-list ${subModule === "mechanics" ? "active" : "" + }`} + onClick={() => setSubModule("mechanics")} > - +
setActiveList("simulations")} + className={`sidebar-action-list ${subModule === "simulations" ? "active" : "" + }`} + onClick={() => setSubModule("simulations")} > - +
setActiveList("analysis")} + className={`sidebar-action-list ${subModule === "analysis" ? "active" : "" + }`} + onClick={() => setSubModule("analysis")} > - +
)} @@ -70,7 +68,7 @@ const SideBarRight: React.FC = () => { )} {/* process builder */} {toggleUI && - activeList === "properties" && + subModule === "properties" && activeModule !== "visualization" && (
@@ -84,21 +82,28 @@ const SideBarRight: React.FC = () => { {toggleUI && activeModule === "simulation" && ( <> - {activeList === "mechanics" && ( + {(subModule === "mechanics" && selectedActionSphere) && (
)} - {activeList === "analysis" && ( + {(subModule === "mechanics" && !selectedActionSphere) && ( +
+
+ {/* */} +
+
+ )} + {subModule === "analysis" && (
)} - {activeList === "simulations" && ( + {subModule === "simulations" && (
diff --git a/app/src/components/layout/sidebarRight/mechanics/MachineMechanics.tsx b/app/src/components/layout/sidebarRight/mechanics/MachineMechanics.tsx index 9aa27bb..85ae67a 100644 --- a/app/src/components/layout/sidebarRight/mechanics/MachineMechanics.tsx +++ b/app/src/components/layout/sidebarRight/mechanics/MachineMechanics.tsx @@ -11,8 +11,11 @@ import LabledDropdown from "../../../ui/inputs/LabledDropdown"; import RegularDropDown from "../../../ui/inputs/RegularDropDown"; import { handleResize } from "../../../../functions/handleResizePannel"; import EyeDropInput from "../../../ui/inputs/EyeDropInput"; +import { useSelectedActionSphere } from "../../../../store/store"; const MachineMechanics: React.FC = () => { + const { selectedActionSphere, setSelectedActionSphere } = useSelectedActionSphere(); + console.log('selectedActionSphere: ', selectedActionSphere); const [actionList, setActionList] = useState([]); const [triggerList, setTriggerList] = useState([]); const [selectedItem, setSelectedItem] = useState<{ @@ -68,8 +71,8 @@ const MachineMechanics: React.FC = () => { return (
-
Selected Object
-
+
{selectedActionSphere.path.modelName}
+ {/*
Process:
"} @@ -79,7 +82,7 @@ const MachineMechanics: React.FC = () => {
-
+
*/}
@@ -97,12 +100,11 @@ const MachineMechanics: React.FC = () => { {actionList.map((action, index) => (
{ {triggerList.map((trigger, index) => (
{ label="Speed" value="" activeOption=".mm" - onChange={() => {}} + onChange={() => { }} /> diff --git a/app/src/components/ui/componets/DisplayZone.tsx b/app/src/components/ui/componets/DisplayZone.tsx index 3bf6b8f..57fb4eb 100644 --- a/app/src/components/ui/componets/DisplayZone.tsx +++ b/app/src/components/ui/componets/DisplayZone.tsx @@ -55,9 +55,9 @@ const DisplayZone: React.FC = ({ const [selectedOption, setSelectedOption] = React.useState( null ); - console.log('setSelectedOption: ', setSelectedOption); + // console.log('setSelectedOption: ', setSelectedOption); const [options, setOptions] = React.useState([]); - console.log('setOptions: ', setOptions); + // console.log('setOptions: ', setOptions); // Scroll to the selected option when it changes useEffect(() => { diff --git a/app/src/modules/builder/groups/zoneGroup.tsx b/app/src/modules/builder/groups/zoneGroup.tsx index bd0087e..3bf2b59 100644 --- a/app/src/modules/builder/groups/zoneGroup.tsx +++ b/app/src/modules/builder/groups/zoneGroup.tsx @@ -83,7 +83,7 @@ const ZoneGroup: React.FC = () => { useEffect(() => { - localStorage.setItem('zones', zones); + localStorage.setItem('zones', JSON.stringify(zones)); }, [zones]) diff --git a/app/src/modules/scene/postProcessing/postProcessing.tsx b/app/src/modules/scene/postProcessing/postProcessing.tsx index 1c6c7ab..b94f64f 100644 --- a/app/src/modules/scene/postProcessing/postProcessing.tsx +++ b/app/src/modules/scene/postProcessing/postProcessing.tsx @@ -1,7 +1,7 @@ import * as THREE from 'three' import { EffectComposer, N8AO, Outline } from '@react-three/postprocessing' import { BlendFunction } from 'postprocessing' -import { useDeletableFloorItem, useSelectedEventSphere, useSelectedPath, useSelectedWallItem, useselectedFloorItem } from '../../../store/store'; +import { useDeletableFloorItem, useSelectedActionSphere, useSelectedPath, useSelectedWallItem, useselectedFloorItem } from '../../../store/store'; import * as Types from '../../../types/world/worldTypes' import * as CONSTANTS from '../../../types/world/worldConstants'; @@ -9,7 +9,7 @@ export default function PostProcessing() { const { deletableFloorItem, setDeletableFloorItem } = useDeletableFloorItem(); const { selectedWallItem, setSelectedWallItem } = useSelectedWallItem(); const { selectedFloorItem, setselectedFloorItem } = useselectedFloorItem(); - const { selectedEventSphere } = useSelectedEventSphere(); + const { selectedActionSphere } = useSelectedActionSphere(); const { selectedPath } = useSelectedPath(); function flattenChildren(children: any[]) { @@ -75,9 +75,9 @@ export default function PostProcessing() { xRay={true} /> } - {selectedEventSphere && + {selectedActionSphere && { - const { selectedEventSphere, setSelectedEventSphere } = useSelectedEventSphere(); - - const { events, triggers }: any = useControls({ - events: { - value: selectedEventSphere?.point?.userData?.events || '', - options: ['Event1', 'Event2', 'Event3'], - onChange: (newEvent: string) => updatePathData(newEvent, 'events') - }, - triggers: { - value: selectedEventSphere?.point?.userData?.triggers || '', - options: ['None', 'Trigger1', 'Trigger2', 'Trigger3'], - onChange: (newTrigger: string) => updatePathData(newTrigger, 'triggers') - }, - }); - - function updatePathData(value: string, key: 'events' | 'triggers') { - if (!selectedEventSphere) return; - - const updatedPaths = simulationPaths.map((path) => - path.modeluuid === selectedEventSphere.path.modeluuid - ? { - ...path, - points: path.points.map((point) => - point.uuid === selectedEventSphere.point.uuid - ? { ...point, [key]: value } - : point - ), - } - : path - ); - console.log('updatedPaths: ', updatedPaths); - setSimulationPaths(updatedPaths); - } - - return null; -}; - -export default EventsControl; diff --git a/app/src/modules/simulation/path/pathCreation.tsx b/app/src/modules/simulation/path/pathCreation.tsx index f79d646..3bf865d 100644 --- a/app/src/modules/simulation/path/pathCreation.tsx +++ b/app/src/modules/simulation/path/pathCreation.tsx @@ -1,16 +1,18 @@ import * as THREE from 'three'; import { useRef, useState, useEffect } from 'react'; import { Sphere, TransformControls } from '@react-three/drei'; -import { useIsConnecting, useRenderDistance, useSelectedEventSphere, useSelectedPath, useSimulationPaths } from '../../../store/store'; +import { useIsConnecting, useRenderDistance, useSelectedActionSphere, useSelectedPath, useSimulationPaths } from '../../../store/store'; import { useFrame, useThree } from '@react-three/fiber'; +import { useSubModuleStore } from '../../../store/useModuleStore'; interface Path { modeluuid: string; + modelName: string; points: { uuid: string; position: [number, number, number]; rotation: [number, number, number]; - events: { uuid: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; + actions: { uuid: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; triggers: { uuid: string; type: string; isUsed: boolean }[] | []; }[]; pathPosition: [number, number, number]; @@ -20,7 +22,8 @@ interface Path { function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject }) { const { renderDistance } = useRenderDistance(); - const { setSelectedEventSphere, selectedEventSphere } = useSelectedEventSphere(); + const { setSubModule } = useSubModuleStore(); + const { setSelectedActionSphere, selectedActionSphere } = useSelectedActionSphere(); const { setSelectedPath } = useSelectedPath(); const { simulationPaths, setSimulationPaths } = useSimulationPaths(); const { isConnecting, setIsConnecting } = useIsConnecting(); @@ -34,7 +37,7 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject useEffect(() => { setTransformMode(null); const handleKeyDown = (e: KeyboardEvent) => { - if (!selectedEventSphere) return; + if (!selectedActionSphere) return; if (e.key === 'g') { setTransformMode(prev => prev === 'translate' ? null : 'translate'); } @@ -45,7 +48,7 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); - }, [selectedEventSphere]); + }, [selectedActionSphere]); useFrame(() => { Object.values(groupRefs.current).forEach(group => { @@ -57,23 +60,23 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject }); const updateSimulationPaths = () => { - if (!selectedEventSphere) return; + if (!selectedActionSphere) return; const updatedPaths: Path[] = simulationPaths.map((path) => ({ ...path, points: path.points.map((point) => - point.uuid === selectedEventSphere.point.uuid + point.uuid === selectedActionSphere.point.uuid ? { ...point, position: [ - selectedEventSphere.point.position.x, - selectedEventSphere.point.position.y, - selectedEventSphere.point.position.z, + selectedActionSphere.point.position.x, + selectedActionSphere.point.position.y, + selectedActionSphere.point.position.z, ], rotation: [ - selectedEventSphere.point.rotation.x, - selectedEventSphere.point.rotation.y, - selectedEventSphere.point.rotation.z, + selectedActionSphere.point.rotation.x, + selectedActionSphere.point.rotation.y, + selectedActionSphere.point.rotation.z, ] } : point @@ -100,11 +103,12 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject if (isConnecting) return; e.stopPropagation(); setSelectedPath({ path, group: groupRefs.current[path.modeluuid] }); - setSelectedEventSphere(null); + setSelectedActionSphere(null); setTransformMode(null); }} onPointerMissed={() => { setSelectedPath(null); + setSubModule('properties'); }} > {path.points.map((point, index) => ( @@ -118,14 +122,18 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject onClick={(e) => { if (isConnecting) return; e.stopPropagation(); - setSelectedEventSphere({ + setSelectedActionSphere({ path, point: sphereRefs.current[point.uuid] }); + setSubModule('mechanics'); setSelectedPath(null); }} userData={{ point, path }} - onPointerMissed={() => setSelectedEventSphere(null)} + onPointerMissed={() => { + setSubModule('properties'); + setSelectedActionSphere(null) + }} > diff --git a/app/src/modules/simulation/simulation.tsx b/app/src/modules/simulation/simulation.tsx index 6851e9d..e57152d 100644 --- a/app/src/modules/simulation/simulation.tsx +++ b/app/src/modules/simulation/simulation.tsx @@ -1,5 +1,5 @@ import { useState, useEffect, useRef } from 'react'; -import { useConnections, useFloorItems, useSelectedEventSphere, useSelectedPath, useSimulationPaths } from '../../store/store'; +import { useConnections, useFloorItems, useSelectedActionSphere, useSelectedPath, useSimulationPaths } from '../../store/store'; import { useThree } from '@react-three/fiber'; import * as THREE from 'three'; import Behaviour from './behaviour/behaviour'; @@ -19,10 +19,10 @@ function Simulation() { }, [simulationPaths]); // useEffect(() => { - // if (selectedEventSphere) { - // console.log('selectedEventSphere: ', selectedEventSphere); + // if (selectedActionSphere) { + // console.log('selectedActionSphere: ', selectedActionSphere); // } - // }, [selectedEventSphere]); + // }, [selectedActionSphere]); // useEffect(() => { // if (selectedPath) { diff --git a/app/src/modules/simulation/simulationUI.tsx b/app/src/modules/simulation/simulationUI.tsx new file mode 100644 index 0000000..57da1f0 --- /dev/null +++ b/app/src/modules/simulation/simulationUI.tsx @@ -0,0 +1,381 @@ +import { useMemo, useState } from 'react'; +import { useSelectedActionSphere, useToggleView, useSimulationPaths, useSelectedPath, useStartSimulation } from '../../store/store'; +import * as THREE from 'three'; +import useModuleStore from '../../store/useModuleStore'; + +function SimulationUI() { + const { ToggleView } = useToggleView(); + const { activeModule } = useModuleStore(); + const { startSimulation, setStartSimulation } = useStartSimulation(); + const { selectedActionSphere } = useSelectedActionSphere(); + const { selectedPath, setSelectedPath } = useSelectedPath(); + const { simulationPaths, setSimulationPaths } = useSimulationPaths(); + + const handleAddAction = () => { + if (!selectedActionSphere) return; + + const newAction = { uuid: THREE.MathUtils.generateUUID(), type: 'Inherit', material: 'Inherit', delay: 'Inherit', spawnInterval: 'Inherit', isUsed: false }; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { ...point, actions: [...point.actions, newAction] } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleDeleteAction = (uuid: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { ...point, actions: point.actions.filter(action => action.uuid !== uuid) } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleActionSelect = (uuid: string, actionType: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + actions: point.actions.map((action) => + action.uuid === uuid ? { ...action, type: actionType } : action + ), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleMaterialSelect = (uuid: string, material: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + actions: point.actions.map((action) => + action.uuid === uuid ? { ...action, material } : action + ), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleDelayChange = (uuid: string, delay: number | string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + actions: point.actions.map((action) => + action.uuid === uuid ? { ...action, delay } : action + ), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleSpawnIntervalChange = (uuid: string, spawnInterval: number | string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + actions: point.actions.map((action) => + action.uuid === uuid ? { ...action, spawnInterval } : action + ), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleSpeedChange = (speed: number) => { + if (!selectedPath) return; + + const updatedPaths = simulationPaths.map((path) => + path.modeluuid === selectedPath.path.modeluuid ? { ...path, speed } : path + ); + + setSimulationPaths(updatedPaths); + setSelectedPath({ ...selectedPath, path: { ...selectedPath.path, speed } }); + }; + + const handleAddTrigger = () => { + if (!selectedActionSphere) return; + + const newTrigger = { uuid: THREE.MathUtils.generateUUID(), type: '', isUsed: false }; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { ...point, triggers: [...point.triggers, newTrigger] } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleDeleteTrigger = (uuid: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { ...point, triggers: point.triggers.filter(trigger => trigger.uuid !== uuid) } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleTriggerSelect = (uuid: string, triggerType: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + triggers: point.triggers.map((trigger) => + trigger.uuid === uuid ? { ...trigger, type: triggerType } : trigger + ), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleResetPath = () => { + if (!selectedPath) return; + + }; + + + const handleActionToggle = (uuid: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + actions: point.actions.map((action) => ({ + ...action, + isUsed: action.uuid === uuid ? !action.isUsed : false, + })), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const handleTriggerToggle = (uuid: string) => { + if (!selectedActionSphere) return; + + const updatedPaths = simulationPaths.map((path) => ({ + ...path, + points: path.points.map((point) => + point.uuid === selectedActionSphere.point.uuid + ? { + ...point, + triggers: point.triggers.map((trigger) => ({ + ...trigger, + isUsed: trigger.uuid === uuid ? !trigger.isUsed : false, + })), + } + : point + ), + })); + + setSimulationPaths(updatedPaths); + }; + + const selectedPoint = useMemo(() => { + if (!selectedActionSphere) return null; + return simulationPaths.flatMap((path) => path.points).find((point) => point.uuid === selectedActionSphere.point.uuid); + }, [selectedActionSphere, simulationPaths]); + + return ( + <> + {activeModule === "simulation" && ( +
+ {!ToggleView && ( + <> + + + {selectedPath && ( +
+ + handleSpeedChange(parseFloat(e.target.value))} + /> +
+ )} + + {selectedActionSphere && ( +
+ + + + {selectedPoint?.actions.map((action) => ( +
+ + + + + {(action.type === 'Spawn' || action.type === 'Swap') && ( +
+ +
+ )} + + {action.type === 'Delay' && ( +
+ + handleDelayChange(action.uuid, parseInt(e.target.value) || 'Inherit')} + /> + +
+ )} + + {action.type === 'Spawn' && ( +
+ + handleSpawnIntervalChange(action.uuid, parseInt(e.target.value) || 'Inherit')} + /> + +
+ )} +
+
+ ))} + +
+ + {selectedPoint?.triggers.map((trigger) => ( +
+ + + +
+
+ ))} + + +
+ )} + + {selectedPath && ( +
+ +
+ )} + + )} +
+ )} + + ); +} + +export default SimulationUI; \ No newline at end of file diff --git a/app/src/pages/Project.tsx b/app/src/pages/Project.tsx index a1af9db..33c3a1b 100644 --- a/app/src/pages/Project.tsx +++ b/app/src/pages/Project.tsx @@ -8,6 +8,7 @@ import Tools from "../components/ui/Tools"; import Scene from "../modules/scene/scene"; import { useSocketStore, useFloorItems, useOrganization, useUserName, useWallItems, useZones } from "../store/store"; import { useNavigate } from "react-router-dom"; +import SimulationUI from "../modules/simulation/simulationUI"; const Project: React.FC = () => { let navigate = useNavigate(); @@ -45,6 +46,7 @@ const Project: React.FC = () => { {activeModule === "visualization" && } +
); }; diff --git a/app/src/pages/UserAuth.tsx b/app/src/pages/UserAuth.tsx index 5b3f16c..b89f34e 100644 --- a/app/src/pages/UserAuth.tsx +++ b/app/src/pages/UserAuth.tsx @@ -2,6 +2,9 @@ import React, { useState, FormEvent } from "react"; import { useNavigate } from "react-router-dom"; import { LogoIconLarge } from "../components/icons/Logo"; import { EyeIcon } from "../components/icons/ExportCommonIcons"; +import { useOrganization, useUserName } from "../store/store"; +import { signInApi } from "../services/factoryBuilder/signInSignUp/signInApi"; +import { signUpApi } from "../services/factoryBuilder/signInSignUp/signUpApi"; // import LoadingPage from "../components/templates/LoadingPage"; const UserAuth: React.FC = () => { @@ -9,34 +12,50 @@ const UserAuth: React.FC = () => { const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(""); - const [isSignIn, setIsSignIn] = useState(true); // Toggle between login and register - const [userName, setUserName] = useState(""); // Username for registration + const [isSignIn, setIsSignIn] = useState(true); + const { userName, setUserName } = useUserName(); + const { organization, setOrganization } = useOrganization(); const navigate = useNavigate(); - const handleLogin = (e: FormEvent) => { + const handleLogin = async (e: FormEvent) => { e.preventDefault(); - // Dummy validation for "account not found" - if (email !== "user@example.com") { - setError("Account not found"); - } else { - setError(""); - console.log("Login Successful!"); - console.log("Email:", email); - console.log("Password:", password); - } + + const organization = (email.split("@")[1]).split(".")[0]; + try { + const res = await signInApi(email, password, organization); + + if (res.message === "login successfull") { + setError(""); + setOrganization(organization); + setUserName(res.name); + localStorage.setItem("userId", res.userId); + localStorage.setItem("email", res.email); + localStorage.setItem("userName", res.name); + if (res.isShare) { + navigate("/Project"); + } + } else if (res.message === "User Not Found!!! Kindly signup...") { + setError("Account not found"); + } + } catch (error) { } }; - const handleRegister = (e: FormEvent) => { + const handleRegister = async (e: FormEvent) => { e.preventDefault(); - // Dummy validation for registration if (email && password && userName) { setError(""); - console.log("Registration Successful!"); - console.log("Username:", userName); - console.log("Email:", email); - console.log("Password:", password); - setIsSignIn(true); + try { + const organization = (email.split("@")[1]).split(".")[0]; + const res = await signUpApi(userName, email, password, organization); + + if (res.message === "New User created") { + setIsSignIn(true); + } + if (res.message === "User already exists") { + setError("User already exists"); + } + } catch (error) { } } else { setError("Please fill all the fields!"); } @@ -97,6 +116,7 @@ const UserAuth: React.FC = () => { )} setEmail(e.target.value)} @@ -104,6 +124,7 @@ const UserAuth: React.FC = () => { />
{ +export const signInApi = async (email: string, password: Object, organization: Object) => { try { const response = await fetch(`${url_Backend_dwinzo}/api/v1/login`, { method: "POST", diff --git a/app/src/services/factoryBuilder/signInSignUp/signUpApi.ts b/app/src/services/factoryBuilder/signInSignUp/signUpApi.ts index 87ded2b..c27b381 100644 --- a/app/src/services/factoryBuilder/signInSignUp/signUpApi.ts +++ b/app/src/services/factoryBuilder/signInSignUp/signUpApi.ts @@ -1,6 +1,6 @@ let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; -export const signUp = async (userName: string, email: string, password: Object, organization: Object) => { +export const signUpApi = async (userName: string, email: string, password: Object, organization: Object) => { try { const response = await fetch(`${url_Backend_dwinzo}/api/v1/signup`, { method: "POST", @@ -11,7 +11,7 @@ export const signUp = async (userName: string, email: string, password: Object, }); if (!response.ok) { - throw new Error("Failed to signUp"); + throw new Error("Failed to signUpApi"); } const result = await response.json(); diff --git a/app/src/store/store.ts b/app/src/store/store.ts index f14b808..d92d5bb 100644 --- a/app/src/store/store.ts +++ b/app/src/store/store.ts @@ -283,9 +283,9 @@ export const useDrawMaterialPath = create((set: any) => ({ setDrawMaterialPath: (x: any) => set({ drawMaterialPath: x }), })); -export const useSelectedEventSphere = create((set: any) => ({ - selectedEventSphere: undefined, - setSelectedEventSphere: (x: any) => set({ selectedEventSphere: x }), +export const useSelectedActionSphere = create((set: any) => ({ + selectedActionSphere: undefined, + setSelectedActionSphere: (x: any) => set({ selectedActionSphere: x }), })); export const useSelectedPath = create((set: any) => ({ @@ -293,11 +293,77 @@ export const useSelectedPath = create((set: any) => ({ setSelectedPath: (x: any) => set({ selectedPath: x }), })); -export const useSimulationPaths = create((set) => ({ +interface Path { + modeluuid: string; + modelName: string; + points: { + uuid: string; + position: [number, number, number]; + rotation: [number, number, number]; + actions: { uuid: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; + triggers: { uuid: string; type: string; isUsed: boolean }[] | []; + }[]; + pathPosition: [number, number, number]; + pathRotation: [number, number, number]; + speed: number; +} + +interface SimulationPathsStore { + simulationPaths: Path[]; + setSimulationPaths: (paths: Path[]) => void; +} + +export const useSimulationPaths = create((set) => ({ simulationPaths: [], setSimulationPaths: (paths) => set({ simulationPaths: paths }), })); + +// interface Point { +// uuid: string; +// position: [number, number, number]; +// rotation: [number, number, number]; +// event: { +// uuid: string; +// type: string; +// material: string; +// delay: number | string; +// spawnInterval: number | string; +// isUsed: boolean; +// }; +// trigger: { +// uuid: string; +// type: string; +// isUsed: boolean; +// }; +// } + +// interface Process { +// processId: string; +// processName: string; +// points: Point[]; +// pathPosition: [number, number, number]; +// pathRotation: [number, number, number]; +// speed: number; +// isUsed: boolean; +// } + +// interface Path { +// modeluuid: string; +// processes: Process[]; +// } + +// interface SimulationPathsStore { +// simulationPaths: Path[]; +// setSimulationPaths: (paths: Path[]) => void; +// } + +// export const useSimulationPaths = create((set) => ({ +// simulationPaths: [], +// setSimulationPaths: (paths) => set({ simulationPaths: paths }), +// })); + + export const useConnections = create((set) => ({ connections: [], diff --git a/app/src/store/useModuleStore.ts b/app/src/store/useModuleStore.ts index c7e1e98..6373af5 100644 --- a/app/src/store/useModuleStore.ts +++ b/app/src/store/useModuleStore.ts @@ -1,4 +1,3 @@ -// store/useModuleStore.ts import { create } from "zustand"; interface ModuleStore { @@ -12,3 +11,16 @@ const useModuleStore = create((set) => ({ })); export default useModuleStore; + +// New store for subModule +interface SubModuleStore { + subModule: string; + setSubModule: (subModule: string) => void; +} + +const useSubModuleStore = create((set) => ({ + subModule: "properties", // Initial subModule state + setSubModule: (subModule) => set({ subModule }), // Update subModule state +})); + +export { useSubModuleStore }; \ No newline at end of file diff --git a/app/src/types/world/worldConstants.ts b/app/src/types/world/worldConstants.ts index ce5cacd..5e558af 100644 --- a/app/src/types/world/worldConstants.ts +++ b/app/src/types/world/worldConstants.ts @@ -270,7 +270,7 @@ export const planeConfig: PlaneConfig = { width: 300, // Width of the plane height: 300, // Height of the plane - color: "white" // Color of the plane + color: "#f3f3f3" // Color of the plane } export const shadowConfig: ShadowConfig = { diff --git a/app/src/types/world/worldTypes.d.ts b/app/src/types/world/worldTypes.d.ts index 9d3fad0..e4d4d36 100644 --- a/app/src/types/world/worldTypes.d.ts +++ b/app/src/types/world/worldTypes.d.ts @@ -270,26 +270,6 @@ export type setSelectedItemsIndexSetState = (index: number | null) => void; export type RefCSM = React.MutableRefObject; export type RefCSMHelper = React.MutableRefObject; - -interface Path { - modeluuid: string; - points: { - uuid: string; - position: [number, number, number]; - rotation: [number, number, number]; - events: { uuid: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; - triggers: { uuid: string; type: string; isUsed: boolean }[] | []; - }[]; - pathPosition: [number, number, number]; - pathRotation: [number, number, number]; - speed: number; -} - -interface SimulationPathsStore { - simulationPaths: Path[]; - setSimulationPaths: (paths: Path[]) => void; -} - interface PathConnection { fromPathUUID: string; fromUUID: string;