forked from andika/membership-fe
106 lines
3.6 KiB
JavaScript
106 lines
3.6 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { useNavigate, useSearchParams, Link } from 'react-router-dom';
|
|
import axios from 'axios';
|
|
import { Button } from '../components/ui/button';
|
|
import { Card } from '../components/ui/card';
|
|
import { CheckCircle, XCircle, Loader2 } from 'lucide-react';
|
|
import Navbar from '../components/Navbar';
|
|
|
|
const API_URL = process.env.REACT_APP_BACKEND_URL;
|
|
|
|
const VerifyEmail = () => {
|
|
const navigate = useNavigate();
|
|
const [searchParams] = useSearchParams();
|
|
const [status, setStatus] = useState('loading');
|
|
const [message, setMessage] = useState('');
|
|
const token = searchParams.get('token');
|
|
|
|
useEffect(() => {
|
|
const verifyEmail = async () => {
|
|
if (!token) {
|
|
setStatus('error');
|
|
setMessage('Invalid verification link.');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await axios.get(`${API_URL}/api/auth/verify-email?token=${token}`);
|
|
setStatus('success');
|
|
setMessage(response.data.message);
|
|
} catch (error) {
|
|
setStatus('error');
|
|
setMessage(error.response?.data?.detail || 'Verification failed. Please try again.');
|
|
}
|
|
};
|
|
|
|
verifyEmail();
|
|
}, [token]);
|
|
|
|
return (
|
|
<div className="min-h-screen bg-[#FDFCF8]">
|
|
<Navbar />
|
|
|
|
<div className="max-w-2xl mx-auto px-6 py-20">
|
|
<Card className="p-12 bg-white rounded-2xl border border-[#EAE0D5] shadow-lg text-center">
|
|
{status === 'loading' && (
|
|
<>
|
|
<Loader2 className="h-20 w-20 text-[#E07A5F] mx-auto mb-6 animate-spin" />
|
|
<h1 className="text-3xl font-semibold fraunces text-[#3D405B] mb-4">
|
|
Verifying Your Email...
|
|
</h1>
|
|
<p className="text-lg text-[#6B708D]">
|
|
Please wait while we verify your email address.
|
|
</p>
|
|
</>
|
|
)}
|
|
|
|
{status === 'success' && (
|
|
<>
|
|
<CheckCircle className="h-20 w-20 text-[#81B29A] mx-auto mb-6" />
|
|
<h1 className="text-3xl font-semibold fraunces text-[#3D405B] mb-4">
|
|
Email Verified Successfully!
|
|
</h1>
|
|
<p className="text-lg text-[#6B708D] mb-8">
|
|
{message}
|
|
</p>
|
|
<p className="text-base text-[#6B708D] mb-8">
|
|
Next steps: Attend an event and meet a board member within 90 days. Once you've attended an event, our admin team will review your application.
|
|
</p>
|
|
<Link to="/login">
|
|
<Button
|
|
className="bg-[#E07A5F] text-white hover:bg-[#D0694E] rounded-full px-12 py-6 text-lg font-medium shadow-lg"
|
|
data-testid="login-redirect-button"
|
|
>
|
|
Go to Login
|
|
</Button>
|
|
</Link>
|
|
</>
|
|
)}
|
|
|
|
{status === 'error' && (
|
|
<>
|
|
<XCircle className="h-20 w-20 text-[#E07A5F] mx-auto mb-6" />
|
|
<h1 className="text-3xl font-semibold fraunces text-[#3D405B] mb-4">
|
|
Verification Failed
|
|
</h1>
|
|
<p className="text-lg text-[#6B708D] mb-8">
|
|
{message}
|
|
</p>
|
|
<Link to="/">
|
|
<Button
|
|
className="bg-[#E07A5F] text-white hover:bg-[#D0694E] rounded-full px-12 py-6 text-lg font-medium shadow-lg"
|
|
data-testid="home-redirect-button"
|
|
>
|
|
Go to Home
|
|
</Button>
|
|
</Link>
|
|
</>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default VerifyEmail;
|