/** * WordPress dependencies */ import { Button, Modal } from '@safe-wordpress/components'; import { useState } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { isEqual } from 'lodash'; import { css } from '@nelio/forms/css'; import { useActionType } from '@nelio/forms/actions'; import type { ActionInstance } from '@nelio/forms/types'; type EditActionModalProps< T > = { readonly formId: number; readonly isNew: boolean; readonly action: ActionInstance< T >; readonly onClose: () => void; readonly onSave: ( action: ActionInstance< T > ) => void; }; export function EditActionModal< T >( { formId, action, isNew, onClose, onSave, }: EditActionModalProps< T > ): JSX.Element | null { const [ editAction, setEditAction ] = useState( action ); const actionType = useActionType( action.type ); const EditComponent = actionType?.edit; const isDirty = ! isEqual( action, editAction ); if ( ! EditComponent ) { return null; } //end if return ( setEditAction( { ...editAction, name } ), setAttributes: ( attributes ) => setEditAction( { ...editAction, attributes: { ...editAction.attributes, ...attributes, }, } ), } } />
); } // ====== // STYLES // ====== const MODAL = css( { maxWidth: '35em', '.components-base-control': { marginBottom: '1em', }, } ); const EDIT_ACTIONS = css( { display: 'flex', flexDirection: 'row', justifyContent: 'flex-end', gap: '1em', } );