@everymatrix/nuts-inbox-widget 0.0.9 → 1.44.0

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.
Files changed (35) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/nuts-inbox-widget.cjs.js +1 -1
  3. package/dist/cjs/nuts-inbox-widget_3.cjs.entry.js +476 -449
  4. package/dist/collection/api/methods/index.js +135 -0
  5. package/dist/collection/api/methods/types.js +1 -0
  6. package/dist/collection/components/nuts-inbox-widget/nuts-inbox-widget.css +5 -0
  7. package/dist/collection/components/nuts-inbox-widget/nuts-inbox-widget.js +100 -123
  8. package/dist/collection/components/nuts-notification/constants.js +1 -0
  9. package/dist/collection/components/nuts-notification/nuts-notification.css +26 -11
  10. package/dist/collection/components/nuts-notification/nuts-notification.js +158 -100
  11. package/dist/collection/components/nuts-popover/nuts-popover.css +43 -0
  12. package/dist/collection/components/nuts-popover/nuts-popover.js +122 -61
  13. package/dist/collection/types/nuts-inbox-widget.types.js +0 -8
  14. package/dist/collection/utils/locale.utils.js +12 -4
  15. package/dist/collection/utils/utils.js +16 -0
  16. package/dist/components/nuts-inbox-widget.js +55 -235
  17. package/dist/components/nuts-notification2.js +278 -84
  18. package/dist/components/nuts-popover2.js +61 -45
  19. package/dist/esm/loader.js +1 -1
  20. package/dist/esm/nuts-inbox-widget.js +1 -1
  21. package/dist/esm/nuts-inbox-widget_3.entry.js +477 -450
  22. package/dist/nuts-inbox-widget/nuts-inbox-widget.esm.js +1 -1
  23. package/dist/nuts-inbox-widget/p-d0db9d2d.entry.js +1 -0
  24. package/dist/types/api/methods/index.d.ts +7 -0
  25. package/dist/types/api/methods/types.d.ts +65 -0
  26. package/dist/types/components/nuts-inbox-widget/nuts-inbox-widget.d.ts +20 -11
  27. package/dist/types/components/nuts-notification/constants.d.ts +1 -0
  28. package/dist/types/components/nuts-notification/nuts-notification.d.ts +18 -6
  29. package/dist/types/components/nuts-popover/nuts-popover.d.ts +17 -2
  30. package/dist/types/components.d.ts +50 -2
  31. package/dist/types/types/nuts-inbox-widget.types.d.ts +4 -7
  32. package/dist/types/utils/utils.d.ts +2 -0
  33. package/package.json +4 -1
  34. package/dist/nuts-inbox-widget/p-4788b3e5.entry.js +0 -1
  35. /package/dist/types/Users/{raul.vasile/workspace/everymatrix → adrian.pripon/Documents/Work}/widgets-stencil/packages/nuts-inbox-widget/.stencil/packages/nuts-inbox-widget/stencil.config.d.ts +0 -0
@@ -1,27 +1,47 @@
1
- import { Component, h, Prop, State, Event, Listen, Watch } from '@stencil/core';
1
+ import { Component, h, Prop, State, Event, Listen, Watch, } from '@stencil/core';
2
2
  import { formatDistanceToNow } from 'date-fns';
3
3
  import { translate, getTranslations } from '../../utils/locale.utils';
4
4
  import * as dateFnsLocales from 'date-fns/locale';
5
- import { WarningFilled, InfoCircleFilled, CheckCircleFilled, CloseCircleFilled, UpCircleFilled, QuestionCircleFilled, } from '@ant-design/icons-svg';
5
+ import { WarningFilled, InfoCircleFilled, CheckCircleFilled, CloseCircleFilled, UpCircleFilled, QuestionCircleFilled, DownOutlined, } from '@ant-design/icons-svg';
6
6
  import { renderIconDefinitionToSVGElement } from '@ant-design/icons-svg/es/helpers';
