Fix: Dynamically add ShowWhen fields to the form watch (#28135)

This commit is contained in:
Peter Holmberg 2020-10-13 09:11:15 +02:00 committed by GitHub
parent 4ab90f9397
commit 87d6f90acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,9 +36,22 @@ export const NotificationChannelForm: FC<Props> = ({
}) => {
const styles = getStyles(useTheme());
/*
Finds fields that have dependencies on other fields and removes duplicates.
Needs to be prefixed with settings.
*/
const fieldsToWatch =
new Set(
selectedChannel?.options
.filter(o => o.showWhen.field)
.map(option => {
return `settings.${option.showWhen.field}`;
})
) || [];
useEffect(() => {
watch(['type', 'settings.priority', 'sendReminder', 'uploadImage']);
}, []);
watch(['type', 'sendReminder', 'uploadImage', ...fieldsToWatch]);
}, [fieldsToWatch]);
const currentFormValues = getValues();