"use client"; import { useState } from "react"; import { ErrorLine } from "@/components/ui"; import { printAccessSlip } from "@/components/dialogs"; import { SLIP_DAYS, daysBetween, facilityDate, facilityToday, slipLive, type StaffRec } from "@/lib/compute"; import type { Act, Mutate } from "./shared"; /* Staff app activation. The code comes back once, in the op's response, and is never in the snapshot. */ export default function SelfService({ st, act, mutate, isAdmin, facility, tz }: { st: StaffRec; act: Act; mutate: Mutate; isAdmin: boolean; facility: string; tz: string }) { const [code, setCode] = useState(null); const [err, setErr] = useState(""); const [busy, setBusy] = useState(false); const today = facilityToday(tz); const live = slipLive(st.selfCodeAt, today, tz); const printed = facilityDate(st.selfCodeAt ?? "", tz); const age = printed ? daysBetween(printed, today) : null; const left = age === null ? null : SLIP_DAYS - age; const when = age === 0 ? "today" : age === 1 ? "yesterday" : `${age} days ago`; if (code) { return (
Code for {st.first}
{code}
Shown once. Print or copy it now.
); } return (
{st.selfEmail ? <>Signed up as {st.selfEmail}. : st.selfCode ? age === null ? <>Code outstanding but won't work (no print date). : live ? <>Code printed {when}, unused; expires {left === 1 ? "tomorrow" : `in ${left} days`}. : <>Code printed {when} has expired. : <>No staff-app login yet.}
{isAdmin && (
{!st.selfEmail && ( )} {st.selfCode && !st.selfEmail && } {st.selfEmail && ( )}
)}
); }