Advertisement
zidniryi

Untitled

Mar 23rd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.60 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import {
  3. Text,
  4. View,
  5. StyleSheet,
  6. Dimensions,
  7. ScrollView,
  8. Modal,
  9. Image,
  10. FlatList,
  11. Clipboard,
  12. ToastAndroid,
  13. DeviceEventEmitter,
  14. Alert
  15. } from 'react-native'
  16. import { Container, Button, Row } from 'native-base'
  17. import LinearGradient from 'react-native-linear-gradient'
  18. import bcaLogo from 'src/design/image/dompet/bca.png'
  19. import BackHeader from 'src/design/view/__global/back-header'
  20. import {
  21. responsiveWidth,
  22. responsiveHeight,
  23. responsiveFontSize
  24. } from 'react-native-responsive-dimensions'
  25. import firebase from 'react-native-firebase'
  26. import currencyFormat from '../../../../lib/util/currencyFormat'
  27. // import TopUpBCA from '../_services/topUpBCA'
  28. import { confirmTopUpBCA } from '../_services/topUpBCA'
  29. import moment from 'moment'
  30.  
  31. // This is component Timer
  32. function Timer({ interval }) {
  33. const pad = n => (n < 10 ? '0' + n : n)
  34. const duration = moment.duration(interval)
  35. return (
  36. <View style={styles.timerContainer}>
  37. <Text style={styles.textTime}> Batas waktu transfer dalam </Text>
  38. <Text style={styles.textTime}>{pad(duration.minutes())}</Text>
  39. <Text style={styles.textTime}> Menit </Text>
  40. <Text style={styles.textTime}>{pad(duration.seconds())}</Text>
  41. <Text style={styles.textTime}> Detik </Text>
  42. </View>
  43. )
  44. }
  45.  
  46. class C_KonfirmasiTopUpViaATM extends Component {
  47. constructor(props) {
  48. super(props)
  49.  
  50. this.state = {
  51. modalVisible: false,
  52. amount: this.props.navigation.state.params.amountTopUp,
  53. transactionCode: this.props.navigation.state.params.transactionCode,
  54. clipboardContent: null,
  55. // Timer
  56. start: 0,
  57. now: 0,
  58. laps: []
  59. }
  60. }
  61.  
  62. componentDidMount() {
  63. this.start()
  64. }
  65. componentWillUnmount() {
  66. clearInterval(this.timer)
  67. }
  68.  
  69.  
  70. start = () => {
  71. const now = 1584959692593
  72. this.setState({
  73. start: now,
  74. now,
  75. laps: [0]
  76. })
  77. this.timer = setInterval(() => {
  78. this.setState({ now: new Date().getTime() })
  79. }, 500)
  80. };
  81.  
  82. setModalVisible(visible) {
  83. this.setState({ modalVisible: visible })
  84. }
  85.  
  86. handleTopUpBCA() {
  87. confirmTopUpBCA(this.state.transactionCode)
  88. .then(data => {
  89. if (data.success) {
  90. this.setModalVisible(true)
  91. }
  92. })
  93. .catch(error => {
  94. console.log(error.response.data)
  95. Alert.alert('Top Up Belum Terkonfirmasi', 'Silahkan menunggu beberapa saat, kami akan melakukan verifikasi pembayaran top up anda')
  96. })
  97. }
  98.  
  99. readFromClipboard = async () => {
  100. // To get the text from clipboard
  101. const clipboardContent = await Clipboard.getString()
  102. this.setState({ clipboardContent })
  103. }
  104.  
  105. writeToClipboard = async () => {
  106. // To copy the text to clipboard
  107. await Clipboard.setString(this.state.clipboardContent)
  108. ToastAndroid.showWithGravityAndOffset(
  109. 'Nominal berhasil di salin',
  110. ToastAndroid.LONG,
  111. ToastAndroid.BOTTOM,
  112. 25,
  113. 50
  114. )
  115. }
  116.  
  117. onTextClipboard = () => {
  118. this.setState({
  119. amount: this.props.navigation.state.params.amount_top_up
  120. })
  121. }
  122. // kuy latest code 2
  123. render() {
  124. firebase.analytics().setCurrentScreen('KONFIRMASI TOP UP')
  125. const { now, start, laps } = this.state
  126. const timer = now - start
  127. if (this.state.now > 1584959692593 + 10000000) {
  128. clearInterval(this.timer)
  129. return (
  130. <Text>Waktu Habis</Text>
  131. )
  132. }
  133.  
  134. return (
  135. <Container style={styles.outerContainer}>
  136. <BackHeader navigate={this.props.navigation}>
  137. KONFIRMASI TOP UP
  138. </BackHeader>
  139. <View style={styles.container}>
  140. <Timer
  141. interval={laps.reduce((total, curr) => total + curr, 0) + timer}
  142. style={styles.timer}
  143. />
  144. </View>
  145. <ScrollView>
  146. <View style={styles.mainContent}>
  147.  
  148.  
  149. <View style={styles.transferToList}>
  150. <Text style={styles.transferToListText}>
  151. Transfer ke no. rekening :
  152. </Text>
  153. <Row style={styles.bankRow}>
  154. <Image source={bcaLogo} />
  155. <Text
  156. style={[
  157. styles.transferToListText,
  158. styles.bankText,
  159. styles.transferToBoldText
  160. ]}
  161. >
  162. Bank BCA, Jakarta
  163. </Text>
  164. </Row>
  165. </View>
  166.  
  167. <View style={[styles.transferToList, styles.removeBorderBottom]}>
  168. <Text
  169. style={[styles.transferToListText, styles.transferToBoldText]}
  170. >
  171. 093 3089 981
  172. </Text>
  173. <Text
  174. style={[styles.transferToListText, styles.transferToBoldText]}
  175. >
  176. a/n PT Halo Komunikasi Sejahtera
  177. </Text>
  178. </View>
  179.  
  180. <View style={styles.transferValueWrapper}>
  181. <View style={styles.transferValueContentTop}>
  182. <Text style={styles.transferValueTitle}>
  183. Jumlah yang harus ditransfer
  184. </Text>
  185. <Row style={styles.transferPriceWrapper}>
  186. <View style={styles.priceWrapper}>
  187. <Text style={styles.transferPrice}>
  188. {currencyFormat(this.state.amount)}
  189. </Text>
  190. <View style={styles.triangle} />
  191. </View>
  192.  
  193. <Button
  194. style={styles.copyButton}
  195. onPress={this.writeToClipboard}
  196. >
  197. <Text style={styles.copyButtonText}>Salin</Text>
  198. </Button>
  199. </Row>
  200. </View>
  201.  
  202. <View style={styles.transferValueContentBottom}>
  203. <Text style={styles.transferValueContentBottomText}>
  204. Transfer tepat sampai{' '}
  205. <Text style={styles.transferToBoldText}>3 digit akhir</Text>.
  206. Perbedaan nomnal menghambat proses verifikasi
  207. </Text>
  208. </View>
  209. </View>
  210. </View>
  211.  
  212. <View style={styles.noteWrapper}>
  213. <Text style={styles.noteTitle}>Petunjuk Transfer :</Text>
  214. <FlatList
  215. data={[
  216. { key: 'Minimal transfer dana sebesar Rp 10.000 (sepuluh ribu rupiah).' },
  217. {
  218. key:
  219. 'Transfer dana tidak akan dikenakan biaya tambahan atau GRATIS.'
  220. }
  221. ]}
  222. renderItem={({ item, index }) => (
  223. <View>
  224. <Text style={[styles.listFont, styles.listNumber]}>
  225. {`${index + 1}. `}
  226. </Text>
  227.  
  228. <Text style={[styles.listFont, styles.listText]}>
  229. {item.key}
  230. </Text>
  231. </View>
  232. )}
  233. />
  234. </View>
  235. </ScrollView>
  236.  
  237. <View style={styles.buttonWrapper}>
  238. <Button
  239. style={styles.buttonStyle}
  240. onPress={() => { this.handleTopUpBCA() }}
  241. >
  242. <LinearGradient
  243. colors={['#FF7E5F', '#FF624B']}
  244. start={{ x: 0, y: 0 }}
  245. end={{ x: 1, y: 0 }}
  246. style={styles.buttonLinear}
  247. >
  248. <Text style={styles.buttonText}>Konfirmasi</Text>
  249. </LinearGradient>
  250. </Button>
  251. </View>
  252.  
  253. <Modal
  254. animationType='slide'
  255. transparent
  256. visible={this.state.modalVisible}
  257. >
  258. <View style={styles.popupWrapper}>
  259. <View style={styles.popupContentWrapper}>
  260. <View style={styles.popupContentHead}>
  261. <Image
  262. source={require('image/topUp/ic_top-up-berhasil.png')}
  263. style={styles.imageTopUp}
  264. resizeMode='contain'
  265. />
  266. <Text style={styles.popupTitle}>Berhasil !</Text>
  267. </View>
  268. <View style={styles.popupContentBody}>
  269. <Text style={styles.popupContent}>Top up via saldo tunai </Text>
  270. <Text style={styles.popupContent}>telah berhasil diproses</Text>
  271. </View>
  272. <View style={styles.popupContentFoot}>
  273. <Button
  274. style={styles.buttonStyle}
  275. onPress={() => {
  276. DeviceEventEmitter.emit('RefreshSaldo')
  277. this.setModalVisible(false)
  278. this.props.navigation.navigate('vendorDashboard')
  279. }}
  280. >
  281. <LinearGradient
  282. colors={['#FF7E5F', '#FF624B']}
  283. start={{ x: 0, y: 0 }}
  284. end={{ x: 1, y: 0 }}
  285. style={styles.buttonLinear}
  286. >
  287. <Text style={styles.buttonText}>OK</Text>
  288. </LinearGradient>
  289. </Button>
  290. </View>
  291. </View>
  292. </View>
  293. </Modal>
  294. </Container>
  295. )
  296. }
  297. }
  298.  
  299. const screenWidth = Dimensions.get('window').width
  300.  
  301. const styles = StyleSheet.create({
  302. outerContainer: {
  303. backgroundColor: '#f7f7f7',
  304. flex: 1,
  305. position: 'relative'
  306. },
  307. mainContent: {
  308. paddingHorizontal: 20,
  309. paddingBottom: 20,
  310. backgroundColor: '#ffffff',
  311. borderBottomWidth: 1,
  312. borderColor: '#e4e4e4'
  313. },
  314. transferToList: {
  315. paddingVertical: 20,
  316. alignItems: 'center',
  317. borderBottomWidth: 1,
  318. borderColor: '#e4e4e4'
  319. },
  320. transferToListText: {
  321. color: '#555555',
  322. fontSize: 15
  323. },
  324. bankRow: {
  325. marginTop: 15
  326. },
  327. bankText: {
  328. marginLeft: 10
  329. },
  330. transferToBoldText: {
  331. fontWeight: 'bold'
  332. },
  333. transferValueWrapper: {
  334. borderRadius: 10,
  335. borderWidth: 1,
  336. borderColor: '#2490D4',
  337. marginTop: 10
  338. },
  339. transferValueContentTop: {
  340. backgroundColor: '#E8F3FA',
  341. borderTopLeftRadius: 8,
  342. borderTopRightRadius: 8,
  343. alignItems: 'center',
  344. padding: 25,
  345. paddingBottom: 20
  346. },
  347. transferValueTitle: {
  348. color: '#707273',
  349. fontSize: 15,
  350. fontWeight: 'bold'
  351. },
  352. transferPriceWrapper: {
  353. alignItems: 'center',
  354. marginTop: 15
  355. },
  356. priceWrapper: {
  357. position: 'relative'
  358. },
  359. triangle: {
  360. backgroundColor: '#1C8CD2',
  361. width: 20,
  362. height: 20,
  363. position: 'absolute',
  364. transform: [{ rotate: '45deg' }],
  365. bottom: -34,
  366. right: 14
  367. },
  368. copyButton: {
  369. backgroundColor: 'transparent',
  370. borderRadius: 8,
  371. elevation: 0,
  372. borderWidth: 1,
  373. borderColor: '#2490D4',
  374. paddingHorizontal: 15,
  375. marginLeft: 15
  376. },
  377. copyButtonText: {
  378. color: '#3598D7',
  379. fontWeight: 'bold'
  380. },
  381. transferPrice: {
  382. color: '#1C8CD2',
  383. fontSize: 28,
  384. fontWeight: 'bold'
  385. },
  386. transferPrice3Digit: {
  387. color: '#136FC1',
  388. position: 'relative'
  389. },
  390. transferValueContentBottom: {
  391. backgroundColor: '#1C8CD2',
  392. borderBottomLeftRadius: 8,
  393. borderBottomRightRadius: 8,
  394. padding: 25
  395. },
  396. transferValueContentBottomText: {
  397. fontSize: 13,
  398. color: '#ffffff',
  399. textAlign: 'center'
  400. },
  401. noteWrapper: {
  402. paddingHorizontal: 20,
  403. paddingTop: 25,
  404. paddingBottom: 40
  405. },
  406. noteTitle: {
  407. color: '#898989',
  408. fontWeight: 'bold',
  409. fontSize: 17
  410. },
  411. listFont: {
  412. color: '#898989',
  413. fontSize: 15
  414. },
  415. listNumber: {
  416. width: 20,
  417. position: 'absolute',
  418. marginTop: 10
  419. },
  420. listText: {
  421. width: screenWidth - 60,
  422. position: 'relative',
  423. left: 20,
  424. marginTop: 10
  425. },
  426. buttonWrapper: {
  427. paddingVertical: 20,
  428. paddingHorizontal: 25,
  429. borderTopWidth: 1,
  430. borderColor: '#dfdfdf',
  431. width: '100%',
  432. backgroundColor: '#ffffff'
  433. },
  434. buttonStyle: {
  435. width: '100%',
  436. borderRadius: 5,
  437. justifyContent: 'center',
  438. elevation: 0
  439. },
  440. buttonLinear: {
  441. width: '100%',
  442. height: '100%',
  443. justifyContent: 'center',
  444. alignItems: 'center',
  445. paddingVertical: 25,
  446. borderTopRightRadius: 8,
  447. borderTopLeftRadius: 8,
  448. borderBottomRightRadius: 8,
  449. borderBottomLeftRadius: 8
  450. },
  451. buttonText: {
  452. color: '#ffffff',
  453. fontWeight: 'bold',
  454. fontSize: 14
  455. },
  456. popupWrapper: {
  457. backgroundColor: 'rgba(52, 52, 52, 0.8)',
  458. flex: 1,
  459. justifyContent: 'center',
  460. alignItems: 'center'
  461. },
  462. popupContentWrapper: {
  463. backgroundColor: '#ffffff',
  464. borderRadius: 8,
  465. width: 300,
  466. alignItems: 'center'
  467. },
  468. popupContentHead: {
  469. paddingTop: 25,
  470. paddingBottom: 20
  471. },
  472. popupContentBody: {
  473. paddingBottom: 20
  474. },
  475. popupContentFoot: {
  476. padding: 20,
  477. borderColor: '#dfdfdf',
  478. borderTopWidth: 1
  479. },
  480. popupTitle: {
  481. color: '#565656',
  482. fontSize: responsiveFontSize(2.2),
  483. fontWeight: 'bold'
  484. },
  485. popupContent: {
  486. color: '#565656',
  487. fontSize: responsiveFontSize(1.8)
  488. },
  489. removeBorderBottom: {
  490. borderBottomWidth: 0
  491. },
  492. imageTopUp: {
  493. width: responsiveWidth(14),
  494. height: responsiveHeight(7.8),
  495. alignSelf: 'center',
  496. marginBottom: responsiveHeight(1.7)
  497. },
  498. // Astaga
  499. timerContainer: {
  500. flexDirection: 'row',
  501. alignItems: 'center'
  502. },
  503. container: {
  504. alignItems: 'center',
  505. backgroundColor: '#FF6D2E',
  506. width: responsiveWidth(100)
  507. },
  508. textTime: {
  509. color: '#FFF',
  510. alignSelf: 'center',
  511. textAlign: 'center'
  512. }
  513. })
  514.  
  515. export default C_KonfirmasiTopUpViaATM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement