Refactor: clients → companies schema v2

This commit is contained in:
Krao Hasanee
2026-03-26 23:42:06 -04:00
commit 719209fa25
61 changed files with 8192 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
import { useState } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
export default function Login() {
const { login } = useAuth();
const navigate = useNavigate();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const handleLogin = async (e) => {
e.preventDefault();
setLoading(true);
setError('');
const { error: err } = await login(email, password);
if (err) {
setError('Invalid email or password.');
setLoading(false);
return;
}
// onAuthStateChange in AuthContext sets currentUser + role → redirect handled below
};
// After login, AuthContext updates currentUser. Use onAuthStateChange to redirect.
// We rely on ProtectedRoute to handle post-login navigation.
// But we need to redirect on success — watch currentUser via auth state.
// Simplest: redirect after successful login based on profile role.
const handleSuccess = async (e) => {
e.preventDefault();
setLoading(true);
setError('');
const { error: err } = await login(email, password);
if (err) {
setError('Invalid email or password.');
setLoading(false);
return;
}
// Small delay to let onAuthStateChange set currentUser
setTimeout(() => {
// Will be redirected by ProtectedRoute if they go to /dashboard or /my-requests
navigate('/dashboard');
}, 300);
};
return (
<div className="auth-page">
<div className="auth-card">
<div className="auth-logo">
<img src="/fourge-logo.png" alt="Fourge Branding" style={{ width: 200, marginBottom: 8 }} />
<p>Client & Project Portal</p>
</div>
<form onSubmit={handleSuccess}>
<div className="form-group">
<label>Email Address</label>
<input
type="email"
placeholder="you@example.com"
value={email}
onChange={e => { setEmail(e.target.value); setError(''); }}
required
/>
</div>
<div className="form-group">
<label>Password</label>
<input
type="password"
placeholder="••••••••"
value={password}
onChange={e => { setPassword(e.target.value); setError(''); }}
required
/>
</div>
{error && <p style={{ color: '#ef4444', fontSize: 13, marginBottom: 12 }}>{error}</p>}
<button type="submit" className="btn btn-primary w-full btn-lg" disabled={loading}>
{loading ? 'Signing in...' : 'Sign In'}
</button>
</form>
<p style={{ textAlign: 'center', marginTop: 20, fontSize: 13, color: '#a8a8a8' }}>
New client?{' '}
<Link to="/signup" style={{ color: 'var(--accent)' }}>Create an account</Link>
</p>
</div>
</div>
);
}