Skip to content

Commit

Permalink
fix: PetType and refactored list
Browse files Browse the repository at this point in the history
  • Loading branch information
redxzeta committed May 11, 2022
1 parent 5fc872d commit 96c7ea1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/components/pets/PetType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "react-bootstrap";
import { Navigate, useParams } from "react-router-dom";
import useSWR from "swr";
import { PetListType } from "types/PetType";
import { PET_LIST_CONST, PetListType } from "types/PetType";

import { usePetAuth } from "../../context/TokenContext";
import { petFinderURL } from "../../routes/API";
Expand All @@ -34,7 +34,8 @@ export default function PetType() {
const { type } = useParams<{ type: PetListType }>();
const { tokenHeaders } = usePetAuth();

if (!type) return <Navigate to={"/pet"} replace={true} />;
if (!type || !PET_LIST_CONST.includes(type))
return <Navigate to={"/pets"} replace={true} />;

// Fetching the data through SWR
const { data: petSearchList, error: fetcherror } = useSWR(
Expand Down
25 changes: 14 additions & 11 deletions src/types/PetType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ export type AnimalPhotos = {
medium: string;
};

export type PetListType =
| "Dog"
| "Cat"
| "Rabbit"
| "Horse"
| "Bird"
| "dog"
| "cat"
| "rabbit"
| "horse"
| "bird";
export const PET_LIST_CONST = [
"Dog",
"Cat",
"Rabbit",
"Horse",
"Bird",
"dog",
"cat",
"rabbit",
"horse",
"bird",
] as const;

export type PetListType = typeof PET_LIST_CONST[number];

export type PetCardType = {
id: string;
Expand Down

0 comments on commit 96c7ea1

Please sign in to comment.