From 37cc727c69cc8555646cc75b7159d675df0048e8 Mon Sep 17 00:00:00 2001 From: William Moraes Date: Mon, 3 Jun 2024 19:47:08 -0300 Subject: [PATCH] feat: :sparkles: add alert to shelter edit page, when some error occurs --- src/app/user/shelters/[id]/edit/page.tsx | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/app/user/shelters/[id]/edit/page.tsx b/src/app/user/shelters/[id]/edit/page.tsx index 41a8c6b..0949829 100644 --- a/src/app/user/shelters/[id]/edit/page.tsx +++ b/src/app/user/shelters/[id]/edit/page.tsx @@ -1,10 +1,12 @@ "use client"; -import { notFound } from "next/navigation"; import { api } from "~/trpc/react"; import { FormEditRegister } from "~/app/user/shelters/_components"; import { Skeleton } from "~/components/ui/skeleton"; -import { toast } from "sonner"; +import { notFound } from "next/navigation"; +import { FiAlertTriangle } from "react-icons/fi"; + +import { Alert, AlertDescription, AlertTitle } from "~/components/ui/alert"; export default function EditShelterPage({ params, @@ -16,13 +18,24 @@ export default function EditShelterPage({ id: Number(params.id), }); - if (error?.data?.httpStatus === 404 && !isLoading) { - notFound(); - } + if (error) { + if (error?.data?.code === "NOT_FOUND") { + return notFound(); + } - if (!data && !isLoading) { - toast.error( - "Erro ao carregar os dados abrigo. Tente novamente mais tarde.", + return ( +
+
+ + + Erro + + Ocorreu um erro ao carregar os dados do abrigo. Por favor, tente + novamente mais tarde. + + +
+
); }