47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
|
|
import { faCircle, faCircleCheck, faCircleNotch, faCircleXmark } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
type Status = "idle" | "running" | "success" | "failed" | string | undefined;
|
|
|
|
const statusStyles: Record<
|
|
"idle" | "running" | "success" | "failed",
|
|
{ label: string; icon: IconDefinition; className: string; iconClassName?: string }
|
|
> = {
|
|
idle: {
|
|
label: "Idle",
|
|
icon: faCircle,
|
|
className: "bg-muted text-muted-foreground border border-border"
|
|
},
|
|
running: {
|
|
label: "Running",
|
|
icon: faCircleNotch,
|
|
className: "bg-amber-100 text-amber-800 border border-amber-200",
|
|
iconClassName: "animate-spin"
|
|
},
|
|
success: {
|
|
label: "Success",
|
|
icon: faCircleCheck,
|
|
className: "bg-emerald-100 text-emerald-800 border border-emerald-200"
|
|
},
|
|
failed: {
|
|
label: "Failed",
|
|
icon: faCircleXmark,
|
|
className: "bg-red-100 text-red-800 border border-red-200"
|
|
}
|
|
};
|
|
|
|
export function JobStatusBadge({ status }: { status: Status }) {
|
|
const normalized = (status || "idle") as keyof typeof statusStyles;
|
|
const style = statusStyles[normalized] || statusStyles.idle;
|
|
|
|
return (
|
|
<span
|
|
className={`inline-flex items-center gap-1 rounded-full px-3 py-1 text-xs font-semibold ${style.className}`}
|
|
>
|
|
<FontAwesomeIcon icon={style.icon} className={`h-3.5 w-3.5 ${style.iconClassName || ""}`} />
|
|
{style.label}
|
|
</span>
|
|
);
|
|
}
|