"use client"; /** * v1.11.0 — Settings → Sharing (Epic C, C7). * * The OWNER surface for clinician share links. A share link is a time-boxed, * scope-frozen, read-only view of the owner's own health record at * `/c/`, optionally exposing a scoped read-only FHIR face. The raw * `hls_` token is shown EXACTLY ONCE on create — the list never carries it * (the server only stores its hash). * * The create form + one-time reveal live in the shared `ShareLinkCreateForm` * (mounted here and from the document detail sheet's Share action); this * section owns the create card chrome plus the active/revoked lists and the * revoke action. Reads unwrap `(await res.json()).data`; the query key comes * from the centralised factory. No markdown anywhere — every value renders as * escaped React text. * * v1.18.7 — restored as a first-class Settings section. The visible heading + * subtitle now come from the shared shell chrome in the route; this body is * the share-links card. Cards paint through `` so the surface * matches every sibling section 1:1. */ import { useMemo, useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { FileText, KeyRound, Share2, Trash2 } from "lucide-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { EmptyState } from "@/components/ui/empty-state"; import { SettingsCard } from "@/components/settings/settings-card"; import { SettingsCardHeader } from "@/components/settings/_card-header"; import { ShareLinkCreateForm, type ShareLinkSummary, } from "@/components/settings/share-link-create-form"; import { useAuth } from "@/hooks/use-auth"; import { formatDate, formatDateTime } from "@/lib/format"; import { useTranslations } from "@/lib/i18n/context"; import { queryKeys } from "@/lib/query-keys"; import { apiDelete, apiGet } from "@/lib/api/api-fetch"; export function SharingSection() { // v1.18.7 — the visible heading + subtitle come from the shared settings // shell chrome in the route; this body is the share-links card only. return (
); } function ShareLinksCard() { const { t } = useTranslations(); const { isAuthenticated } = useAuth(); const queryClient = useQueryClient(); const [showRevoked, setShowRevoked] = useState(false); const { data: links } = useQuery({ queryKey: queryKeys.shareLinks(), queryFn: () => apiGet<{ shareLinks: ShareLinkSummary[] }>("/api/share-links").then( (data) => data.shareLinks, ), enabled: isAuthenticated, }); const revokeMutation = useMutation({ mutationFn: (id: string) => apiDelete(`/api/share-links/${id}`), onSuccess: () => { queryClient.invalidateQueries({ queryKey: queryKeys.shareLinks() }); }, }); const activeLinks = useMemo( () => (links ?? []).filter((l) => l.active), [links], ); const inactiveLinks = useMemo( () => (links ?? []).filter((l) => !l.active), [links], ); return (

{t("settings.sharing.activeTitle")}

{activeLinks.length === 0 ? ( ) : (
    {activeLinks.map((link) => (
  • {link.label}

    {t("settings.sharing.statusActive")} {link.protected && ( {t("settings.sharing.protected")} )} {link.documentCount > 0 && ( {link.documentCount} )} {link.allowFhirApi && ( FHIR )}

    {t("settings.sharing.created")}: {" "} {formatDate(link.createdAt)}

    {t("settings.sharing.expires")}: {" "} {formatDateTime(link.expiresAt)}

    {t("settings.sharing.accessCount")}: {" "} {link.accessCount} {link.lastAccessAt ? ` · ${formatDateTime(link.lastAccessAt)}` : ""}

    {t("settings.sharing.revoke")} {t("settings.sharing.revokeDescription")} {t("common.cancel")} revokeMutation.mutate(link.id)} > {t("settings.sharing.revoke")}
  • ))}
)}
{inactiveLinks.length > 0 && (
{showRevoked && (
    {inactiveLinks.map((link) => (
  • {link.label}

    {link.revokedAt ? t("settings.sharing.statusRevoked") : t("settings.sharing.statusExpired")}

    {t("settings.sharing.accessCount")}: {" "} {link.accessCount}

  • ))}
)}
)}
); }