PersonalInformation.js 5.21 KB
Newer Older
dungtnguyen's avatar
dungtnguyen committed
1
import {Formik} from 'formik';
dungtnguyen's avatar
dungtnguyen committed
2 3 4
import React, {memo} from 'react';
import {Image, TouchableOpacity, View} from 'react-native';
import AppText from '../../../../components/AppText';
dungtnguyen's avatar
dungtnguyen committed
5 6 7 8
import ButtonComponent from '../../../../components/ButtonComponent';
import TextInputComponent from '../../../../components/TextInputComponent';
import config from '../../../../config';
import commonStyles from '../../../../styles/commonStyles';
dungtnguyen's avatar
dungtnguyen committed
9 10 11
import {IMAGES} from '../../../../values/images';
import string from '../../../../values/string';
import styles from '../../style';
dungtnguyen's avatar
dungtnguyen committed
12
import colors from '../../../../values/colors';
dungtnguyen's avatar
dungtnguyen committed
13 14

const PersonalInformation = React.memo(
dungtnguyen's avatar
dungtnguyen committed
15
  ({userInfo, onEditUserInfo, editUserInfo, handleSubmitChangeInfo}) => {
dungtnguyen's avatar
dungtnguyen committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    const personalInfo = [
      {
        name: 'Họ',
        value: userInfo?.first_name || '',
        icon: IMAGES.IcInfoGuess,
        width: '50%',
      },
      {
        name: 'Tên lót',
        value: userInfo?.middle_name || '',
        icon: IMAGES.IcInfoGuess,
        width: '50%',
      },
      {
        name: 'Tên',
        value: userInfo?.last_name || '',
        icon: IMAGES.IcInfoGuess,
        width: '50%',
      },
      {
        name: 'Giới tính',
        value: userInfo?.gender ? 'Nam' : 'Nữ',
        icon: IMAGES.IcInfoGuess,
        width: '50%',
      },
      {
        name: 'Số điện thoại',
        value: userInfo?.cell_phone || '',
        icon: IMAGES.IcPhone,
        width: '100%',
      },
      {
        name: 'Email',
        value: userInfo?.email || '',
        icon: IMAGES.IcMailGray,
        width: '100%',
      },
    ];
    return (
      <View style={[styles.viewInfo]}>
        <View style={styles.viewTitle}>
          <AppText style={{fontSize: 17}}>
            {string.PERSONAL_INFORMATION}
          </AppText>
          <View>
dungtnguyen's avatar
dungtnguyen committed
61 62 63 64 65 66 67 68 69 70 71 72
            {!editUserInfo?.personalInfo ? (
              <TouchableOpacity
                onPress={() =>
                  onEditUserInfo(config.profileField.PERSONAL_INFO)
                }>
                <Image source={IMAGES.IcEdit} style={{height: 30, width: 30}} />
              </TouchableOpacity>
            ) : (
              <TouchableOpacity onPress={() => onEditUserInfo()}>
                <Image source={IMAGES.IcReject} />
              </TouchableOpacity>
            )}
dungtnguyen's avatar
dungtnguyen committed
73 74 75
          </View>
        </View>
        <View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
dungtnguyen's avatar
dungtnguyen committed
76 77 78 79 80 81 82 83 84 85
          {!editUserInfo?.personalInfo ? (
            personalInfo.map(item => (
              <View
                key={item.name}
                style={[styles.infoView, {width: item.width}]}>
                <Image source={item.icon} style={{width: 20, height: 20}} />
                <View style={{marginLeft: 5}}>
                  <AppText>{item.name}</AppText>
                  <AppText isSubText>{item?.value}</AppText>
                </View>
dungtnguyen's avatar
dungtnguyen committed
86
              </View>
dungtnguyen's avatar
dungtnguyen committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
            ))
          ) : (
            <Formik
              initialValues={{
                first_name: userInfo?.first_name || '',
                middle_name: userInfo?.middle_name || '',
                last_name: userInfo?.last_name || '',
                gender: userInfo?.gender ? 'Nam' : 'Nữ',
                cell_phone: userInfo?.cell_phone || '',
              }}
              onSubmit={values => handleSubmitChangeInfo(values)}>
              {({handleChange, handleBlur, handleSubmit, values}) => (
                <View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
                  {personalInfo.map((item, index) => {
                    if (index === personalInfo.length - 1) {
                      return null;
                    }
                    return (
                      <View
                        key={item.name}
                        style={{
                          width: item.width,
                          paddingHorizontal: 5,
                        }}>
                        <TextInputComponent
                          value={Object.values(values)[index]}
                          label={item.name}
                          placeholder={`Vui lòng nhập ${item.name} của bạn`}
                          styleAreaInput={{
                            backgroundColor: colors.white,
                            width: '100%',
                          }}
                          autoCompleteType={'postal-address'}
                          keyboardType={'email'}
                          onChangeText={handleChange(
                            Object.keys(values)[index],
                          )}
                        />
                      </View>
                    );
                  })}
                  <ButtonComponent
                    style={[styles.btnSubmit]}
                    text={'Đồng ý'}
                    textStyle={{color: colors.white}}
                    onPress={handleSubmit}
                  />
                </View>
              )}
            </Formik>
          )}
dungtnguyen's avatar
dungtnguyen committed
138 139 140 141
        </View>
      </View>
    );
  },
dungtnguyen's avatar
dungtnguyen committed
142 143 144 145 146 147 148
  // function (prevProps, nextProps) {
  //   return (
  //     prevProps.userInfo === nextProps.userInfo ||
  //     prevProps.editUserInfo === nextProps.editUserInfo ||
  //     prevProps.onEditUserInfo() === nextProps.onEditUserInfo()
  //   );
  // },
dungtnguyen's avatar
dungtnguyen committed
149 150 151
);

export default memo(PersonalInformation);