|
1 | 1 | import { useState, useEffect } from 'react'; |
2 | | -import { Link } from 'react-router-dom'; |
3 | | -import { User, Mail, Shield, Award, TrendingUp, Loader2, AlertTriangle, CheckCircle2, XCircle, Clock, Zap, Lock, Key, CalendarDays, Code, PieChart } from 'lucide-react'; |
| 2 | +import { Link, useNavigate } from 'react-router-dom'; |
| 3 | +import { User, Mail, Shield, Award, TrendingUp, Loader2, AlertTriangle, CheckCircle2, XCircle, Clock, Zap, Lock, Key, CalendarDays, Code, PieChart, Trash2 } from 'lucide-react'; |
4 | 4 | import { useAuth } from '../context/AuthContext'; |
5 | 5 | import api from '../services/api'; |
| 6 | +import toast from 'react-hot-toast'; |
6 | 7 | import type { Submission } from '../types'; |
7 | 8 | import { useDocumentTitle } from '../hooks/useDocumentTitle'; |
8 | 9 | import GamificationSection from '../components/GamificationSection'; |
@@ -38,7 +39,8 @@ const STATUS_MAP: Record<string, { label: string; icon: React.ReactNode; classNa |
38 | 39 |
|
39 | 40 | export default function Profile() { |
40 | 41 | useDocumentTitle('个人中心'); |
41 | | - const { user } = useAuth(); |
| 42 | + const { user, logout } = useAuth(); |
| 43 | + const navigate = useNavigate(); |
42 | 44 | const [profile, setProfile] = useState<any>(null); |
43 | 45 | const [submissions, setSubmissions] = useState<Submission[]>([]); |
44 | 46 | const [loading, setLoading] = useState(true); |
@@ -424,6 +426,29 @@ export default function Profile() { |
424 | 426 | )} |
425 | 427 | </div> |
426 | 428 |
|
| 429 | + {/* Delete Account */} |
| 430 | + <div className="card p-6 border-red-600/20"> |
| 431 | + <button |
| 432 | + onClick={async () => { |
| 433 | + if (window.confirm('确定要删除账户吗?所有提交记录也将被永久删除。此操作不可撤销。')) { |
| 434 | + try { |
| 435 | + await api.auth.deleteAccount(); |
| 436 | + toast.success('账户已删除'); |
| 437 | + logout(); |
| 438 | + navigate('/'); |
| 439 | + } catch (err: any) { |
| 440 | + toast.error(err.message || '删除失败'); |
| 441 | + } |
| 442 | + } |
| 443 | + }} |
| 444 | + className="flex items-center gap-2 text-sm font-medium text-red-400 hover:text-red-300 transition-colors" |
| 445 | + > |
| 446 | + <Trash2 className="w-4 h-4" /> |
| 447 | + 删除账户 |
| 448 | + </button> |
| 449 | + <p className="text-xs text-dark-500 mt-2">删除后不可恢复,所有数据将被清除</p> |
| 450 | + </div> |
| 451 | + |
427 | 452 | {/* Recent submissions */} |
428 | 453 | <div className="card p-6"> |
429 | 454 | <h2 className="text-lg font-semibold text-white mb-4">最近提交</h2> |
|
0 commit comments