|
| 1 | +import { ExternalLink, History, Clock, CheckCircle2, AlertCircle, XCircle } from "lucide-react"; |
| 2 | +import { useState } from "react"; |
| 3 | +interface Submission { |
| 4 | + id: number; |
| 5 | + phoneNumber: string; |
| 6 | + productLink: string; |
| 7 | + codeLink: string; |
| 8 | + submittedAt: string; |
| 9 | + status: "pending" | "approved" | "rejected"; |
| 10 | +} |
| 11 | + |
| 12 | +const HistorySubmit = () => { |
| 13 | + const [submissions] = useState<Submission[]>([ |
| 14 | + { |
| 15 | + id: 1, |
| 16 | + phoneNumber: "0123456789", |
| 17 | + productLink: "https://demo.example.com", |
| 18 | + codeLink: "https://github.com/user/project", |
| 19 | + submittedAt: "2025-12-19 14:30:00", |
| 20 | + status: "approved", |
| 21 | + }, |
| 22 | + { |
| 23 | + id: 2, |
| 24 | + phoneNumber: "0123456789", |
| 25 | + productLink: "https://demo-v2.example.com", |
| 26 | + codeLink: "https://github.com/user/project-v2", |
| 27 | + |
| 28 | + submittedAt: "2025-12-19 16:45:00", |
| 29 | + status: "pending", |
| 30 | + }, |
| 31 | + ]); |
| 32 | + |
| 33 | + const getStatusBadge = (status: Submission["status"]) => { |
| 34 | + switch (status) { |
| 35 | + case "approved": |
| 36 | + return ( |
| 37 | + <span className="inline-flex items-center gap-1.5 rounded-md border border-green-200/50 bg-green-50 px-2.5 py-1 text-xs font-medium text-green-700"> |
| 38 | + <CheckCircle2 className="h-3.5 w-3.5" /> |
| 39 | + Đã ghi nhận |
| 40 | + </span> |
| 41 | + ); |
| 42 | + case "rejected": |
| 43 | + return ( |
| 44 | + <span className="inline-flex items-center gap-1.5 rounded-md border border-red-200/50 bg-red-50 px-2.5 py-1 text-xs font-medium text-red-700"> |
| 45 | + <XCircle className="h-3.5 w-3.5" /> |
| 46 | + Không hợp lệ |
| 47 | + </span> |
| 48 | + ); |
| 49 | + case "pending": |
| 50 | + default: |
| 51 | + return ( |
| 52 | + <span className="inline-flex items-center gap-1.5 rounded-md border border-yellow-200/50 bg-yellow-50 px-2.5 py-1 text-xs font-medium text-yellow-700"> |
| 53 | + <AlertCircle className="h-3.5 w-3.5" /> |
| 54 | + Chờ xác nhận |
| 55 | + </span> |
| 56 | + ); |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + return ( |
| 61 | + <div className="overflow-hidden rounded-md border border-gray-200/70 bg-white"> |
| 62 | + <div className="border-b border-gray-200/70 bg-gradient-to-r from-gray-50/80 to-white px-5 py-4 sm:px-6"> |
| 63 | + <h2 className="text-base font-semibold tracking-tight text-gray-900 sm:text-lg">Lịch sử nộp bài</h2> |
| 64 | + <p className="mt-1.5 text-xs leading-relaxed text-gray-500 sm:text-sm"> |
| 65 | + Danh sách các lần nộp bài của nhóm. |
| 66 | + </p> |
| 67 | + </div> |
| 68 | + |
| 69 | + <div className="overflow-x-auto"> |
| 70 | + {submissions.length === 0 ? ( |
| 71 | + <div className="py-16 text-center"> |
| 72 | + <div className="mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-gray-100"> |
| 73 | + <History className="h-8 w-8 text-gray-400" /> |
| 74 | + </div> |
| 75 | + <p className="mt-4 text-sm font-medium text-gray-900">Chưa có lịch sử nộp bài</p> |
| 76 | + <p className="mt-1 text-xs text-gray-500">Hãy nộp bài dự thi của bạn ở form phía trên</p> |
| 77 | + </div> |
| 78 | + ) : ( |
| 79 | + <table className="w-full"> |
| 80 | + <thead className="bg-gray-50/50"> |
| 81 | + <tr> |
| 82 | + <th className="px-4 py-3 text-left text-xs font-semibold tracking-wide text-gray-600 uppercase sm:px-6 sm:py-3.5"> |
| 83 | + Lần nộp |
| 84 | + </th> |
| 85 | + <th className="px-4 py-3 text-left text-xs font-semibold tracking-wide text-gray-600 uppercase sm:px-6 sm:py-3.5"> |
| 86 | + Thời gian |
| 87 | + </th> |
| 88 | + <th className="px-4 py-3 text-left text-xs font-semibold tracking-wide text-gray-600 uppercase sm:px-6 sm:py-3.5"> |
| 89 | + Link sản phẩm |
| 90 | + </th> |
| 91 | + |
| 92 | + <th className="px-4 py-3 text-left text-xs font-semibold tracking-wide text-gray-600 uppercase sm:px-6 sm:py-3.5"> |
| 93 | + Trạng thái |
| 94 | + </th> |
| 95 | + </tr> |
| 96 | + </thead> |
| 97 | + <tbody className="divide-y divide-gray-200/60 bg-white"> |
| 98 | + {submissions |
| 99 | + .slice() |
| 100 | + .reverse() |
| 101 | + .map((submission, index) => { |
| 102 | + const isLatest = index === 0; |
| 103 | + return ( |
| 104 | + <tr key={submission.id} className="transition-colors hover:bg-gray-50/50"> |
| 105 | + <td className="px-4 py-3.5 text-sm font-medium whitespace-nowrap text-gray-900 sm:px-6 sm:py-4"> |
| 106 | + <div className="flex items-center gap-2"> |
| 107 | + <span>#{submissions.length - index}</span> |
| 108 | + {isLatest && ( |
| 109 | + <span className="bg-primary/10 text-primary rounded-md px-2 py-0.5 text-xs font-medium"> |
| 110 | + Mới nhất |
| 111 | + </span> |
| 112 | + )} |
| 113 | + </div> |
| 114 | + </td> |
| 115 | + <td className="px-4 py-3.5 text-sm whitespace-nowrap text-gray-600 sm:px-6 sm:py-4"> |
| 116 | + <div className="flex items-center gap-1.5"> |
| 117 | + <Clock className="h-3.5 w-3.5 text-gray-400" /> |
| 118 | + <span> |
| 119 | + {new Date(submission.submittedAt).toLocaleString("vi-VN")} |
| 120 | + </span> |
| 121 | + </div> |
| 122 | + </td> |
| 123 | + <td className="px-4 py-3.5 text-sm sm:px-6 sm:py-4"> |
| 124 | + <div className="flex flex-col gap-2"> |
| 125 | + <a |
| 126 | + href={submission.productLink} |
| 127 | + target="_blank" |
| 128 | + rel="noopener noreferrer" |
| 129 | + className="text-primary hover:text-primary/80 flex items-center gap-1.5 font-medium transition-colors" |
| 130 | + > |
| 131 | + <ExternalLink className="h-3.5 w-3.5" /> |
| 132 | + <span>Xem sản phẩm</span> |
| 133 | + </a> |
| 134 | + {submission.codeLink && ( |
| 135 | + <a |
| 136 | + href={submission.codeLink} |
| 137 | + target="_blank" |
| 138 | + rel="noopener noreferrer" |
| 139 | + className="flex items-center gap-1.5 text-gray-600 transition-colors hover:text-gray-900" |
| 140 | + > |
| 141 | + <ExternalLink className="h-3.5 w-3.5" /> |
| 142 | + <span>Mã nguồn</span> |
| 143 | + </a> |
| 144 | + )} |
| 145 | + </div> |
| 146 | + </td> |
| 147 | + |
| 148 | + <td className="px-4 py-3.5 text-sm whitespace-nowrap sm:px-6 sm:py-4"> |
| 149 | + {getStatusBadge(submission.status)} |
| 150 | + </td> |
| 151 | + </tr> |
| 152 | + ); |
| 153 | + })} |
| 154 | + </tbody> |
| 155 | + </table> |
| 156 | + )} |
| 157 | + </div> |
| 158 | + </div> |
| 159 | + ); |
| 160 | +}; |
| 161 | + |
| 162 | +export default HistorySubmit; |
0 commit comments