import { FormikErrors } from 'formik'; import { array, object, SchemaOf, string } from 'yup'; import { FormError } from '@@/form-components/FormError'; import { InputList, ItemProps } from '@@/form-components/InputList'; import { InputLabeled } from '@@/form-components/Input/InputLabeled'; interface Sysctls { name: string; value: string; } export type Values = Array; export function SysctlsField({ values, onChange, errors, }: { values: Values; onChange: (value: Values) => void; errors?: FormikErrors[]; }) { return ( ({ name: '', value: '' })} /> ); } function Item({ item, onChange, error }: ItemProps) { return (
onChange({ ...item, name: e.target.value })} label="name" placeholder="e.g. FOO" className="w-1/2" size="small" /> onChange({ ...item, value: e.target.value })} label="value" placeholder="e.g. bar" className="w-1/2" size="small" />
{error && {Object.values(error)[0]}}
); } export function sysctlsValidation(): SchemaOf { return array( object({ name: string().required('Name is required'), value: string().required('Value is required'), }) ); }