@coras-io/embed 0.8.3 → 0.10.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.
- package/CHANGELOG.md +20 -0
- package/dist/components/attraction-card/long/attraction-long-card.styles.js +14 -4
- package/dist/components/attraction-card/short/attraction-short-card.styles.js +3 -1
- package/dist/components/locations-results/locations-results.component.d.ts +3 -0
- package/dist/components/locations-results/locations-results.component.js +16 -2
- package/dist/components/loyalty-badge/loyalty-badge.component.d.ts +34 -0
- package/dist/components/loyalty-badge/loyalty-badge.component.js +141 -0
- package/dist/components/loyalty-badge/loyalty-badge.d.ts +8 -0
- package/dist/components/loyalty-badge/loyalty-badge.js +6 -0
- package/dist/components/loyalty-badge/loyalty-badge.styles.js +61 -0
- package/dist/components/loyalty-badge/loyalty-badge.types.d.ts +6 -0
- package/dist/components/loyalty-badge/loyalty-badge.utils.d.ts +23 -0
- package/dist/components/loyalty-badge/loyalty-badge.utils.js +30 -0
- package/dist/containers/basket/basket.component.d.ts +2 -1
- package/dist/containers/basket/basket.component.js +17 -44
- package/dist/containers/navbar/navbar.styles.js +4 -2
- package/dist/contexts/properties.context.d.ts +8 -0
- package/dist/contexts/properties.context.js +5 -0
- package/dist/core/events.d.ts +1 -0
- package/dist/core/types/api-schema.d.ts +183 -5
- package/dist/core/types/core/index.d.ts +0 -1
- package/dist/core/types/index.d.ts +0 -1
- package/dist/core/utils/loyalty.d.ts +37 -4
- package/dist/core/utils/loyalty.js +14 -5
- package/dist/core/utils/seats.d.ts +6 -0
- package/dist/core/utils/seats.js +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/locales/ar-SA.d.ts +5 -0
- package/dist/locales/ar-SA.js +5 -0
- package/dist/locales/da-DK.d.ts +5 -0
- package/dist/locales/da-DK.js +5 -0
- package/dist/locales/de-DE.d.ts +5 -0
- package/dist/locales/de-DE.js +5 -0
- package/dist/locales/en-IE.d.ts +5 -0
- package/dist/locales/en-IE.js +5 -0
- package/dist/locales/en-US.d.ts +5 -0
- package/dist/locales/en-US.js +5 -0
- package/dist/locales/es-ES.d.ts +5 -0
- package/dist/locales/es-ES.js +5 -0
- package/dist/locales/fr-FR.d.ts +5 -0
- package/dist/locales/fr-FR.js +5 -0
- package/dist/locales/fr-MA.d.ts +5 -0
- package/dist/locales/fr-MA.js +5 -0
- package/dist/locales/is-IS.d.ts +5 -0
- package/dist/locales/is-IS.js +5 -0
- package/dist/locales/it-IT.d.ts +5 -0
- package/dist/locales/it-IT.js +5 -0
- package/dist/locales/ms-MY.d.ts +5 -0
- package/dist/locales/ms-MY.js +5 -0
- package/dist/locales/nb-NO.d.ts +5 -0
- package/dist/locales/nb-NO.js +5 -0
- package/dist/locales/pl-PL.d.ts +5 -0
- package/dist/locales/pl-PL.js +5 -0
- package/dist/locales/pt-PT.d.ts +5 -0
- package/dist/locales/pt-PT.js +5 -0
- package/dist/locales/sv-SE.d.ts +5 -0
- package/dist/locales/sv-SE.js +5 -0
- package/dist/locales/th-TH.d.ts +5 -0
- package/dist/locales/th-TH.js +5 -0
- package/dist/locales/tr-TR.d.ts +5 -0
- package/dist/locales/tr-TR.js +5 -0
- package/dist/locales/zh-CN.d.ts +5 -0
- package/dist/locales/zh-CN.js +5 -0
- package/dist/locales/zh-HK.d.ts +5 -0
- package/dist/locales/zh-HK.js +5 -0
- package/dist/mixins/base.mixin.d.ts +2 -0
- package/dist/mixins/base.mixin.js +8 -1
- package/dist/mixins/location-search/location-search.js +88 -13
- package/dist/sdk/page-registry.js +2 -0
- package/dist/sdk/theme.d.ts +1 -1
- package/dist/sdk/types.d.ts +9 -1
- package/dist/sdk/validation.js +51 -0
- package/dist/styles/tokens.d.ts +1 -1
- package/dist/styles/tokens.generated.d.ts +1 -1
- package/dist/styles/tokens.generated.js +1 -1
- package/dist/styles/tokens.metadata.js +18 -0
- package/dist/views/chrome-only-page/chrome-only-page.component.d.ts +1 -0
- package/dist/views/details-page/details-page.component.d.ts +2 -1
- package/dist/views/details-page/details-page.component.js +15 -5
- package/dist/views/details-page/partials/location-highlights/location-highlights.component.d.ts +2 -0
- package/dist/views/details-page/partials/location-highlights/location-highlights.component.js +16 -2
- package/dist/views/help-page/help-page.component.d.ts +1 -0
- package/dist/views/landing-page/landing-page.component.d.ts +2 -3
- package/dist/views/landing-page/landing-page.component.js +10 -18
- package/dist/views/payment-page/controllers/form-validation.controller.d.ts +4 -1
- package/dist/views/payment-page/controllers/form-validation.controller.js +7 -2
- package/dist/views/payment-page/partials/confirmation/confirmation.component.js +49 -27
- package/dist/views/payment-page/payment-page.component.d.ts +6 -0
- package/dist/views/payment-page/payment-page.component.js +76 -8
- package/dist/views/payment-page/payment-page.loyalty.d.ts +13 -0
- package/dist/views/payment-page/payment-page.loyalty.js +80 -0
- package/dist/views/payment-page/payment-page.styles.js +16 -0
- package/dist/views/payment-page/payment-page.utils.d.ts +1 -1
- package/dist/views/payment-page/payment-page.utils.js +19 -1
- package/dist/views/payment-page/services/payment-api.service.d.ts +1 -0
- package/dist/views/search-page/search-page.component.d.ts +1 -0
- package/dist/views/search-page/search-page.component.js +9 -0
- package/dist/views/suggestion-widget/suggestion-widget.component.d.ts +1 -0
- package/dist/views/suggestion-widget/suggestion-widget.component.js +11 -1
- package/package.json +5 -5
- package/dist/components/points/points.component.d.ts +0 -9
- package/dist/components/points/points.component.js +0 -36
- package/dist/components/points/points.d.ts +0 -8
- package/dist/components/points/points.js +0 -6
- package/dist/components/points/points.styles.js +0 -47
- package/dist/core/types/core/points.d.ts +0 -4
- package/dist/mixins/points/points.d.ts +0 -3
- package/dist/mixins/points/points.js +0 -30
- package/dist/mixins/points/types.d.ts +0 -8
- package/dist/mixins/points/types.js +0 -1
- /package/dist/components/{points/points.styles.d.ts → loyalty-badge/loyalty-badge.styles.d.ts} +0 -0
- /package/dist/{core/types/core/points.js → components/loyalty-badge/loyalty-badge.types.js} +0 -0
|
@@ -13,6 +13,7 @@ import { DEFAULT_LOCALE } from "../../../constants.js";
|
|
|
13
13
|
import { convertToLocaleCurrency } from "../../../../core/currency/index.js";
|
|
14
14
|
import { getLoyaltyAmount } from "../../../../core/utils/loyalty.js";
|
|
15
15
|
import { formatDateTimeForDisplay, formatTimeForDisplay, } from "../../../../core/utils/datetime.js";
|
|
16
|
+
import { getSeatDetails } from "../../../../core/utils/seats.js";
|
|
16
17
|
import { consume } from "@lit/context";
|
|
17
18
|
import { pageDispatchContext, } from "../../../../contexts/events.context.js";
|
|
18
19
|
let CorasConfirmation = class CorasConfirmation extends LitElement {
|
|
@@ -85,7 +86,9 @@ let CorasConfirmation = class CorasConfirmation extends LitElement {
|
|
|
85
86
|
</p>
|
|
86
87
|
</div>
|
|
87
88
|
|
|
88
|
-
${this.reservations.map((reservation, index) =>
|
|
89
|
+
${this.reservations.map((reservation, index) => {
|
|
90
|
+
const { section, seats } = getSeatDetails(reservation.tickets);
|
|
91
|
+
return html `
|
|
89
92
|
${index > 0 ? html `<div class="reservation-spacer"></div>` : nothing}
|
|
90
93
|
|
|
91
94
|
<div class="confirmation-container">
|
|
@@ -106,18 +109,18 @@ let CorasConfirmation = class CorasConfirmation extends LitElement {
|
|
|
106
109
|
<div class="info-label">${msg("Time")}</div>
|
|
107
110
|
<div class="info-value">
|
|
108
111
|
${formatDateTimeForDisplay({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
dateTime: reservation.start_datetime,
|
|
113
|
+
timezone: reservation.timezone,
|
|
114
|
+
locale: this.locale || navigator.language,
|
|
115
|
+
}, {
|
|
116
|
+
includeYear: true,
|
|
117
|
+
shortFormat: true,
|
|
118
|
+
})},
|
|
116
119
|
${formatTimeForDisplay({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
dateTime: reservation.start_datetime,
|
|
121
|
+
timezone: reservation.timezone,
|
|
122
|
+
locale: this.locale || navigator.language,
|
|
123
|
+
})}
|
|
121
124
|
</div>
|
|
122
125
|
</div>
|
|
123
126
|
|
|
@@ -125,39 +128,58 @@ let CorasConfirmation = class CorasConfirmation extends LitElement {
|
|
|
125
128
|
<div class="info-label">${msg("Location")}</div>
|
|
126
129
|
<div class="info-value">
|
|
127
130
|
${reservation.location_name
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
? html `${reservation.location_name}, ${reservation.city}`
|
|
132
|
+
: reservation.city}
|
|
130
133
|
</div>
|
|
131
134
|
</div>
|
|
132
135
|
|
|
136
|
+
${section
|
|
137
|
+
? html `
|
|
138
|
+
<div class="info-item">
|
|
139
|
+
<div class="info-label">${msg("Section")}</div>
|
|
140
|
+
<div class="info-value" data-testid="section">
|
|
141
|
+
${section}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
`
|
|
145
|
+
: nothing}
|
|
146
|
+
${seats
|
|
147
|
+
? html `
|
|
148
|
+
<div class="info-item">
|
|
149
|
+
<div class="info-label">${msg("Seats")}</div>
|
|
150
|
+
<div class="info-value" data-testid="seats">${seats}</div>
|
|
151
|
+
</div>
|
|
152
|
+
`
|
|
153
|
+
: nothing}
|
|
133
154
|
${"tour_language" in reservation && reservation.tour_language
|
|
134
|
-
|
|
155
|
+
? html `
|
|
135
156
|
<div class="info-item">
|
|
136
157
|
<div class="info-label">${msg("Language")}</div>
|
|
137
158
|
<div class="info-value">${reservation.tour_language}</div>
|
|
138
159
|
</div>
|
|
139
160
|
`
|
|
140
|
-
|
|
161
|
+
: nothing}
|
|
141
162
|
|
|
142
163
|
<div class="info-item">
|
|
143
164
|
<div class="info-label">${msg("Amount Paid")}</div>
|
|
144
165
|
<div class="info-value">
|
|
145
166
|
${(() => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
167
|
+
const payAmount = getLoyaltyAmount(reservation.loyalty, "pay");
|
|
168
|
+
return this.loyalty && payAmount
|
|
169
|
+
? `${new Intl.NumberFormat(this.locale || navigator.language).format(payAmount)} FIDA`
|
|
170
|
+
: convertToLocaleCurrency({
|
|
171
|
+
value: reservation.total_price,
|
|
172
|
+
locale: this.locale || navigator.language,
|
|
173
|
+
currency: (reservation.currency ||
|
|
174
|
+
"USD"),
|
|
175
|
+
});
|
|
176
|
+
})()}
|
|
156
177
|
</div>
|
|
157
178
|
</div>
|
|
158
179
|
</div>
|
|
159
180
|
</div>
|
|
160
|
-
|
|
181
|
+
`;
|
|
182
|
+
})}
|
|
161
183
|
|
|
162
184
|
<div class="help-text">
|
|
163
185
|
${msg("If you need help with your order, please visit our")}
|
|
@@ -37,6 +37,7 @@ declare const CorasPaymentPage_base: import("../../contexts/utils.js").Construct
|
|
|
37
37
|
locale: import("../../index.js").SupportedLocales;
|
|
38
38
|
locales: import("../../index.js").SupportedLocales[];
|
|
39
39
|
loyaltyPoints: boolean;
|
|
40
|
+
loyaltyProgramme: import("../../core/utils/loyalty.js").LoyaltyProgramme | null;
|
|
40
41
|
logger: Logger;
|
|
41
42
|
client: import("openapi-fetch").Client<import("../../core/types/api-schema.js").paths>;
|
|
42
43
|
getPageProperties(): PaymentPageParamsEvent;
|
|
@@ -74,6 +75,8 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
|
|
|
74
75
|
private cdpReady;
|
|
75
76
|
private pendingTransferRecoveryStarted;
|
|
76
77
|
private apiService;
|
|
78
|
+
protected willUpdate(changedProperties: PropertyValues): void;
|
|
79
|
+
private appliedLoyaltyRequirements;
|
|
77
80
|
private getApiService;
|
|
78
81
|
private showCryptoAuthModal;
|
|
79
82
|
private transactionId;
|
|
@@ -138,6 +141,7 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
|
|
|
138
141
|
*/
|
|
139
142
|
private shouldShowBillingAddress;
|
|
140
143
|
private renderContactDetailsEditable;
|
|
144
|
+
private renderLoyaltyProgrammeFields;
|
|
141
145
|
private renderActivityDetails;
|
|
142
146
|
private validateWalletEmail;
|
|
143
147
|
/**
|
|
@@ -239,6 +243,8 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
|
|
|
239
243
|
private renderContent;
|
|
240
244
|
private getLoyaltyAccountUrl;
|
|
241
245
|
private renderSuccess;
|
|
246
|
+
private renderLoyaltyProgrammeTerms;
|
|
247
|
+
private renderLoyaltyProgrammeEarned;
|
|
242
248
|
private renderPending;
|
|
243
249
|
private renderFailure;
|
|
244
250
|
/**
|
|
@@ -44,7 +44,9 @@ import "./partials/billing-address/billing-address.js";
|
|
|
44
44
|
import { getBookingSession, removeBookingSession, } from "../../core/api/middlewares/booking-session/booking-session.utils.js";
|
|
45
45
|
import { PaymentApiService } from "./services/payment-api.service.js";
|
|
46
46
|
import { getDefaultPhoneCode, getDefaultCountry, getShortestExpirationSeconds, getTotalQuantity, getTotalPrice, validateWalletEmail, findCountryCode as findCountryCodeUtil, toE164, prepareReservationData, prepareAttendeesData, isApiError, unwrapApiErrorBody, mapApiErrorsToForm, prepareCustomerData as prepareCustomerDataUtil, getFieldConfig, isFinalStatus, pollTransactionStatus, INVALID_FIELD_SELECTOR, } from "./payment-page.utils.js";
|
|
47
|
-
import { getLoyaltyAmount } from "../../core/utils/loyalty.js";
|
|
47
|
+
import { getLoyaltyAmount, sumProgrammeUnitsEarned, } from "../../core/utils/loyalty.js";
|
|
48
|
+
import { renderLoyaltyBadge } from "../../components/loyalty-badge/loyalty-badge.utils.js";
|
|
49
|
+
import { buildLoyaltyFieldsConfig, collectLoyaltyMetadata, getLoyaltyFieldName, } from "./payment-page.loyalty.js";
|
|
48
50
|
import { consume } from "@lit/context";
|
|
49
51
|
import { currentPageContext } from "../../contexts/current-page.context.js";
|
|
50
52
|
import { convertToLocaleCurrency } from "../../core/currency/index.js";
|
|
@@ -141,6 +143,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
141
143
|
this.cdpReady = false;
|
|
142
144
|
this.pendingTransferRecoveryStarted = false;
|
|
143
145
|
this.apiService = null;
|
|
146
|
+
this.appliedLoyaltyRequirements = null;
|
|
144
147
|
this.showCryptoAuthModal = false;
|
|
145
148
|
this.transactionId = "";
|
|
146
149
|
this.userId = "";
|
|
@@ -506,6 +509,15 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
506
509
|
locale: this.locale,
|
|
507
510
|
};
|
|
508
511
|
}
|
|
512
|
+
willUpdate(changedProperties) {
|
|
513
|
+
super.willUpdate(changedProperties);
|
|
514
|
+
const loyaltyRequirements = this.reservationsCheckTask.value?.loyalty ?? null;
|
|
515
|
+
if (changedProperties.has("loyaltyProgramme") ||
|
|
516
|
+
loyaltyRequirements !== this.appliedLoyaltyRequirements) {
|
|
517
|
+
this.appliedLoyaltyRequirements = loyaltyRequirements;
|
|
518
|
+
this.formController.additionalFields = buildLoyaltyFieldsConfig(loyaltyRequirements, this.loyaltyProgramme);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
509
521
|
getApiService() {
|
|
510
522
|
if (!this.apiService) {
|
|
511
523
|
this.apiService = new PaymentApiService({
|
|
@@ -759,6 +771,23 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
759
771
|
</div>
|
|
760
772
|
`;
|
|
761
773
|
}
|
|
774
|
+
renderLoyaltyProgrammeFields() {
|
|
775
|
+
const requirements = this.reservationsCheckTask.value?.loyalty;
|
|
776
|
+
if (!requirements || requirements.requirements.length === 0) {
|
|
777
|
+
return nothing;
|
|
778
|
+
}
|
|
779
|
+
return html `
|
|
780
|
+
<section class="loyalty-programme" data-testid="loyalty-programme-fields">
|
|
781
|
+
<h2>${msg("Additional details")}</h2>
|
|
782
|
+
<div class="fields-container">
|
|
783
|
+
${requirements.requirements.map((requirement) => this.renderField({
|
|
784
|
+
fieldName: getLoyaltyFieldName(requirement.field),
|
|
785
|
+
}))}
|
|
786
|
+
</div>
|
|
787
|
+
</section>
|
|
788
|
+
<hr class="section-divider" />
|
|
789
|
+
`;
|
|
790
|
+
}
|
|
762
791
|
renderActivityDetails() {
|
|
763
792
|
const data = this.reservationsCheckTask.value;
|
|
764
793
|
if (!data?.reservations || !data.reservations.length) {
|
|
@@ -1206,6 +1235,10 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
1206
1235
|
this.logger.error("Cannot confirm reservation: booking session is missing.");
|
|
1207
1236
|
return null;
|
|
1208
1237
|
}
|
|
1238
|
+
const metadata = {
|
|
1239
|
+
...this.metadata,
|
|
1240
|
+
...collectLoyaltyMetadata(this.reservationsCheckTask.value?.loyalty, this.formController.formValues),
|
|
1241
|
+
};
|
|
1209
1242
|
const body = {
|
|
1210
1243
|
first_name: this.getFieldValue("first_name"),
|
|
1211
1244
|
second_name: this.getFieldValue("second_name"),
|
|
@@ -1220,10 +1253,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
1220
1253
|
id_number: null,
|
|
1221
1254
|
wallet_address: null,
|
|
1222
1255
|
transaction_hash: null,
|
|
1223
|
-
|
|
1224
|
-
...(Object.keys(this.metadata).length > 0
|
|
1225
|
-
? { metadata: this.metadata }
|
|
1226
|
-
: {}),
|
|
1256
|
+
...(Object.keys(metadata).length > 0 ? { metadata } : {}),
|
|
1227
1257
|
};
|
|
1228
1258
|
const customHeaders = {};
|
|
1229
1259
|
if (this.paymentType === "crypto") {
|
|
@@ -1372,7 +1402,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
1372
1402
|
if (fieldName === "phone") {
|
|
1373
1403
|
return this.renderPhoneField(fieldName);
|
|
1374
1404
|
}
|
|
1375
|
-
const fieldConfig = getFieldConfig(fieldName,
|
|
1405
|
+
const fieldConfig = getFieldConfig(fieldName, this.formController.fields);
|
|
1376
1406
|
if (!fieldConfig)
|
|
1377
1407
|
return null;
|
|
1378
1408
|
const value = this.getFieldValue(fieldName);
|
|
@@ -1492,8 +1522,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
1492
1522
|
<form id="form" @submit=${this.onFormSubmit}>
|
|
1493
1523
|
${this.renderContactDetailsEditable()}
|
|
1494
1524
|
<hr class="section-divider" />
|
|
1495
|
-
${this.
|
|
1496
|
-
${this.renderPaymentDetailsStep()}
|
|
1525
|
+
${this.renderLoyaltyProgrammeFields()} ${this.renderActivityDetails()}
|
|
1526
|
+
${this.renderPaymentTypeSelector()} ${this.renderPaymentDetailsStep()}
|
|
1497
1527
|
</form>
|
|
1498
1528
|
${this.renderCryptoAuthModalElement()}
|
|
1499
1529
|
`;
|
|
@@ -1569,6 +1599,44 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
|
|
|
1569
1599
|
></coras-collect-fida>
|
|
1570
1600
|
</div>`
|
|
1571
1601
|
: nothing}
|
|
1602
|
+
${this.renderLoyaltyProgrammeEarned()}
|
|
1603
|
+
</div>
|
|
1604
|
+
`;
|
|
1605
|
+
}
|
|
1606
|
+
renderLoyaltyProgrammeTerms(termsUrl) {
|
|
1607
|
+
const href = safeUrl(termsUrl);
|
|
1608
|
+
if (!href)
|
|
1609
|
+
return nothing;
|
|
1610
|
+
return html `
|
|
1611
|
+
<a
|
|
1612
|
+
class="loyalty-terms"
|
|
1613
|
+
href=${href}
|
|
1614
|
+
target="_blank"
|
|
1615
|
+
rel="noopener noreferrer"
|
|
1616
|
+
>${msg("Terms & Conditions")}</a
|
|
1617
|
+
>
|
|
1618
|
+
`;
|
|
1619
|
+
}
|
|
1620
|
+
renderLoyaltyProgrammeEarned() {
|
|
1621
|
+
const programme = this.loyaltyProgramme;
|
|
1622
|
+
const reservations = this.reservationsTask.value?.reservations ?? [];
|
|
1623
|
+
const earned = sumProgrammeUnitsEarned(reservations, programme);
|
|
1624
|
+
if (!programme || earned <= 0) {
|
|
1625
|
+
return nothing;
|
|
1626
|
+
}
|
|
1627
|
+
return html `
|
|
1628
|
+
<div
|
|
1629
|
+
class="loyalty-programme-earned"
|
|
1630
|
+
data-testid="loyalty-programme-earned"
|
|
1631
|
+
>
|
|
1632
|
+
${renderLoyaltyBadge({
|
|
1633
|
+
loyalty: null,
|
|
1634
|
+
programme,
|
|
1635
|
+
amount: earned,
|
|
1636
|
+
locale: this.locale,
|
|
1637
|
+
variant: "banner",
|
|
1638
|
+
})}
|
|
1639
|
+
${this.renderLoyaltyProgrammeTerms(programme.termsUrl ?? null)}
|
|
1572
1640
|
</div>
|
|
1573
1641
|
`;
|
|
1574
1642
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loyalty programme checkout fields. `GET /reservations/check` lists the
|
|
3
|
+
* fields and their rules (required, pattern, max length); the host's
|
|
4
|
+
* `config.loyalty` supplies the wording. This module turns both into the
|
|
5
|
+
* payment page's field config (the field's label shown as its placeholder,
|
|
6
|
+
* like the billing address fields) and collects the values into the
|
|
7
|
+
* reservation `metadata` the API validates and stores.
|
|
8
|
+
*/
|
|
9
|
+
import type { LoyaltyProgramme, LoyaltyRequirements } from "../../core/utils/loyalty.js";
|
|
10
|
+
import type { FieldsConfig, FormValues } from "./payment-page.types.js";
|
|
11
|
+
export declare function getLoyaltyFieldName(field: string): string;
|
|
12
|
+
export declare function buildLoyaltyFieldsConfig(requirements: LoyaltyRequirements | null | undefined, programme: LoyaltyProgramme | null | undefined): FieldsConfig;
|
|
13
|
+
export declare function collectLoyaltyMetadata(requirements: LoyaltyRequirements | null | undefined, formValues: FormValues): Record<string, string>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loyalty programme checkout fields. `GET /reservations/check` lists the
|
|
3
|
+
* fields and their rules (required, pattern, max length); the host's
|
|
4
|
+
* `config.loyalty` supplies the wording. This module turns both into the
|
|
5
|
+
* payment page's field config (the field's label shown as its placeholder,
|
|
6
|
+
* like the billing address fields) and collects the values into the
|
|
7
|
+
* reservation `metadata` the API validates and stores.
|
|
8
|
+
*/
|
|
9
|
+
import { msg } from "@lit/localize";
|
|
10
|
+
import { composeValidators, maxLength, required, } from "./payment-page.validators.js";
|
|
11
|
+
/** Form field names are prefixed so they cannot collide with the fixed fields. */
|
|
12
|
+
const LOYALTY_FIELD_PREFIX = "loyalty_";
|
|
13
|
+
export function getLoyaltyFieldName(field) {
|
|
14
|
+
return `${LOYALTY_FIELD_PREFIX}${field}`;
|
|
15
|
+
}
|
|
16
|
+
function matchesPattern(pattern) {
|
|
17
|
+
// The API compiled the pattern already; a pattern this engine rejects is
|
|
18
|
+
// left to the API's own validation rather than blocking the form.
|
|
19
|
+
let regex = null;
|
|
20
|
+
try {
|
|
21
|
+
regex = new RegExp(`^(?:${pattern})$`);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
regex = null;
|
|
25
|
+
}
|
|
26
|
+
return ({ value }) => {
|
|
27
|
+
if (!value || !regex)
|
|
28
|
+
return undefined;
|
|
29
|
+
return regex.test(value) ? undefined : msg("Please enter a valid value");
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function createLoyaltyFieldValidator(requirement) {
|
|
33
|
+
const validators = [];
|
|
34
|
+
if (requirement.required)
|
|
35
|
+
validators.push(required);
|
|
36
|
+
validators.push(maxLength(requirement.max_length));
|
|
37
|
+
if (requirement.pattern)
|
|
38
|
+
validators.push(matchesPattern(requirement.pattern));
|
|
39
|
+
const validate = composeValidators(...validators);
|
|
40
|
+
// The value is sent trimmed, so it is validated trimmed as well.
|
|
41
|
+
return (params) => validate({
|
|
42
|
+
...params,
|
|
43
|
+
value: typeof params.value === "string" ? params.value.trim() : params.value,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** "miles_and_more_card_number" reads as "Miles and more card number" when the host gave no wording. */
|
|
47
|
+
function humaniseFieldName(field) {
|
|
48
|
+
const words = field.replace(/_/g, " ").trim();
|
|
49
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
50
|
+
}
|
|
51
|
+
export function buildLoyaltyFieldsConfig(requirements, programme) {
|
|
52
|
+
if (!requirements)
|
|
53
|
+
return {};
|
|
54
|
+
return Object.fromEntries(requirements.requirements.map((requirement) => {
|
|
55
|
+
const text = programme?.fields?.[requirement.field];
|
|
56
|
+
return [
|
|
57
|
+
getLoyaltyFieldName(requirement.field),
|
|
58
|
+
{
|
|
59
|
+
label: () => "",
|
|
60
|
+
placeholder: () => text?.label ?? humaniseFieldName(requirement.field),
|
|
61
|
+
helpText: () => text?.helpText ?? "",
|
|
62
|
+
validators: createLoyaltyFieldValidator(requirement),
|
|
63
|
+
type: "text",
|
|
64
|
+
autocomplete: "off",
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
export function collectLoyaltyMetadata(requirements, formValues) {
|
|
70
|
+
if (!requirements)
|
|
71
|
+
return {};
|
|
72
|
+
const metadata = {};
|
|
73
|
+
for (const requirement of requirements.requirements) {
|
|
74
|
+
const value = formValues[getLoyaltyFieldName(requirement.field)];
|
|
75
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
76
|
+
metadata[requirement.field] = value.trim();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return metadata;
|
|
80
|
+
}
|
|
@@ -251,6 +251,22 @@ export default css `
|
|
|
251
251
|
padding: 2rem 0;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
.loyalty-programme-earned .loyalty-terms {
|
|
255
|
+
display: inline-block;
|
|
256
|
+
margin-top: 0.5rem;
|
|
257
|
+
color: var(--coras-color-link);
|
|
258
|
+
font-size: var(--coras-font-size-sm);
|
|
259
|
+
text-decoration: underline;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.loyalty-programme-earned {
|
|
263
|
+
display: flex;
|
|
264
|
+
flex-direction: column;
|
|
265
|
+
align-items: center;
|
|
266
|
+
gap: 0.25rem;
|
|
267
|
+
margin-top: 1.5rem;
|
|
268
|
+
}
|
|
269
|
+
|
|
254
270
|
.collect-fida-container {
|
|
255
271
|
margin-top: 2rem;
|
|
256
272
|
}
|
|
@@ -69,7 +69,7 @@ export declare const validateField: (fieldName: string, value: string, formError
|
|
|
69
69
|
*/
|
|
70
70
|
export declare const validateForm: (formValues: FormValues, formErrors: Record<string, string>, FIELDS: FieldsConfig, required: (params: {
|
|
71
71
|
value: string;
|
|
72
|
-
}) => string | undefined, checkData: components["schemas"]["CheckReservationsResponse"] | undefined, shouldValidateBillingAddress?: boolean, contextProvider?: (fieldName: string) => ValidatorContext | undefined) => {
|
|
72
|
+
}) => string | undefined, checkData: components["schemas"]["CheckReservationsResponse"] | undefined, shouldValidateBillingAddress?: boolean, contextProvider?: (fieldName: string) => ValidatorContext | undefined, additionalFieldNames?: readonly string[]) => {
|
|
73
73
|
isValid: boolean;
|
|
74
74
|
errors: Record<string, string>;
|
|
75
75
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { msg } from "@lit/localize";
|
|
2
2
|
import { apiGet } from "../../core/api/queries.js";
|
|
3
3
|
import { getLoyaltyAmount } from "../../core/utils/loyalty.js";
|
|
4
|
+
import { getLoyaltyFieldName } from "./payment-page.loyalty.js";
|
|
4
5
|
import { APIError } from "../../core/api/api-error.js";
|
|
5
6
|
import { parsePhoneNumberFromString, } from "libphonenumber-js/min";
|
|
6
7
|
import { validEmail, } from "./payment-page.validators.js";
|
|
@@ -232,7 +233,7 @@ export const validateField = (fieldName, value, formErrors, FIELDS, required, co
|
|
|
232
233
|
* When false, skips billing address validation regardless of API requirements.
|
|
233
234
|
* When undefined, uses the API requirements to determine if validation is needed.
|
|
234
235
|
*/
|
|
235
|
-
export const validateForm = (formValues, formErrors, FIELDS, required, checkData, shouldValidateBillingAddress, contextProvider) => {
|
|
236
|
+
export const validateForm = (formValues, formErrors, FIELDS, required, checkData, shouldValidateBillingAddress, contextProvider, additionalFieldNames = []) => {
|
|
236
237
|
let isValid = true;
|
|
237
238
|
let newErrors = { ...formErrors };
|
|
238
239
|
const validateFieldFn = (fieldName) => {
|
|
@@ -259,6 +260,9 @@ export const validateForm = (formValues, formErrors, FIELDS, required, checkData
|
|
|
259
260
|
if (hasEmailField(checkData)) {
|
|
260
261
|
validateFieldFn("email");
|
|
261
262
|
}
|
|
263
|
+
for (const fieldName of additionalFieldNames) {
|
|
264
|
+
validateFieldFn(fieldName);
|
|
265
|
+
}
|
|
262
266
|
// Validate billing address fields only when they are displayed.
|
|
263
267
|
// Defaults to true for backward compatibility, but callers should always pass the parameter.
|
|
264
268
|
const validateBillingAddress = shouldValidateBillingAddress ?? true;
|
|
@@ -585,6 +589,20 @@ export function mapApiErrorsToForm(error, currentFormErrors, attendees, reservat
|
|
|
585
589
|
}
|
|
586
590
|
});
|
|
587
591
|
}
|
|
592
|
+
// Loyalty programme fields: `errors.metadata.<name>` maps to `loyalty_<name>`
|
|
593
|
+
else if (field === "metadata" &&
|
|
594
|
+
typeof message === "object" &&
|
|
595
|
+
message !== null &&
|
|
596
|
+
!Array.isArray(message)) {
|
|
597
|
+
Object.entries(message).forEach(([metadataKey, fieldErrors]) => {
|
|
598
|
+
const errorMessage = Array.isArray(fieldErrors) && fieldErrors.length > 0
|
|
599
|
+
? fieldErrors[0]
|
|
600
|
+
: String(fieldErrors);
|
|
601
|
+
if (errorMessage) {
|
|
602
|
+
formErrors[getLoyaltyFieldName(metadataKey)] = errorMessage;
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
}
|
|
588
606
|
// Handle nested fields like customer.email
|
|
589
607
|
else if (field.includes(".")) {
|
|
590
608
|
const [category, specificField] = field.split(".");
|
|
@@ -41,6 +41,7 @@ export declare class PaymentApiService {
|
|
|
41
41
|
data: {
|
|
42
42
|
general: components["schemas"]["GeneralRequirements"];
|
|
43
43
|
reservations: components["schemas"]["ReservationRequirementsAndRestrictions"][];
|
|
44
|
+
loyalty: components["schemas"]["LoyaltyRequirements"];
|
|
44
45
|
};
|
|
45
46
|
response: Response;
|
|
46
47
|
}>;
|
|
@@ -18,6 +18,7 @@ declare const CorasSearchPage_base: import("../../contexts/utils.js").Constructo
|
|
|
18
18
|
locale: import("../../index.js").SupportedLocales;
|
|
19
19
|
locales: import("../../index.js").SupportedLocales[];
|
|
20
20
|
loyaltyPoints: boolean;
|
|
21
|
+
loyaltyProgramme: import("../../index.js").CorasLoyaltyProgramme | null;
|
|
21
22
|
logger: import("../../core/logger.js").Logger;
|
|
22
23
|
client: Client<paths>;
|
|
23
24
|
getPageProperties(): SearchPageParamsEvent;
|
|
@@ -30,6 +30,7 @@ import { adaptPresetImages } from "../../core/images/preset-adapter.js";
|
|
|
30
30
|
import { ErrorModalMixin } from "../../mixins/error-modal.mixin.js";
|
|
31
31
|
import { getLocale, setLocale } from "../../core/i18n/localization.js";
|
|
32
32
|
import { getApiLanguageCode } from "../../core/utils/locale.js";
|
|
33
|
+
import { renderLoyaltyBadge } from "../../components/loyalty-badge/loyalty-badge.utils.js";
|
|
33
34
|
/**
|
|
34
35
|
* Search page component for displaying search results.
|
|
35
36
|
*
|
|
@@ -298,6 +299,14 @@ let CorasSearchPage = class CorasSearchPage extends ErrorModalMixin(LocationSear
|
|
|
298
299
|
locale=${this.locale}
|
|
299
300
|
@click=${() => this.handleAttractionClick(result.attraction_id)}
|
|
300
301
|
>
|
|
302
|
+
${renderLoyaltyBadge({
|
|
303
|
+
loyalty: result.loyalty,
|
|
304
|
+
programme: this.loyaltyProgramme,
|
|
305
|
+
locale: this.locale,
|
|
306
|
+
variant: "card",
|
|
307
|
+
slot: "points",
|
|
308
|
+
from: true,
|
|
309
|
+
})}
|
|
301
310
|
</coras-attraction-long-card>
|
|
302
311
|
`)}
|
|
303
312
|
</div>
|
|
@@ -13,6 +13,7 @@ declare const CorasSuggestionWidget_base: import("../../contexts/utils.js").Cons
|
|
|
13
13
|
locale: import("../../index.js").SupportedLocales;
|
|
14
14
|
locales: import("../../index.js").SupportedLocales[];
|
|
15
15
|
loyaltyPoints: boolean;
|
|
16
|
+
loyaltyProgramme: import("../../index.js").CorasLoyaltyProgramme | null;
|
|
16
17
|
logger: import("../../core/logger.js").Logger;
|
|
17
18
|
client: import("openapi-fetch").Client<import("../../core/types/api-schema.js").paths>;
|
|
18
19
|
getPageProperties(): PageParamsEvent;
|
|
@@ -20,6 +20,7 @@ import { IMAGE_BASE_URL } from "../../core/images/constants.js";
|
|
|
20
20
|
import { BaseMixin } from "../../mixins/base.mixin.js";
|
|
21
21
|
import { apiGet } from "../../core/api/queries.js";
|
|
22
22
|
import { convertToLocaleCurrency } from "../../core/currency/index.js";
|
|
23
|
+
import { renderLoyaltyBadge } from "../../components/loyalty-badge/loyalty-badge.utils.js";
|
|
23
24
|
let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitElement) {
|
|
24
25
|
constructor() {
|
|
25
26
|
super(...arguments);
|
|
@@ -97,7 +98,16 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
|
|
|
97
98
|
timezone=${card.timezone}
|
|
98
99
|
locale=${this.locale}
|
|
99
100
|
@click=${() => this.handleCardClick(card)}
|
|
100
|
-
|
|
101
|
+
>
|
|
102
|
+
${renderLoyaltyBadge({
|
|
103
|
+
loyalty: card.loyalty,
|
|
104
|
+
programme: this.loyaltyProgramme,
|
|
105
|
+
locale: this.locale,
|
|
106
|
+
variant: "card",
|
|
107
|
+
slot: "points",
|
|
108
|
+
from: true,
|
|
109
|
+
})}
|
|
110
|
+
</coras-attraction-short-card>
|
|
101
111
|
`;
|
|
102
112
|
}
|
|
103
113
|
renderExploreCard(country, city) {
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
23
|
-
"version": "0.
|
|
23
|
+
"version": "0.10.0",
|
|
24
24
|
"private": false,
|
|
25
25
|
"homepage": "https://docs.coras.io",
|
|
26
26
|
"bugs": {
|
|
@@ -105,9 +105,9 @@
|
|
|
105
105
|
"ts-lit-plugin": "2.0.2",
|
|
106
106
|
"typescript": "6.0.3",
|
|
107
107
|
"typescript-eslint": "8.67.0",
|
|
108
|
-
"vite": "8.2.
|
|
108
|
+
"vite": "8.2.4",
|
|
109
109
|
"vitest": "4.1.11",
|
|
110
|
-
"@coras-io/static": "0.0
|
|
110
|
+
"@coras-io/static": "0.1.0"
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
113
|
"@coinbase/cdp-core": "0.0.122",
|
|
@@ -120,12 +120,12 @@
|
|
|
120
120
|
"@stripe/stripe-js": "^9.14.0",
|
|
121
121
|
"date-fns": "^4.4.0",
|
|
122
122
|
"date-fns-tz": "^3.2.0",
|
|
123
|
-
"dompurify": "^3.4.
|
|
123
|
+
"dompurify": "^3.4.17",
|
|
124
124
|
"libphonenumber-js": "^1.13.11",
|
|
125
125
|
"lit": "^3.3.3",
|
|
126
126
|
"openapi-fetch": "^0.17.0",
|
|
127
127
|
"viem": "^2.55.19",
|
|
128
|
-
"@coras-io/brand-tokens": "^0.
|
|
128
|
+
"@coras-io/brand-tokens": "^0.7.0"
|
|
129
129
|
},
|
|
130
130
|
"scripts": {
|
|
131
131
|
"lint": "eslint \"src/**/*.ts*\"",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type CSSResultGroup, LitElement } from "lit";
|
|
2
|
-
import "../icon/icon.js";
|
|
3
|
-
declare const CorasPoints_base: import("../../mixins/points/types.js").Constructor<import("../../mixins/points/types.js").PointsMixinInterface> & typeof LitElement;
|
|
4
|
-
export declare class CorasPoints extends CorasPoints_base {
|
|
5
|
-
static styles: CSSResultGroup;
|
|
6
|
-
points: string;
|
|
7
|
-
render(): import("lit").TemplateResult<1>;
|
|
8
|
-
}
|
|
9
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { LitElement, html } from "lit";
|
|
8
|
-
import { property } from "lit/decorators.js";
|
|
9
|
-
import { PointsMixin } from "../../mixins/points/points.js";
|
|
10
|
-
import styles from "./points.styles.js";
|
|
11
|
-
import "../icon/icon.js";
|
|
12
|
-
export class CorasPoints extends PointsMixin(LitElement) {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this.points = "";
|
|
16
|
-
}
|
|
17
|
-
static { this.styles = styles; }
|
|
18
|
-
render() {
|
|
19
|
-
return html `
|
|
20
|
-
<div class="logo">
|
|
21
|
-
<img data-testid="logo" src=${this.pointsLogoUrl} />
|
|
22
|
-
</div>
|
|
23
|
-
<div class="body">
|
|
24
|
-
<img
|
|
25
|
-
data-testid="points-icon"
|
|
26
|
-
class="points-icon"
|
|
27
|
-
src=${this.pointsIconUrl}
|
|
28
|
-
/>
|
|
29
|
-
<span data-testid="points">${this.points} ${this.pointsUnit}</span>
|
|
30
|
-
</div>
|
|
31
|
-
`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
__decorate([
|
|
35
|
-
property({ type: String })
|
|
36
|
-
], CorasPoints.prototype, "points", void 0);
|