Advertisement
rizkyalviandra

componentTransaction.js

Sep 26th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { StyleSheet, Text, View } from 'react-native';
  4. import Modal from 'react-native-modal';
  5. import Carousel from 'react-native-snap-carousel';
  6. import moment from 'moment';
  7. import { human } from 'react-native-typography';
  8. import {
  9.   TextContainerTop,
  10.   TextContainer,
  11.   TextContainerBotValid,
  12.   TextContainerBotInvalid,
  13. } from '../__textblock';
  14. import PopupItemCard from '../__popupitemcard';
  15. import { CardNavLeft, CardNavRight } from '../__cardnavigationbutton';
  16. import { color, common, dimensions } from '../../styles/theme';
  17. import { itemIndexSelector } from '../../states/selector/__utils';
  18. import { transactionsById, transactionsLength } from '../../states/selector/_transaction';
  19. import { onIncreaseIndex, onDecreaseIndex } from '../../states/__utils';
  20. import ToRupiah from '../../utils/ToRupiah';
  21. import { ParseTotal } from '../../utils/ParseTransaction';
  22.  
  23. class TransactionPopup extends React.PureComponent {
  24.   renderCarousel = ({ item, index }) => { return <PopupItemCard data={item} id={index} />};
  25.  
  26.   render() {
  27.     const {
  28.       isOpen, onClose, data, dataLength, index, increaseIndex, decreaseIndex,
  29.     } = this.props;
  30.  
  31.     return (
  32.       <Modal
  33.         style={styles.modal}
  34.         isVisible={isOpen}
  35.         onBackButtonPress={() => onClose()}
  36.         onBackdropPress={() => onClose()}
  37.         animationIn="fadeInUp"
  38.         animationOut="fadeOutDown"
  39.         animationInTiming={500}
  40.         animationOutTiming={500}
  41.         useNativeDriver
  42.         hideModalContentWhileAnimating
  43.       >
  44.         <View style={styles.modalContainer}>
  45.           <View style={styles.modalHeader}>
  46.             <Text style={[human.headline, common.textPrimary]}>Transaction Details</Text>
  47.             <Text>{`${index + 1} of ${dataLength}`}</Text>
  48.           </View>
  49.           {data ? (
  50.             <React.Fragment>
  51.               <TextContainerTop
  52.                 label="Tanggal"
  53.                 data={moment(data.tanggal).format('DD MMMM YYYY')}
  54.               />
  55.               {data.kode_trans === 'SC' ? (
  56.                 <React.Fragment>
  57.                   <TextContainer label="No.Invoice" data={data.no_invoice} />
  58.                   <TextContainer label="No.Bon Manual" data={data.no_bon_manual || '-'} />
  59.                   <TextContainer label="Outlet" data={data.kd_counter} />
  60.                  
  61.                   {data.details.length !== 0 ? (
  62.                     <React.Fragment>
  63.                       <TextContainer label="Details" data=" " />
  64.                       <View style={styles.detailContainer}>
  65.                         <Carousel
  66.                           data={data.details}
  67.                           renderItem={this.renderCarousel}
  68.                           itemWidth={dimensions.fullWidth * 0.48}
  69.                           sliderWidth={dimensions.fullWidth * 0.8}
  70.                         />
  71.                       </View>
  72.                     </React.Fragment>
  73.                   ) : (
  74.                     <TextContainer label="Details" data="-" />
  75.                   )}
  76.                   <TextContainer label="Quantity" data={data.qty} />
  77.                   <TextContainer label="Gross" data={ToRupiah(ParseTotal(data.details))}  />
  78.                   <TextContainer
  79.                     label="Discount"
  80.                     data={data.discount === null ? '-' : data.discount}
  81.                   />
  82.                   <TextContainer label="Nett" data={ToRupiah(ParseTotal(data.details) - (ParseTotal(data.details) * data.discount))} />
  83.                  
  84.                 </React.Fragment>
  85.               ) : (
  86.                 <React.Fragment>
  87.                   <TextContainer label="No.Invoice" data={data.no_invoice} />
  88.                   <TextContainer label="Outlet" data={data.kd_counter} />
  89.                   <TextContainer label="Details" data={data.remark} />
  90.                 </React.Fragment>
  91.               )}
  92.               {data.is_approved !== '0' ? (
  93.                 <TextContainerBotValid label="Status" data="Approved" />
  94.               ) : (
  95.                 <TextContainerBotInvalid label="Status" data="Waiting For Approval" />
  96.               )}
  97.             </React.Fragment>
  98.           ) : (
  99.             <Text>No transaction detail :(</Text>
  100.           )}
  101.           <View style={styles.modalFooter}>
  102.             {index >= 0 && <CardNavLeft onPress={() => decreaseIndex()} />}
  103.             {index + 1 <= dataLength && <CardNavRight onPress={() => increaseIndex()} />}
  104.           </View>
  105.         </View>
  106.       </Modal>
  107.     );
  108.   }
  109. }
  110.  
  111. const styles = StyleSheet.create({
  112.   modal: {
  113.     justifyContent: 'flex-end',
  114.     margin: 0,
  115.   },
  116.   modalContainer: {
  117.     alignSelf: 'center',
  118.     backgroundColor: color.colorBase,
  119.     width: dimensions.fullWidth,
  120.     borderTopLeftRadius: 4,
  121.     borderTopRightRadius: 4,
  122.     padding: 20,
  123.   },
  124.   modalHeader: {
  125.     flexDirection: 'row',
  126.     justifyContent: 'space-between',
  127.     marginBottom: 8,
  128.   },
  129.   modalFooter: {
  130.     flexDirection: 'row',
  131.     justifyContent: 'space-between',
  132.     marginTop: 8,
  133.   },
  134.   detailContainer: {
  135.     backgroundColor: color.colorOff,
  136.     paddingHorizontal: 16,
  137.     justifyContent: 'center',
  138.     alignItems: 'center',
  139.   },
  140. });
  141.  
  142. const mapStateToProps = state => ({
  143.   data: transactionsById(state),
  144.   dataLength: transactionsLength(state),
  145.   index: itemIndexSelector(state),
  146. });
  147.  
  148. const mapDispatchToProps = dispatch => ({
  149.   increaseIndex: () => {
  150.     dispatch(onIncreaseIndex());
  151.   },
  152.   decreaseIndex: () => {
  153.     dispatch(onDecreaseIndex());
  154.   },
  155. });
  156.  
  157. export default connect(
  158.   mapStateToProps,
  159.   mapDispatchToProps,
  160. )(TransactionPopup);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement