diff --git a/src/frontend/src/components/EditFlowSettingsComponent/index.tsx b/src/frontend/src/components/EditFlowSettingsComponent/index.tsx index 28b82d78e..6504c2b4e 100644 --- a/src/frontend/src/components/EditFlowSettingsComponent/index.tsx +++ b/src/frontend/src/components/EditFlowSettingsComponent/index.tsx @@ -1,7 +1,8 @@ -import React, { ChangeEvent, useState } from "react"; +import React, { ChangeEvent, useEffect, useRef, useState } from "react"; import { Input } from "../../components/ui/input"; import { Label } from "../../components/ui/label"; import { Textarea } from "../../components/ui/textarea"; +import { readFlowsFromDatabase } from "../../controllers/API"; type InputProps = { name: string | null; @@ -9,6 +10,8 @@ type InputProps = { maxLength?: number; flows: Array<{ id: string; name: string; description: string }>; tabId: string; + invalidName: boolean; + setInvalidName: (invalidName: boolean) => void; setName: (name: string) => void; setDescription: (description: string) => void; updateFlow: (flow: { id: string; name: string }) => void; @@ -16,6 +19,8 @@ type InputProps = { export const EditFlowSettings: React.FC = ({ name, + invalidName, + setInvalidName, description, maxLength = 50, flows, @@ -25,6 +30,14 @@ export const EditFlowSettings: React.FC = ({ updateFlow, }) => { const [isMaxLength, setIsMaxLength] = useState(false); + const nameLists = useRef([]); + useEffect(() => { + readFlowsFromDatabase().then((flows) => { + flows.forEach((flow) => { + nameLists.current.push(flow.name); + }); + }); + }, []); const handleNameChange = (event: ChangeEvent) => { const { value } = event.target; @@ -33,7 +46,11 @@ export const EditFlowSettings: React.FC = ({ } else { setIsMaxLength(false); } - + if (!nameLists.current.includes(value)) { + setInvalidName(false); + } else { + setInvalidName(true); + } setName(value); }; @@ -55,6 +72,9 @@ export const EditFlowSettings: React.FC = ({ {isMaxLength && ( Character limit reached )} + {invalidName && ( + Name already in use + )} f.id === tabId).description ); + const [invalidName, setInvalidName] = useState(false); + function handleClick() { let savedFlow = flows.find((f) => f.id === tabId); savedFlow.name = name; @@ -39,6 +41,8 @@ export default function FlowSettingsModal({ -