7
+ import { MAX_NOTIFICATION_TEXT_LENGTH } from './constants';
8
+ import { createAuthHeaders, truncate } from '../../utils/utils';
9
+ import { deleteMessage, markAsRead } from '../../api/methods';
7
10
  const systemIcons = {
8
11
  warning: {
9
- icon: renderIconDefinitionToSVGElement(WarningFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#FFF000' } }),
12
+ icon: renderIconDefinitionToSVGElement(WarningFilled, {
13
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#FFF000' },
14
+ }),
10
15
  },
11
16
  info: {
12
- icon: renderIconDefinitionToSVGElement(InfoCircleFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#0000FF' } }),
17
+ icon: renderIconDefinitionToSVGElement(InfoCircleFilled, {
18
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#0000FF' },
19
+ }),
13
20
  },
14
21
  up: {
15
- icon: renderIconDefinitionToSVGElement(UpCircleFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#A1A1B2' } }),
22
+ icon: renderIconDefinitionToSVGElement(UpCircleFilled, {
23
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#A1A1B2' },
24
+ }),
16
25
  },
17
26
  question: {
18
- icon: renderIconDefinitionToSVGElement(QuestionCircleFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#A1A1B2' } }),
27
+ icon: renderIconDefinitionToSVGElement(QuestionCircleFilled, {
28
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#A1A1B2' },
29
+ }),
19
30
  },
20
31
  success: {
21
- icon: renderIconDefinitionToSVGElement(CheckCircleFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#4D9980' } }),
32
+ icon: renderIconDefinitionToSVGElement(CheckCircleFilled, {
33
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#4D9980' },
34
+ }),
22
35
  },
23
36
  error: {
24
- icon: renderIconDefinitionToSVGElement(CloseCircleFilled, { extraSVGAttrs: { width: '20px', height: '20px', fill: '#E54545' } }),
37
+ icon: renderIconDefinitionToSVGElement(CloseCircleFilled, {
38
+ extraSVGAttrs: { width: '20px', height: '20px', fill: '#E54545' },
39
+ }),
40
+ },
41
+ arrowDown: {
42
+ icon: renderIconDefinitionToSVGElement(DownOutlined, {
43
+ extraSVGAttrs: { width: '16px', height: '16px', fill: '#A1A1B2' },
44
+ }),
25
45
  },
26
46
  };
27
47
  const dateFnsLocale = (lang) => {
@@ -40,6 +60,68 @@ export class NutsNotification {
40
60
  this.showSettingsModal = false;
41
61
  this.messageSeen = false;
42
62
  this.messageRead = false;
63
+ this.toggleSettingsModal = (e) => {
64
+ e.stopImmediatePropagation();
65
+ this.showSettingsModal = !this.showSettingsModal;
66
+ this.settingsOpened.emit(this.messageId);
67
+ };
68
+ this.toggleNotificationRead = async (event) => {
69
+ event === null || event === void 0 ? void 0 : event.stopImmediatePropagation();
70
+ const unread = this.messageRead;
71
+ const markAsReadBody = {
72
+ messageId: `${this.messageId}`,
73
+ mark: {
74
+ seen: !unread,
75
+ read: !unread,
76
+ },
77
+ };
78
+ const notificationData = await markAsRead({
79
+ baseUrl: this.baseUrl,
80
+ body: markAsReadBody,
81
+ headers: this.defaultHeaders,
82
+ unread,
83
+ });
84
+ this.messageRead = notificationData.messageRead;
85
+ this.messageSeen = notificationData.messageSeen;
86
+ this.showSettingsModal = notificationData.showSettingsModal;
87
+ };
88
+ this.deleteNotification = async () => {
89
+ const deleteMessageResponse = await deleteMessage({
90
+ baseUrl: this.baseUrl,
91
+ headers: this.defaultHeaders,
92
+ messageId: this.messageId,
93
+ });
94
+ this.showSettingsModal = deleteMessageResponse;
95
+ if (deleteMessageResponse) {
96
+ return;
97
+ }
98
+ this.messageDeteled.emit(this.messageId);
99
+ };
100
+ this.notificationActionHandler = () => {
101
+ var _a, _b, _c;
102
+ if (this.notificationAction == 'default' || !this.notificationAction) {
103
+ if (this.redirectUrl.length > 0) {
104
+ window.location.href = this.redirectUrl;
105
+ }
106
+ }
107
+ if (this.notificationAction == 'postMessage') {
108
+ window.postMessage({ type: 'NotificationRedirect', url: this.redirectUrl }, window.location.href);
109
+ }
110
+ if (!this.messageRead) {
111
+ this.toggleNotificationRead();
112
+ }
113
+ if (((_a = this.content) === null || _a === void 0 ? void 0 : _a.length) <= MAX_NOTIFICATION_TEXT_LENGTH) {
114
+ return;
115
+ }
116
+ if (((_b = this.displayedContent) === null || _b === void 0 ? void 0 : _b.length) !== ((_c = this.content) === null || _c === void 0 ? void 0 : _c.length) &&
117
+ this.displayedContent !== this.content) {
118
+ this.displayedContent = this.content;
119
+ this.dropdownArrowRef.classList.add('FlipX');
120
+ return;
121
+ }
122
+ this.displayedContent = truncate(this.content, MAX_NOTIFICATION_TEXT_LENGTH);
123
+ this.dropdownArrowRef.classList.remove('FlipX');
124
+ };
43
125
  this.setClientStyling = () => {
44
126
  let sheet = document.createElement('style');
45
127
  sheet.innerHTML = this.clientStyling;
@@ -52,12 +134,20 @@ export class NutsNotification {
52
134
  .then((res) => res.text())
53
135
  .then((data) => {
54
136
  cssFile.innerHTML = data;
55
- setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
137
+ setTimeout(() => {
138
+ this.stylingContainer.prepend(cssFile);
139
+ }, 1);
56
140
  })
57
141
  .catch((err) => {
58
142
  console.log('error ', err);
59
143
  });
60
144
  };
145
+ this.assignRefToStylingContainer = (ref) => {
146
+ this.stylingContainer = ref;
147
+ };
148
+ this.assignRefToDropdownArrow = (ref) => {
149
+ this.dropdownArrowRef = ref;
150
+ };
61
151
  }
62
152
  allNotificationsReadHandler() {
63
153
  this.messageSeen = true;
@@ -79,103 +169,36 @@ export class NutsNotification {
79
169
  connectedCallback() {
80
170
  this.messageSeen = this.seen;
81
171
  this.messageRead = this.read;
82
- }
83
- deleteMessage(messageId) {
84
- let url = new URL(`${this.backendUrl}/v1/widgets/messages/${messageId}`);
85
- const headers = new Headers();
86
- headers.append('Authorization', `Bearer ${this.token || ''}`);
87
- const options = {
88
- method: 'DELETE',
89
- headers,
90
- };
91
- fetch(url.href, options)
92
- .then((res) => res.json())
93
- .then(() => {
94
- this.showSettingsModal = false;
95
- this.messageDeteled.emit(messageId);
96
- })
97
- .catch((err) => {
98
- console.error('err', err);
99
- });
100
- }
101
- markAsRead(messageId) {
102
- let url = new URL(`${this.backendUrl}/v1/widgets/messages/markAs`);
103
- const headers = new Headers();
104
- headers.append('Authorization', `Bearer ${this.token || ''}`);
105
- headers.append('Content-Type', 'application/json');
106
- const body = {
107
- messageId: `${messageId}`,
108
- mark: {
109
- seen: true,
110
- read: true
111
- }
112
- };
113
- const options = {
114
- method: 'POST',
115
- headers,
116
- body: JSON.stringify(body)
117
- };
118
- fetch(url.href, options)
119
- .then((res) => res.json())
120
- .then((response) => {
121
- this.messageSeen = response.data[0].seen;
122
- this.messageRead = response.data[0].read;
123
- this.showSettingsModal = false;
124
- })
125
- .catch((err) => {
126
- console.error('err', err);
127
- });
128
- }
129
- toggleSettingsModal(e) {
130
- e.stopImmediatePropagation();
131
- this.showSettingsModal = !this.showSettingsModal;
132
- if (this.showSettingsModal) {
133
- let rect = this.settingsButtonRef.getBoundingClientRect();
134
- this.settingsModalRef.style.left = `${rect.left}px`;
135
- this.settingsModalRef.style.top = `${rect.top}px`;
136
- this.settingsOpened.emit(this.messageId);
137
- }
138
- }
139
- notificationActionHandler() {
140
- if (this.notificationAction == 'default' || !this.notificationAction) {
141
- if (this.redirectUrl.length > 0) {
142
- window.location.href = this.redirectUrl;
143
- }
144
- }
145
- if (this.notificationAction == 'postMessage') {
146
- window.postMessage({ type: 'NotificationRedirect', url: this.redirectUrl }, window.location.href);
147
- }
172
+ this.displayedContent = truncate(this.content, MAX_NOTIFICATION_TEXT_LENGTH);
173
+ this.defaultHeaders = createAuthHeaders(this.token, this.sessionId, this.admin);
174
+ this.baseUrl = `${this.backendUrl}/v1/${this.operatorId}`;
148
175
  }
149
176
  render() {
150
- var _a;
151
- return (h("div", null,
152
- h("div", { class: 'NotificationContainer' + (this.messageSeen ? '' : ' Unseen'), ref: el => this.stylingContainer = el, onClick: () => this.notificationActionHandler() },
153
- this.badge ? h("div", { class: "AvatarContainer" },
154
- h("div", { class: "Avatar" }, ((_a = systemIcons[this.badge]) === null || _a === void 0 ? void 0 : _a.icon) ?
155
- h("div", { innerHTML: systemIcons[this.badge].icon }) :
156
- h("img", { class: "AvatarImage", src: this.badge }))) : '',
177
+ var _a, _b;
178
+ return (h("div", { class: "Wrapper" },
179
+ h("div", { class: 'NotificationContainer' + (this.messageSeen ? '' : ' Unseen'), ref: this.assignRefToStylingContainer, onClick: this.notificationActionHandler },
180
+ this.badge ? (h("div", { class: "AvatarContainer" },
181
+ h("div", { class: "Avatar" }, ((_a = systemIcons[this.badge]) === null || _a === void 0 ? void 0 : _a.icon) ? (h("div", { innerHTML: systemIcons[this.badge].icon })) : (h("img", { class: "AvatarImage", src: this.badge }))))) : (''),
157
182
  h("div", { class: "ContentContainer" },
158
- h("p", null, this.content),
159
- h("p", { class: "Date" }, formatDistanceToNow(new Date(this.date), { addSuffix: true, locale: dateFnsLocale(this.language) }))),
160
- h("div", { class: "Settings", onClick: (e) => this.toggleSettingsModal(e), ref: el => this.settingsButtonRef = el },
161
- h("svg", { width: "30", height: "30", viewBox: "0 0 30 30", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
162
- h("path", { d: "M20.625 15.5C20.625 16.5547 21.4453 17.375 22.5 17.375C23.5156 17.375 24.375 16.5547 24.375 15.5C24.375 14.4844 23.5156 13.625 22.5 13.625C21.4453 13.625 20.625 14.4844 20.625 15.5ZM9.375 15.5C9.375 14.4844 8.51562 13.625 7.5 13.625C6.44531 13.625 5.625 14.4844 5.625 15.5C5.625 16.5547 6.44531 17.375 7.5 17.375C8.51562 17.375 9.375 16.5547 9.375 15.5ZM16.875 15.5C16.875 14.4844 16.0156 13.625 15 13.625C13.9453 13.625 13.125 14.4844 13.125 15.5C13.125 16.5547 13.9453 17.375 15 17.375C16.0156 17.375 16.875 16.5547 16.875 15.5Z", fill: "currentColor" }))),
163
- this.messageSeen ? '' : h("div", { class: "UnseenButton" },
164
- h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "10px", height: "10px", viewBox: "0 0 16 16", fill: "none" },
165
- h("rect", { x: "1.5", y: "1.5", width: "13", height: "13", rx: "6.5", fill: "url(#paint0_linear_1722_2699)", stroke: "#1E1E26", "stroke-width": "3" }),
166
- h("defs", null,
167
- h("linearGradient", { id: "paint0_linear_1722_2699", x1: "8", y1: "13", x2: "8", y2: "3", gradientUnits: "userSpaceOnUse" },
168
- h("stop", { "stop-color": "#FF512F" }),
169
- h("stop", { offset: "1", "stop-color": "#DD2476" })))))),
170
- this.showSettingsModal ? h("div", { class: "SettingsDropdown", ref: el => this.settingsModalRef = el },
171
- h("button", { onClick: () => this.markAsRead(this.messageId) },
183
+ h("p", null, this.displayedContent),
184
+ h("p", { class: "Date" }, formatDistanceToNow(new Date(this.date), {
185
+ addSuffix: true,
186
+ locale: dateFnsLocale(this.language),
187
+ }))),
188
+ h("div", { class: "RightActionsContainer" },
189
+ h("div", { class: "Settings", onClick: this.toggleSettingsModal },
190
+ h("svg", { width: "24", height: "24", viewBox: "0 0 30 30", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
191
+ h("path", { d: "M20.625 15.5C20.625 16.5547 21.4453 17.375 22.5 17.375C23.5156 17.375 24.375 16.5547 24.375 15.5C24.375 14.4844 23.5156 13.625 22.5 13.625C21.4453 13.625 20.625 14.4844 20.625 15.5ZM9.375 15.5C9.375 14.4844 8.51562 13.625 7.5 13.625C6.44531 13.625 5.625 14.4844 5.625 15.5C5.625 16.5547 6.44531 17.375 7.5 17.375C8.51562 17.375 9.375 16.5547 9.375 15.5ZM16.875 15.5C16.875 14.4844 16.0156 13.625 15 13.625C13.9453 13.625 13.125 14.4844 13.125 15.5C13.125 16.5547 13.9453 17.375 15 17.375C16.0156 17.375 16.875 16.5547 16.875 15.5Z", fill: "currentColor" }))),
192
+ ((_b = this.content) === null || _b === void 0 ? void 0 : _b.length) > MAX_NOTIFICATION_TEXT_LENGTH && (h("div", { class: "AccordionArrow", innerHTML: systemIcons.arrowDown.icon, ref: this.assignRefToDropdownArrow })))),
193
+ this.showSettingsModal ? (h("div", { class: "SettingsDropdown" },
194
+ h("button", { onClick: this.toggleNotificationRead },
172
195
  h("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
173
196
  h("path", { d: "M14.9434 5.17969C14.2109 4.59375 13.625 4.125 10.1387 1.60547C9.64062 1.25391 8.67383 0.375 8 0.375V0.404297C7.9707 0.404297 7.9707 0.375 7.9707 0.375C7.29688 0.375 6.33008 1.25391 5.83203 1.60547C2.3457 4.125 1.75977 4.59375 1.02734 5.17969C0.675781 5.44336 0.5 5.85352 0.5 6.26367V13.9688C0.5 14.7598 1.11523 15.375 1.90625 15.375H14.0938C14.8555 15.375 15.5 14.7598 15.5 13.9688V6.26367C15.5 5.85352 15.2949 5.44336 14.9434 5.17969ZM9.37695 11.1562C8.9668 11.4785 8.46875 11.6543 8 11.6543C7.50195 11.6543 7.00391 11.4785 6.59375 11.1562L2.375 7.8457V6.49805C2.99023 6 3.72266 5.44336 6.94531 3.12891C7.0332 3.04102 7.15039 2.95312 7.26758 2.86523C7.41406 2.74805 7.73633 2.48438 8 2.33789C8.23438 2.48438 8.55664 2.74805 8.70312 2.86523C8.82031 2.95312 8.9375 3.04102 9.02539 3.12891C12.2188 5.44336 12.9805 6 13.625 6.49805V7.8457L9.37695 11.1562Z", fill: "currentColor" })),
174
- translate('markAsRead', this.language)),
175
- h("button", { onClick: () => this.deleteMessage(this.messageId) },
197
+ translate(this.messageRead ? 'markAsUnread' : 'markAsRead', this.language)),
198
+ h("button", { onClick: this.deleteNotification },
176
199
  h("svg", { width: "16", height: "16", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
177
200
  h("path", { d: "M4.375 15.4375C4.375 16.1758 4.94922 16.75 5.6875 16.75H13.5625C14.2734 16.75 14.875 16.1758 14.875 15.4375V6.25H4.375V15.4375ZM11.8125 8.4375C11.8125 8.21875 12.0039 8 12.25 8C12.4688 8 12.6875 8.21875 12.6875 8.4375V14.5625C12.6875 14.8086 12.4688 15 12.25 15C12.0039 15 11.8125 14.8086 11.8125 14.5625V8.4375ZM9.1875 8.4375C9.1875 8.21875 9.37891 8 9.625 8C9.84375 8 10.0625 8.21875 10.0625 8.4375V14.5625C10.0625 14.8086 9.84375 15 9.625 15C9.37891 15 9.1875 14.8086 9.1875 14.5625V8.4375ZM6.5625 8.4375C6.5625 8.21875 6.75391 8 7 8C7.21875 8 7.4375 8.21875 7.4375 8.4375V14.5625C7.4375 14.8086 7.21875 15 7 15C6.75391 15 6.5625 14.8086 6.5625 14.5625V8.4375ZM15.3125 3.625H12.25L11.9219 2.99609C11.8398 2.85938 11.7031 2.75 11.5391 2.75H7.68359C7.51953 2.75 7.38281 2.85938 7.30078 2.99609L7 3.625H3.9375C3.69141 3.625 3.5 3.84375 3.5 4.0625V4.9375C3.5 5.18359 3.69141 5.375 3.9375 5.375H15.3125C15.5312 5.375 15.75 5.18359 15.75 4.9375V4.0625C15.75 3.84375 15.5312 3.625 15.3125 3.625Z", fill: "currentColor" })),
178
- translate('removeMessage', this.language))) : ''));
201
+ translate('removeMessage', this.language)))) : ('')));
179
202
  }
180
203
  static get is() { return "nuts-notification"; }
181
204
  static get originalStyleUrls() { return {
@@ -304,6 +327,40 @@ export class NutsNotification {
304
327
  "attribute": "language",
305
328
  "reflect": true
306
329
  },
330
+ "sessionId": {
331
+ "type": "string",
332
+ "mutable": false,
333
+ "complexType": {
334
+ "original": "string",
335
+ "resolved": "string",
336
+ "references": {}
337
+ },
338
+ "required": true,
339
+ "optional": false,
340
+ "docs": {
341
+ "tags": [],
342
+ "text": "The sessionID of the user"
343
+ },
344
+ "attribute": "session-id",
345
+ "reflect": true
346
+ },
347
+ "admin": {
348
+ "type": "boolean",
349
+ "mutable": false,
350
+ "complexType": {
351
+ "original": "boolean",
352
+ "resolved": "boolean",
353
+ "references": {}
354
+ },
355
+ "required": false,
356
+ "optional": true,
357
+ "docs": {
358
+ "tags": [],
359
+ "text": "Indicates if the associated sessionId is an admin or a player sessionId"
360
+ },
361
+ "attribute": "admin",
362
+ "reflect": true
363
+ },
307
364
  "userId": {
308
365
  "type": "string",
309
366
  "mutable": false,
@@ -480,7 +537,8 @@ export class NutsNotification {
480
537
  static get states() { return {
481
538
  "showSettingsModal": {},
482
539
  "messageSeen": {},
483
- "messageRead": {}
540
+ "messageRead": {},
541
+ "displayedContent": {}
484
542
  }; }
485
543
  static get events() { return [{
486
544
  "method": "messageDeteled",
@@ -13,6 +13,8 @@
13
13
  direction: ltr;
14
14
  width: 420px;
15
15
  z-index: 999;
16
+ position: absolute;
17
+ right: 0;
16
18
  }
17
19
  .Popover .Header {
18
20
  display: flex;
@@ -72,6 +74,7 @@
72
74
  .Popover .NotificationList {
73
75
  height: 400px;
74
76
  overflow: auto;
77
+ box-shadow: 0px 20px 10px -20px rgba(0, 0, 0, 0.45) inset, 0px -20px 10px -20px rgba(0, 0, 0, 0.45) inset;
75
78
  }
76
79
  .Popover .NotificationList .NoMessages {
77
80
  display: flex;
@@ -83,4 +86,44 @@
83
86
  .Popover .NotificationList .NoMessages p {
84
87
  color: var(--emfe-w-color-white, #fff);
85
88
  opacity: 0.7;
89
+ }
90
+ .Popover .Pagination {
91
+ display: flex;
92
+ justify-content: space-around;
93
+ margin-top: 13px;
94
+ }
95
+ .Popover .Pagination .Button {
96
+ width: 43%;
97
+ }
98
+ .Popover .Pagination .Button button {
99
+ font-family: inherit;
100
+ border: 0px;
101
+ background-color: transparent;
102
+ outline: 0px;
103
+ width: 100%;
104
+ text-align: left;
105
+ text-decoration: none;
106
+ box-sizing: border-box;
107
+ padding: 10px 12px;
108
+ cursor: pointer;
109
+ border-radius: 7px;
110
+ display: flex;
111
+ align-items: center;
112
+ color: var(--emfe-w-color-white, white);
113
+ font-weight: 400;
114
+ font-size: 14px;
115
+ justify-content: center;
116
+ }
117
+ .Popover .Pagination .Button button svg {
118
+ width: 15px;
119
+ height: 15px;
120
+ fill: white;
121
+ }
122
+ .Popover .Pagination .Button button:disabled {
123
+ cursor: default;
124
+ opacity: 0.5;
125
+ }
126
+ .Popover .Pagination .Button button:hover:enabled {
127
+ background: var(--emfe-w-color-gray-300, #3d3d4d);
128
+ transition: 300ms;
86
129
  }
@@ -1,5 +1,7 @@
1
- import { Component, h, Listen, Event, Prop, State, Watch } from '@stencil/core';
1
+ import { Component, h, Listen, Event, Prop, State, Watch, } from '@stencil/core';
2
2
  import { translate, getTranslations } from '../../utils/locale.utils';
3
+ import { getNotifications, markAllAsRead } from '../../api/methods';
4
+ import { createAuthHeaders } from '../../utils/utils';
3
5
  export class NutsPopover {
4
6
  constructor() {
5
7
  /**
@@ -12,6 +14,25 @@ export class NutsPopover {
12
14
  this.translationUrl = '';
13
15
  this.isLoading = true;
14
16
  this.showMarkAll = false;
17
+ this.currentPage = 0;
18
+ this.updateNotificationsDataAfterPageChange = (getNotificationsData) => {
19
+ this.isLoading = getNotificationsData.isLoading;
20
+ this.notifications = getNotificationsData.notifications;
21
+ };
22
+ this.nextPage = async () => {
23
+ getNotifications({
24
+ baseUrl: this.baseUrl,
25
+ headers: this.defaultHeaders,
26
+ page: ++this.currentPage,
27
+ }).then((data) => this.updateNotificationsDataAfterPageChange(data));
28
+ };
29
+ this.prevPage = () => {
30
+ getNotifications({
31
+ baseUrl: this.baseUrl,
32
+ headers: this.defaultHeaders,
33
+ page: --this.currentPage,
34
+ }).then((data) => this.updateNotificationsDataAfterPageChange(data));
35
+ };
15
36
  this.setClientStyling = () => {
16
37
  let sheet = document.createElement('style');
17
38
  sheet.innerHTML = this.clientStyling;
@@ -24,21 +45,43 @@ export class NutsPopover {
24
45
  .then((res) => res.text())
25
46
  .then((data) => {
26
47
  cssFile.innerHTML = data;
27
- setTimeout(() => { this.stylingContainer.prepend(cssFile); }, 1);
48
+ setTimeout(() => {
49
+ this.stylingContainer.prepend(cssFile);
50
+ }, 1);
28
51
  })
29
52
  .catch((err) => {
30
53
  console.log('error ', err);
31
54
  });
32
55
  };
56
+ this.markAllNotificationsAsRead = async () => {
57
+ const markedAllNotificationsAsRead = await markAllAsRead({
58
+ baseUrl: this.baseUrl,
59
+ headers: this.defaultHeaders,
60
+ });
61
+ if (markedAllNotificationsAsRead) {
62
+ this.allNotificationsRead.emit();
63
+ }
64
+ };
65
+ this.assignRefToStylingContainer = (ref) => {
66
+ this.stylingContainer = ref;
67
+ };
33
68
  }
34
69
  messageDeteledHandler(event) {
35
70
  this.notifications = this.notifications.filter((item) => {
36
71
  return item._id != event.detail;
37
72
  });
38
- this.getNotifications();
73
+ getNotifications({
74
+ baseUrl: this.baseUrl,
75
+ headers: this.defaultHeaders,
76
+ page: this.currentPage,
77
+ }).then((data) => this.updateNotificationsDataAfterPageChange(data));
39
78
  }
40
79
  newNotificationHandler(event) {
41
- this.notifications = [event.detail, ...this.notifications];
80
+ if (Array.isArray(this.notifications)) {
81
+ this.notifications = [event.detail, ...this.notifications];
82
+ return;
83
+ }
84
+ this.notifications = [event.detail];
42
85
  }
43
86
  unseenCountHandler(newValue) {
44
87
  if (newValue == 0) {
@@ -59,72 +102,56 @@ export class NutsPopover {
59
102
  await getTranslations(this.translationUrl);
60
103
  }
61
104
  }
62
- getNotifications() {
63
- let url = new URL(`${this.backendUrl}/v1/widgets/notifications/feed`);
64
- const headers = new Headers();
65
- headers.append('Authorization', `Bearer ${this.token || ''}`);
66
- headers.append('Content-Type', 'application/json');
67
- url.searchParams.append('page', '0');
68
- const options = {
69
- method: 'GET',
70
- headers,
71
- };
72
- fetch(url.href, options)
73
- .then((res) => res.json())
74
- .then((response) => {
75
- this.isLoading = false;
76
- this.notifications = response.data;
77
- });
78
- }
79
- markAllAsRead() {
80
- let url = new URL(`${this.backendUrl}/v1/widgets/messages/read`);
81
- const headers = new Headers();
82
- headers.append('Authorization', `Bearer ${this.token || ''}`);
83
- const options = {
84
- method: 'POST',
85
- body: JSON.stringify({}),
86
- headers,
87
- };
88
- fetch(url.href, options)
89
- .then((res) => res.json())
90
- .then(() => {
91
- this.allNotificationsRead.emit();
92
- })
93
- .catch((err) => {
94
- console.error('err', err);
95
- });
96
- }
97
105
  connectedCallback() {
98
- this.getNotifications();
106
+ this.baseUrl = `${this.backendUrl}/v1/${this.operatorId}`;
107
+ this.defaultHeaders = createAuthHeaders(this.token, this.sessionId, this.admin);
108
+ getNotifications({
109
+ baseUrl: this.baseUrl,
110
+ headers: this.defaultHeaders,
111
+ page: this.currentPage,
112
+ }).then((data) => this.updateNotificationsDataAfterPageChange(data));
99
113
  if (this.unseenCount != 0) {
100
114
  this.showMarkAll = true;
101
115
  }
102
116
  }
103
117
  render() {
104
- return (h("div", { class: "Popover", ref: el => this.stylingContainer = el },
118
+ return (h("div", { class: "Popover", ref: this.assignRefToStylingContainer },
105
119
  h("div", { class: "Header" },
106
120
  h("div", { class: "Title" },
107
121
  translate('notifications', this.language),
108
- this.unseenCount > 0 ? h("div", { class: "UnseenCounter" }, this.unseenCount) : ''),
109
- this.showMarkAll ? h("div", { class: "MarkAsRead", onClick: () => this.markAllAsRead() }, translate('markAllAsRead', this.language)) : ''),
110
- h("div", { class: "NotificationList" }, !this.isLoading && (this.notifications.length > 0 ? this.notifications.map((item) => {
111
- var _a;
112
- return (h("nuts-notification", { "client-styling": this.clientStyling, key: item.id, "user-id": this.userId, "operator-id": this.operatorId, content: item.content, "message-id": item.id, badge: ((_a = item.actor) === null || _a === void 0 ? void 0 : _a.data) || '', date: item.createdAt, read: item.read, seen: item.seen, language: this.language, "notification-action": this.notificationAction, token: this.token, "backend-url": this.backendUrl, "redirect-url": item.cta.data.url, "translation-url": this.translationUrl }));
113
- }) : h("div", { class: "NoMessages" },
114
- h("svg", { width: "120", height: "108", viewBox: "0 0 120 108", fill: "none" },
115
- h("circle", { cx: "11.3191", cy: "30.7872", r: "6.31915", stroke: "#3D3D4D", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
116
- h("ellipse", { cx: "60.117", cy: "27.9787", rx: "5.96809", ry: "5.61702", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
117
- h("path", { d: "M79.5424 49.4934C79.5424 44.1598 77.6437 39.0446 74.2641 35.2732C70.8844 31.5017 66.3006 29.3829 61.5211 29.3829C56.7415 29.3829 52.1578 31.5017 48.7781 35.2732C45.3985 39.0446 43.4998 44.1598 43.4998 49.4934C43.4998 72.9557 34.4892 79.6592 34.4892 79.6592H88.553C88.553 79.6592 79.5424 72.9557 79.5424 49.4934Z", fill: "#292933" }),
118
- h("path", { d: "M68.8995 81.7552C68.1496 83.551 67.0731 85.0417 65.778 86.0779C64.4828 87.1141 63.0144 87.6595 61.5198 87.6595C60.0252 87.6595 58.5568 87.1141 57.2617 86.0779C55.9665 85.0417 54.8901 83.551 54.1401 81.7552", fill: "#292933" }),
119
- h("path", { d: "M81.2976 50.2203C81.2976 68.2545 87.2222 76.7327 90.2814 79.9083C90.7671 80.4126 90.3802 81.4764 89.68 81.4764C88.0927 81.4764 86.5488 81.4764 85.0422 81.4764M68.5814 82.946C67.6854 84.8068 66.3993 86.3513 64.8518 87.425C63.3044 88.4987 61.5499 89.0638 59.7641 89.0638C57.9783 89.0638 56.2239 88.4987 54.6765 87.425C53.129 86.3513 51.8429 84.8068 50.9468 82.946M79.712 42.3723C78.6394 39.8192 77.0439 37.4727 74.991 35.4861C70.953 31.5783 65.4763 29.3829 59.7656 29.3829C54.055 29.3829 48.5783 31.5783 44.5403 35.4861C43.3681 36.6205 42.345 37.8722 41.4832 39.2127C40.4958 40.7487 39.7202 42.4013 39.1747 44.1276C38.5563 46.0847 38.2337 48.1364 38.2337 50.2203C38.2337 53.2503 38.0665 56.0106 37.7737 58.5212M34.8401 70.7608C32.9874 75.4551 30.7688 78.331 29.2526 79.9055C28.767 80.4099 29.155 81.4764 29.8551 81.4764C47.1962 81.4764 59.3571 81.4764 74.1593 81.4764", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
120
- h("path", { d: "M55.6345 59.0737C55.1665 59.7144 54.4949 60.2462 53.6868 60.6159C52.8787 60.9855 51.9625 61.1801 51.0299 61.1801C50.0973 61.1801 49.1811 60.9855 48.373 60.6159C47.5649 60.2462 46.8933 59.7144 46.4254 59.0737", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
121
- h("path", { d: "M73.1877 59.0737C72.7197 59.7144 72.0481 60.2462 71.24 60.6159C70.4319 60.9855 69.5157 61.1801 68.5831 61.1801C67.6506 61.1801 66.7344 60.9855 65.9263 60.6159C65.1182 60.2462 64.4465 59.7144 63.9786 59.0737", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
122
- h("circle", { cx: "107.511", cy: "56.0638", r: "7.02128", stroke: "#3D3D4D", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
123
- h("circle", { cx: "16.4252", cy: "58.1703", r: "4.21277", fill: "#3D3D4D" }),
124
- h("ellipse", { cx: "59.9573", cy: "104.511", rx: "25.2766", ry: "2.80851", fill: "#3D3D4D" }),
125
- h("path", { d: "M81.5317 18.1489H88.553L81.5317 25.1702H88.553", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
126
- h("path", { d: "M96.6807 2H106.51L96.6807 11.8298H106.51", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" })),
127
- h("p", null, translate('noMessages', this.language)))))));
122
+ this.unseenCount > 0 ? (h("div", { class: "UnseenCounter" }, this.unseenCount)) : ('')),
123
+ this.showMarkAll ? (h("div", { class: "MarkAsRead", onClick: this.markAllNotificationsAsRead }, translate('markAllAsRead', this.language))) : ('')),
124
+ h("div", { class: "NotificationList" }, !this.isLoading &&
125
+ (this.notifications.length > 0 ? (this.notifications.map((item) => {
126
+ var _a;
127
+ return (h("nuts-notification", { "client-styling": this.clientStyling, key: item.id, "user-id": this.userId, "operator-id": this.operatorId, content: item.content, "message-id": item.id, badge: ((_a = item.actor) === null || _a === void 0 ? void 0 : _a.data) || '', admin: this.admin, sessionId: this.sessionId, date: item.createdAt, read: item.read, seen: item.seen, language: this.language, "notification-action": this.notificationAction, token: this.token, "backend-url": this.backendUrl, "redirect-url": item.cta.data.url, "translation-url": this.translationUrl }));
128
+ })) : (h("div", { class: "NoMessages" },
129
+ h("svg", { width: "120", height: "108", viewBox: "0 0 120 108", fill: "none" },
130
+ h("circle", { cx: "11.3191", cy: "30.7872", r: "6.31915", stroke: "#3D3D4D", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
131
+ h("ellipse", { cx: "60.117", cy: "27.9787", rx: "5.96809", ry: "5.61702", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
132
+ h("path", { d: "M79.5424 49.4934C79.5424 44.1598 77.6437 39.0446 74.2641 35.2732C70.8844 31.5017 66.3006 29.3829 61.5211 29.3829C56.7415 29.3829 52.1578 31.5017 48.7781 35.2732C45.3985 39.0446 43.4998 44.1598 43.4998 49.4934C43.4998 72.9557 34.4892 79.6592 34.4892 79.6592H88.553C88.553 79.6592 79.5424 72.9557 79.5424 49.4934Z", fill: "#292933" }),
133
+ h("path", { d: "M68.8995 81.7552C68.1496 83.551 67.0731 85.0417 65.778 86.0779C64.4828 87.1141 63.0144 87.6595 61.5198 87.6595C60.0252 87.6595 58.5568 87.1141 57.2617 86.0779C55.9665 85.0417 54.8901 83.551 54.1401 81.7552", fill: "#292933" }),
134
+ h("path", { d: "M81.2976 50.2203C81.2976 68.2545 87.2222 76.7327 90.2814 79.9083C90.7671 80.4126 90.3802 81.4764 89.68 81.4764C88.0927 81.4764 86.5488 81.4764 85.0422 81.4764M68.5814 82.946C67.6854 84.8068 66.3993 86.3513 64.8518 87.425C63.3044 88.4987 61.5499 89.0638 59.7641 89.0638C57.9783 89.0638 56.2239 88.4987 54.6765 87.425C53.129 86.3513 51.8429 84.8068 50.9468 82.946M79.712 42.3723C78.6394 39.8192 77.0439 37.4727 74.991 35.4861C70.953 31.5783 65.4763 29.3829 59.7656 29.3829C54.055 29.3829 48.5783 31.5783 44.5403 35.4861C43.3681 36.6205 42.345 37.8722 41.4832 39.2127C40.4958 40.7487 39.7202 42.4013 39.1747 44.1276C38.5563 46.0847 38.2337 48.1364 38.2337 50.2203C38.2337 53.2503 38.0665 56.0106 37.7737 58.5212M34.8401 70.7608C32.9874 75.4551 30.7688 78.331 29.2526 79.9055C28.767 80.4099 29.155 81.4764 29.8551 81.4764C47.1962 81.4764 59.3571 81.4764 74.1593 81.4764", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
135
+ h("path", { d: "M55.6345 59.0737C55.1665 59.7144 54.4949 60.2462 53.6868 60.6159C52.8787 60.9855 51.9625 61.1801 51.0299 61.1801C50.0973 61.1801 49.1811 60.9855 48.373 60.6159C47.5649 60.2462 46.8933 59.7144 46.4254 59.0737", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
136
+ h("path", { d: "M73.1877 59.0737C72.7197 59.7144 72.0481 60.2462 71.24 60.6159C70.4319 60.9855 69.5157 61.1801 68.5831 61.1801C67.6506 61.1801 66.7344 60.9855 65.9263 60.6159C65.1182 60.2462 64.4465 59.7144 63.9786 59.0737", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
137
+ h("circle", { cx: "107.511", cy: "56.0638", r: "7.02128", stroke: "#3D3D4D", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
138
+ h("circle", { cx: "16.4252", cy: "58.1703", r: "4.21277", fill: "#3D3D4D" }),
139
+ h("ellipse", { cx: "59.9573", cy: "104.511", rx: "25.2766", ry: "2.80851", fill: "#3D3D4D" }),
140
+ h("path", { d: "M81.5317 18.1489H88.553L81.5317 25.1702H88.553", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" }),
141
+ h("path", { d: "M96.6807 2H106.51L96.6807 11.8298H106.51", stroke: "#828299", "stroke-width": "3.5", "stroke-linecap": "round", "stroke-linejoin": "round" })),
142
+ h("p", null, translate('noMessages', this.language)))))),
143
+ !this.isLoading &&
144
+ (this.notifications.length >= 10 || this.currentPage !== 0) ? (h("div", { class: "Pagination" },
145
+ h("div", { class: "Button" },
146
+ h("button", { disabled: this.currentPage <= 0, onClick: this.prevPage },
147
+ h("svg", { class: "svg-icon", viewBox: "0 0 20 20" },
148
+ h("path", { d: "M8.388,10.049l4.76-4.873c0.303-0.31,0.297-0.804-0.012-1.105c-0.309-0.304-0.803-0.293-1.105,0.012L6.726,9.516c-0.303,0.31-0.296,0.805,0.012,1.105l5.433,5.307c0.152,0.148,0.35,0.223,0.547,0.223c0.203,0,0.406-0.08,0.559-0.236c0.303-0.309,0.295-0.803-0.012-1.104L8.388,10.049z" })),
149
+ translate('prev', this.language))),
150
+ h("div", { class: "Button" },
151
+ h("button", { disabled: this.notifications.length < 10, onClick: this.nextPage },
152
+ translate('next', this.language),
153
+ h("svg", { class: "svg-icon", viewBox: "0 0 20 20" },
154
+ h("path", { d: "M11.611,10.049l-4.76-4.873c-0.303-0.31-0.297-0.804,0.012-1.105c0.309-0.304,0.803-0.293,1.105,0.012l5.306,5.433c0.304,0.31,0.296,0.805-0.012,1.105L7.83,15.928c-0.152,0.148-0.35,0.223-0.547,0.223c-0.203,0-0.406-0.08-0.559-0.236c-0.303-0.309-0.295-0.803,0.012-1.104L11.611,10.049z" })))))) : ('')));
128
155
  }
129
156
  static get is() { return "nuts-popover"; }
130
157
  static get originalStyleUrls() { return {
@@ -202,6 +229,40 @@ export class NutsPopover {
202
229
  "attribute": "token",
203
230
  "reflect": true
204
231
  },
232
+ "sessionId": {
233
+ "type": "string",
234
+ "mutable": false,
235
+ "complexType": {
236
+ "original": "string",
237
+ "resolved": "string",
238
+ "references": {}
239
+ },
240
+ "required": true,
241
+ "optional": false,
242
+ "docs": {
243
+ "tags": [],
244
+ "text": "The sessionID of the user"
245
+ },
246
+ "attribute": "session-id",
247
+ "reflect": true
248
+ },
249
+ "admin": {
250
+ "type": "boolean",
251
+ "mutable": false,
252
+ "complexType": {
253
+ "original": "boolean",
254
+ "resolved": "boolean",
255
+ "references": {}
256
+ },
257
+ "required": false,
258
+ "optional": true,
259
+ "docs": {
260
+ "tags": [],
261
+ "text": "Indicates if the associated sessionId is an admin or a player sessionId"
262
+ },
263
+ "attribute": "admin",
264
+ "reflect": true
265
+ },
205
266
  "backendUrl": {
206
267
  "type": "string",
207
268
  "mutable": false,