This commit is contained in:
@@ -12,7 +12,7 @@ import { extractErrorMessage } from '@/config/func'
|
||||
|
||||
const LoginStep1: FC = () => {
|
||||
|
||||
const { phone, setPhone, setStepLogin } = useAuthStore()
|
||||
const { phone, setPhone, setStepLogin, setDevOtpCode } = useAuthStore()
|
||||
const loginWithOtp = useLoginWithOtp()
|
||||
const checkHasAccount = useCheckHasAccount()
|
||||
|
||||
@@ -27,7 +27,10 @@ const LoginStep1: FC = () => {
|
||||
onSubmit(values) {
|
||||
setPhone(values.phone_email)
|
||||
loginWithOtp.mutate({ phone: values.phone_email }, {
|
||||
onSuccess() {
|
||||
onSuccess(data) {
|
||||
// TODO: remove before production — dev-only OTP autofill
|
||||
const code = data?.data?.code
|
||||
if (code) setDevOtpCode(String(code))
|
||||
setStepLogin(2)
|
||||
toast('کد تایید ارسال شد', 'success')
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Paths } from '@/config/Paths'
|
||||
|
||||
const LoginStep2: FC = () => {
|
||||
|
||||
const { phone, setStepLogin } = useAuthStore()
|
||||
const { phone, setStepLogin, devOtpCode, setDevOtpCode } = useAuthStore()
|
||||
const { value, reset } = useCountDown(2, true)
|
||||
const otpVerify = useOtpVerify()
|
||||
const loginWithOtp = useLoginWithOtp()
|
||||
@@ -24,7 +24,8 @@ const LoginStep2: FC = () => {
|
||||
const formik = useFormik<OtpVerifyType>({
|
||||
initialValues: {
|
||||
phone: phone,
|
||||
otp: ''
|
||||
// TODO: remove before production — dev-only OTP autofill
|
||||
otp: devOtpCode,
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
otp: Yup.string()
|
||||
@@ -81,7 +82,14 @@ const LoginStep2: FC = () => {
|
||||
|
||||
const reSend = () => {
|
||||
loginWithOtp.mutate({ phone: phone }, {
|
||||
onSuccess: () => {
|
||||
onSuccess: (data) => {
|
||||
// TODO: remove before production — dev-only OTP autofill
|
||||
const code = data?.data?.code
|
||||
if (code) {
|
||||
const otp = String(code)
|
||||
setDevOtpCode(otp)
|
||||
formik.setFieldValue('otp', otp)
|
||||
}
|
||||
reset()
|
||||
toast('کد مجدد ارسال شد', 'success')
|
||||
},
|
||||
|
||||
@@ -14,4 +14,8 @@ export const useAuthStore = create<AuthStoreType>((set) => ({
|
||||
setStepLogin(value) {
|
||||
set({ stepLogin: value });
|
||||
},
|
||||
devOtpCode: "",
|
||||
setDevOtpCode(value) {
|
||||
set({ devOtpCode: value });
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -12,6 +12,9 @@ export type AuthStoreType = {
|
||||
setEmail: (value: string) => void;
|
||||
stepLogin: number;
|
||||
setStepLogin: (value: number) => void;
|
||||
/** TODO: remove before production — dev-only OTP from API response */
|
||||
devOtpCode: string;
|
||||
setDevOtpCode: (value: string) => void;
|
||||
};
|
||||
|
||||
export type LoginWithPasswordType = {
|
||||
|
||||
Reference in New Issue
Block a user