Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export { QuoteIcon, QuoteIcon as Quote } from "@solar-icons/react/bold-duotone/q
export { Dialog2Icon as LanguagesIcon, Dialog2Icon as Languages } from "@solar-icons/react/bold-duotone/dialog-2";
export { Chart2Icon as AnalyticsIcon, Chart2Icon as BarChart3 } from "@solar-icons/react/bold-duotone/chart-2";
export { LinkIcon, LinkIcon as Link2 } from "@solar-icons/react/bold-duotone/link";
export { VideocameraIcon as Video } from "@solar-icons/react/bold-duotone/videocamera";
export { Plane2Icon as PublishIcon, Plane2Icon as Send } from "@solar-icons/react/bold-duotone/plane-2";
export { TrashBinTrashIcon as TrashIcon, TrashBinTrashIcon as Trash2 } from "@solar-icons/react/bold-duotone/trash-bin-trash";
export { Book2Icon as BookIcon, Book2Icon as BookOpen } from "@solar-icons/react/bold-duotone/book-2";
Expand Down
49 changes: 49 additions & 0 deletions components/icons/meeting-icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// The services a meeting link can be on, by its address: their own marks, and a camera for any other.

import { Video } from "@/components/icons";

export type MeetingService = "zoom" | "meet" | "teams" | "other";

/** Which service a meeting link is on. */
export function serviceOf(url: string): MeetingService {
let host = "";
try {
host = new URL(url).hostname.toLowerCase();
} catch {
return "other";
}
if (host === "zoom.us" || host.endsWith(".zoom.us") || host.endsWith(".zoomgov.com")) return "zoom";
if (host === "meet.google.com") return "meet";
if (host === "teams.microsoft.com" || host === "teams.live.com" || host.endsWith(".teams.microsoft.com")) return "teams";
return "other";
}

/** Whether a link is a sign-up page rather than the call: Zoom's registration for a meeting or a webinar. */
export const isSignUp = (url: string) => serviceOf(url) === "zoom" && /\/(meeting|webinar)\/register\//.test(url);

/** Zoom's app mark: its camera, white on its blue. */
function ZoomMark({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" aria-hidden>
<rect width="24" height="24" rx="6" fill="#0B5CFF" />
<path fill="#fff" d="M5 9.2A1.7 1.7 0 0 1 6.7 7.5h6.6a1.7 1.7 0 0 1 1.7 1.7v5.6a1.7 1.7 0 0 1-1.7 1.7H6.7A1.7 1.7 0 0 1 5 14.8Zm11 1.4 2.4-1.9c.4-.3 1-.1 1 .5v5.6c0 .6-.6.8-1 .5L16 13.4Z" />
</svg>
);
}

/** Google Meet's mark (Simple Icons). */
function MeetMark({ className }: { className?: string }) {
return (
<svg className={className} viewBox="0 0 24 24" fill="#00832D" aria-hidden>
<path d="M5.53 2.13 0 7.75h5.53zm.398 0v5.62h7.608v3.65l5.47-4.45c-.014-1.22.031-2.25-.025-3.46-.148-1.09-1.287-1.47-2.236-1.36zM23.1 4.32c-.802.295-1.358.995-2.047 1.49-2.506 2.05-4.982 4.12-7.468 6.19 3.025 2.59 6.04 5.18 9.065 7.76 1.218.671 1.428-.814 1.328-1.64v-13a.828.828 0 0 0-.877-.825zM.038 8.15v7.7h5.53v-7.7zm13.577 8.1H6.008v5.62c3.864-.006 7.737.011 11.58-.009 1.02-.07 1.618-1.12 1.468-2.07v-2.51l-5.47-4.68v3.65zm-13.577 0c.02 1.44-.041 2.88.033 4.31.162.948 1.158 1.43 2.047 1.31h3.464v-5.62z" />
</svg>
);
}

/** The mark for a meeting link's service. Teams has no mark it lets others draw, so it takes the camera. */
export function MeetingMark({ url, className }: { url: string; className?: string }) {
const service = serviceOf(url);
if (service === "zoom") return <ZoomMark className={className} />;
if (service === "meet") return <MeetMark className={className} />;
return <Video className={className} />;
}
144 changes: 131 additions & 13 deletions components/reports/intake-notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import { createContext, useContext, useSyncExternalStore } from "react";
import { useFormatter, useTranslations } from "next-intl";
import { Ban, CalendarClock, FileText, Hourglass } from "@/components/icons";
import { ArrowUpRight, Ban, CalendarClock, Clock3, FileText, Hourglass } from "@/components/icons";
import { MeetingMark, serviceOf, type MeetingService } from "@/components/icons/meeting-icons";
import { ListEmpty } from "@/components/evidence-libraries/list-controls";
import { StatusChip } from "@/components/evidence-libraries/configuration/status-chip";
import { Button } from "@/components/ui/button";
import type { IntakeState } from "@/lib/reports/intake";
import { TooltipHint } from "@/components/ui/tooltip";
import { hoursAt, type IntakeState, type Meeting } from "@/lib/reports/intake";
import { cn } from "@/lib/utils";

