Skip to content

Commit

Permalink
Merge pull request #382 from ConductionNL/fix/missing-fields
Browse files Browse the repository at this point in the history
Added requested changes
  • Loading branch information
remko48 authored Jun 3, 2024
2 parents 9835d39 + 2c05609 commit 0c88df1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
16 changes: 10 additions & 6 deletions pwa/src/templates/templateParts/actionsForm/ActionFormTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ 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 })),
Expand Down Expand Up @@ -159,6 +153,16 @@ export const ActionFormTemplate: React.FC<ActionFormTemplateProps> = ({ 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 (
<div className={styles.container}>
<form onSubmit={handleSubmit(onSubmit)} id={formId}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ cronjo
const payload = {
...data,
throws: data.throws?.map((_throw: any) => _throw.value),
userId: data.userId?.value ?? null,
};

createOrEditCronjob.mutate({ payload, id: cronjob?.id });
Expand All @@ -61,12 +62,6 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ 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 })),
Expand All @@ -81,6 +76,16 @@ export const CronjobFormTemplate: React.FC<CronjobFormTemplateProps> = ({ 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 (
<div>
<form onSubmit={handleSubmit(onSubmit)} id={formId}>
Expand Down

0 comments on commit 0c88df1

Please sign in to comment.