import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import Exit from '../assets/exit.svg'; import Input from '../components/Input'; import { ActiveState } from '../models/misc'; const isValidFunctionName = (name: string): boolean => { const pattern = /^[a-zA-Z0-9_-]+$/; return pattern.test(name); }; interface AddActionModalProps { modalState: ActiveState; setModalState: (state: ActiveState) => void; handleSubmit: (actionName: string) => void; } export default function AddActionModal({ modalState, setModalState, handleSubmit, }: AddActionModalProps) { const { t } = useTranslation(); const [actionName, setActionName] = React.useState(''); const [functionNameError, setFunctionNameError] = useState(false); // New error state const handleAddAction = () => { if (!isValidFunctionName(actionName)) { setFunctionNameError(true); // Set error state if invalid return; } setFunctionNameError(false); // Clear error state if valid handleSubmit(actionName); setModalState('INACTIVE'); }; return (

New Action

Action Name setActionName(e.target.value)} borderVariant="thin" placeholder={'Enter name'} />

Use only letters, numbers, underscores, and hyphens (e.g., `get_user_data`, `send-report`).

{functionNameError && (

Invalid function name format. Use only letters, numbers, underscores, and hyphens.

)}
); }