From 12fd0c7c2741ba7e32119ee3afb088f15eaccf76 Mon Sep 17 00:00:00 2001 From: Mads Nylund <73914541+MadsNyl@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:32:25 +0200 Subject: [PATCH] fixed error on updating user, and form errors on manual singup (#1061) --- .../Profile/components/ProfileSettings/UserSettings.tsx | 2 +- src/pages/SignUp/index.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/Profile/components/ProfileSettings/UserSettings.tsx b/src/pages/Profile/components/ProfileSettings/UserSettings.tsx index 1ab09e2f..41948e91 100644 --- a/src/pages/Profile/components/ProfileSettings/UserSettings.tsx +++ b/src/pages/Profile/components/ProfileSettings/UserSettings.tsx @@ -41,7 +41,7 @@ export const UserSettings = ({ isAdmin, user }: UserSettingsProps) => { const form = useForm>({ resolver: zodResolver(formSchema), - defaultValues: { ...user, gender: user.gender.toString() }, + defaultValues: { ...user, image: user.image || '', gender: user.gender.toString() }, }); const onSubmit = (values: z.infer) => { diff --git a/src/pages/SignUp/index.tsx b/src/pages/SignUp/index.tsx index caebf5a0..5437a542 100644 --- a/src/pages/SignUp/index.tsx +++ b/src/pages/SignUp/index.tsx @@ -84,7 +84,14 @@ const SignUp = () => { navigate(redirectURL || URLS.login); }, onError: (e) => { - toast.error(e.detail); + Object.keys(e.detail).forEach((key: string) => { + if (key in userData) { + const errorKey = key as keyof UserCreate; + const errorMessage = (e.detail as unknown as Record)[key]; + form.setError(errorKey, { message: errorMessage }); + } + }); + toast.error('Det er en eller flere feil i skjemaet'); }, }); };