-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from emiliosheinz/feat/enable-create-shelters
feat: enable create shelters
- Loading branch information
Showing
25 changed files
with
905 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240603234056_update_uuid_to_be_required/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[uuid]` on the table `Shelter` will be added. If there are existing duplicate values, this will fail. | ||
- Made the column `uuid` on table `Shelter` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Shelter" ALTER COLUMN "uuid" SET NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Shelter_uuid_key" ON "Shelter"("uuid"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import { api } from "~/trpc/react"; | ||
import { FormEditRegister } from "~/app/user/shelters/_components"; | ||
import { Skeleton } from "~/components/ui/skeleton"; | ||
import { notFound } from "next/navigation"; | ||
import { FiAlertTriangle } from "react-icons/fi"; | ||
|
||
import { Alert, AlertDescription, AlertTitle } from "~/components/ui/alert"; | ||
|
||
export default function EditShelterPage({ | ||
params, | ||
}: { | ||
params: { uuid: string }; | ||
}) { | ||
const { data, isLoading, error } = | ||
api.userShelters.findUserShelterByUuid.useQuery({ | ||
uuid: params.uuid, | ||
}); | ||
|
||
if (error) { | ||
if (error?.data?.code === "NOT_FOUND") { | ||
return notFound(); | ||
} | ||
|
||
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> | ||
); | ||
} | ||
|
||
if (isLoading) { | ||
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"> | ||
<Skeleton className="h-[33px] w-[180px] rounded-xl" /> | ||
<Skeleton className="h-[300px] w-full rounded-xl" /> | ||
<Skeleton className="h-[300px] w-full rounded-xl" /> | ||
<Skeleton className="h-[300px] w-full rounded-xl" /> | ||
</div> | ||
</main> | ||
); | ||
} | ||
|
||
return <FormEditRegister shelter={data} />; | ||
} |
File renamed without changes.
74 changes: 74 additions & 0 deletions
74
src/app/user/shelters/_components/form-edit-register/dialog-delete/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"use client"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/components/ui/dialog"; | ||
|
||
import { toast } from "sonner"; | ||
|
||
import { FiTrash } from "react-icons/fi"; | ||
import { useState } from "react"; | ||
import { api } from "~/trpc/react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export function DialogDelete({ shelterUuid }: { shelterUuid: string }) { | ||
const router = useRouter(); | ||
const [open, setOpen] = useState(false); | ||
|
||
const deleteShelter = api.userShelters.delete.useMutation({ | ||
onSuccess: () => { | ||
toast.success("Abrigo excluído com sucesso!"); | ||
router.replace("/user/shelters"); | ||
setOpen(false); | ||
}, | ||
onError: (error) => { | ||
setOpen(false); | ||
toast.error("Ops! Houve um erro ao excluir o abrigo."); | ||
console.error(error); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger asChild> | ||
<Button type="button" variant="destructive"> | ||
<FiTrash className="mr-2" /> | ||
Excluir | ||
</Button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Atenção</DialogTitle> | ||
<DialogDescription> | ||
Você tem certeza que deseja excluir este abrigo? Esta ação não pode | ||
ser desfeita. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button | ||
type="button" | ||
variant="secondary" | ||
onClick={() => setOpen(false)} | ||
> | ||
Cancelar | ||
</Button> | ||
<Button | ||
type="button" | ||
onClick={() => { | ||
deleteShelter.mutate({ uuid: shelterUuid }); | ||
}} | ||
> | ||
Excluir | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./shelters-list-table"; | ||
export * from "./form-edit-register"; |
Oops, something went wrong.