@coursebuilder/commerce-next
Version:
Commerce Functionality for Course Builder with Next.js
39 lines (38 loc) • 2.46 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const getNumericValue = (value) => {
if (typeof value === 'string') {
return Number(value);
}
else if (typeof value === 'number') {
return value;
}
else if (typeof value?.toNumber === 'function') {
return value.toNumber();
}
else {
return 0;
}
};
export const RegionalPricingBox = ({ availablePPPCoupon, appliedPPPCoupon, setMerchantCoupon, index, setAutoApplyPPP, purchaseToUpgradeExists, }) => {
const regionNames = new Intl.DisplayNames(['en'], { type: 'region' });
if (!availablePPPCoupon?.country) {
console.error('No country found for PPP coupon', { availablePPPCoupon });
return null;
}
const countryCode = availablePPPCoupon.country;
const country = regionNames.of(countryCode);
const percentageDiscount = getNumericValue(availablePPPCoupon.percentageDiscount);
const percentOff = Math.floor(percentageDiscount * 100);
// if we are upgrading a Core(PPP) to a Bundle(PPP) and the PPP coupon is
// valid and auto-applied then we hide the checkbox to reduce confusion.
const hideCheckbox = purchaseToUpgradeExists;
return (_jsxs("div", { "data-ppp-container": index, children: [_jsxs("div", { "data-ppp-header": "", children: [_jsxs("strong", { children: ["We noticed that you're from", ' ', _jsx("img", { src: `https://hardcore-golick-433858.netlify.app/image?code=${countryCode}`, alt: `${country} flag`, width: 18, height: 14 }), ' ', country, ". To help facilitate global learning, we are offering purchasing power parity pricing."] }), _jsxs("p", { children: ["Please note that you will only be able to view content from within", ' ', country, ", and no bonuses will be provided."] }), !hideCheckbox && _jsx("p", { children: "If that is something that you need:" })] }), !hideCheckbox && (_jsxs("label", { children: [_jsx("input", { type: "checkbox", checked: Boolean(appliedPPPCoupon), onChange: () => {
setAutoApplyPPP(false);
if (appliedPPPCoupon) {
setMerchantCoupon(undefined);
}
else {
setMerchantCoupon(availablePPPCoupon);
}
} }), _jsxs("span", { children: ["Activate ", percentOff, "% off with regional pricing"] })] }))] }));
};