import { useEffect, useState } from "react"; import { useMail } from "@/store/mail"; import { Switch } from "@/ui/misc"; import { toast } from "@/ui/toast"; import { toInputDateTime, fromInputDateTime, toUTCDate } from "@/lib/dates"; import { formatFullDateTime } from "@/lib/datetime"; import { dateTimeKey, useSettings } from "@/store/settings"; import { client, CAP } from "@/jmap/client"; export function VacationSettings() { const vacation = useMail((s) => s.vacation); const load = useMail((s) => s.loadVacation); const save = useMail((s) => s.saveVacation); const [enabled, setEnabled] = useState(false); const [subject, setSubject] = useState(""); const [body, setBody] = useState(""); const [from, setFrom] = useState(""); const [to, setTo] = useState(""); const [busy, setBusy] = useState(false); const available = client.hasCapability(CAP.vacation); // The date pickers themselves are native controls and follow the browser's // locale; echo the value back in the user's chosen format so there is no doubt. useSettings((s) => dateTimeKey(s.settings)); const echo = (v: string) => { const d = fromInputDateTime(v); return v && !Number.isNaN(d.getTime()) ? formatFullDateTime(d) : ""; }; useEffect(() => { void load(); }, [load]); useEffect(() => { if (!vacation) return; setEnabled(vacation.isEnabled); setSubject(vacation.subject ?? ""); setBody(vacation.textBody ?? ""); setFrom(vacation.fromDate ? toInputDateTime(new Date(vacation.fromDate)) : ""); setTo(vacation.toDate ? toInputDateTime(new Date(vacation.toDate)) : ""); }, [vacation]); if (!available) return

Out of office

Vacation responses are not available for this account.

; const submit = async () => { setBusy(true); try { await save({ isEnabled: enabled, subject: subject || null, textBody: body || null, htmlBody: null, fromDate: from ? toUTCDate(fromInputDateTime(from)) : null, toDate: to ? toUTCDate(fromInputDateTime(to)) : null, }); toast.success(enabled ? "Auto-reply is on" : "Auto-reply saved"); } catch (err) { toast.error((err as Error).message); } finally { setBusy(false); } }; return (

Out of office

Automatically reply to people who email you while you're away. Each sender gets at most one reply.

setFrom(e.target.value)} /> {echo(from) &&

{echo(from)}

}
setTo(e.target.value)} /> {echo(to) &&

{echo(to)}

}
setSubject(e.target.value)} placeholder="Out of office" />