Merge pull request #21158 from strapi/fix/webhook-edit

fix: webhook button submitting and remove row clearing
This commit is contained in:
Alexandre BODIN 2024-09-06 10:24:20 +02:00 committed by GitHub
commit f1956fb015
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,8 +36,18 @@ const HeadersInput = () => {
const addFieldRow = useForm('HeadersInput', (state) => state.addFieldRow);
const removeFieldRow = useForm('HeadersInput', (state) => state.removeFieldRow);
const setFieldValue = useForm('HeadersInput', (state) => state.onChange);
const { value = [] } = useField<Header[]>('headers');
const removeRow = (index: number) => {
// if we are removing the last row, simply clear it
if (value.length === 1) {
setFieldValue('headers', [{ key: '', value: '' }]);
} else {
removeFieldRow('headers', index);
}
};
return (
<Flex direction="column" alignItems="stretch" gap={1}>
<DSField.Label>
@ -47,9 +57,9 @@ const HeadersInput = () => {
})}
</DSField.Label>
<Box padding={8} background="neutral100" hasRadius>
{value.map((_, index) => {
{value.map((val, index) => {
return (
<Grid.Root key={index} gap={4} padding={2}>
<Grid.Root key={`${index}-${JSON.stringify(val.key)}`} gap={4} padding={2}>
<Grid.Item col={6} direction="column" alignItems="stretch">
<HeaderCombobox
name={`headers.${index}.key`}
@ -81,8 +91,7 @@ const HeadersInput = () => {
padding="0.4rem"
alignItems="center"
justifyContent="center"
disabled={value.length === 1}
onClick={() => removeFieldRow('headers', index)}
onClick={() => removeRow(index)}
color="primary600"
label={formatMessage(
{
@ -91,6 +100,7 @@ const HeadersInput = () => {
},
{ number: index + 1 }
)}
type="button"
>
<Minus width="0.8rem" />
</IconButton>