diff --git a/src/features/authentication/components/DateOfBirth.tsx b/src/features/authentication/components/DateOfBirth.tsx
index 7f0b0e7..9ac94a0 100644
--- a/src/features/authentication/components/DateOfBirth.tsx
+++ b/src/features/authentication/components/DateOfBirth.tsx
@@ -1,28 +1,74 @@
import { useMemo } from 'react';
-import { DatePicker } from '@mui/x-date-pickers/DatePicker';
+import {
+ DatePicker,
+ PickersDay,
+ type PickersDayProps,
+} from '@mui/x-date-pickers';
import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali';
+import { enUS } from 'date-fns/locale';
+import { faIR as faIRJalali } from 'date-fns-jalali/locale';
+import { getDay } from 'date-fns-jalali';
+import { format as formatJalali } from 'date-fns-jalali';
+import { format } from 'date-fns';
+
import { useTranslation } from 'react-i18next';
interface DateOfBirthProps {
value: Date | null;
onChange: (date: Date | null) => void;
}
-export function DateOfBirth({ value, onChange }: DateOfBirthProps) {
+
+const toPersianDigits = (str: string) =>
+ str.replace(/\d/g, (d) => '۰۱۲۳۴۵۶۷۸۹'[+d]);
+
+export default function DateOfBirth({ value, onChange }: DateOfBirthProps) {
const { t, i18n } = useTranslation('completionForm');
const isFarsi = i18n.language === 'fa' || i18n.language === 'fa-IR';
- const Adapter = useMemo(() => {
- return isFarsi ? AdapterDateFnsJalali : AdapterDateFns;
+ const { Adapter, locale, formatString, dayOfWeekFormatter } = useMemo(() => {
+ if (isFarsi) {
+ const persianDays = ['ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش'];
+ return {
+ Adapter: AdapterDateFnsJalali,
+ locale: faIRJalali,
+ formatString: 'yyyy/MM/dd',
+ dayOfWeekFormatter: (date: Date) => persianDays[getDay(date)],
+ };
+ }
+ return {
+ Adapter: AdapterDateFns,
+ locale: enUS,
+ formatString: 'MM/dd/yyyy',
+ dayOfWeekFormatter: undefined,
+ };
}, [isFarsi]);
+ const CustomDay = (props: PickersDayProps) => {
+ const dayNumber = isFarsi
+ ? formatJalali(props.day, 'dd')
+ : format(props.day, 'dd');
+ return (
+
+ {isFarsi ? toPersianDigits(dayNumber) : dayNumber}
+
+ );
+ };
+
return (
-
+
{isVerifyingCode ? (
-
-
-
+
) : (
t('completion.checkCodeButton')
)}
diff --git a/src/features/authentication/components/PersonalInfoFields.tsx b/src/features/authentication/components/PersonalInfoFields.tsx
index 7ee8a46..f3d2c66 100644
--- a/src/features/authentication/components/PersonalInfoFields.tsx
+++ b/src/features/authentication/components/PersonalInfoFields.tsx
@@ -6,12 +6,19 @@ import {
Select,
Box,
Autocomplete,
+ type SelectChangeEvent,
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import { Woman, Man } from 'iconsax-react';
import { useState, type Dispatch, type SetStateAction } from 'react';
-import { DateOfBirth } from './DateOfBirth';
import { countries } from '../data/Countries';
+import DateOfBirth from './DateOfBirth';
+
+interface CountryType {
+ name: string;
+ fa: string;
+ flag: string;
+}
interface PersonalInfoFieldsProps {
firstName: string;
@@ -45,22 +52,37 @@ export function PersonalInfoFields({
const { t } = useTranslation('completionForm');
const [countryError, setCountryError] = useState(false);
- const handleChangeSex = (e: any) => {
+ // Language check to pass down for date picker
+ // const isFarsi = i18n.language === 'fa' || i18n.language === 'fa-IR';
+
+ const handleChangeSex = (e: SelectChangeEvent<'male' | 'female'>) => {
setSex(e.target.value as 'female' | 'male');
};
- const handleChangeCountry = (_: any, newValue: any) => {
- setCountry(newValue ? newValue.name : '');
- setCountryError(false);
+ const handleChangeCountry = (
+ _: React.SyntheticEvent,
+ newValue: string | CountryType | null,
+ ) => {
+ if (typeof newValue === 'string') {
+ setCountry(newValue);
+ setCountryError(false);
+ } else if (newValue === null) {
+ setCountry('');
+ setCountryError(false);
+ } else {
+ setCountry(newValue.name);
+ setCountryError(false);
+ }
};
const handleCountryBlur = (e: React.FocusEvent) => {
const inputValue = e.target.value.trim();
+ // Check if input matches any country's fa name
const exists = countries.some((c) => c.fa === inputValue);
setCountryError(Boolean(inputValue && !exists));
};
- const handleInputChange = (_: any, value: string) => {
+ const handleInputChange = (_: React.SyntheticEvent, value: string) => {
const exists = countries.some((c) => c.fa === value.trim());
setCountryError(Boolean(value.trim() && !exists));
};