From f9a754560ffac2db08938cc2e61ca1ea89c54539 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Mon, 25 Mar 2024 15:20:42 +0800 Subject: [PATCH 1/7] if org null checked condition --- src/features/Account/screens/AccountScreen.js | 3 +- .../Account/screens/OrganizationScreen.js | 20 +++++++----- src/features/Core/screens/OrdersScreen.js | 32 +++++++++++++------ translations/en.json | 4 +++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/features/Account/screens/AccountScreen.js b/src/features/Account/screens/AccountScreen.js index f3697597..7d9bac76 100644 --- a/src/features/Account/screens/AccountScreen.js +++ b/src/features/Account/screens/AccountScreen.js @@ -27,7 +27,8 @@ const AccountScreen = ({ navigation }) => { }; useEffect(() => { - driver.currentOrganization().then(setCurrentOrganization); + const res = driver.currentOrganization().then(setCurrentOrganization); + console.log('current::::', JSON.stringify(currentOrganization)); }, []); const RenderBackground = props => { diff --git a/src/features/Account/screens/OrganizationScreen.js b/src/features/Account/screens/OrganizationScreen.js index 710a2837..08f90155 100644 --- a/src/features/Account/screens/OrganizationScreen.js +++ b/src/features/Account/screens/OrganizationScreen.js @@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react'; import { ActivityIndicator, Alert, FlatList, RefreshControl, Text, TouchableOpacity, View } from 'react-native'; import Toast from 'react-native-toast-message'; import tailwind from 'tailwind'; -import { getColorCode, logError } from 'utils'; +import { getColorCode, logError, translate } from 'utils'; import { useDriver } from 'utils/Auth'; const Organization = ({ navigation, route }) => { @@ -95,19 +95,23 @@ const Organization = ({ navigation, route }) => { ) : ( - Organizations + {translate('Account.OrganizationScreen.title')} navigation.goBack()} style={tailwind('rounded-full ')}> )} - } - data={organizations} - keyExtractor={item => item.id} - renderItem={renderItem} - /> + {organizations.length === 0 ? ( + {translate('Account.OrganizationScreen.empty')} + ) : ( + } + data={organizations} + keyExtractor={item => item.id} + renderItem={renderItem} + /> + )} ); }; diff --git a/src/features/Core/screens/OrdersScreen.js b/src/features/Core/screens/OrdersScreen.js index b578cd28..733c1778 100644 --- a/src/features/Core/screens/OrdersScreen.js +++ b/src/features/Core/screens/OrdersScreen.js @@ -33,6 +33,8 @@ const OrdersScreen = ({ navigation }) => { const [isLoaded, setIsLoaded] = useState(false); const [orders, setOrders] = useResourceCollection(`orders_${format(date, 'yyyyMMdd')}`, Order, fleetbase.getAdapter()); const [nearbyOrders, setNearbyOrders] = useState([]); + const [currentOrganization, setCurrentOrganization] = useState(); + const [searchingForNearbyOrders, setSearchingForNearbyOrders] = useState(false); const startingDate = new Date().setDate(date.getDate() - 2); const datesWhitelist = [ @@ -52,7 +54,7 @@ const OrdersScreen = ({ navigation }) => { setParams(prevParams => ({ ...prevParams, [key]: updatedValue })); }, []); - const loadOrders = useCallback((options = {}) => { + const loadOrders = useCallback(async (options = {}) => { if (options.isRefreshing) { setIsRefreshing(true); } @@ -61,17 +63,27 @@ const OrdersScreen = ({ navigation }) => { setIsQuerying(true); } - return fleetbase.orders - .query(params) - .then(setOrders) - .catch(logError) - .finally(() => { - setIsRefreshing(false); - setIsQuerying(false); - setIsLoaded(true); - }); + try { + const updatedParams = { + ...params, + company_uuid: currentOrganization?.id, + }; + + const ordersData = await fleetbase.orders.query(updatedParams); + setOrders(ordersData); + } catch (error) { + logError(error); + } finally { + setIsRefreshing(false); + setIsQuerying(false); + setIsLoaded(true); + } }); + useEffect(() => { + driver.currentOrganization().then(setCurrentOrganization); + console.log('current::::', JSON.stringify(currentOrganization)); + }, []); const loadNearbyOrders = useCallback((options = {}) => { if (options.isRefreshing) { setIsRefreshing(true); diff --git a/translations/en.json b/translations/en.json index 82038bf1..a046b288 100644 --- a/translations/en.json +++ b/translations/en.json @@ -19,6 +19,10 @@ "emailLabelText": "Your email address", "phoneLabelText": "Your mobile number", "saveButtonText": "Save Profile" + }, + "OrganizationScreen": { + "title": "Organizations", + "empty": "No organizations" } }, "Auth": { From 1d07b3a89d1fdb391331fb5477c7da4ac48f823c Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Mon, 25 Mar 2024 18:18:21 +0800 Subject: [PATCH 2/7] org data is passed in the order data --- src/features/Core/screens/OrdersScreen.js | 55 +++++++++++++---------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/features/Core/screens/OrdersScreen.js b/src/features/Core/screens/OrdersScreen.js index 733c1778..c6cacbb8 100644 --- a/src/features/Core/screens/OrdersScreen.js +++ b/src/features/Core/screens/OrdersScreen.js @@ -54,35 +54,44 @@ const OrdersScreen = ({ navigation }) => { setParams(prevParams => ({ ...prevParams, [key]: updatedValue })); }, []); - const loadOrders = useCallback(async (options = {}) => { - if (options.isRefreshing) { - setIsRefreshing(true); - } + const loadOrders = useCallback( + async (options = {}) => { + if (options.isRefreshing) { + setIsRefreshing(true); + } - if (options.isQuerying) { - setIsQuerying(true); - } + if (options.isQuerying) { + setIsQuerying(true); + } - try { - const updatedParams = { - ...params, - company_uuid: currentOrganization?.id, - }; - - const ordersData = await fleetbase.orders.query(updatedParams); - setOrders(ordersData); - } catch (error) { - logError(error); - } finally { - setIsRefreshing(false); - setIsQuerying(false); - setIsLoaded(true); + try { + // Fetch orders based on the selected organization + const updatedParams = { + ...params, + company: currentOrganization?.id, // Use the current organization's ID + }; + + const ordersData = await fleetbase.orders.query(updatedParams); + setOrders(ordersData); + } catch (error) { + logError(error); + } finally { + setIsRefreshing(false); + setIsQuerying(false); + setIsLoaded(true); + } + }, + [currentOrganization, params, fleetbase.orders] + ); + + useEffect(() => { + if (currentOrganization) { + loadOrders({ isQuerying: isLoaded }); } - }); + }, [currentOrganization]); useEffect(() => { driver.currentOrganization().then(setCurrentOrganization); - console.log('current::::', JSON.stringify(currentOrganization)); }, []); const loadNearbyOrders = useCallback((options = {}) => { if (options.isRefreshing) { From 6861cd40d240016a62406d9155d1edfdd5ad4958 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 12:00:34 +0800 Subject: [PATCH 3/7] added org token util --- src/features/Core/screens/OrdersScreen.js | 44 ++++++++--------------- src/hooks/use-fleetbase.js | 5 +-- src/utils/Helper.js | 6 ++++ src/utils/index.js | 2 ++ 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/features/Core/screens/OrdersScreen.js b/src/features/Core/screens/OrdersScreen.js index c6cacbb8..bd9a1c71 100644 --- a/src/features/Core/screens/OrdersScreen.js +++ b/src/features/Core/screens/OrdersScreen.js @@ -54,41 +54,25 @@ const OrdersScreen = ({ navigation }) => { setParams(prevParams => ({ ...prevParams, [key]: updatedValue })); }, []); - const loadOrders = useCallback( - async (options = {}) => { - if (options.isRefreshing) { - setIsRefreshing(true); - } - - if (options.isQuerying) { - setIsQuerying(true); - } + const loadOrders = useCallback((options = {}) => { + if (options.isRefreshing) { + setIsRefreshing(true); + } - try { - // Fetch orders based on the selected organization - const updatedParams = { - ...params, - company: currentOrganization?.id, // Use the current organization's ID - }; + if (options.isQuerying) { + setIsQuerying(true); + } - const ordersData = await fleetbase.orders.query(updatedParams); - setOrders(ordersData); - } catch (error) { - logError(error); - } finally { + return fleetbase.orders + .query(params) + .then(setOrders) + .catch(logError) + .finally(() => { setIsRefreshing(false); setIsQuerying(false); setIsLoaded(true); - } - }, - [currentOrganization, params, fleetbase.orders] - ); - - useEffect(() => { - if (currentOrganization) { - loadOrders({ isQuerying: isLoaded }); - } - }, [currentOrganization]); + }); + }); useEffect(() => { driver.currentOrganization().then(setCurrentOrganization); diff --git a/src/hooks/use-fleetbase.js b/src/hooks/use-fleetbase.js index d92c7912..a9b04d6f 100644 --- a/src/hooks/use-fleetbase.js +++ b/src/hooks/use-fleetbase.js @@ -1,6 +1,7 @@ import Fleetbase from '@fleetbase/sdk'; import config from 'config'; -import { getString, get } from 'utils/Storage'; +import { isObject } from 'utils'; +import { get, getString } from 'utils/Storage'; const useFleetbase = () => { let { FLEETBASE_KEY, FLEETBASE_HOST, FLEETBASE_NAMESPACE } = config; @@ -16,7 +17,7 @@ const useFleetbase = () => { FLEETBASE_HOST = _FLEETBASE_HOST; } - if (typeof _DRIVER === 'object' && typeof _DRIVER?.token === 'string') { + if (isObject(_DRIVER) && typeof _DRIVER.token === 'string') { FLEETBASE_KEY = _DRIVER.token; } diff --git a/src/utils/Helper.js b/src/utils/Helper.js index 1c28420a..3114ad94 100644 --- a/src/utils/Helper.js +++ b/src/utils/Helper.js @@ -575,6 +575,10 @@ export default class HelperUtil { subtitle, }; } + + static isObject(obj) { + return obj && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]'; + } } const listCountries = HelperUtil.listCountries; @@ -588,6 +592,7 @@ const isApple = HelperUtil.isApple(); const isVoid = HelperUtil.isVoid; const isEmpty = HelperUtil.isEmpty; const isFalsy = HelperUtil.isFalsy; +const isObject = HelperUtil.isObject; const logError = HelperUtil.logError; const mutatePlaces = HelperUtil.mutatePlaces; const debounce = HelperUtil.debounce; @@ -613,6 +618,7 @@ export { isArray, isEmpty, isFalsy, + isObject, isLastIndex, isVoid, listCountries, diff --git a/src/utils/index.js b/src/utils/index.js index 86960b77..6e1516f3 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -10,6 +10,7 @@ import { isVoid, isEmpty, isFalsy, + isObject, logError, mutatePlaces, debounce, @@ -121,6 +122,7 @@ export { isVoid, isEmpty, isFalsy, + isObject, toBoolean, logError, calculatePercentage, From 6e15133352a5d022dd4f3f0e2ee6966f58d08ab2 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 12:24:23 +0800 Subject: [PATCH 4/7] added current org icon --- src/features/Account/screens/OrganizationScreen.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/features/Account/screens/OrganizationScreen.js b/src/features/Account/screens/OrganizationScreen.js index 08f90155..bd7a243a 100644 --- a/src/features/Account/screens/OrganizationScreen.js +++ b/src/features/Account/screens/OrganizationScreen.js @@ -1,4 +1,4 @@ -import { faWindowClose } from '@fortawesome/free-solid-svg-icons'; +import { faWindowClose, faCheck } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'; import React, { useEffect, useState } from 'react'; import { ActivityIndicator, Alert, FlatList, RefreshControl, Text, TouchableOpacity, View } from 'react-native'; @@ -81,8 +81,9 @@ const Organization = ({ navigation, route }) => { - {item?.getAttribute('name')} + {item.getAttribute('name')} + {currentOrganization.getAttribute('id') === item.id && } From 6a9202440cedf396c42c667daf986e5d297909aa Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 13:01:02 +0800 Subject: [PATCH 5/7] upgraded version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 37f9d9ff..12d8217a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/navigator-app", - "version": "1.1.15", + "version": "1.1.16", "description": "Fleetbase Fleet-Ops extension provides a fleet management and last mile delivery operations system module.", "keywords": [ "fleetbase-navigator", @@ -43,7 +43,7 @@ "@react-native-community/masked-view": "^0.1.11", "@react-native-community/netinfo": "^11.2.1", "@react-native-community/push-notification-ios": "^1.8.0", - "@react-native-picker/picker": "^2.0.31", + "@react-native-picker/picker": "2.0.31", "@react-navigation/bottom-tabs": "^6.3.1", "@react-navigation/native": "^6.0.10", "@react-navigation/stack": "^6.2.1", From af118ad6ba11686f7b238ced5959e08565eab0d8 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 13:19:36 +0800 Subject: [PATCH 6/7] removed unused package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 12d8217a..945bc074 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@react-native-community/masked-view": "^0.1.11", "@react-native-community/netinfo": "^11.2.1", "@react-native-community/push-notification-ios": "^1.8.0", - "@react-native-picker/picker": "2.0.31", "@react-navigation/bottom-tabs": "^6.3.1", "@react-navigation/native": "^6.0.10", "@react-navigation/stack": "^6.2.1", From 8007bd0e7bb2dd1f57034ba43b66665d7ef42674 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 16:16:24 +0800 Subject: [PATCH 7/7] updated icon --- src/features/Account/screens/OrganizationScreen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/Account/screens/OrganizationScreen.js b/src/features/Account/screens/OrganizationScreen.js index bd7a243a..d110ad11 100644 --- a/src/features/Account/screens/OrganizationScreen.js +++ b/src/features/Account/screens/OrganizationScreen.js @@ -79,11 +79,11 @@ const Organization = ({ navigation, route }) => { const renderItem = ({ item }) => ( confirmSwitchOrganization(item.id)}> - + {item.getAttribute('name')} - {currentOrganization.getAttribute('id') === item.id && } + {currentOrganization.getAttribute('id') === item.id && }