1 "use client"
2
3 import React, { useEffect, useState } from "react"
4 import clsx from "clsx"
5 import { CloudStatus, CloudStatusIndicator } from "types"
6 import { Tooltip } from "../../Tooltip"
7 import { CLOUD_STATUS_PAGE_URL } from "../../../constants"
8 import { getCloudStatus } from "../../../utils/get-cloud-status"
9
10 // the full class names are used so that tailwind can pick them up
11 const indicatorColors: Record<CloudStatusIndicator, string> = {
12 none: "bg-medusa-tag-green-icon",
13 maintenance: "bg-medusa-tag-blue-icon",
14 minor: "bg-medusa-tag-orange-icon",
15 major: "bg-medusa-tag-orange-icon",
16 critical: "bg-medusa-tag-red-icon",
17 }
18
19 export const ContentMenuCloudStatus = () => {
20 const [status, setStatus] = useState<CloudStatus | null>(null)
21
22 useEffect(() => {
23 getCloudStatus()
24 .then(setStatus)
25 .catch((e) => {
26 // fail silently, we don't want to break the page if the status can't be loaded
27 console.error("Failed to load the Medusa Cloud status", e)
28 })
29 }, [])
30
31 if (!status) {
32 return null
33 }
34
35 return (
36 <div className="px-docs_0.5">
37 <a
38 href={CLOUD_STATUS_PAGE_URL}
39 target="_blank"
40 rel="noopener noreferrer"
41 className={clsx(
42 "flex w-full items-center rounded-docs_sm no-underline",
43 "px-docs_0.5 py-docs_0.25",
44 "text-medusa-fg-subtle text-x-small-plus",
45 "hover:bg-medusa-bg-base-hover hover:text-medusa-fg-base"
46 )}
47 // the row only shows the "Medusa Cloud" label, so the status itself is
48 // conveyed with the block's color and in the tooltip. this makes it
49 // available to screen readers as well.
50 aria-label={`Medusa Cloud status: ${status.description}. Opens the status page in a new tab.`}
51 data-testid="content-menu-cloud-status"
52 >
53 <Tooltip
54 text={status.description}
55 tooltipClassName="font-base"
56 className="w-full"
57 innerClassName="flex items-center gap-docs_0.5"
58 place="left"
59 >
60 <span
61 className={clsx(
62 "h-docs_0.5 w-docs_0.5 flex-shrink-0 rounded-docs_xxs",
63 indicatorColors[status.indicator] || "bg-medusa-tag-neutral-icon"
64 )}
65 data-testid="content-menu-cloud-status-indicator"
66 />
67 Medusa Cloud
68 </Tooltip>
69 </a>
70 </div>
71 )
72 }