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 (