Files
HealthLog/src/lib/queries/use-privacy-summary.ts
T
Marc-André Bombeck 63574b98a6 feat(account): show the deletion grace window and its undo
The deletion dialogs, the managed-profile delete dialog and the Data &
Privacy page read the window from the privacy summary and say what
happens: the account is locked at once, erased after the stated number
of days, and an admin of the server can undo it until then; a wipe keeps
a copy an admin can restore for the same time. Copies in the server's
backups age out after their retention period, and the text says that
too. With the window set to 0 they keep the immediate wording.

The sign-in page names the erasure date when a sign-in, a passkey or the
single sign-on callback is refused for an account pending deletion. The
admin users list shows a pending account with its date and an "Undo
deletion" action, and the backups list labels the copy taken before a
wipe. Every new string is translated in all nine languages.
2026-10-25 13:51:01 +01:00

55 lines
1.7 KiB
TypeScript

"use client";
/**
* The privacy facts the server states (`GET /api/settings/privacy-summary`):
* the retention windows, the deletion grace window and the encryption-at-rest
* summary. One reader for every surface that quotes them, so the privacy page
* and the deletion dialogs share one cache entry with one shape.
*/
import { useQuery } from "@tanstack/react-query";
import { apiGet } from "@/lib/api/api-fetch";
import { useAuth } from "@/hooks/use-auth";
import { queryKeys } from "@/lib/query-keys";
export interface PrivacySummary {
retention: {
coachMessagesDays: number;
auditLogDays: number;
deliveryLogDays: number;
/** Days until an account, profile or wipe deletion completes; 0: at once. */
accountDeletionGraceDays: number;
};
encryption: {
algorithm: string;
columnCount: number;
modelCount: number;
};
}
export function usePrivacySummary() {
const { isAuthenticated } = useAuth();
return useQuery({
queryKey: queryKeys.privacySummary(),
queryFn: () => apiGet<PrivacySummary>("/api/settings/privacy-summary"),
enabled: isAuthenticated,
});
}
/**
* The deletion grace window in days, or null while it is not known (still
* loading, or the read failed): a dialog that states it must not guess.
* `pending` is true only while the first read is in flight, so a control can
* wait for the number instead of showing a sentence it would then change.
*/
export function useAccountDeletionGrace(): {
days: number | null;
pending: boolean;
} {
const { data, isPending, isError } = usePrivacySummary();
return {
days: data?.retention.accountDeletionGraceDays ?? null,
pending: isPending && !isError,
};
}