From 284e60fab336fe4b3653ec5654d3c3e905978275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=87=D8=B1=D8=B2=D8=A7=D8=AF=20=D9=82=D8=AF=D8=B1?= =?UTF-8?q?=D8=AA=DB=8C?= Date: Sat, 9 Aug 2025 12:58:28 +0330 Subject: [PATCH] chore: authorization module name changed and backend type and request functions added --- src/App.tsx | 2 +- .../authorization/api/authorizationAPI.ts | 96 ++++++++++++++++ .../components/AuthenticationCard.tsx | 0 .../AuthenticationSteps.tsx | 2 +- .../AuthenticationSteps/CompleteSignUp.tsx | 0 .../AuthenticationSteps/EnterPasswordForm.tsx | 0 .../AuthenticationSteps/LoginRegiserForm.tsx | 2 +- .../AuthenticationSteps/OtpVerifyForm.tsx | 2 +- .../components/CountryCodeSelector.tsx | 0 .../ForgetPassword/ChangePassword.tsx | 0 .../ForgetPasswordContainer.tsx | 2 +- .../ForgetPassword/ForgetPasswordOtp.tsx | 2 +- .../ForgetPassword/ForgettedPasswordInfo.tsx | 2 +- .../data/countries.ts | 0 .../index.ts | 0 .../routes/AuthenticationPage.tsx | 2 +- .../types/authTypes.ts} | 0 src/features/authorization/types/userTypes.ts | 106 ++++++++++++++++++ src/types/apiResponse.ts | 13 +++ src/types/commonTypes.ts | 1 + src/types/fetchPromise.ts | 5 + 21 files changed, 229 insertions(+), 8 deletions(-) create mode 100644 src/features/authorization/api/authorizationAPI.ts rename src/features/{authentication => authorization}/components/AuthenticationCard.tsx (100%) rename src/features/{authentication => authorization}/components/AuthenticationSteps/AuthenticationSteps.tsx (98%) rename src/features/{authentication => authorization}/components/AuthenticationSteps/CompleteSignUp.tsx (100%) rename src/features/{authentication => authorization}/components/AuthenticationSteps/EnterPasswordForm.tsx (100%) rename src/features/{authentication => authorization}/components/AuthenticationSteps/LoginRegiserForm.tsx (98%) rename src/features/{authentication => authorization}/components/AuthenticationSteps/OtpVerifyForm.tsx (98%) rename src/features/{authentication => authorization}/components/CountryCodeSelector.tsx (100%) rename src/features/{authentication => authorization}/components/ForgetPassword/ChangePassword.tsx (100%) rename src/features/{authentication => authorization}/components/ForgetPassword/ForgetPasswordContainer.tsx (96%) rename src/features/{authentication => authorization}/components/ForgetPassword/ForgetPasswordOtp.tsx (98%) rename src/features/{authentication => authorization}/components/ForgetPassword/ForgettedPasswordInfo.tsx (98%) rename src/features/{authentication => authorization}/data/countries.ts (100%) rename src/features/{authentication => authorization}/index.ts (100%) rename src/features/{authentication => authorization}/routes/AuthenticationPage.tsx (94%) rename src/features/{authentication/types/auth-types.ts => authorization/types/authTypes.ts} (100%) create mode 100644 src/features/authorization/types/userTypes.ts create mode 100644 src/types/apiResponse.ts create mode 100644 src/types/commonTypes.ts create mode 100644 src/types/fetchPromise.ts diff --git a/src/App.tsx b/src/App.tsx index 0d50227..700db76 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import { CssBaseline } from '@mui/material'; import './App.css'; import { LanguageManager } from './components/LanguageManager'; -import { AuthenticationPage } from './features/authentication/routes/AuthenticationPage'; +import { AuthenticationPage } from './features/authorization/routes/AuthenticationPage'; function App() { return ( diff --git a/src/features/authorization/api/authorizationAPI.ts b/src/features/authorization/api/authorizationAPI.ts new file mode 100644 index 0000000..990924b --- /dev/null +++ b/src/features/authorization/api/authorizationAPI.ts @@ -0,0 +1,96 @@ +import type { ApiResponse } from '@/types/apiResponse'; +import type { FetchPromise } from '@/types/fetchPromise'; +import type { + ConfirmEmailOtpRequest, + ConfirmForgetPassCodeRequest, + ConfirmOtpResponse, + ConfirmSmsOtpRequest, + GetUserStatusByPhoneNumberOrEmailRequest, + GetUserStatusByPhoneNumberOrEmailResponse, + LoginOrSignUpWithGoogleRequest, + LoginOrSignUpWithGoogleResponse, + LoginRequest, + LoginResponse, + ResetPasswordRequest, + ResetPasswordResponse, + SendEmailOtpRequest, + SendForgetPassCodeRequest, + SendSmsOtpRequest, +} from '../types/userTypes'; + +const API_URL = 'https://account.business-harmony.com/api/'; + +export const fetchRequest = ( + url: string, + body: Object | null, +): FetchPromise => { + return fetch(`${API_URL}/${url}`, { + body: JSON.stringify(body), + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }); +}; + +// GetUserStatusByPhoneNumberOrEmail + +export const getUserStatusByPhoneNumberOrEmail = async ( + body: GetUserStatusByPhoneNumberOrEmailRequest, +) => { + return fetchRequest( + 'User/GetUserStatusByPhoneNumberOrEmail', + body, + ); +}; + +export const loginOrSignUpWithOtp = async (body: LoginRequest) => { + return fetchRequest('User/LoginOrSignUpWithOtp', body); +}; + +export const loginWithPassword = async (body: LoginRequest) => { + return fetchRequest('User/LoginWithPassword', body); +}; + +export const sendSmsOtp = async (body: SendSmsOtpRequest) => { + return fetchRequest('User/SendSmsOtp', body); +}; + +export const sendEmailOtp = async (body: SendEmailOtpRequest) => { + return fetchRequest('User/SendEmailOtp', body); +}; + +export const confirmSmsOtp = async (body: ConfirmSmsOtpRequest) => { + return fetchRequest('User/ConfirmSmsOtp', body); +}; + +export const confirmEmailOtp = async (body: ConfirmEmailOtpRequest) => { + return fetchRequest('User/ConfirmEmailOtp', body); +}; + +export const resetPassword = async (body: ResetPasswordRequest) => { + return fetchRequest('User/ResetPassword', body); +}; + +export const sendForgetPassCode = async (body: SendForgetPassCodeRequest) => { + return fetchRequest('User/SendForgetPassCode', body); +}; + +export const ConfirmForgetPassCode = async ( + body: ConfirmForgetPassCodeRequest, +) => { + return fetchRequest('User/ConfirmForgetPassCode', body); +}; + +export const loginOrSignUpWithGoogle = async ( + body: LoginOrSignUpWithGoogleRequest, +) => { + return fetchRequest( + 'User/LoginOrSignUpWithGoogle', + body, + ); +}; + +export const logOut = async () => { + return fetchRequest('User/LogOut', {}); +}; diff --git a/src/features/authentication/components/AuthenticationCard.tsx b/src/features/authorization/components/AuthenticationCard.tsx similarity index 100% rename from src/features/authentication/components/AuthenticationCard.tsx rename to src/features/authorization/components/AuthenticationCard.tsx diff --git a/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx b/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx similarity index 98% rename from src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx rename to src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx index b88a506..c9c951a 100644 --- a/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx +++ b/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx @@ -1,6 +1,6 @@ import React, { useState, type JSX } from 'react'; import { LoginRegisterForm } from './LoginRegiserForm'; -import type { AuthMode, AuthType } from '../../types/auth-types'; +import type { AuthMode, AuthType } from '../../types/authTypes'; import { OtpVerifyForm } from './OtpVerifyForm'; import { isNumeric } from '@/utils/regexes/isNumeric'; import { CompleteSignUp } from './CompleteSignUp'; diff --git a/src/features/authentication/components/AuthenticationSteps/CompleteSignUp.tsx b/src/features/authorization/components/AuthenticationSteps/CompleteSignUp.tsx similarity index 100% rename from src/features/authentication/components/AuthenticationSteps/CompleteSignUp.tsx rename to src/features/authorization/components/AuthenticationSteps/CompleteSignUp.tsx diff --git a/src/features/authentication/components/AuthenticationSteps/EnterPasswordForm.tsx b/src/features/authorization/components/AuthenticationSteps/EnterPasswordForm.tsx similarity index 100% rename from src/features/authentication/components/AuthenticationSteps/EnterPasswordForm.tsx rename to src/features/authorization/components/AuthenticationSteps/EnterPasswordForm.tsx diff --git a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx b/src/features/authorization/components/AuthenticationSteps/LoginRegiserForm.tsx similarity index 98% rename from src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx rename to src/features/authorization/components/AuthenticationSteps/LoginRegiserForm.tsx index df79514..66e7cbd 100644 --- a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx +++ b/src/features/authorization/components/AuthenticationSteps/LoginRegiserForm.tsx @@ -10,7 +10,7 @@ import { useRef, useState, type Dispatch } from 'react'; import { useTranslation } from 'react-i18next'; import { Google } from 'iconsax-reactjs'; import { isNumeric } from '@/utils/regexes/isNumeric'; -import type { AuthMode, AuthType } from '../../types/auth-types'; +import type { AuthMode, AuthType } from '../../types/authTypes'; import { isEmail } from '@/utils/regexes/isEmail'; import parsePhoneNumberFromString from 'libphonenumber-js'; import { AuthenticationCard } from '../AuthenticationCard'; diff --git a/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx b/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx similarity index 98% rename from src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx rename to src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx index 1997972..54de8ba 100644 --- a/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx +++ b/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx @@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next'; import { Alert, Box, Button, Snackbar, Stack, Typography } from '@mui/material'; import { Edit2 } from 'iconsax-reactjs'; import DigitInput from '@/components/components/DigitsInput'; -import type { AuthMode, AuthType } from '../../types/auth-types'; +import type { AuthMode, AuthType } from '../../types/authTypes'; import { useEffect, useState } from 'react'; import { Toast } from '@/components/Toast'; import { AuthenticationCard } from '../AuthenticationCard'; diff --git a/src/features/authentication/components/CountryCodeSelector.tsx b/src/features/authorization/components/CountryCodeSelector.tsx similarity index 100% rename from src/features/authentication/components/CountryCodeSelector.tsx rename to src/features/authorization/components/CountryCodeSelector.tsx diff --git a/src/features/authentication/components/ForgetPassword/ChangePassword.tsx b/src/features/authorization/components/ForgetPassword/ChangePassword.tsx similarity index 100% rename from src/features/authentication/components/ForgetPassword/ChangePassword.tsx rename to src/features/authorization/components/ForgetPassword/ChangePassword.tsx diff --git a/src/features/authentication/components/ForgetPassword/ForgetPasswordContainer.tsx b/src/features/authorization/components/ForgetPassword/ForgetPasswordContainer.tsx similarity index 96% rename from src/features/authentication/components/ForgetPassword/ForgetPasswordContainer.tsx rename to src/features/authorization/components/ForgetPassword/ForgetPasswordContainer.tsx index d95d294..a8112fb 100644 --- a/src/features/authentication/components/ForgetPassword/ForgetPasswordContainer.tsx +++ b/src/features/authorization/components/ForgetPassword/ForgetPasswordContainer.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import type { AuthType } from '../../types/auth-types'; +import type { AuthType } from '../../types/authTypes'; import { ForgettedPasswordInfo } from './ForgettedPasswordInfo'; import { ForgetPasswordOtp } from './ForgetPasswordOtp'; import { ChangePassword } from './ChangePassword'; diff --git a/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx b/src/features/authorization/components/ForgetPassword/ForgetPasswordOtp.tsx similarity index 98% rename from src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx rename to src/features/authorization/components/ForgetPassword/ForgetPasswordOtp.tsx index bb67a5f..62c81cb 100644 --- a/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx +++ b/src/features/authorization/components/ForgetPassword/ForgetPasswordOtp.tsx @@ -2,7 +2,7 @@ import { useTranslation } from 'react-i18next'; import { Alert, Box, Button, Snackbar, Stack, Typography } from '@mui/material'; import { Edit2 } from 'iconsax-reactjs'; import DigitInput from '@/components/components/DigitsInput'; -import type { AuthMode, AuthType } from '../../types/auth-types'; +import type { AuthMode, AuthType } from '../../types/authTypes'; import { useEffect, useState } from 'react'; import { Toast } from '@/components/Toast'; import { AuthenticationCard } from '../AuthenticationCard'; diff --git a/src/features/authentication/components/ForgetPassword/ForgettedPasswordInfo.tsx b/src/features/authorization/components/ForgetPassword/ForgettedPasswordInfo.tsx similarity index 98% rename from src/features/authentication/components/ForgetPassword/ForgettedPasswordInfo.tsx rename to src/features/authorization/components/ForgetPassword/ForgettedPasswordInfo.tsx index 64f05e5..dc43ebf 100644 --- a/src/features/authentication/components/ForgetPassword/ForgettedPasswordInfo.tsx +++ b/src/features/authorization/components/ForgetPassword/ForgettedPasswordInfo.tsx @@ -10,7 +10,7 @@ import { useRef, useState, type Dispatch } from 'react'; import { useTranslation } from 'react-i18next'; import { Google } from 'iconsax-reactjs'; import { isNumeric } from '@/utils/regexes/isNumeric'; -import type { AuthMode, AuthType } from '../../types/auth-types'; +import type { AuthMode, AuthType } from '../../types/authTypes'; import { isEmail } from '@/utils/regexes/isEmail'; import parsePhoneNumberFromString from 'libphonenumber-js'; import { AuthenticationCard } from '../AuthenticationCard'; diff --git a/src/features/authentication/data/countries.ts b/src/features/authorization/data/countries.ts similarity index 100% rename from src/features/authentication/data/countries.ts rename to src/features/authorization/data/countries.ts diff --git a/src/features/authentication/index.ts b/src/features/authorization/index.ts similarity index 100% rename from src/features/authentication/index.ts rename to src/features/authorization/index.ts diff --git a/src/features/authentication/routes/AuthenticationPage.tsx b/src/features/authorization/routes/AuthenticationPage.tsx similarity index 94% rename from src/features/authentication/routes/AuthenticationPage.tsx rename to src/features/authorization/routes/AuthenticationPage.tsx index 871d641..d34cc01 100644 --- a/src/features/authentication/routes/AuthenticationPage.tsx +++ b/src/features/authorization/routes/AuthenticationPage.tsx @@ -17,7 +17,7 @@ export function AuthenticationPage() { }} > - + ); } diff --git a/src/features/authentication/types/auth-types.ts b/src/features/authorization/types/authTypes.ts similarity index 100% rename from src/features/authentication/types/auth-types.ts rename to src/features/authorization/types/authTypes.ts diff --git a/src/features/authorization/types/userTypes.ts b/src/features/authorization/types/userTypes.ts new file mode 100644 index 0000000..54070a0 --- /dev/null +++ b/src/features/authorization/types/userTypes.ts @@ -0,0 +1,106 @@ +// GetUserStatusByPhoneNumberOrEmail + +import type { ApiResponse } from '@/types/apiResponse'; +import type { GUID } from '@/types/commonTypes'; + +export interface GetUserStatusByPhoneNumberOrEmailRequest { + phoneNumber?: string; + email?: string; +} + +export interface GetUserStatusByPhoneNumberOrEmailResponse extends ApiResponse { + userStatus: UserStatus; +} + +export enum UserStatus { + None = 0, + Value1 = 1, + Value2 = 2, + Value3 = 3, +} + +// LoginOrSignUpWithOtp + +export interface LoginRequest { + otpCode: string; + phoneNumber?: string; + email?: string; + returnUrl: string; +} + +export interface LoginResponse extends ApiResponse { + returnUrl: string; + userId: GUID; + registeredWithOutPhoneNumber: boolean; + completedUserInformation: boolean; +} + +// SendSmsOtp + +export interface SendSmsOtpRequest { + phoneNumber: string; +} + +// SendEmailOtp + +export interface SendEmailOtpRequest { + email: string; +} + +// ConfirmOtp + +export interface ConfirmEmailOtpRequest { + email: string; + otpCode: string; +} + +export interface ConfirmSmsOtpRequest { + phoneNumber: string; + otpCode: string; +} + +export interface ConfirmOtpResponse extends ApiResponse { + confirm: boolean; +} + +// ResetPassword + +export interface ResetPasswordRequest { + email?: string; + phoneNumber?: string; + newPassword: string; + confirmNewPassword: string; +} + +export interface ResetPasswordResponse extends ApiResponse { + passwordChanged: boolean; +} + +// SendForgetPassCode + +export interface SendForgetPassCodeRequest { + email?: string; + phoneNumber?: string; +} + +// ConfirmForgetPassCode + +export interface ConfirmForgetPassCodeRequest { + email: string; + phoneNumber: string; + code: string; +} + +// LoginOrSignUpWithGoogle + +export interface LoginOrSignUpWithGoogleRequest { + idToken: string; + returnUrl: string; +} + +export interface LoginOrSignUpWithGoogleResponse extends ApiResponse { + userId: GUID; + registeredWithOutPhoneNumber: boolean; + completedUserInformation: boolean; + returnUrl: string; +} diff --git a/src/types/apiResponse.ts b/src/types/apiResponse.ts new file mode 100644 index 0000000..abc0599 --- /dev/null +++ b/src/types/apiResponse.ts @@ -0,0 +1,13 @@ +export interface ApiResponse { + success: boolean; + errorCode: number; + message: string; + validations: ApiResponseValidation[]; +} + +export interface ApiResponseValidation { + message: string; + code: number; + property: string; + severity: number; +} diff --git a/src/types/commonTypes.ts b/src/types/commonTypes.ts new file mode 100644 index 0000000..a380ad0 --- /dev/null +++ b/src/types/commonTypes.ts @@ -0,0 +1 @@ +export type GUID = `${string}-${string}-${string}-${string}-${string}`; diff --git a/src/types/fetchPromise.ts b/src/types/fetchPromise.ts new file mode 100644 index 0000000..84483d5 --- /dev/null +++ b/src/types/fetchPromise.ts @@ -0,0 +1,5 @@ +export type FetchPromise = Promise>; + +export interface FetchResponse extends Response { + json(): Promise; +}