@licklist/design 0.44.550-dev.0 → 0.44.550-dev.2
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.
- package/dist/events/event-statistic-modal/utils/index.d.ts +10 -4
- package/dist/events/event-statistic-modal/utils/index.d.ts.map +1 -1
- package/dist/events/event-statistic-modal/utils/index.js +1 -1
- package/package.json +1 -1
- package/src/events/event-statistic-modal/EventStatisticModal.stories.tsx +51 -0
- package/src/events/event-statistic-modal/utils/index.ts +81 -45
|
@@ -4,12 +4,18 @@ export declare const TRANSLATION_KEYS: {
|
|
|
4
4
|
total: string;
|
|
5
5
|
totalPerCategory: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type TableDataRecord = {
|
|
8
8
|
name: string;
|
|
9
9
|
key: string;
|
|
10
10
|
isHeader?: boolean;
|
|
11
11
|
isBold?: boolean;
|
|
12
|
-
quantity: string
|
|
13
|
-
total: string
|
|
14
|
-
|
|
12
|
+
quantity: string;
|
|
13
|
+
total: string;
|
|
14
|
+
metadata?: {
|
|
15
|
+
_productsSold: number;
|
|
16
|
+
_total: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const convertEventStatisticToTableData: (date: string, eventStatistic: EventStatistic) => TableDataRecord[];
|
|
20
|
+
export {};
|
|
15
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/events/event-statistic-modal/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kEAAkE,CAAC;AAIlG,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/events/event-statistic-modal/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kEAAkE,CAAC;AAIlG,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gCAAgC,SACrC,MAAM,kBACI,cAAc,sBA4G/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@licklist/core/dist/Config"),o=require("luxon"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),a=require("@licklist/core/dist/Config"),o=require("luxon"),e={shortQuantity:"shortQuantity",total:"total",totalPerCategory:"totalPerCategory"};exports.TRANSLATION_KEYS=e,exports.convertEventStatisticToTableData=function(r,c){var n,l,i=0,u=0;if(!c)return[];var d=o.DateTime.fromISO(r).toUTC().toFormat(a.DATE_FORMAT),y=null!==(l=null===(n=Object.keys(null==c?void 0:c.productCategorySummary))||void 0===n?void 0:n.filter((function(t){return o.DateTime.fromFormat(t,a.DATE_TIME_FULL_FORMAT).toFormat(a.DATE_FORMAT)===d})))&&void 0!==l?l:[],m=new Map;return y.map((function(t){return null==c?void 0:c.productCategorySummary[t]})).flat().sort((function(t,a){return t.categoryName===a.categoryName?0:t.categoryName>a.categoryName?1:-1})).forEach((function(t){var a,o=t.totalPerCategory,r=t.productsSummary,c=void 0===r?[]:r,n=t.categoryName,l=t.eventId,d=0;i+=o||0,m.has("".concat(n))||m.set("".concat(n),{name:n,key:"".concat(l,".").concat(n),isBold:!0,isHeader:!0,quantity:e.shortQuantity,total:e.total}),null==c||c.forEach((function(t){var a,o=t.productsSold,e=t.name,r=t.totalQuantity,c=t.total;d+=o;var i=null!==(a=m.get("".concat(n,".").concat(e)))&&void 0!==a?a:{metadata:{_productsSold:0,_total:0}};m.set("".concat(n,".").concat(e),{name:e,key:"".concat(l,".").concat(n,".").concat(e),quantity:r?"".concat(i.metadata._productsSold+o," / ").concat(r):String(i.metadata._productsSold+o),total:String(i.metadata._total+c),metadata:{_productsSold:i.metadata._productsSold+o,_total:i.metadata._total+c}})}));var y=null!==(a=m.get("".concat(n,".").concat(e.totalPerCategory)))&&void 0!==a?a:{quantity:0,total:0};m.set("".concat(n,".").concat(e.totalPerCategory),{name:e.totalPerCategory,key:"".concat(l,".").concat(n,".").concat(e.totalPerCategory),quantity:String(Number(y.quantity)+d),total:String(Number(y.total)+o),isBold:!0}),u+=d})),m.set("".concat(e.total,".").concat(i),{name:e.total,key:"".concat(e.total,".").concat(i),quantity:String(u),total:String(i),isBold:!0}),t.__spreadArray([],t.__read(m.values()),!1)};
|
package/package.json
CHANGED
|
@@ -91,6 +91,57 @@ Default.args = {
|
|
|
91
91
|
],
|
|
92
92
|
},
|
|
93
93
|
],
|
|
94
|
+
"2023-08-31 10:35:00": [
|
|
95
|
+
{
|
|
96
|
+
eventId: 1236,
|
|
97
|
+
categoryName: "ticket",
|
|
98
|
+
totalPerCategory: 1300,
|
|
99
|
+
productsSummary: [
|
|
100
|
+
{
|
|
101
|
+
id: 221,
|
|
102
|
+
name: "VIP",
|
|
103
|
+
productsSold: 13,
|
|
104
|
+
totalQuantity: 25,
|
|
105
|
+
total: 1300,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
eventId: 1236,
|
|
111
|
+
categoryName: "booking cat",
|
|
112
|
+
totalPerCategory: 275,
|
|
113
|
+
productsSummary: [
|
|
114
|
+
{
|
|
115
|
+
id: 222,
|
|
116
|
+
name: "Table booking",
|
|
117
|
+
productsSold: 11,
|
|
118
|
+
totalQuantity: null,
|
|
119
|
+
total: 275,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
eventId: 1236,
|
|
125
|
+
categoryName: "Menu",
|
|
126
|
+
totalPerCategory: 450,
|
|
127
|
+
productsSummary: [
|
|
128
|
+
{
|
|
129
|
+
id: 223,
|
|
130
|
+
name: "Wine 1 bottle",
|
|
131
|
+
productsSold: 9,
|
|
132
|
+
totalQuantity: null,
|
|
133
|
+
total: 360,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: 224,
|
|
137
|
+
name: "caesar salad",
|
|
138
|
+
productsSold: 9,
|
|
139
|
+
totalQuantity: null,
|
|
140
|
+
total: 90,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
94
145
|
},
|
|
95
146
|
},
|
|
96
147
|
};
|
|
@@ -8,6 +8,19 @@ export const TRANSLATION_KEYS = {
|
|
|
8
8
|
totalPerCategory: "totalPerCategory",
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
type TableDataRecord = {
|
|
12
|
+
name: string;
|
|
13
|
+
key: string;
|
|
14
|
+
isHeader?: boolean;
|
|
15
|
+
isBold?: boolean;
|
|
16
|
+
quantity: string;
|
|
17
|
+
total: string;
|
|
18
|
+
metadata?: {
|
|
19
|
+
_productsSold: number;
|
|
20
|
+
_total: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
11
24
|
export const convertEventStatisticToTableData = (
|
|
12
25
|
date: string,
|
|
13
26
|
eventStatistic: EventStatistic
|
|
@@ -19,15 +32,6 @@ export const convertEventStatisticToTableData = (
|
|
|
19
32
|
return [];
|
|
20
33
|
}
|
|
21
34
|
|
|
22
|
-
const tableDataArray: {
|
|
23
|
-
name: string;
|
|
24
|
-
key: string;
|
|
25
|
-
isHeader?: boolean;
|
|
26
|
-
isBold?: boolean;
|
|
27
|
-
quantity: string | number;
|
|
28
|
-
total: string | number;
|
|
29
|
-
}[] = [];
|
|
30
|
-
|
|
31
35
|
const summaryFormattedDate = DateTime.fromISO(date)
|
|
32
36
|
.toUTC()
|
|
33
37
|
.toFormat(DATE_FORMAT);
|
|
@@ -40,16 +44,26 @@ export const convertEventStatisticToTableData = (
|
|
|
40
44
|
) === summaryFormattedDate
|
|
41
45
|
) ?? [];
|
|
42
46
|
|
|
47
|
+
const summaryMap = new Map<string, TableDataRecord>();
|
|
48
|
+
|
|
43
49
|
summaryDays
|
|
44
50
|
.map((day) => eventStatistic?.productCategorySummary[day])
|
|
45
|
-
.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
.flat()
|
|
52
|
+
.sort((prev, next) =>
|
|
53
|
+
prev.categoryName === next.categoryName
|
|
54
|
+
? 0
|
|
55
|
+
: prev.categoryName > next.categoryName
|
|
56
|
+
? 1
|
|
57
|
+
: -1
|
|
58
|
+
)
|
|
59
|
+
.forEach(
|
|
60
|
+
({ totalPerCategory, productsSummary = [], categoryName, eventId }) => {
|
|
61
|
+
let quantity = 0;
|
|
49
62
|
|
|
50
|
-
|
|
63
|
+
totalAmount += totalPerCategory || 0;
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
if (!summaryMap.has(`${categoryName}`)) {
|
|
66
|
+
summaryMap.set(`${categoryName}`, {
|
|
53
67
|
name: categoryName,
|
|
54
68
|
key: `${eventId}.${categoryName}`,
|
|
55
69
|
isBold: true,
|
|
@@ -57,42 +71,64 @@ export const convertEventStatisticToTableData = (
|
|
|
57
71
|
quantity: TRANSLATION_KEYS.shortQuantity,
|
|
58
72
|
total: TRANSLATION_KEYS.total,
|
|
59
73
|
});
|
|
74
|
+
}
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
tableDataArray.push({
|
|
66
|
-
name,
|
|
67
|
-
key: `${eventId}.${categoryName}.${name}`,
|
|
68
|
-
quantity: totalQuantity
|
|
69
|
-
? `${productsSold} / ${totalQuantity}`
|
|
70
|
-
: String(productsSold),
|
|
71
|
-
total: String(total),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
tableDataArray.push({
|
|
77
|
-
name: TRANSLATION_KEYS.totalPerCategory,
|
|
78
|
-
key: `${eventId}.${categoryName}.${TRANSLATION_KEYS.totalPerCategory}`,
|
|
79
|
-
quantity,
|
|
80
|
-
total: totalPerCategory,
|
|
81
|
-
isBold: true,
|
|
82
|
-
});
|
|
76
|
+
productsSummary?.forEach(
|
|
77
|
+
({ productsSold, name, totalQuantity, total }) => {
|
|
78
|
+
quantity += productsSold;
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
const existingProduct = summaryMap.get(
|
|
81
|
+
`${categoryName}.${name}`
|
|
82
|
+
) ?? {
|
|
83
|
+
metadata: {
|
|
84
|
+
_productsSold: 0,
|
|
85
|
+
_total: 0,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
summaryMap.set(`${categoryName}.${name}`, {
|
|
90
|
+
name,
|
|
91
|
+
key: `${eventId}.${categoryName}.${name}`,
|
|
92
|
+
quantity: totalQuantity
|
|
93
|
+
? `${
|
|
94
|
+
existingProduct.metadata._productsSold + productsSold
|
|
95
|
+
} / ${totalQuantity}`
|
|
96
|
+
: String(existingProduct.metadata._productsSold + productsSold),
|
|
97
|
+
total: String(existingProduct.metadata._total + total),
|
|
98
|
+
metadata: {
|
|
99
|
+
_productsSold:
|
|
100
|
+
existingProduct.metadata._productsSold + productsSold,
|
|
101
|
+
_total: existingProduct.metadata._total + total,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const prevTotalPerCategory = summaryMap.get(
|
|
108
|
+
`${categoryName}.${TRANSLATION_KEYS.totalPerCategory}`
|
|
109
|
+
) ?? {
|
|
110
|
+
quantity: 0,
|
|
111
|
+
total: 0,
|
|
112
|
+
};
|
|
113
|
+
summaryMap.set(`${categoryName}.${TRANSLATION_KEYS.totalPerCategory}`, {
|
|
114
|
+
name: TRANSLATION_KEYS.totalPerCategory,
|
|
115
|
+
key: `${eventId}.${categoryName}.${TRANSLATION_KEYS.totalPerCategory}`,
|
|
116
|
+
quantity: String(Number(prevTotalPerCategory.quantity) + quantity),
|
|
117
|
+
total: String(Number(prevTotalPerCategory.total) + totalPerCategory),
|
|
118
|
+
isBold: true,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
totalQuantity += quantity;
|
|
122
|
+
}
|
|
123
|
+
);
|
|
88
124
|
|
|
89
|
-
|
|
125
|
+
summaryMap.set(`${TRANSLATION_KEYS.total}.${totalAmount}`, {
|
|
90
126
|
name: TRANSLATION_KEYS.total,
|
|
91
127
|
key: `${TRANSLATION_KEYS.total}.${totalAmount}`,
|
|
92
|
-
quantity: totalQuantity,
|
|
93
|
-
total: totalAmount,
|
|
128
|
+
quantity: String(totalQuantity),
|
|
129
|
+
total: String(totalAmount),
|
|
94
130
|
isBold: true,
|
|
95
131
|
});
|
|
96
132
|
|
|
97
|
-
return
|
|
133
|
+
return [...summaryMap.values()];
|
|
98
134
|
};
|