fix: phone number disable state in profile

This commit is contained in:
Sajad Mirjalili
2025-09-26 12:32:50 +03:30
parent 3d2e5ff0e6
commit 3a31313358
3 changed files with 53 additions and 25 deletions

View File

@@ -23,7 +23,7 @@
"woman": "Female", "woman": "Female",
"genderPlaceholder": "Male", "genderPlaceholder": "Male",
"newPhoneNumber": "New phone number", "newPhoneNumber": "New phone number",
"verificationCodeButton": "Send verification code", "verificationCodeButton": "Send code",
"verificationCode": "Verification code", "verificationCode": "Verification code",
"checkCode": "Check code", "checkCode": "Check code",
"successButton": "Confirmed", "successButton": "Confirmed",

View File

@@ -23,6 +23,7 @@ interface CountryCodeSelectorProps {
onChange: (newValue: CountryCode) => void; onChange: (newValue: CountryCode) => void;
menuAnchor: HTMLElement | null; menuAnchor: HTMLElement | null;
onCloseFocusRef: RefObject<HTMLInputElement | null>; onCloseFocusRef: RefObject<HTMLInputElement | null>;
disabled?: boolean;
} }
/** /**
@@ -35,6 +36,7 @@ export function CountryCodeSelector({
onChange, onChange,
menuAnchor, menuAnchor,
onCloseFocusRef, onCloseFocusRef,
disabled = false,
}: CountryCodeSelectorProps) { }: CountryCodeSelectorProps) {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [searchTerm, setSearchTerm] = useState(''); const [searchTerm, setSearchTerm] = useState('');
@@ -47,6 +49,7 @@ export function CountryCodeSelector({
countries.find((c) => c.phone === value) || countries[0]; countries.find((c) => c.phone === value) || countries[0];
const handleClick = () => { const handleClick = () => {
if (disabled) return;
setAnchorEl(menuAnchor); setAnchorEl(menuAnchor);
}; };
@@ -112,14 +115,22 @@ export function CountryCodeSelector({
pl: show ? 0.25 : 0, pl: show ? 0.25 : 0,
'&:hover': { '&:hover': {
cursor: 'pointer', cursor: disabled ? 'default' : 'pointer',
}, },
}} }}
> >
{/* This inner Box prevents the content from being squeezed during the transition */} {/* This inner Box prevents the content from being squeezed during the transition */}
<Icon Component={ArrowDown2} size="medium" variant="Bold" /> <Icon
Component={ArrowDown2}
color={disabled ? 'text.disabled' : undefined}
size="medium"
variant="Bold"
/>
<LTRTypography variant="body1" color="text.primary"> <LTRTypography
variant="body1"
color={disabled ? 'text.disabled' : 'text.primary'}
>
{value} {value}
</LTRTypography> </LTRTypography>
@@ -131,6 +142,7 @@ export function CountryCodeSelector({
width: '1.5rem', width: '1.5rem',
marginTop: '-2px', marginTop: '-2px',
marginRight: '4px', marginRight: '4px',
opacity: disabled ? 0.4 : 1,
}} }}
/> />

View File

@@ -37,7 +37,7 @@ export default function PhoneEditForm({
phoneNumberError, phoneNumberError,
verificationCodeError, verificationCodeError,
}: PhoneEditFormProps) { }: PhoneEditFormProps) {
const { t } = useTranslation('setting'); const { t, i18n } = useTranslation('setting');
const textFieldRef = useRef<HTMLDivElement>(null); const textFieldRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
@@ -72,6 +72,7 @@ export default function PhoneEditForm({
fullWidth fullWidth
name="phoneNumber" name="phoneNumber"
label={t('settingForm.newPhoneNumber')} label={t('settingForm.newPhoneNumber')}
disabled={isCodeSent}
type="tel" type="tel"
value={phoneNumber} value={phoneNumber}
ref={textFieldRef} ref={textFieldRef}
@@ -81,7 +82,8 @@ export default function PhoneEditForm({
helperText={phoneNumberError} helperText={phoneNumberError}
onChange={(e) => setPhoneNumber(e.target.value)} onChange={(e) => setPhoneNumber(e.target.value)}
placeholder="09123456789" placeholder="09123456789"
InputProps={{ slotProps={{
input: {
endAdornment: endAdornment:
buttonState === 'counting' ? ( buttonState === 'counting' ? (
<InputAdornment position="end"> <InputAdornment position="end">
@@ -102,14 +104,28 @@ export default function PhoneEditForm({
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
) : ( ) : (
i18n.dir() === 'rtl' && (
<CountryCodeSelector <CountryCodeSelector
value={countryCode} value={countryCode}
onChange={setCountryCode} onChange={setCountryCode}
show={true} show={true}
disabled={isCodeSent}
menuAnchor={textFieldRef.current}
onCloseFocusRef={inputRef}
/>
)
),
startAdornment: i18n.dir() === 'ltr' && (
<CountryCodeSelector
value={countryCode}
onChange={setCountryCode}
disabled={isCodeSent}
show={true}
menuAnchor={textFieldRef.current} menuAnchor={textFieldRef.current}
onCloseFocusRef={inputRef} onCloseFocusRef={inputRef}
/> />
), ),
},
}} }}
/> />