| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- /**
- * Profile Settings页面
- * @邠心vbe on 2021/04/27
- */
- import React, { Component } from 'react';
- import { View, Text, StyleSheet, Image, ScrollView, Switch, Pressable } from 'react-native';
- import apiUser from '../../api/apiUser';
- import { host, setAccessToken } from '../../api/http';
- import Button, { ElevationObject } from '../../components/Button';
- import Dialog from '../../components/Dialog';
- import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
- import utils from '../../utils/utils';
- import { PageList } from '../Router';
- export default class ProfileV2 extends Component {
- constructor(props) {
- super(props);
- this.state = {
- userInfo: userInfo,
- refreshId: 0,
- totalVehicle: 0
- };
- }
- componentDidMount() {
- this.init();
- this.props.navigation.addListener('focus', () => {
- this.init();
- });
- }
- init() {
- getUserInfo(info => {
- this.setState({
- userInfo: info,
- refreshId: this.state.refreshId + 1
- });
- }, true);
- }
- removeVehicle(id) {
- Dialog.showDialog({
- title: 'Remove Vehicle',
- message: 'Are you sure you want to remove this vehicle?',
- callback: btn => {
- if (btn == 'ok') {
- Dialog.dismissLoading();
- this.deleteVehicle(id);
- }
- }
- })
- }
- deleteVehicle(id) {
- Dialog.showProgressDialog();
- apiUser.deleteVehicle({
- vehiclePk: id
- }).then(res => {
- Dialog.dismissLoading();
- toastShort('Delete successfully');
- this.setState({
- refreshId: this.state.refreshId + 1
- })
- }).catch(err => {
- Dialog.dismissLoading();
- toastShort(err);
- });
- }
- deleteAccount() {
- Dialog.showDialog({
- title: 'Delete Account',
- message: 'Are you sure you want to delete your account? This operation cannot be revoke.',
- ok: 'CONFIRM',
- callback: button => {
- if (button == Dialog.BUTTON_OK) {
- this.deleteMyAccount();
- }
- }
- })
- }
- deleteMyAccount() {
- Dialog.showProgressDialog();
- apiUser.deleteAccount().then(res => {
- toastShort('Successfully deleted!')
- Dialog.dismissLoading();
- //startPage(PageList.login);
- this.requestLogout();
- }).catch(err => {
- Dialog.dismissLoading();
- toastShort(err)
- })
- }
- logout() {
- Dialog.showDialog({
- title: 'Sign out',
- message: 'Are you sure you want to sign out?',
- callback: btn => {
- if (btn == 'ok') {
- Dialog.showProgressDialog();
- setTimeout(() => {
- this.requestLogout();
- }, 500);
- }
- }
- })
- }
- async requestLogout() {
- const data = await getStorageJsonSync('loginData');
- if (data && data.email) {
- delete data.password
- setStorageJson('loginData', data);
- setStorage('RegisterTokenDate', "");
- }
- global.userInfo = {}
- /*this.setState({
- isLogin: false,
- userInfo: {}
- });*/
- setAccessToken('');
- goBack();
- Dialog.dismissLoading();
- }
- render() {
- return (
- <ScrollView style={styles.container}>
- {/* Profile Info */}
- <View style={styles.cardView}>
- <Pressable
- style={styles.profileView}
- onPress={() => startPage(PageList.editProfile)}>
- { this.state.userInfo.photoUrl
- ? <Image
- style={styles.avatar}
- source={{uri: host + this.state.userInfo.photoUrl}}/>
- : <Image
- style={styles.avatar}
- source={require('../../images/user/ic-avatar-default.png')}/>
- }
- <View style={styles.infoContent}>
- <Text
- style={styles.nickname}
- ellipsizeMode='tail'
- numberOfLines={1}>{this.state.userInfo.nickName}</Text>
- <Text style={styles.userText}>{this.state.userInfo.email}</Text>
- <Text style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</Text>
- </View>
- <FontAwesome
- size={34}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- </View>
- {/* Wallet Info */}
- <Pressable
- style={styles.cardView}
- onPress={() => startPage(PageList.wallet)}>
- <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-wallet.png')}/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>Credit Wallet: </Text>
- <Text style={styles.cardPrimary}>{currency}{this.state.userInfo.credit}</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- {/* Vehicle Info */}
- <Pressable
- style={styles.cardView}
- onPress={() => startPage(PageList.myVehicles)}>
- <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-vehicle.png')}/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>My Vehicles: </Text>
- <Text style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- {/* Vehicle List */}
- {/* <View style={styles.titleView}>
- <Text style={styles.title}>My Vehicles</Text>
- <Button
- style={{backgroundColor: colorLight}}
- borderRadius={3}
- viewStyle={styles.titleAdd}
- onClick={() => {
- startPage(PageList.addVehicle)
- }}>
- <Entypo name='plus' size={14} color={colorDark}/>
- <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
- </Button>
- </View> */}
- {/* <View style={styles.verhicleList}>
- <VehicleList
- refreshId={this.state.refreshId}
- onResult={count => {
- this.setState({
- totalVehicle: count
- })
- }}
- onDelete={id => this.removeVehicle(id)}
- />
- </View> */}
- {/* Account List */}
- {/* <View style={styles.titleView}>
- <Text style={styles.title}>My Cards</Text>
- <Button
- textColor={textPrimary}
- style={styles.titleAdd}
- onClick={() => {
- startPage(PageList.addCard)
- }}>
- <Entypo name='plus' size={14} color={colorDark}/>
- <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
- </Button>
- </View>
- <View style={styles.accountList}>
- <CardList refreshId={this.state.refreshId}/>
- </View> */}
- <Pressable
- style={styles.cardView}
- onPress={() => startPage(PageList.changePassword, {action: "change"})}>
- <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-account.png')}/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>Account Security</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- {/* Notifications */}
- <Pressable
- style={styles.cardView}
- onPress={() => startPage(PageList.settings)}>
- <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-notification.png')}/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>Notification Settings</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- {/* this.state.userInfo.userType == "Public" &&
- <Pressable
- style={styles.cardView}
- onPress={() => startPage(PageList.registerFleet)}>
- <MaterialCommunityIcons
- style={styles.cardIcon}
- name="credit-card-edit"
- size={32}
- color="#00638C"/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>Apply as PHV/Fleet</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- */}
- <Pressable
- style={styles.cardView}
- onPress={() => this.deleteAccount()}>
- <MaterialCommunityIcons
- style={styles.cardIcon}
- name="account-remove"
- size={32}
- color="#00638C"/>
- <View style={styles.cardInfo}>
- <Text style={styles.cardLabel}>Delete Account</Text>
- </View>
- <FontAwesome
- size={28}
- color={textCancel}
- name='angle-right'/>
- </Pressable>
- {/* <Button
- style={styles.deleteButton}
- text="DELETE MY ACCOUNT"
- textColor={textButton}
- onClick={() => this.deleteAccount()}
- /> */}
- <Button
- style={styles.deleteButton}
- text="Logout"
- textColor={textButton}
- onClick={() => this.logout()}
- />
- </ScrollView>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: pageBackground
- },
- headerView: {
- paddingBottom: 72
- },
- background: {
- left: 0,
- right: 0,
- bottom: 0,
- height: $vw(62.4),
- alignItems: 'center',
- position: 'absolute'
- },
- profileView: {
- zIndex: 10,
- alignItems: 'center',
- flexDirection: 'row'
- },
- avatar: {
- width: 66,
- height: 66,
- borderWidth: 2,
- borderRadius: 80,
- borderColor: "#00638C"
- },
- infoContent: {
- flex: 1,
- paddingLeft: 16,
- },
- nickname: {
- color: '#000',
- fontSize: 20,
- fontWeight: 'bold',
- paddingTop: 1,
- paddingBottom: 1,
- },
- userText: {
- color: textPrimary,
- fontSize: 13,
- paddingTop: 1.5
- },
- cardView: {
- padding: 16,
- marginTop: 16,
- marginLeft: 16,
- marginRight: 16,
- borderRadius: 10,
- ...ElevationObject(5),
- alignItems: 'center',
- flexDirection: 'row',
- backgroundColor: colorLight,
- },
- cardItem: {
- flex: 1,
- alignItems: 'center',
- flexDirection: 'row',
- justifyContent: 'center'
- },
- cardDivide: {
- borderLeftWidth: 1,
- borderLeftColor: '#EEE'
- },
- cardIcon: {
- width: 32,
- height: 32
- },
- cardInfo: {
- flex: 1,
- paddingLeft: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- cardPrimary: {
- color: textPrimary,
- fontSize: 18,
- paddingBottom: 2
- },
- cardLabel: {
- color: textPrimary,
- fontSize: 16,
- fontWeight: 'bold'
- },
- titleView: {
- padding: 12,
- alignItems: 'center',
- flexDirection: 'row'
- },
- title: {
- flex: 1,
- padding: 8,
- color: '#000',
- fontSize: 16,
- },
- titleAdd: {
- padding: 8,
- color: textPrimary,
- alignItems: 'center',
- flexDirection: 'row'
- },
- verhicleList: {
- paddingLeft: 16,
- paddingRight: 16,
- marginBottom: -16
- },
- accountList: {
- paddingLeft: 16,
- paddingRight: 16,
- marginBottom: -16
- },
- notificationView: {
- marginLeft: 16,
- marginRight: 16,
- marginBottom: 20,
- borderRadius: 10,
- overflow: 'hidden',
- paddingLeft: 16,
- paddingRight: 16,
- borderColor: '#f5f5f5',
- borderWidth: 1,
- backgroundColor: colorLight,
- ...ElevationObject(1.5)
- },
- notificationItem: {
- paddingTop: 16,
- paddingBottom: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- notiLabel: {
- flex: 1,
- color: textPrimary,
- fontSize: 14
- },
- divide: {
- borderTopWidth: 1,
- borderTopColor: '#eee'
- },
- deleteButton: {
- ...$margin(48, 16, 16),
- backgroundColor: '#EA0A2A'
- }
- })
-
|