ProfileV2.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. * Profile Settings页面
  3. * @邠心vbe on 2021/04/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Image, ScrollView } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import { setAccessToken } from '../../api/http';
  9. import Button, { ElevationObject } from '../../components/Button';
  10. import Dialog from '../../components/Dialog';
  11. import TextView from '../../components/TextView';
  12. import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  13. import utils from '../../utils/utils';
  14. import { PageList } from '../Router';
  15. import app from '../../../app.json';
  16. import { ShadowViewV2 } from '../../components/ShadowView';
  17. export default class ProfileV2 extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. userInfo: userInfo,
  22. refreshId: 0,
  23. totalVehicle: 0
  24. };
  25. }
  26. componentDidMount() {
  27. this.init();
  28. this.props.navigation.addListener('focus', () => {
  29. this.init();
  30. });
  31. }
  32. init() {
  33. getUserInfo(info => {
  34. this.setState({
  35. userInfo: info,
  36. refreshId: this.state.refreshId + 1
  37. });
  38. }, true);
  39. }
  40. deleteAccount() {
  41. utils.logEventTracking("user_action", "delete_account")
  42. Dialog.showDialog({
  43. title: $t('profile.deleteAccount'),
  44. message: $t('profile.confirmDeleteAccount'),
  45. ok: $t('nav.confirm'),
  46. callback: button => {
  47. if (button == Dialog.BUTTON_OK) {
  48. this.deleteMyAccount();
  49. }
  50. }
  51. })
  52. }
  53. deleteMyAccount(again=false) {
  54. Dialog.showProgressDialog();
  55. apiUser.deleteAccount({
  56. secondConfirm: again
  57. }).then(res => {
  58. toastShort($t('profile.deleteAccountSuccess'))
  59. Dialog.dismissLoading();
  60. this.requestLogout();
  61. /*setTimeout(() => {
  62. startPage(PageList.login);
  63. }, 500);*/
  64. }).catch(err => {
  65. Dialog.dismissLoading();
  66. //toastShort(err)
  67. setTimeout(() => {
  68. if (err.code == 5334 || err.code == 5368) {
  69. Dialog.showDialog({
  70. title: $t('profile.deleteAccount'),
  71. message: err.msg,
  72. ok: $t("nav.confirm"),
  73. callback: button => {
  74. if (button == Dialog.BUTTON_OK) {
  75. setTimeout(() => {
  76. this.deleteMyAccount(true);
  77. }, 500)
  78. }
  79. }
  80. })
  81. } else {
  82. Dialog.showResultDialog(err.msg);
  83. }
  84. }, 500);
  85. })
  86. }
  87. logout() {
  88. utils.logEventTracking("user_action", "logout")
  89. Dialog.showDialog({
  90. title: $t('profile.signOut'),
  91. message: $t('profile.tipSignOut'),
  92. callback: btn => {
  93. if (btn == Dialog.BUTTON_OK) {
  94. Dialog.showProgressDialog();
  95. setTimeout(() => {
  96. this.requestLogout();
  97. }, 500);
  98. }
  99. }
  100. })
  101. }
  102. async requestLogout() {
  103. const data = await getStorageJsonSync('loginData');
  104. if (data && data.email) {
  105. delete data.password
  106. setStorageJson('loginData', data);
  107. setStorage('RegisterTokenDate', "");
  108. }
  109. global.hasAnalytics = false;
  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. <EndView half/>
  124. <Button
  125. style={styles.cardView}
  126. viewStyle={styles.profileView}
  127. android_ripple={ripple}
  128. onClick={() => startPage(PageList.editProfile)}>
  129. { this.state.userInfo.photoUrl
  130. ? <Image
  131. style={styles.avatar}
  132. source={{uri: utils.getImageUrl(this.state.userInfo.photoUrl)}}/>
  133. : <Image
  134. style={styles.avatar}
  135. source={require('../../images/user/ic-avatar-default.png')}/>
  136. }
  137. <View style={styles.infoContent}>
  138. <TextView
  139. style={styles.nickname}
  140. ellipsizeMode='tail'
  141. numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
  142. <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
  143. <TextView style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</TextView>
  144. {/* <View style={styles.userTypeView}>
  145. { this.state.userInfo.userType?.split(";").map((item, index) => {
  146. return <TextView key={index} style={styles.userTypeText}>{item}</TextView>
  147. })
  148. }
  149. </View> */}
  150. </View>
  151. <FontAwesome
  152. size={24}
  153. color={textCancel}
  154. name='angle-right'/>
  155. </Button>
  156. <ShadowViewV2/>
  157. <EndView half/>
  158. {/* Wallet Info */}
  159. {/* app.v4.wallet
  160. ? <Button
  161. style={styles.cardView}
  162. viewStyle={styles.profileItem}
  163. onClick={() => startPage(PageList.wallets)}>
  164. <Image
  165. style={styles.cardIcon}
  166. source={require('../../images/user/card-wallet.png')}/>
  167. <View style={styles.cardInfo}>
  168. <TextView style={styles.cardLabel}>{$t('drawer.wallets')}</TextView>
  169. </View>
  170. <FontAwesome
  171. size={24}
  172. color={textCancel}
  173. name='angle-right'/>
  174. </Button>
  175. : <Button
  176. style={styles.cardView}
  177. viewStyle={styles.profileItem}
  178. onClick={() => startPage(PageList.wallet)}>
  179. <Image
  180. style={styles.cardIcon}
  181. source={require('../../images/user/card-wallet.png')}/>
  182. <View style={styles.cardInfo}>
  183. <TextView style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</TextView>
  184. <TextView style={styles.cardPrimary}>{this.state.userInfo.creditStr}</TextView>
  185. </View>
  186. <FontAwesome
  187. size={24}
  188. color={textCancel}
  189. name='angle-right'/>
  190. </Button>
  191. */}
  192. <ShadowViewV2/>
  193. { (utils.isNotEmpty(this.state.userInfo.groupWallet) && !app.v4.wallet) && <>
  194. <Button
  195. style={styles.cardView}
  196. viewStyle={styles.profileItem}>
  197. <Image
  198. style={styles.cardIcon}
  199. source={require('../../images/user/card-wallet.png')}/>
  200. <View style={styles.cardInfo}>
  201. <TextView style={styles.cardLabel}>{this.state.userInfo.groupWallet.walletName}:</TextView>
  202. <TextView style={styles.cardPrimary}>{this.state.userInfo.groupWallet.creditStr}, Expires on {this.state.userInfo.groupWallet.expireTime}</TextView>
  203. </View>
  204. </Button>
  205. <ShadowViewV2/>
  206. </>
  207. }
  208. {/* Vehicle Info */}
  209. { app.vehicle.enable && <>
  210. <Button
  211. style={styles.cardView}
  212. viewStyle={styles.profileItem}
  213. onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
  214. <Image
  215. style={styles.cardIcon}
  216. source={require('../../images/user/card-vehicle.png')}/>
  217. <View style={styles.cardInfo}>
  218. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  219. <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView>
  220. </View>
  221. <FontAwesome
  222. size={24}
  223. color={textCancel}
  224. name='angle-right'/>
  225. </Button>
  226. <ShadowViewV2/>
  227. </>
  228. }
  229. {/* Vehicle List */}
  230. {/* <View style={styles.titleView}>
  231. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  232. <Button
  233. style={{backgroundColor: colorLight}}
  234. borderRadius={3}
  235. viewStyle={styles.titleAdd}
  236. onClick={() => {
  237. startPage(PageList.addVehicle)
  238. }}>
  239. <Entypo name='plus' size={14} color={colorDark}/>
  240. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  241. </Button>
  242. </View> */}
  243. {/* <View style={styles.verhicleList}>
  244. <VehicleList
  245. refreshId={this.state.refreshId}
  246. onResult={count => {
  247. this.setState({
  248. totalVehicle: count
  249. })
  250. }}
  251. onDelete={id => this.removeVehicle(id)}
  252. />
  253. </View> */}
  254. {/* Account List */}
  255. {/* <View style={styles.titleView}>
  256. <Text style={styles.title}>My Cards</Text>
  257. <Button
  258. textColor={textPrimary}
  259. style={styles.titleAdd}
  260. onClick={() => {
  261. startPage(PageList.addCard)
  262. }}>
  263. <Entypo name='plus' size={14} color={colorDark}/>
  264. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  265. </Button>
  266. </View>
  267. <View style={styles.accountList}>
  268. <CardList refreshId={this.state.refreshId}/>
  269. </View> */}
  270. {/* <Button
  271. style={styles.cardView}
  272. viewStyle={styles.profileItem}
  273. onClick={() => this.deleteAccount()}>
  274. <MaterialCommunityIcons
  275. style={styles.cardIcon}
  276. name="account-remove"
  277. size={32}
  278. color="#00638C"/>
  279. <View style={styles.cardInfo}>
  280. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  281. </View>
  282. <FontAwesome
  283. size={24}
  284. color={textCancel}
  285. name='angle-right'/>
  286. </Button>
  287. <ShadowViewV2/> */}
  288. <Button
  289. style={styles.cardView}
  290. viewStyle={styles.profileItem}
  291. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  292. <Image
  293. style={styles.cardIcon}
  294. source={require('../../images/user/card-account.png')}/>
  295. <View style={styles.cardInfo}>
  296. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  297. </View>
  298. <FontAwesome
  299. size={24}
  300. color={textCancel}
  301. name='angle-right'/>
  302. </Button>
  303. <ShadowViewV2/>
  304. {/* Notifications */}
  305. { !app.v3.drawer && <>
  306. <Button
  307. style={styles.cardView}
  308. viewStyle={styles.profileItem}
  309. onClick={() => startPage(PageList.settings)}>
  310. <Image
  311. style={styles.cardIcon}
  312. source={require('../../images/user/card-notification.png')}/>
  313. <View style={styles.cardInfo}>
  314. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  315. </View>
  316. <FontAwesome
  317. size={24}
  318. color={textCancel}
  319. name='angle-right'/>
  320. </Button>
  321. <ShadowViewV2/>
  322. </>
  323. }
  324. { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") && <>
  325. <Button
  326. style={styles.cardView}
  327. viewStyle={styles.profileItem}
  328. onClick={() => startPage(PageList.registerFleet)}>
  329. <MaterialCommunityIcons
  330. style={styles.cardIcon}
  331. name="credit-card-edit"
  332. size={32}
  333. color="#00638C"/>
  334. <View style={styles.cardInfo}>
  335. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  336. </View>
  337. <FontAwesome
  338. size={24}
  339. color={textCancel}
  340. name='angle-right'/>
  341. </Button>
  342. <ShadowViewV2/>
  343. </>
  344. }
  345. { app.v3.drawer && <>
  346. <Button
  347. style={styles.cardView}
  348. viewStyle={styles.profileItem}
  349. onClick={() => startPage(PageList.feedback)}>
  350. <MaterialCommunityIcons
  351. style={styles.cardIcon}
  352. name="message-alert-outline"
  353. color="#00638C"
  354. size={32}
  355. />
  356. <View style={styles.cardInfo}>
  357. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  358. </View>
  359. <FontAwesome
  360. size={24}
  361. color={textCancel}
  362. name='angle-right'/>
  363. </Button>
  364. <ShadowViewV2/>
  365. <Button
  366. style={styles.cardView}
  367. viewStyle={styles.profileItem}
  368. onClick={() => startPage(PageList.settings)}>
  369. <MaterialIcons
  370. style={styles.cardIcon}
  371. name="settings"
  372. color="#00638C"
  373. size={32}
  374. />
  375. <View style={styles.cardInfo}>
  376. <TextView style={styles.cardLabel}>{$t('drawer.settings')}</TextView>
  377. </View>
  378. <FontAwesome
  379. size={24}
  380. color={textCancel}
  381. name='angle-right'/>
  382. </Button>
  383. <ShadowViewV2/>
  384. </>}
  385. <Button
  386. style={styles.cardView}
  387. viewStyle={styles.profileItem}
  388. onClick={() => startPage(PageList.about)}>
  389. <MaterialCommunityIcons
  390. style={styles.cardIcon}
  391. name="information-outline"
  392. color="#00638C"
  393. size={32}
  394. />
  395. <View style={styles.cardInfo}>
  396. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  397. </View>
  398. <FontAwesome
  399. size={24}
  400. color={textCancel}
  401. name='angle-right'/>
  402. </Button>
  403. <ShadowViewV2/>
  404. <Button
  405. style={styles.cardView}
  406. viewStyle={styles.profileItem}
  407. onClick={() => {
  408. this.deleteAccount();
  409. //startPage(PageList.deleteAccount)
  410. }}>
  411. <MaterialCommunityIcons
  412. style={styles.cardIcon}
  413. name="account-remove"
  414. size={32}
  415. color="#00638C"/>
  416. <View style={styles.cardInfo}>
  417. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  418. </View>
  419. <FontAwesome
  420. size={24}
  421. color={textCancel}
  422. name='angle-right'/>
  423. </Button>
  424. <ShadowViewV2/>
  425. {/* <Button
  426. style={styles.deleteButton}
  427. text="DELETE MY ACCOUNT"
  428. textColor={textButton}
  429. onClick={() => this.deleteAccount()}
  430. /> */}
  431. <Button
  432. style={styles.deleteButton}
  433. text={$t('profile.logout')}
  434. textColor={textLight}
  435. elevation={4}
  436. textSize={20}
  437. onClick={() => this.logout()}
  438. />
  439. </ScrollView>
  440. );
  441. }
  442. }
  443. const styles = StyleSheet.create({
  444. container: {
  445. flex: 1,
  446. backgroundColor: pageBackground
  447. },
  448. headerView: {
  449. paddingBottom: 72
  450. },
  451. background: {
  452. left: 0,
  453. right: 0,
  454. bottom: 0,
  455. height: $vw(62.4),
  456. alignItems: 'center',
  457. position: 'absolute'
  458. },
  459. profileView: {
  460. zIndex: 10,
  461. padding: 16,
  462. alignItems: 'center',
  463. flexDirection: 'row'
  464. },
  465. avatar: {
  466. width: 66,
  467. height: 66,
  468. borderWidth: 2,
  469. borderRadius: 80,
  470. borderColor: "#00638C"
  471. },
  472. infoContent: {
  473. flex: 1,
  474. paddingLeft: 16,
  475. },
  476. nickname: {
  477. color: '#000',
  478. fontSize: 20,
  479. fontWeight: 'bold',
  480. paddingTop: 1,
  481. paddingBottom: 1,
  482. },
  483. userText: {
  484. color: textPrimary,
  485. fontSize: 13,
  486. paddingTop: 1.5
  487. },
  488. cardView: {
  489. zIndex: 2,
  490. marginTop: 8,
  491. marginLeft: 16,
  492. marginRight: 16,
  493. borderRadius: 10,
  494. overflow: 'hidden',
  495. //...ElevationObject(5),
  496. alignItems: 'center',
  497. flexDirection: 'row',
  498. backgroundColor: colorLight,
  499. },
  500. profileItem: {
  501. ...$padding(24, 16),
  502. alignItems: 'center',
  503. flexDirection: 'row',
  504. justifyContent: 'center',
  505. },
  506. cardItem: {
  507. flex: 1,
  508. alignItems: 'center',
  509. flexDirection: 'row',
  510. justifyContent: 'center'
  511. },
  512. cardDivide: {
  513. borderLeftWidth: 1,
  514. borderLeftColor: '#EEE'
  515. },
  516. cardIcon: {
  517. width: 32,
  518. height: 32
  519. },
  520. cardInfo: {
  521. flex: 1,
  522. paddingLeft: 16,
  523. alignItems: 'flex-start',
  524. flexDirection: 'column'
  525. },
  526. cardPrimary: {
  527. color: textPrimary,
  528. fontSize: 16,
  529. paddingTop: 2
  530. },
  531. cardLabel: {
  532. color: textPrimary,
  533. fontSize: 16,
  534. fontWeight: 'bold'
  535. },
  536. titleView: {
  537. padding: 12,
  538. alignItems: 'center',
  539. flexDirection: 'row'
  540. },
  541. title: {
  542. flex: 1,
  543. padding: 8,
  544. color: '#000',
  545. fontSize: 16,
  546. },
  547. titleAdd: {
  548. padding: 8,
  549. color: textPrimary,
  550. alignItems: 'center',
  551. flexDirection: 'row'
  552. },
  553. verhicleList: {
  554. paddingLeft: 16,
  555. paddingRight: 16,
  556. marginBottom: -16
  557. },
  558. accountList: {
  559. paddingLeft: 16,
  560. paddingRight: 16,
  561. marginBottom: -16
  562. },
  563. notificationView: {
  564. marginLeft: 16,
  565. marginRight: 16,
  566. marginBottom: 20,
  567. borderRadius: 10,
  568. overflow: 'hidden',
  569. paddingLeft: 16,
  570. paddingRight: 16,
  571. borderColor: '#f5f5f5',
  572. borderWidth: 1,
  573. backgroundColor: colorLight,
  574. ...ElevationObject(1.5)
  575. },
  576. notificationItem: {
  577. paddingTop: 16,
  578. paddingBottom: 16,
  579. alignItems: 'center',
  580. flexDirection: 'row'
  581. },
  582. notiLabel: {
  583. flex: 1,
  584. color: textPrimary,
  585. fontSize: 14
  586. },
  587. divide: {
  588. borderTopWidth: 1,
  589. borderTopColor: '#eee'
  590. },
  591. deleteButton: {
  592. borderRadius: 4,
  593. ...$margin(16, 16, 24),
  594. backgroundColor: '#EA0A2A'
  595. },
  596. userTypeView: {
  597. paddingTop: 2,
  598. alignItems: 'center',
  599. flexDirection: 'row'
  600. },
  601. userTypeText: {
  602. color: textLight,
  603. fontSize: 8,
  604. marginRight: 4,
  605. borderRadius: 2,
  606. textAlign: "center",
  607. ...$padding(2, 4),
  608. backgroundColor: colorAccent
  609. }
  610. })