Skip to content

Commit

Permalink
MWPW-142249: checkout-link flows (#1863)
Browse files Browse the repository at this point in the history
* MWPW-142249: checkout links flows for

download
upgrade
twp modal
d2p modal

* update commerce lib

* fix failing tests

* fix failing test

* fix failing test

* improve config override logic

* increase test coverage

* removed old code

* fix value cancellation per locale and add test

* add more tests

---------

Co-authored-by: Mariia Lukianets <[email protected]>
  • Loading branch information
yesil and 3ch023 authored Feb 14, 2024
1 parent 89950ae commit 968e533
Show file tree
Hide file tree
Showing 11 changed files with 496 additions and 131 deletions.
23 changes: 12 additions & 11 deletions libs/blocks/global-navigation/utilities/getUserEntitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { getConfig } from '../../../utils/utils.js';

const API_WAIT_TIMEOUT = 10000;
const FORMAT_RAW = 'raw';
let entitlements = {};

const getAcceptLanguage = (locale = 'en-US') => [
Expand All @@ -24,14 +25,14 @@ const getQueryParameters = (params) => {
return query.length ? `?${query.join('&')}` : '';
};

const emptyEntitlements = () => ({
const emptyEntitlements = (format) => (format === FORMAT_RAW ? [] : ({
clouds: {},
arrangement_codes: {},
fulfilled_codes: {},
offer_families: {},
offers: {},
list: { fulfilled_codes: [] },
});
}));
const CREATIVE_CLOUD = 'creative_cloud';
const DOCUMENT_CLOUD = 'document_cloud';
const EXPERIENCE_CLOUD = 'experience_cloud';
Expand Down Expand Up @@ -94,7 +95,7 @@ const mapSubscriptionCodes = (allOffers) => {
};
};

const getSubscriptions = async ({ queryParams }) => {
const getSubscriptions = async ({ queryParams }, format) => {
const config = getConfig();
const profile = await window.adobeIMS.getProfile();
const apiUrl = config.env.name === 'prod'
Expand All @@ -111,7 +112,7 @@ const getSubscriptions = async ({ queryParams }) => {
'Accept-Language': getAcceptLanguage(config.locale.ietf),
},
})
.then((response) => (response.status === 200 ? response.json() : emptyEntitlements()));
.then((response) => (response.status === 200 ? response.json() : emptyEntitlements(format)));
return res;
};

Expand All @@ -125,30 +126,30 @@ const getSubscriptions = async ({ queryParams }) => {
const getUserEntitlements = async ({ params, format } = {}) => {
if (!window.adobeIMS?.isSignedInUser()) {
entitlements = {};
return Promise.resolve(emptyEntitlements());
return Promise.resolve(emptyEntitlements(format));
}

const queryParams = getQueryParameters(params);
if (entitlements[queryParams]) {
return format === 'raw'
return format === FORMAT_RAW
? entitlements[queryParams]
: entitlements[queryParams]
.then((res) => mapSubscriptionCodes(res))
.catch(() => emptyEntitlements());
.catch(() => emptyEntitlements(format));
}

entitlements[queryParams] = entitlements[queryParams]
|| new Promise((resolve) => {
getSubscriptions({ queryParams })
getSubscriptions({ queryParams }, format)
.then((data) => resolve(data))
.catch(() => resolve(emptyEntitlements()));
.catch(() => resolve(emptyEntitlements(format)));
});

return format === 'raw'
return format === FORMAT_RAW
? entitlements[queryParams]
: entitlements[queryParams]
.then((res) => mapSubscriptionCodes(res))
.catch(() => emptyEntitlements());
.catch(() => emptyEntitlements(format));
};

export default getUserEntitlements;
2 changes: 1 addition & 1 deletion libs/blocks/merch-offers/merch-offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

export default async function init(el) {
el.append(el.querySelector('p'));
el.append(...el.querySelectorAll('p'));
el.append(...el.querySelectorAll('[data-wcs-osi]'));
el.firstElementChild.remove();
return el;
Expand Down
18 changes: 18 additions & 0 deletions libs/blocks/merch/merch.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ a[is='checkout-link'] > span {
content: "\00a0";
}

@media (max-width: 1200px) {
#checkout-link-modal {
height: 100vh;
border-radius: 0;
}
}

#checkout-link-modal {
display: flex;
}

#checkout-link-modal iframe {
flex: 1;
}

#checkout-link-modal iframe.d2p {
max-height: 850px;
}
Loading

0 comments on commit 968e533

Please sign in to comment.