Files
approagency-admin-panel/lib/utils.ts
T
2026-02-19 22:13:11 +03:30

52 lines
1.4 KiB
TypeScript

import { User } from "@/types/user";
export const formatDate = (dateString: string | null): string => {
if (!dateString) return 'نامشخص';
try {
const date = new Date(dateString);
return new Intl.DateTimeFormat('fa-IR', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(date);
} catch {
return 'نامشخص';
}
};
export const formatPrice = (price: number | null): string => {
if (price === null || price === undefined) return '0';
return new Intl.NumberFormat('fa-IR').format(price);
};
export const getProductTypeLabel = (type: number | null): string => {
const types: Record<number, string> = {
1: 'ماهیانه',
2: 'سه ماهه',
3: 'شش ماهه',
4: 'سالیانه',
};
return type && types[type] ? types[type] : 'نامشخص';
};
export const getFullName = (user: User): string => {
if (user.full_name) return user.full_name;
const firstName = user.first_name || '';
const lastName = user.last_name || '';
if (firstName || lastName) {
return `${firstName} ${lastName}`.trim();
}
return 'نامشخص';
};
export const getEmail = (email: string | null): string => {
return email || 'ایمیل ثبت نشده';
};
export const getMobile = (mobile: string | null): string => {
return mobile || 'شماره موبایل ثبت نشده';
};