Advertisement
Badal_hs_shah

Untitled

Feb 13th, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {RW3PriceCheck} from './../services/models/RW3PriceCheck';
  2. import {FlatList, SafeAreaView, StyleSheet, Text, View} from 'react-native';
  3. import {useEffect, useState} from 'react';
  4. import {useTheme} from '@src/themes';
  5. import {useRoute} from '@react-navigation/native';
  6. import InvalidVersionAlert from '@src/components/atoms/InvalidVersionAlert';
  7. import React from 'react';
  8. import renderSeparatorListView from '@src/components/atoms/renderSeparatorListView';
  9. import StorelistcellDS from '@src/components/storeList/StorecellDS';
  10. import {convertDate} from '@src/constants/ISPCHelper';
  11. import {RW3PriceCheckType} from '@src/services/models/RW3PriceCheckType';
  12.  
  13. const PricecheckList = () => {
  14.   const routes = useRoute<any>();
  15.   const {theme, dark} = useTheme();
  16.   //Required for display Alert
  17.   const [alertTitle, setAlertTitle] = useState<string>();
  18.   const [alertOptions, setAlertOptions] = useState<string[]>([]);
  19.   const [alertMessage, setAlertMessage] = useState<string[]>([]);
  20.   const refAlert = React.useRef<any>();
  21.   //=============================================
  22.   const [priceCheckList, setPriceCheckList] = useState<RW3PriceCheck[]>([]);
  23.  
  24.   useEffect(() => {
  25.     // let priceCheck = routes.params.priceChecks;
  26.     const {priceChecks} = routes.params;
  27.     setPriceCheckList(priceChecks);
  28.   }, [routes.params]);
  29.  
  30.   const renderSeparator = () => {
  31.     return <View style={[styles.viewSeparator]} />;
  32.   };
  33.  
  34.   const renderItem = ({item, index}) => {
  35.     const priceCheck: RW3PriceCheck = item;
  36.     const type: RW3PriceCheckType = priceCheck.type;
  37.  
  38.     let formattedDate;
  39.  
  40.     const displayViewType = (() => {
  41.       if (type === RW3PriceCheckType.RW3PriceCheckTypeBoth) {
  42.         formattedDate = convertDate(priceCheck.endDate);
  43.         return priceCheck.hasScrapeData ? 4 : 3;
  44.       } else {
  45.         formattedDate = convertDate(priceCheck.endDate);
  46.         return priceCheck.hasScrapeData ? 2 : 1;
  47.       }
  48.     })();
  49.  
  50.     <StorelistcellDS
  51.       displayDate={formattedDate}
  52.       currentType={displayViewType}
  53.       mainTitle={priceCheck.name}
  54.       subTitle={''}
  55.       distance={''}
  56.       currentPricecheck={priceCheck}
  57.       isFromPriceCheck={true}
  58.       onPress={function () {
  59.         //navigateToPricecheckList(item);
  60.       }}
  61.     />;
  62.   };
  63.  
  64.   return (
  65.     <SafeAreaView
  66.       style={[
  67.         styles.safeAreaContainer,
  68.         {backgroundColor: theme.palette.appWhiteColor},
  69.       ]}>
  70.       <View
  71.         style={[
  72.           styles.viewContainer,
  73.           {
  74.             backgroundColor: theme.palette.backgroundcolor,
  75.           },
  76.         ]}>
  77.         <InvalidVersionAlert
  78.           ref={refAlert}
  79.           title={alertTitle}
  80.           message={alertMessage}
  81.           options={alertOptions}
  82.           cancelButtonIndex={0}
  83.         />
  84.         <FlatList
  85.           data={priceCheckList}
  86.           keyExtractor={(item, index) => `${index}`}
  87.           renderItem={renderItem}
  88.           ItemSeparatorComponent={renderSeparator}
  89.         />
  90.       </View>
  91.     </SafeAreaView>
  92.   );
  93. };
  94.  
  95. export default PricecheckList;
  96.  
  97. const styles = StyleSheet.create({
  98.   safeAreaContainer: {flex: 1},
  99.   viewContainer: {flex: 1, padding: 0},
  100.   viewSeparator: {
  101.     height: 1,
  102.     width: '100%',
  103.     backgroundColor: '#CED0CE',
  104.   },
  105. });
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement