Spaces:
Sleeping
Sleeping
Download apps/web/src/components/ui/documents/DocumentAccessLog.tsx from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 5.9 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/ui/documents/DocumentAccessLog.tsx
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/web/src/components/ui/documents/DocumentAccessLog.tsx
-
curl -L -o DocumentAccessLog.tsx https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/ui/documents/DocumentAccessLog.tsx
5.9 kB
| "use client"; | |
| import { useCallback, useMemo } from "react"; | |
| import { | |
| Clock, | |
| User, | |
| Download, | |
| Share2, | |
| ChevronRight, | |
| ExternalLink, | |
| Activity, | |
| Lock, | |
| } from "lucide-react"; | |
| import { trpc } from "@/lib/trpc"; | |
| import { DocumentAction } from "@micprotocol/shared-types"; | |
| import { Badge } from "@micprotocol/ui"; | |
| interface DocumentAccessLogProps { | |
| documentId: string; | |
| } | |
| function ActionBadge({ action }: { action: DocumentAction }) { | |
| const config: Record<string, { color: string; bg: string; label: string }> = { | |
| view: { color: "var(--color-primary)", bg: "color-mix(in srgb, var(--color-primary) 12%, transparent)", label: "View" }, | |
| download: { color: "var(--color-success)", bg: "color-mix(in srgb, var(--color-success) 12%, transparent)", label: "Download" }, | |
| share_create: { color: "var(--color-warning)", bg: "color-mix(in srgb, var(--color-warning) 12%, transparent)", label: "Share" }, | |
| share_revoke: { color: "var(--color-error)", bg: "color-mix(in srgb, var(--color-error) 12%, transparent)", label: "Revoke" }, | |
| upload: { color: "var(--color-success)", bg: "color-mix(in srgb, var(--color-success) 12%, transparent)", label: "Upload" }, | |
| delete: { color: "var(--color-destructive)", bg: "color-mix(in srgb, var(--color-destructive) 12%, transparent)", label: "Delete" }, | |
| }; | |
| const c = config[action] || config.view; | |
| return ( | |
| <Badge tone="secondary" style={{ fontSize: "var(--text-xs)", textTransform: "uppercase", letterSpacing: "0.05em" }}> | |
| {c.label} | |
| </Badge> | |
| ); | |
| } | |
| export default function DocumentAccessLog({ documentId }: DocumentAccessLogProps) { | |
| const { data, isLoading } = trpc.documents.accessLogs.useQuery( | |
| { documentId, page: 1, limit: 50 }, | |
| { retry: false, refetchOnWindowFocus: false } | |
| ); | |
| const logs = data?.items ?? []; | |
| const total = data?.total ?? 0; | |
| return ( | |
| <div className="animate-fade-in space-y-6"> | |
| <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "var(--space-4)" }}> | |
| <div> | |
| <h2 style={{ fontSize: "var(--text-xl)", fontWeight: 700, letterSpacing: "-0.02em" }}>Access Log</h2> | |
| <p style={{ color: "var(--text-secondary)", fontSize: "var(--text-sm)" }}>{total} access event{total === 1 ? "" : "s"}</p> | |
| </div> | |
| </div> | |
| <div className="card" style={{ overflow: "hidden" }}> | |
| <div style={{ padding: "var(--space-4)" }}> | |
| {isLoading && ( | |
| <div style={{ display: "flex", alignItems: "center", gap: "var(--space-3)", color: "var(--text-tertiary)" }}> | |
| <Activity className="animate-spin" size={16} /> | |
| <span>Loading access log...</span> | |
| </div> | |
| )} | |
| {!isLoading && logs.length === 0 && ( | |
| <div style={{ padding: "var(--space-6)", textAlign: "center", color: "var(--text-tertiary)" }}> | |
| <Activity size={24} style={{ opacity: 0.4 }} /> | |
| <p style={{ marginTop: "var(--space-3)" }}>No access events yet</p> | |
| </div> | |
| )} | |
| {!isLoading && logs.length > 0 && ( | |
| <table style={{ width: "100%", borderCollapse: "collapse" }}> | |
| <thead> | |
| <tr style={{ borderBottom: "1px solid var(--border-color)" }}> | |
| <th style={{ padding: "var(--space-3) var(--space-4)", textAlign: "left", fontSize: "var(--text-xs)", fontWeight: 600, color: "var(--text-tertiary)", textTransform: "uppercase", letterSpacing: "0.05em" }}>Action</th> | |
| <th style={{ padding: "var(--space-3) var(--space-4)", textAlign: "left", fontSize: "var(--text-xs)", fontWeight: 600, color: "var(--text-tertiary)", textTransform: "uppercase", letterSpacing: "0.05em" }}>Actor</th> | |
| <th style={{ padding: "var(--space-3) var(--space-4)", textAlign: "left", fontSize: "var(--text-xs)", fontWeight: 600, color: "var(--text-tertiary)", textTransform: "uppercase", letterSpacing: "0.05em" }}>Time</th> | |
| <th style={{ padding: "var(--space-3) var(--space-4)", textAlign: "left", fontSize: "var(--text-xs)", fontWeight: 600, color: "var(--text-tertiary)", textTransform: "uppercase", letterSpacing: "0.05em" }}>IP Address</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {logs.map((log: any) => ( | |
| <tr key={log.id} style={{ borderBottom: "1px solid var(--border-color-subtle)" }}> | |
| <td style={{ padding: "var(--space-3) var(--space-4)" }}> | |
| <ActionBadge action={log.action as DocumentAction} /> | |
| </td> | |
| <td style={{ padding: "var(--space-3) var(--space-4)" }}> | |
| <div style={{ display: "flex", alignItems: "center", gap: "var(--space-2)" }}> | |
| <div style={{ width: 24, height: 24, borderRadius: "var(--radius-full)", background: "var(--bg-tertiary)", display: "flex", alignItems: "center", justifyContent: "center" }}> | |
| <User size={10} color="var(--text-tertiary)" /> | |
| </div> | |
| <span style={{ fontSize: "var(--text-sm)", color: "var(--text-primary)" }}>{log.userName ?? "Unknown"}</span> | |
| </div> | |
| </td> | |
| <td style={{ padding: "var(--space-3) var(--space-4)", fontSize: "var(--text-sm)", color: "var(--text-secondary)" }}> | |
| {new Date(log.createdAt).toLocaleString()} | |
| </td> | |
| <td style={{ padding: "var(--space-3) var(--space-4)", fontSize: "var(--text-sm)", color: "var(--text-secondary)", fontFamily: "var(--font-mono)" }}> | |
| {log.ipAddress ?? "—"} | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |