create-react-my-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +77 -0
- package/package.json +32 -0
- package/template/backend/config/db.js +21 -0
- package/template/backend/controllers/authcontroller.js +81 -0
- package/template/backend/controllers/reportcontroller.js +31 -0
- package/template/backend/database/schema.sql +21 -0
- package/template/backend/middleware/authentication.js +10 -0
- package/template/backend/package-lock.json +1417 -0
- package/template/backend/package.json +19 -0
- package/template/backend/routes/authroute.js +12 -0
- package/template/backend/routes/reportroute.js +7 -0
- package/template/backend/server.js +55 -0
- package/template/frontend/eslint.config.js +29 -0
- package/template/frontend/index.html +12 -0
- package/template/frontend/package-lock.json +3934 -0
- package/template/frontend/package.json +31 -0
- package/template/frontend/public/vite.svg +1 -0
- package/template/frontend/src/App.css +0 -0
- package/template/frontend/src/App.jsx +38 -0
- package/template/frontend/src/assets/react.svg +1 -0
- package/template/frontend/src/components/Button.jsx +44 -0
- package/template/frontend/src/components/Form.jsx +150 -0
- package/template/frontend/src/components/Navbar.jsx +83 -0
- package/template/frontend/src/components/Table.jsx +77 -0
- package/template/frontend/src/components/protectedroute.jsx +41 -0
- package/template/frontend/src/config/api.js +8 -0
- package/template/frontend/src/index.css +46 -0
- package/template/frontend/src/main.jsx +10 -0
- package/template/frontend/src/pages/login.jsx +42 -0
- package/template/frontend/src/pages/report.jsx +90 -0
- package/template/frontend/src/pages/signup.jsx +46 -0
- package/template/frontend/src/pages/trial.jsx +87 -0
- package/template/frontend/vite.config.js +10 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "client",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@tailwindcss/vite": "^4.1.17",
|
|
14
|
+
"axios": "^1.13.2",
|
|
15
|
+
"react": "^19.2.0",
|
|
16
|
+
"react-dom": "^19.2.0",
|
|
17
|
+
"react-router-dom": "^7.9.5",
|
|
18
|
+
"tailwindcss": "^4.1.17"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@eslint/js": "^9.39.1",
|
|
22
|
+
"@types/react": "^19.2.2",
|
|
23
|
+
"@types/react-dom": "^19.2.2",
|
|
24
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
25
|
+
"eslint": "^9.39.1",
|
|
26
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
27
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
28
|
+
"globals": "^16.5.0",
|
|
29
|
+
"vite": "^7.2.2"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<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="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
|
2
|
+
import Login from './pages/login';
|
|
3
|
+
import Signup from './pages/signup';
|
|
4
|
+
import Trial from './pages/trial';
|
|
5
|
+
import Report from './pages/report';
|
|
6
|
+
import ProtectedRoute from './components/protectedroute';
|
|
7
|
+
|
|
8
|
+
const App = () => (
|
|
9
|
+
<Router>
|
|
10
|
+
<div className="min-h-screen bg-black text-white">
|
|
11
|
+
<Routes>
|
|
12
|
+
<Route path="/login" element={<Login />} />
|
|
13
|
+
<Route path="/signup" element={<Signup />} />
|
|
14
|
+
<Route
|
|
15
|
+
path="/trial"
|
|
16
|
+
element={
|
|
17
|
+
<ProtectedRoute>
|
|
18
|
+
<Trial />
|
|
19
|
+
</ProtectedRoute>
|
|
20
|
+
}
|
|
21
|
+
/>
|
|
22
|
+
|
|
23
|
+
<Route
|
|
24
|
+
path="/report"
|
|
25
|
+
element={
|
|
26
|
+
<ProtectedRoute>
|
|
27
|
+
<Report />
|
|
28
|
+
</ProtectedRoute>
|
|
29
|
+
}
|
|
30
|
+
/>
|
|
31
|
+
<Route path="/" element={<Navigate to="/trial" replace />} />
|
|
32
|
+
<Route path="*" element={<Navigate to="/trial" replace />} />
|
|
33
|
+
</Routes>
|
|
34
|
+
</div>
|
|
35
|
+
</Router>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<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>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const sizes = {
|
|
2
|
+
sm: 'px-4 py-2 text-xs',
|
|
3
|
+
md: 'px-6 py-2.5 text-sm',
|
|
4
|
+
lg: 'px-8 py-3 text-base',
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const themes = {
|
|
8
|
+
white: 'bg-white text-black border border-white hover:bg-neutral-200',
|
|
9
|
+
black: 'bg-black text-white border border-white hover:bg-neutral-900',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const Button = ({
|
|
13
|
+
children,
|
|
14
|
+
text,
|
|
15
|
+
size = 'md',
|
|
16
|
+
theme = 'white',
|
|
17
|
+
type = 'button',
|
|
18
|
+
disabled = false,
|
|
19
|
+
loading = false,
|
|
20
|
+
className = '',
|
|
21
|
+
onClick,
|
|
22
|
+
...props
|
|
23
|
+
}) => {
|
|
24
|
+
const label = children ?? text;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<button
|
|
28
|
+
type={type}
|
|
29
|
+
disabled={disabled || loading}
|
|
30
|
+
onClick={onClick}
|
|
31
|
+
className={[
|
|
32
|
+
'inline-flex items-center justify-center font-medium uppercase tracking-wider rounded-sm transition-all duration-200 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed active:scale-[0.98]',
|
|
33
|
+
sizes[size] ?? sizes.md,
|
|
34
|
+
themes[theme] ?? themes.white,
|
|
35
|
+
className,
|
|
36
|
+
].join(' ')}
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
{loading ? 'Please wait...' : label}
|
|
40
|
+
</button>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default Button;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import Button from './Button';
|
|
3
|
+
|
|
4
|
+
const validateField = (field, value, formData = {}) => {
|
|
5
|
+
if (field.required && !String(value ?? '').trim()) {
|
|
6
|
+
return `${field.label || field.placeholder || field.name} is required`;
|
|
7
|
+
}
|
|
8
|
+
if (field.minLength && value && value.length < field.minLength) {
|
|
9
|
+
return `Must be at least ${field.minLength} characters`;
|
|
10
|
+
}
|
|
11
|
+
if (field.type === 'email' && value) {
|
|
12
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13
|
+
if (!emailRegex.test(value)) return 'Invalid email';
|
|
14
|
+
}
|
|
15
|
+
if (field.type === 'password' && value && field.validatePassword !== false) {
|
|
16
|
+
if (value.length < 6) return 'At least 6 characters';
|
|
17
|
+
if (!/[A-Z]/.test(value)) return 'Needs an uppercase letter';
|
|
18
|
+
if (!/[a-z]/.test(value)) return 'Needs a lowercase letter';
|
|
19
|
+
if (!/[0-9]/.test(value)) return 'Needs a number';
|
|
20
|
+
}
|
|
21
|
+
if (typeof field.validate === 'function') {
|
|
22
|
+
return field.validate(value, formData) || '';
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const Form = ({
|
|
28
|
+
fields = [],
|
|
29
|
+
onSubmit,
|
|
30
|
+
loading = false,
|
|
31
|
+
error = '',
|
|
32
|
+
submitText = 'Submit',
|
|
33
|
+
title = '',
|
|
34
|
+
description = '',
|
|
35
|
+
initialValues = {},
|
|
36
|
+
submitTheme = 'white',
|
|
37
|
+
submitSize = 'md',
|
|
38
|
+
className = '',
|
|
39
|
+
}) => {
|
|
40
|
+
const [formData, setFormData] = useState(initialValues);
|
|
41
|
+
const [errors, setErrors] = useState({});
|
|
42
|
+
|
|
43
|
+
const handleChange = (e) => {
|
|
44
|
+
const { name, value } = e.target;
|
|
45
|
+
setFormData((prev) => ({ ...prev, [name]: value }));
|
|
46
|
+
if (errors[name]) setErrors((prev) => ({ ...prev, [name]: '' }));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleSubmit = (e) => {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
const nextErrors = {};
|
|
52
|
+
let invalid = false;
|
|
53
|
+
|
|
54
|
+
fields.forEach((field) => {
|
|
55
|
+
const msg = validateField(field, formData[field.name], formData);
|
|
56
|
+
if (msg) {
|
|
57
|
+
nextErrors[field.name] = msg;
|
|
58
|
+
invalid = true;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (invalid) {
|
|
63
|
+
setErrors(nextErrors);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
onSubmit?.(formData);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const inputClass = (name) =>
|
|
71
|
+
`w-full h-11 px-4 bg-black border rounded-sm text-white placeholder:text-neutral-600 focus:outline-none transition-colors duration-200 ${
|
|
72
|
+
errors[name] ? 'border-neutral-400' : 'border-neutral-700 focus:border-white'
|
|
73
|
+
}`;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className={`animate-fade-in ${className}`}>
|
|
77
|
+
<div className="border border-neutral-800 rounded-sm p-6 sm:p-8">
|
|
78
|
+
{title && (
|
|
79
|
+
<h2 className="text-lg font-semibold text-white uppercase tracking-wider mb-1">{title}</h2>
|
|
80
|
+
)}
|
|
81
|
+
{description && <p className="text-neutral-500 text-sm mb-6">{description}</p>}
|
|
82
|
+
{error && (
|
|
83
|
+
<p className="text-sm text-neutral-300 border border-neutral-700 rounded-sm px-3 py-2 mb-5">
|
|
84
|
+
{error}
|
|
85
|
+
</p>
|
|
86
|
+
)}
|
|
87
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
88
|
+
{fields.map((field) => (
|
|
89
|
+
<div key={field.name}>
|
|
90
|
+
{field.label && (
|
|
91
|
+
<label htmlFor={field.name} className="block text-xs uppercase tracking-widest text-neutral-500 mb-1.5">
|
|
92
|
+
{field.label}
|
|
93
|
+
</label>
|
|
94
|
+
)}
|
|
95
|
+
{field.type === 'select' ? (
|
|
96
|
+
<select
|
|
97
|
+
id={field.name}
|
|
98
|
+
name={field.name}
|
|
99
|
+
value={formData[field.name] ?? ''}
|
|
100
|
+
onChange={handleChange}
|
|
101
|
+
required={field.required}
|
|
102
|
+
className={inputClass(field.name)}
|
|
103
|
+
>
|
|
104
|
+
<option value="">{field.placeholder}</option>
|
|
105
|
+
{(field.options ?? []).map((opt) => (
|
|
106
|
+
<option key={opt.value} value={opt.value}>
|
|
107
|
+
{opt.label}
|
|
108
|
+
</option>
|
|
109
|
+
))}
|
|
110
|
+
</select>
|
|
111
|
+
) : field.type === 'textarea' ? (
|
|
112
|
+
<textarea
|
|
113
|
+
id={field.name}
|
|
114
|
+
name={field.name}
|
|
115
|
+
value={formData[field.name] ?? ''}
|
|
116
|
+
onChange={handleChange}
|
|
117
|
+
placeholder={field.placeholder}
|
|
118
|
+
required={field.required}
|
|
119
|
+
rows={field.rows ?? 4}
|
|
120
|
+
className={`${inputClass(field.name)} h-auto py-3 resize-none`}
|
|
121
|
+
/>
|
|
122
|
+
) : (
|
|
123
|
+
<input
|
|
124
|
+
id={field.name}
|
|
125
|
+
type={field.type || 'text'}
|
|
126
|
+
name={field.name}
|
|
127
|
+
value={formData[field.name] ?? ''}
|
|
128
|
+
onChange={handleChange}
|
|
129
|
+
placeholder={field.placeholder}
|
|
130
|
+
required={field.required}
|
|
131
|
+
min={field.min}
|
|
132
|
+
max={field.max}
|
|
133
|
+
className={inputClass(field.name)}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
{errors[field.name] && (
|
|
137
|
+
<p className="text-xs text-neutral-400 mt-1">{errors[field.name]}</p>
|
|
138
|
+
)}
|
|
139
|
+
</div>
|
|
140
|
+
))}
|
|
141
|
+
<Button type="submit" theme={submitTheme} size={submitSize} loading={loading} className="w-full mt-2">
|
|
142
|
+
{submitText}
|
|
143
|
+
</Button>
|
|
144
|
+
</form>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default Form;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Link, useNavigate, useLocation } from 'react-router-dom';
|
|
3
|
+
import { api } from '../config/api';
|
|
4
|
+
import Button from './Button';
|
|
5
|
+
|
|
6
|
+
const Navbar = () => {
|
|
7
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
8
|
+
const [loggingOut, setLoggingOut] = useState(false);
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
const location = useLocation();
|
|
11
|
+
|
|
12
|
+
const links = [
|
|
13
|
+
{ to: '/trial', label: 'Form & Table' },
|
|
14
|
+
{ to: '/report', label: 'Report' },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const handleLogout = async () => {
|
|
18
|
+
try {
|
|
19
|
+
setLoggingOut(true);
|
|
20
|
+
await api.post('/auth/logout');
|
|
21
|
+
} catch {
|
|
22
|
+
/* still redirect */
|
|
23
|
+
} finally {
|
|
24
|
+
setLoggingOut(false);
|
|
25
|
+
setMenuOpen(false);
|
|
26
|
+
navigate('/login');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const linkClass = (path) =>
|
|
31
|
+
`text-sm uppercase tracking-widest transition-colors duration-200 ${location.pathname === path ? 'text-white' : 'text-neutral-500 hover:text-white'
|
|
32
|
+
}`;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<header className="sticky top-0 z-50 border-b border-neutral-800 bg-black/90 backdrop-blur-md">
|
|
36
|
+
<nav className="max-w-6xl mx-auto px-5 h-16 flex items-center justify-between">
|
|
37
|
+
<Link to="/trial" className="text-white font-semibold text-sm uppercase tracking-[0.2em]">
|
|
38
|
+
|
|
39
|
+
</Link>
|
|
40
|
+
|
|
41
|
+
<div className="hidden md:flex items-center gap-8">
|
|
42
|
+
{links.map((link) => (
|
|
43
|
+
<Link key={link.to} to={link.to} className={linkClass(link.to)}>
|
|
44
|
+
{link.label}
|
|
45
|
+
</Link>
|
|
46
|
+
))}
|
|
47
|
+
<Button size="sm" theme="black" onClick={handleLogout} loading={loggingOut}>
|
|
48
|
+
Logout
|
|
49
|
+
</Button>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<button
|
|
53
|
+
type="button"
|
|
54
|
+
className="md:hidden text-white text-xl leading-none"
|
|
55
|
+
onClick={() => setMenuOpen((o) => !o)}
|
|
56
|
+
aria-label="Menu"
|
|
57
|
+
>
|
|
58
|
+
{menuOpen ? '×' : '☰'}
|
|
59
|
+
</button>
|
|
60
|
+
</nav>
|
|
61
|
+
|
|
62
|
+
{menuOpen && (
|
|
63
|
+
<div className="md:hidden border-t border-neutral-800 px-5 py-6 flex flex-col gap-5 items-center animate-fade-in">
|
|
64
|
+
{links.map((link) => (
|
|
65
|
+
<Link
|
|
66
|
+
key={link.to}
|
|
67
|
+
to={link.to}
|
|
68
|
+
className={linkClass(link.to)}
|
|
69
|
+
onClick={() => setMenuOpen(false)}
|
|
70
|
+
>
|
|
71
|
+
{link.label}
|
|
72
|
+
</Link>
|
|
73
|
+
))}
|
|
74
|
+
<Button size="sm" theme="black" onClick={handleLogout} loading={loggingOut}>
|
|
75
|
+
Logout
|
|
76
|
+
</Button>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
</header>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default Navbar;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Button from './Button';
|
|
2
|
+
|
|
3
|
+
const Table = ({
|
|
4
|
+
columns = [],
|
|
5
|
+
data = [],
|
|
6
|
+
onEdit,
|
|
7
|
+
onDelete,
|
|
8
|
+
title = '',
|
|
9
|
+
emptyMessage = 'No data yet',
|
|
10
|
+
className = '',
|
|
11
|
+
}) => {
|
|
12
|
+
const hasActions = onEdit || onDelete;
|
|
13
|
+
const colSpan = columns.length + (hasActions ? 1 : 0);
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div className={`animate-fade-in ${className}`}>
|
|
17
|
+
<div className="border border-neutral-800 rounded-sm overflow-hidden">
|
|
18
|
+
{title && (
|
|
19
|
+
<div className="px-6 py-4 border-b border-neutral-800">
|
|
20
|
+
<h2 className="text-lg font-semibold text-white uppercase tracking-wider">{title}</h2>
|
|
21
|
+
</div>
|
|
22
|
+
)}
|
|
23
|
+
<div className="overflow-x-auto">
|
|
24
|
+
<table className="w-full min-w-[480px] text-sm">
|
|
25
|
+
<thead>
|
|
26
|
+
<tr className="border-b border-neutral-800 bg-neutral-950">
|
|
27
|
+
{columns.map((col) => (
|
|
28
|
+
<th key={col.key} className="px-5 py-3 text-left text-xs uppercase tracking-widest text-neutral-500 font-medium">
|
|
29
|
+
{col.label}
|
|
30
|
+
</th>
|
|
31
|
+
))}
|
|
32
|
+
{hasActions && (
|
|
33
|
+
<th className="px-5 py-3 text-left text-xs uppercase tracking-widest text-neutral-500 font-medium">
|
|
34
|
+
Actions
|
|
35
|
+
</th>
|
|
36
|
+
)}
|
|
37
|
+
</tr>
|
|
38
|
+
</thead>
|
|
39
|
+
<tbody>
|
|
40
|
+
{data.length === 0 ? (
|
|
41
|
+
<tr>
|
|
42
|
+
<td colSpan={colSpan} className="px-5 py-12 text-center text-neutral-500">
|
|
43
|
+
{emptyMessage}
|
|
44
|
+
</td>
|
|
45
|
+
</tr>
|
|
46
|
+
) : (
|
|
47
|
+
data.map((row, i) => (
|
|
48
|
+
<tr key={row.id ?? i} className="border-b border-neutral-900 hover:bg-neutral-950 transition-colors duration-150">
|
|
49
|
+
{columns.map((col) => (
|
|
50
|
+
<td key={col.key} className="px-5 py-3.5 text-neutral-300">
|
|
51
|
+
{col.render ? col.render(row[col.key], row) : row[col.key]}
|
|
52
|
+
</td>
|
|
53
|
+
))}
|
|
54
|
+
{hasActions && (
|
|
55
|
+
<td className="px-5 py-3.5">
|
|
56
|
+
<div className="flex flex-wrap gap-2">
|
|
57
|
+
{onEdit && (
|
|
58
|
+
<Button size="sm" theme="white" onClick={() => onEdit(row)}>Edit</Button>
|
|
59
|
+
)}
|
|
60
|
+
{onDelete && (
|
|
61
|
+
<Button size="sm" theme="black" onClick={() => onDelete(row)}>Delete</Button>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
</td>
|
|
65
|
+
)}
|
|
66
|
+
</tr>
|
|
67
|
+
))
|
|
68
|
+
)}
|
|
69
|
+
</tbody>
|
|
70
|
+
</table>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default Table;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Navigate } from 'react-router-dom';
|
|
3
|
+
import { api } from '../config/api';
|
|
4
|
+
|
|
5
|
+
const ProtectedRoute = ({ children }) => {
|
|
6
|
+
const [authenticated, setAuthenticated] = useState(false);
|
|
7
|
+
const [loading, setLoading] = useState(true);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const checkAuth = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const response = await api.get('/auth/me');
|
|
13
|
+
if (response.status === 200) {
|
|
14
|
+
setAuthenticated(true);
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
setAuthenticated(false);
|
|
18
|
+
} finally {
|
|
19
|
+
setLoading(false);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
checkAuth();
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
if (loading) {
|
|
27
|
+
return (
|
|
28
|
+
<div className="min-h-screen flex justify-center items-center bg-black">
|
|
29
|
+
<p className="text-neutral-400 text-sm uppercase tracking-widest">Loading...</p>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!authenticated) {
|
|
35
|
+
return <Navigate to="/login" replace />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return children;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default ProtectedRoute;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
html,
|
|
4
|
+
body,
|
|
5
|
+
#root {
|
|
6
|
+
min-height: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
background-color: #000000;
|
|
12
|
+
color: #ffffff;
|
|
13
|
+
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
|
14
|
+
-webkit-font-smoothing: antialiased;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@keyframes fade-in {
|
|
18
|
+
from {
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transform: translateY(8px);
|
|
21
|
+
}
|
|
22
|
+
to {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
transform: translateY(0);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.animate-fade-in {
|
|
29
|
+
animation: fade-in 0.35s ease-out forwards;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.page-shell {
|
|
33
|
+
min-height: calc(100vh - 4rem);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.auth-card {
|
|
37
|
+
border: 1px solid #262626;
|
|
38
|
+
background: #0a0a0a;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@media print {
|
|
42
|
+
header,
|
|
43
|
+
.no-print {
|
|
44
|
+
display: none !important;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Link, useNavigate } from 'react-router-dom';
|
|
3
|
+
import Form from '../components/Form';
|
|
4
|
+
import { api } from '../config/api';
|
|
5
|
+
|
|
6
|
+
const fields = [
|
|
7
|
+
{ name: 'username', label: 'Username', placeholder: 'Your username', required: true },
|
|
8
|
+
{ name: 'password', label: 'Password', type: 'password', placeholder: 'Your password', required: true, validatePassword: false },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const Login = () => {
|
|
12
|
+
const [error, setError] = useState('');
|
|
13
|
+
const [loading, setLoading] = useState(false);
|
|
14
|
+
const navigate = useNavigate();
|
|
15
|
+
|
|
16
|
+
const handleSubmit = async (data) => {
|
|
17
|
+
try {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
setError('');
|
|
20
|
+
await api.post('/auth/login', data);
|
|
21
|
+
navigate('/trial');
|
|
22
|
+
} catch (err) {
|
|
23
|
+
setError(err.response?.data?.message || 'Login failed');
|
|
24
|
+
} finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="min-h-screen flex items-center justify-center px-5 py-16">
|
|
31
|
+
<div className="w-full max-w-md animate-fade-in">
|
|
32
|
+
<p className="text-center text-xs uppercase tracking-[0.3em] text-neutral-500 mb-8">Welcome back</p>
|
|
33
|
+
<Form title="Login" fields={fields} onSubmit={handleSubmit} loading={loading} error={error} submitText="Sign in" submitTheme="white" />
|
|
34
|
+
<p className="text-center text-sm text-neutral-500 mt-8">
|
|
35
|
+
New here? <Link to="/signup" className="text-white hover:underline">Create account</Link>
|
|
36
|
+
</p>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default Login;
|