From f7952a09ac0fa7ec7d4f7a2a3b70af6e953c3b65 Mon Sep 17 00:00:00 2001 From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com> Date: Fri, 2 Aug 2024 10:11:16 +0200 Subject: [PATCH] fix: null issue on product details (#668) * RM#82727 --- changelogs/unreleased/82727.json | 5 +++++ .../src/hooks/use-stock-header-actions.js | 4 ++-- .../products/ProductStockDetailsScreen.js | 22 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/82727.json diff --git a/changelogs/unreleased/82727.json b/changelogs/unreleased/82727.json new file mode 100644 index 0000000000..eda1e2a25b --- /dev/null +++ b/changelogs/unreleased/82727.json @@ -0,0 +1,5 @@ +{ + "title": "Product details: add activity indicator when product is null to avoid errors", + "type": "fix", + "packages": "stock" +} diff --git a/packages/apps/stock/src/hooks/use-stock-header-actions.js b/packages/apps/stock/src/hooks/use-stock-header-actions.js index 2e2a355e7e..42e3dc52da 100644 --- a/packages/apps/stock/src/hooks/use-stock-header-actions.js +++ b/packages/apps/stock/src/hooks/use-stock-header-actions.js @@ -236,7 +236,7 @@ const useProductDetailsActions = () => { model: 'com.axelor.apps.base.db.Product', modelId: product?.id, disableMailMessages: !mobileSettings?.isTrackerMessageEnabled, - attachedFileScreenTitle: product.name, + attachedFileScreenTitle: product?.name, }); }, [mobileSettings, product]); }; @@ -250,7 +250,7 @@ const useProductStockDetailsActions = () => { model: 'com.axelor.apps.base.db.Product', modelId: product?.id, disableMailMessages: !mobileSettings?.isTrackerMessageEnabled, - attachedFileScreenTitle: product.name, + attachedFileScreenTitle: product?.name, }); }, [mobileSettings, product]); }; diff --git a/packages/apps/stock/src/screens/products/ProductStockDetailsScreen.js b/packages/apps/stock/src/screens/products/ProductStockDetailsScreen.js index 7d428b7f7d..b039623a15 100644 --- a/packages/apps/stock/src/screens/products/ProductStockDetailsScreen.js +++ b/packages/apps/stock/src/screens/products/ProductStockDetailsScreen.js @@ -18,12 +18,18 @@ import React, {useCallback, useEffect, useState} from 'react'; import {StyleSheet, View, Dimensions} from 'react-native'; -import {EditableInput, Picker, Screen, ScrollView} from '@axelor/aos-mobile-ui'; import { - useSelector, + EditableInput, + Picker, + Screen, + ScrollView, + useConfig, +} from '@axelor/aos-mobile-ui'; +import { useDispatch, - useTranslator, usePermitted, + useSelector, + useTranslator, } from '@axelor/aos-mobile-core'; import { ProductCardStockIndicatorList, @@ -47,6 +53,7 @@ const ProductStockDetailsScreen = ({route}) => { const {readonly, hidden} = usePermitted({ modelName: 'com.axelor.apps.stock.db.StockLocationLine', }); + const {setActivityIndicator} = useConfig(); const {loadingProductFromId, productFromId: product} = useSelector( state => state.product, @@ -91,6 +98,11 @@ const ProductStockDetailsScreen = ({route}) => { } }, [companyId, dispatch, product, stockLocation]); + useEffect(() => { + const isActivityIndicator = loadingProductFromId && product?.id == null; + setActivityIndicator(isActivityIndicator); + }, [loadingProductFromId, product, setActivityIndicator]); + const handleLockerChange = input => { if (stockLocation != null) { dispatch( @@ -104,6 +116,10 @@ const ProductStockDetailsScreen = ({route}) => { } }; + if (product?.id !== productId) { + return null; + } + return (