diff --git a/src/utils/index.ts b/src/utils/index.ts index 9344edf9..9a7936d1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -14,28 +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 config = { - message, - position: position ? position : 'bottom', - } as any - - if (canDismiss) { - config.buttons = [ - { - text: 'Dismiss', - role: 'cancel', - }, - ] - } - - if (!manualDismiss) { - config.duration = 3000 - } - - const toast = await toastController.create(config) - // present toast if manual dismiss is not needed - return !manualDismiss ? toast.present() : toast +const showToast = async (message: string) => { + const toast = await toastController + .create({ + message, + duration: 3000, + position: 'bottom' + }) + return toast.present(); } const handleDateTimeInput = (dateTimeValue: any) => { diff --git a/src/views/InProgress.vue b/src/views/InProgress.vue index 173cca5e..474fbfe0 100644 --- a/src/views/InProgress.vue +++ b/src/views/InProgress.vue @@ -317,30 +317,20 @@ export default defineComponent({ 'orderId': order.orderId } + emitter.emit('presentLoader'); try { - emitter.emit('presentLoader'); const resp = await OrderService.packOrder(params); - if (hasError(resp)) { + if (resp.status === 200 && !hasError(resp)) { + showToast(translate('Order packed successfully')); + } else { throw resp.data } - emitter.emit('dismissLoader'); - - if (data.length) { - // additional parameters for dismiss button and manual dismiss ability - const toast: any = await showToast(translate('Order packed successfully. Document generation in process'), true, true) - toast.present() - - if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) { - await OrderService.printShippingLabelAndPackingSlip(order.shipmentIds) - } else if(data.includes('printPackingSlip')) { - await OrderService.printPackingSlip(order.shipmentIds) - } else if(data.includes('printShippingLabel')) { - await OrderService.printShippingLabel(order.shipmentIds) - } - - toast.dismiss() - } else { - showToast(translate('Order packed successfully')); + if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) { + await OrderService.printShippingLabelAndPackingSlip(order.shipmentIds) + } else if(data.includes('printPackingSlip')) { + await OrderService.printPackingSlip(order.shipmentIds) + } else if(data.includes('printShippingLabel')) { + await OrderService.printShippingLabel(order.shipmentIds) } // TODO: handle the case of fetching in progress orders after packing an order // when packing an order the API runs too fast and the solr index does not update resulting in having the current packed order in the inProgress section @@ -349,6 +339,8 @@ export default defineComponent({ showToast(translate('Failed to pack order')) logger.error('Failed to pack order', err) } + + emitter.emit('dismissLoader'); } }] });