From 2f826999f453c483b6c7e69583d0beb16eb4aaa5 Mon Sep 17 00:00:00 2001 From: "Eng. Elias" Date: Tue, 27 Feb 2024 10:59:02 +0400 Subject: [PATCH] Add New Agent Modal + replace TE Switch with TW Material Switch --- src/app/agents/page.tsx | 98 ++++++----- src/components/inputs/file.tsx | 4 +- src/components/inputs/switch.tsx | 22 --- src/components/modals/agent_modal.tsx | 17 +- src/components/modals/mission_modal.tsx | 11 +- src/components/modals/new_agent_modal.tsx | 193 ++++++++++++++++++++++ 6 files changed, 278 insertions(+), 67 deletions(-) delete mode 100644 src/components/inputs/switch.tsx create mode 100644 src/components/modals/new_agent_modal.tsx diff --git a/src/app/agents/page.tsx b/src/app/agents/page.tsx index 614432d..08bfa84 100644 --- a/src/app/agents/page.tsx +++ b/src/app/agents/page.tsx @@ -1,15 +1,17 @@ "use client"; import AgentModal from "@/components/modals/agent_modal"; +import NewAgentModal from "@/components/modals/new_agent_modal"; import { Agent } from "@/types/agent"; import { GET_AGENTS } from "@/utils/graphql_queries"; import { useQuery } from "@apollo/client"; import { Icon } from "@iconify/react"; -import { Button } from "@material-tailwind/react"; +import { Button, IconButton } from "@material-tailwind/react"; import { useState } from "react"; const AgentsPage = () => { - const [showModal, setShowModal] = useState(false); + const [showAgentModal, setShowAgentModal] = useState(false); + const [showNewAgentModal, setShowNewAgentModal] = useState(false); const [selectedAgent, setSelectedAgent] = useState(null); @@ -29,45 +31,63 @@ const AgentsPage = () => { } return ( -
- {data.agents.map((agent: Agent, i: number) => ( -
-
- Agent -
-
- {agent.role} -
-
- Goal: {agent.goal} -
-
- + Agent +
+
+ {agent.role} +
+
+ Goal: {agent.goal} +
+
+ +
-
- ))} - + ))} + + ); }; diff --git a/src/components/inputs/file.tsx b/src/components/inputs/file.tsx index 1fc060f..6d70f76 100644 --- a/src/components/inputs/file.tsx +++ b/src/components/inputs/file.tsx @@ -4,8 +4,9 @@ export default function TWFileInput(props: { accept?: string; disabled?: boolean; multiple?: boolean; + onChange?: (event: React.ChangeEvent) => void; }) { - const { accept, disabled, multiple } = props; + const { accept, disabled, multiple, onChange = () => {} } = props; return ( ); } diff --git a/src/components/inputs/switch.tsx b/src/components/inputs/switch.tsx deleted file mode 100644 index 9dfc0c0..0000000 --- a/src/components/inputs/switch.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from "react"; - -export default function Switch(props: { - checked?: boolean; - defaultChecked?: boolean; - disabled?: boolean; - onChange?: React.ChangeEventHandler; -}) { - const { checked, defaultChecked, disabled = false, onChange } = props; - - return ( - - ); -} diff --git a/src/components/modals/agent_modal.tsx b/src/components/modals/agent_modal.tsx index 8699658..133f04d 100644 --- a/src/components/modals/agent_modal.tsx +++ b/src/components/modals/agent_modal.tsx @@ -16,9 +16,9 @@ import { TETextarea, TESelect, } from "tw-elements-react"; -import Switch from "../inputs/switch"; import TWFileInput from "../inputs/file"; import { selectTheme } from "@/data/consts"; +import { Switch } from "@material-tailwind/react"; export default function AgentModal(props: { agent: Agent | null; @@ -139,6 +139,8 @@ export default function AgentModal(props: { {isEdit ? ( { setTempAgent((prevState) => ({ @@ -149,7 +151,9 @@ export default function AgentModal(props: { /> ) : ( )} @@ -158,6 +162,8 @@ export default function AgentModal(props: { {isEdit ? ( { setTempAgent((prevState) => ({ @@ -167,7 +173,12 @@ export default function AgentModal(props: { }} /> ) : ( - + )} diff --git a/src/components/modals/mission_modal.tsx b/src/components/modals/mission_modal.tsx index 782af2a..90a49f2 100644 --- a/src/components/modals/mission_modal.tsx +++ b/src/components/modals/mission_modal.tsx @@ -14,11 +14,11 @@ import { TEInput, TESelect, } from "tw-elements-react"; -import Switch from "../inputs/switch"; import { Mission } from "@/types/mission"; import MissionTaskEditor from "../inputs/mission_tasks_editor"; import { TasksAccordion } from "../ui/tasks_accordions"; import { Process, selectTheme } from "@/data/consts"; +import { Switch } from "@material-tailwind/react"; export default function MissionModal(props: { mission: Mission | null; @@ -108,6 +108,8 @@ export default function MissionModal(props: { {isEdit ? ( { setTempMission((prevState) => ({ @@ -117,7 +119,12 @@ export default function MissionModal(props: { }} /> ) : ( - + )}
diff --git a/src/components/modals/new_agent_modal.tsx b/src/components/modals/new_agent_modal.tsx new file mode 100644 index 0000000..d1a7a13 --- /dev/null +++ b/src/components/modals/new_agent_modal.tsx @@ -0,0 +1,193 @@ +import { selectTheme } from "@/data/consts"; +import { tools } from "@/data/data"; +import { Agent } from "@/types/agent"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import React, { useState } from "react"; +import { + TEInput, + TEModal, + TEModalBody, + TEModalContent, + TEModalDialog, + TEModalFooter, + TEModalHeader, + TERipple, + TESelect, + TETextarea, +} from "tw-elements-react"; +import TWFileInput from "../inputs/file"; +import { Switch } from "@material-tailwind/react"; + +function NewAgentModal(props: { showModal: boolean; setShowModal: Function }) { + const { showModal, setShowModal } = props; + + const [tempAgent, setTempAgent] = useState(); + + const [selectedImage, setSelectedImage] = useState< + string | ArrayBuffer | null + >(null); + + const handleImageChange = (event: React.ChangeEvent) => { + const file = event?.target?.files?.[0]; + const reader = new FileReader(); + + reader.onloadend = () => { + setSelectedImage(reader.result); + }; + + if (file) { + reader.readAsDataURL(file); + } + }; + + return ( +
+ + + + +

+ Add new agent to you Crew +

+ +
+ +
+
+
+ + { + setTempAgent((prevState) => ({ + ...prevState!, + role: event.target.value, + })); + }} + /> +
+
+ + { + setTempAgent((prevState) => ({ + ...prevState!, + goal: event.target.value, + })); + }} + /> +
+
+ + { + setTempAgent((prevState) => ({ + ...prevState!, + backstory: event.target.value, + })); + }} + /> +
+
+ Tools: + { + const newValue = event.map((item: any) => item.value); + setTempAgent((prevState) => ({ + ...prevState!, + tools: newValue, + })); + }} + className="w-full" + theme={selectTheme} + /> +
+
+ + { + setTempAgent((prevState) => ({ + ...prevState!, + allowDelegation: !!event.target.value, + })); + }} + /> +
+
+ + { + setTempAgent((prevState) => ({ + ...prevState!, + verbose: !!event.target.value, + })); + }} + /> +
+
+ +
+ + + {selectedImage && ( + Agent Image + )} +
+
+
+ + + + + + + + + +
+
+
+
+ ); +} + +export default NewAgentModal;