Feat: Add message when name is invalid
This commit is contained in:
parent
38f60933b2
commit
21ed3ec97c
1 changed files with 19 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import { Label } from "../../components/ui/label";
|
||||||
import { Textarea } from "../../components/ui/textarea";
|
import { Textarea } from "../../components/ui/textarea";
|
||||||
import { InputProps } from "../../types/components";
|
import { InputProps } from "../../types/components";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export const EditFlowSettings: React.FC<InputProps> = ({
|
export const EditFlowSettings: React.FC<InputProps> = ({
|
||||||
name,
|
name,
|
||||||
|
|
@ -17,6 +18,8 @@ export const EditFlowSettings: React.FC<InputProps> = ({
|
||||||
}: InputProps): JSX.Element => {
|
}: InputProps): JSX.Element => {
|
||||||
const [isMaxLength, setIsMaxLength] = useState(false);
|
const [isMaxLength, setIsMaxLength] = useState(false);
|
||||||
const [isEndpointNameValid, setIsEndpointNameValid] = useState(true);
|
const [isEndpointNameValid, setIsEndpointNameValid] = useState(true);
|
||||||
|
const [isInvalidName, setIsInvalidName] = useState(false);
|
||||||
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
|
|
||||||
const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => {
|
const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
|
|
@ -25,6 +28,19 @@ export const EditFlowSettings: React.FC<InputProps> = ({
|
||||||
} else {
|
} else {
|
||||||
setIsMaxLength(false);
|
setIsMaxLength(false);
|
||||||
}
|
}
|
||||||
|
let invalid = false;
|
||||||
|
for (let i = 0; i < invalidNameList!.length; i++) {
|
||||||
|
if (value === invalidNameList![i]) {
|
||||||
|
invalid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (value === currentFlow?.name) {
|
||||||
|
invalid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
invalid = false;
|
||||||
|
}
|
||||||
|
setIsInvalidName(invalid);
|
||||||
setName!(value);
|
setName!(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -55,6 +71,9 @@ export const EditFlowSettings: React.FC<InputProps> = ({
|
||||||
{isMaxLength && (
|
{isMaxLength && (
|
||||||
<span className="edit-flow-span">Character limit reached</span>
|
<span className="edit-flow-span">Character limit reached</span>
|
||||||
)}
|
)}
|
||||||
|
{isInvalidName && (
|
||||||
|
<span className="edit-flow-span">Invalid name</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{setName ? (
|
{setName ? (
|
||||||
<Input
|
<Input
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue