// R-UX4 interim UI (AD-28). The screen receives a secret-free VM and injected // commands. Reveal/copy plaintext exists only in short-lived component state. import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherArchive, FeatherLock, FeatherPlus, FeatherRotateCcw } from "@subframe/core"; import type { EntryRow, VaultDetailVM } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { Select } from "~/ui/components/Select"; import { Tabs } from "~/ui/components/Tabs"; import { Tag_Label } from "~/ui/components/Tag_Label"; import { TextInput } from "~/ui/components/TextInput"; export type VaultSecretField = "username" | "password" | "notes"; export type VaultAccessLevel = "read" | "write" | "admin"; type EntryDraft = { entryId?: string; title: string; url: string; username: string; password: string; notes: string; }; export type HrVaultDetailActions = { onReveal: (entryId: string, field: VaultSecretField) => Promise; onCopy: (entryId: string, field: VaultSecretField) => Promise; onCreateEntry: (input: Omit) => void; onUpdateEntry: (input: EntryDraft & { entryId: string }) => void; onArchiveEntry: (entryId: string) => void; onRestoreEntry: (entryId: string) => void; onGrantAccess: (input: { targetUserId: string; permissionLevel: VaultAccessLevel }) => void; onRevokeAccess: (targetUserId: string) => void; onExport: () => Promise; }; export type HrVaultDetailPageProps = { vm: VaultDetailVM; submitting: boolean; actionFeedback?: { status: "success" | "error"; messageKey: string } | null; actions: HrVaultDetailActions; }; function SecretField({ entryId, field, labelKey, autoClearMs, onReveal, onCopy, }: { entryId: string; field: VaultSecretField; labelKey: string; autoClearMs: number; onReveal: HrVaultDetailActions["onReveal"]; onCopy: HrVaultDetailActions["onCopy"]; }) { const { t } = useTranslation(); const [value, setValue] = useState(null); const [loading, setLoading] = useState(false); const [copied, setCopied] = useState(false); const [error, setError] = useState(false); const revealTimer = useRef | null>(null); const clipboardTimer = useRef | null>(null); function hide() { setValue(null); if (revealTimer.current) clearTimeout(revealTimer.current); revealTimer.current = null; } useEffect(() => { const onVisibilityChange = () => { if (document.visibilityState === "hidden") hide(); }; document.addEventListener("visibilitychange", onVisibilityChange); return () => { document.removeEventListener("visibilitychange", onVisibilityChange); if (revealTimer.current) clearTimeout(revealTimer.current); if (clipboardTimer.current) clearTimeout(clipboardTimer.current); }; }, []); async function reveal() { setLoading(true); setError(false); try { const revealed = await onReveal(entryId, field); if (revealed == null) { setError(true); return; } setValue(revealed); if (revealTimer.current) clearTimeout(revealTimer.current); revealTimer.current = setTimeout(hide, autoClearMs); } finally { setLoading(false); } } async function copy() { setLoading(true); setError(false); try { const copyValue = await onCopy(entryId, field); if (copyValue == null) { setError(true); return; } if (!navigator.clipboard) { setError(true); return; } try { await navigator.clipboard.writeText(copyValue); } catch { setError(true); return; } setCopied(true); if (clipboardTimer.current) clearTimeout(clipboardTimer.current); clipboardTimer.current = setTimeout(() => { void navigator.clipboard?.writeText("").catch(() => {}); setCopied(false); }, autoClearMs); } finally { setLoading(false); } } return (
{t(labelKey)} {value ?? t("hr.passwordSafe.detail.concealed")}
{value == null ? ( ) : ( )}
{error ? t("hr.passwordSafe.detail.secretActionFailed") : copied ? t("hr.passwordSafe.detail.copyCleared") : value != null ? t("hr.passwordSafe.detail.revealExpires") : ""}
); } function EntryCard({ entry, autoClearMs, canWrite, submitting, actions, onEdit, }: { entry: EntryRow; autoClearMs: number; canWrite: boolean; submitting: boolean; actions: HrVaultDetailActions; onEdit: (entry: EntryRow) => void; }) { const { t } = useTranslation(); return (
{entry.title} {entry.url ? {entry.url} : null}
{entry.tags.map((tag) => {tag})}
{canWrite ? (
) : null}
{entry.hasUsername ? : null} {entry.hasPassword ? : null} {entry.hasNotes ? : null}
); } export function HrVaultDetailPage({ vm, submitting, actionFeedback, actions }: HrVaultDetailPageProps) { const { t } = useTranslation(); const [tab, setTab] = useState<"entries" | "access" | "activities">("entries"); const [entryOpen, setEntryOpen] = useState(false); const [accessOpen, setAccessOpen] = useState(false); const [exportOpen, setExportOpen] = useState(false); const [exporting, setExporting] = useState(false); const [exportStatus, setExportStatus] = useState<"success" | "error" | null>(null); const [entry, setEntry] = useState({ title: "", url: "", username: "", password: "", notes: "" }); const [access, setAccess] = useState<{ targetUserId: string; permissionLevel: VaultAccessLevel }>({ targetUserId: "", permissionLevel: "read" }); if (vm.status !== "ready" || !vm.data) { return ( } title={t("hr.passwordSafe.title")} subtitle={t("hr.passwordSafe.detail.subtitle")} subtitleTone="secondary" /> ); } const data = vm.data; const availableMembers = data.memberOptions.filter((member) => !member.hasAccess); const tabItems = ["entries", "access", "activities"] as const; function resetEntry() { setEntry({ title: "", url: "", username: "", password: "", notes: "" }); } function submitEntry() { if (entry.entryId) actions.onUpdateEntry({ ...entry, entryId: entry.entryId }); else actions.onCreateEntry(entry); setEntryOpen(false); resetEntry(); } return ( } title={data.vaultName} subtitle={t("hr.passwordSafe.detail.subtitle")} subtitleTone="secondary" actions={ <> {t(`hr.passwordSafe.access.${data.accessLevel}`)} {data.canExport ? : null} {data.canManageAccess ? : null} {data.canWrite ? : null} } /> {actionFeedback ? ( ) : null} {exportStatus ? ( ) : null} {tabItems.map((item, index) => ( setTab(item)} onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); setTab(item); return; } if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return; event.preventDefault(); const offset = event.key === "ArrowRight" ? 1 : -1; const nextIndex = (index + offset + tabItems.length) % tabItems.length; setTab(tabItems[nextIndex]); const tabs = event.currentTarget.parentElement?.querySelectorAll('[role="tab"]'); tabs?.[nextIndex]?.focus(); }} > {t(`hr.passwordSafe.tabs.${item}`)} ))} {tab === "entries" ? (
{data.rows.length === 0 && data.archivedRows.length === 0 ? ( ) : null} {data.rows.map((row) => ( { setEntry({ entryId: selected.id, title: selected.title, url: selected.url ?? "", username: "", password: "", notes: "" }); setEntryOpen(true); }} /> ))} {data.canWrite && data.archivedRows.length > 0 ? (

{t("hr.passwordSafe.detail.archivedEntries")}

{data.archivedRows.map((row) => (
{row.title}
))}
) : null}
) : null} {tab === "access" ? (
{!data.canManageAccess ? ( ) : data.accessRows.length === 0 ? ( ) : ( data.accessRows.map((row) => (
{row.displayName} {row.email} {row.roleNames.join(", ") || t("hr.passwordSafe.noRole")}
)) )}
) : null} {tab === "activities" ? (
{data.activityRows.length === 0 ? ( ) : ( data.activityRows.map((activity) => (
{t(activity.actionLabelKey)} {activity.actorLabel} · {activity.createdAtLabel}
)) )}
) : null}

{t(entry.entryId ? "hr.passwordSafe.detail.editEntry" : "hr.passwordSafe.detail.newEntry")}

{(["title", "url", "username", "password", "notes"] as const).map((field) => ( setEntry((current) => ({ ...current, [field]: event.target.value }))} /> ))} {entry.entryId ?

{t("hr.passwordSafe.detail.editSecretsHint")}

: null}

{t("hr.passwordSafe.detail.manageAccess")}

{availableMembers.length === 0 ?

{t("hr.passwordSafe.allMembersGranted")}

: null}

{t("hr.passwordSafe.export.title")}

{t("hr.passwordSafe.export.body")}

); }