Skip to content

Commit

Permalink
Merge pull request #149 from WildCodeSchool/fix/147/bugfix-admin-rout…
Browse files Browse the repository at this point in the history
…e-protection

typo role ADMIN into Admin
  • Loading branch information
AntoniSDev authored Dec 12, 2024
2 parents 79ad020 + 1ea0fa1 commit 84e8ce8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
img/node_modules
frontend/src/generated/graphql-types.ts
3 changes: 2 additions & 1 deletion frontend/src/components/AdminRouteProtection.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useContext } from "react";
import { Navigate } from "react-router-dom";
import { UserContext } from "./Layout";
import { Role } from "../interface/types";

function AdminRouteProtection({ children }: { children: React.ReactNode }) {
const userInfo = useContext(UserContext);

if (!userInfo.isLoggedIn || userInfo.role !== "ADMIN") {
if (!userInfo.isLoggedIn || userInfo.role !== Role.Admin) {
return <Navigate to="/" replace />;
}

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
import { Input, Button, message } from "antd";
import { Link } from "react-router-dom";
import { UserContext } from "../components/Layout";
import { Role, useLogoutLazyQuery } from "../generated/graphql-types";
import { useLogoutLazyQuery } from "../generated/graphql-types";
import Logo from "../assets/logo.png";
import RangePicker from "./RangePicker";
import { Role } from "../interface/types";

const { Search } = Input;

Expand All @@ -27,14 +28,13 @@ function Navbar() {
];

const onSearch = (value?: string) => {
console.log("value", value)
if (value) {
navigate(`/search/${value}`)
navigate(`/search/${value}`);
} else {
navigate("/search")
navigate("/search");
}
}
};

return (
<div className="flex flex-col p-4 bg-lightBlue">
<div className="flex justify-between items-center">
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/interface/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface NewProductFormValues {
export type Article = {
id: number;
product?: ProductCard;
reservations?: Reservation[] | null
reservations?: Reservation[] | null;
};

export type Reservation = {
Expand All @@ -78,3 +78,8 @@ export type Reservation = {
export type ReservationData = Reservation & {
totalPrice?: number;
};

export enum Role {
Admin = "Admin",
User = "User",
}

0 comments on commit 84e8ce8

Please sign in to comment.