@licklist/design 0.44.486-dev.70 → 0.44.486-dev.71
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-card/EventCard.js +1 -1
- package/dist/events/event-card/utils.d.ts +28 -1
- package/dist/events/event-card/utils.d.ts.map +1 -1
- package/dist/events/event-card/utils.js +1 -1
- package/package.json +1 -1
- package/src/events/event-card/EventCard.tsx +1 -1
- package/src/events/event-card/utils.ts +83 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),a=require("react"),n=e(a),r=require("@licklist/core/dist/Config"),l=require("react-i18next"),c=require("react-bootstrap"),i=require("../../static/Icon.js"),s=e(require("clsx")),m=require("react-intl"),o=require("../../tiptap-editor/TipTapEditor.js"),u=require("./utils.js"),d=require("../../assets/dashboard/chartBar.svg.js");exports.EventCard=function(e){var E=e.name,v=e.description,p=e.date,y=e.imageUrl,f=e.sales,b=e.onPreview,N=e.onEdit,C=e.onCopy,k=e.onRemove,g=e.hasPermission,x=void 0===g||g,q=e.onStatistic,w=e.eventStatistic,h=e.titleId,T=e.descriptionId,j=l.useTranslation("Design").t,I=m.useIntl(),P=I.formatNumber,_=I.formatDate,B=u.getStatisticInfo(w),S=B.totalViews,D=t.__rest(B,["totalViews"]),M=a.useMemo((function(){return u.formatContentWithoutTags(v,u.EVENT_DESCRIPTION_SIZE)}),[v]);return n.createElement(c.Card,{className:"d-flex flex-column event-card h-100"},n.createElement("div",{className:s("event-card-image-container",!y&&"no-image")},y&&n.createElement(c.Card.Img,{variant:"top",src:y}),n.createElement(c.Badge,{className:"event-card-date",as:"time",dateTime:p,variant:"primary"},_(new Date(p),{weekday:"short",day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"}))),n.createElement(c.Card.Body,null,n.createElement(c.Card.Title,{id:h},E),n.createElement("div",{className:"flex-grow-1"},n.createElement(o.TipTapEditor,{viewMode:!0,disabled:!0,className:s("event-description",!y&&"no-image"),content:M,id:T}),n.createElement("div",{className:"mt-2 ml-2"},Object.keys(D).map((function(e){return n.createElement("div",{className:"event-card-sale",key:e},n.createElement("span",{className:"event-card-sale-name"},j(e),":"," ","totalAmount"===e?P(D[e],{style:"currency",currency:r.Currency.GBP}):D[e]))}))),f&&f.map((function(e){return n.createElement("div",{className:"event-card-sale",key:e.id},n.createElement("div",{className:"event-card-sale-text"},n.createElement("span",{className:"event-card-sale-name"},e.name)," ",n.createElement("span",{className:"event-card-sale-quantity"},[e.current,e.max].map((function(e){return P(e)})).join(" / "))),n.createElement(c.ProgressBar,{now:e.current,max:e.max}))})))),n.createElement(c.Card.Footer,null,n.createElement("div",{className:"d-flex w-100 justify-content-between"},n.createElement("div",{className:"d-flex"},n.createElement("button",{type:"button",className:"event-card-link-button ml-3 mr-4",onClick:q},n.createElement(d.ReactComponent,null)),n.createElement("div",{className:"event-card-views"},n.createElement(i.default,{type:"eye"}),n.createElement("span",null,P(S)))),n.createElement("div",null,n.createElement("button",{type:"button",className:"event-card-link-button",onClick:b},n.createElement(i.default,{type:"external-link-alt"})),x&&n.createElement(n.Fragment,null,n.createElement("button",{type:"button",className:"event-card-link-button",onClick:N},n.createElement(i.default,{type:"edit"})),n.createElement("button",{type:"button",className:"event-card-link-button",onClick:C},n.createElement(i.default,{type:"copy"})),n.createElement("button",{type:"button",className:"event-card-link-button",onClick:k},n.createElement(i.default,{type:"trash-alt"})))))))};
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),a=require("react"),n=e(a),r=require("@licklist/core/dist/Config"),l=require("react-i18next"),c=require("react-bootstrap"),i=require("../../static/Icon.js"),s=e(require("clsx")),m=require("react-intl"),o=require("../../tiptap-editor/TipTapEditor.js"),u=require("./utils.js"),d=require("../../assets/dashboard/chartBar.svg.js");exports.EventCard=function(e){var E=e.name,v=e.description,p=e.date,y=e.imageUrl,f=e.sales,b=e.onPreview,N=e.onEdit,C=e.onCopy,k=e.onRemove,g=e.hasPermission,x=void 0===g||g,q=e.onStatistic,w=e.eventStatistic,h=e.titleId,T=e.descriptionId,j=l.useTranslation("Design").t,I=m.useIntl(),P=I.formatNumber,_=I.formatDate,B=u.getStatisticInfo(w,p),S=B.totalViews,D=t.__rest(B,["totalViews"]),M=a.useMemo((function(){return u.formatContentWithoutTags(v,u.EVENT_DESCRIPTION_SIZE)}),[v]);return n.createElement(c.Card,{className:"d-flex flex-column event-card h-100"},n.createElement("div",{className:s("event-card-image-container",!y&&"no-image")},y&&n.createElement(c.Card.Img,{variant:"top",src:y}),n.createElement(c.Badge,{className:"event-card-date",as:"time",dateTime:p,variant:"primary"},_(new Date(p),{weekday:"short",day:"numeric",month:"short",year:"numeric",hour:"numeric",minute:"numeric"}))),n.createElement(c.Card.Body,null,n.createElement(c.Card.Title,{id:h},E),n.createElement("div",{className:"flex-grow-1"},n.createElement(o.TipTapEditor,{viewMode:!0,disabled:!0,className:s("event-description",!y&&"no-image"),content:M,id:T}),n.createElement("div",{className:"mt-2 ml-2"},Object.keys(D).map((function(e){return n.createElement("div",{className:"event-card-sale",key:e},n.createElement("span",{className:"event-card-sale-name"},j(e),":"," ","totalAmount"===e?P(D[e],{style:"currency",currency:r.Currency.GBP}):D[e]))}))),f&&f.map((function(e){return n.createElement("div",{className:"event-card-sale",key:e.id},n.createElement("div",{className:"event-card-sale-text"},n.createElement("span",{className:"event-card-sale-name"},e.name)," ",n.createElement("span",{className:"event-card-sale-quantity"},[e.current,e.max].map((function(e){return P(e)})).join(" / "))),n.createElement(c.ProgressBar,{now:e.current,max:e.max}))})))),n.createElement(c.Card.Footer,null,n.createElement("div",{className:"d-flex w-100 justify-content-between"},n.createElement("div",{className:"d-flex"},n.createElement("button",{type:"button",className:"event-card-link-button ml-3 mr-4",onClick:q},n.createElement(d.ReactComponent,null)),n.createElement("div",{className:"event-card-views"},n.createElement(i.default,{type:"eye"}),n.createElement("span",null,P(S)))),n.createElement("div",null,n.createElement("button",{type:"button",className:"event-card-link-button",onClick:b},n.createElement(i.default,{type:"external-link-alt"})),x&&n.createElement(n.Fragment,null,n.createElement("button",{type:"button",className:"event-card-link-button",onClick:N},n.createElement(i.default,{type:"edit"})),n.createElement("button",{type:"button",className:"event-card-link-button",onClick:C},n.createElement(i.default,{type:"copy"})),n.createElement("button",{type:"button",className:"event-card-link-button",onClick:k},n.createElement(i.default,{type:"trash-alt"})))))))};
|
|
@@ -2,7 +2,34 @@ import { EventStatistic } from "@licklist/core/dist/DataMapper/Provider/EventSta
|
|
|
2
2
|
export declare function formatContent(content: any, maxSymbols: any): any;
|
|
3
3
|
export declare const formatContentWithoutTags: (content: any, maxLength?: number) => any;
|
|
4
4
|
export declare const EVENT_DESCRIPTION_SIZE = 300;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Calculate the total number of views from the given dates and event statistic.
|
|
7
|
+
*
|
|
8
|
+
* @param {string[]} dates - An array of dates.
|
|
9
|
+
* @param {EventStatistic} eventStatistic - The event statistic object.
|
|
10
|
+
* @returns {number} - The total number of views.
|
|
11
|
+
*/
|
|
12
|
+
export declare const calculateTotalViews: (dates: string[], eventStatistic: EventStatistic) => number;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the total number of products sold and the total amount sold
|
|
15
|
+
* based on the provided dates and event statistics.
|
|
16
|
+
*
|
|
17
|
+
* @param {string[]} dates - An array of dates.
|
|
18
|
+
* @param {EventStatistic} eventStatistic - Object containing event statistics.
|
|
19
|
+
* @returns {number[]} An array representing the total number of products sold and total amount sold.
|
|
20
|
+
*/
|
|
21
|
+
export declare const calculateTotalSoldAndAmount: (dates: string[], eventStatistic: EventStatistic) => [number, number];
|
|
22
|
+
/**
|
|
23
|
+
* Get statistic information for a given event and date.
|
|
24
|
+
* @param {EventStatistic | null} eventStatistic - The event statistic object.
|
|
25
|
+
* @param {string} date - The date in ISO format.
|
|
26
|
+
* @returns {{
|
|
27
|
+
* totalViews: number;
|
|
28
|
+
* totalSold: number;
|
|
29
|
+
* totalAmount: number;
|
|
30
|
+
* }} The statistic information object.
|
|
31
|
+
*/
|
|
32
|
+
export declare const getStatisticInfo: (eventStatistic: EventStatistic | null, date: string) => {
|
|
6
33
|
totalViews: number;
|
|
7
34
|
totalSold: number;
|
|
8
35
|
totalAmount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/events/event-card/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/events/event-card/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kEAAkE,CAAC;AAGlG,wBAAgB,aAAa,CAAC,OAAO,KAAA,EAAE,UAAU,KAAA,OAIhD;AAED,eAAO,MAAM,wBAAwB,2CAepC,CAAC;AAEF,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,UACvB,MAAM,EAAE,kBACC,cAAc,KAC7B,MAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,UAC/B,MAAM,EAAE,kBACC,cAAc,KAC7B,CAAC,MAAM,EAAE,MAAM,CAejB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,mBACX,cAAc,GAAG,IAAI,QAC/B,MAAM;gBAEA,MAAM;eACP,MAAM;iBACJ,MAAM;CAuBpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=300;exports.EVENT_DESCRIPTION_SIZE=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),r=require("@licklist/core/dist/Config"),e=require("luxon");var o=300,a=function(t,r){return t.reduce((function(t,e){var o;return t+Object.values(null!==(o=r.views[e])&&void 0!==o?o:{}).reduce((function(t,r){return t+(r.pageViews||0)}),0)}),0)},n=function(t,r){var e=0,o=0;return t.forEach((function(t){var a;return Object.values(null!==(a=r.productCategorySummary[t])&&void 0!==a?a:{}).forEach((function(t){var r,a=t.totalPerCategory,n=t.productsSummary;o+=a||0,e+=null!==(r=null==n?void 0:n.reduce((function(t,r){return t+r.productsSold}),0))&&void 0!==r?r:0}))})),[e,o]};exports.EVENT_DESCRIPTION_SIZE=o,exports.calculateTotalSoldAndAmount=n,exports.calculateTotalViews=a,exports.formatContent=function(t,r){return t?t.length>r?"".concat(t.slice(0,r),"..."):t:""},exports.formatContentWithoutTags=function(t,r){if(void 0===r&&(r=o),!t)return"";if(t<r)return t;var e=t.replace(/<[^>]*>/g,"").trim().replace(/ |[^a-zA-Z0-9\s]/g,"").replace(/\s\s+/g," ").slice(0,r).split(" "),a=String(t).indexOf(e[e.length-2]);return t.slice(0,a).concat("...")},exports.getStatisticInfo=function(o,u){var i;if(!o)return{totalViews:0,totalSold:0,totalAmount:0};var l=e.DateTime.fromISO(u).toUTC().toFormat(r.DATE_FORMAT),c=e.DateTime.fromISO(u).toUTC().toFormat(r.DATE_TIME_FULL_FORMAT),s=Object.values(null!==(i=o.relativeDays)&&void 0!==i?i:{}),d=a(t.__spreadArray([l],t.__read(s),!1),o),f=t.__read(n(t.__spreadArray([c],t.__read(s),!1),o),2);return{totalViews:d,totalSold:f[0],totalAmount:f[1]}};
|
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ export function EventCard({
|
|
|
50
50
|
}: EventCardProps) {
|
|
51
51
|
const { t } = useTranslation("Design");
|
|
52
52
|
const { formatNumber, formatDate } = useIntl();
|
|
53
|
-
const { totalViews, ...statistics } = getStatisticInfo(eventStatistic);
|
|
53
|
+
const { totalViews, ...statistics } = getStatisticInfo(eventStatistic, date);
|
|
54
54
|
const memoedContent = useMemo(
|
|
55
55
|
() => formatContentWithoutTags(description, EVENT_DESCRIPTION_SIZE),
|
|
56
56
|
[description]
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { DATE_FORMAT, DATE_TIME_FULL_FORMAT } from "@licklist/core/dist/Config";
|
|
1
2
|
import { EventStatistic } from "@licklist/core/dist/DataMapper/Provider/EventStatisticDataMapper";
|
|
3
|
+
import { DateTime } from "luxon";
|
|
2
4
|
|
|
3
5
|
export function formatContent(content, maxSymbols) {
|
|
4
6
|
if (!content) return "";
|
|
@@ -25,27 +27,92 @@ export const formatContentWithoutTags = (
|
|
|
25
27
|
|
|
26
28
|
export const EVENT_DESCRIPTION_SIZE = 300;
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Calculate the total number of views from the given dates and event statistic.
|
|
32
|
+
*
|
|
33
|
+
* @param {string[]} dates - An array of dates.
|
|
34
|
+
* @param {EventStatistic} eventStatistic - The event statistic object.
|
|
35
|
+
* @returns {number} - The total number of views.
|
|
36
|
+
*/
|
|
37
|
+
export const calculateTotalViews = (
|
|
38
|
+
dates: string[],
|
|
39
|
+
eventStatistic: EventStatistic
|
|
40
|
+
): number => {
|
|
41
|
+
return dates.reduce(
|
|
42
|
+
(rootAcc, date) =>
|
|
43
|
+
rootAcc +
|
|
44
|
+
Object.values(eventStatistic.views[date] ?? {}).reduce(
|
|
45
|
+
(acc, view) => acc + (view.pageViews || 0),
|
|
46
|
+
0
|
|
47
|
+
),
|
|
48
|
+
0
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Calculates the total number of products sold and the total amount sold
|
|
54
|
+
* based on the provided dates and event statistics.
|
|
55
|
+
*
|
|
56
|
+
* @param {string[]} dates - An array of dates.
|
|
57
|
+
* @param {EventStatistic} eventStatistic - Object containing event statistics.
|
|
58
|
+
* @returns {number[]} An array representing the total number of products sold and total amount sold.
|
|
59
|
+
*/
|
|
60
|
+
export const calculateTotalSoldAndAmount = (
|
|
61
|
+
dates: string[],
|
|
62
|
+
eventStatistic: EventStatistic
|
|
63
|
+
): [number, number] => {
|
|
30
64
|
let totalSold = 0;
|
|
31
65
|
let totalAmount = 0;
|
|
66
|
+
dates.forEach((date) =>
|
|
67
|
+
Object.values(eventStatistic.productCategorySummary[date] ?? {}).forEach(
|
|
68
|
+
({ totalPerCategory, productsSummary }) => {
|
|
69
|
+
totalAmount += totalPerCategory || 0;
|
|
70
|
+
totalSold +=
|
|
71
|
+
productsSummary?.reduce((acc, curr) => acc + curr.productsSold, 0) ??
|
|
72
|
+
0;
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
);
|
|
32
76
|
|
|
33
|
-
|
|
77
|
+
return [totalSold, totalAmount];
|
|
78
|
+
};
|
|
34
79
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Get statistic information for a given event and date.
|
|
82
|
+
* @param {EventStatistic | null} eventStatistic - The event statistic object.
|
|
83
|
+
* @param {string} date - The date in ISO format.
|
|
84
|
+
* @returns {{
|
|
85
|
+
* totalViews: number;
|
|
86
|
+
* totalSold: number;
|
|
87
|
+
* totalAmount: number;
|
|
88
|
+
* }} The statistic information object.
|
|
89
|
+
*/
|
|
90
|
+
export const getStatisticInfo = (
|
|
91
|
+
eventStatistic: EventStatistic | null,
|
|
92
|
+
date: string
|
|
93
|
+
): {
|
|
94
|
+
totalViews: number;
|
|
95
|
+
totalSold: number;
|
|
96
|
+
totalAmount: number;
|
|
97
|
+
} => {
|
|
98
|
+
const defaultValues = { totalViews: 0, totalSold: 0, totalAmount: 0 };
|
|
99
|
+
if (!eventStatistic) return defaultValues;
|
|
100
|
+
|
|
101
|
+
const viewsFormattedDate = DateTime.fromISO(date)
|
|
102
|
+
.toUTC()
|
|
103
|
+
.toFormat(DATE_FORMAT);
|
|
104
|
+
const summaryFormattedDate = DateTime.fromISO(date)
|
|
105
|
+
.toUTC()
|
|
106
|
+
.toFormat(DATE_TIME_FULL_FORMAT);
|
|
107
|
+
const relatedDays = Object.values(eventStatistic.relativeDays ?? {});
|
|
108
|
+
|
|
109
|
+
const totalViews = calculateTotalViews(
|
|
110
|
+
[viewsFormattedDate, ...relatedDays],
|
|
111
|
+
eventStatistic
|
|
40
112
|
);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
productsSummary?.forEach(({ productsSold }) => {
|
|
46
|
-
totalSold += productsSold;
|
|
47
|
-
});
|
|
48
|
-
})
|
|
113
|
+
const [totalSold, totalAmount] = calculateTotalSoldAndAmount(
|
|
114
|
+
[summaryFormattedDate, ...relatedDays],
|
|
115
|
+
eventStatistic
|
|
49
116
|
);
|
|
50
117
|
|
|
51
118
|
return { totalViews, totalSold, totalAmount };
|