Scaffold frontend/modules/loyalty with types, API client, design system, feature pages, and thin App Router routes. Wire all screens to backend Loyalty service via BFF proxy. Add loyalty docs and update progress. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
/** Shared field/column builders for Hospitality resources. */
|
|
import type { HospitalityColumnConfig, HospitalityFieldConfig } from "@/modules/hospitality/components/HospitalityListCrudPage";
|
|
import { lifecycleStatusLabels, venueFormatLabels } from "@/modules/hospitality/design-system/tokens";
|
|
|
|
export const lifecycleStatusOptions = Object.entries(lifecycleStatusLabels).map(([value, label]) => ({
|
|
value,
|
|
label,
|
|
}));
|
|
|
|
export const venueFormatOptions = Object.entries(venueFormatLabels).map(([value, label]) => ({
|
|
value,
|
|
label,
|
|
}));
|
|
|
|
export function auditColumns(): HospitalityColumnConfig[] {
|
|
return [
|
|
{ key: "created_at", header: "ایجاد", type: "datetime", defaultVisible: false },
|
|
{ key: "updated_at", header: "بهروزرسانی", type: "datetime", defaultVisible: false },
|
|
];
|
|
}
|
|
|
|
export function codeNameStatusColumns(extra: HospitalityColumnConfig[] = []): HospitalityColumnConfig[] {
|
|
return [
|
|
{ key: "code", header: "کد" },
|
|
{ key: "name", header: "نام" },
|
|
...extra,
|
|
{ key: "status", header: "وضعیت", type: "status" },
|
|
...auditColumns(),
|
|
];
|
|
}
|
|
|
|
export function codeNameCreateFields(extra: HospitalityFieldConfig[] = []): HospitalityFieldConfig[] {
|
|
return [
|
|
{ name: "code", label: "کد", required: true },
|
|
{ name: "name", label: "نام", required: true },
|
|
...extra,
|
|
];
|
|
}
|
|
|
|
export function venueIdField(required = true): HospitalityFieldConfig {
|
|
return { name: "venue_id", label: "مکان (Venue ID)", type: "venue", required };
|
|
}
|
|
|
|
export function formatPrice(row: Record<string, unknown>, key = "base_price"): string {
|
|
const amount = Number(row[key] ?? 0);
|
|
const currency = String(row.currency_code ?? "IRR");
|
|
return `${amount.toLocaleString("fa-IR")} ${currency}`;
|
|
}
|
|
|
|
export function countByStatus(rows: Record<string, unknown>[], statusKey = "status") {
|
|
const total = rows.length;
|
|
const active = rows.filter((r) => r[statusKey] === "active" || r[statusKey] === "published").length;
|
|
const draft = rows.filter((r) => r[statusKey] === "draft").length;
|
|
return { total, active, draft };
|
|
}
|