|
| 1 | +import { ExclamationTriangleIcon } from "@heroicons/react/20/solid"; |
| 2 | +import { json } from "@remix-run/node"; |
| 3 | +import { useFetcher } from "@remix-run/react"; |
| 4 | +import { useCallback, useEffect } from "react"; |
| 5 | +import { LinkButton } from "~/components/primitives/Buttons"; |
| 6 | +import { Paragraph } from "~/components/primitives/Paragraph"; |
| 7 | +import { useFeatures } from "~/hooks/useFeatures"; |
| 8 | +import { BetterStackClient } from "~/services/betterstack/betterstack.server"; |
| 9 | + |
| 10 | +export async function loader() { |
| 11 | + const client = new BetterStackClient(); |
| 12 | + const result = await client.getIncidents(); |
| 13 | + |
| 14 | + if (!result.success) { |
| 15 | + return json({ operational: true }); |
| 16 | + } |
| 17 | + |
| 18 | + return json({ |
| 19 | + operational: result.data.data.attributes.aggregate_state === "operational", |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +export function IncidentStatusPanel() { |
| 24 | + const { isManagedCloud } = useFeatures(); |
| 25 | + if (!isManagedCloud) { |
| 26 | + return null; |
| 27 | + } |
| 28 | + |
| 29 | + const fetcher = useFetcher<typeof loader>(); |
| 30 | + |
| 31 | + const fetchIncidents = useCallback(() => { |
| 32 | + if (fetcher.state === "idle") { |
| 33 | + fetcher.load("/resources/incidents"); |
| 34 | + } |
| 35 | + }, [fetcher]); |
| 36 | + |
| 37 | + useEffect(() => { |
| 38 | + fetchIncidents(); |
| 39 | + |
| 40 | + const interval = setInterval(fetchIncidents, 60 * 1000); // 1 minute |
| 41 | + |
| 42 | + return () => clearInterval(interval); |
| 43 | + }, [fetchIncidents]); |
| 44 | + |
| 45 | + const operational = fetcher.data?.operational ?? true; |
| 46 | + |
| 47 | + return ( |
| 48 | + <> |
| 49 | + {!operational && ( |
| 50 | + <div className="p-1"> |
| 51 | + <div className="flex flex-col gap-2 rounded border border-warning/20 bg-warning/5 p-2 pt-1.5"> |
| 52 | + <div className="flex items-center gap-1 border-b border-warning/20 pb-1 text-warning"> |
| 53 | + <ExclamationTriangleIcon className="size-4" /> |
| 54 | + <Paragraph variant="small/bright" className="text-warning"> |
| 55 | + Active Incident |
| 56 | + </Paragraph> |
| 57 | + </div> |
| 58 | + <Paragraph variant="extra-small/bright" className="line-clamp-3 text-warning/80"> |
| 59 | + We're currently experiencing service disruptions. Our team is actively working on |
| 60 | + resolving the issue. Check our status page for real-time updates. |
| 61 | + </Paragraph> |
| 62 | + <LinkButton |
| 63 | + variant="secondary/small" |
| 64 | + to="https://status.trigger.dev" |
| 65 | + target="_blank" |
| 66 | + fullWidth |
| 67 | + > |
| 68 | + View Status Page |
| 69 | + </LinkButton> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + )} |
| 73 | + </> |
| 74 | + ); |
| 75 | +} |
0 commit comments