type Closed = Exclude<IntakeState, { open: true }>;
Expand All @@ -33,18 +35,34 @@ export const IntakeOpen = createContext<IntakeState>({ open: true });
export const IntakeShut = createContext<string | null>(null);
export const useShutNext = () => useContext(IntakeShut);

/** The call authors can join while new reports are open, if the admin gave one. */
export const IntakeMeeting = createContext<Meeting | null>(null);

/** The timezone the admin set new reports' dates and calendar periods in (Settings > Admin > Publications). */
export const IntakeClock = createContext("UTC");

// A zone named by its offset ("GMT", "GMT+1"): every reader knows it, where "WET" or "CAT" leaves most guessing.
// next-intl types only the older names; Intl takes it as it is.
const OFFSET = "shortOffset" as "short";

// The reader's own timezone, from their browser. None on the server, where the admin's stands in until the page is here.
const noSubscribe = () => () => {};
const browserZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;

/** The timezone times are shown in on the Publish page: the reader's own, or the admin's before the browser says. */
function useReaderZone(given?: string) {
const read = useContext(IntakeClock);
return useSyncExternalStore(noSubscribe, browserZone, () => null) ?? given ?? read;
}

/**
* A date on that clock, with its name: the time the admin set, the same for every author wherever they are. Left to
* itself the formatter reads the server's clock, and says nothing of it.
* A date in the reader's own time, with the zone's name, so it reads right wherever they are. Left to itself the
* formatter reads the server's clock, and says nothing of it.
*/
const useWhen = (given?: string) => {
const format = useFormatter();
const read = useContext(IntakeClock);
const timeZone = given ?? read;
return (at: number) => format.dateTime(at, { weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit", timeZone, timeZoneName: "short" });
const timeZone = useReaderZone(given);
return (at: number) => format.dateTime(at, { weekday: "short", day: "numeric", month: "short", hour: "2-digit", minute: "2-digit", timeZone, timeZoneName: OFFSET });
};

/** Why a new report can't start or a draft go on now, in a few words for beside the button; null while they can. `given` and `timeZone` are for the page that provides them. */
Expand All @@ -56,6 +74,7 @@ export function useIntakeShut(given?: IntakeState, timeZone?: string): string |
if (state.open) return null;
if (state.why === "off") return t("off");
if (state.why === "notYet") return t("notYet", { date: when(state.at) });
if (state.why === "between") return t("between", { date: when(state.at) });
if (state.why === "full" && state.reopensAt !== null) return t("next", { date: when(state.reopensAt) });
return t("over");
}
Expand All @@ -64,6 +83,22 @@ export function useIntakeShut(given?: IntakeState, timeZone?: string): string |
function useIntakeWords(state: Closed) {
const t = useTranslations("publishReports.flow.intake");
const when = useWhen();
const format = useFormatter();
const admin = useContext(IntakeClock);
const timeZone = useReaderZone();
if (state.why === "between") {
const time = (at: number, zone: boolean) => format.dateTime(at, { hour: "2-digit", minute: "2-digit", timeZone, timeZoneName: zone ? OFFSET : undefined });
// The hours as they fall next, on the admin's clock: their true end across a clock change, and the reader's
// weekdays from the days they really fall on, which hours near midnight can move.
const to = hoursAt(state.hours, state.at, admin)?.end ?? state.at;
const weekday = (at: number) => ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].indexOf(new Intl.DateTimeFormat("en-US", { weekday: "short", timeZone }).format(at));
const starts: number[] = [];
for (let next = hoursAt(state.hours, state.at, admin); next && starts.length < state.hours.days.length; next = hoursAt(state.hours, next.end, admin)) starts.push(next.start);
starts.sort((a, b) => weekday(a) - weekday(b));
const days = starts.map((at) => format.dateTime(at, { weekday: "long", timeZone }));
const words = { from: time(state.at, false), to: time(to, true), days: format.list(days) };
return { icon: Clock3, title: t("between.title"), body: t(days.length === 7 ? "between.everyDay" : "between.someDays", words), chip: t("opens", { date: when(state.at) }) };
}
if (state.why === "off") return { icon: Ban, title: t("off.title"), body: t("off.body"), chip: null };
if (state.why === "notYet") return { icon: CalendarClock, title: t("notYet.title"), body: t("notYet.body"), chip: t("opens", { date: when(state.at) }) };
if (state.why === "ended") return { icon: Hourglass, title: t("over.title"), body: t("ended.body"), chip: t("closed", { date: when(state.at) }) };
Expand All @@ -80,19 +115,101 @@ export function IntakeNotice({ className }: { className?: string }) {
function ClosedNotice({ state, className }: { state: Closed; className?: string }) {
const { icon: Icon, title, body, chip } = useIntakeWords(state);
return (
<div role="status" className={cn("flex flex-wrap items-center gap-x-4 gap-y-2.5 rounded-2xl bg-inset px-4 py-3", className)}>
<div role="status" className={cn("flex flex-wrap items-start gap-x-4 gap-y-2.5 rounded-2xl bg-inset px-4 py-3", className)}>
<span className="flex min-w-0 flex-1 basis-64 items-start gap-3">
<Icon className="mt-0.5 size-4 shrink-0 ink-warning" />
<span className="min-w-0">
<span className="block text-sm font-medium">{title}</span>
<span className="block text-sm text-muted-foreground">{body}</span>
</span>
</span>
{chip ? (
<StatusChip tone="neutral" icon={CalendarClock} className="shrink-0">
{chip}
</StatusChip>
) : null}
<span className="flex min-w-0 flex-wrap items-center gap-2">
{chip ? (
<StatusChip tone="neutral" icon={CalendarClock} className="shrink-0">
{chip}
</StatusChip>
) : null}
<WaitingJoin state={state} />
</span>
</div>
);
}

/** The way into the call, while new reports wait for their hours or their opening: there, and shut until then. */
function WaitingJoin({ state }: { state: Closed }) {
const t = useTranslations("publishReports.flow.intake.meeting");
const meeting = useContext(IntakeMeeting);
const when = useWhen();
if (!meeting) return null;
// A sign-up page is open whenever there is a session still to come: signing up before it is the point.
if (meeting.kind === "register") return state.why === "between" || state.why === "notYet" || (state.why === "full" && state.reopensAt !== null) ? <SignUp meeting={meeting} variant="outline" /> : null;
if (state.why !== "between" && state.why !== "notYet") return null;
return (
<TooltipHint label={t("opensAt", { date: when(state.at) })}>
<span tabIndex={0}>
<Button size="sm" variant="outline" disabled>
<MeetingMark url={meeting.url} className="size-4" /> {t("join")}
</Button>
</span>
</TooltipHint>
);
}

/** A service's name for a button, where it has one: people know where the button takes them. */
const SERVICE_NAME: Partial<Record<MeetingService, string>> = { zoom: "Zoom", meet: "Google Meet", teams: "Teams" };

/** The way to a sign-up page, named for its service. */
function SignUp({ meeting, variant }: { meeting: Meeting; variant?: "outline" }) {
const t = useTranslations("publishReports.flow.intake.meeting");
const name = SERVICE_NAME[serviceOf(meeting.url)];
return (
<Button size="sm" variant={variant} asChild>
<a href={meeting.url} target="_blank" rel="noreferrer">
{variant ? <MeetingMark url={meeting.url} className="size-4" /> : null}
{name ? t("signUpOn", { service: name }) : t("signUp")} <ArrowUpRight />
</a>
</Button>
);
}

/** While new reports are open, the session the admin gave: what it is, until when or how to get in, and the way there. */
export function MeetingBar({ className }: { className?: string }) {
const t = useTranslations("publishReports.flow.intake.meeting");
const state = useContext(IntakeOpen);
const meeting = useContext(IntakeMeeting);
const format = useFormatter();
const timeZone = useReaderZone();
if (!meeting || !state.open) return null;
const service = serviceOf(meeting.url);
const until = state.until == null ? null : format.dateTime(state.until, { hour: "2-digit", minute: "2-digit", timeZone, timeZoneName: OFFSET });
return (
// The mark sits at the title's top, as far from the box's top as from its side: 12px both ways.
<div className={cn("flex flex-wrap items-center gap-x-4 gap-y-2.5 rounded-2xl bg-inset p-3", className)}>
<span className="flex min-w-0 flex-1 basis-64 items-start gap-3">
{/* Zoom's mark is a tile of its own; the others get one the same size. */}
{service === "zoom" ? (
<MeetingMark url={meeting.url} className="size-9 shrink-0 self-start" />
) : (
<span className="flex size-9 shrink-0 self-start items-center justify-center rounded-lg bg-background">
<MeetingMark url={meeting.url} className={cn("size-5", service !== "meet" && "text-primary")} />
</span>
)}
<span className="min-w-0">
<span className="block truncate text-sm font-medium">{meeting.name || t(`service.${service}`)}</span>
<span className="block text-sm text-muted-foreground">
{meeting.kind === "register" ? (SERVICE_NAME[service] ? t("emailed", { service: SERVICE_NAME[service] }) : t("emailedAny")) : until ? t("onUntil", { time: until }) : t("on")}
</span>
</span>
</span>
{meeting.kind === "register" ? (
<SignUp meeting={meeting} />
) : (
<Button size="sm" asChild>
<a href={meeting.url} target="_blank" rel="noreferrer">
{t("join")} <ArrowUpRight />
</a>
</Button>
)}
</div>
);
}
Expand All @@ -118,6 +235,7 @@ function ClosedPage({ state, hasReports, onReports }: { state: Closed; hasReport
{chip}
</StatusChip>
) : null}
<WaitingJoin state={state} />
{hasReports ? (
<Button size="sm" variant="outline" onClick={onReports}>
<FileText /> {t("yourReports")}
Expand Down
Loading
Loading