import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import Input from '../components/Input'; import { ActiveState } from '../models/misc'; import WrapperModal from './WrapperModal'; type AddActionModalProps = { modalState: ActiveState; setModalState: (state: ActiveState) => void; handleSubmit: (actionName: string) => void; }; const isValidFunctionName = (name: string): boolean => { const pattern = /^[a-zA-Z0-9_-]+$/; return pattern.test(name); }; export default function AddActionModal({ modalState, setModalState, handleSubmit, }: AddActionModalProps) { const { t } = useTranslation(); const [actionName, setActionName] = React.useState(''); const [functionNameError, setFunctionNameError] = useState(false); const handleAddAction = () => { if (!isValidFunctionName(actionName)) { setFunctionNameError(true); return; } setFunctionNameError(false); handleSubmit(actionName); setActionName(''); setModalState('INACTIVE'); }; if (modalState !== 'ACTIVE') return null; return ( setModalState('INACTIVE')} className="sm:w-[512px]" >

New Action

Action Name { const value = e.target.value; setActionName(value); setFunctionNameError(!isValidFunctionName(value)); }} borderVariant="thin" labelBgClassName="bg-white dark:bg-charleston-green-2" placeholder={'Enter name'} />

{functionNameError ? 'Invalid function name format. Use only letters, numbers, underscores, and hyphens.' : 'Use only letters, numbers, underscores, and hyphens (e.g., `get_data`, `send_report`, etc.)'}

); }