Add status helpers
This commit is contained in:
26
app/src/lib/status.ts
Normal file
26
app/src/lib/status.ts
Normal 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" };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user