1import { useState, useEffect } from 'react';
2import { useSearchParams, Link } from 'react-router-dom';
3import PublicLayout from '../components/Layout/PublicLayout';
4import { apiFetch } from '../lib/api';
6export default function ResetPassword() {
7 const [params] = useSearchParams();
8 const token = params.get('token') || '';
9 const [password, setPassword] = useState('');
10 const [confirm, setConfirm] = useState('');
11 const [ok, setOk] = useState(false);
12 const [loading, setLoading] = useState(false);
13 const [error, setError] = useState('');
15 async function handleSubmit(e) {
17 if (password !== confirm) { setError('Passwords do not match'); return; }
21 const res = await fetch('/users/reset-password', {
23 headers: { 'Content-Type': 'application/json' },
24 body: JSON.stringify({ token, password })
26 const ct = res.headers.get('content-type') || '';
27 const data = ct.includes('json') ? await res.json() : { };
28 if (!res.ok) throw new Error(data.error || 'Reset failed');
31 setError(err.message || 'Error');
39 <div style={{ maxWidth: 480, margin: '3rem auto', padding: '2rem', background: '#fff', borderRadius: 12, boxShadow: '0 8px 24px rgba(0,0,0,0.08)' }}>
40 <h1>Reset Password</h1>
43 <p>Your password has been reset. You can now <Link to="/login">log in</Link>.</p>
46 <form onSubmit={handleSubmit}>
47 <div style={{ marginBottom: 12 }}>
48 <label>New Password</label>
49 <input type="password" value={password} onChange={(e)=>setPassword(e.target.value)} required style={{ width: '100%', padding: 10, marginTop: 6 }} />
51 <div style={{ marginBottom: 12 }}>
52 <label>Confirm Password</label>
53 <input type="password" value={confirm} onChange={(e)=>setConfirm(e.target.value)} required style={{ width: '100%', padding: 10, marginTop: 6 }} />
55 {error && <div style={{ color: 'red', marginBottom: 8 }}>{error}</div>}
56 <button disabled={loading} style={{ padding: '10px 16px' }}>{loading ? 'Resetting…' : 'Reset Password'}</button>