From e2b788928b48d10bf25fabb916b63561faa505a5 Mon Sep 17 00:00:00 2001 From: Ankit Gupta Date: Thu, 18 Feb 2021 15:54:00 +0530 Subject: [PATCH 01/34] fixed multiple tree flow till review page --- app/components/Common/ImageCapturing/index.js | 51 ++++++++----------- app/components/Common/InventoryList/index.js | 5 +- app/components/InventoryOverview/index.js | 42 +++++++-------- app/components/LocateTree/index.js | 1 + app/components/RegisterTree/index.js | 2 - app/components/SelectSpecies/index.js | 17 +++---- app/components/TreeInventory/index.js | 20 ++++++-- 7 files changed, 70 insertions(+), 68 deletions(-) diff --git a/app/components/Common/ImageCapturing/index.js b/app/components/Common/ImageCapturing/index.js index 2e1c7ce83..3960b7efb 100644 --- a/app/components/Common/ImageCapturing/index.js +++ b/app/components/Common/ImageCapturing/index.js @@ -1,5 +1,13 @@ import React, { useState, useContext, useRef, useEffect } from 'react'; -import { View, StyleSheet, SafeAreaView, Image, TouchableOpacity, Modal } from 'react-native'; +import { + View, + StyleSheet, + SafeAreaView, + Image, + TouchableOpacity, + Modal, + BackHandler, +} from 'react-native'; import Header from '../Header'; import PrimaryButton from '../PrimaryButton'; import Alrighty from '../Alrighty'; @@ -55,6 +63,7 @@ const ImageCapturing = ({ const [isAlrightyModalShow, setIsAlrightyModalShow] = useState(false); useEffect(() => { + BackHandler.addEventListener('hardwareBackPress', onBackPress); if (inventoryType === 'multiple') { getCoordByIndex({ inventory_id: state.inventoryID, index: activeMarkerIndex }).then( ({ coordsLength, coord }) => { @@ -72,6 +81,7 @@ const ImageCapturing = ({ } }); } + return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress); }, []); const generateMarkers = () => { @@ -236,34 +246,16 @@ const ImageCapturing = ({ )} - - {/* - - */} - - - {inventoryType === 'single' ? ( - - ) : ( - [] - )} + + {imagePath ? ( setIsAlrightyModalShow(true) : onPressContinue } btnText={i18next.t('label.continue')} - style={inventoryType === 'multiple' ? styles.bottomBtnsWidth : {}} - halfWidth={inventoryType === 'single'} + halfWidth={true} /> ) : ( [] diff --git a/app/components/Common/InventoryList/index.js b/app/components/Common/InventoryList/index.js index 402f63cfb..5c691a2b4 100644 --- a/app/components/Common/InventoryList/index.js +++ b/app/components/Common/InventoryList/index.js @@ -13,6 +13,7 @@ export default function InventoryList({ inventoryList, accessibilityLabel, inven const { dispatch } = useContext(InventoryContext); const onPressInventory = (item) => { + console.log('onPressInventory item', item); setInventoryId(item.inventory_id)(dispatch); if (item.status !== INCOMPLETE_INVENTORY) { navigation.navigate('SingleTreeOverview'); @@ -83,8 +84,8 @@ export default function InventoryList({ inventoryList, accessibilityLabel, inven inventoryStatus === INCOMPLETE_INVENTORY ? null : inventoryStatus === 'pending' - ? 'cloud-outline' - : 'cloud-check' + ? 'cloud-outline' + : 'cloud-check' } data={data} inventoryStatus={inventoryStatus} diff --git a/app/components/InventoryOverview/index.js b/app/components/InventoryOverview/index.js index 3347e0c81..65163ef1b 100644 --- a/app/components/InventoryOverview/index.js +++ b/app/components/InventoryOverview/index.js @@ -13,6 +13,7 @@ import { StyleSheet, Text, View, + BackHandler, } from 'react-native'; import { TouchableOpacity } from 'react-native-gesture-handler'; import DateTimePickerModal from 'react-native-modal-datetime-picker'; @@ -47,13 +48,24 @@ const InventoryOverview = ({ navigation }) => { const [isShowSpeciesListModal, setIsShowSpeciesListModal] = useState(false); useEffect(() => { + BackHandler.addEventListener('hardwareBackPress', hardBackHandler); + const unsubscribe = navigation.addListener('focus', () => { initialState(); let data = { inventory_id: state.inventoryID, last_screen: 'InventoryOverview' }; updateLastScreen(data); }); + return () => { + unsubscribe(); + BackHandler.removeEventListener('hardwareBackPress', hardBackHandler); + }; }, []); + const hardBackHandler = () => { + navigation.navigate('TreeInventory'); + return true; + }; + const initialState = () => { getInventory({ inventoryID: state.inventoryID }).then((inventory) => { setInventory(inventory); @@ -246,7 +258,7 @@ const InventoryOverview = ({ navigation }) => { }; const renderDatePicker = () => { - const handleConfirm = (data) => onChangeDate(null, data); + const handleConfirm = (data) => onChangeDate(data); const hideDatePicker = () => setShowDate(false); return ( @@ -267,7 +279,7 @@ const InventoryOverview = ({ navigation }) => { ); }; - const onChangeDate = (event, selectedDate) => { + const onChangeDate = (selectedDate) => { setShowDate(false); setInventory({ ...inventory, plantation_date: selectedDate }); updatePlantingDate({ @@ -280,7 +292,7 @@ const InventoryOverview = ({ navigation }) => { return ( status === INCOMPLETE_INVENTORY && ( setIsShowSpeciesListModal(true)} + onPress={handleSelectSpecies} style={{ flexDirection: 'row', justifyContent: 'space-around', @@ -306,7 +318,7 @@ const InventoryOverview = ({ navigation }) => { }; const onPressDate = (status) => { - if (status === INCOMPLETE_INVENTORY && inventory.locate_tree == 'off-site') { + if (status === INCOMPLETE_INVENTORY && inventory.locate_tree === 'off-site') { setShowDate(true); } }; @@ -318,20 +330,11 @@ const InventoryOverview = ({ navigation }) => { }); }; - const renderSelectSpeciesModal = () => { - const closeSelectSpeciesModal = () => setIsShowSpeciesListModal(false); - if (inventory) { - return ( - - ); - } else { - return; - } + const handleSelectSpecies = () => { + navigation.navigate('SelectSpecies', { + closeSelectSpeciesModal: () => setIsShowSpeciesListModal(false), + onPressSaveAndContinueMultiple, + }); }; let locationType; @@ -374,7 +377,7 @@ const InventoryOverview = ({ navigation }) => { {renderDatePicker()} - {renderSelectSpeciesModal()} ); }; diff --git a/app/components/LocateTree/index.js b/app/components/LocateTree/index.js index bcc1b1c96..ac0b9e890 100644 --- a/app/components/LocateTree/index.js +++ b/app/components/LocateTree/index.js @@ -89,6 +89,7 @@ const LocateTree = ({ navigation }) => { heading={i18next.t('label.locate_tree_geo_json')} subHeadingStyle={{ fontStyle: 'italic' }} rightIcon={} + disabled /> {isRooted && Device is rooted} diff --git a/app/components/RegisterTree/index.js b/app/components/RegisterTree/index.js index ef5904af6..de40aef98 100644 --- a/app/components/RegisterTree/index.js +++ b/app/components/RegisterTree/index.js @@ -59,8 +59,6 @@ const RegisterTree = ({ navigation }) => { subHeadingStyle={treeType === 'multiple' && styles.activeTextColor} testID={'page_rt_multiple_trees'} accessibilityLabel={'Multiple Trees'} - disabled - style={{ backgroundColor: Colors.GRAY_LIGHT }} /> diff --git a/app/components/SelectSpecies/index.js b/app/components/SelectSpecies/index.js index d866be84b..047ea24eb 100644 --- a/app/components/SelectSpecies/index.js +++ b/app/components/SelectSpecies/index.js @@ -1,4 +1,4 @@ -import { useNavigation } from '@react-navigation/native'; +import { useNavigation, useRoute } from '@react-navigation/native'; import i18next from 'i18next'; import React, { useContext, useEffect, useState } from 'react'; import { @@ -25,13 +25,7 @@ import { Header, PrimaryButton } from '../Common'; import ManageSpecies from '../ManageSpecies'; import { updateSingleTreeSpecie } from '../../repositories/inventory'; -const SelectSpecies = ({ - visible, - closeSelectSpeciesModal, - route, - invent, - onPressSaveAndContinueMultiple, -}) => { +const SelectSpecies = () => { const [isShowTreeCountModal, setIsShowTreeCountModal] = useState(false); const [treeCount, setTreeCount] = useState(''); const [activeSpecie, setActiveSpecie] = useState(undefined); @@ -52,6 +46,7 @@ const SelectSpecies = ({ const { state } = useContext(InventoryContext); const { state: speciesState, dispatch: speciesDispatch } = useContext(SpeciesContext); const navigation = useNavigation(); + const route = useRoute(); useEffect(() => { // let species; @@ -162,12 +157,14 @@ const SelectSpecies = ({ } } - onPressSaveAndContinueMultiple(selectedSpeciesList); + if (route?.params?.onPressSaveAndContinueMultiple) { + route.params.onPressSaveAndContinueMultiple(selectedSpeciesList); + } setActiveSpecie(undefined); setIsShowTreeCountModal(false); setTreeCount(''); - closeSelectSpeciesModal(); + navigation.goBack(); }; const renderTreeCountModal = () => { diff --git a/app/components/TreeInventory/index.js b/app/components/TreeInventory/index.js index ebbeab8dc..f09d010b8 100644 --- a/app/components/TreeInventory/index.js +++ b/app/components/TreeInventory/index.js @@ -1,7 +1,15 @@ import { StackActions } from '@react-navigation/native'; import i18next from 'i18next'; import React, { useContext, useEffect, useState } from 'react'; -import { ActivityIndicator, SafeAreaView, ScrollView, StyleSheet, View, Alert } from 'react-native'; +import { + ActivityIndicator, + SafeAreaView, + ScrollView, + StyleSheet, + View, + Alert, + BackHandler, +} from 'react-native'; import { SvgXml } from 'react-native-svg'; import { Colors } from '_styles'; import { empty_inventory_banner } from '../../assets'; @@ -19,11 +27,15 @@ const TreeInventory = ({ navigation }) => { const [allInventory, setAllInventory] = useState(null); useEffect(() => { + // BackHandler.addEventListener('hardwareBackPress', handleBackPress); const unsubscribe = navigation.addListener('focus', () => { initialState(); }); - return unsubscribe; + return () => { + unsubscribe(); + // BackHandler.removeEventListener('hardwareBackPress', handleBackPress); + }; }, [navigation]); const handleBackPress = () => { @@ -186,8 +198,8 @@ const TreeInventory = ({ navigation }) => { {allInventory && allInventory.length > 0 ? renderInventoryListContainer() : allInventory == null - ? renderLoadingInventoryList() - : renderEmptyInventoryList()} + ? renderLoadingInventoryList() + : renderEmptyInventoryList()} ); }; From fd7e7b7699a886c7f4e6c2bf8e6b74e74ade4e7f Mon Sep 17 00:00:00 2001 From: Ankit Gupta Date: Thu, 18 Feb 2021 17:04:29 +0530 Subject: [PATCH 02/34] fixed plantation date on review page --- .eslintrc.js | 75 +++++++++----------- app/components/Common/InventoryList/index.js | 4 +- app/components/InventoryOverview/index.js | 2 +- app/components/TreeInventory/index.js | 4 +- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index da80cc971..ca92c7c7c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,44 +1,37 @@ module.exports = { - "env": { - "browser": true, - "es6": true, - "react-native/react-native": true, + env: { + browser: true, + es6: true, + 'react-native/react-native': true, + }, + extends: ['eslint:recommended', 'plugin:react/recommended'], + globals: { + Atomics: 'readonly', + SharedArrayBuffer: 'readonly', + }, + parserOptions: { + ecmaFeatures: { + jsx: true, }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended" - ], - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": [ - "react", - "react-native", - "prettier" - ], - "parser": "babel-eslint", - "rules": { - indent: ['error', 2, { SwitchCase: 1 }], - quotes: ['error', 'single'], - semi: ['error', 'always'], - 'linebreak-style': ['error', 'unix'], - 'no-undef': ['error'], - 'no-console': ['warn'], - 'no-unused-vars': ['warn'], - 'react/prop-types': ['off'], - 'react-native/no-unused-styles': ['warn'], - 'react-native/split-platform-components': ['warn'], - 'react-native/no-inline-styles': ['warn'], - 'react-native/no-color-literals': ['off'], - 'prettier/prettier': 0, - 'eslint(no-prototype-builtins)': 0 - } + ecmaVersion: 2018, + sourceType: 'module', + }, + plugins: ['react', 'react-native', 'prettier'], + parser: 'babel-eslint', + rules: { + indent: ['error', 2, { SwitchCase: 1 }], + quotes: ['error', 'single'], + semi: ['error', 'always'], + 'linebreak-style': ['error', 'windows'], + 'no-undef': ['error'], + 'no-console': ['warn'], + 'no-unused-vars': ['warn'], + 'react/prop-types': ['off'], + 'react-native/no-unused-styles': ['warn'], + 'react-native/split-platform-components': ['warn'], + 'react-native/no-inline-styles': ['warn'], + 'react-native/no-color-literals': ['off'], + 'prettier/prettier': 0, + 'eslint(no-prototype-builtins)': 0, + }, }; diff --git a/app/components/Common/InventoryList/index.js b/app/components/Common/InventoryList/index.js index 5c691a2b4..2a24f5b67 100644 --- a/app/components/Common/InventoryList/index.js +++ b/app/components/Common/InventoryList/index.js @@ -84,8 +84,8 @@ export default function InventoryList({ inventoryList, accessibilityLabel, inven inventoryStatus === INCOMPLETE_INVENTORY ? null : inventoryStatus === 'pending' - ? 'cloud-outline' - : 'cloud-check' + ? 'cloud-outline' + : 'cloud-check' } data={data} inventoryStatus={inventoryStatus} diff --git a/app/components/InventoryOverview/index.js b/app/components/InventoryOverview/index.js index 65163ef1b..f16628be6 100644 --- a/app/components/InventoryOverview/index.js +++ b/app/components/InventoryOverview/index.js @@ -367,7 +367,7 @@ const InventoryOverview = ({ navigation }) => {