diff --git a/src/App.tsx b/src/App.tsx index ea5cd38..3a08722 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,9 +1,9 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; - import LandingPage from './pages/LandingPage' -import AuthenticatedDashboard from './pages/Dashboard'; +import Dashboard from './pages/Dashboard'; +import DevPage from './pages/DevPage'; import './App.css' @@ -16,12 +16,17 @@ function App() { - {/*public routes*/} + {/* public routes */} } /> - {/* protected routes*/} + + {/* protected routes */} } + element={} + /> + } /> diff --git a/src/components/LoginPanel/LoginPanel.tsx b/src/components/LoginPanel/LoginPanel.tsx index 9ad9d39..ff760fa 100644 --- a/src/components/LoginPanel/LoginPanel.tsx +++ b/src/components/LoginPanel/LoginPanel.tsx @@ -57,7 +57,7 @@ const LoginPanel = () => { setOpen(false); } catch (error: unknown) { - console.log(error); + console.error(error); if (error instanceof AxiosError) { setError(error.response?.data.error || "An error occurred"); return; diff --git a/src/hocs/WithAuth/WithAuth.tsx b/src/hocs/WithAuth/WithAuth.tsx index c800beb..8c077d5 100644 --- a/src/hocs/WithAuth/WithAuth.tsx +++ b/src/hocs/WithAuth/WithAuth.tsx @@ -1,21 +1,15 @@ import React, { useEffect, useState, ComponentType } from "react"; import { useNavigate } from "react-router-dom"; - -// eslint-disable-next-line @typescript-eslint/no-empty-object-type -type WithAuthProps = { - -}; - const withAuth =

(WrappedComponent: ComponentType

) => { - const ComponentWithAuth: React.FC

= (props) => { + const ComponentWithAuth: React.FC

= (props) => { const navigate = useNavigate(); const [isAuthenticated, setIsAuthenticated] = useState(false); useEffect(() => { const token = localStorage.getItem("token"); if (!token) { - navigate("/"); //maybe propmt them to login? + navigate("/"); //maybe propmt them to login? return; } diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index e8c99d0..f5a8711 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -2,9 +2,16 @@ import { useState, useEffect } from "react"; const TOKEN_STORAGE_KEY = "token"; +interface User { + userId: number; + username: string; + role: string; + iat: number; +} + const useAuth = () => { const [accessToken, setAccessToken] = useState(null); - const [user, setUser] = useState(null); + const [user, setUser] = useState(null); useEffect(() => { const storedToken = localStorage.getItem(TOKEN_STORAGE_KEY); diff --git a/src/models/QuestModels/questResponse.ts b/src/models/QuestModels/questResponse.ts new file mode 100644 index 0000000..5a42d88 --- /dev/null +++ b/src/models/QuestModels/questResponse.ts @@ -0,0 +1,6 @@ +export interface Quest { + title: string, + description: string, + objectives: string[], + image_url: string, +} \ No newline at end of file diff --git a/src/pages/Dashboard/Dashboard.tsx b/src/pages/Dashboard/Dashboard.tsx index 7e8c300..62d3965 100644 --- a/src/pages/Dashboard/Dashboard.tsx +++ b/src/pages/Dashboard/Dashboard.tsx @@ -17,4 +17,5 @@ const Dashboard: React.FC = () => { }; const AuthenticatedDashboard = withAuth(Dashboard); + export default AuthenticatedDashboard; \ No newline at end of file diff --git a/src/pages/DevPage.tsx b/src/pages/DevPage.tsx new file mode 100644 index 0000000..450339b --- /dev/null +++ b/src/pages/DevPage.tsx @@ -0,0 +1,41 @@ +import useAuth from "@/hooks/useAuth" +import questService from "@/service/questService"; +import { useState } from "react"; + +import { Quest } from "../models/QuestModels/questResponse" + +const DevPage: React.FC = () => { + const { accessToken } = useAuth(); + const [currentQuest, setCurrentQuest] = useState(null); + + const handleGetRandomQuest = async () => { + if (!accessToken) return; + const randomQuestResponse = await questService.getRandomQuest(accessToken); + + setCurrentQuest(randomQuestResponse); + } + + return ( +

+ { + + } + { + currentQuest && +
+ {currentQuest.title} + {currentQuest.description} + { + currentQuest.objectives?.map((objective, index) => + {objective} + )} +
+ } +
+ ) +} + +export default DevPage \ No newline at end of file diff --git a/src/pages/LandingPage/LandingPage.tsx b/src/pages/LandingPage/LandingPage.tsx index baa3c17..d38ae61 100644 --- a/src/pages/LandingPage/LandingPage.tsx +++ b/src/pages/LandingPage/LandingPage.tsx @@ -1,9 +1,8 @@ import LoginPanel from "@/components/LoginPanel"; import SuggestionsPanel from "@/components/SuggestionsPanel/SuggestionsPanel"; - +import { Link } from "react-router-dom"; const LandingPage = () => { - return (
@@ -11,7 +10,7 @@ const LandingPage = () => {

Welcome to the resurected rust app

- + Dev hre
diff --git a/src/service/questService.ts b/src/service/questService.ts new file mode 100644 index 0000000..2a8717a --- /dev/null +++ b/src/service/questService.ts @@ -0,0 +1,14 @@ +import sendRequest from "@/lib/sendRequest"; +import { Quest } from "../models/QuestModels/questResponse" + +const basePath = '/quests'; + +export default { + getRandomQuest: async (accessToken: string) => { + return await sendRequest({ + method: 'GET', + endpoint: `${basePath}/random-quest?filters=pvp,raiding`, + accessToken + }) as Promise; + }, +} \ No newline at end of file