@kompasid/lit-web-components 0.7.9 → 0.8.1

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 (23) hide show
  1. package/demo/index.html +37 -1
  2. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.d.ts +8 -1
  3. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js +95 -33
  4. package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js.map +1 -1
  5. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.d.ts +18 -0
  6. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js +78 -0
  7. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js.map +1 -1
  8. package/dist/src/components/kompasid-header-account/types.d.ts +2 -0
  9. package/dist/src/components/kompasid-header-account/types.js.map +1 -1
  10. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.d.ts +29 -2
  11. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js +115 -57
  12. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js.map +1 -1
  13. package/dist/tailwind/tailwind.js +151 -171
  14. package/dist/tailwind/tailwind.js.map +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/package.json +1 -1
  17. package/src/components/kompasid-grace-period/KompasGracePeriod.ts +93 -31
  18. package/src/components/kompasid-grace-period/readme.md +2 -0
  19. package/src/components/kompasid-header-account/KompasHeaderAccount.ts +34 -0
  20. package/src/components/kompasid-header-account/types.ts +2 -0
  21. package/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.ts +84 -56
  22. package/tailwind/tailwind.css +38 -99
  23. package/tailwind/tailwind.ts +151 -171
@@ -28,6 +28,7 @@ export class KompasGracePeriod extends LitElement {
28
28
  * property totalGracePeriod = how many days are left in grace period
29
29
  * property isColumn = changes how the component looks on different screen sizes
30
30
  * property isShowButton = shows or hides a subscription button
31
+ * property isEpaper = is paywall opened in epaper page
31
32
  * property paywall_location = the location where user encounter the paywall
32
33
  * property paywall_subscription_package = the name of the subscription package viewed by user
33
34
  * property paywall_subscription_id = the ID of the subscription package viewed by user
@@ -43,11 +44,14 @@ export class KompasGracePeriod extends LitElement {
43
44
  * property tracker_page_domain = page Domain
44
45
  * property tracker_metered_wall_type = the type of Metered Wall
45
46
  * property tracker_metered_wall_balance = the balance of their metered wall
47
+ * property tracker_epaper_edition = the edition of epaper viewed by user
46
48
  */
47
49
 
48
50
  @property({ type: Number }) totalGracePeriod = 0
49
51
  @property({ type: Boolean }) isColumn = false
50
52
  @property({ type: Boolean }) isShowButton = false
53
+ @property({ type: Boolean }) isEpaper = false
54
+ @property({ type: Boolean }) isBackgroundOnContentOnly = false
51
55
  @property({ type: String }) paywall_location = ''
52
56
  @property({ type: String }) paywall_subscription_package = ''
53
57
  @property({ type: Number }) paywall_subscription_id = 0
@@ -63,12 +67,14 @@ export class KompasGracePeriod extends LitElement {
63
67
  @property({ type: String }) tracker_page_domain = ''
64
68
  @property({ type: String }) tracker_metered_wall_type = ''
65
69
  @property({ type: Number }) tracker_metered_wall_balance = 0
70
+ @property({ type: String }) tracker_epaper_edition = ''
66
71
 
67
72
  /**
68
73
  * State
69
74
  */
70
75
  @state() private maxGracePeriod = 7
71
- @state() private updateSubscription = 'https://checkoutv2.kompas.id'
76
+ @state() private subscriptionPage = 'https://www.kompas.id/berlangganan'
77
+ @state() private checkoutPage = 'https://checkoutv2.kompas.id'
72
78
 
73
79
  private getCountdownGracePeriod() {
74
80
  const { totalGracePeriod } = this
@@ -94,47 +100,72 @@ export class KompasGracePeriod extends LitElement {
94
100
  }
95
101
 
96
102
  private redirectToBerlangganan(): void {
103
+ this.dataLayeronPerbaruiLanggananButton()
104
+ this.sendGtmEvent('subscribe_button_clicked', true)
105
+
106
+ window.open(this.subscriptionPage)
107
+ }
108
+
109
+ private redirectToCheckout(): void {
97
110
  this.dataLayeronPerbaruiLanggananButton()
98
111
  const originHost: string = encodeURIComponent(window.location.href)
99
112
 
100
113
  this.sendGtmEvent('subscribe_button_clicked')
101
114
 
102
115
  window.open(
103
- `${this.updateSubscription}/kdp?productId=${this.paywall_subscription_id}&referrer=${originHost}&source=article`
116
+ `${this.checkoutPage}/kdp?productId=${this.paywall_subscription_id}&referrer=${originHost}&source=article`,
104
117
  )
105
118
  }
106
119
 
107
- private getGtmParams(): Record<string, any> {
108
- return {
109
- paywall_location: this.paywall_location,
110
- paywall_subscription_package: this.paywall_subscription_package,
111
- paywall_subscription_id: this.paywall_subscription_id,
112
- paywall_subscription_price: this.paywall_subscription_price,
113
- paywall_position: this.paywall_position,
114
- page_type: this.tracker_page_type,
115
- content_id: this.tracker_content_id,
116
- content_title: this.tracker_content_title,
117
- content_categories: this.tracker_content_categories,
118
- content_type: this.tracker_content_type,
119
- user_type: this.tracker_user_type,
120
- subscription_status: this.tracker_subscription_status,
121
- page_domain: this.tracker_page_domain || 'Kompas.id',
122
- metered_wall_type: this.tracker_metered_wall_type || 'GP',
123
- metered_wall_balance: this.tracker_metered_wall_balance,
120
+ private getGtmParams(
121
+ excludeSubscriptionParams: boolean = false,
122
+ ): Record<string, any> {
123
+ const gtmParams: Record<string, any> = {}
124
+
125
+ if (!this.isEpaper) {
126
+ gtmParams.content_title = this.tracker_content_title
127
+ gtmParams.content_id = this.tracker_content_id
128
+ gtmParams.content_categories = this.tracker_content_categories
129
+ gtmParams.content_type = this.tracker_content_type
130
+ gtmParams.page_type = this.tracker_page_type
131
+ } else {
132
+ gtmParams.epaper_edition = this.tracker_epaper_edition
124
133
  }
134
+
135
+ if (!excludeSubscriptionParams) {
136
+ gtmParams.paywall_subscription_package = this.paywall_subscription_package
137
+ gtmParams.paywall_subscription_id = this.paywall_subscription_id
138
+ gtmParams.paywall_subscription_price = this.paywall_subscription_price
139
+ }
140
+
141
+ gtmParams.paywall_location = this.paywall_location
142
+ gtmParams.paywall_position = this.paywall_position
143
+ gtmParams.user_type = this.tracker_user_type
144
+ gtmParams.subscription_status = this.tracker_subscription_status
145
+ gtmParams.page_domain = this.tracker_page_domain || 'Kompas.id'
146
+ gtmParams.metered_wall_type = this.tracker_metered_wall_type || 'GP'
147
+ gtmParams.metered_wall_balance = this.tracker_metered_wall_balance
148
+
149
+ return gtmParams
125
150
  }
126
151
 
127
- private sendGtmEvent(event: string) {
152
+ private sendGtmEvent(
153
+ event: string,
154
+ excludeSubscriptionParams: boolean = false,
155
+ ) {
128
156
  let gtmParams: Record<string, any> = { event }
129
157
 
130
158
  if (event === 'paywall_viewed') {
131
159
  gtmParams.impressions = [
132
160
  {
133
- ...this.getGtmParams(),
161
+ ...this.getGtmParams(excludeSubscriptionParams),
134
162
  },
135
163
  ]
136
164
  } else {
137
- gtmParams = { ...gtmParams, ...this.getGtmParams() }
165
+ gtmParams = {
166
+ ...gtmParams,
167
+ ...this.getGtmParams(excludeSubscriptionParams),
168
+ }
138
169
  }
139
170
 
140
171
  window.dataLayer.push(gtmParams)
@@ -159,26 +190,56 @@ export class KompasGracePeriod extends LitElement {
159
190
  }
160
191
 
161
192
  private gracePeriodTemplate() {
193
+ const { isColumn, isBackgroundOnContentOnly } = this
194
+
195
+ const wrapperColumnClass = isColumn
196
+ ? 'rounded-lg'
197
+ : 'md:flex-row lg:px-8 md:space-x-4 px-4 py-4'
198
+ const buttonColumnClass = isColumn
199
+ ? ''
200
+ : 'md:w-1/2 justify-end md:flex-row pt-4 md:pt-0'
201
+ const otherBtnColumnClass = isColumn ? '' : 'md:w-auto'
202
+ const wrapperBgClass = !isBackgroundOnContentOnly ? 'p-4' : ''
203
+ const contentBgClass = isBackgroundOnContentOnly
204
+ ? 'bg-orange-100 p-4 rounded-lg mb-4'
205
+ : ''
206
+
162
207
  return html`
163
208
  <div
164
- class="${this.isColumn
165
- ? 'rounded-lg'
166
- : 'md:flex-row lg:px-8'} flex flex-col w-full justify-end py-4 md:space-x-4 px-4 bottom-0 max-w-7xl mx-auto"
209
+ class="bottom-0 mx-auto flex w-full max-w-7xl flex-col justify-end ${wrapperColumnClass} ${wrapperBgClass}"
167
210
  >
168
- <div class="text-grey-600 text-sm md:text-base self-center text-left">
211
+ <div
212
+ class="self-center text-left text-sm text-grey-600 md:text-base ${contentBgClass}"
213
+ >
169
214
  ${this.getCountdownGracePeriod()}
170
215
  </div>
171
- ${!this.isShowButton
216
+ ${this.isShowButton
172
217
  ? html`
173
218
  <div
174
- class="flex self-center w-full md:w-1/2 justify-end pt-4 md:pt-0"
219
+ class="flex w-full flex-col gap-4 self-center ${buttonColumnClass}"
175
220
  >
176
221
  <button
177
- @click=${this.redirectToBerlangganan}
178
- class="bg-green-500 p-2 px-5 rounded-md font-bold text-grey-100 text-sm md:text-base w-full md:w-auto"
222
+ @click=${this.redirectToCheckout}
223
+ class="w-full rounded-md bg-green-500 p-2 px-5 text-sm font-bold text-grey-100 md:w-auto md:text-base"
179
224
  >
180
225
  Perbarui Langganan
181
226
  </button>
227
+ <div class="md:block hidden">
228
+ <button
229
+ @click=${this.redirectToBerlangganan}
230
+ class="bg-transparent w-full rounded-md border border-green-500 p-1.5 px-5 text-sm font-bold text-green-500 md:text-base ${otherBtnColumnClass}"
231
+ >
232
+ Paket Lainnya
233
+ </button>
234
+ </div>
235
+ <div class="md:hidden block">
236
+ <button
237
+ @click=${this.redirectToBerlangganan}
238
+ class="bg-transparent w-full rounded-md border border-green-500 p-1.5 px-5 text-sm font-bold text-green-500 md:text-base ${otherBtnColumnClass}"
239
+ >
240
+ Lihat Paket Lainnya
241
+ </button>
242
+ </div>
182
243
  </div>
183
244
  `
184
245
  : nothing}
@@ -195,8 +256,9 @@ export class KompasGracePeriod extends LitElement {
195
256
  }
196
257
 
197
258
  render() {
259
+ const bgClass = !this.isBackgroundOnContentOnly ? 'bg-orange-100' : ''
198
260
  return html`
199
- <div class="sticky bottom-0 w-full h-full bg-orange-100">
261
+ <div class="sticky bottom-0 h-full w-full ${bgClass}">
200
262
  ${this.totalGracePeriod > 0 ? this.gracePeriodTemplate() : nothing}
201
263
  </div>
202
264
  `
@@ -8,6 +8,7 @@ Ini adalah redesign komponen _grace period_ yang digunakan pada [kompas.id](http
8
8
  | ------------------------------ | ------------------------------ | ----------- | ------------------------| ----------- |
9
9
  | `totalGracePeriod` | `total-grace-period` | | `number` | `0` |
10
10
  | `isColumn` | `is-column` | | `boolean` | `false` |
11
+ | `isEpaper` | `is-epaper` | | `boolean` | `false` |
11
12
  | `isShowButton` | `is-show-button` | | `boolean` | `false` |
12
13
  | `subscriptionId` | `subscription-id` | | `string` | `false` |
13
14
  | `paywall_location` | `paywall_location` | | `string` | `''` |
@@ -25,6 +26,7 @@ Ini adalah redesign komponen _grace period_ yang digunakan pada [kompas.id](http
25
26
  | `tracker_page_type` | `tracker_page_type` | | `string` | `''` |
26
27
  | `tracker_subscription_status` | `tracker_subscription_status` | | `string` | `''` |
27
28
  | `tracker_user_type` | `tracker_user_type` | | `string` | `''` |
29
+ | `tracker_epaper_edition` | `tracker_epaper_edition` | | `string` | `''` |
28
30
 
29
31
  ----------------------------------------------
30
32
 
@@ -108,6 +108,25 @@ export class KompasHeaderAccount extends LitElement {
108
108
  @property({ type: String }) subscriptionUrl = ''
109
109
  @property({ type: Number }) totalGracePeriod = 0
110
110
 
111
+ /**
112
+ * Props For Grace Period Tracker
113
+ */
114
+ @property({ type: String }) paywall_location = ''
115
+ @property({ type: String }) paywall_subscription_package = ''
116
+ @property({ type: Number }) paywall_subscription_id = 0
117
+ @property({ type: Number }) paywall_subscription_price = 0
118
+ @property({ type: Number }) paywall_position = 0
119
+ @property({ type: String }) tracker_page_type = ''
120
+ @property({ type: String }) tracker_content_id = ''
121
+ @property({ type: String }) tracker_content_title = ''
122
+ @property({ type: String }) tracker_content_categories = ''
123
+ @property({ type: String }) tracker_content_type = ''
124
+ @property({ type: String }) tracker_user_type = ''
125
+ @property({ type: String }) tracker_subscription_status = ''
126
+ @property({ type: String }) tracker_page_domain = ''
127
+ @property({ type: String }) tracker_metered_wall_type = ''
128
+ @property({ type: Number }) tracker_metered_wall_balance = 0
129
+
111
130
  private toggleSidebar() {
112
131
  this.isShowSidebar = !this.isShowSidebar
113
132
  }
@@ -184,6 +203,21 @@ export class KompasHeaderAccount extends LitElement {
184
203
  .userData=${this.formattedUserData}
185
204
  .subscriptionUrl=${this.subscriptionUrl}
186
205
  .totalGracePeriod=${this.totalGracePeriod}
206
+ paywall_location=${this.paywall_location}
207
+ paywall_subscription_package=${this.paywall_subscription_package}
208
+ paywall_subscription_id=${this.paywall_subscription_id}
209
+ paywall_subscription_price=${this.paywall_subscription_price}
210
+ paywall_position=${this.paywall_position}
211
+ tracker_page_type=${this.tracker_page_type}
212
+ tracker_content_id=${this.tracker_content_id}
213
+ tracker_content_title=${this.tracker_content_title}
214
+ tracker_content_categories=${this.tracker_content_categories}
215
+ tracker_content_type=${this.tracker_content_type}
216
+ tracker_user_type=${this.tracker_user_type}
217
+ tracker_subscription_status=${this.tracker_subscription_status}
218
+ tracker_page_domain=${this.tracker_page_domain}
219
+ tracker_metered_wall_type=${this.tracker_metered_wall_type}
220
+ tracker_metered_wall_balance=${this.tracker_metered_wall_balance}
187
221
  ></kompasid-header-account-profile>
188
222
  <div class="pl-4 pr-3 py-4 text-left">
189
223
  <kompasid-header-account-menu
@@ -2,6 +2,8 @@ export interface User {
2
2
  userName: string
3
3
  expired: string
4
4
  isNearExpired: boolean
5
+ totalGracePeriod: number
6
+ isGracePeriod: boolean
5
7
  activeInfo: string
6
8
  isMembership: boolean
7
9
  updateMembership: string
@@ -1,7 +1,11 @@
1
1
  import { LitElement, html, css } from 'lit'
2
- import { customElement, property } from 'lit/decorators.js'
2
+ import { format, subDays, addDays } from 'date-fns'
3
+ import { id } from 'date-fns/locale/id'
4
+ import { customElement, property, state } from 'lit/decorators.js'
3
5
  import { TWStyles } from '../../../tailwind/tailwind.js'
4
6
  import { truncate } from '../../utils/text.js'
7
+ import { User } from '../kompasid-header-account/types.js'
8
+ import '../kompasid-grace-period/KompasGracePeriod.js'
5
9
 
6
10
  @customElement('kompasid-header-account-profile')
7
11
  export class KompasHeaderAccountProfile extends LitElement {
@@ -16,11 +20,41 @@ export class KompasHeaderAccountProfile extends LitElement {
16
20
  TWStyles,
17
21
  ]
18
22
 
23
+ /**
24
+ * Props
25
+ */
19
26
  @property({ type: String }) userInitialName = ''
20
- @property({ type: Object }) userData = {}
21
- @property({ type: String }) subscriptionUrl = ''
27
+ @property({ type: Object }) userData = {} as User
22
28
  @property({ type: Number }) totalGracePeriod = 0
23
29
 
30
+ /**
31
+ * Props For Grace Period Tracker
32
+ */
33
+ @property({ type: String }) paywall_location = ''
34
+ @property({ type: String }) paywall_subscription_package = ''
35
+ @property({ type: Number }) paywall_subscription_id = 0
36
+ @property({ type: Number }) paywall_subscription_price = 0
37
+ @property({ type: Number }) paywall_position = 0
38
+ @property({ type: String }) tracker_page_type = ''
39
+ @property({ type: String }) tracker_content_id = ''
40
+ @property({ type: String }) tracker_content_title = ''
41
+ @property({ type: String }) tracker_content_categories = ''
42
+ @property({ type: String }) tracker_content_type = ''
43
+ @property({ type: String }) tracker_user_type = ''
44
+ @property({ type: String }) tracker_subscription_status = ''
45
+ @property({ type: String }) tracker_page_domain = ''
46
+ @property({ type: String }) tracker_metered_wall_type = ''
47
+ @property({ type: Number }) tracker_metered_wall_balance = 0
48
+
49
+ /**
50
+ * State
51
+ */
52
+ @state() private maxGracePeriod = 7
53
+
54
+ formatDate(date: Date | string) {
55
+ return format(new Date(date), 'dd MMM yyyy', { locale: id })
56
+ }
57
+
24
58
  private renderSkeletonLoading() {
25
59
  return html`
26
60
  <div>
@@ -42,47 +76,11 @@ export class KompasHeaderAccountProfile extends LitElement {
42
76
  }
43
77
 
44
78
  private renderProfileContent() {
45
- /**
46
- * Expired Button Element
47
- */
48
- const subscribeButton = () => {
49
- if (!(this.userData as any)?.updateMembership) {
50
- return html``
51
- }
52
- const handleSubscribe = () => {
53
- window.location.href = this.subscriptionUrl
54
- }
55
-
56
- return html`
57
- <div class="w-full">
58
- <button
59
- onClick=${handleSubscribe}
60
- class="w-full rounded-lg px-4 py-3 mt-4 h-10 flex justify-center items-center bg-green-500 text-grey-100 font-bold text-base focus:outline-none"
61
- >
62
- ${(this.userData as any)?.updateMembership}
63
- </button>
64
- </div>
65
- `
66
- }
67
- /**
68
- * expired Info Element
69
- */
70
- const expiredInfo = () => {
71
- const isNearExpired = (this.userData as any)?.isNearExpired
72
- const expiredTextColor = isNearExpired
73
- ? `text-orange-400`
74
- : `text-grey-600`
75
-
76
- return html`<p class="${expiredTextColor} font-bold">
77
- ${(this.userData as any)?.expired}
78
- </p>`
79
- }
80
-
81
79
  /**
82
80
  * membership icon element, show if isMebership has truthy value
83
81
  */
84
82
  const membershipIcon = () => {
85
- if (!(this.userData as any)?.isMembership) {
83
+ if (!this.userData?.isMembership) {
86
84
  return html``
87
85
  }
88
86
 
@@ -101,15 +99,31 @@ export class KompasHeaderAccountProfile extends LitElement {
101
99
  * Active Info Element
102
100
  */
103
101
 
104
- const activeInfo = () => {
105
- const isNearExpired = (this.userData as any)?.isNearExpired
106
- const expiredTextColor = isNearExpired
107
- ? `text-orange-400`
102
+ const activeInfoTemplate = () => {
103
+ const { isGracePeriod, totalGracePeriod, activeInfo } = this.userData
104
+
105
+ const expiredTextColor = isGracePeriod
106
+ ? `text-orange-500`
108
107
  : `text-grey-600`
109
108
 
110
- return html`<p class="capitalize text-sm ${expiredTextColor}">
111
- ${(this.userData as any)?.activeInfo}
112
- </p>`
109
+ const startGracePeriodDate = this.formatDate(
110
+ subDays(new Date().toLocaleDateString(), totalGracePeriod - 1)
111
+ )
112
+ const endGracePeriodDate = this.formatDate(
113
+ addDays(
114
+ new Date().toLocaleDateString(),
115
+ this.maxGracePeriod - totalGracePeriod
116
+ )
117
+ )
118
+
119
+ const text = isGracePeriod
120
+ ? html`<span> Periode Masa Tenggang </span>
121
+ <p class="font-bold">
122
+ ${startGracePeriodDate} - ${endGracePeriodDate}
123
+ </p> `
124
+ : activeInfo || ''
125
+
126
+ return html`<p class="capitalize text-sm ${expiredTextColor}">${text}</p>`
113
127
  }
114
128
 
115
129
  return html`<div
@@ -127,21 +141,35 @@ export class KompasHeaderAccountProfile extends LitElement {
127
141
 
128
142
  <div class="flex flex-col text-left">
129
143
  <p class="capitalize font-bold text-base text-blue-600">
130
- ${truncate((this.userData as any)?.userName, 25)}
144
+ ${truncate(this.userData.userName, 25)}
131
145
  </p>
132
- ${activeInfo()} ${expiredInfo()}
146
+ ${activeInfoTemplate()}
133
147
  </div>
134
148
  </div>
135
149
 
136
150
  <div class="mt-4">
137
- <!-- <kompas-grace-period
138
- totalGracePeriod="{this.totalGracePeriod}"
139
- isColoumn="{true}"
140
- isShowButton="{true}"
141
- /> -->
151
+ <kompasid-grace-period
152
+ totalGracePeriod=${this.userData.totalGracePeriod}
153
+ isColumn="true"
154
+ isShowButton="true"
155
+ isBackgroundOnContentOnly="true"
156
+ paywall_location=${this.paywall_location}
157
+ paywall_subscription_package=${this.paywall_subscription_package}
158
+ paywall_subscription_id=${this.paywall_subscription_id}
159
+ paywall_subscription_price=${this.paywall_subscription_price}
160
+ paywall_position=${this.paywall_position}
161
+ tracker_page_type=${this.tracker_page_type}
162
+ tracker_content_id=${this.tracker_content_id}
163
+ tracker_content_title=${this.tracker_content_title}
164
+ tracker_content_categories=${this.tracker_content_categories}
165
+ tracker_content_type=${this.tracker_content_type}
166
+ tracker_user_type=${this.tracker_user_type}
167
+ tracker_subscription_status=${this.tracker_subscription_status}
168
+ tracker_page_domain=${this.tracker_page_domain}
169
+ tracker_metered_wall_type=${this.tracker_metered_wall_type}
170
+ tracker_metered_wall_balance=${this.tracker_metered_wall_balance}
171
+ ></kompasid-grace-period>
142
172
  </div>
143
-
144
- ${subscribeButton()}
145
173
  </div>`
146
174
  }
147
175