Skip to content

Commit

Permalink
Router
Browse files Browse the repository at this point in the history
  • Loading branch information
mtguerson committed Apr 8, 2024
1 parent e310ae5 commit 684b541
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 114 deletions.
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>fincheck</title>
</head>
<body>
<div id="root"></div>
Expand Down
6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
38 changes: 5 additions & 33 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
const [count, setCount] = useState(0)
import { Router } from "./Router";

export function App() {
return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}

export default App
<Router />
);
}
19 changes: 19 additions & 0 deletions frontend/src/Router/AuthGuard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Navigate, Outlet } from 'react-router-dom';

interface AuthGuardProps {
isPrivate: boolean;
}

export function AuthGuard({ isPrivate }: AuthGuardProps) {
const signedIn = false;

if (!signedIn && isPrivate) {
return <Navigate to="/login" replace />
}

if (signedIn && !isPrivate) {
return <Navigate to="/" replace />
}

return <Outlet />
}
19 changes: 19 additions & 0 deletions frontend/src/Router/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Routes, Route, BrowserRouter} from 'react-router-dom';
import {AuthGuard} from './AuthGuard';

export function Router() {
return (
<BrowserRouter>
<Routes>
<Route element={<AuthGuard isPrivate={false}/>}>
<Route path="/login" element={<h1>Login</h1>} />
<Route path="/register" element={<h1>Register</h1>} />
</Route>

<Route element={<AuthGuard isPrivate />}>
<Route path="/" element={<h1>Dashbord</h1>} />
</Route>
</Routes>
</BrowserRouter>
);
}
71 changes: 3 additions & 68 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
@@ -1,68 +1,3 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
@tailwind base;
@tailwind components;
@tailwind utilities;
2 changes: 1 addition & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { App } from './App'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
Expand Down
12 changes: 12 additions & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}

Loading

0 comments on commit 684b541

Please sign in to comment.