feat(auth): implement login authorization

feat(font): implement satoshi font family
This commit is contained in:
shafin-r
2026-01-11 15:44:51 +06:00
parent bd6f1d2333
commit 1506c25796
35 changed files with 3870 additions and 7 deletions

View File

View File

@ -1,10 +1,27 @@
import "./App.css";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { Login } from "./pages/login";
import { StudentDashboard } from "./pages/StudentDashboard";
import { ProtectedRoute } from "./components/ProtectedRoute";
function App() {
return (
<>
<h1 className="text-7xl font-bold">Edbridge Scholars</h1>
</>
<BrowserRouter>
<Routes>
<Route path="/login" element={<Login />} />
{/* Protected Routes */}
<Route path="/student" element={<ProtectedRoute />}>
<Route index element={<StudentDashboard />} />
{/* Add more subroutes here as needed */}
</Route>
{/* Redirect root to student */}
<Route path="/" element={<Navigate to="/student" replace />} />
{/* Catch all - redirect to student */}
<Route path="*" element={<Navigate to="/student" replace />} />
</Routes>
</BrowserRouter>
);
}

172
src/assets/auth.css Normal file
View File

@ -0,0 +1,172 @@
/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.4.14,
* Autoprefixer: v10.4.7
* Browsers: last 4 version
*/
/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.4.14,
* Autoprefixer: v10.4.7
* Browsers: last 4 version
*/
/* Auth Pages Styling */
.login-container {
min-height: 100vh;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
background-color: var(--secondary-bg);
background-image: -o-linear-gradient(315deg, #f5f5f5 0%, #ffffff 100%);
background-image: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
padding: 1rem;
}
.auth-container {
max-width: 420px;
width: 100%;
padding: 2.5rem;
border-radius: 12px;
-webkit-box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
background-color: var(--tertiary-bg);
border: 1px solid var(--secondary-border);
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.auth-container:hover {
-webkit-box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
.auth-title {
text-align: center;
margin-bottom: 1.5rem;
color: var(--intensive-text);
font-weight: 700;
font-size: 1.75rem;
}
.auth-footer {
text-align: center;
margin-top: 1.5rem;
font-size: 0.9rem;
color: var(--neutral);
}
.auth-footer a {
color: var(--primary-text);
font-weight: 500;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.auth-footer a:hover {
text-decoration: underline;
}
/* Form Styling */
.auth-container .field {
margin-bottom: 1.25rem;
}
.auth-container .label {
color: var(--intensive-text) !important;
font-weight: 600;
font-size: 0.9rem;
margin-bottom: 0.5rem;
}
.auth-container .input {
color: var(--intensive-text) !important;
border-radius: 8px;
border: 1px solid var(--secondary-border);
padding: 0.75rem 1rem;
height: auto;
font-size: 1rem;
-webkit-box-shadow: none;
box-shadow: none;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.auth-container .input:focus {
border-color: var(--primary-bg);
-webkit-box-shadow: 0 0 0 2px rgba(110, 68, 255, 0.1);
box-shadow: 0 0 0 2px rgba(110, 68, 255, 0.1);
}
.auth-container .input.is-danger {
border-color: var(--error-bg);
}
.auth-container .button {
height: auto;
padding: 0.75rem 1.5rem;
font-weight: 600;
font-size: 1rem;
border-radius: 8px;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.auth-container .button.is-primary {
background-color: var(--primary-bg);
border: none;
}
.auth-container .button.is-primary:hover {
background-color: var(--primary-dark);
-webkit-box-shadow: 0 4px 12px rgba(110, 68, 255, 0.3);
box-shadow: 0 4px 12px rgba(110, 68, 255, 0.3);
-webkit-transform: translateY(-2px);
-ms-transform: translateY(-2px);
transform: translateY(-2px);
}
.auth-container .checkbox {
font-size: 0.9rem;
color: var(--neutral-dark);
}
.auth-container .help.is-danger {
font-size: 0.8rem;
margin-top: 0.25rem;
}
.auth-container .notification {
border-radius: 8px;
padding: 1rem;
margin-bottom: 1.5rem;
}
.auth-container .notification .delete {
position: absolute;
right: 0.75rem;
top: 0.75rem;
}
/* Responsive Adjustments */
@media screen and (max-width: 768px) {
.auth-container {
padding: 2rem;
max-width: 100%;
margin: 0 1rem;
}
}

2087
src/assets/custom.css Normal file

File diff suppressed because it is too large Load Diff

BIN
src/assets/ed_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
src/assets/ed_logo1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 62 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 127 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 57 KiB

10
src/assets/logo-dark.svg Normal file
View File

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="100" viewBox="0 0 400 100">
<style>
.logo-text { fill: #1F0954; font-family: Arial, sans-serif; font-weight: bold; }
.scholars-text { fill: #1F0954; font-family: Arial, sans-serif; font-weight: normal; }
.logo-shape { fill: #1F0954; }
</style>
<path class="logo-shape" d="M20,20 C20,60 60,80 100,80 L100,20 C60,20 60,60 20,60 Z" />
<text class="logo-text" x="120" y="70" font-size="48">EDBRIDGE</text>
<text class="scholars-text" x="120" y="90" font-size="20">SCHOLARS</text>
</svg>

After

Width:  |  Height:  |  Size: 565 B

View File

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="100" viewBox="0 0 400 100">
<style>
.logo-text { fill: #6E44FF; font-family: Arial, sans-serif; font-weight: bold; }
.scholars-text { fill: #6E44FF; font-family: Arial, sans-serif; font-weight: normal; }
.logo-shape { fill: #6E44FF; }
</style>
<path class="logo-shape" d="M20,20 C20,60 60,80 100,80 L100,20 C60,20 60,60 20,60 Z" />
<text class="logo-text" x="120" y="70" font-size="48">EDBRIDGE</text>
<text class="scholars-text" x="120" y="90" font-size="20">SCHOLARS</text>
</svg>

After

Width:  |  Height:  |  Size: 565 B

10
src/assets/logo-white.svg Normal file
View File

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="100" viewBox="0 0 400 100">
<style>
.logo-text { fill: #FFFFFF; font-family: Arial, sans-serif; font-weight: bold; }
.scholars-text { fill: #FFFFFF; font-family: Arial, sans-serif; font-weight: normal; }
.logo-shape { fill: #FFFFFF; }
</style>
<path class="logo-shape" d="M20,20 C20,60 60,80 100,80 L100,20 C60,20 60,60 20,60 Z" />
<text class="logo-text" x="120" y="70" font-size="48">EDBRIDGE</text>
<text class="scholars-text" x="120" y="90" font-size="20">SCHOLARS</text>
</svg>

After

Width:  |  Height:  |  Size: 565 B

132
src/assets/math-styles.css Normal file
View File

@ -0,0 +1,132 @@
/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.4.14,
* Autoprefixer: v10.4.7
* Browsers: last 4 version
*/
/* Math Rendering Styles */
/* General math container */
.math-content {
font-size: 1rem;
line-height: 1.6;
}
/* Inline math */
.math-inline {
display: inline-block;
vertical-align: middle;
}
/* Block math */
.math-block {
display: block;
margin: 1rem 0;
overflow-x: auto;
text-align: center;
}
/* Math editor toolbar */
.math-symbols-toolbar {
background-color: #f7f7f7;
border-radius: 6px;
padding: 0.75rem;
margin-top: 0.5rem;
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.math-symbols-toolbar button {
margin-right: 0.25rem;
margin-bottom: 0.25rem;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.math-symbols-toolbar button:hover {
background-color: #6e44ff;
color: white;
}
/* Math examples section */
.math-examples {
background-color: #f8f9fa;
border-radius: 6px;
padding: 0.75rem;
margin-top: 0.5rem;
border: 1px solid #e9ecef;
}
.math-examples table {
margin-bottom: 0;
}
.math-examples th,
.math-examples td {
padding: 0.4rem 0.5rem;
vertical-align: middle;
}
.math-examples code {
background-color: rgba(110, 68, 255, 0.1);
color: #6e44ff;
padding: 0.2rem 0.4rem;
border-radius: 4px;
}
/* Question option styling */
.option-content {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
max-width: calc(100% - 60px);
}
/* Short answer styling */
.short-answer-content {
background-color: rgba(0, 199, 164, 0.05);
border: 1px solid #00c7a4;
border-radius: 6px;
padding: 1rem;
}
/* Katex specific overrides */
.katex {
font-size: 1.1em;
}
.katex-display {
overflow-x: auto;
overflow-y: hidden;
padding: 0.5rem 0;
}
/* Preview mode styling */
.preview-container {
min-height: 100px;
background-color: #fff;
border: 1px solid #dbdbdb;
border-radius: 6px;
padding: 1rem;
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}
/* Tabs styling */
.tabs ul {
border-bottom-color: #dbdbdb;
}
.tabs li.is-active a {
border-bottom-color: #6e44ff;
color: #6e44ff;
}
/* Textarea focus styling */
#math-editor-textarea:focus {
border-color: #6e44ff;
-webkit-box-shadow: 0 0 0 0.125em rgba(110, 68, 255, 0.25);
box-shadow: 0 0 0 0.125em rgba(110, 68, 255, 0.25);
}

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

Before

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,781 @@
/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.4.14,
* Autoprefixer: v10.4.7
* Browsers: last 4 version
*/
/* Student Profile Custom Styles - Unconventional Design */
/* Container */
.student-profile-container {
max-width: 1400px;
margin: 0 auto;
padding: 2rem 1rem;
overflow-x: hidden;
}
/* Back Button */
.back-button-container {
margin-bottom: 2rem;
position: relative;
z-index: 10;
}
/* Hero Section */
.student-profile-hero {
background: -o-linear-gradient(315deg, #6e44ff 0%, #9f84ff 100%);
background: linear-gradient(135deg, #6e44ff 0%, #9f84ff 100%);
border-radius: 0;
padding: 0;
margin-bottom: 3rem;
position: relative;
overflow: hidden;
color: white;
min-height: 400px;
-webkit-box-shadow: 0 15px 30px rgba(110, 68, 255, 0.2);
box-shadow: 0 15px 30px rgba(110, 68, 255, 0.2);
}
.student-profile-hero::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23ffffff' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E");
opacity: 0.5;
}
.hero-content {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 3rem 2rem;
position: relative;
z-index: 2;
}
.student-info {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
padding-right: 2rem;
}
.hero-illustration {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
position: relative;
}
.hero-illustration img {
max-width: 100%;
max-height: 350px;
-webkit-transform: scale(1.2) translateY(-20px);
-ms-transform: scale(1.2) translateY(-20px);
transform: scale(1.2) translateY(-20px);
-webkit-filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
}
/* Student Profile Elements */
.student-profile-avatar {
width: 120px;
height: 120px;
border-radius: 0;
border: 4px solid white;
-webkit-box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 1.5rem;
}
.student-profile-name {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.student-profile-email {
font-size: 1.1rem;
opacity: 0.9;
margin-bottom: 1rem;
}
.student-profile-tags {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-bottom: 1.5rem;
}
.student-profile-tag {
background-color: rgba(255, 255, 255, 0.2);
color: white;
border-radius: 0;
padding: 0.3rem 1rem;
margin-right: 0.5rem;
font-weight: 500;
}
.student-profile-tag.is-active {
background-color: #00c7a4;
}
.student-profile-tag.is-inactive {
background-color: #ff2c73;
}
.student-profile-tag.is-suspended {
background-color: #ffa500;
}
.student-meta {
margin-top: 1.5rem;
}
.student-meta-item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-bottom: 0.5rem;
}
.student-meta-item .icon {
margin-right: 0.5rem;
}
/* Main Content Layout */
.student-profile-main {
display: -ms-grid;
display: grid;
-ms-grid-columns: 1fr 2rem 2fr;
grid-template-columns: 1fr 2fr;
gap: 2rem;
margin-top: 2rem;
}
/* Sections */
.student-profile-section {
background-color: white;
border-radius: 0;
-webkit-box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
padding: 1.5rem;
margin-bottom: 2rem;
position: relative;
overflow: hidden;
-webkit-transition: -webkit-transform 0.3s ease, -webkit-box-shadow 0.3s ease;
transition: -webkit-transform 0.3s ease, -webkit-box-shadow 0.3s ease;
-o-transition: transform 0.3s ease, box-shadow 0.3s ease;
transition: transform 0.3s ease, box-shadow 0.3s ease;
transition: transform 0.3s ease, box-shadow 0.3s ease,
-webkit-transform 0.3s ease, -webkit-box-shadow 0.3s ease;
}
.student-profile-section:hover {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
-webkit-box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}
.student-profile-section-title {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 1.5rem;
color: #333;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.student-profile-section-title::after {
content: "";
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
height: 2px;
background-color: #f0f0f0;
margin-left: 1rem;
}
/* Statistics Section */
.stats-section {
position: relative;
overflow: hidden;
}
.stats-illustration-container {
position: absolute;
top: -20px;
right: -20px;
opacity: 0.1;
z-index: 0;
-webkit-transform: rotate(10deg);
-ms-transform: rotate(10deg);
transform: rotate(10deg);
}
.stats-illustration {
width: 150px;
height: auto;
}
/* Performance Overview */
.performance-overview {
margin-bottom: 1.5rem;
position: relative;
z-index: 1;
}
.performance-header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-bottom: 1rem;
}
.performance-title {
font-size: 1.2rem;
font-weight: 600;
color: #333;
}
.performance-badge {
background-color: #6e44ff;
color: white;
padding: 0.3rem 1rem;
font-weight: 600;
font-size: 0.9rem;
border-radius: 0;
}
/* Stats Grid */
.stats-grid {
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 1rem;
position: relative;
z-index: 1;
margin-bottom: 2rem;
}
.student-profile-stat {
text-align: center;
padding: 1.5rem;
background-color: #f9f9f9;
border-radius: 0;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.student-profile-stat:hover {
background-color: #6e44ff;
color: white;
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
.student-profile-stat:hover .student-profile-stat-value,
.student-profile-stat:hover .student-profile-stat-label,
.student-profile-stat:hover .stat-trend {
color: white;
}
.student-profile-stat-value {
font-size: 2.5rem;
font-weight: 700;
color: #6e44ff;
line-height: 1;
margin-bottom: 0.5rem;
}
.student-profile-stat-label {
font-size: 0.9rem;
color: #666;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 600;
margin-bottom: 0.5rem;
}
.stat-trend {
font-size: 0.8rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
gap: 0.25rem;
}
.stat-trend.positive {
color: #00c7a4;
}
.stat-trend.negative {
color: #ff2c73;
}
.stat-trend.neutral {
color: #999;
}
/* Subject Performance */
.subject-performance {
position: relative;
z-index: 1;
}
.subject-performance-title {
font-size: 1.2rem;
font-weight: 600;
color: #333;
margin-bottom: 1rem;
}
.subject-cards {
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1rem;
}
.subject-card {
background-color: white;
border: 1px solid #f0f0f0;
-webkit-box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
overflow: hidden;
}
.subject-card:hover {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
-webkit-box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}
.subject-card-header {
background-color: #6e44ff;
color: white;
padding: 0.75rem 1rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.subject-card-label {
font-weight: 600;
font-size: 1rem;
}
.subject-card-score {
font-weight: 700;
font-size: 1.2rem;
}
.subject-card-body {
padding: 1rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.subject-card-icon {
width: 40px;
height: 40px;
background-color: rgba(110, 68, 255, 0.1);
border-radius: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-right: 1rem;
color: #6e44ff;
font-size: 1.2rem;
}
.subject-card-info {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.subject-card-trend {
font-size: 0.9rem;
font-weight: 600;
margin-bottom: 0.25rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
gap: 0.25rem;
}
.subject-card-trend.positive {
color: #00c7a4;
}
.subject-card-trend.negative {
color: #ff2c73;
}
.subject-card-trend.neutral {
color: #999;
}
.subject-card-status {
font-size: 0.8rem;
color: #666;
text-transform: uppercase;
letter-spacing: 1px;
}
/* Settings Section */
.settings-section {
margin-top: 2rem;
}
.settings-content {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.settings-illustration-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 1.5rem;
}
.settings-illustration {
max-width: 100%;
height: 150px;
}
/* Practice Sheets Section */
.practice-sheets-section {
position: relative;
}
.practice-sheets-content {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.practice-illustration-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 1.5rem;
}
.practice-illustration {
height: 120px;
width: auto;
}
.practice-sheets-table-container {
position: relative;
z-index: 1;
}
/* Activity Section */
.activity-section {
position: relative;
}
.activity-content {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.activity-illustration-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 1.5rem;
}
.activity-illustration {
height: 120px;
width: auto;
}
.activity-timeline-container {
position: relative;
z-index: 1;
}
.activity-timeline {
position: relative;
padding-left: 2rem;
}
.activity-timeline::before {
content: "";
position: absolute;
top: 0;
left: 8px;
height: 100%;
width: 2px;
background-color: #f0f0f0;
}
.activity-item {
position: relative;
padding-bottom: 1.5rem;
}
.activity-item:last-child {
padding-bottom: 0;
}
.activity-marker {
position: absolute;
left: -2rem;
top: 0;
width: 18px;
height: 18px;
border-radius: 0;
background-color: #6e44ff;
border: 3px solid white;
-webkit-box-shadow: 0 0 0 2px #f0f0f0;
box-shadow: 0 0 0 2px #f0f0f0;
z-index: 1;
}
.activity-marker.is-success {
background-color: #00c7a4;
}
.activity-marker.is-warning {
background-color: #ffd166;
}
.activity-date {
font-size: 0.8rem;
color: #999;
margin-bottom: 0.25rem;
font-weight: 500;
}
.activity-content {
font-weight: 500;
color: #333;
}
.activity-score {
font-weight: 700;
color: #6e44ff;
}
/* Illustration Sections */
.math-illustration-section,
.study-illustration-section {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 2rem;
background-color: #f9f9f9;
min-height: 300px;
}
.math-illustration,
.study-illustration {
max-width: 100%;
max-height: 250px;
-webkit-filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.1));
filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.1));
}
/* Button Styles */
.hip-button {
background-color: #6e44ff;
color: white;
border: none;
border-radius: 0;
padding: 0.5rem 1.5rem;
font-weight: 600;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
-webkit-box-shadow: 0 4px 10px rgba(110, 68, 255, 0.3);
box-shadow: 0 4px 10px rgba(110, 68, 255, 0.3);
}
.hip-button:hover {
background-color: #5a36d5;
-webkit-transform: translateY(-2px);
-ms-transform: translateY(-2px);
transform: translateY(-2px);
-webkit-box-shadow: 0 6px 15px rgba(110, 68, 255, 0.4);
box-shadow: 0 6px 15px rgba(110, 68, 255, 0.4);
color: white;
}
.hip-button.is-small {
padding: 0.25rem 0.75rem;
font-size: 0.85rem;
}
/* Responsive Styles */
@media screen and (max-width: 1200px) {
.student-profile-main {
-ms-grid-columns: 1fr;
grid-template-columns: 1fr;
}
.hero-content {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
text-align: center;
}
.student-info {
padding-right: 0;
margin-bottom: 2rem;
}
.student-profile-tags {
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.student-meta {
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.student-meta-item {
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
}
@media screen and (max-width: 768px) {
.student-profile-hero {
min-height: auto;
}
.hero-content {
padding: 2rem 1rem;
}
.student-profile-name {
font-size: 2rem;
}
.student-profile-avatar {
width: 100px;
height: 100px;
}
.hero-illustration img {
max-height: 200px;
}
.math-illustration-section,
.study-illustration-section {
min-height: 200px;
}
.math-illustration,
.study-illustration {
max-height: 180px;
}
}

View File

@ -0,0 +1,13 @@
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { useAuthStore } from "../stores/authStore";
export const ProtectedRoute = () => {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
const location = useLocation();
if (!isAuthenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
}
return <Outlet />;
};

View File

@ -1 +1,161 @@
@import "tailwindcss";
@import "tailwindcss";
/* ================================
Satoshi Font Family
================================ */
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Light.woff2") format("woff2");
font-weight: 300;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-LightItalic.woff2") format("woff2");
font-weight: 300;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Italic.woff2") format("woff2");
font-weight: 400;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Medium.woff2") format("woff2");
font-weight: 500;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-MediumItalic.woff2") format("woff2");
font-weight: 500;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Bold.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-BoldItalic.woff2") format("woff2");
font-weight: 700;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-Black.woff2") format("woff2");
font-weight: 900;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Satoshi";
src: url("./assets/fonts/Satoshi-BlackItalic.woff2") format("woff2");
font-weight: 900;
font-style: italic;
font-display: swap;
}
@theme {
--font-satoshi: "Satoshi", system-ui, sans-serif;
}
@layer utilities {
/* Base family */
.font-satoshi {
font-family: var(--font-satoshi);
}
/* Light */
.font-satoshi-light {
font-family: var(--font-satoshi);
font-weight: 300;
font-style: normal;
}
.font-satoshi-light-italic {
font-family: var(--font-satoshi);
font-weight: 300;
font-style: italic;
}
/* Regular */
.font-satoshi-regular {
font-family: var(--font-satoshi);
font-weight: 400;
font-style: normal;
}
.font-satoshi-italic {
font-family: var(--font-satoshi);
font-weight: 400;
font-style: italic;
}
/* Medium */
.font-satoshi-medium {
font-family: var(--font-satoshi);
font-weight: 500;
font-style: normal;
}
.font-satoshi-medium-italic {
font-family: var(--font-satoshi);
font-weight: 500;
font-style: italic;
}
/* Bold */
.font-satoshi-bold {
font-family: var(--font-satoshi);
font-weight: 700;
font-style: normal;
}
.font-satoshi-bold-italic {
font-family: var(--font-satoshi);
font-weight: 700;
font-style: italic;
}
/* Black */
.font-satoshi-black {
font-family: var(--font-satoshi);
font-weight: 900;
font-style: normal;
}
.font-satoshi-black-italic {
font-family: var(--font-satoshi);
font-weight: 900;
font-style: italic;
}
}

157
src/pages/Login.tsx Normal file
View File

@ -0,0 +1,157 @@
import { useState, useEffect } from "react";
import type { FormEvent } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import { useAuthStore } from "../stores/authStore";
interface LocationState {
from?: {
pathname: string;
};
}
export const Login = () => {
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
const navigate = useNavigate();
const location = useLocation();
const { login, isAuthenticated, isLoading, error, clearError } =
useAuthStore();
const from = (location.state as LocationState)?.from?.pathname || "/student";
// Redirect if already authenticated
useEffect(() => {
if (isAuthenticated) {
navigate("/student", { replace: true });
}
}, [isAuthenticated, navigate]);
// Clear error when component unmounts or inputs change
useEffect(() => {
return () => clearError();
}, [clearError]);
const handleSubmit = async (e: FormEvent<HTMLButtonElement>) => {
e.preventDefault();
clearError();
const success = await login({ email, password });
if (success) {
navigate(from, { replace: true });
}
};
// Don't render login form if already authenticated
if (isAuthenticated) {
return null;
}
return (
<div className="min-h-screen flex items-center justify-center ">
<div className="bg-white p-8 rounded-lg shadow-lg w-full max-w-sm border border-gray-300">
<div className="flex justify-center mb-6">
<img
src="src/assets/ed_logo.png"
alt="EdBridge logo"
className="h-15 w-auto object-contain"
draggable={false}
/>
</div>
<h2 className="text-3xl font-satoshi-bold text-center text-gray-800">
Welcome Back
</h2>
<div className="space-y-6">
<div>
<label
htmlFor="email"
className="block text-sm font-satoshi-medium text-gray-700 mb-2"
>
Email
</label>
<input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
disabled={isLoading}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent outline-none transition disabled:bg-gray-100 disabled:cursor-not-allowed"
placeholder="Enter your email"
/>
</div>
<div>
<label
htmlFor="password"
className="block text-sm font-satoshi-medium text-gray-700 mb-2"
>
Password
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={isLoading}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent outline-none transition disabled:bg-gray-100 disabled:cursor-not-allowed"
placeholder="Enter your password"
/>
<div className="flex items-center mt-4">
<input
id="rememberMe"
type="checkbox"
className="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded"
/>
<label
htmlFor="rememberMe"
className="ml-2 block text-sm font-satoshi-medium text-gray-700"
>
Remember me
</label>
</div>
</div>
{error && (
<div className="bg-red-50 text-red-600 p-3 rounded-lg text-sm">
{error}
</div>
)}
<button
onClick={handleSubmit}
disabled={isLoading || !email || !password}
className="w-full bg-indigo-600 text-white py-2 rounded-lg hover:bg-indigo-700 transition font-medium disabled:bg-gray-400 disabled:cursor-not-allowed flex items-center justify-center font-satoshi"
>
{isLoading ? (
<>
<svg
className="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Signing in...
</>
) : (
"Sign In"
)}
</button>
</div>
</div>
</div>
);
};

View File

@ -0,0 +1,62 @@
import { useNavigate } from "react-router-dom";
import { useAuthStore } from "../stores/authStore";
export const StudentDashboard = () => {
const user = useAuthStore((state) => state.user);
const logout = useAuthStore((state) => state.logout);
const navigate = useNavigate();
const handleLogout = () => {
logout();
navigate("/login");
};
return (
<div className="min-h-screen bg-gray-50">
<nav className="bg-white shadow-sm">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between items-center h-16">
<h1 className="text-xl font-semibold text-gray-800">
Student Portal
</h1>
<div className="flex items-center gap-4">
{user?.avatar_url && (
<img
src={user.avatar_url}
alt={user.name}
className="w-8 h-8 rounded-full"
/>
)}
<span className="text-sm text-gray-600">
Welcome, {user?.name}!
</span>
<button
onClick={handleLogout}
className="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 transition text-sm font-medium"
>
Logout
</button>
</div>
</div>
</div>
</nav>
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div className="bg-white rounded-lg shadow p-6">
<h2 className="text-2xl font-bold text-gray-800 mb-4">Dashboard</h2>
<div className="space-y-2 text-gray-600">
<p>Email: {user?.email}</p>
<p>Role: {user?.role}</p>
<p>Status: {user?.status}</p>
<p>
Member since:{" "}
{user?.joined_at
? new Date(user.joined_at).toLocaleDateString()
: "N/A"}
</p>
</div>
</div>
</main>
</div>
);
};

75
src/stores/authStore.ts Normal file
View File

@ -0,0 +1,75 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { api, type User, type LoginRequest } from "../utils/api";
interface AuthState {
user: User | null;
token: string | null;
isAuthenticated: boolean;
isLoading: boolean;
error: string | null;
login: (credentials: LoginRequest) => Promise<boolean>;
logout: () => void;
clearError: () => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
error: null,
login: async (credentials: LoginRequest) => {
set({ isLoading: true, error: null });
try {
const response = await api.login(credentials);
set({
user: response.user,
token: response.token,
isAuthenticated: true,
isLoading: false,
error: null,
});
return true;
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : "Login failed";
set({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
error: errorMessage,
});
return false;
}
},
logout: () => {
set({
user: null,
token: null,
isAuthenticated: false,
error: null,
});
},
clearError: () => set({ error: null }),
}),
{
name: "auth-storage",
partialize: (state) => ({
user: state.user,
token: state.token,
isAuthenticated: state.isAuthenticated,
}),
}
)
);

101
src/utils/api.ts Normal file
View File

@ -0,0 +1,101 @@
const API_URL = "https://dsat-api.edbridgescholars.com";
export interface LoginRequest {
email: string;
password: string;
}
export interface User {
email: string;
name: string;
role: "STUDENT" | "TEACHER" | "ADMIN";
avatar_url: string;
id: string;
status: "ACTIVE" | "INACTIVE";
joined_at: string;
last_active: string;
}
export interface LoginResponse {
token: string;
token_type: string;
user: User;
}
export interface ApiError {
detail?: string;
message?: string;
}
class ApiClient {
private baseURL: string;
constructor(baseURL: string) {
this.baseURL = baseURL;
}
private async request<T>(
endpoint: string,
options: RequestInit = {}
): Promise<T> {
const url = `${this.baseURL}${endpoint}`;
const config: RequestInit = {
...options,
headers: {
"Content-Type": "application/json",
...options.headers,
},
};
try {
const response = await fetch(url, config);
if (!response.ok) {
const error: ApiError = await response.json().catch(() => ({
message: "An error occurred",
}));
throw new Error(error.detail || error.message || "Request failed");
}
return await response.json();
} catch (error) {
if (error instanceof Error) {
throw error;
}
throw new Error("Network error occurred");
}
}
// Auth endpoints
async login(credentials: LoginRequest): Promise<LoginResponse> {
return this.request<LoginResponse>("/auth/login/", {
method: "POST",
body: JSON.stringify(credentials),
});
}
// Authenticated request helper
async authenticatedRequest<T>(
endpoint: string,
token: string,
options: RequestInit = {}
): Promise<T> {
return this.request<T>(endpoint, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
},
});
}
// Example: Get user profile (authenticated endpoint)
async getUserProfile(token: string): Promise<User> {
return this.authenticatedRequest<User>("/auth/me", token);
}
// Add more API methods here as needed
}
export const api = new ApiClient(API_URL);