diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4766155..9b08e10 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -25,7 +25,7 @@ export default function RootLayout({ }>) { return ( ({ + ...jest.requireActual("@/features/pets"), + usePetPageViewModel: jest.fn(), +})) + +const baseHookMock = { + pet: petResponseMock, + isLoading: false, +} + +const mockParams = { id: petResponseMock.id } + +describe("Pet Details Page", () => { + beforeEach(() => { + jest.clearAllMocks() + React.use = jest.fn().mockReturnValue(mockParams) + ;(usePetPageViewModel as jest.Mock).mockReturnValue(baseHookMock) + }) + + it("should display the title and subtitle", () => { + renderWithProviders() + + expect( + screen.getByRole("heading", { name: /detalhes do pet/i }) + ).toBeInTheDocument() + expect(screen.getByText(/visualização completa/i)).toBeInTheDocument() + }) + + it("should display the edit and delete buttons", () => { + renderWithProviders() + + expect(screen.getByRole("button", { name: /editar/i })).toBeInTheDocument() + expect(screen.getByRole("button", { name: /excluir/i })).toBeInTheDocument() + }) + + it("should render the PetDetails component", () => { + renderWithProviders() + + expect( + screen.getByRole("heading", { level: 3, name: /informações do pet/i }) + ).toBeInTheDocument() + expect(screen.queryByTestId("page-loader")).not.toBeInTheDocument() + }) + + it("should render the Loader page when loading", () => { + ;(usePetPageViewModel as jest.Mock).mockReturnValue({ + ...baseHookMock, + isLoading: true, + }) + renderWithProviders() + + expect(screen.getByTestId("page-loader")).toBeInTheDocument() + }) +}) diff --git a/src/app/pets/[id]/page.tsx b/src/app/pets/[id]/page.tsx new file mode 100644 index 0000000..badd08a --- /dev/null +++ b/src/app/pets/[id]/page.tsx @@ -0,0 +1,38 @@ +"use client" + +import { + PetActionButtons, + PetDetails, + usePetPageViewModel, +} from "@/features/pets" +import { PageLayout, PageLoader } from "@/shared/components" +import React from "react" + +interface PageProps { + params: Promise<{ id: string }> +} + +export default function Page({ params }: PageProps) { + const { id } = React.use(params) + const { pet, isLoading } = usePetPageViewModel(id) + + return ( + <> + + + + } + > + + + + ) +} diff --git a/src/app/pets/page.test.tsx b/src/app/pets/page.test.tsx index 6ea93ea..9b4df9a 100644 --- a/src/app/pets/page.test.tsx +++ b/src/app/pets/page.test.tsx @@ -2,11 +2,11 @@ import { renderWithProviders } from "@/shared/test-utils/custom-render" import Page from "./page" import { screen } from "@testing-library/react" import { petPageMock } from "@/shared/test-utils/mocks/pets-mocks" -import { usePetsListPageViewModel } from "@/features/pets" +import { usePetsPageViewModel } from "@/features/pets" jest.mock("@/features/pets", () => ({ ...jest.requireActual("@/features/pets"), - usePetsListPageViewModel: jest.fn(), + usePetsPageViewModel: jest.fn(), PetListHeader: () =>
, })) @@ -19,7 +19,7 @@ const baseHookMock = { describe("Pets Page", () => { beforeEach(() => { - ;(usePetsListPageViewModel as jest.Mock).mockReturnValue(baseHookMock) + ;(usePetsPageViewModel as jest.Mock).mockReturnValue(baseHookMock) }) it("should render PetListHeader", () => { @@ -34,7 +34,7 @@ describe("Pets Page", () => { }) it('should display "nenhum pet foi encontrado" when the list is empty', () => { - ;(usePetsListPageViewModel as jest.Mock).mockReturnValue({ + ;(usePetsPageViewModel as jest.Mock).mockReturnValue({ ...baseHookMock, pagePetCurrent: { ...petPageMock, content: [] }, }) @@ -44,7 +44,7 @@ describe("Pets Page", () => { }) it("should display only the loader when loading and not render any pet card", () => { - ;(usePetsListPageViewModel as jest.Mock).mockReturnValue({ + ;(usePetsPageViewModel as jest.Mock).mockReturnValue({ ...baseHookMock, isLoading: true, }) diff --git a/src/app/pets/page.tsx b/src/app/pets/page.tsx index 20490b7..a93c0c0 100644 --- a/src/app/pets/page.tsx +++ b/src/app/pets/page.tsx @@ -1,15 +1,11 @@ "use client" -import { - PetList, - PetListHeader, - usePetsListPageViewModel, -} from "@/features/pets" +import { PetList, PetListHeader, usePetsPageViewModel } from "@/features/pets" import { CustomPagination, SectionLoader } from "@/shared/components" export default function Page() { const { pagePetCurrent, isLoading, page, handleChangePage } = - usePetsListPageViewModel() + usePetsPageViewModel() return (
diff --git a/src/features/pets/api/pets-api.ts b/src/features/pets/api/pets-api.ts index 98c81e4..b295fad 100644 --- a/src/features/pets/api/pets-api.ts +++ b/src/features/pets/api/pets-api.ts @@ -9,8 +9,11 @@ export const petsApi = { create: async (pet: PetSchema): Promise => { await api.post(BASE_URL, pet) }, - - get: async (page: number, size: number): Promise> => { + get: async (id: string): Promise => { + const { data } = await api.get(`${BASE_URL}/${id}`) + return data + }, + getAll: async (page: number, size: number): Promise> => { const { data } = await api.get(BASE_URL, { params: { page, size }, }) diff --git a/src/features/pets/components/pet-action-buttons/PetActionButtons.tsx b/src/features/pets/components/pet-action-buttons/PetActionButtons.tsx new file mode 100644 index 0000000..ad47a7a --- /dev/null +++ b/src/features/pets/components/pet-action-buttons/PetActionButtons.tsx @@ -0,0 +1,26 @@ +import { DeleteButton, InfoButton } from "@/shared/components" +import { cn } from "@/shared/lib/utils" +import { Edit, Trash2 } from "lucide-react" + +interface PetActionButtonsProps { + containerClassName?: string + infoButtonClassName?: string + deleteButtonClassName?: string +} + +export function PetActionButtons({ + containerClassName, + infoButtonClassName, + deleteButtonClassName, +}: PetActionButtonsProps) { + return ( +
+ + Editar + + + Excluir + +
+ ) +} diff --git a/src/features/pets/components/pet-card/PetCard.tsx b/src/features/pets/components/pet-card/PetCard.tsx index 0e5dab4..7d3f3b8 100644 --- a/src/features/pets/components/pet-card/PetCard.tsx +++ b/src/features/pets/components/pet-card/PetCard.tsx @@ -1,23 +1,26 @@ import { Pet } from "../../types/pets.types" -import { ContainerLayout, DeleteButton, InfoButton } from "@/shared/components" -import { Edit, Trash2, PawPrint } from "lucide-react" +import { ContainerLayout, ImagePlaceholder } from "@/shared/components" import { PetStatusBadge } from "../pet-status-badge/PetStatusBadge" +import { PetTagBadge } from "../pet-tag-badge/PetTagBadge" +import { PetActionButtons } from "../pet-action-buttons/PetActionButtons" +import { useNavigate } from "@/shared/hooks/useNavigate" interface PetCardProps { pet: Pet } export function PetCard({ pet }: PetCardProps) { + const { toPet } = useNavigate() + return ( toPet(pet.id)} > -
- -
+ -
+

{pet.name}

@@ -27,27 +30,18 @@ export function PetCard({ pet }: PetCardProps) {
{pet.tags.slice(0, 4).map((tag) => ( - - {tag} - + ))} {pet.tags.length > 4 && ( ... )}
-
- - Editar - - - Excluir - -
+ ) } diff --git a/src/features/pets/components/pet-details/PetDetails.test.tsx b/src/features/pets/components/pet-details/PetDetails.test.tsx new file mode 100644 index 0000000..6b5ed66 --- /dev/null +++ b/src/features/pets/components/pet-details/PetDetails.test.tsx @@ -0,0 +1,54 @@ +import { render, screen } from "@testing-library/react" +import { PetDetails } from "./PetDetails" +import { petResponseMock } from "@/shared/test-utils/mocks/pets-mocks" + +jest.mock("@/shared/components", () => ({ + ...jest.requireActual("@/shared/components"), + ImagePlaceholder: () =>
, +})) + +describe(PetDetails.name, () => { + it("should display content section titles", () => { + render() + + expect(screen.getByText("Fotos do Pet")).toBeInTheDocument() + expect(screen.getByText("Informações do Pet")).toBeInTheDocument() + }) + + it("should display the subtitles in the 'Informações do Pet' section", () => { + render() + + expect(screen.getByText("ID")).toBeInTheDocument() + expect(screen.getByText("Nome")).toBeInTheDocument() + expect(screen.getByText("Espécie")).toBeInTheDocument() + expect(screen.getByText("Status")).toBeInTheDocument() + expect(screen.getByText("Tags")).toBeInTheDocument() + }) + + it("should display 4 image placeholders", () => { + render() + expect(screen.getAllByTestId("image-placeholder")).toHaveLength(4) + }) + + it("should display pet information (id, name, species and status)", () => { + render() + + expect(screen.getByText(petResponseMock.id)).toBeInTheDocument() + expect(screen.getByText(petResponseMock.name)).toBeInTheDocument() + expect(screen.getByText(petResponseMock.species)).toBeInTheDocument() + expect(screen.getByText(/disponível/i)).toBeInTheDocument() + }) + + it("should display all pet tags", () => { + render() + petResponseMock.tags.forEach((tag) => { + expect(screen.getByText(tag)).toBeInTheDocument() + }) + }) + + it('should display "Nenhuma tag foi cadastrada" when there are no tags', () => { + const pet = { ...petResponseMock, tags: [] } + render() + expect(screen.getByText(/nenhuma tag foi cadastrada/i)).toBeInTheDocument() + }) +}) diff --git a/src/features/pets/components/pet-details/PetDetails.tsx b/src/features/pets/components/pet-details/PetDetails.tsx new file mode 100644 index 0000000..e572c26 --- /dev/null +++ b/src/features/pets/components/pet-details/PetDetails.tsx @@ -0,0 +1,59 @@ +import { ContainerLayout, ImagePlaceholder } from "@/shared/components" +import { Pet } from "../../types/pets.types" +import { PetStatusBadge } from "../pet-status-badge/PetStatusBadge" +import { PetTagBadge } from "../pet-tag-badge/PetTagBadge" + +interface PetDetailsProps { + pet: Pet | undefined +} + +export function PetDetails({ pet }: PetDetailsProps) { + if (!pet) return + + return ( +
+ + +
+ + + +
+
+ +
+
+

ID

+

{pet.id}

+
+
+

Nome

+

{pet.name}

+
+
+

Espécie

+

{pet.species}

+
+
+

Status

+ +
+
+

Tags

+ {pet.tags.length === 0 ? ( + + Nenhuma tag foi cadastrada + + ) : ( +
+ {pet.tags.map((tag) => ( + + ))} +
+ )} +
+
+
+
+ ) +} diff --git a/src/features/pets/components/pet-status-badge/PetStatusBadge.tsx b/src/features/pets/components/pet-status-badge/PetStatusBadge.tsx index 4b7f4e6..ad8f609 100644 --- a/src/features/pets/components/pet-status-badge/PetStatusBadge.tsx +++ b/src/features/pets/components/pet-status-badge/PetStatusBadge.tsx @@ -4,13 +4,13 @@ interface PetStatusBadgeProps { status: PetStatus } -const petStatusColors: Record = { - AVAILABLE: "bg-green-100 text-green-700 border-green-200", - IN_ANALYSIS: "bg-yellow-100 text-yellow-700 border-yellow-300", - ADOPTED: "bg-sky-100 text-sky-700 border-sky-200", -} - export function PetStatusBadge({ status }: PetStatusBadgeProps) { + const petStatusColors: Record = { + AVAILABLE: "bg-green-100 text-green-700 border-green-200", + IN_ANALYSIS: "bg-yellow-100 text-yellow-700 border-yellow-300", + ADOPTED: "bg-sky-100 text-sky-700 border-sky-200", + } + return ( + {tag} + + ) +} diff --git a/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.test.ts b/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.test.ts new file mode 100644 index 0000000..008e79a --- /dev/null +++ b/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.test.ts @@ -0,0 +1,80 @@ +import { renderHook } from "@testing-library/react" +import { usePetPageViewModel } from "./usePetPageViewModel" +import { petResponseMock } from "@/shared/test-utils/mocks/pets-mocks" +import { usePet } from "../pet/usePet" +import * as toastUtils from "@/shared/utils/toast-utils" +import { mockNavigation } from "../../../../../jest.setup" +import axios from "axios" + +jest.mock("@/features/pets/hooks/pet/usePet", () => ({ + usePet: jest.fn(), +})) +jest.mock("@/shared/utils/toast-utils", () => ({ + showErrorToast: jest.fn(), +})) +jest.mock("axios", () => ({ + isAxiosError: jest.fn(), +})) + +const baseHookMock = { + data: petResponseMock, + isLoading: false, + isError: false, + error: undefined, +} + +describe(usePetPageViewModel.name, () => { + beforeEach(() => { + jest.clearAllMocks() + ;(usePet as jest.Mock).mockReturnValue(baseHookMock) + }) + + it("should return the pet correctly", () => { + const { result } = renderHook(() => usePetPageViewModel(petResponseMock.id)) + expect(result.current.pet).toEqual(petResponseMock) + }) + + it("should return loading true when usePet is loading", () => { + ;(usePet as jest.Mock).mockReturnValue({ + ...baseHookMock, + isLoading: true, + }) + const { result } = renderHook(() => usePetPageViewModel(petResponseMock.id)) + expect(result.current.isLoading).toBe(true) + }) + + it("should return loading false when usePet is not loading", () => { + const { result } = renderHook(() => usePetPageViewModel(petResponseMock.id)) + expect(result.current.isLoading).toBe(false) + }) + + it('should show error toast with "Ops! Esse pet não está disponível." and navigate to Pets on 404 error', () => { + const error = { status: 404 } + ;(usePet as jest.Mock).mockReturnValue({ + ...baseHookMock, + isError: true, + error, + }) + ;(axios.isAxiosError as unknown as jest.Mock).mockReturnValue(true) + renderHook(() => usePetPageViewModel(petResponseMock.id)) + + expect(toastUtils.showErrorToast as jest.Mock).toHaveBeenCalledWith( + "Ops! Esse pet não está disponível." + ) + expect(mockNavigation.routerFunctions.push).toHaveBeenCalledWith("/pets") + }) + + it("should show default error toast and navigate to Pets on generic error", () => { + const error = { status: 500 } + ;(usePet as jest.Mock).mockReturnValue({ + ...baseHookMock, + isError: true, + error, + }) + ;(axios.isAxiosError as unknown as jest.Mock).mockReturnValue(true) + renderHook(() => usePetPageViewModel(petResponseMock.id)) + + expect(toastUtils.showErrorToast as jest.Mock).toHaveBeenCalled() + expect(mockNavigation.routerFunctions.push).toHaveBeenCalledWith("/pets") + }) +}) diff --git a/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.ts b/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.ts new file mode 100644 index 0000000..ab89e52 --- /dev/null +++ b/src/features/pets/hooks/pet-page-view-model/usePetPageViewModel.ts @@ -0,0 +1,33 @@ +import { useEffect } from "react" +import { Pet } from "../../types/pets.types" +import { showErrorToast } from "@/shared/utils/toast-utils" +import { usePet } from "../pet/usePet" +import axios from "axios" +import { useNavigate } from "@/shared/hooks/useNavigate" + +interface UsePetPageViewModelResult { + pet?: Pet + isLoading: boolean +} + +export function usePetPageViewModel(id: string): UsePetPageViewModelResult { + const { toPets } = useNavigate() + const { data, isLoading, isError, error } = usePet(id) + + useEffect(() => { + if (isError && axios.isAxiosError(error)) { + if (error.status === 404) { + showErrorToast("Ops! Esse pet não está disponível.") + } else { + showErrorToast() + } + + toPets() + } + }, [isError, error, toPets]) + + return { + pet: data, + isLoading, + } +} diff --git a/src/features/pets/hooks/pet/usePet.ts b/src/features/pets/hooks/pet/usePet.ts new file mode 100644 index 0000000..10b099d --- /dev/null +++ b/src/features/pets/hooks/pet/usePet.ts @@ -0,0 +1,10 @@ +import { useQuery } from "@tanstack/react-query" +import { petsApi } from "../../api/pets-api" +import { Pet } from "../../types/pets.types" + +export function usePet(id: string) { + return useQuery({ + queryKey: ["pet", id], + queryFn: () => petsApi.get(id), + }) +} diff --git a/src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.test.ts b/src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.test.ts similarity index 79% rename from src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.test.ts rename to src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.test.ts index d4e2a79..069ed29 100644 --- a/src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.test.ts +++ b/src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.test.ts @@ -1,5 +1,5 @@ import { renderHook, act } from "@testing-library/react" -import { usePetsListPageViewModel } from "./usePetsListViewModel" +import { usePetsPageViewModel } from "./usePetsPageViewModel" import { usePets } from "../pets/usePets" import * as toastUtils from "@/shared/utils/toast-utils" import { petPageMock } from "@/shared/test-utils/mocks/pets-mocks" @@ -18,14 +18,14 @@ const baseHookMock = { isError: false, } -describe(usePetsListPageViewModel.name, () => { +describe(usePetsPageViewModel.name, () => { beforeEach(() => { jest.clearAllMocks() ;(usePets as jest.Mock).mockReturnValue(baseHookMock) }) it("should return pets page data correctly", () => { - const { result } = renderHook(() => usePetsListPageViewModel()) + const { result } = renderHook(() => usePetsPageViewModel()) expect(result.current.pagePetCurrent).toEqual(petPageMock) expect(result.current.isLoading).toBe(false) expect(result.current.page).toBe(0) @@ -36,7 +36,7 @@ describe(usePetsListPageViewModel.name, () => { ...baseHookMock, isLoading: true, }) - const { result } = renderHook(() => usePetsListPageViewModel()) + const { result } = renderHook(() => usePetsPageViewModel()) expect(result.current.isLoading).toBe(true) }) @@ -45,7 +45,7 @@ describe(usePetsListPageViewModel.name, () => { ...baseHookMock, isFetching: true, }) - const { result } = renderHook(() => usePetsListPageViewModel()) + const { result } = renderHook(() => usePetsPageViewModel()) expect(result.current.isLoading).toBe(true) }) @@ -54,13 +54,13 @@ describe(usePetsListPageViewModel.name, () => { ...baseHookMock, isError: true, }) - renderHook(() => usePetsListPageViewModel()) + renderHook(() => usePetsPageViewModel()) expect(toastUtils.showErrorToast as jest.Mock).toHaveBeenCalled() }) it("should change page when handleChangePage is called", () => { const nextPage = 2 - const { result } = renderHook(() => usePetsListPageViewModel()) + const { result } = renderHook(() => usePetsPageViewModel()) act(() => { result.current.handleChangePage(nextPage) }) @@ -72,7 +72,7 @@ describe(usePetsListPageViewModel.name, () => { ...baseHookMock, data: undefined, }) - const { result } = renderHook(() => usePetsListPageViewModel()) + const { result } = renderHook(() => usePetsPageViewModel()) expect(result.current.pagePetCurrent).toEqual({ content: [], totalPages: 0, diff --git a/src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.ts b/src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.ts similarity index 88% rename from src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.ts rename to src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.ts index ccfa1a2..c4e609c 100644 --- a/src/features/pets/hooks/use-pets-list-view-model/usePetsListViewModel.ts +++ b/src/features/pets/hooks/pets-page-view-model/usePetsPageViewModel.ts @@ -4,14 +4,14 @@ import { PageResponse } from "@/shared/types/common.types" import { Pet } from "../../types/pets.types" import { showErrorToast } from "@/shared/utils/toast-utils" -interface UsePetsListPageViewModelResult { +interface UsePetsPageViewModelResult { pagePetCurrent: PageResponse isLoading: boolean page: number handleChangePage: (page: number) => void } -export function usePetsListPageViewModel(): UsePetsListPageViewModelResult { +export function usePetsPageViewModel(): UsePetsPageViewModelResult { const [page, setPage] = useState(0) const { data, isLoading: petsLoading, isFetching, isError } = usePets(page) diff --git a/src/features/pets/hooks/pets/usePets.ts b/src/features/pets/hooks/pets/usePets.ts index 7400684..aa5a0ff 100644 --- a/src/features/pets/hooks/pets/usePets.ts +++ b/src/features/pets/hooks/pets/usePets.ts @@ -6,7 +6,7 @@ import { Pet } from "../../types/pets.types" export function usePets(page = 0, size = 6) { return useQuery>({ queryKey: ["pets", page], - queryFn: () => petsApi.get(page, size), + queryFn: () => petsApi.getAll(page, size), placeholderData: keepPreviousData, }) } diff --git a/src/features/pets/index.ts b/src/features/pets/index.ts index 87c952e..8d58046 100644 --- a/src/features/pets/index.ts +++ b/src/features/pets/index.ts @@ -1,5 +1,9 @@ export { PetListHeader } from "./components/pet-list-header/PetListHeader" export { PetForm } from "./components/pet-form/PetForm" -export { useCreatePetPageViewModel } from "./hooks/create-pet-page-view-model/useCreatePetPageViewModel" export { PetList } from "./components/pet-list/PetList" -export { usePetsListPageViewModel } from "./hooks/use-pets-list-view-model/usePetsListViewModel" +export { PetDetails } from "./components/pet-details/PetDetails" +export { PetActionButtons } from "./components/pet-action-buttons/PetActionButtons" + +export { usePetsPageViewModel } from "./hooks/pets-page-view-model/usePetsPageViewModel" +export { useCreatePetPageViewModel } from "./hooks/create-pet-page-view-model/useCreatePetPageViewModel" +export { usePetPageViewModel } from "./hooks/pet-page-view-model/usePetPageViewModel" diff --git a/src/shared/components/index.ts b/src/shared/components/index.ts index b0ba2a7..a1d52fe 100644 --- a/src/shared/components/index.ts +++ b/src/shared/components/index.ts @@ -2,15 +2,20 @@ export { FormBase } from "@/shared/components/form/form-base/FormBase" export { InputField } from "@/shared/components/form/input-field/InputField" export { CheckboxField } from "@/shared/components/form/checkbox-field/CheckboxField" export { SelectField } from "@/shared/components/form/select-field/SelectField" -export { PageLayout } from "@/shared/components/layout/page-layout/PageLayout" + export { SectionLoader } from "@/shared/components/loaders/section-loader/SectionLoader" export { PageLoader } from "@/shared/components/loaders/page-loader/PageLoader" -export { ContainerLayout } from "@/shared/components/layout/container-layout/ContainerLayout" + export { PrimaryButton } from "./buttons/primary-button/PrimaryButton" export { LinkButton } from "./buttons/link-button/LinkButton" export { InfoButton } from "./buttons/info-button/InfoButton" export { SubmitButton } from "./buttons/submit-button/SubmitButton" export { DeleteButton } from "./buttons/delete-button/DeleteButton" + +export { PageLayout } from "@/shared/components/layout/page-layout/PageLayout" +export { ContainerLayout } from "@/shared/components/layout/container-layout/ContainerLayout" export { Footer } from "./layout/footer/Footer" export { Header } from "./layout/header/Header" +export { ImagePlaceholder } from "./layout/image-placeholder/ImagePlaceholder" + export { CustomPagination } from "./pagination/custom-pagination/CustomPagination" diff --git a/src/shared/components/layout/container-layout/ContainerLayout.tsx b/src/shared/components/layout/container-layout/ContainerLayout.tsx index 312b127..5e1a233 100644 --- a/src/shared/components/layout/container-layout/ContainerLayout.tsx +++ b/src/shared/components/layout/container-layout/ContainerLayout.tsx @@ -4,12 +4,14 @@ interface ContainerLayoutProps { title?: string className?: string children: React.ReactNode + onClick?: React.MouseEventHandler } export function ContainerLayout({ title, className, children, + onClick, }: ContainerLayoutProps) { return (
{title &&

{title}

} {children} diff --git a/src/shared/components/layout/image-placeholder/ImagePlaceholder.tsx b/src/shared/components/layout/image-placeholder/ImagePlaceholder.tsx new file mode 100644 index 0000000..ee875d5 --- /dev/null +++ b/src/shared/components/layout/image-placeholder/ImagePlaceholder.tsx @@ -0,0 +1,23 @@ +import { cn } from "@/shared/lib/utils" +import { PawPrint } from "lucide-react" + +interface ImagePlaceholderProps { + className?: string + iconSize?: number +} + +export function ImagePlaceholder({ + className, + iconSize = 65, +}: ImagePlaceholderProps) { + return ( +
+ +
+ ) +} diff --git a/src/shared/components/layout/page-layout/PageLayout.tsx b/src/shared/components/layout/page-layout/PageLayout.tsx index 79b5b60..450eecc 100644 --- a/src/shared/components/layout/page-layout/PageLayout.tsx +++ b/src/shared/components/layout/page-layout/PageLayout.tsx @@ -19,7 +19,7 @@ export function PageLayout({ const { goBack } = useNavigate() return ( -
+
diff --git a/src/shared/hooks/useNavigate.ts b/src/shared/hooks/useNavigate.ts index 05def74..8d6d5d5 100644 --- a/src/shared/hooks/useNavigate.ts +++ b/src/shared/hooks/useNavigate.ts @@ -3,19 +3,26 @@ import { useRouter } from "next/navigation" interface UseNavigateResult { toPets: () => void + toPet: (id: string) => void toNewPet: () => void goBack: () => void } export function useNavigate(): UseNavigateResult { + const BASE_PET_URL = "/pets" + const router = useRouter() + function toPet(id: string): void { + router.push(`${BASE_PET_URL}/${id}`) + } + function toPets(): void { - router.push("/pets") + router.push(BASE_PET_URL) } function toNewPet(): void { - router.push("/pets/novo") + router.push(`${BASE_PET_URL}/novo`) } function goBack(): void { @@ -24,6 +31,7 @@ export function useNavigate(): UseNavigateResult { return { toPets, + toPet, toNewPet, goBack, }