// The rules for a read-only link: when it stops working, and an optional passcode. Shown under the link. import { useState } from 'react'; const OPTIONS = [['', 'Never'], ['1', 'In 1 day'], ['7', 'In 7 days'], ['30', 'In 30 days']]; const field = 'rounded-lg border border-[var(--r-line)] bg-[var(--r-bg)] px-2.5 py-1.5 text-sm text-[var(--r-text)] focus:outline-none focus:ring-2 focus:ring-[var(--r-line)]'; export const expiryText = (expiresAt, now = Date.now()) => { if (!expiresAt) return 'Never expires'; if (expiresAt <= now) return 'Expired'; const days = Math.ceil((expiresAt - now) / 86_400_000); return `Expires ${new Date(expiresAt).toLocaleDateString()} (${days} day${days === 1 ? '' : 's'} left)`; }; export default function LinkRules({ expiresAt, hasPasscode, busy, onSave }) { const [days, setDays] = useState('keep'); // 'keep' | '' | '1' | '7' | '30' const [passcode, setPasscode] = useState(''); const dirty = days !== 'keep' || passcode.trim() !== ''; const save = async () => { const options = {}; if (days !== 'keep') options.expiresInDays = days === '' ? null : Number(days); if (passcode.trim()) options.passcode = passcode.trim(); if (await onSave(options)) { setDays('keep'); setPasscode(''); } }; return (
{expiryText(expiresAt)} ยท {hasPasscode ? 'Needs a passcode' : 'No passcode'}
Send the passcode separately from the link. Anyone with both can read it until it expires or you turn it off.