Skip to content

Commit

Permalink
feat: ✨ add alert to shelter edit page, when some error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
willMoraes committed Jun 3, 2024
1 parent 6660547 commit 37cc727
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/app/user/shelters/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<main className="mx-auto max-w-7xl bg-white px-4">
<div className="m-auto flex w-full max-w-2xl flex-col flex-wrap gap-3 pt-6">
<Alert variant="destructive">
<FiAlertTriangle />
<AlertTitle>Erro</AlertTitle>
<AlertDescription>
Ocorreu um erro ao carregar os dados do abrigo. Por favor, tente
novamente mais tarde.
</AlertDescription>
</Alert>
</div>
</main>
);
}

Expand Down

0 comments on commit 37cc727

Please sign in to comment.