Add status helpers

This commit is contained in:
thesn10
2026-07-02 22:20:35 +02:00
parent eb35dd0cdb
commit 639fe0e202

26
app/src/lib/status.ts Normal file
View File

@@ -0,0 +1,26 @@
import type { OrderStatus } from "@/data/mock";
export type StatusColor = "default" | "accent" | "success" | "warning" | "danger";
export interface StatusInfo {
label: string;
color: StatusColor;
}
const ORDER_STATUS_INFO: Record<OrderStatus, StatusInfo> = {
AwaitingConfirm: { label: "Awaiting Confirm", color: "warning" },
Active: { label: "Active", color: "accent" },
Complete: { label: "Complete", color: "success" },
Cancelled: { label: "Cancelled", color: "default" },
Disputed: { label: "Disputed", color: "danger" },
};
export function orderStatusInfo(status: OrderStatus): StatusInfo {
return ORDER_STATUS_INFO[status];
}
export function availabilityInfo(qty: number): StatusInfo {
if (qty === 0) return { label: "Out of Stock", color: "default" };
if (qty <= 3) return { label: `Only ${qty} left!`, color: "warning" };
return { label: `${qty} in stock`, color: "success" };
}