@ancon/wildcat-utils 1.20.2 → 1.20.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { CheckoutStatus, OrderFormat, TicketItemStatus, TicketStatus } from '@ancon/wildcat-types';
|
|
2
2
|
declare type CheckoutOrderSummaryItem = {
|
|
3
|
-
id: string;
|
|
4
3
|
ticketItem: {
|
|
5
4
|
status: TicketItemStatus;
|
|
6
|
-
ticketItemId: string;
|
|
7
5
|
};
|
|
8
6
|
};
|
|
9
7
|
declare type CheckoutSummary = {
|
|
@@ -45,17 +43,21 @@ declare enum TranslationKey {
|
|
|
45
43
|
}
|
|
46
44
|
declare type TranslationsWithMeta = {
|
|
47
45
|
[TranslationKey.MultipleItemsAreReadyToCollect]: ({ meta, }: {
|
|
46
|
+
key: TranslationKey;
|
|
48
47
|
meta: {
|
|
49
48
|
count: number;
|
|
50
49
|
};
|
|
51
50
|
}) => Translation;
|
|
52
|
-
[TranslationKey.EnjoyMealWhileOtherItemsBeingPrepared]: ({ meta, }: {
|
|
51
|
+
[TranslationKey.EnjoyMealWhileOtherItemsBeingPrepared]: ({ key, meta, }: {
|
|
52
|
+
key: TranslationKey;
|
|
53
53
|
meta: {
|
|
54
54
|
count: number;
|
|
55
55
|
};
|
|
56
56
|
}) => Translation;
|
|
57
57
|
};
|
|
58
|
-
declare type TranslatedTexts = Record<Exclude<TranslationKey, keyof TranslationsWithMeta>, (
|
|
58
|
+
declare type TranslatedTexts = Record<Exclude<TranslationKey, keyof TranslationsWithMeta>, ({ key }: {
|
|
59
|
+
key: TranslationKey;
|
|
60
|
+
}) => Translation> & TranslationsWithMeta;
|
|
59
61
|
declare function getOrderStatusTexts(checkout: CheckoutSummary, options: Options, texts?: TranslatedTexts): [Translation, TranslationKey];
|
|
60
62
|
export { TranslationKey };
|
|
61
63
|
export default getOrderStatusTexts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),O=require("./getCheckoutItemsMappedByTicketItemStatus.js");var
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("@ancon/wildcat-types"),O=require("./getCheckoutItemsMappedByTicketItemStatus.js");var u=(e=>(e.YourOrderIsBeingProcessed="yourOrderIsBeingProcessed",e.YourOrderWasCancelled="yourOrderWasCancelled",e.ProcessingPayment="processingPayment",e.YourOrderIsBeingPrepared="yourOrderIsBeingPrepared",e.YourOrderIsReadyToCollect="yourOrderIsReadyToCollect",e.YourOrderHasBeenCompleted="yourOrderHasBeenCompleted",e.YourOrderWillArriveAtYourTable="yourOrderWillArriveAtYourTable",e.ModifiedDeliveryStartTime="modifiedDeliveryStartTime",e.ModifiedPickUpTime="modifiedPickUpTime",e.YourOrderHasBeenAcceptedEstimatedTime="yourOrderHasBeenAcceptedEstimatedTime",e.YourOrderHasBeenAcceptedPickupTime="yourOrderHasBeenAcceptedPickupTime",e.YourOrderIsBeingDelivered="yourOrderIsBeingDelivered",e.YourOrderIsReady="yourOrderIsReady",e.DeliveryWasCompleted="deliveryWasCompleted",e.OneItemIsReadyToCollect="oneItemIsReadyToCollect",e.MultipleItemsAreReadyToCollect="multipleItemsAreReadyToCollect",e.EnjoyMealWhileOtherItemsBeingPrepared="enjoyMealWhileOtherItemsBeingPrepared",e))(u||{});function C(e){switch(e){case r.CheckoutStatus.Created:case r.CheckoutStatus.Ready:case r.CheckoutStatus.Processing:case r.CheckoutStatus.Authorized:return"yourOrderIsBeingProcessed";case r.CheckoutStatus.Canceled:return"yourOrderWasCancelled";case r.CheckoutStatus.Received:return"processingPayment";case r.CheckoutStatus.ReadyToCollect:return"yourOrderIsReadyToCollect";default:return null}}function I(e){switch(e){case r.TicketStatus.Pending:case r.TicketStatus.PendingAccept:return"processingPayment";case r.TicketStatus.Preparing:return"yourOrderIsBeingPrepared";case r.TicketStatus.Ready:return"yourOrderIsReadyToCollect";case r.TicketStatus.Closed:return"yourOrderHasBeenCompleted";case r.TicketStatus.Canceled:return"yourOrderWasCancelled";default:throw new Error(`Unhandled ticket status "${e}" in getTranslationKeyByTicketStatus()`)}}function f({useMarkAsPickedUp:e,checkoutStatus:o,ticketStatus:d}){const i=o!=null,s=d!=null;if(i){const t=o===r.CheckoutStatus.Captured,a=o===r.CheckoutStatus.InProgress;return e&&(t||a)}if(s){const t=d===r.TicketStatus.Preparing,a=d===r.TicketStatus.Ready;return t||a}return!1}function h({orderFormat:e},{checkoutStatus:o,ticketStatus:d,useMarkAsPickedUp:i,pickupTimeUpdated:s},t){if(f({useMarkAsPickedUp:i,checkoutStatus:o,ticketStatus:d})){if(t.ready>0)return t.ready<2?["oneItemIsReadyToCollect"]:["multipleItemsAreReadyToCollect",{count:t.ready}];if(t.done>0&&t.done<t.all)return["enjoyMealWhileOtherItemsBeingPrepared",{count:Math.max(0,t.all-t.done-t.ready)}]}if(d!=null)return[I(d)];const a=C(o);if(a)return[a];const c=o===r.CheckoutStatus.Captured,y=o===r.CheckoutStatus.InProgress,m=o===r.CheckoutStatus.Done,n=e===r.OrderFormat.TableOrder,l=e===r.OrderFormat.Delivery;if(c)return n?["yourOrderWillArriveAtYourTable"]:s&&l?["modifiedDeliveryStartTime"]:s?["modifiedPickUpTime"]:i?["yourOrderHasBeenAcceptedPickupTime"]:["yourOrderHasBeenAcceptedEstimatedTime"];if(y)return s&&l?["modifiedDeliveryStartTime"]:l?["yourOrderIsBeingDelivered"]:s?["modifiedPickUpTime"]:i?["yourOrderIsBeingPrepared"]:["yourOrderIsBeingPrepared"];if(m){const p=e===r.OrderFormat.EatIn,g=e===r.OrderFormat.TakeAway;if(p||g)return i?["yourOrderHasBeenCompleted"]:["yourOrderIsReady"];if(l)return["deliveryWasCompleted"];if(n)return i?["yourOrderIsReadyToCollect"]:["yourOrderWillArriveAtYourTable"]}throw new Error("Could not resolve translation key in getTranslationKey()")}const T={yourOrderIsBeingProcessed:()=>({title:"Your order is being processed"}),yourOrderWasCancelled:()=>({title:"Your order was canceled",message:"Sorry. Your order could not go through."}),processingPayment:()=>({title:"Processing payment",message:"Please wait while your payment is being processed"}),yourOrderIsBeingPrepared:()=>({title:"Your order is now being prepared!",message:"We will let you know when it is ready for pickup."}),yourOrderIsReadyToCollect:()=>({title:"Your order is ready to be collected!",message:"Please go ahead and show this screen at the collection point"}),yourOrderHasBeenCompleted:()=>({title:"Enjoy your meal!",message:"Your order has been completed!"}),yourOrderWillArriveAtYourTable:()=>({title:"Your order has been accepted!",message:"It will arrive at your table shortly"}),modifiedDeliveryStartTime:()=>({title:"Your delivery time was modified",message:"Delivery will start at approximately 00:00."}),modifiedPickUpTime:()=>({title:"Your pickup time was modified",message:"Pickup time: 00:00"}),yourOrderHasBeenAcceptedEstimatedTime:()=>({title:"Your order has been accepted",message:"Estimated time: 00:00"}),yourOrderHasBeenAcceptedPickupTime:()=>({title:"Your order has been accepted",message:"Pickup time: 00:00"}),yourOrderIsBeingDelivered:()=>({title:"Your order is being delivered",message:"It will arrive at your door shortly. Enjoy your meal!"}),yourOrderIsReady:()=>({title:"Your order is ready",message:"Enjoy your meal!"}),deliveryWasCompleted:()=>({title:"Your order was completed",message:"Enjoy your meal!"}),oneItemIsReadyToCollect:()=>({title:"One item is ready to pick up!"}),multipleItemsAreReadyToCollect:()=>({title:"Multiple items are ready to pick up!"}),enjoyMealWhileOtherItemsBeingPrepared:({meta:e})=>({title:"Enjoy your meal while the rest of the items are being prepared!",message:`${e.count} more items are being prepared`})};function P(e,o,d=T){const i=O(e.items),[s,t]=h(e,o,{all:i.all.length,ready:i.ready.length,done:i.done.length}),a=d[s]({key:s,meta:t});if(!a)throw new Error("Could not resolve translation in getOrderStatusTexts()");return[a,s]}exports.TranslationKey=u;exports.default=P;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { CheckoutStatus as
|
|
2
|
-
import
|
|
3
|
-
var
|
|
1
|
+
import { CheckoutStatus as t, OrderFormat as u, TicketStatus as l } from "@ancon/wildcat-types";
|
|
2
|
+
import f from "./getCheckoutItemsMappedByTicketItemStatus.mjs";
|
|
3
|
+
var I = /* @__PURE__ */ ((e) => (e.YourOrderIsBeingProcessed = "yourOrderIsBeingProcessed", e.YourOrderWasCancelled = "yourOrderWasCancelled", e.ProcessingPayment = "processingPayment", e.YourOrderIsBeingPrepared = "yourOrderIsBeingPrepared", e.YourOrderIsReadyToCollect = "yourOrderIsReadyToCollect", e.YourOrderHasBeenCompleted = "yourOrderHasBeenCompleted", e.YourOrderWillArriveAtYourTable = "yourOrderWillArriveAtYourTable", e.ModifiedDeliveryStartTime = "modifiedDeliveryStartTime", e.ModifiedPickUpTime = "modifiedPickUpTime", e.YourOrderHasBeenAcceptedEstimatedTime = "yourOrderHasBeenAcceptedEstimatedTime", e.YourOrderHasBeenAcceptedPickupTime = "yourOrderHasBeenAcceptedPickupTime", e.YourOrderIsBeingDelivered = "yourOrderIsBeingDelivered", e.YourOrderIsReady = "yourOrderIsReady", e.DeliveryWasCompleted = "deliveryWasCompleted", e.OneItemIsReadyToCollect = "oneItemIsReadyToCollect", e.MultipleItemsAreReadyToCollect = "multipleItemsAreReadyToCollect", e.EnjoyMealWhileOtherItemsBeingPrepared = "enjoyMealWhileOtherItemsBeingPrepared", e))(I || {});
|
|
4
4
|
function C(e) {
|
|
5
5
|
switch (e) {
|
|
6
|
-
case
|
|
7
|
-
case
|
|
8
|
-
case
|
|
9
|
-
case
|
|
6
|
+
case t.Created:
|
|
7
|
+
case t.Ready:
|
|
8
|
+
case t.Processing:
|
|
9
|
+
case t.Authorized:
|
|
10
10
|
return "yourOrderIsBeingProcessed";
|
|
11
|
-
case
|
|
11
|
+
case t.Canceled:
|
|
12
12
|
return "yourOrderWasCancelled";
|
|
13
|
-
case
|
|
13
|
+
case t.Received:
|
|
14
14
|
return "processingPayment";
|
|
15
|
-
case
|
|
15
|
+
case t.ReadyToCollect:
|
|
16
16
|
return "yourOrderIsReadyToCollect";
|
|
17
17
|
default:
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function P(e) {
|
|
22
22
|
switch (e) {
|
|
23
|
-
case
|
|
24
|
-
case
|
|
23
|
+
case l.Pending:
|
|
24
|
+
case l.PendingAccept:
|
|
25
25
|
return "processingPayment";
|
|
26
|
-
case
|
|
26
|
+
case l.Preparing:
|
|
27
27
|
return "yourOrderIsBeingPrepared";
|
|
28
|
-
case
|
|
28
|
+
case l.Ready:
|
|
29
29
|
return "yourOrderIsReadyToCollect";
|
|
30
|
-
case
|
|
30
|
+
case l.Closed:
|
|
31
31
|
return "yourOrderHasBeenCompleted";
|
|
32
|
-
case
|
|
32
|
+
case l.Canceled:
|
|
33
33
|
return "yourOrderWasCancelled";
|
|
34
34
|
default:
|
|
35
35
|
throw new Error(
|
|
@@ -37,46 +37,68 @@ function T(e) {
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
function B({
|
|
41
|
+
useMarkAsPickedUp: e,
|
|
42
|
+
checkoutStatus: o,
|
|
43
|
+
ticketStatus: s
|
|
44
|
+
}) {
|
|
45
|
+
const i = o != null, d = s != null;
|
|
46
|
+
if (i) {
|
|
47
|
+
const r = o === t.Captured, a = o === t.InProgress;
|
|
48
|
+
return e && (r || a);
|
|
49
|
+
}
|
|
50
|
+
if (d) {
|
|
51
|
+
const r = s === l.Preparing, a = s === l.Ready;
|
|
52
|
+
return r || a;
|
|
53
|
+
}
|
|
54
|
+
return !1;
|
|
55
|
+
}
|
|
56
|
+
function T({ orderFormat: e }, {
|
|
57
|
+
checkoutStatus: o,
|
|
58
|
+
ticketStatus: s,
|
|
59
|
+
useMarkAsPickedUp: i,
|
|
60
|
+
pickupTimeUpdated: d
|
|
45
61
|
}, r) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
62
|
+
if (B({
|
|
63
|
+
useMarkAsPickedUp: i,
|
|
64
|
+
checkoutStatus: o,
|
|
65
|
+
ticketStatus: s
|
|
66
|
+
})) {
|
|
67
|
+
if (r.ready > 0)
|
|
68
|
+
return r.ready < 2 ? ["oneItemIsReadyToCollect"] : [
|
|
69
|
+
"multipleItemsAreReadyToCollect",
|
|
70
|
+
{ count: r.ready }
|
|
71
|
+
];
|
|
72
|
+
if (r.done > 0 && r.done < r.all)
|
|
73
|
+
return [
|
|
74
|
+
"enjoyMealWhileOtherItemsBeingPrepared",
|
|
75
|
+
{ count: Math.max(0, r.all - r.done - r.ready) }
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
if (s != null)
|
|
79
|
+
return [P(s)];
|
|
80
|
+
const a = C(o);
|
|
81
|
+
if (a)
|
|
82
|
+
return [a];
|
|
83
|
+
const c = o === t.Captured, m = o === t.InProgress, p = o === t.Done, y = e === u.TableOrder, n = e === u.Delivery;
|
|
84
|
+
if (c)
|
|
85
|
+
return y ? ["yourOrderWillArriveAtYourTable"] : d && n ? ["modifiedDeliveryStartTime"] : d ? ["modifiedPickUpTime"] : i ? ["yourOrderHasBeenAcceptedPickupTime"] : ["yourOrderHasBeenAcceptedEstimatedTime"];
|
|
64
86
|
if (m)
|
|
65
|
-
return
|
|
87
|
+
return d && n ? ["modifiedDeliveryStartTime"] : n ? ["yourOrderIsBeingDelivered"] : d ? ["modifiedPickUpTime"] : i ? ["yourOrderIsBeingPrepared"] : ["yourOrderIsBeingPrepared"];
|
|
66
88
|
if (p) {
|
|
67
89
|
const g = e === u.EatIn, O = e === u.TakeAway;
|
|
68
90
|
if (g || O)
|
|
69
|
-
return
|
|
91
|
+
return i ? ["yourOrderHasBeenCompleted"] : ["yourOrderIsReady"];
|
|
70
92
|
if (n)
|
|
71
93
|
return ["deliveryWasCompleted"];
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
94
|
+
if (y)
|
|
95
|
+
return i ? ["yourOrderIsReadyToCollect"] : ["yourOrderWillArriveAtYourTable"];
|
|
74
96
|
}
|
|
75
97
|
throw new Error("Could not resolve translation key in getTranslationKey()");
|
|
76
98
|
}
|
|
77
|
-
const
|
|
99
|
+
const h = {
|
|
78
100
|
yourOrderIsBeingProcessed: () => ({
|
|
79
|
-
title: "Your order is being processed
|
|
101
|
+
title: "Your order is being processed"
|
|
80
102
|
}),
|
|
81
103
|
yourOrderWasCancelled: () => ({
|
|
82
104
|
title: "Your order was canceled",
|
|
@@ -141,17 +163,17 @@ const B = {
|
|
|
141
163
|
message: `${e.count} more items are being prepared`
|
|
142
164
|
})
|
|
143
165
|
};
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
all:
|
|
147
|
-
ready:
|
|
148
|
-
done:
|
|
149
|
-
}),
|
|
150
|
-
if (!
|
|
166
|
+
function w(e, o, s = h) {
|
|
167
|
+
const i = f(e.items), [d, r] = T(e, o, {
|
|
168
|
+
all: i.all.length,
|
|
169
|
+
ready: i.ready.length,
|
|
170
|
+
done: i.done.length
|
|
171
|
+
}), a = s[d]({ key: d, meta: r });
|
|
172
|
+
if (!a)
|
|
151
173
|
throw new Error("Could not resolve translation in getOrderStatusTexts()");
|
|
152
|
-
return [
|
|
174
|
+
return [a, d];
|
|
153
175
|
}
|
|
154
176
|
export {
|
|
155
|
-
|
|
156
|
-
|
|
177
|
+
I as TranslationKey,
|
|
178
|
+
w as default
|
|
157
179
|
};
|