Merge pull request #32 from rkheftan/fix/enter

feat: add using enter instead pushing the button
This commit is contained in:
SajadMRjl
2025-09-14 11:59:13 +03:30
committed by GitHub
17 changed files with 674 additions and 558 deletions

2
.env
View File

@@ -1,6 +1,6 @@
VITE_GOOGLE_CLIENT_ID=https://272098283932-bft2gvlgjn8edopg0lnqjq1i9ekdmipt.apps.googleusercontent.com VITE_GOOGLE_CLIENT_ID=https://272098283932-bft2gvlgjn8edopg0lnqjq1i9ekdmipt.apps.googleusercontent.com
VITE_DEFUALT_AUTH_RETURN_URL=/setting/profile VITE_DEFUALT_AUTH_RETURN_URL=/setting/profile
VITE_APP_URL=https://account.business-harmony.com VITE_APP_URL=https://accounts.business-harmony.com
VITE_API_URL=https://accounts.business-harmony.com/api VITE_API_URL=https://accounts.business-harmony.com/api
VITE_IDENTITY_URL=https://accounts.business-harmony.com/connect/token VITE_IDENTITY_URL=https://accounts.business-harmony.com/connect/token
VITE_IDENTITY_CLIENT_ID=harmony_identity VITE_IDENTITY_CLIENT_ID=harmony_identity

View File

