@kompasid/lit-web-components 0.9.31 → 0.9.32

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.
@@ -1,9 +1,8 @@
1
1
  import { LitElement, html, css } from 'lit'
2
- import { format, subDays, addDays } from 'date-fns'
2
+ import { format, addDays, differenceInDays } from 'date-fns'
3
3
  import { id } from 'date-fns/locale/id'
4
4
  import { customElement, property, state } from 'lit/decorators.js'
5
5
  import { TWStyles } from '../../../tailwind/tailwind.js'
6
- import { truncate } from '../../utils/text.js'
7
6
  import { User } from '../kompasid-header-account/types.js'
8
7
  import '../kompasid-grace-period/KompasGracePeriod.js'
9
8
 
@@ -81,7 +80,7 @@ export class KompasHeaderAccountProfile extends LitElement {
81
80
  * Subs Button Element
82
81
  */
83
82
  const subscribeButton = () => {
84
- if (!(this.userData as any)?.updateMembership) {
83
+ if (!(this.userData as any)?.isMembership) {
85
84
  return html``
86
85
  }
87
86
  const handleSubscribe = () => {
@@ -93,9 +92,9 @@ export class KompasHeaderAccountProfile extends LitElement {
93
92
  <div class="w-full">
94
93
  <button
95
94
  @click=${handleSubscribe}
96
- 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"
95
+ class="w-full rounded-lg px-4 py-3 mt-4 h-10 flex justify-center items-center bg-brand-1 text-grey-100 font-bold text-base focus:outline-none"
97
96
  >
98
- ${(this.userData as any)?.updateMembership}
97
+ Berlangganan Sekarang
99
98
  </button>
100
99
  </div>
101
100
  `
@@ -124,84 +123,133 @@ export class KompasHeaderAccountProfile extends LitElement {
124
123
  */
125
124
 
126
125
  const activeInfoTemplate = () => {
127
- const { isGracePeriod, totalGracePeriod, activeInfo, expired } =
128
- this.userData
126
+ const {
127
+ isGracePeriod,
128
+ totalGracePeriod,
129
+ isMembership,
130
+ activeInfo,
131
+ expired,
132
+ } = this.userData
133
+ let result = html``
134
+ let endGracePeriodDate = ''
129
135
 
130
- let startGracePeriodDate
131
- let endGracePeriodDate
136
+ const nowDate = new Date()
137
+ const isoDateString = expired.replace(' ', 'T')
138
+ const expiredDate = new Date(isoDateString)
139
+ const subsDaysLeft: number = differenceInDays(expiredDate, nowDate)
132
140
 
133
- if (isGracePeriod) {
134
- const totalGraceSubs = Math.max(totalGracePeriod - 1, 0)
135
- startGracePeriodDate = this.formatDate(
136
- subDays(new Date(), totalGraceSubs)
137
- )
138
- endGracePeriodDate = this.formatDate(
139
- addDays(new Date(), this.maxGracePeriod - totalGraceSubs)
140
- )
141
+ const gracePeriodCard = () => {
142
+ if (isGracePeriod) {
143
+ const totalGraceSubs = Math.max(totalGracePeriod - 1, 0)
144
+ endGracePeriodDate = this.formatDate(
145
+ addDays(new Date(), this.maxGracePeriod - totalGraceSubs)
146
+ )
147
+ }
148
+ const label = activeInfo ?? 'Periode Masa Tenggang'
149
+ return html`
150
+ <div class="text-orange-500 gracePeriodCard">
151
+ <span>${label}</span>
152
+ <p class="font-bold">hingga ${endGracePeriodDate}</p>
153
+ </div>
154
+ `
155
+ }
156
+
157
+ const lessThan3daysCard = () => {
158
+ const label = activeInfo ?? 'Aktif Berlangganan'
159
+ return html`
160
+ <div class="lessThan3daysCard">
161
+ <span> ${label} </span>
162
+ <p class="font-bold">Berakhir ${subsDaysLeft} hari lagi</p>
163
+ </div>
164
+ `
141
165
  }
142
166
 
143
- const expiredTextColor = isGracePeriod
144
- ? `text-orange-500`
145
- : `text-grey-600`
167
+ const moreThan3daysCard = () => {
168
+ const formattedExpired = this.formatDate(expired)
169
+ const label = activeInfo ?? 'Aktif Berlangganan'
170
+ return html`
171
+ <div class="moreThan3daysCard">
172
+ <span>${label}</span>
173
+ <p class="font-bold">hingga ${formattedExpired}</p>
174
+ </div>
175
+ `
176
+ }
177
+
178
+ const noSubsCard = () => {
179
+ const label = activeInfo ?? 'Tidak Berlangganan'
180
+ return html`
181
+ <div class="noSubsCard">
182
+ <span>${label}</span>
183
+ </div>
184
+ `
185
+ }
146
186
 
147
- const text = isGracePeriod
148
- ? html`<span> Periode Masa Tenggang </span>
149
- <p class="font-bold">
150
- ${startGracePeriodDate} - ${endGracePeriodDate}
151
- </p> `
152
- : html`<p>${activeInfo}</p>
153
- <p class="font-bold">${expired}</p>` || ''
187
+ if (isGracePeriod) {
188
+ result = gracePeriodCard()
189
+ } else if (subsDaysLeft > 0 && subsDaysLeft < 3) {
190
+ result = lessThan3daysCard()
191
+ } else if (subsDaysLeft >= 3) {
192
+ result = moreThan3daysCard()
193
+ } else if (!isMembership || subsDaysLeft < 1) {
194
+ result = noSubsCard()
195
+ }
154
196
 
155
- return html`<p class="text-sm ${expiredTextColor}">${text}</p>`
197
+ return html`<p class="text-sm text-grey-600 ${subsDaysLeft}-days-left">
198
+ ${result}
199
+ </p>`
156
200
  }
157
201
 
158
- return html`<div
159
- class="active-info flex flex-col items-start leading-none text-left font-sans"
160
- >
161
- <div class="flex flex-row items-center gap-4">
162
- <div
163
- class="flex bg-brand-1 flex-shrink-0 p-5 rounded-full h-16 w-16 items-center justify-center relative"
164
- >
165
- <span class="capitalize text-2xl text-grey-100 font-bold"
166
- >${this.userInitialName}</span
202
+ return html`
203
+ <div
204
+ class="active-info flex flex-col items-start leading-none text-left font-sans"
205
+ >
206
+ <div class="flex flex-row items-center gap-4">
207
+ <div
208
+ class="flex bg-brand-1 flex-shrink-0 p-5 rounded-full h-16 w-16 items-center justify-center relative"
167
209
  >
168
- ${membershipIcon()}
169
- </div>
210
+ <span class="capitalize text-2xl text-grey-100 font-bold">
211
+ ${this.userInitialName}
212
+ </span>
213
+ ${membershipIcon()}
214
+ </div>
170
215
 
171
- <div class="flex flex-col text-left">
172
- <p class="capitalize font-bold text-base text-blue-600">
173
- ${truncate(this.userData.userName, 25)}
174
- </p>
175
- ${activeInfoTemplate()}
216
+ <div class="flex flex-col text-left">
217
+ <p class="capitalize font-bold text-base text-blue-600">
218
+ ${this.userData.userName}
219
+ </p>
220
+ ${activeInfoTemplate()}
221
+ </div>
176
222
  </div>
177
- </div>
178
223
 
179
- ${this.userData?.isGracePeriod
180
- ? html`<div class="mt-4">
181
- <kompasid-grace-period
182
- totalGracePeriod=${this.userData.totalGracePeriod}
183
- isColumn="true"
184
- isShowButton="true"
185
- isBackgroundOnContentOnly="true"
186
- paywall_location=${this.paywall_location}
187
- paywall_subscription_package=${this.paywall_subscription_package}
188
- paywall_subscription_id=${this.paywall_subscription_id}
189
- paywall_subscription_price=${this.paywall_subscription_price}
190
- paywall_position=${this.paywall_position}
191
- tracker_page_type=${this.tracker_page_type}
192
- tracker_content_id=${this.tracker_content_id}
193
- tracker_content_title=${this.tracker_content_title}
194
- tracker_content_categories=${this.tracker_content_categories}
195
- tracker_content_type=${this.tracker_content_type}
196
- tracker_user_type=${this.tracker_user_type}
197
- tracker_subscription_status=${this.tracker_subscription_status}
198
- tracker_page_domain=${this.tracker_page_domain}
199
- tracker_metered_wall_type=${this.tracker_metered_wall_type}
200
- tracker_metered_wall_balance=${this.tracker_metered_wall_balance}
201
- ></kompasid-grace-period>
202
- </div>`
203
- : subscribeButton()}
204
- </div>`
224
+ ${this.userData?.isGracePeriod
225
+ ? html` <div class="mt-4 kompasid-grace-period">
226
+ <kompasid-grace-period
227
+ totalGracePeriod=${this.userData.totalGracePeriod}
228
+ isColumn="true"
229
+ isShowButton="true"
230
+ isBackgroundOnContentOnly="true"
231
+ paywall_location=${this.paywall_location}
232
+ paywall_subscription_package=${this
233
+ .paywall_subscription_package}
234
+ paywall_subscription_id=${this.paywall_subscription_id}
235
+ paywall_subscription_price=${this.paywall_subscription_price}
236
+ paywall_position=${this.paywall_position}
237
+ tracker_page_type=${this.tracker_page_type}
238
+ tracker_content_id=${this.tracker_content_id}
239
+ tracker_content_title=${this.tracker_content_title}
240
+ tracker_content_categories=${this.tracker_content_categories}
241
+ tracker_content_type=${this.tracker_content_type}
242
+ tracker_user_type=${this.tracker_user_type}
243
+ tracker_subscription_status=${this.tracker_subscription_status}
244
+ tracker_page_domain=${this.tracker_page_domain}
245
+ tracker_metered_wall_type=${this.tracker_metered_wall_type}
246
+ tracker_metered_wall_balance=${this
247
+ .tracker_metered_wall_balance}
248
+ ></kompasid-grace-period>
249
+ </div>`
250
+ : subscribeButton()}
251
+ </div>
252
+ `
205
253
  }
206
254
 
207
255
  override async connectedCallback() {
@@ -210,11 +258,12 @@ export class KompasHeaderAccountProfile extends LitElement {
210
258
 
211
259
  render() {
212
260
  return html`
213
- <div class="flex flex-shrink-0 flex-col bg-blue-100 p-4">
261
+ <div class="flex flex-shrink-0 flex-col p-4">
214
262
  ${!this.userData
215
263
  ? this.renderSkeletonLoading()
216
264
  : this.renderProfileContent()}
217
265
  </div>
266
+ <hr class="border-grey-300 mx-4" />
218
267
  `
219
268
  }
220
269
  }
@@ -637,7 +637,7 @@ export class KompasIdPaywallBody extends LitElement {
637
637
  >
638
638
  ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
639
639
  </button>`
640
- } else if (type === 'proMiningArticle' && isPrevHistoryExist) {
640
+ } else if (type === 'proMiningOutlook' && isPrevHistoryExist) {
641
641
  buttonContent = html` <button
642
642
  @click=${this.redirectToPrevUrl}
643
643
  class="hidden md:block w-8 h-8 pl-4 ${textColorClass}"