/** * LUMI版本Register页面 * @邠心vbe on 2024/05/31 */ import React, { Component } from 'react'; import { View, ScrollView, StyleSheet, TextInput, Pressable } from 'react-native'; import apiUser from '../../api/apiUser'; import Button from '../../components/Button'; import { PageList } from '../Router'; import Dialog from '../../components/Dialog'; import Dropdown from '../../components/Dropdown'; import { CountryDropNum, GetCountryList } from '../../components/CountryIcon'; import CheckBox from '../../components/CheckBox'; import TextView from '../../components/TextView'; import utils from '../../utils/utils'; export default class RegisterVL extends Component { constructor(props) { super(props); this.state = { agree: true, countryNum: '65', countryCode: "SG", userInfo: { email: "", phone: "", vehicle: {}, password: "", verificationCode: "" }, countryList: [], params: {...this.props.route.params}, email: '', password: '', sendMinutes: 0, strengthCheck: { minLength: false, wordCase: false, oneNumber: false, allCheck: false }, showPassword: false }; } componentDidMount() { this.getCountryList(); } togglePassword() { this.setState({ showPassword: !this.state.showPassword }) } applyStrength(text) { const strength = this.state.strengthCheck; strength.allCheck = true; if (text.length >= 8) { strength.minLength = true; } else { strength.minLength = false; strength.allCheck = false; } if (/\d{1,}/.test(text)) { strength.oneNumber = true; } else { strength.oneNumber = false; strength.allCheck = false; } if (/[a-z]{1,}/.test(text) && /[A-Z]{1,}/.test(text)) { strength.wordCase = true; } else { strength.wordCase = false; strength.allCheck = false; } this.setState({ password: text, strengthCheck: strength }); } changeInfo(key, value) { var info = this.state.userInfo; info[key] = value; this.setState({ 'userInfo': info }); } changeAgree(ag) { this.setState({ agree: ag }) } changeCountry(value, index) { this.setState({ countryCode: value }) if (this.canChangeCalling) { const country = this.state.countryList[index] this.changeCalling(country.countryNum, -1); } } changeCalling(value, index) { this.setState({ countryNum: value }) if (index >= 0) { this.canChangeCalling = false; } } getCountryList() { GetCountryList(list => { this.setState({ countryList: list }) }) } sendVerification() { var info = this.state.userInfo; if (!info.email) { toastShort($t('sign.plsInputEmail')); return; } if (!utils.isValidEmail(info.email)) { toastShort($t('sign.errEmailFormat')); return; } Dialog.showProgressDialog() apiUser.sendVerificationCodeV2({email: info.email, type: "register"}).then(res => { Dialog.dismissLoading() //this.state.sendMinutes = 60; this.state.sendMinutes = res.data?.resendTime ?? 60; toastShort($t('sign.sendOTPSuccess')); this.contdownTime(); }).catch(err => { Dialog.dismissLoading() toastShort(err); }); } contdownTime() { if (this.state.sendMinutes > 0) { this.setState({ sendMinutes: this.state.sendMinutes - 1 }) setTimeout(() => { this.contdownTime(); }, 1000); } } onRegister() { //console.log('sign up', this.state); var info = this.state.userInfo; if (!info.nickName) { toastShort($t('sign.plsInputDiaplayName')); return; } if (!info.email) { toastShort($t('sign.plsInputEmail')); return; } if (!utils.isValidEmail(info.email)) { toastShort($t('sign.errEmailFormat')); return; } /*if (!info.verificationCode) { toastShort($t('sign.plsInputOTP')); return; }*/ if (!info.phone) { toastShort($t('sign.plsInputContactNo')); return; } if (!/^\d{6,15}$/.test(info.phone)) { toastShort($t('sign.errContactNoFormat')); return; } if (!this.state.password) { toastShort($t('sign.plsInputPassword')); return; } if (!this.state.strengthCheck.allCheck) { toastShort($t('sign.errPasswordStrong')); return; } if (!info.password) { toastShort($t('sign.plsInputPassword2')); return; } if (info.password != this.state.password) { toastShort($t('sign.errPasswordConfirm')); return; } if (this.state.isFleetDriver) { if (!info.pdvLicence) { toastShort($t('sign.plsInputPDVLicence')); return; } if (this.state.pdvImages[0] == '' || this.state.pdvImages[1] == '') { toastShort($t('sign.plsUploadLicencePhotos')); return; } } let param = Object.assign({}, info); //param.phone = this.state.countryNum + info.phone param.callingCode = this.state.countryNum; param.countryCode = this.state.countryCode; if (this.state.isFleetDriver) { param.userType = 'Driver'; param.pdvLicencePictures = this.state.pdvImages; param.fleetCompanyId = this.state.fleetCompanyId; } else { param.userType = 'Public'; } param.otp = param.verificationCode; param.vehicle = this.state.vehicleInfo; console.log('params', param); Dialog.showProgressDialog(); apiUser.register(param).then(res => { Dialog.dismissLoading(); //toastShort('Sign up successfully!'); if (isIOS) { setTimeout(() => { this.showSuccessDialog(); }, 600); } else { this.showSuccessDialog(); } }).catch(err => { toastShort(err); Dialog.dismissLoading(); }); } render() { return ( {/* Registration details Please input relevant info as stated */} this.changeInfo('nickName', v)} /> this.changeInfo('email', v)} /> {/* this.changeInfo('verificationCode', v)} />