From d20b49a4fe99226232d394327a082f6a38409a1a Mon Sep 17 00:00:00 2001 From: Sanskar Soni Date: Tue, 29 Aug 2023 16:39:52 +0530 Subject: [PATCH] Implemented: toast for Blocked Pop-Ups when Generating Order Documents, changes in showToast function as needed and changes in progress view (how show toast is called) as showToast function changed (#254) --- src/locales/en.json | 1 + src/locales/es.json | 1 + src/services/OrderService.ts | 30 +++++++++++++++++++++++++----- src/utils/index.ts | 18 +++++++++--------- src/views/InProgress.vue | 4 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 399fcb25..0f81eaaf 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -238,6 +238,7 @@ "Turn on fulfillment": "Turn on fulfillment", "Turn on fulfillment for ": "Turn on fulfillment for { facilityName }", "Turn off fulfillment for ": "Turn off fulfillment for { facilityName }", + "Unable to open as browser is blocking pop-ups.": "Unable to open { documentName } as browser is blocking pop-ups.", "Unpack": "Unpack", "Unpacking this order will send it back to 'In progress' and it will have to be repacked.": "Unpacking this order will send it back to 'In progress' and it will have to be repacked.", "Update": "Update", diff --git a/src/locales/es.json b/src/locales/es.json index d7fdc4f9..d9d6dcb8 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -238,6 +238,7 @@ "Turn on fulfillment": "Activar Cumplimiento", "Turn on fulfillment for ": "Activar cumplimiento para {facilityName}", "Turn off fulfillment for ": "Desactivar cumplimiento para {facilityName}", + "Unable to open as browser is blocking pop-ups.": "Unable to open { documentName } as browser is blocking pop-ups.", "Unpack": "Desempacar", "Unpacking this order will send it back to 'In progress' and it will have to be repacked.": "Desempacar este pedido lo enviará de vuelta a 'En curso' y tendrá que ser vuelto a empacar.", "Update": "Update", diff --git a/src/services/OrderService.ts b/src/services/OrderService.ts index 942e4a26..1928f271 100644 --- a/src/services/OrderService.ts +++ b/src/services/OrderService.ts @@ -3,6 +3,7 @@ import { translate } from '@/i18n'; import logger from '@/logger'; import { showToast } from '@/utils'; import store from '@/store'; +import { cogOutline } from 'ionicons/icons'; const findOpenOrders = async (query: any): Promise => { return api({ @@ -191,7 +192,12 @@ const printPackingSlip = async (shipmentIds: Array): Promise => { // Generate local file URL for the blob received const pdfUrl = window.URL.createObjectURL(resp.data); // Open the file in new tab - (window as any).open(pdfUrl, "_blank").focus(); + try { + (window as any).open(pdfUrl, "_blank").focus(); + } + catch { + showToast(translate('Unable to open as browser is blocking pop-ups.', {documentName: 'packing slip'}), { icon: cogOutline }); + } } catch (err) { showToast(translate('Failed to print packing slip')) @@ -218,7 +224,12 @@ const printShippingLabel = async (shipmentIds: Array): Promise => { // Generate local file URL for the blob received const pdfUrl = window.URL.createObjectURL(resp.data); // Open the file in new tab - (window as any).open(pdfUrl, "_blank").focus(); + try { + (window as any).open(pdfUrl, "_blank").focus(); + } + catch { + showToast(translate('Unable to open as browser is blocking pop-ups.', {documentName: 'shipping label'}), { icon: cogOutline }); + } } catch (err) { showToast(translate('Failed to print shipping label')) @@ -246,7 +257,12 @@ const printShippingLabelAndPackingSlip = async (shipmentIds: Array): Pro // Generate local file URL for the blob received const pdfUrl = window.URL.createObjectURL(resp.data); // Open the file in new tab - (window as any).open(pdfUrl, "_blank").focus(); + try { + (window as any).open(pdfUrl, "_blank").focus(); + } + catch { + showToast(translate('Unable to open as browser is blocking pop-ups.', {documentName: 'shipping label and packing slip'}), { icon: cogOutline }); + } } catch (err) { showToast(translate('Failed to print shipping label and packing slip')) @@ -272,8 +288,12 @@ const printPicklist = async (picklistId: string): Promise => { // Generate local file URL for the blob received const pdfUrl = window.URL.createObjectURL(resp.data); // Open the file in new tab - (window as any).open(pdfUrl, "_blank").focus(); - + try { + (window as any).open(pdfUrl, "_blank").focus(); + } + catch { + showToast(translate('Unable to open as browser is blocking pop-ups.', {documentName: 'picklist'}), { icon: cogOutline }); + } } catch (err) { showToast(translate('Failed to print picklist')) logger.error("Failed to print picklist", err) diff --git a/src/utils/index.ts b/src/utils/index.ts index 0ff9b1fd..c80cd4d8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -14,13 +14,14 @@ const hasError = (response: any) => { return typeof response.data != "object" || !!response.data._ERROR_MESSAGE_ || !!response.data._ERROR_MESSAGE_LIST_ || !!response.data.error; } -const showToast = async (message: string, canDismiss?: boolean, manualDismiss?: boolean, position?: string) => { +const showToast = async (message: string, options?: any) => { const config = { - message, - position: position ? position : 'bottom', - } as any + message, + ...options + } as any; - if (canDismiss) { + if(!options.position) config.position = 'bottom'; + if(options.canDismiss){ config.buttons = [ { text: translate('Dismiss'), @@ -28,14 +29,13 @@ const showToast = async (message: string, canDismiss?: boolean, manualDismiss?: }, ] } - - if (!manualDismiss) { - config.duration = 3000 + if (!options.manualDismiss) { + config.duration = 3000; } const toast = await toastController.create(config) // present toast if manual dismiss is not needed - return !manualDismiss ? toast.present() : toast + return !options.manualDismiss ? toast.present() : toast } const handleDateTimeInput = (dateTimeValue: any) => { diff --git a/src/views/InProgress.vue b/src/views/InProgress.vue index c33bb6be..6419f2b2 100644 --- a/src/views/InProgress.vue +++ b/src/views/InProgress.vue @@ -347,7 +347,7 @@ export default defineComponent({ if (data.length) { // additional parameters for dismiss button and manual dismiss ability - toast = await showToast(translate('Order packed successfully. Document generation in process'), true, true) + toast = await showToast(translate('Order packed successfully. Document generation in process'), { canDismiss: true, manualDismiss: true }) toast.present() if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) { @@ -435,7 +435,7 @@ export default defineComponent({ // the associated ids, currently passing the associated shipmentId if (data.length) { // additional parameters for dismiss button and manual dismiss ability - toast = await showToast(translate('Order packed successfully. Document generation in process'), true, true) + toast = await showToast(translate('Order packed successfully. Document generation in process'), { canDismiss: true, manualDismiss: true }) toast.present() if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) { await OrderService.printShippingLabelAndPackingSlip(shipmentIds)