feat(calendar): add year picker functionality to PersianDatePicker and PersianCalendar
This commit is contained in:
@@ -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' }}
|
||||
/>
|
||||
<input
|
||||
type="text" dir="ltr" value={birthDate} placeholder="تاریخ تولد ۱۳۷۰/۰۱/۰۱"
|
||||
onChange={(e) => 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' }}
|
||||
<PersianDatePicker
|
||||
value={birthDate}
|
||||
onChange={setBirthDate}
|
||||
placeholder="تاریخ تولد"
|
||||
height={38}
|
||||
minWidth={170}
|
||||
enableYearPicker
|
||||
/>
|
||||
<button className="btn primary" onClick={submitIban} disabled={addIbanMut.isPending} style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}>
|
||||
<PlusIcon style={{ width: 16, height: 16 }} />
|
||||
|
||||
Reference in New Issue
Block a user