Commit 87d6f90a by Peter Holmberg Committed by GitHub

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

parent 4ab90f93
...@@ -36,9 +36,22 @@ export const NotificationChannelForm: FC<Props> = ({ ...@@ -36,9 +36,22 @@ export const NotificationChannelForm: FC<Props> = ({
}) => { }) => {
const styles = getStyles(useTheme()); 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(() => { useEffect(() => {
watch(['type', 'settings.priority', 'sendReminder', 'uploadImage']); watch(['type', 'sendReminder', 'uploadImage', ...fieldsToWatch]);
}, []); }, [fieldsToWatch]);
const currentFormValues = getValues(); const currentFormValues = getValues();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment