Skip to content

Commit

Permalink
fix: after updating a role, UI was showing old, incorrect version of …
Browse files Browse the repository at this point in the history
…the role
  • Loading branch information
niekcandaele committed Oct 28, 2024
1 parent a5de69c commit a5a6ae6
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ export const RoleForm: FC<CreateUpdateRoleFormProps> = ({
}
}, [open]);

const { control, handleSubmit, formState } = useForm<IFormInputs>({
const { control, handleSubmit, formState, reset } = useForm<IFormInputs>({
mode: 'onChange',
resolver: zodResolver(validationSchema),
defaultValues: initialData && {
name: initialData.name,
permissions: {},
},
});

useEffect(() => {
if (!initialData) return;
reset({
name: initialData.name,
permissions: Object.values(permissions).reduce(
(acc, permission) => ({
Expand All @@ -100,8 +108,8 @@ export const RoleForm: FC<CreateUpdateRoleFormProps> = ({
}),
{},
),
},
});
});
}, [initialData]);

return (
<Drawer open={open} onOpenChange={setOpen} promptCloseConfirmation={formState.isDirty}>
Expand Down

0 comments on commit a5a6ae6

Please sign in to comment.