diff --git a/assets/admin/components/ui/PersianCalendar.tsx b/assets/admin/components/ui/PersianCalendar.tsx index 8a60b6a0..1c5da859 100644 --- a/assets/admin/components/ui/PersianCalendar.tsx +++ b/assets/admin/components/ui/PersianCalendar.tsx @@ -5,6 +5,8 @@ interface Props { value: string; // YYYY-MM-DD Gregorian onChange: (v: string) => void; onClose: () => void; + /** انتخاب سال→ماه→روز را فعال می‌کند (پیش‌فرض خاموش — مناسب تاریخ تولد). */ + enableYearPicker?: boolean; } const WEEK_DAYS = ['ش', 'ی', 'د', 'س', 'چ', 'پ', 'ج']; @@ -65,7 +67,7 @@ function jalaliToGregorian(jy: number, jm: number, jd: number): string { const JALALI_MONTHS = ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند']; -export default function PersianCalendar({ value, onChange, onClose }: Props) { +export default function PersianCalendar({ value, onChange, onClose, enableYearPicker = false }: Props) { const ref = useRef(null); const todayGreg = new Date().toISOString().slice(0, 10); @@ -74,6 +76,11 @@ export default function PersianCalendar({ value, onChange, onClose }: Props) { const [viewYear, setViewYear] = useState(valueJ.year); const [viewMonth, setViewMonth] = useState(valueJ.month); + const [mode, setMode] = useState<'day' | 'month' | 'year'>('day'); + // ابتدای بازه‌ی ۱۲تایی سال در نمای انتخاب سال + const [yearRangeStart, setYearRangeStart] = useState(valueJ.year - (valueJ.year % 12)); + + const faYear = (y: number) => y.toLocaleString('fa-IR', { useGrouping: false }); useEffect(() => { function handler(e: MouseEvent) { @@ -119,52 +126,122 @@ export default function PersianCalendar({ value, onChange, onClose }: Props) { }}> {/* Header */}
- - - {JALALI_MONTHS[viewMonth - 1]} {viewYear.toLocaleString('fa-IR')} - -
- {/* Week day headers */} -
- {WEEK_DAYS.map(d => ( -
- {d} + {/* Day view */} + {mode === 'day' && ( + <> +
+ {WEEK_DAYS.map(d => ( +
+ {d} +
+ ))}
- ))} -
+
+ {cells.map((day, i) => { + if (!day) return
; + const sel = isSelected(day); + const tod = isToday(day) && !sel; + return ( + + ); + })} +
+ + )} - {/* Days grid */} -
- {cells.map((day, i) => { - if (!day) return
; - const sel = isSelected(day); - const tod = isToday(day) && !sel; - return ( - - ); - })} -
+ {/* Month view */} + {mode === 'month' && ( +
+ {JALALI_MONTHS.map((mName, idx) => { + const m = idx + 1; + const active = m === viewMonth; + return ( + + ); + })} +
+ )} + + {/* Year view */} + {mode === 'year' && ( +
+ {Array.from({ length: 12 }, (_, i) => yearRangeStart + i).map(y => { + const active = y === viewYear; + return ( + + ); + })} +
+ )}
); } @@ -174,3 +251,9 @@ const navBtnStyle: React.CSSProperties = { color: 'var(--text-2)', padding: 4, borderRadius: 'var(--r-sm)', display: 'flex', alignItems: 'center', }; + +const gridItemStyle: React.CSSProperties = { + height: 40, borderRadius: 'var(--r-sm)', fontSize: 13, fontWeight: 500, + border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', + transition: 'background 0.1s', +}; diff --git a/assets/admin/components/ui/PersianDatePicker.tsx b/assets/admin/components/ui/PersianDatePicker.tsx index a18e2c3d..75972f74 100644 --- a/assets/admin/components/ui/PersianDatePicker.tsx +++ b/assets/admin/components/ui/PersianDatePicker.tsx @@ -9,9 +9,11 @@ interface Props { placeholder?: string; height?: number; minWidth?: number; + /** انتخاب سال→ماه→روز را فعال می‌کند (پیش‌فرض خاموش). */ + enableYearPicker?: boolean; } -export default function PersianDatePicker({ value, onChange, placeholder = 'انتخاب تاریخ', height = 38, minWidth = 148 }: Props) { +export default function PersianDatePicker({ value, onChange, placeholder = 'انتخاب تاریخ', height = 38, minWidth = 148, enableYearPicker = false }: Props) { const [open, setOpen] = useState(false); return ( @@ -43,6 +45,7 @@ export default function PersianDatePicker({ value, onChange, placeholder = 'ان value={value} onChange={(v) => { onChange(v); setOpen(false); }} onClose={() => setOpen(false)} + enableYearPicker={enableYearPicker} /> )}
diff --git a/assets/admin/pages/RepresentationProfilePage.tsx b/assets/admin/pages/RepresentationProfilePage.tsx index 155dcdbe..2b3652d6 100644 --- a/assets/admin/pages/RepresentationProfilePage.tsx +++ b/assets/admin/pages/RepresentationProfilePage.tsx @@ -4,6 +4,18 @@ import { toast } from 'sonner'; import { CheckBadgeIcon, TrashIcon, PlusIcon } from '@heroicons/react/24/outline'; import { api } from '../lib/api'; import type { ApiResponse } from '../lib/api'; +import PersianDatePicker from '../components/ui/PersianDatePicker'; + +// تبدیل تاریخ میلادی ISO (YYYY-MM-DD) به شمسی Y/m/d برای استعلام api.ir +function toJalali(iso: string): string { + if (!iso) return ''; + const parts = new Intl.DateTimeFormat('en-US-u-ca-persian-nu-latn', { + year: 'numeric', month: '2-digit', day: '2-digit', + }).formatToParts(new Date(iso + 'T00:00:00')); + const get = (t: string) => parts.find(p => p.type === t)?.value ?? ''; + const y = get('year'), m = get('month'), d = get('day'); + return y && m && d ? `${y}/${m}/${d}` : ''; +} interface IbanItem { id: string; @@ -81,10 +93,9 @@ export default function RepresentationProfilePage() { const submitIban = () => { if (!iban.trim()) { toast.error('شماره شبا را وارد کنید'); return; } - if (!/^\d{4}[\/\-.]\d{1,2}[\/\-.]\d{1,2}$/.test(birthDate.trim())) { - toast.error('تاریخ تولد را به صورت 1370/01/01 وارد کنید'); return; - } - addIbanMut.mutate({ iban: iban.trim(), birth_date: birthDate.trim() }); + const jalali = toJalali(birthDate); + if (!jalali) { toast.error('تاریخ تولد را انتخاب کنید'); return; } + addIbanMut.mutate({ iban: iban.trim(), birth_date: jalali }); }; return ( @@ -171,10 +182,13 @@ export default function RepresentationProfilePage() { onChange={(e) => setIban(e.target.value)} style={{ width: 320, height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box', fontFamily: 'monospace' }} /> - setBirthDate(e.target.value)} - style={{ width: 180, height: 38, padding: '0 12px', borderRadius: 'var(--r-sm)', border: '1px solid var(--border)', background: 'var(--surface)', color: 'var(--text)', fontSize: 13, boxSizing: 'border-box', textAlign: 'center' }} +