mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
api client for testing
This commit is contained in:
42
client/src/App.css
Normal file
42
client/src/App.css
Normal file
@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
127
client/src/App.tsx
Normal file
127
client/src/App.tsx
Normal file
@ -0,0 +1,127 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { CssBaseline, ThemeProvider, createTheme } from '@mui/material';
|
||||
import { AuthProvider } from './contexts/AuthContext';
|
||||
import { LoginForm } from './components/auth/LoginForm';
|
||||
import { RegisterForm } from './components/auth/RegisterForm';
|
||||
import { AuthLayout } from './components/layout/AuthLayout';
|
||||
import { Dashboard } from './components/dashboard/Dashboard';
|
||||
import { JuniorsList } from './components/juniors/JuniorsList';
|
||||
import { AddJuniorForm } from './components/juniors/AddJuniorForm';
|
||||
import { TasksList } from './components/tasks/TasksList';
|
||||
|
||||
// Create theme
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
primary: {
|
||||
main: '#00A7E1', // Bright blue like Zod Wallet
|
||||
light: '#33B7E7',
|
||||
dark: '#0074B2',
|
||||
},
|
||||
secondary: {
|
||||
main: '#FF6B6B', // Coral red for accents
|
||||
light: '#FF8E8E',
|
||||
dark: '#FF4848',
|
||||
},
|
||||
background: {
|
||||
default: '#F8F9FA',
|
||||
paper: '#FFFFFF',
|
||||
},
|
||||
text: {
|
||||
primary: '#2D3748', // Dark gray for main text
|
||||
secondary: '#718096', // Medium gray for secondary text
|
||||
},
|
||||
},
|
||||
typography: {
|
||||
fontFamily: '"Inter", "Helvetica", "Arial", sans-serif',
|
||||
h1: {
|
||||
fontWeight: 700,
|
||||
fontSize: '2.5rem',
|
||||
},
|
||||
h2: {
|
||||
fontWeight: 600,
|
||||
fontSize: '2rem',
|
||||
},
|
||||
h3: {
|
||||
fontWeight: 600,
|
||||
fontSize: '1.75rem',
|
||||
},
|
||||
h4: {
|
||||
fontWeight: 600,
|
||||
fontSize: '1.5rem',
|
||||
},
|
||||
h5: {
|
||||
fontWeight: 600,
|
||||
fontSize: '1.25rem',
|
||||
},
|
||||
h6: {
|
||||
fontWeight: 600,
|
||||
fontSize: '1rem',
|
||||
},
|
||||
button: {
|
||||
textTransform: 'none',
|
||||
fontWeight: 500,
|
||||
},
|
||||
},
|
||||
shape: {
|
||||
borderRadius: 12,
|
||||
},
|
||||
components: {
|
||||
MuiButton: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
borderRadius: '8px',
|
||||
padding: '8px 16px',
|
||||
fontWeight: 500,
|
||||
},
|
||||
contained: {
|
||||
boxShadow: 'none',
|
||||
'&:hover': {
|
||||
boxShadow: 'none',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiCard: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
borderRadius: '16px',
|
||||
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<AuthProvider>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
{/* Public routes */}
|
||||
<Route path="/login" element={<LoginForm />} />
|
||||
<Route path="/register" element={<RegisterForm />} />
|
||||
|
||||
{/* Protected routes */}
|
||||
<Route element={<AuthLayout />}>
|
||||
<Route path="/dashboard" element={<Dashboard />} />
|
||||
<Route path="/juniors" element={<JuniorsList />} />
|
||||
<Route path="/juniors/new" element={<AddJuniorForm />} />
|
||||
<Route path="/tasks" element={<TasksList />} />
|
||||
</Route>
|
||||
|
||||
{/* Redirect root to dashboard or login */}
|
||||
<Route
|
||||
path="/"
|
||||
element={<Navigate to="/dashboard" replace />}
|
||||
/>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</AuthProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
147
client/src/api/client.ts
Normal file
147
client/src/api/client.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import axios from 'axios';
|
||||
import { CreateJuniorRequest, JuniorTheme } from '../types/junior';
|
||||
import { CreateTaskRequest, TaskStatus, TaskSubmission } from '../types/task';
|
||||
|
||||
const API_BASE_URL = 'http://79.72.0.143';
|
||||
const AUTH_TOKEN = btoa('zod-digital:Zod2025'); // Base64 encode credentials
|
||||
|
||||
// Helper function to get auth header
|
||||
const getAuthHeader = () => {
|
||||
const token = localStorage.getItem('accessToken');
|
||||
return token ? `Bearer ${token}` : `Basic ${AUTH_TOKEN}`;
|
||||
};
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-client-id': 'web-client'
|
||||
}
|
||||
});
|
||||
|
||||
// Add request interceptor to include current auth header
|
||||
apiClient.interceptors.request.use(config => {
|
||||
config.headers.Authorization = getAuthHeader();
|
||||
return config;
|
||||
});
|
||||
|
||||
// Add response interceptor to handle errors
|
||||
apiClient.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
const errorMessage = error.response?.data?.message ||
|
||||
error.response?.data?.error ||
|
||||
error.message ||
|
||||
'An unexpected error occurred';
|
||||
|
||||
console.error('API Error:', {
|
||||
status: error.response?.status,
|
||||
message: errorMessage,
|
||||
data: error.response?.data
|
||||
});
|
||||
|
||||
// Throw error with meaningful message
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
);
|
||||
|
||||
// Auth API
|
||||
export const authApi = {
|
||||
register: (countryCode: string, phoneNumber: string) => {
|
||||
// Ensure phone number is in the correct format (remove any non-digit characters)
|
||||
const cleanPhoneNumber = phoneNumber.replace(/\D/g, '');
|
||||
return apiClient.post('/api/auth/register/otp', {
|
||||
countryCode: countryCode.startsWith('+') ? countryCode : `+${countryCode}`,
|
||||
phoneNumber: cleanPhoneNumber
|
||||
});
|
||||
},
|
||||
|
||||
verifyOtp: (countryCode: string, phoneNumber: string, otp: string) =>
|
||||
apiClient.post('/api/auth/register/verify', { countryCode, phoneNumber, otp }),
|
||||
|
||||
setEmail: (email: string) => {
|
||||
// Use the stored token from localStorage
|
||||
const storedToken = localStorage.getItem('accessToken');
|
||||
if (!storedToken) {
|
||||
throw new Error('No access token found');
|
||||
}
|
||||
return apiClient.post('/api/auth/register/set-email', { email });
|
||||
},
|
||||
|
||||
setPasscode: (passcode: string) => {
|
||||
// Use the stored token from localStorage
|
||||
const storedToken = localStorage.getItem('accessToken');
|
||||
if (!storedToken) {
|
||||
throw new Error('No access token found');
|
||||
}
|
||||
return apiClient.post('/api/auth/register/set-passcode', { passcode });
|
||||
},
|
||||
|
||||
login: (email: string, password: string) =>
|
||||
apiClient.post('/api/auth/login', {
|
||||
grantType: 'PASSWORD',
|
||||
email,
|
||||
password,
|
||||
fcmToken: 'web-client-token', // Required by API
|
||||
signature: 'web-login' // Required by API
|
||||
})
|
||||
};
|
||||
|
||||
// Juniors API
|
||||
export const juniorsApi = {
|
||||
createJunior: (data: CreateJuniorRequest) =>
|
||||
apiClient.post('/api/juniors', data),
|
||||
|
||||
getJuniors: (page = 1, size = 10) =>
|
||||
apiClient.get(`/api/juniors?page=${page}&size=${size}`),
|
||||
|
||||
getJunior: (juniorId: string) =>
|
||||
apiClient.get(`/api/juniors/${juniorId}`),
|
||||
|
||||
setTheme: (data: JuniorTheme) =>
|
||||
apiClient.post('/api/juniors/set-theme', data),
|
||||
|
||||
getQrCode: (juniorId: string) =>
|
||||
apiClient.get(`/api/juniors/${juniorId}/qr-code`),
|
||||
|
||||
validateQrCode: (token: string) =>
|
||||
apiClient.get(`/api/juniors/qr-code/${token}/validate`)
|
||||
};
|
||||
|
||||
// Document API
|
||||
export const documentApi = {
|
||||
upload: (file: File, documentType: string) => {
|
||||
const formData = new FormData();
|
||||
formData.append('document', file);
|
||||
formData.append('documentType', documentType);
|
||||
return apiClient.post('/api/document', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Tasks API
|
||||
export const tasksApi = {
|
||||
createTask: (data: CreateTaskRequest) =>
|
||||
apiClient.post('/api/tasks', data),
|
||||
|
||||
getTasks: (status: TaskStatus, page = 1, size = 10, juniorId?: string) => {
|
||||
const url = new URL('/api/tasks', API_BASE_URL);
|
||||
url.searchParams.append('status', status);
|
||||
url.searchParams.append('page', page.toString());
|
||||
url.searchParams.append('size', size.toString());
|
||||
if (juniorId) url.searchParams.append('juniorId', juniorId);
|
||||
return apiClient.get(url.pathname + url.search);
|
||||
},
|
||||
|
||||
submitTask: (taskId: string, data: TaskSubmission) =>
|
||||
apiClient.patch(`/api/tasks/${taskId}/submit`, data),
|
||||
|
||||
approveTask: (taskId: string) =>
|
||||
apiClient.patch(`/api/tasks/${taskId}/approve`),
|
||||
|
||||
rejectTask: (taskId: string) =>
|
||||
apiClient.patch(`/api/tasks/${taskId}/reject`)
|
||||
};
|
1
client/src/assets/react.svg
Normal file
1
client/src/assets/react.svg
Normal file
@ -0,0 +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>
|
After Width: | Height: | Size: 4.0 KiB |
146
client/src/components/auth/LoginForm.tsx
Normal file
146
client/src/components/auth/LoginForm.tsx
Normal file
@ -0,0 +1,146 @@
|
||||
import { Alert, Box, Button, Container, Paper, TextField, Typography } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
|
||||
export const LoginForm = () => {
|
||||
const { login } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const [formData, setFormData] = useState({
|
||||
email: '',
|
||||
password: '',
|
||||
});
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await login(formData.email, formData.password);
|
||||
navigate('/dashboard');
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Login failed. Please check your credentials.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[name]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: 'background.default',
|
||||
}}
|
||||
>
|
||||
<Container maxWidth="sm" sx={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
|
||||
<Box sx={{ mb: 4, textAlign: 'center' }}>
|
||||
<Typography variant="h3" component="h1" gutterBottom sx={{ fontWeight: 700, color: 'primary.main' }}>
|
||||
Zod Alkhair | API TEST
|
||||
</Typography>
|
||||
<Typography variant="h6" sx={{ color: 'text.secondary', mb: 4 }}>
|
||||
login to your account.
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
p: 4,
|
||||
borderRadius: 3,
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
backgroundColor: 'background.paper'
|
||||
}}
|
||||
>
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Box component="form" onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Email"
|
||||
name="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
autoFocus
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Password"
|
||||
name="password"
|
||||
type="password"
|
||||
value={formData.password}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
fullWidth
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{
|
||||
mt: 3,
|
||||
mb: 2,
|
||||
height: 48,
|
||||
borderRadius: 2,
|
||||
textTransform: 'none',
|
||||
fontSize: '1rem'
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Signing in...' : 'Sign in'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
fullWidth
|
||||
variant="text"
|
||||
sx={{
|
||||
textTransform: 'none',
|
||||
fontSize: '1rem',
|
||||
color: 'text.secondary',
|
||||
'&:hover': {
|
||||
color: 'primary.main'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/register')}
|
||||
>
|
||||
signup
|
||||
</Button>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
};
|
254
client/src/components/auth/RegisterForm.tsx
Normal file
254
client/src/components/auth/RegisterForm.tsx
Normal file
@ -0,0 +1,254 @@
|
||||
import { Alert, Box, Button, Container, Paper, Step, StepLabel, Stepper, TextField, Typography } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
|
||||
const steps = ['Phone Verification', 'Email', 'Set Passcode'];
|
||||
|
||||
export const RegisterForm = () => {
|
||||
const { register, verifyOtp, setEmail, setPasscode } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const [activeStep, setActiveStep] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [formData, setFormData] = useState({
|
||||
countryCode: '+962',
|
||||
phoneNumber: '',
|
||||
otp: '',
|
||||
email: '',
|
||||
passcode: '',
|
||||
confirmPasscode: '',
|
||||
otpRequested: false
|
||||
});
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
switch (activeStep) {
|
||||
case 0:
|
||||
if (!formData.otpRequested) {
|
||||
// Request OTP
|
||||
await register(formData.countryCode, formData.phoneNumber);
|
||||
setFormData(prev => ({ ...prev, otpRequested: true }));
|
||||
} else {
|
||||
// Verify OTP
|
||||
await verifyOtp(formData.countryCode, formData.phoneNumber, formData.otp);
|
||||
setActiveStep(1);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
await setEmail(formData.email);
|
||||
setActiveStep(2);
|
||||
break;
|
||||
case 2:
|
||||
if (formData.passcode !== formData.confirmPasscode) {
|
||||
throw new Error('Passcodes do not match');
|
||||
}
|
||||
await setPasscode(formData.passcode);
|
||||
navigate('/dashboard');
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Registration failed');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[name]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
const renderStepContent = () => {
|
||||
switch (activeStep) {
|
||||
case 0:
|
||||
return (
|
||||
<>
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Phone Number"
|
||||
name="phoneNumber"
|
||||
value={formData.phoneNumber}
|
||||
onChange={handleInputChange}
|
||||
placeholder="7XXXXXXXX"
|
||||
required
|
||||
disabled={formData.otpRequested}
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{formData.otpRequested && (
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="OTP"
|
||||
name="otp"
|
||||
value={formData.otp}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter OTP"
|
||||
required
|
||||
autoFocus
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
case 1:
|
||||
return (
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Email"
|
||||
name="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
autoFocus
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
case 2:
|
||||
return (
|
||||
<>
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Passcode"
|
||||
name="passcode"
|
||||
type="password"
|
||||
value={formData.passcode}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
autoFocus
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<TextField
|
||||
fullWidth
|
||||
margin="normal"
|
||||
label="Confirm Passcode"
|
||||
name="confirmPasscode"
|
||||
type="password"
|
||||
value={formData.confirmPasscode}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
sx={{
|
||||
'& .MuiOutlinedInput-root': {
|
||||
borderRadius: 2,
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: 'background.default',
|
||||
}}
|
||||
>
|
||||
<Container maxWidth="sm" sx={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
|
||||
<Box sx={{ mb: 4, textAlign: 'center' }}>
|
||||
<Typography variant="h3" component="h1" gutterBottom sx={{ fontWeight: 700, color: 'primary.main' }}>
|
||||
Zod Alkhair | API TEST
|
||||
</Typography>
|
||||
<Typography variant="h6" sx={{ color: 'text.secondary', mb: 4 }}>
|
||||
signup
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Paper
|
||||
elevation={0}
|
||||
sx={{
|
||||
p: 4,
|
||||
borderRadius: 3,
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
backgroundColor: 'background.paper'
|
||||
}}
|
||||
>
|
||||
<Stepper activeStep={activeStep} sx={{ mb: 4 }}>
|
||||
{steps.map((label) => (
|
||||
<Step key={label}>
|
||||
<StepLabel>{label}</StepLabel>
|
||||
</Step>
|
||||
))}
|
||||
</Stepper>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Box component="form" onSubmit={handleSubmit}>
|
||||
{renderStepContent()}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
fullWidth
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{
|
||||
mt: 3,
|
||||
mb: 2,
|
||||
height: 48,
|
||||
borderRadius: 2,
|
||||
textTransform: 'none',
|
||||
fontSize: '1rem'
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Processing...' : activeStep === 0 && !formData.otpRequested ? 'Send OTP' : 'Continue'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
fullWidth
|
||||
variant="text"
|
||||
sx={{
|
||||
textTransform: 'none',
|
||||
fontSize: '1rem',
|
||||
color: 'text.secondary',
|
||||
'&:hover': {
|
||||
color: 'primary.main'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/login')}
|
||||
>
|
||||
sign in
|
||||
</Button>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
};
|
151
client/src/components/dashboard/Dashboard.tsx
Normal file
151
client/src/components/dashboard/Dashboard.tsx
Normal file
@ -0,0 +1,151 @@
|
||||
import {
|
||||
People as PeopleIcon,
|
||||
Assignment as TaskIcon,
|
||||
TrendingUp as TrendingUpIcon,
|
||||
AccountBalance as WalletIcon
|
||||
} from '@mui/icons-material';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Card,
|
||||
CardContent,
|
||||
Grid,
|
||||
Paper,
|
||||
Typography,
|
||||
useTheme
|
||||
} from '@mui/material';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
export const Dashboard = () => {
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const stats = [
|
||||
{
|
||||
title: 'Total Juniors',
|
||||
value: '3',
|
||||
icon: <PeopleIcon sx={{ fontSize: 40, color: 'primary.main' }} />,
|
||||
action: () => navigate('/juniors')
|
||||
},
|
||||
{
|
||||
title: 'Active Tasks',
|
||||
value: '5',
|
||||
icon: <TaskIcon sx={{ fontSize: 40, color: 'secondary.main' }} />,
|
||||
action: () => navigate('/tasks')
|
||||
},
|
||||
{
|
||||
title: 'Total Balance',
|
||||
value: 'SAR 500',
|
||||
icon: <WalletIcon sx={{ fontSize: 40, color: 'success.main' }} />,
|
||||
action: () => { }
|
||||
},
|
||||
{
|
||||
title: 'Monthly Growth',
|
||||
value: '+15%',
|
||||
icon: <TrendingUpIcon sx={{ fontSize: 40, color: 'info.main' }} />,
|
||||
action: () => { }
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Box sx={{ mb: 4 }}>
|
||||
<Typography variant="h4" sx={{ fontWeight: 600, color: 'text.primary', mb: 1 }}>
|
||||
Welcome to Zod Alkhair,
|
||||
</Typography>
|
||||
<Typography variant="body1" sx={{ color: 'text.secondary' }}>
|
||||
This is the API Testing client
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Grid container spacing={3} sx={{ mb: 4 }}>
|
||||
{stats.map((stat, index) => (
|
||||
<Grid item xs={12} sm={6} md={3} key={index}>
|
||||
<Card
|
||||
sx={{
|
||||
height: '100%',
|
||||
cursor: 'pointer',
|
||||
transition: 'transform 0.2s',
|
||||
'&:hover': {
|
||||
transform: 'translateY(-4px)'
|
||||
}
|
||||
}}
|
||||
onClick={stat.action}
|
||||
>
|
||||
<CardContent>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
|
||||
{stat.icon}
|
||||
</Box>
|
||||
<Typography variant="h5" sx={{ fontWeight: 600, mb: 1 }}>
|
||||
{stat.value}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary' }}>
|
||||
{stat.title}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
|
||||
<Grid container spacing={3}>
|
||||
<Grid item xs={12} md={8}>
|
||||
<Paper
|
||||
sx={{
|
||||
p: 3,
|
||||
height: '100%',
|
||||
backgroundColor: theme.palette.primary.main,
|
||||
color: 'white'
|
||||
}}
|
||||
>
|
||||
<Typography variant="h6" sx={{ mb: 2, fontWeight: 600 }}>
|
||||
Quick Actions
|
||||
</Typography>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Button
|
||||
fullWidth
|
||||
variant="contained"
|
||||
sx={{
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
||||
'&:hover': {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.2)'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/juniors/new')}
|
||||
>
|
||||
Add New Junior
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Button
|
||||
fullWidth
|
||||
variant="contained"
|
||||
sx={{
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
||||
'&:hover': {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.2)'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/tasks/new')}
|
||||
>
|
||||
Create New Task
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Paper>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<Paper sx={{ p: 3, height: '100%' }}>
|
||||
<Typography variant="h6" sx={{ mb: 2, fontWeight: 600 }}>
|
||||
Recent Activity
|
||||
</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ textAlign: 'center', mt: 4 }}>
|
||||
No recent activity
|
||||
</Typography>
|
||||
</Paper>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
);
|
||||
};
|
90
client/src/components/document/DocumentUpload.tsx
Normal file
90
client/src/components/document/DocumentUpload.tsx
Normal file
@ -0,0 +1,90 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
CircularProgress,
|
||||
Alert
|
||||
} from '@mui/material';
|
||||
import { CloudUpload as CloudUploadIcon } from '@mui/icons-material';
|
||||
import { documentApi } from '../../api/client';
|
||||
import { DocumentType } from '../../types/document';
|
||||
import { ApiError } from '../../types/api';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
interface DocumentUploadProps {
|
||||
onUploadSuccess: (documentId: string) => void;
|
||||
documentType: DocumentType;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export const DocumentUpload = ({ onUploadSuccess, documentType, label }: DocumentUploadProps) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [success, setSuccess] = useState(false);
|
||||
|
||||
const handleFileChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setLoading(true);
|
||||
setError('');
|
||||
setSuccess(false);
|
||||
|
||||
try {
|
||||
const response = await documentApi.upload(file, documentType);
|
||||
console.log('Document upload response:', response.data);
|
||||
const documentId = response.data.data.id;
|
||||
console.log('Extracted document ID:', documentId);
|
||||
onUploadSuccess(documentId);
|
||||
setSuccess(true);
|
||||
} catch (err) {
|
||||
if (err instanceof AxiosError && err.response?.data) {
|
||||
const apiError = err.response.data as ApiError;
|
||||
const messages = Array.isArray(apiError.message)
|
||||
? apiError.message.map(m => `${m.field}: ${m.message}`).join('\n')
|
||||
: apiError.message;
|
||||
setError(messages);
|
||||
} else {
|
||||
setError(err instanceof Error ? err.message : 'Failed to upload document');
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<input
|
||||
accept="image/*,.pdf"
|
||||
style={{ display: 'none' }}
|
||||
id={`upload-${documentType}`}
|
||||
type="file"
|
||||
onChange={handleFileChange}
|
||||
disabled={loading}
|
||||
/>
|
||||
<label htmlFor={`upload-${documentType}`}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
component="span"
|
||||
startIcon={loading ? <CircularProgress size={20} /> : <CloudUploadIcon />}
|
||||
disabled={loading}
|
||||
fullWidth
|
||||
>
|
||||
{loading ? 'Uploading...' : label}
|
||||
</Button>
|
||||
</label>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mt: 1, whiteSpace: 'pre-line' }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{success && (
|
||||
<Alert severity="success" sx={{ mt: 1 }}>
|
||||
Document uploaded successfully
|
||||
</Alert>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
266
client/src/components/juniors/AddJuniorForm.tsx
Normal file
266
client/src/components/juniors/AddJuniorForm.tsx
Normal file
@ -0,0 +1,266 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Box,
|
||||
TextField,
|
||||
Button,
|
||||
Typography,
|
||||
Paper,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
Select,
|
||||
MenuItem,
|
||||
Grid,
|
||||
Alert,
|
||||
SelectChangeEvent,
|
||||
Divider
|
||||
} from '@mui/material';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { juniorsApi } from '../../api/client';
|
||||
import { CreateJuniorRequest } from '../../types/junior';
|
||||
import { DocumentUpload } from '../document/DocumentUpload';
|
||||
import { DocumentType } from '../../types/document';
|
||||
import { ApiError } from '../../types/api';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
export const AddJuniorForm = () => {
|
||||
const navigate = useNavigate();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [formData, setFormData] = useState<CreateJuniorRequest>({
|
||||
countryCode: '+962',
|
||||
phoneNumber: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
dateOfBirth: '',
|
||||
email: '',
|
||||
relationship: 'PARENT',
|
||||
civilIdFrontId: '',
|
||||
civilIdBackId: ''
|
||||
});
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
console.log('Form data:', formData);
|
||||
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
if (!formData.civilIdFrontId || !formData.civilIdBackId) {
|
||||
console.log('Missing documents - Front:', formData.civilIdFrontId, 'Back:', formData.civilIdBackId);
|
||||
throw new Error('Please upload both front and back civil ID documents');
|
||||
}
|
||||
|
||||
console.log('Submitting data:', formData);
|
||||
const dataToSubmit = {
|
||||
...formData,
|
||||
civilIdFrontId: formData.civilIdFrontId.trim(),
|
||||
civilIdBackId: formData.civilIdBackId.trim()
|
||||
};
|
||||
await juniorsApi.createJunior(dataToSubmit);
|
||||
navigate('/juniors');
|
||||
} catch (err) {
|
||||
console.error('Create junior error:', err);
|
||||
if (err instanceof AxiosError && err.response?.data) {
|
||||
const apiError = err.response.data as ApiError;
|
||||
const messages = Array.isArray(apiError.message)
|
||||
? apiError.message.map(m => `${m.field}: ${m.message}`).join('\n')
|
||||
: apiError.message;
|
||||
setError(messages);
|
||||
} else {
|
||||
setError(err instanceof Error ? err.message : 'Failed to create junior');
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: value
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSelectChange = (e: SelectChangeEvent) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name as string]: value
|
||||
}));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log('Form data updated:', formData);
|
||||
}, [formData]);
|
||||
|
||||
const handleCivilIdFrontUpload = (documentId: string) => {
|
||||
console.log('Front ID uploaded:', documentId);
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
civilIdFrontId: documentId
|
||||
}));
|
||||
};
|
||||
|
||||
const handleCivilIdBackUpload = (documentId: string) => {
|
||||
console.log('Back ID uploaded:', documentId);
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
civilIdBackId: documentId
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
Add New Junior
|
||||
</Typography>
|
||||
|
||||
<Paper sx={{ p: 3, maxWidth: 600, mx: 'auto' }}>
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3, whiteSpace: 'pre-line' }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Box component="form" onSubmit={handleSubmit}>
|
||||
<Grid container spacing={3}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>Country Code</InputLabel>
|
||||
<Select
|
||||
name="countryCode"
|
||||
value={formData.countryCode}
|
||||
label="Country Code"
|
||||
onChange={handleSelectChange}
|
||||
>
|
||||
<MenuItem value="+962">Jordan (+962)</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Phone Number"
|
||||
name="phoneNumber"
|
||||
value={formData.phoneNumber}
|
||||
onChange={handleInputChange}
|
||||
placeholder="7XXXXXXXX"
|
||||
required
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="First Name"
|
||||
name="firstName"
|
||||
value={formData.firstName}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Last Name"
|
||||
name="lastName"
|
||||
value={formData.lastName}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Email"
|
||||
name="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Date of Birth"
|
||||
name="dateOfBirth"
|
||||
type="date"
|
||||
value={formData.dateOfBirth}
|
||||
onChange={handleInputChange}
|
||||
required
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>Relationship</InputLabel>
|
||||
<Select
|
||||
name="relationship"
|
||||
value={formData.relationship}
|
||||
label="Relationship"
|
||||
onChange={handleSelectChange}
|
||||
>
|
||||
<MenuItem value="PARENT">Parent</MenuItem>
|
||||
<MenuItem value="GUARDIAN">Guardian</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<Divider sx={{ my: 2 }}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
Civil ID Documents
|
||||
</Typography>
|
||||
</Divider>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12} sm={6}>
|
||||
<DocumentUpload
|
||||
documentType={DocumentType.PASSPORT}
|
||||
label="Upload Civil ID Front"
|
||||
onUploadSuccess={handleCivilIdFrontUpload}
|
||||
/>
|
||||
{formData.civilIdFrontId && (
|
||||
<Typography variant="caption" color="success.main" sx={{ mt: 1, display: 'block' }}>
|
||||
Civil ID Front uploaded (ID: {formData.civilIdFrontId})
|
||||
</Typography>
|
||||
)}
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<DocumentUpload
|
||||
documentType={DocumentType.PASSPORT}
|
||||
label="Upload Civil ID Back"
|
||||
onUploadSuccess={handleCivilIdBackUpload}
|
||||
/>
|
||||
{formData.civilIdBackId && (
|
||||
<Typography variant="caption" color="success.main" sx={{ mt: 1, display: 'block' }}>
|
||||
Civil ID Back uploaded (ID: {formData.civilIdBackId})
|
||||
</Typography>
|
||||
)}
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Box sx={{ mt: 3, display: 'flex', gap: 2, justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => navigate('/juniors')}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Adding...' : 'Add Junior'}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
};
|
121
client/src/components/juniors/JuniorsList.tsx
Normal file
121
client/src/components/juniors/JuniorsList.tsx
Normal file
@ -0,0 +1,121 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Grid,
|
||||
Card,
|
||||
CardContent,
|
||||
CardMedia,
|
||||
Button,
|
||||
CircularProgress,
|
||||
Pagination
|
||||
} from '@mui/material';
|
||||
import { juniorsApi } from '../../api/client';
|
||||
import { Junior, PaginatedResponse } from '../../types/junior';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
export const JuniorsList = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [juniors, setJuniors] = useState<Junior[]>([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const fetchJuniors = async (pageNum: number) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await juniorsApi.getJuniors(pageNum);
|
||||
const data = response.data as PaginatedResponse<Junior>;
|
||||
setJuniors(data.data);
|
||||
setTotalPages(data.meta.pageCount);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load juniors');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchJuniors(page);
|
||||
}, [page]);
|
||||
|
||||
const handlePageChange = (event: React.ChangeEvent<unknown>, value: number) => {
|
||||
setPage(value);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" minHeight="200px">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Typography color="error">{error}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mb={3}>
|
||||
<Typography variant="h4">Juniors</Typography>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => navigate('/juniors/new')}
|
||||
>
|
||||
Add Junior
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<Grid container spacing={3}>
|
||||
{juniors.map((junior) => (
|
||||
<Grid item xs={12} sm={6} md={4} key={junior.id}>
|
||||
<Card>
|
||||
<CardMedia
|
||||
component="img"
|
||||
height="140"
|
||||
image={junior.profilePicture?.url || '/default-avatar.png'}
|
||||
alt={junior.fullName}
|
||||
sx={{ objectFit: 'contain', bgcolor: 'grey.100' }}
|
||||
/>
|
||||
<CardContent>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
{junior.fullName}
|
||||
</Typography>
|
||||
<Typography color="textSecondary">
|
||||
{junior.relationship}
|
||||
</Typography>
|
||||
<Box mt={2}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
onClick={() => navigate(`/juniors/${junior.id}`)}
|
||||
>
|
||||
View Details
|
||||
</Button>
|
||||
</Box>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<Box display="flex" justifyContent="center" mt={4}>
|
||||
<Pagination
|
||||
count={totalPages}
|
||||
page={page}
|
||||
onChange={handlePageChange}
|
||||
color="primary"
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
175
client/src/components/layout/AuthLayout.tsx
Normal file
175
client/src/components/layout/AuthLayout.tsx
Normal file
@ -0,0 +1,175 @@
|
||||
import React from 'react';
|
||||
import { Navigate, Outlet, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
AppBar,
|
||||
Toolbar,
|
||||
Typography,
|
||||
Button,
|
||||
Box,
|
||||
Container,
|
||||
List,
|
||||
ListItem,
|
||||
Drawer,
|
||||
Divider
|
||||
} from '@mui/material';
|
||||
import {
|
||||
Dashboard as DashboardIcon,
|
||||
People as PeopleIcon,
|
||||
Assignment as TasksIcon,
|
||||
Person as ProfileIcon
|
||||
} from '@mui/icons-material';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
|
||||
export const AuthLayout = () => {
|
||||
const { isAuthenticated, user, logout } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', minHeight: '100vh' }}>
|
||||
<AppBar
|
||||
position="fixed"
|
||||
sx={{
|
||||
zIndex: (theme) => theme.zIndex.drawer + 1,
|
||||
backgroundColor: 'background.paper',
|
||||
boxShadow: 'none',
|
||||
borderBottom: '1px solid',
|
||||
borderColor: 'divider'
|
||||
}}
|
||||
>
|
||||
<Toolbar>
|
||||
<Typography variant="h5" component="div" sx={{ flexGrow: 1, color: 'text.primary', fontWeight: 600 }}>
|
||||
Zod Alkhair | API Testting client
|
||||
</Typography>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||
{user && (
|
||||
<Typography variant="body1" sx={{ color: 'text.primary' }}>
|
||||
{user.firstName} {user.lastName}
|
||||
</Typography>
|
||||
)}
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={logout}
|
||||
size="small"
|
||||
>
|
||||
Logout
|
||||
</Button>
|
||||
</Box>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
|
||||
<Drawer
|
||||
variant="permanent"
|
||||
sx={{
|
||||
width: 280,
|
||||
flexShrink: 0,
|
||||
'& .MuiDrawer-paper': {
|
||||
width: 280,
|
||||
boxSizing: 'border-box',
|
||||
marginTop: '64px',
|
||||
backgroundColor: 'background.paper',
|
||||
borderRight: '1px solid',
|
||||
borderColor: 'divider',
|
||||
padding: 2
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Box sx={{ overflow: 'auto' }}>
|
||||
<List>
|
||||
<ListItem component="div">
|
||||
<Button
|
||||
fullWidth
|
||||
sx={{
|
||||
justifyContent: 'flex-start',
|
||||
pl: 2,
|
||||
py: 1.5,
|
||||
borderRadius: 2,
|
||||
color: 'text.primary',
|
||||
'&:hover': {
|
||||
backgroundColor: 'primary.light',
|
||||
color: 'primary.contrastText'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/dashboard')}
|
||||
startIcon={<DashboardIcon />}
|
||||
>
|
||||
Dashboard
|
||||
</Button>
|
||||
</ListItem>
|
||||
<ListItem component="div">
|
||||
<Button
|
||||
fullWidth
|
||||
sx={{
|
||||
justifyContent: 'flex-start',
|
||||
pl: 2,
|
||||
py: 1.5,
|
||||
borderRadius: 2,
|
||||
color: 'text.primary',
|
||||
'&:hover': {
|
||||
backgroundColor: 'primary.light',
|
||||
color: 'primary.contrastText'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/juniors')}
|
||||
startIcon={<PeopleIcon />}
|
||||
>
|
||||
Juniors
|
||||
</Button>
|
||||
</ListItem>
|
||||
<ListItem component="div">
|
||||
<Button
|
||||
fullWidth
|
||||
sx={{
|
||||
justifyContent: 'flex-start',
|
||||
pl: 2,
|
||||
py: 1.5,
|
||||
borderRadius: 2,
|
||||
color: 'text.primary',
|
||||
'&:hover': {
|
||||
backgroundColor: 'primary.light',
|
||||
color: 'primary.contrastText'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/tasks')}
|
||||
startIcon={<TasksIcon />}
|
||||
>
|
||||
Tasks
|
||||
</Button>
|
||||
</ListItem>
|
||||
</List>
|
||||
<Divider />
|
||||
<List>
|
||||
<ListItem component="div">
|
||||
<Button
|
||||
fullWidth
|
||||
sx={{
|
||||
justifyContent: 'flex-start',
|
||||
pl: 2,
|
||||
py: 1.5,
|
||||
borderRadius: 2,
|
||||
color: 'text.primary',
|
||||
'&:hover': {
|
||||
backgroundColor: 'primary.light',
|
||||
color: 'primary.contrastText'
|
||||
}
|
||||
}}
|
||||
onClick={() => navigate('/profile')}
|
||||
startIcon={<ProfileIcon />}
|
||||
>
|
||||
Profile
|
||||
</Button>
|
||||
</ListItem>
|
||||
</List>
|
||||
</Box>
|
||||
</Drawer>
|
||||
|
||||
<Container component="main" sx={{ flexGrow: 1, p: 4, marginLeft: '280px', marginTop: '64px' }}>
|
||||
<Outlet />
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
};
|
200
client/src/components/tasks/TasksList.tsx
Normal file
200
client/src/components/tasks/TasksList.tsx
Normal file
@ -0,0 +1,200 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
Grid,
|
||||
Card,
|
||||
CardContent,
|
||||
Button,
|
||||
CircularProgress,
|
||||
Pagination,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
Select,
|
||||
MenuItem,
|
||||
Chip,
|
||||
SelectChangeEvent
|
||||
} from '@mui/material';
|
||||
import { tasksApi, juniorsApi } from '../../api/client';
|
||||
import { Task, TaskStatus } from '../../types/task';
|
||||
import { Junior, PaginatedResponse } from '../../types/junior';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const statusColors = {
|
||||
PENDING: 'warning',
|
||||
IN_PROGRESS: 'info',
|
||||
COMPLETED: 'success'
|
||||
} as const;
|
||||
|
||||
export const TasksList = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [tasks, setTasks] = useState<Task[]>([]);
|
||||
const [juniors, setJuniors] = useState<Junior[]>([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const [status, setStatus] = useState<TaskStatus>('PENDING');
|
||||
const [selectedJuniorId, setSelectedJuniorId] = useState<string>('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const fetchJuniors = async () => {
|
||||
try {
|
||||
const response = await juniorsApi.getJuniors(1, 100);
|
||||
const data = response.data as PaginatedResponse<Junior>;
|
||||
setJuniors(data.data);
|
||||
} catch (err) {
|
||||
console.error('Failed to load juniors:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchTasks = async (pageNum: number) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await tasksApi.getTasks(status, pageNum, 10, selectedJuniorId || undefined);
|
||||
const data = response.data as PaginatedResponse<Task>;
|
||||
setTasks(data.data);
|
||||
setTotalPages(data.meta.pageCount);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load tasks');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchJuniors();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchTasks(page);
|
||||
}, [page, status, selectedJuniorId]);
|
||||
|
||||
const handlePageChange = (event: React.ChangeEvent<unknown>, value: number) => {
|
||||
setPage(value);
|
||||
};
|
||||
|
||||
const handleStatusChange = (event: SelectChangeEvent) => {
|
||||
setStatus(event.target.value as TaskStatus);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const handleJuniorChange = (event: SelectChangeEvent) => {
|
||||
setSelectedJuniorId(event.target.value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
if (loading && page === 1) {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" minHeight="200px">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Typography color="error">{error}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mb={3}>
|
||||
<Typography variant="h4">Tasks</Typography>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => navigate('/tasks/new')}
|
||||
>
|
||||
Create Task
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" gap={2} mb={3}>
|
||||
<FormControl sx={{ minWidth: 200 }}>
|
||||
<InputLabel>Status</InputLabel>
|
||||
<Select
|
||||
value={status}
|
||||
label="Status"
|
||||
onChange={handleStatusChange}
|
||||
>
|
||||
<MenuItem value="PENDING">Pending</MenuItem>
|
||||
<MenuItem value="IN_PROGRESS">In Progress</MenuItem>
|
||||
<MenuItem value="COMPLETED">Completed</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
|
||||
<FormControl sx={{ minWidth: 200 }}>
|
||||
<InputLabel>Junior</InputLabel>
|
||||
<Select
|
||||
value={selectedJuniorId}
|
||||
label="Junior"
|
||||
onChange={handleJuniorChange}
|
||||
>
|
||||
<MenuItem value="">All Juniors</MenuItem>
|
||||
{juniors.map(junior => (
|
||||
<MenuItem key={junior.id} value={junior.id}>
|
||||
{junior.fullName}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Box>
|
||||
|
||||
<Grid container spacing={3}>
|
||||
{tasks.map((task) => (
|
||||
<Grid item xs={12} sm={6} md={4} key={task.id}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="flex-start">
|
||||
<Typography variant="h6" gutterBottom>
|
||||
{task.title}
|
||||
</Typography>
|
||||
<Chip
|
||||
label={task.status}
|
||||
color={statusColors[task.status]}
|
||||
size="small"
|
||||
/>
|
||||
</Box>
|
||||
<Typography color="textSecondary" gutterBottom>
|
||||
Due: {new Date(task.dueDate).toLocaleDateString()}
|
||||
</Typography>
|
||||
<Typography variant="body2" gutterBottom>
|
||||
{task.description}
|
||||
</Typography>
|
||||
<Typography color="primary" gutterBottom>
|
||||
Reward: ${task.rewardAmount}
|
||||
</Typography>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
Assigned to: {task.junior.fullName}
|
||||
</Typography>
|
||||
<Box mt={2}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
onClick={() => navigate(`/tasks/${task.id}`)}
|
||||
>
|
||||
View Details
|
||||
</Button>
|
||||
</Box>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<Box display="flex" justifyContent="center" mt={4}>
|
||||
<Pagination
|
||||
count={totalPages}
|
||||
page={page}
|
||||
onChange={handlePageChange}
|
||||
color="primary"
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
119
client/src/contexts/AuthContext.tsx
Normal file
119
client/src/contexts/AuthContext.tsx
Normal file
@ -0,0 +1,119 @@
|
||||
import React, { createContext, useContext, useState, useCallback } from 'react';
|
||||
import { authApi } from '../api/client';
|
||||
import { User, LoginResponse } from '../types/auth';
|
||||
|
||||
interface AuthContextType {
|
||||
isAuthenticated: boolean;
|
||||
user: User | null;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
register: (countryCode: string, phoneNumber: string) => Promise<void>;
|
||||
verifyOtp: (countryCode: string, phoneNumber: string, otp: string) => Promise<string>;
|
||||
setEmail: (email: string) => Promise<void>;
|
||||
setPasscode: (passcode: string) => Promise<void>;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextType | null>(null);
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within an AuthProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
|
||||
const login = useCallback(async (email: string, password: string) => {
|
||||
try {
|
||||
const response = await authApi.login(email, password);
|
||||
const loginData = response.data.data as LoginResponse;
|
||||
setUser(loginData.user);
|
||||
// Store tokens
|
||||
localStorage.setItem('accessToken', loginData.accessToken);
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken);
|
||||
setIsAuthenticated(true);
|
||||
// Store tokens or other auth data in localStorage if needed
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
setUser(null);
|
||||
setIsAuthenticated(false);
|
||||
// Clear any stored auth data
|
||||
localStorage.clear();
|
||||
}, []);
|
||||
|
||||
// Registration state
|
||||
const [registrationData, setRegistrationData] = useState<{
|
||||
countryCode?: string;
|
||||
phoneNumber?: string;
|
||||
email?: string;
|
||||
token?: string;
|
||||
}>({});
|
||||
|
||||
const register = useCallback(async (countryCode: string, phoneNumber: string) => {
|
||||
try {
|
||||
await authApi.register(countryCode, phoneNumber);
|
||||
setRegistrationData({ countryCode, phoneNumber });
|
||||
} catch (error) {
|
||||
console.error('Registration failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const verifyOtp = useCallback(async (countryCode: string, phoneNumber: string, otp: string) => {
|
||||
try {
|
||||
const response = await authApi.verifyOtp(countryCode, phoneNumber, otp);
|
||||
console.log('OTP verification response:', response.data);
|
||||
const { accessToken } = response.data.data;
|
||||
console.log('Access token:', accessToken);
|
||||
// Store token in localStorage immediately
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
setRegistrationData(prev => ({ ...prev, token: accessToken }));
|
||||
return accessToken;
|
||||
} catch (error) {
|
||||
console.error('OTP verification failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const setEmail = useCallback(async (email: string) => {
|
||||
try {
|
||||
await authApi.setEmail(email);
|
||||
setRegistrationData(prev => ({ ...prev, email }));
|
||||
} catch (error) {
|
||||
console.error('Setting email failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const setPasscode = useCallback(async (passcode: string) => {
|
||||
try {
|
||||
await authApi.setPasscode(passcode);
|
||||
setIsAuthenticated(true);
|
||||
} catch (error) {
|
||||
console.error('Setting passcode failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const value = {
|
||||
isAuthenticated,
|
||||
user,
|
||||
login,
|
||||
logout,
|
||||
register,
|
||||
verifyOtp,
|
||||
setEmail,
|
||||
setPasscode
|
||||
};
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
};
|
52
client/src/index.css
Normal file
52
client/src/index.css
Normal file
@ -0,0 +1,52 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background-color: #F8F9FA;
|
||||
color: #2D3748;
|
||||
}
|
||||
|
||||
/* Custom scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: #F8F9FA;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #CBD5E0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #A0AEC0;
|
||||
}
|
||||
|
||||
/* Smooth transitions */
|
||||
a, button {
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
/* Remove focus outline for mouse users, keep for keyboard users */
|
||||
:focus:not(:focus-visible) {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Keep focus outline for keyboard users */
|
||||
:focus-visible {
|
||||
outline: 2px solid #00A7E1;
|
||||
outline-offset: 2px;
|
||||
}
|
13
client/src/main.tsx
Normal file
13
client/src/main.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
14
client/src/types/api.ts
Normal file
14
client/src/types/api.ts
Normal file
@ -0,0 +1,14 @@
|
||||
interface ApiErrorField {
|
||||
field: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
statusCode: number;
|
||||
message: string | ApiErrorField[];
|
||||
error: string;
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
data: T;
|
||||
}
|
17
client/src/types/auth.ts
Normal file
17
client/src/types/auth.ts
Normal file
@ -0,0 +1,17 @@
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
customerStatus?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
dateOfBirth?: string;
|
||||
countryOfResidence?: string;
|
||||
isJunior?: boolean;
|
||||
isGuardian?: boolean;
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
user: User;
|
||||
}
|
9
client/src/types/document.ts
Normal file
9
client/src/types/document.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export enum DocumentType {
|
||||
PROFILE_PICTURE = 'PROFILE_PICTURE',
|
||||
PASSPORT = 'PASSPORT',
|
||||
DEFAULT_AVATAR = 'DEFAULT_AVATAR',
|
||||
DEFAULT_TASKS_LOGO = 'DEFAULT_TASKS_LOGO',
|
||||
CUSTOM_AVATAR = 'CUSTOM_AVATAR',
|
||||
CUSTOM_TASKS_LOGO = 'CUSTOM_TASKS_LOGO',
|
||||
GOALS = 'GOALS'
|
||||
}
|
41
client/src/types/junior.ts
Normal file
41
client/src/types/junior.ts
Normal file
@ -0,0 +1,41 @@
|
||||
export interface Junior {
|
||||
id: string;
|
||||
fullName: string;
|
||||
relationship: string;
|
||||
profilePicture?: {
|
||||
id: string;
|
||||
name: string;
|
||||
extension: string;
|
||||
documentType: string;
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface CreateJuniorRequest {
|
||||
countryCode: string;
|
||||
phoneNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
dateOfBirth: string;
|
||||
email: string;
|
||||
relationship: string;
|
||||
civilIdFrontId: string;
|
||||
civilIdBackId: string;
|
||||
}
|
||||
|
||||
export interface JuniorTheme {
|
||||
color: string;
|
||||
avatarId: string;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
meta: {
|
||||
page: number;
|
||||
size: number;
|
||||
itemCount: number;
|
||||
pageCount: number;
|
||||
hasPreviousPage: boolean;
|
||||
hasNextPage: boolean;
|
||||
};
|
||||
}
|
42
client/src/types/task.ts
Normal file
42
client/src/types/task.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { Junior } from './junior';
|
||||
|
||||
export interface Task {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
status: 'PENDING' | 'IN_PROGRESS' | 'COMPLETED';
|
||||
dueDate: string;
|
||||
rewardAmount: number;
|
||||
isProofRequired: boolean;
|
||||
submission?: {
|
||||
imageId?: string;
|
||||
submittedAt?: string;
|
||||
status?: 'PENDING' | 'APPROVED' | 'REJECTED';
|
||||
};
|
||||
junior: Junior;
|
||||
image?: {
|
||||
id: string;
|
||||
name: string;
|
||||
extension: string;
|
||||
documentType: string;
|
||||
url: string;
|
||||
};
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface CreateTaskRequest {
|
||||
title: string;
|
||||
description: string;
|
||||
dueDate: string;
|
||||
rewardAmount: number;
|
||||
isProofRequired: boolean;
|
||||
imageId?: string;
|
||||
juniorId: string;
|
||||
}
|
||||
|
||||
export interface TaskSubmission {
|
||||
imageId: string;
|
||||
}
|
||||
|
||||
export type TaskStatus = 'PENDING' | 'IN_PROGRESS' | 'COMPLETED';
|
1
client/src/vite-env.d.ts
vendored
Normal file
1
client/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
Reference in New Issue
Block a user