2023-02-19 02:31:57 -06:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2023-02-19 23:30:45 -08:00
|
|
|
import { i18n } from "../../../next-i18next.config";
|
|
|
|
|
2023-02-19 02:31:57 -06:00
|
|
|
import Block from "components/services/widget/block";
|
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
|
|
|
|
function formatDate(dateString) {
|
|
|
|
const date = new Date(dateString);
|
|
|
|
const now = new Date();
|
2023-02-19 23:30:45 -08:00
|
|
|
let dateOptions = {
|
|
|
|
month: "numeric",
|
2023-02-19 02:31:57 -06:00
|
|
|
day: "numeric",
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "numeric",
|
2023-02-19 23:30:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()) {
|
|
|
|
dateOptions = { timeStyle: "short" };
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Intl.DateTimeFormat(i18n.language, dateOptions).format(date);
|
2023-02-19 02:31:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const { widget } = service;
|
|
|
|
|
|
|
|
const { data, error } = useWidgetAPI(widget, "checks");
|
|
|
|
|
|
|
|
if (error) {
|
2023-04-30 19:09:37 -04:00
|
|
|
return <Container service={service} error={error} />;
|
2023-02-19 02:31:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label={t("healthchecks.status")} />
|
|
|
|
<Block label={t("healthchecks.last_ping")} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label={t("healthchecks.status")} value={t(`healthchecks.${data.status}`)} />
|
|
|
|
<Block
|
|
|
|
label={t("healthchecks.last_ping")}
|
|
|
|
value={data.last_ping ? formatDate(data.last_ping) : t("healthchecks.never")}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|