diff --git a/src/app/missions/page.tsx b/src/app/missions/page.tsx index 4bd6a18..4daad09 100644 --- a/src/app/missions/page.tsx +++ b/src/app/missions/page.tsx @@ -1,15 +1,18 @@ "use client"; import MissionModal from "@/components/modals/mission_modal"; +import NewMissionModal from "@/components/modals/new_mission_modal"; import { missions } from "@/data/data"; import { Mission } from "@/types/mission"; import { GET_MISSIONS } from "@/utils/graphql_queries"; import { useQuery } from "@apollo/client"; -import { Button } from "@material-tailwind/react"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { Button, IconButton } from "@material-tailwind/react"; import { useState } from "react"; const MissionsPage = () => { - const [showModal, setShowModal] = useState(false); + const [showMissionModal, setShowMissionModal] = useState(false); + const [showNewMissionModal, setShowNewMissionModal] = useState(false); const [selectedMission, setSelectedMission] = useState(null); @@ -29,25 +32,43 @@ const MissionsPage = () => { } return ( -
- {data?.missions.map((mission: Mission, i: number) => ( -
-
{ - setSelectedMission(mission); - setShowModal(true); - }} - > -

{mission.name}

+
+
+ { + setShowNewMissionModal(true); + }} + > + + + +
+
+ {data?.missions.map((mission: Mission, i: number) => ( +
+
{ + setSelectedMission(mission); + setShowMissionModal(true); + }} + > +

{mission.name}

+
-
- ))} - + ))} + +
); }; diff --git a/src/components/inputs/mission_tasks_editor.tsx b/src/components/inputs/mission_tasks_editor.tsx index 902f15f..9bfd138 100644 --- a/src/components/inputs/mission_tasks_editor.tsx +++ b/src/components/inputs/mission_tasks_editor.tsx @@ -25,7 +25,7 @@ const MissionTaskEditor: React.FC = ({ description: newTaskDescription, agent: null, }; - const updatedTasks = [...mission.tasks, newTask]; + const updatedTasks = [...(mission?.tasks ?? []), newTask]; const updatedMission: Mission = { ...mission, tasks: updatedTasks }; onMissionChange(updatedMission); setNewTaskName(""); @@ -33,7 +33,7 @@ const MissionTaskEditor: React.FC = ({ }; const handleRemoveTask = (index: number) => { - const updatedTasks = [...mission.tasks]; + const updatedTasks = [...(mission?.tasks ?? [])]; updatedTasks.splice(index, 1); const updatedMission: Mission = { ...mission, tasks: updatedTasks }; onMissionChange(updatedMission); @@ -42,7 +42,7 @@ const MissionTaskEditor: React.FC = ({ return (

Mission Tasks

- {mission.tasks.map((task, index) => ( + {mission?.tasks?.map((task, index) => (

{task.name}

@@ -92,8 +92,8 @@ const MissionTaskEditor: React.FC = ({ ({ + { text: "None", value: undefined }, + ...(mission?.crew ?? []).map((agent) => ({ text: agent.role, value: agent.id, })), diff --git a/src/components/modals/new_mission_modal.tsx b/src/components/modals/new_mission_modal.tsx new file mode 100644 index 0000000..199f014 --- /dev/null +++ b/src/components/modals/new_mission_modal.tsx @@ -0,0 +1,195 @@ +import { Process, selectTheme } from "@/data/consts"; +import { Mission } from "@/types/mission"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { Button, Switch } from "@material-tailwind/react"; +import React, { useState } from "react"; +import { + TEInput, + TEModal, + TEModalBody, + TEModalContent, + TEModalDialog, + TEModalFooter, + TEModalHeader, + TERipple, + TESelect, +} from "tw-elements-react"; +import MissionTaskEditor from "../inputs/mission_tasks_editor"; +import { useQuery } from "@apollo/client"; +import { GET_AGENTS } from "@/utils/graphql_queries"; +import { Agent } from "@/types/agent"; + +function NewMissionModal(props: { + showModal: boolean; + setShowModal: Function; +}): JSX.Element { + const { showModal, setShowModal } = props; + + const [tempMission, setTempMission] = useState({ + id: -1, + name: "", + crew: [], + tasks: [], + verbose: false, + process: Process.SEQUENTIAL, + result: "", + }); + + const { loading, error, data: agentsData } = useQuery(GET_AGENTS); + + return ( +
+ + + + +

+ Create New Mission +

+ +
+ +
+
+ + { + setTempMission((prevState) => ({ + ...prevState!, + name: event.target.value, + })); + }} + /> +
+
+ Crew (Agents): +
+ {loading ? ( + + ) : ( + ({ + text: agent.role, + value: agent.id, + }))} + multiple + onValueChange={(event: any) => { + const newValue = event.map((item: any) => item.value); + const newCrew = agentsData.agents.filter( + (agent: Agent) => newValue.includes(agent.id) + ); + setTempMission((prevState) => ({ + ...prevState!, + crew: newCrew, + })); + }} + theme={selectTheme} + /> + )} +
+
+ + { + setTempMission((prevState) => ({ + ...prevState!, + verbose: !!event.target.value, + })); + }} + /> +
+
+ + { + setTempMission((prevState) => ({ + ...prevState!, + process: event?.value, + })); + }} + className="dark:text-black" + theme={selectTheme} + /> +
+
+ +
+ { + setTempMission(mission); + }} + /> +
+
+
+ + {tempMission?.result && ( +
+ {tempMission?.result} +
+ )} +
+
+ +
+
+
+ + + + + + + + + +
+
+
+
+ ); +} + +export default NewMissionModal;