import Input from 'component/common/Input/Input'; import { Button, styled } from '@mui/material'; import Add from '@mui/icons-material/Add'; import { trim } from 'component/common/util'; import { StrategyParameters } from './StrategyParameters/StrategyParameters.tsx'; import type { IStrategyParameter } from 'interfaces/strategy'; import type React from 'react'; interface IStrategyFormProps { strategyName: string; strategyDesc: string; params: IStrategyParameter[]; setStrategyName: React.Dispatch>; validateStrategyName?: () => void; setStrategyDesc: React.Dispatch>; setParams: React.Dispatch>; handleSubmit: (e: React.FormEvent) => void; handleCancel: () => void; errors: { [key: string]: string }; mode: 'Create' | 'Edit'; clearErrors: () => void; setErrors: React.Dispatch>>; children?: React.ReactNode; } const StyledForm = styled('form')(({ theme }) => ({ display: 'flex', flexDirection: 'column', height: '100%', })); const StyledContainer = styled('div')(({ theme }) => ({ maxWidth: 400, })); const StyledInputDescription = styled('p')(({ theme }) => ({ marginBottom: theme.spacing(1), })); const StyledInput = styled(Input)(({ theme }) => ({ width: '100%', marginBottom: theme.spacing(2), })); const StyledParamButton = styled(Button)(({ theme }) => ({ color: theme.palette.primary.dark, })); const StyledButtonContainer = styled('div')(({ theme }) => ({ marginTop: 'auto', display: 'flex', justifyContent: 'flex-end', })); const StyledCancelButton = styled(Button)(({ theme }) => ({ marginLeft: theme.spacing(3), })); export const StrategyForm: React.FC = ({ children, handleSubmit, handleCancel, strategyName, strategyDesc, params, setParams, setStrategyName, validateStrategyName, setStrategyDesc, errors, mode, clearErrors, }) => { const updateParameter = (index: number, updated: object) => { const item = { ...params[index] }; params[index] = Object.assign({}, item, updated); setParams((prev) => [...prev]); }; const appParameter = () => { setParams((prev) => [ ...prev, { name: '', type: 'string', description: '', required: false }, ]); }; return ( What would you like to call your strategy? setStrategyName(trim(e.target.value))} error={Boolean(errors.name)} errorText={errors.name} onFocus={clearErrors} onBlur={validateStrategyName} /> What is your strategy description? setStrategyDesc(e.target.value)} rows={2} multiline /> { e.preventDefault(); appParameter(); }} variant='outlined' color='secondary' startIcon={} > Add parameter {children} Cancel ); };