From 7ca20f485ba2e3a2926e0728a3d6c8c19636c60c Mon Sep 17 00:00:00 2001 From: hel-axelor <101327380+hel-axelor@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:49:31 +0100 Subject: [PATCH] feat: add Loader toast management (#366) * RM#73988 --- packages/apps/stock/src/index.ts | 8 ++ .../stock/src/screens/loader/LoaderScreen.js | 70 +++++++++++++++++ .../apps/stock/src/screens/loader/index.js | 31 ++++++++ .../src/components/templates/Loader/index.ts | 19 +++++ .../templates/Loader/use-loader-listener.ts | 77 +++++++++++++++++++ .../core/src/components/templates/index.js | 1 + packages/core/src/i18n/translations/en.json | 2 + packages/core/src/i18n/translations/fr.json | 2 + 8 files changed, 210 insertions(+) create mode 100644 packages/apps/stock/src/screens/loader/LoaderScreen.js create mode 100644 packages/apps/stock/src/screens/loader/index.js create mode 100644 packages/core/src/components/templates/Loader/index.ts create mode 100644 packages/core/src/components/templates/Loader/use-loader-listener.ts diff --git a/packages/apps/stock/src/index.ts b/packages/apps/stock/src/index.ts index 23522a1a19..34cfa0230a 100644 --- a/packages/apps/stock/src/index.ts +++ b/packages/apps/stock/src/index.ts @@ -20,6 +20,7 @@ import {Module} from '@axelor/aos-mobile-core'; import CustomerDeliveryScreens from './screens/customerDeliveries'; import InternalMovesScreens from './screens/internalMoves'; import InventoriesScreens from './screens/inventories'; +import LoaderScreens from './screens/loader'; import ProductsScreens from './screens/products'; import StockCorrectionScreens from './screens/stockCorrections'; import SupplierArrivalsScreens from './screens/supplierArrivals'; @@ -45,6 +46,11 @@ export const StockModule: Module = { downToVersion: '7.1.0', }, menus: { + loader_test_screen: { + title: 'Loader', + icon: 'bug-fill', + screen: 'LoaderScreen', + }, stock_menu_product: { title: 'Stock_Product', icon: 'cart-fill', @@ -80,6 +86,7 @@ export const StockModule: Module = { ...CustomerDeliveryScreens, ...InternalMovesScreens, ...InventoriesScreens, + ...LoaderScreens, ...ProductsScreens, ...StockCorrectionScreens, ...SupplierArrivalsScreens, @@ -114,6 +121,7 @@ export * from './screens/auth/UserScreen'; export * from './screens/customerDeliveries'; export * from './screens/internalMoves'; export * from './screens/inventories'; +export * from './screens/loader'; export * from './screens/products'; export * from './screens/stockCorrections'; export * from './screens/supplierArrivals'; diff --git a/packages/apps/stock/src/screens/loader/LoaderScreen.js b/packages/apps/stock/src/screens/loader/LoaderScreen.js new file mode 100644 index 0000000000..f187147e8b --- /dev/null +++ b/packages/apps/stock/src/screens/loader/LoaderScreen.js @@ -0,0 +1,70 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React from 'react'; +import {Button, View} from 'react-native'; +import {Screen} from '@axelor/aos-mobile-ui'; +import {useLoaderListner} from '@axelor/aos-mobile-core'; + +// Screen for test Loader functionnalities +const LoaderScreen = () => { + const process = () => + new Promise(resolve => { + setTimeout(() => { + resolve('Process finished'); + }, 10000); + }); + + const handleCustomAction = () => { + console.log('Custom action executed!'); + }; + + const {loading, listener} = useLoaderListner({ + process, + onSuccess: handleCustomAction, + onError: () => console.warn('An error has occurred!'), + }); + + return ( + + +