From 6e2bd0ce11697cdfd59500d506e68ac22ed38273 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Fri, 10 May 2024 15:24:40 +0200 Subject: [PATCH] fix: Handle existing user when editing profile --- .../_components/profile.accordion.tsx | 35 ++++++++++++++++--- packages/api/src/router/user.ts | 9 +++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/profile.accordion.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/profile.accordion.tsx index b851631df..cc1051138 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/profile.accordion.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/profile.accordion.tsx @@ -5,10 +5,15 @@ import { Button, Stack, TextInput } from "@mantine/core"; import type { RouterOutputs } from "@homarr/api"; import { clientApi } from "@homarr/api/client"; import { useForm, zodResolver } from "@homarr/form"; +import { + showErrorNotification, + showSuccessNotification, +} from "@homarr/notifications"; import { useI18n } from "@homarr/translation/client"; import { validation } from "@homarr/validation"; import { revalidatePathAction } from "~/app/revalidatePathAction"; +import { ErrorDisplay } from "~/components/utils"; interface ProfileAccordionProps { user: NonNullable; @@ -16,11 +21,30 @@ interface ProfileAccordionProps { export const ProfileAccordion = ({ user }: ProfileAccordionProps) => { const t = useI18n(); - const { mutate, isPending } = clientApi.user.editProfile.useMutation({ - onSettled: async () => { - await revalidatePathAction("/manage/users"); - }, - }); + const { mutate, isPending, isError, error } = + clientApi.user.editProfile.useMutation({ + onError(error) { + showErrorNotification({ + title: t( + "management.page.user.edit.section.profile.editProfile.title", + ), + message: error.message, + }); + }, + onSuccess: () => { + showSuccessNotification({ + title: t( + "management.page.user.edit.section.profile.editProfile.title", + ), + message: t( + "management.page.user.edit.section.profile.editProfile.message.profileUpdated", + ), + }); + }, + onSettled: async () => { + await revalidatePathAction("/manage/users"); + }, + }); const form = useForm({ initialValues: { name: user.name ?? "", @@ -41,6 +65,7 @@ export const ProfileAccordion = ({ user }: ProfileAccordionProps) => { return (
+