|
|
@@ -33,6 +33,8 @@ const i18n=global.i18n;
|
|
|
const TYPE_LOGIN="login";
|
|
|
const TYPE_REGISTER="register";
|
|
|
|
|
|
+const LOGIN_TYPE_PASS=0;
|
|
|
+const LOGIN_TYPE_OTP=1;
|
|
|
|
|
|
const LoginForm = ({close}) => {
|
|
|
const {theme,isMobile} = useThemeProvider();
|
|
|
@@ -44,6 +46,7 @@ const LoginForm = ({close}) => {
|
|
|
const regStatus=useSelector(getRegStatus);
|
|
|
const dispatch = useDispatch();
|
|
|
const navigate=useNavigate();
|
|
|
+ const [loginType,setLoginType]=useState(LOGIN_TYPE_PASS);
|
|
|
const {register, handleSubmit, formState: {errors}, control} = useForm({
|
|
|
defaultValues: {
|
|
|
// country:'55',
|
|
|
@@ -51,7 +54,8 @@ const LoginForm = ({close}) => {
|
|
|
password: '',
|
|
|
email:"",
|
|
|
repassword:"",
|
|
|
- lang:""
|
|
|
+ lang:"",
|
|
|
+ code:""
|
|
|
}
|
|
|
});
|
|
|
const {pathname,hash} = useLocation();
|
|
|
@@ -107,68 +111,150 @@ const LoginForm = ({close}) => {
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
- const renderLoginForm=()=>{
|
|
|
+ const renderLoginToReg=()=>{
|
|
|
return (
|
|
|
- <Spring type="slideUp" >
|
|
|
+ <div className={styles.l_reg_new}>
|
|
|
+ <div>{i18n.t("login.reg_new_des")}</div>
|
|
|
+ <div className={styles.reg_btn} onClick={() => {
|
|
|
+ // setShowType(TYPE_REGISTER);
|
|
|
+ if (isMobile()) navigatRoute(ROUTE_PATH.SIGN_UP)
|
|
|
+ else setShowType(TYPE_REGISTER);
|
|
|
+ }}>
|
|
|
+ {i18n.t("sign_up")}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ const renderGuestLogin=()=>{
|
|
|
+ return (
|
|
|
+ <button type={"button"} className={styles.guest_btn}>
|
|
|
+ {i18n.t("login.guest_login")}
|
|
|
+ </button>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ const renderPassLogin = () => {
|
|
|
+ return (
|
|
|
+ <form autoComplete="off" className={styles.l_form} onSubmit={handleSubmit((data) => {
|
|
|
+ onSubmitLogin(data);
|
|
|
+ })}>
|
|
|
+ <Controller control={control}
|
|
|
+ name="account"
|
|
|
+ rules={{required: true}}
|
|
|
+ render={({field: {ref, onChange, value}, fieldState: {error}}) => {
|
|
|
+ let message = error ? i18n.t("form_errors.phone_" + country) : "";
|
|
|
+ return (<PhoneInput
|
|
|
+ className={classNames({'input-control--error': error})}
|
|
|
+ value={value}
|
|
|
+ message={message}
|
|
|
+ onChange={e => onChange(e.target.value)}
|
|
|
+ onChangeCountry={(country) => {
|
|
|
+ setCountry(country);
|
|
|
+ }}
|
|
|
+ placeholder={i18n.t('login.phone_ph')}
|
|
|
+ innerRef={ref}/>)
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Controller control={control}
|
|
|
+ name="password"
|
|
|
+ rules={{required: true, minLength: 6}}
|
|
|
+ render={({field: {ref, onChange, value}, fieldState: {error}}) => (
|
|
|
+ <PasswordInput
|
|
|
+ className={classNames({'input-control--error': error})}
|
|
|
+ value={value}
|
|
|
+ message={error ? i18n.t("form_errors.pass") : ''}
|
|
|
+ onChange={e => onChange(e.target.value)}
|
|
|
+ placeholder={i18n.t('login.login_pwd')}
|
|
|
+ innerRef={ref}/>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ <button className={"button-green"}>
|
|
|
+ {
|
|
|
+ loginStatus === REQ_STATUS.LOADING ? renderLoading() : i18n.t("login.sign_in_btn")
|
|
|
+ }
|
|
|
+ </button>
|
|
|
+ {renderGuestLogin()}
|
|
|
+ {renderLoginToReg()}
|
|
|
+ </form>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ const renderOTPLogin=()=>{
|
|
|
+ return (
|
|
|
+ <form autoComplete="off" className={styles.l_form} onSubmit={handleSubmit((data) => {
|
|
|
+ onSubmitLogin(data);
|
|
|
+ })}>
|
|
|
+ <Controller control={control}
|
|
|
+ name="account"
|
|
|
+ rules={{required: true}}
|
|
|
+ render={({field: {ref, onChange, value}, fieldState: {error}}) => {
|
|
|
+ let message = error ? i18n.t("form_errors.phone_" + country) : "";
|
|
|
+ return (<PhoneInput
|
|
|
+ className={classNames({'input-control--error': error})}
|
|
|
+ value={value}
|
|
|
+ message={message}
|
|
|
+ onChange={e => onChange(e.target.value)}
|
|
|
+ onChangeCountry={(country) => {
|
|
|
+ setCountry(country);
|
|
|
+ }}
|
|
|
+ placeholder={i18n.t('login.phone_ph')}
|
|
|
+ innerRef={ref}/>)
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Controller control={control}
|
|
|
+ name="code"
|
|
|
+ rules={{required: true}}
|
|
|
+ render={({field: {ref, onChange, value}, fieldState: {error}}) => {
|
|
|
+ return (
|
|
|
+ <div className={`d-flex flex-column g-6`}>
|
|
|
+ <div
|
|
|
+ className={`input-control ${classNames({'input-control--error': error})}`}>
|
|
|
+ <input
|
|
|
+ type={'text'}
|
|
|
+ autoComplete="off"
|
|
|
+ ref={ref}
|
|
|
+ onChange={e => onChange(e.target.value)}
|
|
|
+ placeholder={i18n.t('login.otp_ph')}
|
|
|
+ />
|
|
|
+ <button type={"button"} className={styles.otp_btn}>OTP</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <button className={"button-green"}>
|
|
|
+ {
|
|
|
+ loginStatus === REQ_STATUS.LOADING ? renderLoading() : i18n.t("login.sign_in_btn")
|
|
|
+ }
|
|
|
+ </button>
|
|
|
+ {renderGuestLogin()}
|
|
|
+ {renderLoginToReg()}
|
|
|
+ </form>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ const renderLoginForm = () => {
|
|
|
+ return (
|
|
|
+ <Spring type="slideUp">
|
|
|
<div className={styles.l_title}>{i18n.t("login.login_title")}</div>
|
|
|
- <form autoComplete="off" className={styles.l_form} onSubmit={handleSubmit((data) => {
|
|
|
- onSubmitLogin(data);
|
|
|
- })}>
|
|
|
- <Controller control={control}
|
|
|
- name="account"
|
|
|
- rules={{required: true}}
|
|
|
- render={({field: {ref, onChange, value}, fieldState: {error}}) => {
|
|
|
- let message=error?i18n.t("form_errors.phone_"+country):"";
|
|
|
- return (<PhoneInput
|
|
|
- className={classNames({'input-control--error': error})}
|
|
|
- value={value}
|
|
|
- message={message}
|
|
|
- onChange={e => onChange(e.target.value)}
|
|
|
- onChangeCountry={(country)=>{
|
|
|
- setCountry(country);
|
|
|
- }}
|
|
|
- placeholder={i18n.t('login.phone_ph')}
|
|
|
- innerRef={ref}/>)
|
|
|
- }}
|
|
|
- />
|
|
|
- <Controller control={control}
|
|
|
- name="password"
|
|
|
- rules={{required: true,minLength:6}}
|
|
|
- render={({field: {ref, onChange, value}, fieldState: {error}}) => (
|
|
|
- <PasswordInput
|
|
|
- className={classNames({'input-control--error': error})}
|
|
|
- value={value}
|
|
|
- message={error?i18n.t("form_errors.pass"):''}
|
|
|
- onChange={e => onChange(e.target.value)}
|
|
|
- placeholder={i18n.t('login.login_pwd')}
|
|
|
- innerRef={ref}/>
|
|
|
- )}
|
|
|
- />
|
|
|
- {/*<div className={styles.l_forgot}>*/}
|
|
|
- {/* <button className={styles.forgot_btn}>*/}
|
|
|
- {/* {i18n.t("login.forgot")}*/}
|
|
|
- {/* </button>*/}
|
|
|
- {/*</div>*/}
|
|
|
- <button className={"button-green"}>
|
|
|
- {
|
|
|
- loginStatus===REQ_STATUS.LOADING?renderLoading():i18n.t("login.sign_in_btn")
|
|
|
- }
|
|
|
+ <div className={styles.l_type_tabs}>
|
|
|
+ <button className={`${styles.l_type_btn} ${loginType === LOGIN_TYPE_PASS ? styles.active : ''}`}
|
|
|
+ onClick={() => {
|
|
|
+ setLoginType(LOGIN_TYPE_PASS)
|
|
|
+ }}>
|
|
|
+ <span>{i18n.t("login.login_type.password")}</span>
|
|
|
</button>
|
|
|
- <div className={styles.l_reg_new}>
|
|
|
- <div>{i18n.t("login.reg_new_des")}</div>
|
|
|
- <div className={styles.reg_btn} onClick={()=>{
|
|
|
- // setShowType(TYPE_REGISTER);
|
|
|
- if(isMobile())navigatRoute(ROUTE_PATH.SIGN_UP)
|
|
|
- else setShowType(TYPE_REGISTER);
|
|
|
- }}>
|
|
|
- {i18n.t("sign_up")}
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </form>
|
|
|
+ <button className={`${styles.l_type_btn} ${loginType === LOGIN_TYPE_OTP ? styles.active : ''}`}
|
|
|
+ onClick={() => {
|
|
|
+ setLoginType(LOGIN_TYPE_OTP)
|
|
|
+ }}>
|
|
|
+ <span>{i18n.t("login.login_type.otp")}</span>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ {
|
|
|
+ loginType===LOGIN_TYPE_PASS?renderPassLogin():renderOTPLogin()
|
|
|
+ }
|
|
|
</Spring>
|
|
|
)
|
|
|
}
|
|
|
- const renderRegisterForm=()=>{
|
|
|
+ const renderRegisterForm = () => {
|
|
|
return (
|
|
|
<Spring type="slideUp">
|
|
|
<div className={styles.l_title}>{i18n.t("login.reg_title")}</div>
|
|
|
@@ -177,15 +263,15 @@ const LoginForm = ({close}) => {
|
|
|
})}>
|
|
|
<Controller control={control}
|
|
|
name="account"
|
|
|
- rules={{required: true,validate:validatePhone}}
|
|
|
+ rules={{required: true, validate: validatePhone}}
|
|
|
render={({field: {ref, onChange, value}, fieldState: {error}}) => {
|
|
|
- let message=error?i18n.t("form_errors.phone_"+country):"";
|
|
|
+ let message = error ? i18n.t("form_errors.phone_" + country) : "";
|
|
|
return (<PhoneInput
|
|
|
className={classNames({'input-control--error': error})}
|
|
|
value={value}
|
|
|
message={message}
|
|
|
onChange={e => onChange(e.target.value)}
|
|
|
- onChangeCountry={(country)=>{
|
|
|
+ onChangeCountry={(country) => {
|
|
|
setCountry(country);
|
|
|
}}
|
|
|
placeholder={i18n.t('login.phone_ph')}
|
|
|
@@ -194,12 +280,12 @@ const LoginForm = ({close}) => {
|
|
|
/>
|
|
|
<Controller control={control}
|
|
|
name="password"
|
|
|
- rules={{required: true,minLength:6}}
|
|
|
+ rules={{required: true, minLength: 6}}
|
|
|
render={({field: {ref, onChange, value}, fieldState: {error}}) => (
|
|
|
<PasswordInput
|
|
|
className={classNames({'input-control--error': error})}
|
|
|
value={value}
|
|
|
- message={error?i18n.t("form_errors.pass"):''}
|
|
|
+ message={error ? i18n.t("form_errors.pass") : ''}
|
|
|
onChange={e => onChange(e.target.value)}
|
|
|
placeholder={i18n.t('login.login_pwd')}
|
|
|
innerRef={ref}/>
|