@kompasid/lit-web-components 0.8.11 → 0.8.13

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.
@@ -137,9 +137,25 @@ export class KompasHeaderNotification extends LitElement {
137
137
  @state() notificationContentData: any[] = []
138
138
  @state() isDataLoaded: boolean = false
139
139
 
140
+ /*
141
+ * property accessToken is the access token of the user
142
+ * property refreshToken is the refresh token of the user
143
+ * property domain is the domain of the API based on website
144
+ * property tracker_user_type is the type of user based on their subscription
145
+ * property tracker_subscription_status is the status of their subscription
146
+ * property tracker_page_domain is the page domain
147
+ * property tracker_metered_wall_type is the type of metered wall
148
+ * property tracker_metered_wall_balance is the balance of their metered wall
149
+ */
150
+
140
151
  @property({ type: String }) accessToken = ''
141
152
  @property({ type: String }) refreshToken = ''
142
153
  @property({ type: String }) domain = 'id' // 'id' | 'cloud'
154
+ @property({ type: String }) tracker_user_type = ''
155
+ @property({ type: String }) tracker_subscription_status = ''
156
+ @property({ type: String }) tracker_page_domain = ''
157
+ @property({ type: String }) tracker_metered_wall_type = ''
158
+ @property({ type: Number }) tracker_metered_wall_balance = 0
143
159
 
144
160
  constructor() {
145
161
  super()
@@ -166,7 +182,7 @@ export class KompasHeaderNotification extends LitElement {
166
182
  super.connectedCallback()
167
183
  this.isShowDropdown = false
168
184
 
169
- if (this.accessToken && this.refreshToken && this.domain)
185
+ if ((this.accessToken || this.refreshToken) && this.domain)
170
186
  await this.loadData()
171
187
  document.addEventListener('click', this.handleClickOutside)
172
188
  }
@@ -263,10 +279,8 @@ export class KompasHeaderNotification extends LitElement {
263
279
  this.notificationInfoData = (
264
280
  values[0] as ApiResponse<UserNotification>
265
281
  ).data
266
- this.notificationInfoData.notificationList = null
267
282
  this.notificationInfoData.notificationList =
268
283
  this.notificationInfoData.notificationList || []
269
-
270
284
  const rubrikData = (values[1] as ApiRubrikResponse<any>).result || []
271
285
  const ePaperData = (values[2] as ApiResponse<any>).data[0] || {}
272
286
 
@@ -299,6 +313,9 @@ export class KompasHeaderNotification extends LitElement {
299
313
 
300
314
  private toggleDropdown() {
301
315
  this.isShowDropdown = !this.isShowDropdown
316
+
317
+ // if opened, fire the datalayer
318
+ if (this.isShowDropdown) this.pushDataLayer('notification_opened')
302
319
  }
303
320
 
304
321
  private notificationIcon() {
@@ -328,7 +345,26 @@ export class KompasHeaderNotification extends LitElement {
328
345
  this.selectedTab = value
329
346
  }
330
347
 
331
- private redirectTo = async (notifId: string, link: string) => {
348
+ private handleNotificationUrlParam = (url: string, type: string) => {
349
+ const params = {
350
+ open_from: type,
351
+ }
352
+ const newUrl = new URL(decodeURIComponent(url))
353
+ if (newUrl.search) {
354
+ for (const [key, value] of Object.entries(params)) {
355
+ if (!newUrl.searchParams.has(key)) {
356
+ newUrl.searchParams.append(key, value)
357
+ }
358
+ }
359
+ } else {
360
+ newUrl.search = new URLSearchParams(params).toString()
361
+ }
362
+
363
+ return newUrl.toString()
364
+ }
365
+
366
+ private redirectTo = async (notifData: NotificationList) => {
367
+ const { notificationId: notifId, link, label } = notifData
332
368
  const res = await this.notifRead(notifId)
333
369
 
334
370
  if (res.status === 200) {
@@ -344,9 +380,9 @@ export class KompasHeaderNotification extends LitElement {
344
380
  }
345
381
  }
346
382
 
383
+ this.pushDataLayer('notification_clicked', 'Information', label)
347
384
  if (link) {
348
- const url = new URL(decodeURIComponent(link))
349
-
385
+ const url = this.handleNotificationUrlParam(link, 'Notification_Info')
350
386
  window.open(url, '_blank')
351
387
  }
352
388
  }
@@ -373,7 +409,7 @@ export class KompasHeaderNotification extends LitElement {
373
409
  return html`
374
410
  <div class="text-center px-4 pt-6 pb-18">
375
411
  <img
376
- src="../../assets/empty-state-notification.png"
412
+ src="https://cdn-www.kompas.id/assets/empty-state-notification.png"
377
413
  alt="empty-state-notification"
378
414
  class="w-auto mx-auto"
379
415
  />
@@ -392,7 +428,7 @@ export class KompasHeaderNotification extends LitElement {
392
428
  : `https://cdn-www.kompas.id/assets/langganan-anda-telah-berakhir.svg`
393
429
 
394
430
  return html`<div class="w-3/4 pr-1">
395
- <div class="flex items-center mb-1 text-xs">
431
+ <div class="flex items-center mb-1 text-xs font-bold">
396
432
  <span class="text-green-500 bg-green-100 rounded-sm p-1 px-2">
397
433
  ${item.label}
398
434
  </span>
@@ -417,7 +453,7 @@ export class KompasHeaderNotification extends LitElement {
417
453
  class="flex w-full text-left items-start p-4 cursor-pointer justify-between ${!item.isRead
418
454
  ? 'bg-blue-100'
419
455
  : ''}"
420
- @click=${() => this.redirectTo(item.notificationId, item.link)}
456
+ @click=${() => this.redirectTo(item)}
421
457
  >
422
458
  ${notificationInfoListTemplate(item)}
423
459
  </button> `
@@ -437,7 +473,7 @@ export class KompasHeaderNotification extends LitElement {
437
473
 
438
474
  private redirectToNotification(tab: string) {
439
475
  window.open(
440
- `https://account.kompas.id/manage-account/notification/${tab}`,
476
+ `https://account.kompas.${this.domain}/manage-account/notification/${tab}`,
441
477
  '_blank'
442
478
  )
443
479
  }
@@ -449,7 +485,7 @@ export class KompasHeaderNotification extends LitElement {
449
485
  return html`
450
486
  <div class="text-center px-4 pt-6 pb-18">
451
487
  <img
452
- src="../../assets/empty-state-notification.png"
488
+ src="https://cdn-www.kompas.id/assets/empty-state-notification.png"
453
489
  alt="empty-state-notification"
454
490
  class="w-auto mx-auto"
455
491
  />
@@ -464,7 +500,7 @@ export class KompasHeaderNotification extends LitElement {
464
500
  const notificationContentListTemplate = (item: any) => html`<div
465
501
  class="w-3/4 pr-1 "
466
502
  >
467
- <div class="flex items-center mb-1 text-xs">
503
+ <div class="flex items-center mb-1 text-xs font-bold">
468
504
  <span class="text-green-500 bg-green-100 rounded-sm p-1 px-2">
469
505
  ${item.category[0].name}
470
506
  </span>
@@ -472,9 +508,7 @@ export class KompasHeaderNotification extends LitElement {
472
508
  ${this.formatDate(item.publishedDateGmt)}</span
473
509
  >
474
510
  </div>
475
- <p class="font-bold text-base text-customTextColor py-1">
476
- ${item.title}
477
- </p>
511
+ <p class="font-bold text-sm text-customTextColor py-1">${item.title}</p>
478
512
  </div>
479
513
  <div class="w-1/4">
480
514
  <img
@@ -491,7 +525,16 @@ export class KompasHeaderNotification extends LitElement {
491
525
  class="flex w-full text-left items-start p-4 cursor-pointer justify-between ${!item.isRead
492
526
  ? 'bg-blue-100'
493
527
  : ''}"
494
- @click=${() => window.open(item.permalink, '_blank')}
528
+ @click=${() => {
529
+ this.pushDataLayer('notification_click', 'Content', 'Content')
530
+ window.open(
531
+ this.handleNotificationUrlParam(
532
+ item.permalink,
533
+ 'Notification_Content'
534
+ ),
535
+ '_blank'
536
+ )
537
+ }}
495
538
  >
496
539
  ${notificationContentListTemplate(item)}
497
540
  </button> `
@@ -521,17 +564,17 @@ export class KompasHeaderNotification extends LitElement {
521
564
  : ''}"
522
565
  >
523
566
  <div class="sticky">
524
- <div class="flex justify-center py-2 border-b border-grey-300">
567
+ <div class="flex justify-center py-4 border-b border-grey-300">
525
568
  <span class="font-bold text-base">Notifikasi</span>
526
569
  </div>
527
570
  <!-- Tabs for Info and Content -->
528
- <div class="flex justify-between">
571
+ <div class="flex justify-between text-grey-400">
529
572
  ${tab.map(
530
573
  item =>
531
574
  html`
532
575
  <button
533
- class="focus:outline-none py-2 w-1/2 ${this.selectedTab ===
534
- item && 'link-active'}"
576
+ class="focus:outline-none font-bold py-2 w-1/2 ${this
577
+ .selectedTab === item && 'link-active'}"
535
578
  @click=${() => this.handleClick(item)}
536
579
  >
537
580
  ${item}
@@ -549,6 +592,56 @@ export class KompasHeaderNotification extends LitElement {
549
592
  `
550
593
  }
551
594
 
595
+ private getParamsData(tab?: string, type?: string): any {
596
+ let notificationData = {}
597
+ let notifType = type
598
+
599
+ if (type && tab) {
600
+ if (type !== 'Content') {
601
+ switch (true) {
602
+ case /langganan/i.test(type):
603
+ notifType = 'Subscription'
604
+ break
605
+ case type === 'Akun':
606
+ notifType = 'Account'
607
+ break
608
+ case /bayar/i.test(type):
609
+ notifType = 'Payment'
610
+ break
611
+ default:
612
+ notifType = 'Information'
613
+ break
614
+ }
615
+ }
616
+
617
+ notificationData = {
618
+ notification_tab: tab,
619
+ notification_type: notifType,
620
+ }
621
+ }
622
+
623
+ const data = {
624
+ user_type: this.tracker_user_type,
625
+ subscription_status: this.tracker_subscription_status,
626
+ page_domain: this.tracker_page_domain || 'Kompas.id',
627
+ metered_wall_type: this.tracker_metered_wall_type || 'FP',
628
+ metered_wall_balance: this.tracker_metered_wall_balance,
629
+ }
630
+
631
+ return {
632
+ ...notificationData,
633
+ ...data,
634
+ }
635
+ }
636
+
637
+ private pushDataLayer(eventName: string, tab?: string, type?: string): void {
638
+ const data = this.getParamsData(tab, type)
639
+ window.dataLayer.push({
640
+ event: eventName,
641
+ ...data,
642
+ })
643
+ }
644
+
552
645
  render() {
553
646
  return html`<div id="headerNotification" class="relative">
554
647
  ${this.isDataLoaded
@@ -12,4 +12,15 @@ Ini adalah komponen _header notification_ yang akan di implementasi pada header
12
12
 
13
13
  ---
14
14
 
15
+ ## Usage
16
+
17
+ ```js
18
+ <kompasid-header-notification
19
+ :accessToken="accessToken" --> // token from cookies
20
+ :refreshToken="refreshToken" --> // refresh token from cookies
21
+ domain="cloud" --> // default id
22
+ style="margin-left: auto; margin-right:15px"
23
+ />
24
+ ```
25
+
15
26
  _Terbikin oleh tim front-end kompas.id_
@@ -1,7 +1,7 @@
1
1
  // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
2
 
3
3
  /** Use Hot Module replacement by adding --hmr to the start command */
4
- const hmr = process.argv.includes('--hmr');
4
+ const hmr = process.argv.includes('--hmr')
5
5
 
6
6
  export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
7
  open: '/demo/',
@@ -24,4 +24,5 @@ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
24
24
  ],
25
25
 
26
26
  // See documentation for all available options
27
- });
27
+ port: 3000,
28
+ })
Binary file