Add activity detail, Jalali pickers, and customer/user profiles.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-02 21:29:00 +03:30
co-authored by Cursor
parent 574feedfa5
commit f884c60cab
39 changed files with 8255 additions and 441 deletions
+84
View File
@@ -176,13 +176,97 @@ export function formatJalaliShort(d: Date): string {
return `${weekdayName(d)} ${toFaDigits(jd)} ${jalaliMonthName(jm)}`;
}
/** مثل: ۸ شهریور ۱۴۰۵ */
export function formatJalaliDay(d: Date): string {
const { jy, jm, jd } = dateToJalali(d);
return `${toFaDigits(jd)} ${jalaliMonthName(jm)} ${toFaDigits(jy)}`;
}
export function toFaDigits(value: number | string): string {
return String(value).replace(/\d/g, (d) => '۰۱۲۳۴۵۶۷۸۹'[Number(d)]!);
}
export function startOfLocalDay(d = new Date()): Date {
const x = new Date(d);
x.setHours(0, 0, 0, 0);
return x;
}
export function formatClockFa(d: Date): string {
const hh = String(d.getHours()).padStart(2, '0');
const mm = String(d.getMinutes()).padStart(2, '0');
return `${toFaDigits(hh)}:${toFaDigits(mm)}`;
}
/** مثل: ۲۴ مرداد ۱۱:۲۰ */
export function formatJalaliDayClock(d: Date): string {
const { jm, jd } = dateToJalali(d);
return `${toFaDigits(jd)} ${jalaliMonthName(jm)} ${formatClockFa(d)}`;
}
export function calendarDaysBetween(from: Date, to: Date): number {
return Math.round(
(startOfLocalDay(to).getTime() - startOfLocalDay(from).getTime()) / 86_400_000,
);
}
/** آخرین ارتباط: امروز ۱۶:۳۰ / ۶ روز پیش */
export function formatRelativeContact(iso: string | null | undefined): string {
if (!iso) return '—';
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return '—';
const days = calendarDaysBetween(d, new Date());
if (days <= 0) return `امروز ${formatClockFa(d)}`;
if (days === 1) return 'دیروز';
return `${toFaDigits(days)} روز پیش`;
}
/** فعالیت بعدی: امروز ۱۶:۳۰ / فردا ۱۰:۰۰ / ۲۴ مرداد ۱۱:۲۰ */
export function formatNextSlot(iso: string | null | undefined): string {
if (!iso) return '—';
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return '—';
const days = calendarDaysBetween(new Date(), d);
if (days === 0) return `امروز ${formatClockFa(d)}`;
if (days === 1) return `فردا ${formatClockFa(d)}`;
if (days === -1) return `دیروز ${formatClockFa(d)}`;
return formatJalaliDayClock(d);
}
export function gregorianDayKey(d: Date): string {
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return `${y}-${m}-${day}`;
}
export function parseLocalInput(value: string | null | undefined): Date | null {
if (!value) return null;
const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?/.exec(value);
if (match) {
return new Date(
Number(match[1]),
Number(match[2]) - 1,
Number(match[3]),
match[4] ? Number(match[4]) : 0,
match[5] ? Number(match[5]) : 0,
);
}
const parsed = new Date(value);
return Number.isNaN(parsed.getTime()) ? null : parsed;
}
export function formatLocalDateInput(d: Date): string {
return gregorianDayKey(d);
}
export function formatLocalDateTimeInput(d: Date): string {
const pad = (n: number) => String(n).padStart(2, '0');
return `${gregorianDayKey(d)}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
}
/** مثل: ۱۴۰۵/۰۶/۱۲ */
export function formatJalaliNumeric(d: Date): string {
const { jy, jm, jd } = dateToJalali(d);
return `${toFaDigits(jy)}/${toFaDigits(String(jm).padStart(2, '0'))}/${toFaDigits(String(jd).padStart(2, '0'))}`;
}