Skip to content

Commit

Permalink
fix($env): fix environment order form state (#8449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek authored Oct 15, 2024
1 parent e22f6a0 commit 258eb36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('OrderEnvironmentsDialog Component', () => {
expect(onSubmitMock).toHaveBeenCalledTimes(1);
expect(onSubmitMock).toHaveBeenCalledWith([
{ name: 'Dev', type: 'development' },
{ name: 'Prod', type: 'development' },
{ name: 'Staging', type: 'development' },
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ export const OrderEnvironmentsDialog: FC<OrderEnvironmentsDialogProps> = ({
});
};

const onTypeChange = (index: number, type: string) => {
setEnvironments(
environments.map((env, i) =>
i === index ? { ...env, type } : { ...env },
),
);
};

const onNameChange = (index: number, name: string) => {
setEnvironments(
environments.map((env, i) =>
i === index ? { ...env, name } : { ...env },
),
);
};

return (
<StyledDialog open={open} title=''>
<FormTemplate
Expand Down Expand Up @@ -199,24 +215,15 @@ export const OrderEnvironmentsDialog: FC<OrderEnvironmentsDialogProps> = ({
}),
)}
onChange={(type) => {
const newEnvironments = [
...environments,
];
newEnvironments[i].type = type;
setEnvironments(newEnvironments);
onTypeChange(i, type);
}}
/>
<TextField
size='small'
label={`Environment ${i + 1} Name`}
value={environments[i]?.name || ''}
onChange={(e) => {
const newEnvironments = [
...environments,
];
newEnvironments[i].name =
e.target.value;
setEnvironments(newEnvironments);
onNameChange(i, e.target.value);
}}
error={!!error}
helperText={error}
Expand Down

0 comments on commit 258eb36

Please sign in to comment.