ProfileV2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /**
  2. * Profile Settings页面
  3. * @邠心vbe on 2021/04/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, ScrollView, Switch, Pressable } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import { host, setAccessToken } from '../../api/http';
  9. import Button, { ElevationObject } from '../../components/Button';
  10. import Dialog from '../../components/Dialog';
  11. import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  12. import utils from '../../utils/utils';
  13. import { PageList } from '../Router';
  14. export default class ProfileV2 extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. userInfo: userInfo,
  19. refreshId: 0,
  20. totalVehicle: 0
  21. };
  22. }
  23. componentDidMount() {
  24. this.init();
  25. this.props.navigation.addListener('focus', () => {
  26. this.init();
  27. });
  28. }
  29. init() {
  30. getUserInfo(info => {
  31. this.setState({
  32. userInfo: info,
  33. refreshId: this.state.refreshId + 1
  34. });
  35. }, true);
  36. }
  37. removeVehicle(id) {
  38. Dialog.showDialog({
  39. title: 'Remove Vehicle',
  40. message: 'Are you sure you want to remove this vehicle?',
  41. callback: btn => {
  42. if (btn == 'ok') {
  43. Dialog.dismissLoading();
  44. this.deleteVehicle(id);
  45. }
  46. }
  47. })
  48. }
  49. deleteVehicle(id) {
  50. Dialog.showProgressDialog();
  51. apiUser.deleteVehicle({
  52. vehiclePk: id
  53. }).then(res => {
  54. Dialog.dismissLoading();
  55. toastShort('Delete successfully');
  56. this.setState({
  57. refreshId: this.state.refreshId + 1
  58. })
  59. }).catch(err => {
  60. Dialog.dismissLoading();
  61. toastShort(err);
  62. });
  63. }
  64. deleteAccount() {
  65. Dialog.showDialog({
  66. title: 'Delete Account',
  67. message: 'Are you sure you want to delete your account? This operation cannot be revoke.',
  68. ok: 'CONFIRM',
  69. callback: button => {
  70. if (button == Dialog.BUTTON_OK) {
  71. this.deleteMyAccount();
  72. }
  73. }
  74. })
  75. }
  76. deleteMyAccount() {
  77. Dialog.showProgressDialog();
  78. apiUser.deleteAccount().then(res => {
  79. toastShort('Successfully deleted!')
  80. Dialog.dismissLoading();
  81. setTimeout(() => {
  82. startPage(PageList.login);
  83. }, 500);
  84. }).catch(err => {
  85. Dialog.dismissLoading();
  86. toastShort(err)
  87. })
  88. }
  89. logout() {
  90. Dialog.showDialog({
  91. title: 'Sign out',
  92. message: 'Are you sure you want to sign out?',
  93. callback: btn => {
  94. if (btn == 'ok') {
  95. Dialog.showProgressDialog();
  96. setTimeout(() => {
  97. this.requestLogout();
  98. }, 500);
  99. }
  100. }
  101. })
  102. }
  103. async requestLogout() {
  104. const data = await getStorageJsonSync('loginData');
  105. if (data && data.email) {
  106. delete data.password
  107. setStorageJson('loginData', data);
  108. setStorage('RegisterTokenDate', "");
  109. }
  110. global.userInfo = {}
  111. /*this.setState({
  112. isLogin: false,
  113. userInfo: {}
  114. });*/
  115. setAccessToken('');
  116. goBack();
  117. Dialog.dismissLoading();
  118. }
  119. render() {
  120. return (
  121. <ScrollView style={styles.container}>
  122. {/* Profile Info */}
  123. <View style={styles.cardView}>
  124. <Pressable
  125. style={styles.profileView}
  126. onPress={() => startPage(PageList.editProfile)}>
  127. { this.state.userInfo.photoUrl
  128. ? <Image
  129. style={styles.avatar}
  130. source={{uri: host + this.state.userInfo.photoUrl}}/>
  131. : <Image
  132. style={styles.avatar}
  133. source={require('../../images/user/ic-avatar-default.png')}/>
  134. }
  135. <View style={styles.infoContent}>
  136. <Text
  137. style={styles.nickname}
  138. ellipsizeMode='tail'
  139. numberOfLines={1}>{this.state.userInfo.nickName}</Text>
  140. <Text style={styles.userText}>{this.state.userInfo.email}</Text>
  141. <Text style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</Text>
  142. </View>
  143. <FontAwesome
  144. size={34}
  145. color={textCancel}
  146. name='angle-right'/>
  147. </Pressable>
  148. </View>
  149. {/* Wallet Info */}
  150. <Pressable
  151. style={styles.cardView}
  152. onPress={() => startPage(PageList.wallet)}>
  153. <Image
  154. style={styles.cardIcon}
  155. source={require('../../images/user/card-wallet.png')}/>
  156. <View style={styles.cardInfo}>
  157. <Text style={styles.cardLabel}>Credit Wallet: </Text>
  158. <Text style={styles.cardPrimary}>{currency}{this.state.userInfo.credit}</Text>
  159. </View>
  160. <FontAwesome
  161. size={28}
  162. color={textCancel}
  163. name='angle-right'/>
  164. </Pressable>
  165. {/* Vehicle Info */}
  166. <Pressable
  167. style={styles.cardView}
  168. onPress={() => startPage(PageList.myVehicles)}>
  169. <Image
  170. style={styles.cardIcon}
  171. source={require('../../images/user/card-vehicle.png')}/>
  172. <View style={styles.cardInfo}>
  173. <Text style={styles.cardLabel}>My Vehicles: </Text>
  174. <Text style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</Text>
  175. </View>
  176. <FontAwesome
  177. size={28}
  178. color={textCancel}
  179. name='angle-right'/>
  180. </Pressable>
  181. {/* Vehicle List */}
  182. {/* <View style={styles.titleView}>
  183. <Text style={styles.title}>My Vehicles</Text>
  184. <Button
  185. style={{backgroundColor: colorLight}}
  186. borderRadius={3}
  187. viewStyle={styles.titleAdd}
  188. onClick={() => {
  189. startPage(PageList.addVehicle)
  190. }}>
  191. <Entypo name='plus' size={14} color={colorDark}/>
  192. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  193. </Button>
  194. </View> */}
  195. {/* <View style={styles.verhicleList}>
  196. <VehicleList
  197. refreshId={this.state.refreshId}
  198. onResult={count => {
  199. this.setState({
  200. totalVehicle: count
  201. })
  202. }}
  203. onDelete={id => this.removeVehicle(id)}
  204. />
  205. </View> */}
  206. {/* Account List */}
  207. {/* <View style={styles.titleView}>
  208. <Text style={styles.title}>My Cards</Text>
  209. <Button
  210. textColor={textPrimary}
  211. style={styles.titleAdd}
  212. onClick={() => {
  213. startPage(PageList.addCard)
  214. }}>
  215. <Entypo name='plus' size={14} color={colorDark}/>
  216. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  217. </Button>
  218. </View>
  219. <View style={styles.accountList}>
  220. <CardList refreshId={this.state.refreshId}/>
  221. </View> */}
  222. <Pressable
  223. style={styles.cardView}
  224. onPress={() => startPage(PageList.changePassword)}>
  225. <Image
  226. style={styles.cardIcon}
  227. source={require('../../images/user/card-account.png')}/>
  228. <View style={styles.cardInfo}>
  229. <Text style={styles.cardLabel}>Account Security</Text>
  230. </View>
  231. <FontAwesome
  232. size={28}
  233. color={textCancel}
  234. name='angle-right'/>
  235. </Pressable>
  236. {/* Notifications */}
  237. <Pressable
  238. style={styles.cardView}
  239. onPress={() => startPage(PageList.settings)}>
  240. <Image
  241. style={styles.cardIcon}
  242. source={require('../../images/user/card-notification.png')}/>
  243. <View style={styles.cardInfo}>
  244. <Text style={styles.cardLabel}>Notification Settings</Text>
  245. </View>
  246. <FontAwesome
  247. size={28}
  248. color={textCancel}
  249. name='angle-right'/>
  250. </Pressable>
  251. { this.state.userInfo.userType == "Public" &&
  252. <Pressable
  253. style={styles.cardView}
  254. onPress={() => startPage(PageList.registerFleet)}>
  255. <MaterialCommunityIcons
  256. style={styles.cardIcon}
  257. name="credit-card-edit"
  258. size={32}
  259. color="#00638C"/>
  260. <View style={styles.cardInfo}>
  261. <Text style={styles.cardLabel}>Apply as PHV/Fleet</Text>
  262. </View>
  263. <FontAwesome
  264. size={28}
  265. color={textCancel}
  266. name='angle-right'/>
  267. </Pressable>
  268. }
  269. <Pressable
  270. style={styles.cardView}
  271. onPress={() => this.deleteAccount()}>
  272. <MaterialCommunityIcons
  273. style={styles.cardIcon}
  274. name="account-remove"
  275. size={32}
  276. color="#00638C"/>
  277. <View style={styles.cardInfo}>
  278. <Text style={styles.cardLabel}>Delete Account</Text>
  279. </View>
  280. <FontAwesome
  281. size={28}
  282. color={textCancel}
  283. name='angle-right'/>
  284. </Pressable>
  285. {/* <Button
  286. style={styles.deleteButton}
  287. text="DELETE MY ACCOUNT"
  288. textColor={textButton}
  289. onClick={() => this.deleteAccount()}
  290. /> */}
  291. <Button
  292. style={styles.deleteButton}
  293. text="Logout"
  294. textColor={textButton}
  295. onClick={() => this.logout()}
  296. />
  297. </ScrollView>
  298. );
  299. }
  300. }
  301. const styles = StyleSheet.create({
  302. container: {
  303. flex: 1,
  304. backgroundColor: pageBackground
  305. },
  306. headerView: {
  307. paddingBottom: 72
  308. },
  309. background: {
  310. left: 0,
  311. right: 0,
  312. bottom: 0,
  313. height: $vw(62.4),
  314. alignItems: 'center',
  315. position: 'absolute'
  316. },
  317. profileView: {
  318. zIndex: 10,
  319. alignItems: 'center',
  320. flexDirection: 'row'
  321. },
  322. avatar: {
  323. width: 66,
  324. height: 66,
  325. borderWidth: 2,
  326. borderRadius: 80,
  327. borderColor: "#00638C"
  328. },
  329. infoContent: {
  330. flex: 1,
  331. paddingLeft: 16,
  332. },
  333. nickname: {
  334. color: '#000',
  335. fontSize: 20,
  336. fontWeight: 'bold',
  337. paddingTop: 1,
  338. paddingBottom: 1,
  339. },
  340. userText: {
  341. color: textPrimary,
  342. fontSize: 13,
  343. paddingTop: 1.5
  344. },
  345. cardView: {
  346. padding: 16,
  347. marginTop: 16,
  348. marginLeft: 16,
  349. marginRight: 16,
  350. borderRadius: 10,
  351. ...ElevationObject(5),
  352. alignItems: 'center',
  353. flexDirection: 'row',
  354. backgroundColor: colorLight,
  355. },
  356. cardItem: {
  357. flex: 1,
  358. alignItems: 'center',
  359. flexDirection: 'row',
  360. justifyContent: 'center'
  361. },
  362. cardDivide: {
  363. borderLeftWidth: 1,
  364. borderLeftColor: '#EEE'
  365. },
  366. cardIcon: {
  367. width: 32,
  368. height: 32
  369. },
  370. cardInfo: {
  371. flex: 1,
  372. paddingLeft: 16,
  373. alignItems: 'center',
  374. flexDirection: 'row'
  375. },
  376. cardPrimary: {
  377. color: textPrimary,
  378. fontSize: 18,
  379. paddingBottom: 2
  380. },
  381. cardLabel: {
  382. color: textPrimary,
  383. fontSize: 16,
  384. fontWeight: 'bold'
  385. },
  386. titleView: {
  387. padding: 12,
  388. alignItems: 'center',
  389. flexDirection: 'row'
  390. },
  391. title: {
  392. flex: 1,
  393. padding: 8,
  394. color: '#000',
  395. fontSize: 16,
  396. },
  397. titleAdd: {
  398. padding: 8,
  399. color: textPrimary,
  400. alignItems: 'center',
  401. flexDirection: 'row'
  402. },
  403. verhicleList: {
  404. paddingLeft: 16,
  405. paddingRight: 16,
  406. marginBottom: -16
  407. },
  408. accountList: {
  409. paddingLeft: 16,
  410. paddingRight: 16,
  411. marginBottom: -16
  412. },
  413. notificationView: {
  414. marginLeft: 16,
  415. marginRight: 16,
  416. marginBottom: 20,
  417. borderRadius: 10,
  418. overflow: 'hidden',
  419. paddingLeft: 16,
  420. paddingRight: 16,
  421. borderColor: '#f5f5f5',
  422. borderWidth: 1,
  423. backgroundColor: colorLight,
  424. ...ElevationObject(1.5)
  425. },
  426. notificationItem: {
  427. paddingTop: 16,
  428. paddingBottom: 16,
  429. alignItems: 'center',
  430. flexDirection: 'row'
  431. },
  432. notiLabel: {
  433. flex: 1,
  434. color: textPrimary,
  435. fontSize: 14
  436. },
  437. divide: {
  438. borderTopWidth: 1,
  439. borderTopColor: '#eee'
  440. },
  441. deleteButton: {
  442. ...$margin(48, 16, 16),
  443. backgroundColor: '#EA0A2A'
  444. }
  445. })