fix build
This commit is contained in:
@@ -1,77 +0,0 @@
|
|||||||
import { FC } from 'react'
|
|
||||||
import Input from '../../../components/Input'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import { CheckHasAccountPhoneType } from '../types/AuthTypes'
|
|
||||||
import { useFormik } from 'formik'
|
|
||||||
import * as Yup from 'yup'
|
|
||||||
import { useAuthStore } from '../store/AuthStore'
|
|
||||||
import Error from '../../../components/Error'
|
|
||||||
import Button from '../../../components/Button'
|
|
||||||
import { useCheckHasAccountRegister, useLoginWithOtp } from '../hooks/useAuthData'
|
|
||||||
import { toast } from '../../../components/Toast'
|
|
||||||
import { ErrorType } from '../../../helpers/types'
|
|
||||||
|
|
||||||
const RegisterStep1: FC = () => {
|
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
|
||||||
const { setPhone, setStepLogin } = useAuthStore()
|
|
||||||
const loginWithOtp = useLoginWithOtp()
|
|
||||||
const checkHasAccount = useCheckHasAccountRegister()
|
|
||||||
|
|
||||||
const formik = useFormik<CheckHasAccountPhoneType>({
|
|
||||||
initialValues: {
|
|
||||||
phone: '',
|
|
||||||
},
|
|
||||||
validationSchema: Yup.object({
|
|
||||||
phone: Yup.string()
|
|
||||||
.required(t('errors.required'))
|
|
||||||
}),
|
|
||||||
onSubmit(values) {
|
|
||||||
checkHasAccount.mutate(values, {
|
|
||||||
onSuccess() {
|
|
||||||
setPhone(values.phone)
|
|
||||||
setStepLogin(2)
|
|
||||||
},
|
|
||||||
onError(error: ErrorType) {
|
|
||||||
toast(error?.response?.data?.error?.message[0], 'error')
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='flex-1'>
|
|
||||||
|
|
||||||
|
|
||||||
<div className='mt-16'>
|
|
||||||
<Input
|
|
||||||
label={t('auth.mobile_number')}
|
|
||||||
placeholder={t('auth.enter_mobile_number')}
|
|
||||||
type='tel'
|
|
||||||
className='text-right'
|
|
||||||
name='phone'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
value={formik.values.phone}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{
|
|
||||||
formik.touched.phone && formik.errors.phone &&
|
|
||||||
<Error
|
|
||||||
errorText={formik.errors.phone}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<Button
|
|
||||||
label={t('auth.next')}
|
|
||||||
className='mt-8'
|
|
||||||
onClick={() => formik.handleSubmit()}
|
|
||||||
isLoading={loginWithOtp.isPending || checkHasAccount.isPending}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default RegisterStep1
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
import { FC, Fragment } from 'react'
|
|
||||||
import { useFormik } from 'formik'
|
|
||||||
import { RegisterType } from '../types/AuthTypes'
|
|
||||||
import * as Yup from 'yup'
|
|
||||||
import { useAuthStore } from '../store/AuthStore'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import Input from '../../../components/Input'
|
|
||||||
import Button from '../../../components/Button'
|
|
||||||
import { useRegister } from '../hooks/useAuthData'
|
|
||||||
import { ErrorType } from '../../../helpers/types'
|
|
||||||
import { Pages } from '../../../config/Pages'
|
|
||||||
import { setToken } from '../../../config/func'
|
|
||||||
import { setRefreshToken } from '../../../config/func'
|
|
||||||
import { getRedirectUrl } from '../../../config/func'
|
|
||||||
import { toast } from '../../../components/Toast'
|
|
||||||
const RegisterStep2: FC = () => {
|
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
|
||||||
const { phone } = useAuthStore()
|
|
||||||
const register = useRegister()
|
|
||||||
|
|
||||||
const formik = useFormik<RegisterType>({
|
|
||||||
initialValues: {
|
|
||||||
firstName: '',
|
|
||||||
lastName: '',
|
|
||||||
code: 0,
|
|
||||||
password: '',
|
|
||||||
phone: phone,
|
|
||||||
},
|
|
||||||
validationSchema: Yup.object({
|
|
||||||
firstName: Yup.string()
|
|
||||||
.required(t('errors.required')),
|
|
||||||
lastName: Yup.string()
|
|
||||||
.required(t('errors.required')),
|
|
||||||
code: Yup.number()
|
|
||||||
.required(t('errors.required')),
|
|
||||||
password: Yup.string()
|
|
||||||
.required(t('errors.required')),
|
|
||||||
phone: Yup.string()
|
|
||||||
.required(t('errors.required')),
|
|
||||||
}),
|
|
||||||
onSubmit(values) {
|
|
||||||
register.mutate(values, {
|
|
||||||
onSuccess(data) {
|
|
||||||
setToken(data?.data?.accessToken?.token)
|
|
||||||
setRefreshToken(data?.data?.refreshToken?.token)
|
|
||||||
const redirectUrl = getRedirectUrl();
|
|
||||||
if (redirectUrl) {
|
|
||||||
window.location.href = redirectUrl;
|
|
||||||
return; // Prevent the default navigation
|
|
||||||
}
|
|
||||||
window.location.href = Pages.dashboard
|
|
||||||
},
|
|
||||||
onError(error: ErrorType) {
|
|
||||||
toast(error?.response?.data?.error?.message[0], 'error')
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Fragment>
|
|
||||||
<div className='mt-5 rowTwoInput'>
|
|
||||||
<Input
|
|
||||||
label={t('auth.name')}
|
|
||||||
placeholder={t('auth.enter_name')}
|
|
||||||
name='firstName'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
error_text={formik.touched.firstName && formik.errors.firstName ? formik.errors.firstName : ''}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Input
|
|
||||||
label={t('auth.family')}
|
|
||||||
placeholder={t('auth.enter_family')}
|
|
||||||
name='lastName'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
error_text={formik.touched.lastName && formik.errors.lastName ? formik.errors.lastName : ''}
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{/* <div className='mt-4 min-w-full rowTwoInput'>
|
|
||||||
<DatePickerComponent
|
|
||||||
label={t('auth.dateofbirth')}
|
|
||||||
onChange={(date: string) => formik.setFieldValue('birthDate', date)}
|
|
||||||
placeholder={t('auth.select_date')}
|
|
||||||
error_text={formik.touched.birthDate && formik.errors.birthDate ? formik.errors.birthDate : ''}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Input
|
|
||||||
label={t('auth.national_code')}
|
|
||||||
placeholder={t('auth.national_code_enter')}
|
|
||||||
name='nationalCode'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
error_text={formik.touched.nationalCode && formik.errors.nationalCode ? formik.errors.nationalCode : ''}
|
|
||||||
/>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
<div className='mt-4 rowTwoInput'>
|
|
||||||
<Input
|
|
||||||
label={t('auth.password')}
|
|
||||||
placeholder={t('auth.enter_password')}
|
|
||||||
type='password'
|
|
||||||
name='password'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
error_text={formik.touched.password && formik.errors.password ? formik.errors.password : ''}
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
label={t('auth.phonen_number')}
|
|
||||||
placeholder={t('auth.enter_phone_number')}
|
|
||||||
readOnly
|
|
||||||
value={phone}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='mt-4 rowTwoInput'>
|
|
||||||
<Input
|
|
||||||
label={t('auth.verify_code')}
|
|
||||||
placeholder={t('auth.enter_verify_code')}
|
|
||||||
type='tel'
|
|
||||||
name='code'
|
|
||||||
onChange={formik.handleChange}
|
|
||||||
error_text={formik.touched.code && formik.errors.code ? formik.errors.code : ''}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
label={t('auth.next')}
|
|
||||||
className='mt-8'
|
|
||||||
onClick={() => formik.handleSubmit()}
|
|
||||||
isLoading={register.isPending}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default RegisterStep2
|
|
||||||
Reference in New Issue
Block a user