Registor.js 4.43 KB
Newer Older
Giang Tran committed
1
import React, {useState} from 'react';
Giang Tran committed
2 3 4 5 6 7 8 9
import {
  View,
  Text,
  StyleSheet,
  Image,
  TouchableOpacity,
  Alert,
} from 'react-native';
Giang Tran committed
10 11 12
import InputIcon from '../../components/Input/InputIcon';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R';
Giang Tran committed
13 14 15
import {checkFormatArray} from '../../Config/Functions';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux';
Giang Tran committed
16
import {registorApi, getOTPApi} from '../../apis/Functions/users';
Giang Tran committed
17
import I18n from '../../helper/i18/i18n';
Giang Tran committed
18
import AppText from '../../components/AppText';
Giang Tran committed
19
import {REGISTEROTP} from '../../routers/ScreenNames';
Giang Tran committed
20
import {showAlert, TYPE} from '../../components/DropdownAlert';
Giang Tran committed
21 22 23

const Registor = (props) => {
  const {navigation} = props;
Giang Tran committed
24 25 26 27

  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const [password_confirmation, setPasswordConfirm] = useState('');
Giang Tran committed
28
  const [sponsor_id, setSponsor_id] = useState('');
Giang Tran committed
29
  const [phone, setPhone] = useState('');
Giang Tran committed
30 31

  const registorClick = async () => {
Giang Tran committed
32 33 34 35 36 37 38 39 40 41 42 43
    const titles = [
      'email',
      I18n.t('Password').toLowerCase(),
      I18n.t('ConfirmPassword').toLowerCase(),
      I18n.t('Phone').toLowerCase(),
    ];
    const index = checkFormatArray([
      email,
      password,
      password_confirmation,
      phone,
    ]);
Giang Tran committed
44

Giang Tran committed
45
    if (index === true) {
Giang Tran committed
46
      props.showLoading();
Giang Tran committed
47 48 49
      const res = await getOTPApi({
        platform: Platform.OS,
        otp_by: email,
Giang Tran committed
50
        type: 'CUSTOMER_REGISTER',
Giang Tran committed
51 52 53 54 55
      });
      props.hideLoading();
      console.log(res);
      if (res.data.code == 200) {
        navigation.navigate(REGISTEROTP, {
Giang Tran committed
56 57 58
          email,
          password,
          password_confirmation,
Giang Tran committed
59
          phone,
Giang Tran committed
60
          sponsor_id,
Giang Tran committed
61
        });
Giang Tran committed
62
      } else {
Giang Tran committed
63
        showAlert(TYPE.ERROR, I18n.t('Notification'), res.data.message);
Giang Tran committed
64 65
      }
    } else {
Giang Tran committed
66 67
      showAlert(
        TYPE.ERROR,
Giang Tran committed
68 69 70
        I18n.t('Notification'),
        I18n.t('Please_fill_in') + titles[index],
      );
Giang Tran committed
71 72
    }
  };
Giang Tran committed
73

Giang Tran committed
74 75 76 77 78 79 80 81 82 83
  return (
    <View
      style={{
        flex: 1,
        paddingHorizontal: 20,
        paddingTop: 20,
        backgroundColor: 'white',
      }}>
      <InputIcon
        icon={R.images.iconEmail}
Giang Tran committed
84
        title={'Email'}
Giang Tran committed
85
        onChangeText={(val) => setEmail(val)}
Giang Tran committed
86
      />
Giang Tran committed
87

Giang Tran committed
88 89
      <InputIcon
        icon={R.images.iconLock}
Giang Tran committed
90
        title={'Password'}
Giang Tran committed
91 92
        onChangeText={(val) => setPassword(val)}
        isPassWord={true}
Giang Tran committed
93 94 95
      />
      <InputIcon
        icon={R.images.iconLock}
Giang Tran committed
96
        title={'Confirm_pass'}
Giang Tran committed
97 98
        onChangeText={(val) => setPasswordConfirm(val)}
        isPassWord={true}
Giang Tran committed
99
      />
Giang Tran committed
100 101 102 103 104 105
      <InputIcon
        icon={R.images.iconPhone3}
        title={'Phone'}
        onChangeText={(val) => setPhone(val)}
        isNumber={true}
      />
Giang Tran committed
106 107
      <InputIcon
        icon={R.images.iconIntroduct}
Giang Tran committed
108
        title={'Code_introduce'}
Giang Tran committed
109 110
        onChangeText={(val) => setSponsor_id(val)}
      />
Giang Tran committed
111 112 113

      <View
        style={{
Giang Tran committed
114
          marginTop: 30,
Giang Tran committed
115 116
          alignItems: 'center',
        }}>
Giang Tran committed
117
        <TouchableOpacity onPress={registorClick} style={styles.wrapLogin}>
Giang Tran committed
118
          <AppText i18nKey={'Register'} style={styles.txtLogin} />
Giang Tran committed
119
          <Image source={R.images.iconRight1} style={styles.imgIcon} />
Giang Tran committed
120
        </TouchableOpacity>
Giang Tran committed
121 122

        <View style={styles.row}>
Giang Tran committed
123
          <AppText i18nKey={'Account_already'} style={styles.txtTitle} />
Giang Tran committed
124 125 126 127
          <TouchableOpacity
            onPress={() => {
              navigation.navigate('LOGIN');
            }}>
Giang Tran committed
128
            <AppText i18nKey={'Login'} style={styles.txtRegistor} />
Giang Tran committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
          </TouchableOpacity>
        </View>
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  forgotView: {
    marginVertical: 20,
    alignItems: 'flex-end',
  },
  txtTitle: {
    fontSize: getFontXD(42),
    color: '#929292',
  },
  txtLogin: {
    fontSize: getFontXD(48),
    color: 'white',
    fontWeight: '700',
  },
  wrapLogin: {
    width: WIDTHXD(512),
    height: HEIGHTXD(150),
    backgroundColor: '#1C6AF6',
    borderRadius: 30,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
  },
  imgIcon: {
    width: WIDTHXD(72),
    height: HEIGHTXD(72),
    marginLeft: 5,
  },
  row: {
    flexDirection: 'row',
    marginTop: 30,
  },
  txtRegistor: {
    fontSize: getFontXD(42),
    color: '#1473E6',
  },
});

Giang Tran committed
174 175 176 177 178 179 180
const mapStateToProps = (state) => {
  return {};
};
export default connect(mapStateToProps, {
  showLoading,
  hideLoading,
})(Registor);