import { useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import type { CompanySecret } from "@paperclipai/shared"; import { Check, KeyRound, MoreHorizontal } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { QueryErrorState, useQueryView } from "@/components/QueryView"; import { EmptyState } from "../../components/EmptyState"; import { secretsApi, type MyUserSecretEntry } from "../../api/secrets"; import { queryKeys } from "../../lib/queryKeys"; import { relativeTime } from "../../lib/utils"; import { useToastActions } from "../../context/ToastContext"; import { SetMyUserSecretDialog } from "./SetMyUserSecretDialog"; import { SecretPathName } from "./SecretPathName"; import { myValueState } from "./my-value-state"; import { describeError } from "@/api/errors"; /** * Secrets → My secrets tab. Lists every secret the organization asks each * member to provide, with whether the signed-in person has added their value, * and lets them add, replace or remove it. */ export function MyUserSecretsTab({ companyId }: { companyId: string }) { const queryClient = useQueryClient(); const { pushToast } = useToastActions(); const [dialogFor, setDialogFor] = useState(null); const mySecretsQuery = useQuery({ queryKey: queryKeys.secrets.myUserSecrets(companyId), queryFn: () => secretsApi.listMyUserSecrets(companyId), }); const mySecretsView = useQueryView(mySecretsQuery); const entries = mySecretsQuery.data ?? []; const clear = useMutation({ mutationFn: (secret: CompanySecret) => secretsApi.removeMyUserSecret(companyId, secret.id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: queryKeys.secrets.myUserSecrets(companyId) }); pushToast({ title: "Your value was removed", tone: "info" }); }, onError: (err) => pushToast({ title: "Couldn't remove your value", body: describeError(err).body, tone: "error", }), }); const needsValue = (entry: MyUserSecretEntry) => entry.definition.status === "active" && !entry.secret; const missingCount = entries.filter(needsValue).length; // Secrets still waiting on this person come first; the rest keep the server's order. const sortedEntries = [...entries].sort( (a, b) => Number(needsValue(b)) - Number(needsValue(a)), ); return (

Values only you provide. Agents use them when they work for you. {missingCount > 0 ? ( {" "} {missingCount} still {missingCount === 1 ? "needs" : "need"} your value. ) : null}

{mySecretsView.kind === "error" ? ( ) : entries.length === 0 && !mySecretsQuery.isPending && mySecretsView.kind !== "reconnecting" ? ( ) : (
    {sortedEntries.map((entry) => ( setDialogFor(entry)} onClear={() => entry.secret && clear.mutate(entry.secret)} clearing={clear.isPending} /> ))}
)} { if (!open) setDialogFor(null); }} />
); } function MyUserSecretRow({ entry, onSet, onClear, clearing, }: { entry: MyUserSecretEntry; onSet: () => void; onClear: () => void; clearing: boolean; }) { const { definition, secret } = entry; const state = myValueState(definition, secret); const disabledDefinition = definition.status !== "active"; const replaced = secret ? secret.latestVersion > 1 && secret.lastRotatedAt : null; return (
  • {/* Agents point people at a secret by this key, so it stays visible. */} {definition.key} {definition.description ? ( {definition.description} ) : null} {definition.usageGuidance ? ( {definition.usageGuidance} ) : null} {disabledDefinition ? ( Turned off by an admin. Agents won't ask for it. ) : state === "inactive" ? ( Your value is turned off. Replace it to use it again. ) : null}
    {secret ? ( {replaced ? `Replaced ${relativeTime(replaced)}` : `Added ${relativeTime(secret.createdAt)}`} {!disabledDefinition ? ( ) : null} Remove your value ) : !disabledDefinition ? ( ) : null}
  • ); }