Skip to main content

useDataRetention

Location: src/hooks/useDataRetention.js

Overview

Provides three hooks for data management: useDataRetention for managing message retention and auto-archive settings, usePostArchive for archiving/unarchiving individual posts, and useDataExport for requesting GDPR-compliant data exports.

Exports

RETENTION_OPTIONS

Available message retention period options:

ValueLabel
3030 days
6060 days
9090 days (default)
180180 days
3651 year

useDataRetention

Manages the user's data retention preferences.

function useDataRetention(): {
settings: { messageRetentionDays: number, autoArchivePosts: boolean },
loading: boolean,
saving: boolean,
error: string | null,
updateSettings: (newSettings: { messageRetentionDays: number, autoArchivePosts: boolean }) => Promise<Result>,
setMessageRetention: (days: number) => Promise<Result>,
setAutoArchive: (enabled: boolean) => Promise<Result>,
refetch: () => Promise<void>
}
PropertyTypeDescription
settingsobjectCurrent retention settings: messageRetentionDays (default 90) and autoArchivePosts (default false)
loadingbooleanWhether settings are being loaded
savingbooleanWhether settings are being saved
errorstring | nullError message if load/save failed
updateSettings(newSettings) => Promise<Result>Update both settings at once via update_retention_settings RPC
setMessageRetention(days) => Promise<Result>Update only the message retention period
setAutoArchive(enabled) => Promise<Result>Toggle the auto-archive setting
refetch() => Promise<void>Re-fetch settings from the database

usePostArchive

Manages archiving/unarchiving individual posts.

function usePostArchive(): {
archiving: boolean,
archivePost: (postId: string) => Promise<{ success?: boolean, error?: string }>,
unarchivePost: (postId: string) => Promise<{ success?: boolean, error?: string }>
}
PropertyTypeDescription
archivingbooleanWhether an archive/unarchive operation is in progress
archivePost(postId) => Promise<Result>Archive a post via archive_post RPC
unarchivePost(postId) => Promise<Result>Unarchive a post via unarchive_post RPC

useDataExport

Handles GDPR data export requests.

function useDataExport(): {
requesting: boolean,
requestId: string | null,
requestExport: () => Promise<{ success?: boolean, requestId?: string, error?: string }>
}
PropertyTypeDescription
requestingbooleanWhether an export request is being submitted
requestIdstring | nullThe ID of the submitted export request
requestExport() => Promise<Result>Submit a data export request via request_data_export RPC

Usage

import { useDataRetention, RETENTION_OPTIONS, useDataExport } from '../hooks/useDataRetention';

function DataRetentionSettings() {
const { settings, saving, setMessageRetention, setAutoArchive } = useDataRetention();
const { requestExport, requesting, requestId } = useDataExport();

return (
<div>
<h3>Message Retention</h3>
<select
value={settings.messageRetentionDays}
onChange={(e) => setMessageRetention(Number(e.target.value))}
disabled={saving}
>
{RETENTION_OPTIONS.map(opt => (
<option key={opt.value} value={opt.value}>{opt.label}</option>
))}
</select>

<label>
<input
type="checkbox"
checked={settings.autoArchivePosts}
onChange={(e) => setAutoArchive(e.target.checked)}
/>
Auto-archive old posts
</label>

<h3>Data Export</h3>
<button onClick={requestExport} disabled={requesting}>
{requesting ? 'Requesting...' : 'Request Data Export'}
</button>
{requestId && <p>Export request submitted (ID: {requestId})</p>}
</div>
);
}

Notes

  • Default message retention is 90 days; auto-archive is disabled by default.
  • Settings are fetched via get_retention_settings RPC and updated via update_retention_settings RPC.
  • The data export request is processed asynchronously on the server; the hook only initiates the request.

Last updated: 2026-02-07