Spaces:
Running
Running
Download frontend/src/components/GlobalModals.tsx from TwanAPI/UploadFile: direct link, hf CLI and curl.
- Browser
- Download file 37 kB
-
https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/components/GlobalModals.tsx
- Command line
-
hf download hf://spaces/TwanAPI/UploadFile/frontend/src/components/GlobalModals.tsx
-
curl -L -o GlobalModals.tsx https://huggingface.co/spaces/TwanAPI/UploadFile/resolve/main/frontend/src/components/GlobalModals.tsx
37 kB
| "use client"; | |
| import React, { useState, useEffect } from "react"; | |
| import { | |
| UploadCloud, | |
| X, | |
| Edit3, | |
| Shield, | |
| Download, | |
| CheckCircle2, | |
| AlertTriangle, | |
| Sparkles, | |
| Share2, | |
| Copy, | |
| Check, | |
| Lock, | |
| Unlock, | |
| Power, | |
| RefreshCw, | |
| ExternalLink, | |
| UserCheck, | |
| UserX, | |
| Clock, | |
| } from "lucide-react"; | |
| import { useCloud } from "@/context/CloudContext"; | |
| import { formatBytes, buildFrontendShareUrl } from "@/lib/api"; | |
| import { ToastMsg } from "@/types/cloud"; | |
| export function GlobalModals() { | |
| const { | |
| uploadModalOpen, | |
| setUploadModalOpen, | |
| uploadTargetFolder, | |
| setUploadTargetFolder, | |
| selectedFiles, | |
| setSelectedFiles, | |
| startBatchUpload, | |
| renameTarget, | |
| setRenameTarget, | |
| newPathInput, | |
| setNewPathInput, | |
| renaming, | |
| handleRenameSubmit, | |
| editingUser, | |
| setEditingUser, | |
| handleSaveUser, | |
| previewFile, | |
| setPreviewFile, | |
| getDownloadUrl, | |
| triggerDownload, | |
| sharesMap, | |
| shareTarget, | |
| setShareTarget, | |
| upsertFileShare, | |
| respondShareRequest, | |
| notify, | |
| toasts, | |
| } = useCloud(); | |
| const [draftRequireApproval, setDraftRequireApproval] = useState<boolean>(true); | |
| const [savingShare, setSavingShare] = useState<boolean>(false); | |
| const [copiedShareLink, setCopiedShareLink] = useState<boolean>(false); | |
| const activeShare = shareTarget ? sharesMap[shareTarget.path] : undefined; | |
| useEffect(() => { | |
| if (shareTarget) { | |
| const sh = sharesMap[shareTarget.path]; | |
| setDraftRequireApproval(sh ? sh.require_approval : true); | |
| setCopiedShareLink(false); | |
| } | |
| }, [shareTarget, sharesMap]); | |
| async function handleEnableShare() { | |
| if (!shareTarget) return; | |
| setSavingShare(true); | |
| await upsertFileShare(shareTarget.path, shareTarget.size, true, draftRequireApproval, false); | |
| setSavingShare(false); | |
| } | |
| async function handleDisableShare() { | |
| if (!shareTarget || !activeShare) return; | |
| setSavingShare(true); | |
| await upsertFileShare(shareTarget.path, shareTarget.size, false, activeShare.require_approval, false); | |
| setSavingShare(false); | |
| } | |
| async function handleToggleRequireApproval(nextVal: boolean) { | |
| if (!shareTarget || !activeShare) return; | |
| setDraftRequireApproval(nextVal); | |
| setSavingShare(true); | |
| await upsertFileShare(shareTarget.path, shareTarget.size, activeShare.enabled, nextVal, false); | |
| setSavingShare(false); | |
| } | |
| async function handleRegenerateShareLink() { | |
| if (!shareTarget || !activeShare) return; | |
| if (!confirm("Đổi mã liên kết mới sẽ vô hiệu hóa liên kết cũ và xóa danh sách đã cấp quyền trước đó. Tiếp tục?")) { | |
| return; | |
| } | |
| setSavingShare(true); | |
| await upsertFileShare(shareTarget.path, shareTarget.size, true, activeShare.require_approval, true); | |
| setSavingShare(false); | |
| } | |
| function handleCopyShareUrl(shareId: string) { | |
| const url = buildFrontendShareUrl(shareId); | |
| navigator.clipboard.writeText(url); | |
| setCopiedShareLink(true); | |
| notify("Đã sao chép liên kết chia sẻ!", "success", url); | |
| setTimeout(() => setCopiedShareLink(false), 2500); | |
| } | |
| return ( | |
| <> | |
| {/* 1. UPLOAD MODAL */} | |
| {uploadModalOpen && ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4"> | |
| <div className="glass-panel w-full max-w-lg rounded-3xl p-6 border border-white/15"> | |
| <div className="flex items-center justify-between mb-4"> | |
| <h3 className="text-base font-bold text-white flex items-center gap-2"> | |
| <UploadCloud className="w-5 h-5 text-indigo-400" /> | |
| <span>Tải tệp lên Upload ThTuanIT</span> | |
| </h3> | |
| <button onClick={() => setUploadModalOpen(false)} className="p-1.5 rounded-xl bg-white/5 text-slate-400"> | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| <div className="space-y-4"> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-300 mb-1">Thư mục đích (tùy chọn)</label> | |
| <input | |
| type="text" | |
| value={uploadTargetFolder} | |
| onChange={(e) => setUploadTargetFolder(e.target.value)} | |
| placeholder="Ví dụ: videos/2026 hoặc để trống lưu ở gốc" | |
| className="w-full bg-slate-900 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white font-mono focus:outline-none" | |
| /> | |
| </div> | |
| <label className="flex flex-col items-center justify-center p-8 border-2 border-dashed border-white/15 hover:border-indigo-500 rounded-2xl bg-slate-900/50 cursor-pointer transition"> | |
| <input | |
| type="file" | |
| multiple | |
| className="hidden" | |
| onChange={(e) => setSelectedFiles(Array.from(e.target.files || []))} | |
| /> | |
| <UploadCloud className="w-10 h-10 text-indigo-400 mb-2" /> | |
| <span className="text-sm font-medium text-slate-200">Nhấn để chọn nhiều tệp hoặc kéo thả</span> | |
| <span className="text-xs text-slate-400 mt-1">Tối đa 10 GiB mỗi tệp qua Upload ThTuanIT Turbo Engine</span> | |
| </label> | |
| {selectedFiles.length > 0 && ( | |
| <div className="max-h-36 overflow-y-auto space-y-1.5"> | |
| {selectedFiles.map((f, i) => ( | |
| <div | |
| key={i} | |
| className="flex justify-between text-xs px-3 py-2 rounded-xl bg-slate-900 border border-white/10" | |
| > | |
| <span className="truncate text-slate-200">{f.name}</span> | |
| <span className="font-mono text-slate-400 ml-2">{formatBytes(f.size)}</span> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| <div className="flex justify-end gap-2 pt-2"> | |
| <button | |
| onClick={() => setUploadModalOpen(false)} | |
| className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300" | |
| > | |
| Hủy | |
| </button> | |
| <button | |
| onClick={startBatchUpload} | |
| className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 text-xs font-bold text-white" | |
| > | |
| Bắt đầu tải lên ({selectedFiles.length}) | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| {/* 2. RENAME / MOVE FILE MODAL */} | |
| {renameTarget && ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4"> | |
| <div className="glass-panel w-full max-w-md rounded-3xl p-6 border border-white/15"> | |
| <div className="flex items-center justify-between mb-4"> | |
| <h3 className="text-base font-bold text-white flex items-center gap-2"> | |
| <Edit3 className="w-5 h-5 text-amber-400" /> | |
| <span>Đổi tên / Di chuyển Tệp tin</span> | |
| </h3> | |
| <button onClick={() => setRenameTarget(null)} className="p-1.5 rounded-xl bg-white/5 text-slate-400"> | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| <form onSubmit={handleRenameSubmit} className="space-y-4"> | |
| <div> | |
| <label className="block text-xs text-slate-400 mb-1">Đường dẫn hiện tại</label> | |
| <p className="text-xs font-mono text-slate-300 bg-slate-900/70 px-3 py-2 rounded-xl border border-white/5"> | |
| {renameTarget.path} | |
| </p> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-200 mb-1">Đường dẫn / Tên mới</label> | |
| <input | |
| type="text" | |
| required | |
| value={newPathInput} | |
| onChange={(e) => setNewPathInput(e.target.value)} | |
| className="w-full bg-slate-900 border border-white/15 focus:border-amber-400 rounded-xl px-3.5 py-2.5 text-sm text-white font-mono focus:outline-none" | |
| /> | |
| </div> | |
| <div className="flex justify-end gap-2"> | |
| <button | |
| type="button" | |
| onClick={() => setRenameTarget(null)} | |
| className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300" | |
| > | |
| Hủy | |
| </button> | |
| <button | |
| type="submit" | |
| disabled={renaming} | |
| className="px-5 py-2 rounded-xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs" | |
| > | |
| {renaming ? "Đang đồng bộ..." : "Lưu thay đổi"} | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| )} | |
| {/* 3. QUICK SHARE MODAL (CHIA SẺ NHANH & PHÊ DUYỆT QUYỀN XEM) */} | |
| {shareTarget && ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-md p-4"> | |
| <div className="glass-panel w-full max-w-xl rounded-3xl p-6 border border-indigo-500/30 space-y-5 max-h-[90vh] overflow-y-auto"> | |
| <div className="flex items-center justify-between border-b border-white/10 pb-4"> | |
| <div className="flex items-center gap-3 min-w-0"> | |
| <div className="w-10 h-10 rounded-2xl bg-indigo-500/20 border border-indigo-500/40 flex items-center justify-center text-indigo-300 shrink-0"> | |
| <Share2 className="w-5 h-5" /> | |
| </div> | |
| <div className="min-w-0"> | |
| <h3 className="text-base font-bold text-white truncate">Chia sẻ nhanh: {shareTarget.name}</h3> | |
| <p className="text-xs text-slate-400 font-mono truncate"> | |
| {formatBytes(shareTarget.size)} • Chủ sở hữu: @{shareTarget.owner} | |
| </p> | |
| </div> | |
| </div> | |
| <button | |
| onClick={() => setShareTarget(null)} | |
| className="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white" | |
| > | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| {/* IF NOT YET ENABLED -> CONFIRMATION TO ALLOW SHARING */} | |
| {!activeShare || !activeShare.enabled ? ( | |
| <div className="space-y-4"> | |
| <div className="p-4 rounded-2xl bg-amber-500/10 border border-amber-500/30 space-y-2"> | |
| <div className="flex items-center gap-2 text-amber-300 font-bold text-xs uppercase tracking-wider"> | |
| <Lock className="w-4 h-4" /> | |
| <span>Xác nhận cho phép chia sẻ tệp tin</span> | |
| </div> | |
| <p className="text-xs text-slate-300 leading-relaxed"> | |
| Tệp <b>{shareTarget.name}</b> hiện đang ở chế độ <b>Riêng tư</b>. Bạn có muốn tạo liên kết chia sẻ | |
| để gửi cho mọi người xem được tệp này không? Bạn có thể <b>tắt chia sẻ bất cứ lúc nào</b>. | |
| </p> | |
| </div> | |
| <div className="space-y-2.5"> | |
| <p className="text-xs font-bold text-slate-200 uppercase tracking-wider"> | |
| Chọn chế độ kiểm soát người xem: | |
| </p> | |
| <label | |
| onClick={() => setDraftRequireApproval(true)} | |
| className={`flex items-start gap-3 p-3.5 rounded-2xl border cursor-pointer transition ${ | |
| draftRequireApproval | |
| ? "bg-indigo-500/15 border-indigo-500/50 text-white" | |
| : "bg-slate-900/70 border-white/10 text-slate-400 hover:border-white/20" | |
| }`} | |
| > | |
| <input | |
| type="radio" | |
| checked={draftRequireApproval} | |
| onChange={() => setDraftRequireApproval(true)} | |
| className="mt-1 accent-indigo-500" | |
| /> | |
| <div className="text-xs space-y-1"> | |
| <p className="font-bold text-slate-100 flex items-center gap-1.5"> | |
| <Lock className="w-3.5 h-3.5 text-indigo-400" /> | |
| <span>Phải hỏi xin phép khi truy cập (Khuyên dùng)</span> | |
| </p> | |
| <p className="text-slate-400 leading-relaxed"> | |
| Người có link khi mở phải gửi yêu cầu và <b>chờ bạn bấm "Cho phép"</b> mới được xem | |
| trước hoặc tải tệp xuống. | |
| </p> | |
| </div> | |
| </label> | |
| <label | |
| onClick={() => setDraftRequireApproval(false)} | |
| className={`flex items-start gap-3 p-3.5 rounded-2xl border cursor-pointer transition ${ | |
| !draftRequireApproval | |
| ? "bg-emerald-500/15 border-emerald-500/50 text-white" | |
| : "bg-slate-900/70 border-white/10 text-slate-400 hover:border-white/20" | |
| }`} | |
| > | |
| <input | |
| type="radio" | |
| checked={!draftRequireApproval} | |
| onChange={() => setDraftRequireApproval(false)} | |
| className="mt-1 accent-emerald-500" | |
| /> | |
| <div className="text-xs space-y-1"> | |
| <p className="font-bold text-slate-100 flex items-center gap-1.5"> | |
| <Unlock className="w-3.5 h-3.5 text-emerald-400" /> | |
| <span>Chia sẻ nhanh trực tiếp qua Link</span> | |
| </p> | |
| <p className="text-slate-400 leading-relaxed"> | |
| Bất kỳ ai nhận được liên kết chia sẻ này đều có thể xem và tải tệp ngay lập tức cho đến khi bạn | |
| tắt liên kết. | |
| </p> | |
| </div> | |
| </label> | |
| </div> | |
| <div className="flex items-center justify-end gap-2.5 pt-2"> | |
| <button | |
| type="button" | |
| onClick={() => setShareTarget(null)} | |
| className="px-4 py-2.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-300" | |
| > | |
| Không chia sẻ | |
| </button> | |
| <button | |
| type="button" | |
| disabled={savingShare} | |
| onClick={handleEnableShare} | |
| className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 flex items-center gap-2" | |
| > | |
| <Share2 className="w-4 h-4" /> | |
| <span>{savingShare ? "Đang tạo liên kết..." : "Cho phép & Bật Link Chia sẻ"}</span> | |
| </button> | |
| </div> | |
| </div> | |
| ) : ( | |
| /* WHEN SHARE IS ACTIVE (ENABLED) */ | |
| <div className="space-y-5"> | |
| {/* Status Banner & Quick OFF Button */} | |
| <div className="p-4 rounded-2xl bg-emerald-500/10 border border-emerald-500/30 flex flex-wrap items-center justify-between gap-3"> | |
| <div className="flex items-center gap-2.5"> | |
| <span className="w-2.5 h-2.5 rounded-full bg-emerald-400 animate-pulse" /> | |
| <div> | |
| <p className="text-xs font-bold text-emerald-300">Liên kết chia sẻ đang BẬT</p> | |
| <p className="text-[11px] text-slate-300"> | |
| {activeShare.require_approval | |
| ? "Chế độ: Người xem phải hỏi xin phép và được bạn duyệt" | |
| : "Chế độ: Ai có link đều xem & tải được ngay"} | |
| </p> | |
| </div> | |
| </div> | |
| <button | |
| type="button" | |
| disabled={savingShare} | |
| onClick={handleDisableShare} | |
| className="px-3.5 py-2 rounded-xl bg-rose-500/20 hover:bg-rose-500/30 border border-rose-500/40 text-xs font-bold text-rose-300 flex items-center gap-1.5 transition" | |
| > | |
| <Power className="w-3.5 h-3.5" /> | |
| <span>Tắt chia sẻ ngay</span> | |
| </button> | |
| </div> | |
| {/* Share URL Box */} | |
| <div className="space-y-2"> | |
| <div className="flex items-center justify-between"> | |
| <label className="text-xs font-bold text-slate-300"> | |
| Liên kết gửi cho mọi người: | |
| </label> | |
| <button | |
| type="button" | |
| onClick={handleRegenerateShareLink} | |
| className="text-[11px] text-indigo-300 hover:text-indigo-200 flex items-center gap-1 font-mono" | |
| > | |
| <RefreshCw className="w-3 h-3" /> Đổi mã link mới | |
| </button> | |
| </div> | |
| <div className="flex items-center gap-2"> | |
| <input | |
| type="text" | |
| readOnly | |
| value={buildFrontendShareUrl(activeShare.id)} | |
| className="flex-1 bg-slate-950 border border-white/15 rounded-xl px-3.5 py-2.5 text-xs font-mono text-indigo-200 focus:outline-none" | |
| /> | |
| <button | |
| type="button" | |
| onClick={() => handleCopyShareUrl(activeShare.id)} | |
| className="px-4 py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white flex items-center gap-1.5 shrink-0 transition" | |
| > | |
| {copiedShareLink ? <Check className="w-4 h-4 text-emerald-300" /> : <Copy className="w-4 h-4" />} | |
| <span>{copiedShareLink ? "Đã chép" : "Sao chép"}</span> | |
| </button> | |
| <a | |
| href={buildFrontendShareUrl(activeShare.id)} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className="p-2.5 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-slate-300 hover:text-white" | |
| title="Mở trang chia sẻ trong tab mới" | |
| > | |
| <ExternalLink className="w-4 h-4" /> | |
| </a> | |
| </div> | |
| </div> | |
| {/* Toggle Require Approval */} | |
| <div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/10 flex items-center justify-between gap-4"> | |
| <div className="space-y-0.5"> | |
| <p className="text-xs font-bold text-white flex items-center gap-1.5"> | |
| {activeShare.require_approval ? ( | |
| <Lock className="w-3.5 h-3.5 text-amber-400" /> | |
| ) : ( | |
| <Unlock className="w-3.5 h-3.5 text-emerald-400" /> | |
| )} | |
| <span>Bắt buộc hỏi xin phép trước khi xem tệp</span> | |
| </p> | |
| <p className="text-[11px] text-slate-400"> | |
| Khi bật, người mở link phải gửi yêu cầu và chờ bạn nhấn "Cho phép" bên dưới. | |
| </p> | |
| </div> | |
| <button | |
| type="button" | |
| disabled={savingShare} | |
| onClick={() => handleToggleRequireApproval(!activeShare.require_approval)} | |
| className={`px-3.5 py-1.5 rounded-xl text-xs font-bold border transition shrink-0 ${ | |
| activeShare.require_approval | |
| ? "bg-amber-500/20 text-amber-300 border-amber-500/40" | |
| : "bg-white/5 text-slate-400 border-white/10 hover:text-white" | |
| }`} | |
| > | |
| {activeShare.require_approval ? "Đang BẬT hỏi phép" : "Đang TẮT hỏi phép"} | |
| </button> | |
| </div> | |
| {/* Access Requests List */} | |
| <div className="space-y-2.5 pt-1 border-t border-white/10"> | |
| <div className="flex items-center justify-between"> | |
| <h4 className="text-xs font-bold uppercase tracking-wider text-slate-300"> | |
| Danh sách người xin quyền xem ({activeShare.requests?.length || 0}) | |
| </h4> | |
| <span className="text-[11px] font-mono text-slate-400">Tự động cập nhật</span> | |
| </div> | |
| {!activeShare.requests || activeShare.requests.length === 0 ? ( | |
| <div className="p-5 rounded-2xl bg-slate-950/60 border border-white/5 text-center text-xs text-slate-400"> | |
| Chưa có yêu cầu xin quyền xem nào cho liên kết này. | |
| </div> | |
| ) : ( | |
| <div className="space-y-2 max-h-56 overflow-y-auto pr-1"> | |
| {activeShare.requests.map((req) => ( | |
| <div | |
| key={req.request_id} | |
| className="p-3 rounded-2xl bg-slate-900/90 border border-white/10 flex flex-wrap items-center justify-between gap-3" | |
| > | |
| <div className="min-w-0 flex-1"> | |
| <div className="flex items-center gap-2"> | |
| <span className="text-xs font-bold text-white truncate">{req.visitor_name}</span> | |
| {req.status === "pending" && ( | |
| <span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-amber-500/20 text-amber-300 border border-amber-500/30 flex items-center gap-1"> | |
| <Clock className="w-3 h-3" /> Chờ cho phép | |
| </span> | |
| )} | |
| {req.status === "approved" && ( | |
| <span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30"> | |
| ✓ Đã cho phép | |
| </span> | |
| )} | |
| {req.status === "rejected" && ( | |
| <span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-rose-500/20 text-rose-300 border border-rose-500/30"> | |
| ✕ Đã từ chối | |
| </span> | |
| )} | |
| </div> | |
| {req.note && <p className="text-xs text-slate-300 mt-0.5 italic">“{req.note}”</p>} | |
| <p className="text-[10px] font-mono text-slate-500 mt-0.5">{req.requested_at}</p> | |
| </div> | |
| <div className="flex items-center gap-1.5"> | |
| {req.status !== "approved" && ( | |
| <button | |
| type="button" | |
| onClick={() => respondShareRequest(activeShare.id, req.request_id, "approved")} | |
| className="px-3 py-1.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-xs font-bold text-white flex items-center gap-1 transition" | |
| > | |
| <UserCheck className="w-3.5 h-3.5" /> | |
| <span>Cho phép</span> | |
| </button> | |
| )} | |
| {req.status !== "rejected" && ( | |
| <button | |
| type="button" | |
| onClick={() => respondShareRequest(activeShare.id, req.request_id, "rejected")} | |
| className="px-3 py-1.5 rounded-xl bg-rose-500/20 hover:bg-rose-500/30 border border-rose-500/30 text-xs font-semibold text-rose-300 flex items-center gap-1 transition" | |
| > | |
| <UserX className="w-3.5 h-3.5" /> | |
| <span>{req.status === "approved" ? "Thu hồi" : "Từ chối"}</span> | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| )} | |
| {/* 4. ADMIN EDIT / CREATE USER MODAL */} | |
| {editingUser && ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4"> | |
| <div className="glass-panel w-full max-w-md rounded-3xl p-6 border border-amber-500/30"> | |
| <div className="flex items-center justify-between mb-4"> | |
| <h3 className="text-base font-bold text-white flex items-center gap-2"> | |
| <Shield className="w-5 h-5 text-amber-400" /> | |
| <span>{editingUser.isNew ? "Thêm người dùng mới" : `Chỉnh sửa @${editingUser.username}`}</span> | |
| </h3> | |
| <button onClick={() => setEditingUser(null)} className="p-1.5 rounded-xl bg-white/5 text-slate-400"> | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| <form onSubmit={handleSaveUser} className="space-y-4"> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-300 mb-1">Tên đăng nhập (Username)</label> | |
| <input | |
| type="text" | |
| required | |
| disabled={!editingUser.isNew} | |
| value={editingUser.username} | |
| onChange={(e) => setEditingUser({ ...editingUser, username: e.target.value })} | |
| className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white font-mono disabled:opacity-60" | |
| /> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-300 mb-1">Tên hiển thị</label> | |
| <input | |
| type="text" | |
| required | |
| value={editingUser.display_name} | |
| onChange={(e) => setEditingUser({ ...editingUser, display_name: e.target.value })} | |
| className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white" | |
| /> | |
| </div> | |
| <div className="grid grid-cols-2 gap-3"> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-300 mb-1">Vai trò (Role)</label> | |
| <select | |
| value={editingUser.role} | |
| disabled={editingUser.username === "admin"} | |
| onChange={(e) => setEditingUser({ ...editingUser, role: e.target.value as "admin" | "user" })} | |
| className="w-full bg-slate-900 border border-white/15 rounded-xl px-3 py-2 text-sm text-white" | |
| > | |
| <option value="user">User (Thành viên)</option> | |
| <option value="admin">Admin (Quản trị viên)</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-medium text-slate-300 mb-1"> | |
| {editingUser.isNew ? "Mật khẩu *" : "Đặt mật khẩu mới"} | |
| </label> | |
| <input | |
| type="password" | |
| required={editingUser.isNew} | |
| value={editingUser.password} | |
| onChange={(e) => setEditingUser({ ...editingUser, password: e.target.value })} | |
| placeholder="••••••••" | |
| className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white font-mono" | |
| /> | |
| </div> | |
| </div> | |
| {editingUser.role !== "admin" && ( | |
| <div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/10 space-y-2.5"> | |
| <p className="text-xs font-semibold text-slate-300">Quyền hạn chi tiết:</p> | |
| <label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer"> | |
| <span>Cho phép tải tệp lên (Upload)</span> | |
| <input | |
| type="checkbox" | |
| checked={editingUser.permissions.can_upload} | |
| onChange={(e) => | |
| setEditingUser({ | |
| ...editingUser, | |
| permissions: { ...editingUser.permissions, can_upload: e.target.checked }, | |
| }) | |
| } | |
| className="rounded accent-indigo-500" | |
| /> | |
| </label> | |
| <label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer"> | |
| <span>Cho phép đổi tên / di chuyển tệp (Rename)</span> | |
| <input | |
| type="checkbox" | |
| checked={editingUser.permissions.can_rename} | |
| onChange={(e) => | |
| setEditingUser({ | |
| ...editingUser, | |
| permissions: { ...editingUser.permissions, can_rename: e.target.checked }, | |
| }) | |
| } | |
| className="rounded accent-indigo-500" | |
| /> | |
| </label> | |
| <label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer"> | |
| <span>Cho phép xóa tệp tin khỏi Bucket (Delete)</span> | |
| <input | |
| type="checkbox" | |
| checked={editingUser.permissions.can_delete} | |
| onChange={(e) => | |
| setEditingUser({ | |
| ...editingUser, | |
| permissions: { ...editingUser.permissions, can_delete: e.target.checked }, | |
| }) | |
| } | |
| className="rounded accent-indigo-500" | |
| /> | |
| </label> | |
| </div> | |
| )} | |
| <div className="flex justify-end gap-2 pt-2"> | |
| <button | |
| type="button" | |
| onClick={() => setEditingUser(null)} | |
| className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300" | |
| > | |
| Hủy | |
| </button> | |
| <button | |
| type="submit" | |
| className="px-5 py-2 rounded-xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs" | |
| > | |
| Lưu cấu hình | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| )} | |
| {/* 5. FULLSCREEN MEDIA PREVIEW MODAL */} | |
| {previewFile && ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/85 backdrop-blur-md p-4"> | |
| <div className="glass-panel w-full max-w-4xl rounded-3xl overflow-hidden border border-white/15 flex flex-col max-h-[90vh]"> | |
| <div className="px-6 py-4 border-b border-white/10 flex items-center justify-between gap-4"> | |
| <div className="min-w-0"> | |
| <div className="flex items-center gap-2"> | |
| <h3 className="text-base font-bold text-white truncate">{previewFile.name}</h3> | |
| <span className="px-2 py-0.5 rounded text-[10px] font-mono bg-indigo-500/20 text-indigo-300 border border-indigo-500/30"> | |
| @{previewFile.owner} | |
| </span> | |
| </div> | |
| <p className="text-xs text-slate-400 font-mono truncate"> | |
| {formatBytes(previewFile.size)} • cloud://thtuanit/{previewFile.path} | |
| </p> | |
| </div> | |
| <div className="flex items-center gap-2"> | |
| <button | |
| onClick={() => { | |
| const target = previewFile; | |
| setPreviewFile(null); | |
| setShareTarget(target); | |
| }} | |
| className="px-3.5 py-1.5 rounded-xl bg-emerald-600/20 hover:bg-emerald-600/30 border border-emerald-500/40 text-xs font-semibold text-emerald-300 flex items-center gap-1.5" | |
| > | |
| <Share2 className="w-3.5 h-3.5" /> Chia sẻ nhanh | |
| </button> | |
| <button | |
| onClick={() => triggerDownload(previewFile)} | |
| className="px-3.5 py-1.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-semibold text-white flex items-center gap-1.5" | |
| > | |
| <Download className="w-3.5 h-3.5" /> Tải xuống | |
| </button> | |
| <button | |
| onClick={() => setPreviewFile(null)} | |
| className="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-300" | |
| > | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| </div> | |
| <div className="p-6 flex-1 overflow-auto flex items-center justify-center bg-slate-950/80 min-h-[340px]"> | |
| {previewFile.category === "video" ? ( | |
| <video | |
| controls | |
| autoPlay | |
| src={getDownloadUrl(previewFile.path, true)} | |
| className="max-h-[68vh] w-full rounded-2xl bg-black shadow-2xl" | |
| /> | |
| ) : previewFile.category === "image" ? ( | |
| <img | |
| src={getDownloadUrl(previewFile.path, true)} | |
| alt={previewFile.name} | |
| className="max-h-[68vh] rounded-2xl object-contain" | |
| /> | |
| ) : ( | |
| <div className="text-center py-10"> | |
| <p className="text-sm text-slate-300 mb-4"> | |
| Tệp <b>{previewFile.name}</b> ({formatBytes(previewFile.size)}) sẵn sàng để tải về máy. | |
| </p> | |
| <button | |
| onClick={() => triggerDownload(previewFile)} | |
| className="px-6 py-3 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white" | |
| > | |
| Tải tệp tin về máy ngay | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| <ToastStack toasts={toasts} /> | |
| </> | |
| ); | |
| } | |
| export function ToastStack({ toasts }: { toasts: ToastMsg[] }) { | |
| return ( | |
| <div className="fixed bottom-5 right-5 z-50 flex flex-col gap-2.5 max-w-sm w-full pointer-events-none"> | |
| {toasts.map((t) => ( | |
| <div | |
| key={t.id} | |
| className={`pointer-events-auto glass px-4 py-3 rounded-2xl border shadow-xl flex items-start gap-3 ${ | |
| t.type === "success" | |
| ? "border-emerald-500/40 text-emerald-200" | |
| : t.type === "error" | |
| ? "border-rose-500/40 text-rose-200" | |
| : "border-indigo-500/40 text-slate-200" | |
| }`} | |
| > | |
| {t.type === "success" ? ( | |
| <CheckCircle2 className="w-5 h-5 text-emerald-400 shrink-0 mt-0.5" /> | |
| ) : t.type === "error" ? ( | |
| <AlertTriangle className="w-5 h-5 text-rose-400 shrink-0 mt-0.5" /> | |
| ) : ( | |
| <Sparkles className="w-5 h-5 text-indigo-400 shrink-0 mt-0.5" /> | |
| )} | |
| <div className="min-w-0 flex-1"> | |
| <p className="text-xs font-semibold">{t.title}</p> | |
| {t.detail && <p className="text-[11px] opacity-80 font-mono truncate mt-0.5">{t.detail}</p>} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| ); | |
| } | |