@@ -1,4 +1,4 @@
import { Button, TextField, Typography } from '@mui/material'; import { Box, Button, TextField, Typography } from '@mui/material';
import parsePhoneNumberFromString from 'libphonenumber-js'; import parsePhoneNumberFromString from 'libphonenumber-js';
import { useRef, useState, type Dispatch } from 'react'; import { useRef, useState, type Dispatch } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -78,6 +78,14 @@ export const CompleteSignUp = ({
return ( return (
<AuthenticationCard> <AuthenticationCard>
<Box
component="form"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!sendSmsLoading) void handleCompleteSignUp();
}}
>
<Typography variant="h5" sx={{ mb: 0.5 }}> <Typography variant="h5" sx={{ mb: 0.5 }}>
{t('completeSignUp.completeSignUp')} {t('completeSignUp.completeSignUp')}
</Typography> </Typography>
@@ -94,7 +102,7 @@ export const CompleteSignUp = ({
inputRef={inputRef} inputRef={inputRef}
label={t('completeSignUp.phoneNumber')} label={t('completeSignUp.phoneNumber')}
value={value} value={value}
onChange={handleChange} onChange={(e) => setValue(e.target.value)}
onBlur={handleBlur} onBlur={handleBlur}
error={inputError} error={inputError}
helperText={inputError ? error : ''} helperText={inputError ? error : ''}
@@ -116,9 +124,10 @@ export const CompleteSignUp = ({
sx={{ my: 4 }} sx={{ my: 4 }}
/> />
<Button loading={sendSmsLoading} onClick={handleCompleteSignUp}> <Button loading={sendSmsLoading} type="submit">
{t('verify.confirmAndContinue')} {t('verify.confirmAndContinue')}
</Button> </Button>
</Box>
</AuthenticationCard> </AuthenticationCard>
); );
}; };

View File

@@ -21,7 +21,6 @@ import {
import type { LoginResult, PasswordLoginRequest } from '../../types/userTypes'; import type { LoginResult, PasswordLoginRequest } from '../../types/userTypes';
import { Icon, useToast } from '@rkheftan/harmony-ui'; import { Icon, useToast } from '@rkheftan/harmony-ui';
import { useApi } from '@/hooks/useApi'; import { useApi } from '@/hooks/useApi';
import { useAuth } from '@/hooks/useAuth';
import { import {
generateTokenWithPassword, generateTokenWithPassword,
type GenerateTokenResponse, type GenerateTokenResponse,

View File

@@ -14,7 +14,6 @@ import {
generateTokenWithGoogle, generateTokenWithGoogle,
type GenerateTokenResponse, type GenerateTokenResponse,
} from '../../api/identityAPI'; } from '../../api/identityAPI';
import { useAuth } from '@/hooks/useAuth';
import type { AuthFactory } from '../../types/authTypes'; import type { AuthFactory } from '../../types/authTypes';
export interface GoogleAuthenticationProps { export interface GoogleAuthenticationProps {

View File

@@ -1,4 +1,4 @@
import { Button, Stack, TextField, Typography } from '@mui/material'; import { Button, Stack, TextField, Typography, Box } from '@mui/material';
import { useRef, useState, type Dispatch } from 'react'; import { useRef, useState, type Dispatch } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { isNumeric } from '@/utils/regexes/isNumeric'; import { isNumeric } from '@/utils/regexes/isNumeric';
@@ -124,6 +124,16 @@ export function LoginRegisterForm({
return ( return (
<AuthenticationCard> <AuthenticationCard>
<Box
component="form"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!userStatusLoading) {
void handleSubmit();
}
}}
>
<Stack spacing={1}> <Stack spacing={1}>
<Typography variant="h5">{t('loginForm.title')}</Typography> <Typography variant="h5">{t('loginForm.title')}</Typography>
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
@@ -159,7 +169,7 @@ export function LoginRegisterForm({
/> />
<Stack spacing={2}> <Stack spacing={2}>
<Button loading={userStatusLoading} onClick={handleSubmit}> <Button loading={userStatusLoading} type="submit">
{t('loginForm.submitButton')} {t('loginForm.submitButton')}
</Button> </Button>
@@ -169,6 +179,7 @@ export function LoginRegisterForm({
disabled={userStatusLoading} disabled={userStatusLoading}
/> />
</Stack> </Stack>
</Box>
</AuthenticationCard> </AuthenticationCard>
); );
} }

View File

@@ -18,7 +18,6 @@ import {
generateTokenWithOtp, generateTokenWithOtp,
type GenerateTokenResponse, type GenerateTokenResponse,
} from '../../api/identityAPI'; } from '../../api/identityAPI';
import { useAuth } from '@/hooks/useAuth';
interface OtpVerifyFormProps { interface OtpVerifyFormProps {
value: string; value: string;
@@ -165,6 +164,16 @@ export function OtpVerifyForm({
return ( return (
<Stack alignItems="center"> <Stack alignItems="center">
<AuthenticationCard> <AuthenticationCard>
<Box
component="form"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!loginSignUpLoading) {
void handleVerifyOTP();
}
}}
>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@@ -198,11 +207,12 @@ export function OtpVerifyForm({
onChange={(value) => setOtpCode(value)} onChange={(value) => setOtpCode(value)}
/> />
<Button onClick={handleVerifyOTP} loading={loginSignUpLoading}> <Button type="submit" loading={loginSignUpLoading}>
{authMode === 'register' {authMode === 'register'
? t('verify.confirmAndContinue') ? t('verify.confirmAndContinue')
: t('verify.confirmAndLogin')} : t('verify.confirmAndLogin')}
</Button> </Button>
</Box>
</AuthenticationCard> </AuthenticationCard>
<Stack <Stack

View File

@@ -95,6 +95,16 @@ export function VerifyPhoneNumber({
return ( return (
<Stack alignItems="center"> <Stack alignItems="center">
<AuthenticationCard> <AuthenticationCard>
<Box
component="form"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!confirmSmsOtpLoading) {
void handleVerifyOTP();
}
}}
>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@@ -130,9 +140,10 @@ export function VerifyPhoneNumber({
onChange={(value) => setOtpCode(value)} onChange={(value) => setOtpCode(value)}
/> />
<Button onClick={handleVerifyOTP} loading={confirmSmsOtpLoading}> <Button type="submit" loading={confirmSmsOtpLoading}>
{t('verify.confirmAndLogin')} {t('verify.confirmAndLogin')}
</Button> </Button>
</Box>
</AuthenticationCard> </AuthenticationCard>
<Stack <Stack

View File

@@ -115,6 +115,16 @@ export function ForgetPasswordOtp({
return ( return (
<Stack alignItems="center"> <Stack alignItems="center">
<AuthenticationCard> <AuthenticationCard>
<Box
component="form"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!confirmForgetPassCodeLoading) {
void handleVerifyOTP();
}
}}
>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
@@ -158,12 +168,10 @@ export function ForgetPasswordOtp({
onChange={(value) => setOtpCode(value)} onChange={(value) => setOtpCode(value)}
/> />
<Button <Button type="submit" loading={confirmForgetPassCodeLoading}>
onClick={handleVerifyOTP}
loading={confirmForgetPassCodeLoading}
>
{t('forgetPassword.confirm')} {t('forgetPassword.confirm')}
</Button> </Button>
</Box>
</AuthenticationCard> </AuthenticationCard>
<Stack <Stack

View File

@@ -11,7 +11,7 @@ import {
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { type SubmitProps } from '../../types/settingForm'; import { type SubmitProps } from '../../types/settingForm';
export function SubmitSection({ onSubmit, loading }: SubmitProps) { export function SubmitSection({ loading }: SubmitProps) {
const { t, i18n } = useTranslation('completionForm'); const { t, i18n } = useTranslation('completionForm');
const [openDialog, setOpenDialog] = useState(false); const [openDialog, setOpenDialog] = useState(false);
@@ -50,8 +50,9 @@ export function SubmitSection({ onSubmit, loading }: SubmitProps) {
<Button <Button
variant="contained" variant="contained"
onClick={onSubmit} type="submit"
disabled={loading} disabled={loading}
form="completionForm"
sx={{ sx={{
width: { xs: '100%', sm: '247px' }, width: { xs: '100%', sm: '247px' },
alignSelf: { xs: 'stretch', sm: 'center' }, alignSelf: { xs: 'stretch', sm: 'center' },

View File

@@ -388,6 +388,15 @@ export function UserCompletionPage() {
scrollbarGutter: 'stable both-edges', scrollbarGutter: 'stable both-edges',
}} }}
maxWidth="730px" maxWidth="730px"
>
<Box
component="form"
id="completionForm"
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
void handleSubmit();
}}
> >
<Box <Box
sx={{ sx={{
@@ -463,7 +472,8 @@ export function UserCompletionPage() {
handleBlur={handleBlur} handleBlur={handleBlur}
/> />
<SubmitSection onSubmit={handleSubmit} loading={isSubmitting} /> <SubmitSection loading={isSubmitting} />
</Box>
</Box> </Box>
</AuthenticationCard> </AuthenticationCard>
</FlexBox> </FlexBox>

View File

@@ -72,6 +72,5 @@ export interface PersonalInfoFieldsProps extends ValidationProps {
} }
export interface SubmitProps { export interface SubmitProps {
onSubmit: () => void;
loading: boolean; loading: boolean;
} }

View File

@@ -46,6 +46,12 @@ export function PasswordDialog({
const [showConfirm, setShowConfirm] = useState(false); const [showConfirm, setShowConfirm] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
const onFormSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();
e.stopPropagation();
if (!loading) handleSubmit();
};
return ( return (
<Dialog <Dialog
open={open} open={open}
@@ -69,6 +75,7 @@ export function PasswordDialog({
</Box> </Box>
</DialogTitle> </DialogTitle>
<Box component="form" onSubmit={onFormSubmit}>
<DialogContent <DialogContent
sx={{ sx={{
display: 'flex', display: 'flex',
@@ -89,7 +96,10 @@ export function PasswordDialog({
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton onClick={() => setShowCurrent(!showCurrent)}> <IconButton
onClick={() => setShowCurrent(!showCurrent)}
type="button"
>
<Icon Component={showCurrent ? Eye : EyeSlash} /> <Icon Component={showCurrent ? Eye : EyeSlash} />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
@@ -115,7 +125,10 @@ export function PasswordDialog({
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton onClick={() => setShowNew(!showNew)}> <IconButton
onClick={() => setShowNew(!showNew)}
type="button"
>
<Icon Component={showNew ? Eye : EyeSlash} /> <Icon Component={showNew ? Eye : EyeSlash} />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
@@ -160,7 +173,10 @@ export function PasswordDialog({
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton onClick={() => setShowConfirm(!showConfirm)}> <IconButton
onClick={() => setShowConfirm(!showConfirm)}
type="button"
>
<Icon Component={showConfirm ? Eye : EyeSlash} /> <Icon Component={showConfirm ? Eye : EyeSlash} />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
@@ -174,7 +190,8 @@ export function PasswordDialog({
fullWidth fullWidth
sx={{ height: 48, textTransform: 'none' }} sx={{ height: 48, textTransform: 'none' }}
variant="contained" variant="contained"
onClick={handleSubmit} type="submit"
disabled={loading}
> >
{loading ? ( {loading ? (
<CircularProgress size={24} color="inherit" /> <CircularProgress size={24} color="inherit" />
@@ -183,6 +200,7 @@ export function PasswordDialog({
)} )}
</Button> </Button>
</DialogActions> </DialogActions>
</Box>
</Dialog> </Dialog>
); );
} }

View File

@@ -14,7 +14,6 @@ import { useProfile } from '../../hooks/useProfile';
export function PersonalInformation() { export function PersonalInformation() {
const imageBaseUrl = import.meta.env.IMAGE_BASE_URL; const imageBaseUrl = import.meta.env.IMAGE_BASE_URL;
const { t } = useTranslation('setting'); const { t } = useTranslation('setting');
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const [uploadedImageUrl, setUploadedImageUrl] = useState<string | null>(null); const [uploadedImageUrl, setUploadedImageUrl] = useState<string | null>(null);
@@ -29,18 +28,14 @@ export function PersonalInformation() {
const [originalData, setOriginalData] = useState<InfoRowData | null>(null); const [originalData, setOriginalData] = useState<InfoRowData | null>(null);
const showToast = useToast(); const showToast = useToast();
const infoRowEditRef = useRef<{ validateFields: () => boolean }>(null); const infoRowEditRef = useRef<{ validateFields: () => boolean }>(null);
const { isLoadingProfile, refetchProfile } = useProfile(); const { isLoadingProfile, refetchProfile } = useProfile();
const { loading: isSavingProfile, execute: executeSaveProfile } = const { loading: isSavingProfile, execute: executeSaveProfile } =
useApi(saveProfile); useApi(saveProfile);
useEffect(() => { useEffect(() => {
const loadProfile = async () => { const loadProfile = async () => {
const profileData = await refetchProfile(); const profileData = await refetchProfile();
if (!profileData) return; if (!profileData) return;
if (profileData.success) { if (profileData.success) {
const fetchedData = { const fetchedData = {
firstName: profileData.firstName ?? '', firstName: profileData.firstName ?? '',
@@ -66,7 +61,6 @@ export function PersonalInformation() {
}); });
} }
}; };
loadProfile(); loadProfile();
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
@@ -85,14 +79,11 @@ export function PersonalInformation() {
if (!data) return; if (!data) return;
const isValid = infoRowEditRef.current?.validateFields?.(); const isValid = infoRowEditRef.current?.validateFields?.();
if (!isValid) return; if (!isValid) return;
const saveData = await executeSaveProfile({ const saveData = await executeSaveProfile({
data, data,
imageUrl: uploadedImageFile, imageUrl: uploadedImageFile,
}); });
if (!saveData) return; if (!saveData) return;
if (saveData?.success) { if (saveData?.success) {
showToast({ showToast({
message: t('settingForm.successSaveProfile'), message: t('settingForm.successSaveProfile'),
@@ -101,7 +92,6 @@ export function PersonalInformation() {
setIsEditing(false); setIsEditing(false);
setOriginalData(data); setOriginalData(data);
setUploadedImageFile(null); setUploadedImageFile(null);
// Force a refetch to update the cache with the new data
refetchProfile({ force: true }); refetchProfile({ force: true });
} else { } else {
showToast({ showToast({
@@ -122,6 +112,7 @@ export function PersonalInformation() {
{isEditing ? ( {isEditing ? (
<> <>
<Button <Button
type="button"
variant="text" variant="text"
onClick={handleCancelClick} onClick={handleCancelClick}
size="large" size="large"
@@ -134,9 +125,11 @@ export function PersonalInformation() {
{t('settingForm.rejectButton')} {t('settingForm.rejectButton')}
</Button> </Button>
<Button <Button
onClick={handleSaveClick} type="submit"
form="profileForm"
size="large" size="large"
variant="contained" variant="contained"
disabled={isSavingProfile}
sx={{ sx={{
textTransform: 'none', textTransform: 'none',
width: { xs: '100%', sm: 'auto' }, width: { xs: '100%', sm: 'auto' },
@@ -174,8 +167,16 @@ export function PersonalInformation() {
> >
<CircularProgress /> <CircularProgress />
</Box> </Box>
) : ( ) : isEditing ? (
<Box <Box
component="form"
id="profileForm"
noValidate
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!isSavingProfile) void handleSaveClick();
}}
sx={{ sx={{
mx: { xs: 2, sm: 3, md: 4 }, mx: { xs: 2, sm: 3, md: 4 },
py: 2, py: 2,
@@ -185,7 +186,6 @@ export function PersonalInformation() {
bgcolor: 'background.paper', bgcolor: 'background.paper',
}} }}
> >
{isEditing && (
<ProfileImage <ProfileImage
initials={initials} initials={initials}
uploadedImageUrl={uploadedImageUrl} uploadedImageUrl={uploadedImageUrl}
@@ -201,21 +201,24 @@ export function PersonalInformation() {
setUploadedImageUrl(null); setUploadedImageUrl(null);
}} }}
/> />
)} <InfoRowEdit ref={infoRowEditRef} data={data} setData={setData} />
{data && </Box>
(isEditing ? (
<InfoRowEdit
ref={infoRowEditRef}
data={data}
setData={setData}
/>
) : ( ) : (
<Box
sx={{
mx: { xs: 2, sm: 3, md: 4 },
py: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
bgcolor: 'background.paper',
}}
>
<InfoRowDisplay <InfoRowDisplay
data={data} data={data}
uploadedImageUrl={uploadedImageUrl} uploadedImageUrl={uploadedImageUrl}
initials={initials} initials={initials}
/> />
))}
</Box> </Box>
)} )}
</CardContainer> </CardContainer>

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'; import { useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import parsePhoneNumberFromString from 'libphonenumber-js'; import parsePhoneNumberFromString from 'libphonenumber-js';
import { PageWrapper } from '../PageWrapper'; import { PageWrapper } from '../PageWrapper';
@@ -40,20 +40,21 @@ export function PhoneNumber() {
const { loading: isSendingCode, execute: executeSendCode } = const { loading: isSendingCode, execute: executeSendCode } =
useApi(sendVerificationCode); useApi(sendVerificationCode);
const { loading: isVerifying, execute: executeConfirmCode } = useApi( const { loading: isVerifying, execute: executeConfirmCode } = useApi(
confirmPhoneNumberCode, confirmPhoneNumberCode,
); );
const { loading: isChangingPhone, execute: executeChangePhone } = const { loading: isChangingPhone, execute: executeChangePhone } =
useApi(changePhoneNumber); useApi(changePhoneNumber);
const isBusy = useMemo(
() => isVerifying || isSendingCode || isChangingPhone,
[isVerifying, isSendingCode, isChangingPhone],
);
useEffect(() => { useEffect(() => {
const loadProfile = async () => { const loadProfile = async () => {
const profileData = await refetchProfile(); const profileData = await refetchProfile();
if (!profileData) return; if (!profileData) return;
if (profileData?.success) { if (profileData?.success) {
setPhones([ setPhones([
{ {
@@ -69,36 +70,32 @@ export function PhoneNumber() {
}); });
} }
}; };
loadProfile(); void loadProfile();
// eslint-disable-next-line react-hooks/exhaustive-deps }, [refetchProfile, toast]);
}, []);
useEffect(() => { useEffect(() => {
if (!phoneNumberTouched) return;
if (!phoneNumber) { if (!phoneNumber) {
setPhoneNumberError(t('settingForm.thisFieldIsRequired')); setPhoneNumberError(t('settingForm.thisFieldIsRequired'));
return; return;
} }
if (!isPhoneValid(countryCode, phoneNumber)) { const parsed = parsePhoneNumberFromString(countryCode + phoneNumber);
const valid = Boolean(parsed?.isValid());
if (!valid) {
setPhoneNumberError(t('settingForm.phoneNumberIsInvalid')); setPhoneNumberError(t('settingForm.phoneNumberIsInvalid'));
} else { } else {
setPhoneNumberError(undefined); setPhoneNumberError(undefined);
} }
// eslint-disable-next-line react-hooks/exhaustive-deps }, [countryCode, phoneNumber, phoneNumberTouched, t]);
}, [countryCode, phoneNumber, phoneNumberTouched]);
useEffect(() => { useEffect(() => {
if (!verificationCodeTouched) return;
if (!verificationCode) { if (!verificationCode) {
setVerificationCodeError(t('settingForm.verificationCodeRequired')); setVerificationCodeError(t('settingForm.verificationCodeRequired'));
return; return;
} }
setVerificationCodeError(undefined); setVerificationCodeError(undefined);
// eslint-disable-next-line react-hooks/exhaustive-deps }, [verificationCode, verificationCodeTouched, t]);
}, [verificationCode, verificationCodeTouched]);
const isPhoneValid = (code: string, phone: string) => {
const phoneNum = parsePhoneNumberFromString(code + phone);
return phoneNum?.isValid();
};
const handleBlur = (key: string) => { const handleBlur = (key: string) => {
if (key === 'phoneNumber') { if (key === 'phoneNumber') {
@@ -126,14 +123,11 @@ export function PhoneNumber() {
const handleSendCode = async () => { const handleSendCode = async () => {
setPhoneNumberTouched(true); setPhoneNumberTouched(true);
if (phoneNumberError) return; if (!phoneNumber || phoneNumberError) return;
const result = await executeSendCode({ const result = await executeSendCode({
phoneNumber: countryCode + phoneNumber.replace(/^0/, ''), phoneNumber: countryCode + phoneNumber.replace(/^0/, ''),
}); });
if (!result) return; if (!result) return;
if (result?.success) { if (result?.success) {
setButtonState('counting'); setButtonState('counting');
setIsVerified(false); setIsVerified(false);
@@ -151,18 +145,13 @@ export function PhoneNumber() {
const handleVerifyCode = async () => { const handleVerifyCode = async () => {
setVerificationCodeTouched(true); setVerificationCodeTouched(true);
if (!verificationCode || verificationCodeError) return;
if (verificationCodeError) return;
const fullPhoneNumber = countryCode + phoneNumber.replace(/^0/, ''); const fullPhoneNumber = countryCode + phoneNumber.replace(/^0/, '');
const confirmResult = await executeConfirmCode({ const confirmResult = await executeConfirmCode({
phoneNumber: fullPhoneNumber, phoneNumber: fullPhoneNumber,
verifyCode: verificationCode, verifyCode: verificationCode,
}); });
if (!confirmResult) return; if (!confirmResult) return;
if (!confirmResult.success || !confirmResult.confirm) { if (!confirmResult.success || !confirmResult.confirm) {
toast({ toast({
message: confirmResult?.message || t('message.serverError'), message: confirmResult?.message || t('message.serverError'),
@@ -170,19 +159,15 @@ export function PhoneNumber() {
}); });
return; return;
} }
setIsVerified(true); setIsVerified(true);
toast({ toast({
message: t('settingForm.phoneVerified'), message: t('settingForm.phoneVerified'),
severity: 'success', severity: 'success',
}); });
const changeResult = await executeChangePhone({ const changeResult = await executeChangePhone({
phoneNumber: fullPhoneNumber, phoneNumber: fullPhoneNumber,
}); });
if (!changeResult) return; if (!changeResult) return;
if (changeResult?.success) { if (changeResult?.success) {
setPhones([ setPhones([
{ {
@@ -212,6 +197,8 @@ export function PhoneNumber() {
isEditing={isEditing} isEditing={isEditing}
toggleEdit={toggleEdit} toggleEdit={toggleEdit}
t={t} t={t}
formId="phoneForm"
isSubmitting={isBusy}
/> />
} }
> >
@@ -228,6 +215,16 @@ export function PhoneNumber() {
<CircularProgress /> <CircularProgress />
</Box> </Box>
) : isEditing ? ( ) : isEditing ? (
<Box
component="form"
id="phoneForm"
noValidate
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
if (!isBusy) void handleVerifyCode();
}}
>
<PhoneEditForm <PhoneEditForm
phoneNumber={phoneNumber} phoneNumber={phoneNumber}
setPhoneNumber={setPhoneNumber} setPhoneNumber={setPhoneNumber}
@@ -236,19 +233,22 @@ export function PhoneNumber() {
verificationCode={verificationCode} verificationCode={verificationCode}
setVerificationCode={setVerificationCode} setVerificationCode={setVerificationCode}
isVerified={isVerified} isVerified={isVerified}
isVerifying={isVerifying || isSendingCode || isChangingPhone} isVerifying={isBusy}
isSendingCode={isSendingCode} isSendingCode={isSendingCode}
buttonState={buttonState} buttonState={buttonState}
setButtonState={setButtonState} setButtonState={setButtonState}
handleSendCode={handleSendCode} handleSendCode={handleSendCode}
handleVerifyClick={handleVerifyCode} handleVerifyClick={handleVerifyCode}
phoneNumberError={phoneNumberTouched ? phoneNumberError : undefined} phoneNumberError={
phoneNumberTouched ? phoneNumberError : undefined
}
verificationCodeError={ verificationCodeError={
verificationCodeTouched ? verificationCodeError : undefined verificationCodeTouched ? verificationCodeError : undefined
} }
handleBlur={handleBlur} handleBlur={handleBlur}
phones={phones} phones={phones}
/> />
</Box>
) : ( ) : (
<PhoneDisplay <PhoneDisplay
phones={phones.map((p) => { phones={phones.map((p) => {

View File

@@ -8,8 +8,10 @@ export default function PhoneActionButtons({
}: PhoneActionButtonsProps) { }: PhoneActionButtonsProps) {
return ( return (
<Box sx={{ display: 'flex', gap: 1 }}> <Box sx={{ display: 'flex', gap: 1 }}>
{isEditing && ( {isEditing ? (
<>
<Button <Button
type="button"
variant="text" variant="text"
onClick={toggleEdit} onClick={toggleEdit}
size="large" size="large"
@@ -21,23 +23,36 @@ export default function PhoneActionButtons({
> >
{t('settingForm.rejectButton')} {t('settingForm.rejectButton')}
</Button> </Button>
)} <Button
type="submit"
form="phoneForm"
size="large"
variant="outlined"
sx={{
borderRadius: 1,
bgcolor: 'primary.main',
color: 'primary.contrastText',
whiteSpace: 'nowrap',
textTransform: 'none',
}}
>
{t('settingForm.saveButton')}
</Button>
</>
) : (
<Button <Button
onClick={toggleEdit} onClick={toggleEdit}
size="large" size="large"
variant="outlined" variant="outlined"
sx={{ sx={{
borderRadius: 1, borderRadius: 1,
bgcolor: isEditing ? 'primary.main' : 'background.default',
color: isEditing ? 'primary.contrastText' : 'primary.main',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
textTransform: 'none', textTransform: 'none',
}} }}
> >
{isEditing {t('settingForm.editPhoneNumber')}
? t('settingForm.saveButton')
: t('settingForm.editPhoneNumber')}
</Button> </Button>
)}
</Box> </Box>
); );
} }

View File

@@ -54,6 +54,21 @@ export default function SocialMediaDialog({
return true; return true;
}; };
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();
e.stopPropagation();
if (isLoading) return;
if (dialogStep === 'enterEmail') {
setTouched(true);
if (!validateEmail(emailInput)) return;
onSendCode();
} else {
onConfirmEmail();
}
};
return ( return (
<Dialog <Dialog
open={open} open={open}
@@ -77,6 +92,7 @@ export default function SocialMediaDialog({
</Box> </Box>
</DialogTitle> </DialogTitle>
<Box component="form" onSubmit={handleSubmit}>
<DialogContent <DialogContent
sx={{ sx={{
display: 'flex', display: 'flex',
@@ -86,7 +102,9 @@ export default function SocialMediaDialog({
}} }}
> >
<Box> <Box>
<Typography fontWeight="bold">{t('settingForm.newEmail')}</Typography> <Typography fontWeight="bold">
{t('settingForm.newEmail')}
</Typography>
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
{t('settingForm.dialogHeader')} {t('settingForm.dialogHeader')}
</Typography> </Typography>
@@ -109,7 +127,7 @@ export default function SocialMediaDialog({
autoComplete="email" autoComplete="email"
inputMode="email" inputMode="email"
sx={{ '& .MuiOutlinedInput-root': { borderRadius: 2 }, mt: 2 }} sx={{ '& .MuiOutlinedInput-root': { borderRadius: 2 }, mt: 2 }}
autoFocus autoFocus={dialogStep === 'enterEmail'}
disabled={isLoading || dialogStep === 'enterCode'} disabled={isLoading || dialogStep === 'enterCode'}
error={touched && !!emailError} error={touched && !!emailError}
helperText={touched && emailError ? emailError : ' '} helperText={touched && emailError ? emailError : ' '}
@@ -136,8 +154,8 @@ export default function SocialMediaDialog({
fullWidth fullWidth
sx={{ height: 48, textTransform: 'none', borderRadius: 2 }} sx={{ height: 48, textTransform: 'none', borderRadius: 2 }}
variant="contained" variant="contained"
type="submit"
disabled={isLoading || (dialogStep === 'enterEmail' && !emailInput)} disabled={isLoading || (dialogStep === 'enterEmail' && !emailInput)}
onClick={dialogStep === 'enterEmail' ? onSendCode : onConfirmEmail}
> >
{isLoading ? ( {isLoading ? (
<CircularProgress size={24} color="inherit" /> <CircularProgress size={24} color="inherit" />
@@ -148,6 +166,7 @@ export default function SocialMediaDialog({
)} )}
</Button> </Button>
</Box> </Box>
</Box>
</Dialog> </Dialog>
); );
} }

View File

@@ -1,3 +1,5 @@
import type { TFunction } from 'i18next';
export enum Gender { export enum Gender {
Male = 2, Male = 2,
Female = 1, Female = 1,
@@ -93,7 +95,9 @@ export interface EmailAccount {
export interface PhoneActionButtonsProps { export interface PhoneActionButtonsProps {
isEditing: boolean; isEditing: boolean;
toggleEdit: () => void; toggleEdit: () => void;
t: (key: string) => string; t: TFunction<'setting'>;
formId?: string;
isSubmitting?: boolean;
} }
export interface PhoneDisplayProps { export interface PhoneDisplayProps {