add: bring back previously disabled api calls

This commit is contained in:
Mahyar Khanbolooki
2025-07-03 19:09:03 +03:30
parent a5d2e9cf72
commit f4f3544597
2 changed files with 83 additions and 74 deletions
+82 -73
View File
@@ -10,12 +10,12 @@ import { AUTH_PAGE_ELEMENT, AUTH_STEP } from '@/enums';
import { useCountdown } from '@/hooks/useCountdown'; import { useCountdown } from '@/hooks/useCountdown';
import StepNewPassword from '@/features/auth/components/StepNewPassword'; import StepNewPassword from '@/features/auth/components/StepNewPassword';
import AuthFormWrapper from '@/features/auth/components/AuthFormWrapper'; import AuthFormWrapper from '@/features/auth/components/AuthFormWrapper';
// import { useLogin } from '@/hooks/auth/useLogin'; import { useLogin } from '@/hooks/auth/useLogin';
// import { useSignup } from '@/hooks/auth/useSignup'; import { useSignup } from '@/hooks/auth/useSignup';
// import { useCheckUserExistsLazy } from '@/hooks/auth/useCheckUserExists'; import { useCheckUserExistsLazy } from '@/hooks/auth/useCheckUserExists';
// import { useOtpRequest } from '@/hooks/auth/useOtpRequest'; import { useOtpRequest } from '@/hooks/auth/useOtpRequest';
// import { useOtpValidation } from '@/hooks/auth/useOtpValidation'; import { useOtpValidation } from '@/hooks/auth/useOtpValidation';
// import { useResetPassword } from '@/hooks/auth/useResetPassword'; import { useResetPassword } from '@/hooks/auth/useResetPassword';
type Props = object type Props = object
@@ -32,12 +32,12 @@ function AuthIndex({ }: Props) {
const { timerRunning, secondsLeft, restart, stop } = useCountdown(step === AUTH_STEP.ENTER_OTP); const { timerRunning, secondsLeft, restart, stop } = useCountdown(step === AUTH_STEP.ENTER_OTP);
const isAuthenticated = useAuthStore((state) => state.isAuthenticated) const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
// const loginMutation = useLogin() const loginMutation = useLogin()
// const signupMutation = useSignup() const signupMutation = useSignup()
// const { run: runUserExistCheck } = useCheckUserExistsLazy() const { run: runUserExistCheck } = useCheckUserExistsLazy()
// const { run: runOtpRequest } = useOtpRequest(); const { run: runOtpRequest } = useOtpRequest();
// const { run: runOtpValidation } = useOtpValidation(); const { run: runOtpValidation } = useOtpValidation();
// const { run: runResetPassword } = useResetPassword(); const { run: runResetPassword } = useResetPassword();
const resetStates = () => { const resetStates = () => {
setNumber(''); setNumber('');
@@ -59,7 +59,7 @@ function AuthIndex({ }: Props) {
useEffect(() => { useEffect(() => {
if (step === AUTH_STEP.ENTER_OTP) { if (step === AUTH_STEP.ENTER_OTP) {
console.log("REQUEST OTP") console.log("REQUEST OTP")
// runOtpRequest(number); runOtpRequest(number);
} }
}, [step]); }, [step]);
@@ -81,7 +81,7 @@ function AuthIndex({ }: Props) {
const prev = otp.padEnd(6).split(''); const prev = otp.padEnd(6).split('');
prev[index] = e.target.value; prev[index] = e.target.value;
const next = prev.join(''); const next = prev.join('');
if(otp.length >= 6 && next.trim().length >= otp.length) return; if (otp.length >= 6 && next.trim().length >= otp.length) return;
setOtp(next.trimEnd()); setOtp(next.trimEnd());
} }
} }
@@ -97,82 +97,91 @@ function AuthIndex({ }: Props) {
setShowPasswordRepeat((state) => !state); setShowPasswordRepeat((state) => !state);
} }
else if (target.id === AUTH_PAGE_ELEMENT.RESET_PASSWORD) { else if (target.id === AUTH_PAGE_ELEMENT.RESET_PASSWORD) {
setShowPassword(false);
setShowPasswordRepeat(false);
setPassword('');
setPasswordRepeat('');
setStep(() => AUTH_STEP.ENTER_OTP) setStep(() => AUTH_STEP.ENTER_OTP)
} }
else if (target.id === AUTH_PAGE_ELEMENT.RESEND_OTP) { else if (target.id === AUTH_PAGE_ELEMENT.RESEND_OTP) {
if (!timerRunning) { if (!timerRunning) {
try { try {
// await runOtpRequest(number); await runOtpRequest(number);
restart(); restart();
} catch { } catch {
console.error("Could not ask for otp")
} }
} }
} }
}; };
const onSubmit = async (e: FormEvent<HTMLFormElement>) => { const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
console.log(step);
e.preventDefault(); e.preventDefault();
setIsPending(true); try {
if (step == AUTH_STEP.ENTER_NUMBER) { setIsPending(true);
if (step == AUTH_STEP.ENTER_NUMBER) {
if (true) { if (await runUserExistCheck(number)) {
setStep(AUTH_STEP.ENTER_PASSWORD) setStep(AUTH_STEP.ENTER_PASSWORD)
} else { } else {
setStep(AUTH_STEP.ENTER_OTP); setStep(AUTH_STEP.ENTER_OTP);
}
} }
else if (step == AUTH_STEP.ENTER_PASSWORD) {
try {
await loginMutation.mutateAsync({ phone: number, password })
console.log("Logged in")
redirect("/")
}
catch (e) {
console.error("Wrong credentials: ", e)
}
}
else if (step == AUTH_STEP.ENTER_OTP) {
if (!await runOtpValidation({ phone: number, otp })) {
setOtp('');
console.error('Wrong otp');
}
stop();
console.log(await runUserExistCheck(number));
if (await runUserExistCheck(number)) {
console.log("1")
setStep(AUTH_STEP.ENTER_RESET_PASSWORD)
} else {
console.log("2")
setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
}
}
else if (step == AUTH_STEP.ENTER_RESET_PASSWORD) {
console.log("Password changed")
try {
await runResetPassword({
phone: number,
newPassword: password,
otp
})
resetStates();
setStep(AUTH_STEP.ENTER_NUMBER)
} catch (ex) {
console.error('Password reset failed: ', ex)
}
}
else if (step == AUTH_STEP.ENTER_NEW_PASSWORD) {
try {
await signupMutation.mutateAsync({ phone: number, password })
console.log("Signed up")
redirect("/")
}
catch (e) {
console.error("Could not signup: ", e)
}
}
} catch (ex) {
console.error(ex)
} finally {
setIsPending(false);
} }
else if (step == AUTH_STEP.ENTER_PASSWORD) {
try {
// await loginMutation.mutateAsync({ phone: number, password })
useAuthStore.getState().isAuthenticated = true;
console.log("Logged in")
redirect("/")
}
catch (e) {
console.log("Wrong credentials: ", e)
}
}
else if (step == AUTH_STEP.ENTER_OTP) {
// if (!await runOtpValidation({ phone: number, otp })) {
// setOtp('');
// console.log('Wrong otp');
// }
setOtp('');
stop();
// if (await runUserExistCheck(number)) {
// setStep(AUTH_STEP.ENTER_RESET_PASSWORD)
// } else {
// setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
// }
setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
}
else if (step == AUTH_STEP.ENTER_RESET_PASSWORD) {
console.log("Password changed")
try {
// await runResetPassword({
// phone: number,
// newPassword: password,
// otp
// })
resetStates();
setStep(AUTH_STEP.ENTER_NUMBER)
} catch (ex) {
console.error('Password reset failed: ', ex)
}
}
else if (step == AUTH_STEP.ENTER_NEW_PASSWORD) {
try {
// await signupMutation.mutateAsync({ phone: number, password })
useAuthStore.getState().isAuthenticated = true;
console.log("Signed up")
redirect("/")
}
catch (e) {
console.log("Could not signup: ", e)
}
}
setIsPending(false);
} }
const stepMap = { const stepMap = {
@@ -10,7 +10,7 @@ function AuthFormWrapper({ children, isPending, ...restProps }: Props) {
<form {...restProps} className='p-6 lg:py-[75px] w-full flex items-center justify-center py-4 lg:items-center lg:px-10 px-4 drop-shadow-black h-full'> <form {...restProps} className='p-6 lg:py-[75px] w-full flex items-center justify-center py-4 lg:items-center lg:px-10 px-4 drop-shadow-black h-full'>
<div className='relative h-full w-full px-4 sm:px-6 lg:p-0 flex flex-col max-h-[812px] max-w-[1200px] bg-container rounded-container overflow-clip lg:flex-row justify-between'> <div className='relative h-full w-full px-4 sm:px-6 lg:p-0 flex flex-col max-h-[812px] max-w-[1200px] bg-container rounded-container overflow-clip lg:flex-row justify-between'>
{children} {children}
<LoadingOverlay visible={isPending} /> <LoadingOverlay visible={isPending} bgOpacity={0} />
</div> </div>
</form> </form>
) )