54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { Colors } from "~/application/enums/shared/Colors";
|
|
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
interface Props {
|
|
startedAt: Date | null;
|
|
finishedAt: Date | null;
|
|
endpoint: string;
|
|
status: number | null;
|
|
}
|
|
export default function StatusBadge({ startedAt, finishedAt, endpoint, status }: Props) {
|
|
const { t } = useTranslation();
|
|
|
|
function getState() {
|
|
if (status === null && startedAt === null) {
|
|
return t("events.webhookAttempts.status.notCaught");
|
|
} else if (status === null && startedAt !== null && finishedAt === null) {
|
|
return t("events.webhookAttempts.status.running");
|
|
} else if (status !== null && finishedAt !== null) {
|
|
if (status >= 200 && status < 300) {
|
|
return `[${status}] ${t("events.webhookAttempts.status.success")}`;
|
|
} else if (status >= 300 && status < 400) {
|
|
return `[${status}] ${t("events.webhookAttempts.status.redirect")}`;
|
|
} else if (status >= 400 && status < 500) {
|
|
return `[${status}] ${t("events.webhookAttempts.status.clientError")}`;
|
|
} else if (status >= 500) {
|
|
return `[${status}] ${t("events.webhookAttempts.status.serverError")}`;
|
|
} else {
|
|
return `[${status}] ${t("events.webhookAttempts.status.unknown")}`;
|
|
}
|
|
} else {
|
|
return t("events.webhookAttempts.status.unknown");
|
|
}
|
|
}
|
|
function getColor() {
|
|
if (status === null) {
|
|
return Colors.YELLOW;
|
|
} else if (status >= 200 && status < 300) {
|
|
return Colors.GREEN;
|
|
} else if (status >= 300 && status < 400) {
|
|
return Colors.ORANGE;
|
|
} else if (status >= 400 && status < 500) {
|
|
return Colors.RED;
|
|
} else {
|
|
return Colors.UNDEFINED;
|
|
}
|
|
}
|
|
return (
|
|
<div title={endpoint}>
|
|
<SimpleBadge title={getState()} color={getColor()} />
|
|
</div>
|
|
);
|
|
}
|