Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: toast for background process on pack action on in-progress page (#185) #214

Merged
merged 10 commits into from
Aug 1, 2023
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"Custom Label": "Custom Label",
"Customer letter": "Customer letter",
"Damaged": "Damaged",
"Define custom label for": "Define custom label for {label}",
"Define custom label for": "Define custom label for {field}",
"Dismiss": "Dismiss",
"Delete": "Delete",
"Delete mapping": "Delete mapping",
"Documents to print when packing orders": "Documents to print when packing orders",
Expand Down Expand Up @@ -109,6 +110,7 @@
"Ordered": "Ordered",
"Order ID": "Order ID",
"Order packed successfully": "Order packed successfully",
"Order packed successfully. Document generation in process": "Order packed successfully. Document generation in process",
"Order shipped successfully": "Order shipped successfully",
"Order Shipment ID": "Order Shipment ID",
"Order unpacked successfully": "Order unpacked successfully",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"Custom Label": "Etiqueta Personalizada",
"Customer letter": "Carta al Cliente",
"Damaged": "Dañado",
"Define custom label for": "Definir etiqueta personalizada para {label}",
"Define custom label for": "Definir etiqueta personalizada para {field}",
"Dismiss": "Dismiss",
"Delete": "Delete",
"Delete mapping": "Delete mapping",
"Documents to print when packing orders": "Documentos para imprimir al empacar pedidos",
Expand Down Expand Up @@ -109,6 +110,7 @@
"Ordered": "Ordenado",
"Order ID": "ID del Pedido",
"Order packed successfully": "Pedido empacado exitosamente",
"Order packed successfully. Document generation in process": "Order packed successfully. Document generation in process",
"Order shipped successfully": "Pedido enviado exitosamente",
"Order Shipment ID": "ID de Envío del Pedido",
"Order unpacked successfully": "Pedido desempacado exitosamente",
Expand Down
30 changes: 22 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ const hasError = (response: any) => {
return !!response.data._ERROR_MESSAGE_ || !!response.data._ERROR_MESSAGE_LIST_;
}

const showToast = async (message: string) => {
const toast = await toastController
.create({
message,
duration: 3000,
position: 'bottom'
})
return toast.present();
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: translate('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 handleDateTimeInput = (dateTimeValue: any) => {
Expand Down
64 changes: 42 additions & 22 deletions src/views/InProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,30 +318,40 @@ export default defineComponent({
'orderId': order.orderId
}

emitter.emit('presentLoader');
try {
emitter.emit('presentLoader');
const resp = await OrderService.packOrder(params);
if (resp.status === 200 && !hasError(resp)) {
showToast(translate('Order packed successfully'));
} else {
if (hasError(resp)) {
throw resp.data
}
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)
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()
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
} else {
showToast(translate('Order packed successfully'));
}
// 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
await Promise.all([this.fetchPickersInformation(), this.updateOrderQuery()]);
} catch (err) {
// in case of error, if loader is not dismissed above
emitter.emit('dismissLoader');
showToast(translate('Failed to pack order'))
logger.error('Failed to pack order', err)
}

emitter.emit('dismissLoader');
}
}]
});
Expand Down Expand Up @@ -395,28 +405,38 @@ export default defineComponent({
const resp = await OrderService.packOrders({
shipmentIds
});
if (resp.status === 200 && !hasError(resp)) {
showToast(translate('Orders packed successfully'));
} else {
if (hasError(resp)) {
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
throw resp.data
}
emitter.emit('dismissLoader');

// TODO: need to check that do we need to pass all the shipmentIds for an order or just need to pass
// the associated ids, currently passing the associated shipmentId
if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) {
await OrderService.printShippingLabelAndPackingSlip(shipmentIds)
} else if(data.includes('printPackingSlip')) {
await OrderService.printPackingSlip(shipmentIds)
} else if(data.includes('printShippingLabel')) {
await OrderService.printShippingLabel(shipmentIds)
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()
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
if (data.includes('printPackingSlip') && data.includes('printShippingLabel')) {
await OrderService.printShippingLabelAndPackingSlip(shipmentIds)
} else if (data.includes('printPackingSlip')) {
await OrderService.printPackingSlip(shipmentIds)
} else if (data.includes('printShippingLabel')) {
await OrderService.printShippingLabel(shipmentIds)
}

toast.dismiss()
} else {
showToast(translate('Order packed successfully'));
}
// TODO: handle the case of fetching in progress orders after packing multiple orders
// when packing multiple orders the API runs too fast and the solr index does not update resulting in having the packed orders in the inProgress section
await Promise.all([this.fetchPickersInformation(), this.updateOrderQuery()])
} catch (err) {
// in case of error, if loader is not dismissed above
emitter.emit('dismissLoader');
showToast(translate('Failed to pack orders'))
logger.error('Failed to pack orders', err)
}
emitter.emit('dismissLoader');
}
}]
});
Expand Down
Loading