import { FC } from 'react'; import { v4 as uuidv4 } from 'uuid'; import AlertOverrideInputGroup from './AlertOverrideInputGroup'; import List from '../List'; const ManageAlertOverride: FC = (props) => { const { alertOverrideTargetOptions, formikUtils, mailRecipientUuid: mrUuid, } = props; const { formik } = formikUtils; const { values: { [mrUuid]: mailRecipient }, } = formik; const { alertOverrides } = mailRecipient; return ( { /** * This is **not** the same as an alert override UUID because 1 alert * override formik value can reference _n_ alert override rules, where * _n_ is the number of subnodes per node. */ const valueId = uuidv4(); formik.setValues((previous: MailRecipientFormikValues) => { const shallow = { ...previous }; const { [mrUuid]: mr } = shallow; mr.alertOverrides = { ...mr.alertOverrides, [valueId]: { level: 2, target: null }, }; return shallow; }); }} renderListItem={(valueId, value: AlertOverrideFormikAlertOverride) => !value.remove && ( ) } /> ); }; export default ManageAlertOverride;