feat: simple impl
This commit is contained in:
@ -4,11 +4,14 @@ import { FC, useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button, Stack } from "@mantine/core";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { Auth } from "@/client";
|
||||
import PhoneInput from "@/components/PhoneInput/PhoneInput";
|
||||
import { useAppDispatch } from "@/lib/store";
|
||||
import { setLoginChallenge, setPhoneNumber } from "@/lib/features/auth/authSlice";
|
||||
import { AuthService } from "@/mocks/authService";
|
||||
import {
|
||||
setLoginChallenge,
|
||||
setPhoneNumber,
|
||||
} from "@/lib/features/auth/authSlice";
|
||||
import { notifications } from "@/lib/notifications";
|
||||
import { useAppDispatch } from "@/lib/store";
|
||||
|
||||
type LoginForm = {
|
||||
phoneNumber: string;
|
||||
@ -39,21 +42,39 @@ const LoginForm: FC<Props> = ({ loginChallenge, isCreatingId = false }) => {
|
||||
}, [loginChallenge]);
|
||||
|
||||
const handleSubmit = (values: LoginForm) => {
|
||||
dispatch(setPhoneNumber(values.phoneNumber));
|
||||
|
||||
new AuthService().requestLogin(values.phoneNumber)
|
||||
const phoneNumber = values.phoneNumber.replace(/ /g, "");
|
||||
dispatch(setPhoneNumber(phoneNumber));
|
||||
Auth.postAuthOtpRequest({
|
||||
body: { phone_number: phoneNumber },
|
||||
})
|
||||
.then(response => response.data)
|
||||
.then(({ ok, message }) => {
|
||||
if (!ok) {
|
||||
notifications.error({ message });
|
||||
} else {
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
if (!response) {
|
||||
notifications.error({
|
||||
message: "Ошибка при отправке запроса",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { ok, message } = response;
|
||||
notifications.guess(ok, { message });
|
||||
if (ok) {
|
||||
router.push("/verify-phone");
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
notifications.error({ message: error.toString() });
|
||||
})
|
||||
});
|
||||
// new AuthService().requestLogin(values.phoneNumber)
|
||||
// .then(response => response.data)
|
||||
// .then(({ ok, message }) => {
|
||||
// if (!ok) {
|
||||
// notifications.error({ message });
|
||||
// } else {
|
||||
// router.push("/verify-phone");
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// console.error(error);
|
||||
// notifications.error({ message: error.toString() });
|
||||
// })
|
||||
};
|
||||
|
||||
const navigateToCreateId = () => router.push("/create-id");
|
||||
|
||||
Reference in New Issue
Block a user