/** * WordPress dependencies */ import { SelectControl } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import clsx from 'clsx'; import type { PostTypeName, WebhookSettings } from '@nelio-content/types'; /** * Internal dependencies */ import './style.scss'; import { TextFieldControl } from '../text-field-control'; import { HeadersFieldControl } from './headers-field-control'; import { FormDataKeyValuesFieldControl } from './form-data-key-values-field-control'; export type WebhookSettingsControlProps = { readonly className?: string; readonly isDisabled?: boolean; readonly hidePlaceholders?: boolean; readonly type?: PostTypeName; readonly settings: WebhookSettings; readonly onChange: ( settings: WebhookSettings ) => void; }; export const WebhookSettingsControl = ( { className, isDisabled, hidePlaceholders, type, settings, onChange, }: WebhookSettingsControlProps ): JSX.Element | null => { return (
onChange( { ...settings, url: value, } ) } /> onChange( { ...settings, method: value as WebhookSettings[ 'method' ], } ) } /> onChange( { ...settings, headers: value } ) } /> { ! [ 'GET', 'HEAD' ].includes( settings.method ) && ( { const newAttrs = { ...settings, bodyType: value as WebhookSettings[ 'bodyType' ], ...( value === 'json' ? { bodyContent: '' } : {} ), ...( value === 'form' ? { bodyContent: [] } : {} ), } as WebhookSettings; onChange( newAttrs ); } } /> ) } { settings.bodyType === 'json' && ( onChange( { ...settings, bodyContent: value, } ) } /> ) } { settings.bodyType === 'form' && ( onChange( { ...settings, bodyContent: value, } ) } /> ) }
); };