diff --git a/lib/utils.ts b/lib/utils.ts index 7a031f2..ac72bbb 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -1,5 +1,10 @@ import { User } from "@/types/user"; +// Single source of truth for product type labels lives in types/product.ts +// (kept in sync with the backend Product::TYPES). Re-exported here so existing +// `@/lib/utils` imports keep working without a divergent (previously wrong) map. +export { getProductTypeLabel } from "@/types/product"; + export const formatDate = (dateString: string | null): string => { if (!dateString) return 'نامشخص'; @@ -20,16 +25,6 @@ export const formatPrice = (price: number | null): string => { return new Intl.NumberFormat('fa-IR').format(price); }; -export const getProductTypeLabel = (type: number | null): string => { - const types: Record = { - 1: 'ماهیانه', - 2: 'سه ماهه', - 3: 'شش ماهه', - 4: 'سالیانه', - }; - return type && types[type] ? types[type] : 'نامشخص'; -}; - export const getFullName = (user: User): string => { if (user.full_name) return user.full_name; diff --git a/types/product.ts b/types/product.ts index 07a9101..09373e7 100644 --- a/types/product.ts +++ b/types/product.ts @@ -35,7 +35,8 @@ export const PRODUCT_TYPES = { 1: 'دائمی', 2: 'سالیانه', 3: '۶ ماهه', - 4: 'ماهیانه' + 4: 'ماهیانه', + 5: 'سه ماهه' } as const; export type ProductType = keyof typeof PRODUCT_TYPES;