login
This commit is contained in:
@@ -6,4 +6,5 @@ export type LoginOTPRequestType = {
|
|||||||
export type LoginVerifyOTPType = {
|
export type LoginVerifyOTPType = {
|
||||||
phone: string;
|
phone: string;
|
||||||
otp: string;
|
otp: string;
|
||||||
|
slug: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,10 +36,9 @@ function StepEnterNumber() {
|
|||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
if (name) {
|
if (name) {
|
||||||
values.slug = name as string
|
values.slug = name as string
|
||||||
values.phone = 'abas'
|
|
||||||
mutateOtpRequest(values, {
|
mutateOtpRequest(values, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast(t('auth.otp_sent'))
|
toast(t('otp_sent'), 'success')
|
||||||
setStep(AUTH_STEP.ENTER_OTP)
|
setStep(AUTH_STEP.ENTER_OTP)
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
@@ -95,17 +94,21 @@ function StepEnterNumber() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{step === AUTH_STEP.ENTER_OTP && (
|
{step === AUTH_STEP.ENTER_OTP && (
|
||||||
<StepOtp phone={formik.values.phone} />
|
<StepOtp phone={formik.values.phone} slug={formik.values.slug} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
{
|
||||||
disabled={!formik.isValid}
|
step === AUTH_STEP.ENTER_NUMBER && (
|
||||||
pending={isPending}
|
<Button
|
||||||
type='button'
|
disabled={!formik.isValid}
|
||||||
onClick={() => formik.handleSubmit()}
|
pending={isPending}
|
||||||
>
|
type='button'
|
||||||
{t('Enter.ButtonSubmit')}
|
onClick={() => formik.handleSubmit()}
|
||||||
</Button>
|
>
|
||||||
|
{t('Enter.ButtonSubmit')}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,30 +6,38 @@ import * as Yup from 'yup'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useOtpVerify } from '@/app/auth/login/hooks/useAuthData'
|
import { useOtpVerify } from '@/app/auth/login/hooks/useAuthData'
|
||||||
import { toast } from '@/components/Toast'
|
import { toast } from '@/components/Toast'
|
||||||
|
import Button from '@/components/button/PrimaryButton'
|
||||||
|
import { extractErrorMessage } from '@/lib/func'
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
phone: string
|
phone: string,
|
||||||
|
slug: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const StepOtp = ({ phone }: Props) => {
|
const StepOtp = ({ phone, slug }: Props) => {
|
||||||
|
|
||||||
const { t } = useTranslation('auth')
|
const { t } = useTranslation('auth')
|
||||||
const { mutate: mutateOtpVerify } = useOtpVerify()
|
const { mutate: mutateOtpVerify, isPending } = useOtpVerify()
|
||||||
const formik = useFormik<LoginVerifyOTPType>({
|
const formik = useFormik<LoginVerifyOTPType>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
phone: phone,
|
phone: phone,
|
||||||
otp: ''
|
otp: '',
|
||||||
|
slug: slug
|
||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
otp: Yup.string().required(t('Errors.OTPRequired'))
|
otp: Yup.string().required(t('Errors.OTPRequired'))
|
||||||
}),
|
}),
|
||||||
onSubmit: (values) => {
|
onSubmit: (values) => {
|
||||||
mutateOtpVerify(values, {
|
mutateOtpVerify(values, {
|
||||||
onSuccess: () => {
|
onSuccess: (data) => {
|
||||||
toast(t('auth.otp_verified'))
|
toast(t('otp_verified'), 'success')
|
||||||
|
localStorage.setItem(process.env.NEXT_PUBLIC_TOKEN_NAME as string, data?.data?.tokens?.accessToken?.token as string)
|
||||||
|
localStorage.setItem(process.env.NEXT_PUBLIC_REFRESH_TOKEN_NAME as string, data?.data?.tokens?.refreshToken?.token as string)
|
||||||
|
window.location.href = `/${slug}`
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.log(error)
|
toast(extractErrorMessage(error), 'error')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -49,9 +57,19 @@ const StepOtp = ({ phone }: Props) => {
|
|||||||
type='tel'
|
type='tel'
|
||||||
autoComplete="one-time-code"
|
autoComplete="one-time-code"
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
className='w-full h-[45px] sm:h-[50px] flex-1 mx-1 sm:mx-2 bg-white border border-gray-300 outline-0 rounded-[10px] text-center text-lg sm:text-xl' />
|
className='w-full h-[45px] sm:h-[50px] flex-1 mx-1 sm:mx-2 bg-white border border-gray-300 outline-0 rounded-[10px] text-center text-sm' />
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className='mt-10'
|
||||||
|
disabled={!formik.isValid}
|
||||||
|
pending={isPending}
|
||||||
|
type='button'
|
||||||
|
onClick={() => formik.handleSubmit()}
|
||||||
|
>
|
||||||
|
{t('OTP.ButtonSubmit')}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
"LabelRememberance": "مرا به خاطر بسپار",
|
"LabelRememberance": "مرا به خاطر بسپار",
|
||||||
"ButtonSubmit": "ورود به منو"
|
"ButtonSubmit": "ورود به منو"
|
||||||
},
|
},
|
||||||
|
"otp_sent": "کد فعالسازی ارسال شد.",
|
||||||
|
"otp_verified": "کد فعالسازی با موفقیت تأیید شد.",
|
||||||
"Errors": {
|
"Errors": {
|
||||||
"PasswordLength": "کلمه عبور باید شامل حداقل 6 کاراکتر باشد",
|
"PasswordLength": "کلمه عبور باید شامل حداقل 6 کاراکتر باشد",
|
||||||
"PasswordMatch": "تکرار کلمه عبور مطابقت ندارد",
|
"PasswordMatch": "تکرار کلمه عبور مطابقت ندارد",
|
||||||
|
|||||||
Reference in New Issue
Block a user