;
-
-export function IncidentStatusReport({
- incident,
- canNotify,
-}: {
- incident: Incident;
- canNotify: boolean;
-}) {
- if (incident.statusReport) {
- return (
-
- );
- }
- return ;
-}
-
-function NotifySubscribers({
- id,
- checked,
- onCheckedChange,
-}: {
- id: string;
- checked: boolean;
- onCheckedChange: (checked: boolean) => void;
-}) {
- return (
-
- onCheckedChange(value === true)}
- />
-
-
- );
-}
-
-function LinkedReport({
- incident,
- report,
- canNotify,
-}: {
- incident: Incident;
- report: NonNullable;
- canNotify: boolean;
-}) {
- const trpc = useTRPC();
- const queryClient = useQueryClient();
- const [composing, setComposing] = useState(false);
- const [confirmUnlink, setConfirmUnlink] = useState(false);
- const [status, setStatus] = useState(
- report.status === "resolved" ? "monitoring" : report.status,
- );
- const [message, setMessage] = useState("");
- const [notifySubscribers, setNotifySubscribers] = useState(canNotify);
- const update = usePublishUpdate(report.id);
- const unlink = useMutation(
- trpc.incident.unlinkStatusReport.mutationOptions({
- onSuccess: () => {
- setConfirmUnlink(false);
- return Promise.all([
- queryClient.invalidateQueries({
- queryKey: trpc.incident.get.queryKey({ id: incident.id }),
- }),
- queryClient.invalidateQueries({
- queryKey: trpc.incident.linkedStatusReportIds.queryKey(),
- }),
- ]);
- },
- onError: (error) => toast.error(errorMessage(error)),
- }),
- );
- const closed = incident.closedAt !== null;
-
- async function post() {
- const parsed = statusReportStatus.find((s) => s === status);
- if (!parsed) return;
- const promise = update.publish({
- statusReportId: report.id,
- status: parsed,
- message,
- date: new Date(),
- notifySubscribers,
- });
- toast.promise(promise, {
- loading: "Posting public update...",
- success: "Public update posted",
- error: (error) => errorMessage(error),
- });
- await promise;
- setMessage("");
- setComposing(false);
- }
-
- return (
-
-
-
- Published
-
-
- {report.status}
-
-
-
- {report.pageId ? (
-
- {report.title}
-
- ) : (
- {report.title}
- )}{" "}
- is what customers see on your status page.
-
-
- {composing ? (
-
-
-
- ) : null}
-
- {composing ? (
- <>
-
-
- >
- ) : (
- <>
-
- {closed ? null : (
-
- )}
- >
- )}
-
-
-
-
- Unlink this status report?
-
- {report.title} stays on your status page as it is, but updates
- from this incident no longer reach it. You can link it again
- later.
-
-
-
- Keep linked
- {
- e.preventDefault();
- unlink.mutate({ id: incident.id });
- }}
- >
- Unlink
-
-
-
-
-
- );
-}
-
-function UnlinkedReport({ incident }: { incident: Incident }) {
- const trpc = useTRPC();
- const queryClient = useQueryClient();
- const [createOpen, setCreateOpen] = useState(false);
- const [linking, setLinking] = useState(false);
- const [pickerOpen, setPickerOpen] = useState(false);
- const [reportId, setReportId] = useState(null);
- const closed = incident.closedAt !== null;
-
- const refresh = () =>
- Promise.all([
- queryClient.invalidateQueries({
- queryKey: trpc.incident.get.queryKey({ id: incident.id }),
- }),
- queryClient.invalidateQueries({
- queryKey: trpc.incident.listEvents.queryKey({ id: incident.id }),
- }),
- queryClient.invalidateQueries({
- queryKey: trpc.incident.linkedStatusReportIds.queryKey(),
- }),
- ]);
- const link = useMutation(
- trpc.incident.linkStatusReport.mutationOptions({ onSuccess: refresh }),
- );
- const { data: reports } = useQuery({
- ...trpc.statusReport.list.queryOptions({ order: "desc" }),
- enabled: !closed,
- });
- const { data: linkedIds } = useQuery({
- ...trpc.incident.linkedStatusReportIds.queryOptions(),
- enabled: !closed,
- });
- // Until both load, the list could offer reports another incident holds.
- const linked = linkedIds ? new Set(linkedIds) : null;
- const linkable =
- reports && linked ? reports.filter((r) => !linked.has(r.id)) : [];
- const selected = linkable.find((r) => r.id === reportId);
- // Closing mid-edit would otherwise strand a form whose footer is gone.
- const showLink = !closed && linking && linkable.length > 0;
-
- return (
-
-
-
-
- Not published
-
-
- {closed
- ? "This incident was never linked to a status report."
- : "Nothing here is public. Customers only see what you publish on your status page."}
-
-
- {showLink ? (
-
-
-
-
-
-
-
-
-
- No status report found.
-
- {linkable.map((r) => (
- {
- setReportId(r.id);
- setPickerOpen(false);
- }}
- >
-
- {r.title}
-
- {r.page.title}
-
-
-
- ))}
-
-
-
-
-
-
- ) : null}
- {closed ? null : (
-
- {showLink ? (
- <>
-
-
- >
- ) : (
- <>
-
- {linkable.length > 0 ? (
-
- ) : null}
- >
- )}
-
- )}
- {/* Mounted on demand: the sheet fetches pages as soon as it renders. */}
- {createOpen ? (
- refresh().catch(console.error)}
- />
- ) : null}
-
- );
-}
--
2.51.2