fix: styles
This commit is contained in:
@@ -26,7 +26,7 @@ export function CountryFlag({ code }: CountryFlagProps) {
|
|||||||
alt={displayName}
|
alt={displayName}
|
||||||
width="24"
|
width="24"
|
||||||
height="16"
|
height="16"
|
||||||
style={{ borderRadius: '2px', border: '1px solid #ccc' }}
|
style={{ borderRadius: 0.25, border: '1px solid' }}
|
||||||
/>
|
/>
|
||||||
<Typography variant="body2">{displayName}</Typography>
|
<Typography variant="body2">{displayName}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
44
src/features/authentication/api/types.ts
Normal file
44
src/features/authentication/api/types.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
export interface TokenRequestPayload {
|
||||||
|
grant_type: 'password';
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
client_id: string;
|
||||||
|
scope: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TokenApiResponse {
|
||||||
|
access_token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GenericApiResponse {
|
||||||
|
success: boolean;
|
||||||
|
message: string;
|
||||||
|
errorCode?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SendEmailOtpPayload {
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfirmEmailOtpPayload {
|
||||||
|
email: string;
|
||||||
|
otpCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CompleteUserInfoPayload {
|
||||||
|
userId: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
gender: 0 | 1 | 2;
|
||||||
|
nationalId: string;
|
||||||
|
birthDate: Date | null;
|
||||||
|
country: string;
|
||||||
|
savePassword?: boolean;
|
||||||
|
password?: string;
|
||||||
|
saveEmail?: boolean;
|
||||||
|
email?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CompleteUserInfoResponse extends GenericApiResponse {
|
||||||
|
validations: { property: string; message: string }[] | null;
|
||||||
|
}
|
||||||
56
src/features/authentication/api/userCompletion.ts
Normal file
56
src/features/authentication/api/userCompletion.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import {
|
||||||
|
type SendEmailOtpPayload,
|
||||||
|
type TokenApiResponse,
|
||||||
|
type ConfirmEmailOtpPayload,
|
||||||
|
type CompleteUserInfoPayload,
|
||||||
|
type CompleteUserInfoResponse,
|
||||||
|
type GenericApiResponse,
|
||||||
|
} from './types';
|
||||||
|
import axios from 'axios';
|
||||||
|
import apiClient from '@/lib/apiClient';
|
||||||
|
|
||||||
|
const AUTH_API_URL = 'https://accounts.business-harmony.com';
|
||||||
|
|
||||||
|
export const getTokenApi = async (): Promise<TokenApiResponse> => {
|
||||||
|
const body = new URLSearchParams();
|
||||||
|
body.set('grant_type', 'password');
|
||||||
|
body.set('username', 'zareian.1381@gmail.com');
|
||||||
|
body.set('password', '123@Qweasd');
|
||||||
|
body.set('client_id', 'harmony_identity');
|
||||||
|
body.set('scope', 'openid harmony_identity profile offline_access');
|
||||||
|
|
||||||
|
const { data } = await axios.post<TokenApiResponse>(
|
||||||
|
`${AUTH_API_URL}/connect/token`,
|
||||||
|
body.toString(),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const sendEmailOtpApi = async (
|
||||||
|
payload: SendEmailOtpPayload,
|
||||||
|
): Promise<GenericApiResponse & { codeSentAnyway?: boolean }> => {
|
||||||
|
const { data } = await apiClient.post('/User/SendEmailOtp', payload);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const confirmEmailOtpApi = async (
|
||||||
|
payload: ConfirmEmailOtpPayload,
|
||||||
|
): Promise<GenericApiResponse> => {
|
||||||
|
const { data } = await apiClient.post('/User/ConfirmEmailOtp', payload);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const completeUserInformationApi = async (
|
||||||
|
payload: CompleteUserInfoPayload,
|
||||||
|
): Promise<CompleteUserInfoResponse> => {
|
||||||
|
const { data } = await apiClient.post(
|
||||||
|
'/User/CompleteUserInformation',
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
TextField,
|
TextField,
|
||||||
Box,
|
Box,
|
||||||
@@ -28,7 +28,7 @@ interface EmailSectionProps {
|
|||||||
handleSendCode: () => void;
|
handleSendCode: () => void;
|
||||||
handleVerifyCode: () => void;
|
handleVerifyCode: () => void;
|
||||||
emailVerified: boolean;
|
emailVerified: boolean;
|
||||||
isVerifyingCode: boolean;
|
loading: boolean;
|
||||||
handleEditEmail: () => void;
|
handleEditEmail: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,15 +46,13 @@ export function EmailSection({
|
|||||||
handleSendCode,
|
handleSendCode,
|
||||||
handleVerifyCode,
|
handleVerifyCode,
|
||||||
emailVerified,
|
emailVerified,
|
||||||
isVerifyingCode,
|
loading,
|
||||||
handleEditEmail,
|
handleEditEmail,
|
||||||
}: EmailSectionProps) {
|
}: EmailSectionProps) {
|
||||||
const { t } = useTranslation('completionForm');
|
const { t } = useTranslation('completionForm');
|
||||||
|
|
||||||
const onSendCodeClick = () => {
|
const onSendCodeClick = () => {
|
||||||
if (!correctEmail) {
|
if (!correctEmail) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleSendCode();
|
handleSendCode();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,15 +60,6 @@ export function EmailSection({
|
|||||||
setShowEmail(e.target.checked);
|
setShowEmail(e.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (emailVerified) {
|
|
||||||
}
|
|
||||||
}, [emailVerified]);
|
|
||||||
|
|
||||||
const fieldSx = {
|
|
||||||
flex: '1 1 260px',
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
@@ -90,7 +79,6 @@ export function EmailSection({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
{showEmail && (
|
{showEmail && (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@@ -105,10 +93,7 @@ export function EmailSection({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -118,40 +103,39 @@ export function EmailSection({
|
|||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
error={email.length > 0 && !correctEmail}
|
error={email.length > 0 && !correctEmail}
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
InputProps={{
|
slotProps={{
|
||||||
startAdornment:
|
input: {
|
||||||
!isVerifyingCode && emailVerified ? (
|
startAdornment:
|
||||||
<InputAdornment position="end">
|
!loading && emailVerified ? (
|
||||||
<Icon
|
<InputAdornment position="end">
|
||||||
Component={TickCircle}
|
|
||||||
size="medium"
|
|
||||||
variant="Bold"
|
|
||||||
color="success.main"
|
|
||||||
/>
|
|
||||||
</InputAdornment>
|
|
||||||
) : null,
|
|
||||||
endAdornment:
|
|
||||||
buttonState === 'counting' ? (
|
|
||||||
<InputAdornment position="start">
|
|
||||||
<IconButton onClick={handleEditEmail}>
|
|
||||||
<Icon
|
<Icon
|
||||||
Component={Edit}
|
Component={TickCircle}
|
||||||
color="primary.main"
|
|
||||||
size="medium"
|
size="medium"
|
||||||
|
variant="Bold"
|
||||||
|
color="success.main"
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</InputAdornment>
|
||||||
</InputAdornment>
|
) : null,
|
||||||
) : null,
|
endAdornment:
|
||||||
}}
|
buttonState === 'counting' ? (
|
||||||
inputProps={{
|
<InputAdornment position="start">
|
||||||
style: {
|
<IconButton onClick={handleEditEmail}>
|
||||||
paddingLeft: buttonState === 'counting' ? '0px' : undefined,
|
<Icon
|
||||||
|
Component={Edit}
|
||||||
|
color="primary.main"
|
||||||
|
size="medium"
|
||||||
|
/>
|
||||||
|
</IconButton>
|
||||||
|
</InputAdornment>
|
||||||
|
) : null,
|
||||||
|
sx: {
|
||||||
|
paddingLeft: buttonState === 'counting' ? 0 : undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{!loading && !emailVerified && (
|
||||||
{!isVerifyingCode && !emailVerified && (
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="text"
|
variant="text"
|
||||||
@@ -167,7 +151,6 @@ export function EmailSection({
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{email && (
|
{email && (
|
||||||
<Typography
|
<Typography
|
||||||
sx={{ color: correctEmail ? 'success.main' : 'error.main' }}
|
sx={{ color: correctEmail ? 'success.main' : 'error.main' }}
|
||||||
@@ -176,17 +159,13 @@ export function EmailSection({
|
|||||||
{correctEmail ? '' : t('completion.emailCorrectForm')}
|
{correctEmail ? '' : t('completion.emailCorrectForm')}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!emailVerified && codeSent && correctEmail && (
|
{!emailVerified && codeSent && correctEmail && (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -194,21 +173,21 @@ export function EmailSection({
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={verificationCode}
|
value={verificationCode}
|
||||||
onChange={(e) => setVerificationCode(e.target.value)}
|
onChange={(e) => setVerificationCode(e.target.value)}
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
disabled={isVerifyingCode}
|
disabled={loading}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleVerifyCode}
|
onClick={handleVerifyCode}
|
||||||
disabled={isVerifyingCode}
|
disabled={loading}
|
||||||
sx={{
|
sx={{
|
||||||
width: { xs: '100%', sm: '156px' },
|
width: { xs: '100%', sm: '156px' },
|
||||||
border: 0.5,
|
border: 0.5,
|
||||||
textTransform: 'none',
|
textTransform: 'none',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isVerifyingCode ? (
|
{loading ? (
|
||||||
<CircularProgress />
|
<CircularProgress size={20} />
|
||||||
) : (
|
) : (
|
||||||
t('completion.checkCodeButton')
|
t('completion.checkCodeButton')
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function PasswordSection({
|
|||||||
}: PasswordSectionProps) {
|
}: PasswordSectionProps) {
|
||||||
const { t } = useTranslation('completionForm');
|
const { t } = useTranslation('completionForm');
|
||||||
const [showPasswordText, setShowPasswordText] = useState(false);
|
const [showPasswordText, setShowPasswordText] = useState(false);
|
||||||
const [showPasswordRepititonText, setShowPasswordRepetitionText] =
|
const [showPasswordRepetitionText, setShowPasswordRepetitionText] =
|
||||||
useState(false);
|
useState(false);
|
||||||
|
|
||||||
const handleTogglePasswordSection = (
|
const handleTogglePasswordSection = (
|
||||||
@@ -59,10 +59,6 @@ export function PasswordSection({
|
|||||||
const handleTogglePasswordRepetitionEye = () =>
|
const handleTogglePasswordRepetitionEye = () =>
|
||||||
setShowPasswordRepetitionText((prev) => !prev);
|
setShowPasswordRepetitionText((prev) => !prev);
|
||||||
|
|
||||||
const fieldSx = {
|
|
||||||
flex: '1 1 260px',
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
@@ -102,10 +98,7 @@ export function PasswordSection({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -114,30 +107,26 @@ export function PasswordSection({
|
|||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
type={showPasswordText ? 'text' : 'password'}
|
type={showPasswordText ? 'text' : 'password'}
|
||||||
sx={fieldSx}
|
sx={{
|
||||||
|
flex: '1 1 260px',
|
||||||
|
'& .MuiInputBase-input': {
|
||||||
|
pr: 8, // Increased padding to accommodate both icons
|
||||||
|
},
|
||||||
|
}}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<InputAdornment position="end" sx={{ height: 'unset' }}>
|
<InputAdornment position="end">
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
width: '100%',
|
justifyContent: 'flex-end',
|
||||||
|
minWidth: '64px', // Adjusted to fit both icons
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{validPassword && (
|
|
||||||
<Box sx={{ position: 'absolute', left: 0, px: 2 }}>
|
|
||||||
<Icon
|
|
||||||
Component={TickCircle}
|
|
||||||
size="medium"
|
|
||||||
color="success.main"
|
|
||||||
variant="Bold"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={handleTogglePasswordEye}
|
onClick={handleTogglePasswordEye}
|
||||||
sx={{ ml: validPassword ? 0.5 : 'auto' }}
|
sx={{ p: 0.5 }}
|
||||||
>
|
>
|
||||||
{showPasswordText ? (
|
{showPasswordText ? (
|
||||||
<Icon
|
<Icon
|
||||||
@@ -153,15 +142,18 @@ export function PasswordSection({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
{validPassword && (
|
||||||
|
<Icon
|
||||||
|
Component={TickCircle}
|
||||||
|
size="medium"
|
||||||
|
color="success.main"
|
||||||
|
variant="Bold"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
inputProps={{
|
|
||||||
style: {
|
|
||||||
paddingRight: validPassword ? '48px' : '20px',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
@@ -175,56 +167,26 @@ export function PasswordSection({
|
|||||||
? t('completion.notCompatibility')
|
? t('completion.notCompatibility')
|
||||||
: ' '
|
: ' '
|
||||||
}
|
}
|
||||||
type={showPasswordRepititonText ? 'text' : 'password'}
|
type={showPasswordRepetitionText ? 'text' : 'password'}
|
||||||
sx={fieldSx}
|
sx={{
|
||||||
|
flex: '1 1 260px',
|
||||||
|
}}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
<InputAdornment position="end" sx={{ height: 'unset' }}>
|
<InputAdornment position="end">
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
width: '100%',
|
justifyContent: 'flex-end',
|
||||||
|
minWidth: '64px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{confirmPassword.length > 0 &&
|
|
||||||
(matchPassword ? (
|
|
||||||
<Box sx={{ position: 'absolute', left: 0, px: 2 }}>
|
|
||||||
<Icon
|
|
||||||
Component={TickCircle}
|
|
||||||
size="medium"
|
|
||||||
color="success.main"
|
|
||||||
variant="Bold"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: 0,
|
|
||||||
alignItems: 'center',
|
|
||||||
px: 2,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
Component={CloseCircle}
|
|
||||||
size="medium"
|
|
||||||
color="error.main"
|
|
||||||
variant="Bold"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
))}
|
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={handleTogglePasswordRepetitionEye}
|
onClick={handleTogglePasswordRepetitionEye}
|
||||||
sx={{
|
sx={{ p: 0.5 }}
|
||||||
ml:
|
|
||||||
confirmPassword.length > 0 && matchPassword
|
|
||||||
? 0.5
|
|
||||||
: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{showPasswordRepititonText ? (
|
{showPasswordRepetitionText ? (
|
||||||
<Icon
|
<Icon
|
||||||
Component={Eye}
|
Component={Eye}
|
||||||
color="primary.main"
|
color="primary.main"
|
||||||
@@ -238,18 +200,18 @@ export function PasswordSection({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
{confirmPassword.length > 0 && (
|
||||||
|
<Icon
|
||||||
|
Component={matchPassword ? TickCircle : CloseCircle}
|
||||||
|
size="medium"
|
||||||
|
color={matchPassword ? 'success.main' : 'error.main'}
|
||||||
|
variant="Bold"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
inputProps={{
|
|
||||||
style: {
|
|
||||||
paddingRight:
|
|
||||||
confirmPassword.length > 0 && matchPassword
|
|
||||||
? '48px'
|
|
||||||
: '45px',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
@@ -259,10 +221,7 @@ export function PasswordSection({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export function PasswordValidationItem({
|
|||||||
variant="body2"
|
variant="body2"
|
||||||
color="text.primary"
|
color="text.primary"
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: { xs: '0.85rem', sm: '0.875rem' },
|
|
||||||
wordBreak: 'break-word',
|
wordBreak: 'break-word',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ import DateOfBirth from './DateOfBirth';
|
|||||||
import { countries } from '../data/Countries';
|
import { countries } from '../data/Countries';
|
||||||
import { CountryFlag } from '@/components/CountryFlag';
|
import { CountryFlag } from '@/components/CountryFlag';
|
||||||
import { Icon } from '@rkheftan/harmony-ui';
|
import { Icon } from '@rkheftan/harmony-ui';
|
||||||
|
import { Gender } from './types';
|
||||||
|
|
||||||
interface PersonalInfoFieldsProps {
|
interface PersonalInfoFieldsProps {
|
||||||
firstName: string;
|
firstName: string;
|
||||||
setFirstName: (v: string) => void;
|
setFirstName: (v: string) => void;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
setLastName: (v: string) => void;
|
setLastName: (v: string) => void;
|
||||||
sex: 'male' | 'female';
|
sex: Gender;
|
||||||
setSex: Dispatch<SetStateAction<'female' | 'male'>>;
|
setSex: Dispatch<SetStateAction<Gender>>;
|
||||||
country: string;
|
country: string;
|
||||||
setCountry: (country: string) => void;
|
setCountry: (country: string) => void;
|
||||||
nationalId: string;
|
nationalId: string;
|
||||||
@@ -46,19 +47,32 @@ export function PersonalInfoFields({
|
|||||||
setCountry,
|
setCountry,
|
||||||
}: PersonalInfoFieldsProps) {
|
}: PersonalInfoFieldsProps) {
|
||||||
const { t } = useTranslation('completionForm');
|
const { t } = useTranslation('completionForm');
|
||||||
|
|
||||||
const countryOptions = countries.map((c) => ({
|
const countryOptions = countries.map((c) => ({
|
||||||
code: c.code,
|
code: c.code,
|
||||||
label: t(c.label, { ns: 'countries' }),
|
label: t(c.label, { ns: 'countries' }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const currentCountry = countryOptions.find((c) => c.code === country) || null;
|
const currentCountry = countryOptions.find((c) => c.code === country) || null;
|
||||||
|
|
||||||
const handleChangeSex = (e: SelectChangeEvent<'male' | 'female'>) => {
|
const handleChangeSex = (e: SelectChangeEvent<Gender>) => {
|
||||||
setSex(e.target.value as 'female' | 'male');
|
setSex(e.target.value as Gender);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldSx = {
|
const genderOptions = [
|
||||||
flex: '1 1 260px',
|
{
|
||||||
};
|
value: Gender.Female,
|
||||||
|
icon: Woman,
|
||||||
|
label: t('completion.woman'),
|
||||||
|
color: '#F50057',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: Gender.Male,
|
||||||
|
icon: Man,
|
||||||
|
label: t('completion.man'),
|
||||||
|
color: '#0091EA',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
|
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
|
||||||
@@ -76,10 +90,7 @@ export function PersonalInfoFields({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -88,7 +99,7 @@ export function PersonalInfoFields({
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={firstName}
|
value={firstName}
|
||||||
onChange={(e) => setFirstName(e.target.value)}
|
onChange={(e) => setFirstName(e.target.value)}
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
label={t('completion.familyName')}
|
label={t('completion.familyName')}
|
||||||
@@ -96,7 +107,7 @@ export function PersonalInfoFields({
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={lastName}
|
value={lastName}
|
||||||
onChange={(e) => setLastName(e.target.value)}
|
onChange={(e) => setLastName(e.target.value)}
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
@@ -105,31 +116,24 @@ export function PersonalInfoFields({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormControl sx={fieldSx}>
|
<FormControl sx={{ flex: '1 1 260px' }}>
|
||||||
<InputLabel>{t('completion.gender')}</InputLabel>
|
<InputLabel>{t('completion.gender')}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
value={sex}
|
value={sex}
|
||||||
label={t('completion.gender')}
|
label={t('completion.gender')}
|
||||||
onChange={handleChangeSex}
|
onChange={handleChangeSex}
|
||||||
>
|
>
|
||||||
<MenuItem value="female">
|
{genderOptions.map((g) => (
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
<MenuItem key={g.value} value={g.value}>
|
||||||
<Icon Component={Woman} color="#F50057" size="small" />
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||||
{t('completion.woman')}
|
<Icon Component={g.icon} size="small" color={g.color} />
|
||||||
</Box>
|
{g.label}
|
||||||
</MenuItem>
|
</Box>
|
||||||
<MenuItem value="male">
|
</MenuItem>
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
))}
|
||||||
<Icon Component={Man} size="small" color="#0091EA" />
|
|
||||||
{t('completion.man')}
|
|
||||||
</Box>
|
|
||||||
</MenuItem>
|
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
@@ -139,7 +143,7 @@ export function PersonalInfoFields({
|
|||||||
value={nationalId}
|
value={nationalId}
|
||||||
onChange={(e) => setNationalId(e.target.value)}
|
onChange={(e) => setNationalId(e.target.value)}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
@@ -148,20 +152,15 @@ export function PersonalInfoFields({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
justifyContent: 'center',
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
'@media(min-width: 600px)': {
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
sx={fieldSx}
|
sx={{ flex: '1 1 260px' }}
|
||||||
options={countryOptions}
|
options={countryOptions}
|
||||||
getOptionLabel={(option) => option.label}
|
getOptionLabel={(option) => option.label}
|
||||||
value={currentCountry}
|
value={currentCountry}
|
||||||
onChange={(_, newValue) => {
|
onChange={(_, newValue) => setCountry(newValue?.code || '')}
|
||||||
setCountry(newValue?.code || '');
|
|
||||||
}}
|
|
||||||
renderOption={(props, option) => (
|
renderOption={(props, option) => (
|
||||||
<Box component="li" {...props} key={option.code}>
|
<Box component="li" {...props} key={option.code}>
|
||||||
<CountryFlag code={option.code} />
|
<CountryFlag code={option.code} />
|
||||||
@@ -174,7 +173,7 @@ export function PersonalInfoFields({
|
|||||||
clearOnEscape
|
clearOnEscape
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Box sx={fieldSx}>
|
<Box sx={{ flex: '1 1 260px' }}>
|
||||||
<DateOfBirth value={birthDate} onChange={setBirthDate} />
|
<DateOfBirth value={birthDate} onChange={setBirthDate} />
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export function SubmitSection({ onSubmit, loading, error, success }: Props) {
|
|||||||
flexWrap: 'wrap',
|
flexWrap: 'wrap',
|
||||||
gap: 2,
|
gap: 2,
|
||||||
px: { xs: 2, sm: 0 },
|
px: { xs: 2, sm: 0 },
|
||||||
mb: '17px',
|
mb: 2,
|
||||||
justifyContent: { xs: 'center', sm: 'flex-start' },
|
justifyContent: { xs: 'center', sm: 'flex-start' },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -46,10 +46,10 @@ export function SubmitSection({ onSubmit, loading, error, success }: Props) {
|
|||||||
}}
|
}}
|
||||||
color="text.primary"
|
color="text.primary"
|
||||||
>
|
>
|
||||||
{t('completion.agreementPart1')}{' '}
|
{t('completion.agreementPart1')}
|
||||||
<Link href="#" onClick={handleOpenDialog}>
|
<Link href="#" onClick={handleOpenDialog}>
|
||||||
{t('completion.agreementLinkText')}
|
{t('completion.agreementLinkText')}
|
||||||
</Link>{' '}
|
</Link>
|
||||||
{t('completion.agreementPart2')}
|
{t('completion.agreementPart2')}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
@@ -65,9 +65,7 @@ export function SubmitSection({ onSubmit, loading, error, success }: Props) {
|
|||||||
>
|
>
|
||||||
{loading
|
{loading
|
||||||
? t('completion.submitting')
|
? t('completion.submitting')
|
||||||
: success
|
: t('completion.registerButton')}
|
||||||
? t('completion.registerButton')
|
|
||||||
: t('completion.registerButton')}
|
|
||||||
</Button>
|
</Button>
|
||||||
{error && <Typography color="error">{error}</Typography>}
|
{error && <Typography color="error">{error}</Typography>}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Box, Typography } from '@mui/material';
|
import { Box, Typography, Button } from '@mui/material';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import Logo from '@/components/Logo';
|
import Logo from '@/components/Logo';
|
||||||
import { PersonalInfoFields } from './PersonalInfoFields';
|
import { PersonalInfoFields } from './PersonalInfoFields';
|
||||||
@@ -11,7 +11,13 @@ import { useToast } from '@rkheftan/harmony-ui';
|
|||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { regex } from '../../../utils/regex';
|
import { regex } from '../../../utils/regex';
|
||||||
import { toLocaleDigits } from '../../../utils/persianDigit';
|
import { toLocaleDigits } from '../../../utils/persianDigit';
|
||||||
|
import axios, { isAxiosError } from 'axios';
|
||||||
import i18n from '@/config/i18n';
|
import i18n from '@/config/i18n';
|
||||||
|
import { Gender } from './types'; // ✅ Added
|
||||||
|
|
||||||
|
interface TokenApiResponse {
|
||||||
|
access_token: string;
|
||||||
|
}
|
||||||
|
|
||||||
export function UserCompletionForm() {
|
export function UserCompletionForm() {
|
||||||
const { t } = useTranslation('completionForm');
|
const { t } = useTranslation('completionForm');
|
||||||
@@ -20,7 +26,9 @@ export function UserCompletionForm() {
|
|||||||
const [lastName, setLastName] = useState('');
|
const [lastName, setLastName] = useState('');
|
||||||
const [nationalId, setNationalId] = useState('');
|
const [nationalId, setNationalId] = useState('');
|
||||||
const [birthDate, setBirthDate] = useState<Date | null>(null);
|
const [birthDate, setBirthDate] = useState<Date | null>(null);
|
||||||
const [sex, setSex] = useState<'female' | 'male'>('female');
|
|
||||||
|
// ✅ Corrected section: use Gender enum
|
||||||
|
const [sex, setSex] = useState<Gender>(Gender.Female);
|
||||||
const [country, setCountry] = useState('');
|
const [country, setCountry] = useState('');
|
||||||
|
|
||||||
const [showPasswordSection, setShowPasswordSection] = useState(false);
|
const [showPasswordSection, setShowPasswordSection] = useState(false);
|
||||||
@@ -38,15 +46,14 @@ export function UserCompletionForm() {
|
|||||||
const [emailVerified, setEmailVerified] = useState(false);
|
const [emailVerified, setEmailVerified] = useState(false);
|
||||||
const [isVerifyingCode, setIsVerifyingCode] = useState(false);
|
const [isVerifyingCode, setIsVerifyingCode] = useState(false);
|
||||||
|
|
||||||
const correctEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hasNumber,
|
hasNumber,
|
||||||
hasMinLength,
|
hasMinLength,
|
||||||
hasUpperAndLower,
|
hasUpperAndLower,
|
||||||
hasSpecialChar,
|
hasSpecialChar,
|
||||||
validPassword,
|
validPassword,
|
||||||
} = regex(password);
|
correctEmail,
|
||||||
|
} = regex(password, email);
|
||||||
const matchPassword = password === confirmPassword;
|
const matchPassword = password === confirmPassword;
|
||||||
const [showPasswordValidations, setShowPasswordValidations] = useState(false);
|
const [showPasswordValidations, setShowPasswordValidations] = useState(false);
|
||||||
|
|
||||||
@@ -95,6 +102,42 @@ export function UserCompletionForm() {
|
|||||||
return t('completion.vericationCodeButton');
|
return t('completion.vericationCodeButton');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [tokenError, setTokenError] = useState<string | null>(null);
|
||||||
|
const apiUrl = 'https://accounts.business-harmony.com';
|
||||||
|
const tokenEndpoint = `${apiUrl}/connect/token`;
|
||||||
|
const getToken = async () => {
|
||||||
|
setTokenError(null);
|
||||||
|
try {
|
||||||
|
const body = new URLSearchParams();
|
||||||
|
body.set('grant_type', 'password');
|
||||||
|
body.set('username', 'zareian.1381@gmail.com');
|
||||||
|
body.set('password', '123@Qweasd');
|
||||||
|
body.set('client_id', 'harmony_identity');
|
||||||
|
body.set('scope', 'openid harmony_identity profile offline_access');
|
||||||
|
const response = await axios.post<TokenApiResponse>(
|
||||||
|
tokenEndpoint,
|
||||||
|
body.toString(),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (response.data?.access_token) {
|
||||||
|
localStorage.setItem('authToken', response.data.access_token);
|
||||||
|
} else {
|
||||||
|
throw new Error('No access token in response');
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
let message = 'Failed to get token';
|
||||||
|
if (isAxiosError(error) && error.response) {
|
||||||
|
message = `Request failed with status ${error.response.status}`;
|
||||||
|
} else if (error instanceof Error) {
|
||||||
|
message = error.message;
|
||||||
|
}
|
||||||
|
setTokenError(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
const storedToken = localStorage.getItem('authToken');
|
const storedToken = localStorage.getItem('authToken');
|
||||||
|
|
||||||
const handleSendCode = async () => {
|
const handleSendCode = async () => {
|
||||||
@@ -218,7 +261,7 @@ export function UserCompletionForm() {
|
|||||||
userId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
|
userId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
gender: sex === 'female' ? 2 : 1,
|
gender: sex === Gender.Female ? 2 : 1, // ✅ Corrected
|
||||||
nationalId,
|
nationalId,
|
||||||
savePassword: showPasswordSection,
|
savePassword: showPasswordSection,
|
||||||
password: showPasswordSection ? password : undefined,
|
password: showPasswordSection ? password : undefined,
|
||||||
@@ -302,8 +345,8 @@ export function UserCompletionForm() {
|
|||||||
setNationalId={setNationalId}
|
setNationalId={setNationalId}
|
||||||
birthDate={birthDate}
|
birthDate={birthDate}
|
||||||
setBirthDate={setBirthDate}
|
setBirthDate={setBirthDate}
|
||||||
sex={sex}
|
sex={sex} // ✅ Corrected
|
||||||
setSex={setSex}
|
setSex={setSex} // ✅ Corrected
|
||||||
country={country}
|
country={country}
|
||||||
setCountry={setCountry}
|
setCountry={setCountry}
|
||||||
/>
|
/>
|
||||||
@@ -338,7 +381,7 @@ export function UserCompletionForm() {
|
|||||||
handleSendCode={handleSendCode}
|
handleSendCode={handleSendCode}
|
||||||
handleVerifyCode={handleVerifyCode}
|
handleVerifyCode={handleVerifyCode}
|
||||||
emailVerified={emailVerified}
|
emailVerified={emailVerified}
|
||||||
isVerifyingCode={isVerifyingCode}
|
loading={isVerifyingCode}
|
||||||
handleEditEmail={handleEditEmail}
|
handleEditEmail={handleEditEmail}
|
||||||
/>
|
/>
|
||||||
<SubmitSection
|
<SubmitSection
|
||||||
@@ -347,6 +390,15 @@ export function UserCompletionForm() {
|
|||||||
error={error}
|
error={error}
|
||||||
success={success}
|
success={success}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
onClick={getToken}
|
||||||
|
size="large"
|
||||||
|
sx={{ textTransform: 'none' }}
|
||||||
|
>
|
||||||
|
Get Token
|
||||||
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
5
src/features/authentication/components/types.ts
Normal file
5
src/features/authentication/components/types.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export enum Gender {
|
||||||
|
None = 0,
|
||||||
|
Female = 1,
|
||||||
|
Male = 2,
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
export function regex(password: string) {
|
export function regex(password: string, email: string) {
|
||||||
const hasNumber = /\d/.test(password);
|
const hasNumber = /\d/.test(password);
|
||||||
const hasMinLength = password.length >= 8;
|
const hasMinLength = password.length >= 8;
|
||||||
const hasUpperAndLower = /[A-Z]/.test(password) && /[a-z]/.test(password);
|
const hasUpperAndLower = /[A-Z]/.test(password) && /[a-z]/.test(password);
|
||||||
const hasSpecialChar = /[!@#$%^&*]/.test(password);
|
const hasSpecialChar = /[!@#$%^&*]/.test(password);
|
||||||
|
const correctEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hasNumber,
|
hasNumber,
|
||||||
@@ -11,5 +12,6 @@ export function regex(password: string) {
|
|||||||
hasSpecialChar,
|
hasSpecialChar,
|
||||||
validPassword:
|
validPassword:
|
||||||
hasNumber && hasMinLength && hasUpperAndLower && hasSpecialChar,
|
hasNumber && hasMinLength && hasUpperAndLower && hasSpecialChar,
|
||||||
|
correctEmail,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user