chore: useApi added to the components

This commit is contained in:
2025-08-15 22:08:31 +03:30
parent e7b596005b
commit 07eb2e7d64
18 changed files with 237 additions and 185 deletions

View File

@@ -12,10 +12,10 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
export const AuthenticationSteps = (): JSX.Element => {
const navigate = useNavigate();
const DEFAULT_RETURN_URL = '/profile';
const [searchParams] = useSearchParams();
const authReturnUrl: string =
searchParams.get('returnUrl') ?? DEFAULT_RETURN_URL;
const authReturnUrl: string | null = searchParams.get('returnUrl');
const authReturnUrlOrDefault: string =
authReturnUrl ?? import.meta.env.VITE_DEFUALT_AUTH_RETURN_URL;
const [authMode, setAuthMode] = useState<AuthMode>('register');
const [authType, setAuthType] = useState<AuthType>('phone');
const [currentStep, setCurrentStep] = useState<AuthStep>('emailOrPhone');
@@ -66,8 +66,8 @@ export const AuthenticationSteps = (): JSX.Element => {
};
const redirectToReturnUrl = () => {
if (authReturnUrl === DEFAULT_RETURN_URL) {
navigate(DEFAULT_RETURN_URL);
if (!authReturnUrl) {
navigate(import.meta.env.VITE_DEFUALT_AUTH_RETURN_URL);
} else {
location.href = authReturnUrl;
}
@@ -77,7 +77,7 @@ export const AuthenticationSteps = (): JSX.Element => {
<>
{currentStep === 'emailOrPhone' && (
<LoginRegisterForm
authReturnUrl={authReturnUrl}
authReturnUrl={authReturnUrlOrDefault}
onGoogleAuthenticated={handleUserLoggedIn}
countryCode={countryCode}
setCountryCode={setCountryCode}
@@ -92,7 +92,7 @@ export const AuthenticationSteps = (): JSX.Element => {
{currentStep === 'verify' && (
<OtpVerifyForm
onVerifyPhoneNumber={handleConfrimPhoneNumber}
authReturnUrl={authReturnUrl}
authReturnUrl={authReturnUrlOrDefault}
countryCode={countryCode}
onOTPVerified={handleUserLoggedIn}
onEditValue={() => setCurrentStep('emailOrPhone')}
@@ -104,7 +104,7 @@ export const AuthenticationSteps = (): JSX.Element => {
{currentStep === 'enterPassword' && (
<EnterPasswordForm
authReturnUrl={authReturnUrl}
authReturnUrl={authReturnUrlOrDefault}
loginRegisterValue={loginRegisterValue}
countryCode={countryCode}
authType={authType}