changes some status
This commit is contained in:
1 parent
cbd17608c1
commit
6e626482f6
15 files changed
+553
-99
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import type { ComponentType } from "react";
|
||||
import { AlertCircle, CheckCircle2, Clock, XCircle } from "lucide-react";
|
||||
import type { SelectOption } from "@/components/formInput";
|
||||
import type { StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { buildEnumOptions, getEnumLabel, isEnumValue, type EnumConfig, type TranslateFn } from "@/constants/enumLabels";
|
||||
|
||||
// ─── Gateway status ───────────────────────────────────────────────────────────
|
||||
|
||||
export const GATEWAY_STATUS_VALUES = ["pending", "paid", "unpaid", "failed"] as const;
|
||||
|
||||
export type GatewayStatusValue = (typeof GATEWAY_STATUS_VALUES)[number];
|
||||
|
||||
export const GATEWAY_STATUS_LABELS: Record<GatewayStatusValue, string> = {
|
||||
pending: "Pending",
|
||||
paid: "Paid",
|
||||
unpaid: "Unpaid",
|
||||
failed: "Failed",
|
||||
};
|
||||
|
||||
const GATEWAY_STATUS_ENUM: EnumConfig<GatewayStatusValue> = {
|
||||
values: GATEWAY_STATUS_VALUES,
|
||||
labels: GATEWAY_STATUS_LABELS,
|
||||
prefix: "onlinePayments.gatewayStatus",
|
||||
};
|
||||
|
||||
export const GATEWAY_STATUS_BADGE_VARIANTS: Record<GatewayStatusValue, StatusBadgeVariant> = {
|
||||
pending: "warning",
|
||||
paid: "success",
|
||||
unpaid: "default",
|
||||
failed: "error",
|
||||
};
|
||||
|
||||
export const GATEWAY_STATUS_ICONS: Record<GatewayStatusValue, ComponentType> = {
|
||||
pending: AlertCircle,
|
||||
paid: CheckCircle2,
|
||||
unpaid: Clock,
|
||||
failed: XCircle,
|
||||
};
|
||||
|
||||
// ─── Paid flag ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const PAID_VALUES = ["paid", "unpaid"] as const;
|
||||
|
||||
export type PaidValue = (typeof PAID_VALUES)[number];
|
||||
|
||||
export const PAID_LABELS: Record<PaidValue, string> = {
|
||||
paid: "Paid",
|
||||
unpaid: "Unpaid",
|
||||
};
|
||||
|
||||
const PAID_ENUM: EnumConfig<PaidValue> = {
|
||||
values: PAID_VALUES,
|
||||
labels: PAID_LABELS,
|
||||
prefix: "onlinePayments.paid",
|
||||
};
|
||||
|
||||
export const PAID_BADGE_VARIANTS: Record<PaidValue, StatusBadgeVariant> = {
|
||||
paid: "success",
|
||||
unpaid: "error",
|
||||
};
|
||||
|
||||
export const PAID_ICONS: Record<PaidValue, ComponentType> = {
|
||||
paid: CheckCircle2,
|
||||
unpaid: XCircle,
|
||||
};
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function withPrefix<T extends string>(config: EnumConfig<T>, prefix?: string): EnumConfig<T> {
|
||||
return prefix ? { ...config, prefix } : config;
|
||||
}
|
||||
|
||||
export function isGatewayStatusValue(status: string): status is GatewayStatusValue {
|
||||
return isEnumValue(GATEWAY_STATUS_VALUES, status);
|
||||
}
|
||||
|
||||
export function getGatewayStatusLabel(status: string, t?: TranslateFn, prefix?: string): string {
|
||||
return getEnumLabel(withPrefix(GATEWAY_STATUS_ENUM, prefix), status, t);
|
||||
}
|
||||
|
||||
export function getGatewayStatusOptions(t?: TranslateFn, prefix?: string): SelectOption[] {
|
||||
return buildEnumOptions(withPrefix(GATEWAY_STATUS_ENUM, prefix), t);
|
||||
}
|
||||
|
||||
export function toPaidValue(paid: boolean): PaidValue {
|
||||
return paid ? "paid" : "unpaid";
|
||||
}
|
||||
|
||||
export function getPaidLabel(paid: boolean, t?: TranslateFn, prefix?: string): string {
|
||||
return getEnumLabel(withPrefix(PAID_ENUM, prefix), toPaidValue(paid), t);
|
||||
}
|
||||
Reference in new issue
Block a user