/** * 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(); setTimeout(() => { startPage(PageList.login); }, 500); }).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 ( {/* Profile Info */} startPage(PageList.editProfile)}> { this.state.userInfo.photoUrl ? : } {this.state.userInfo.nickName} {this.state.userInfo.email} {(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone} {/* Wallet Info */} startPage(PageList.wallet)}> Credit Wallet: {currency}{this.state.userInfo.credit} {/* Vehicle Info */} startPage(PageList.myVehicles)}> My Vehicles: {this.state.userInfo.countVehicle} {/* Vehicle List */} {/* My Vehicles */} {/* { this.setState({ totalVehicle: count }) }} onDelete={id => this.removeVehicle(id)} /> */} {/* Account List */} {/* My Cards */} startPage(PageList.changePassword)}> Account Security {/* Notifications */} startPage(PageList.settings)}> Notification Settings { this.state.userInfo.userType == "Public" && startPage(PageList.registerFleet)}> Apply as PHV/Fleet } this.deleteAccount()}> Delete Account {/*