diff --git a/pwa/src/templates/templateParts/actionsForm/ActionFormTemplate.tsx b/pwa/src/templates/templateParts/actionsForm/ActionFormTemplate.tsx index b3b655d3..0d7cf48c 100644 --- a/pwa/src/templates/templateParts/actionsForm/ActionFormTemplate.tsx +++ b/pwa/src/templates/templateParts/actionsForm/ActionFormTemplate.tsx @@ -117,12 +117,6 @@ export const ActionFormTemplate: React.FC = ({ action } setValue("class", { label: action.class, value: action.class }); - for (const [key, value] of Object.entries(getUsers?.data)) { - if (value?.id === action?.userId) { - setValue("userId", { label: setUserIdLabel(value), value: value.id }); - } - } - setValue( "listens", action["listens"].map((listen: any) => ({ label: listen, value: listen })), @@ -159,6 +153,16 @@ export const ActionFormTemplate: React.FC = ({ action } action && handleSetFormValues(); }, [action]); + React.useEffect(() => { + if (!action) return; + if (!getUsers.isSuccess) return; + getUsers?.data.map((user) => { + if (user?.id === action?.userId) { + setValue("userId", { label: setUserIdLabel(user), value: user.id }); + } + }); + }, [action, getUsers.isSuccess]); + return (
diff --git a/pwa/src/templates/templateParts/cronjobsForm/CronjobsFormTemplate.tsx b/pwa/src/templates/templateParts/cronjobsForm/CronjobsFormTemplate.tsx index e434d0d5..0fd60364 100644 --- a/pwa/src/templates/templateParts/cronjobsForm/CronjobsFormTemplate.tsx +++ b/pwa/src/templates/templateParts/cronjobsForm/CronjobsFormTemplate.tsx @@ -52,6 +52,7 @@ export const CronjobFormTemplate: React.FC = ({ cronjo const payload = { ...data, throws: data.throws?.map((_throw: any) => _throw.value), + userId: data.userId?.value ?? null, }; createOrEditCronjob.mutate({ payload, id: cronjob?.id }); @@ -61,12 +62,6 @@ export const CronjobFormTemplate: React.FC = ({ cronjo const basicFields: string[] = ["reference", "version", "name", "description", "crontab", "isEnabled"]; basicFields.forEach((field) => setValue(field, cronjob[field])); - for (const [key, value] of Object.entries(getUsers?.data)) { - if (value?.id === cronjob?.userId) { - setValue("userId", { label: setUserIdLabel(value), value: value.id }); - } - } - setValue( "throws", cronjob["throws"]?.map((_throw: any) => ({ label: _throw, value: _throw })), @@ -81,6 +76,16 @@ export const CronjobFormTemplate: React.FC = ({ cronjo cronjob && handleSetFormValues(); }, [cronjob]); + React.useEffect(() => { + if (!cronjob) return; + if (!getUsers.isSuccess) return; + getUsers?.data.map((user) => { + if (user?.id === cronjob?.userId) { + setValue("userId", { label: setUserIdLabel(user), value: user.id }); + } + }); + }, [cronjob, getUsers.isSuccess]); + return (