@@ -62,8 +75,7 @@ const CourseSidebarPrice = () => {
);
}
- const hasDiscountedPrice = coursePrice.discounted < coursePrice.list;
-
+ const hasDiscountedPrice = sumOfArray(coursePrice.discounted || []) < sumOfArray(coursePrice.listRange);
// Case 2: No subsidies found but learner can request a subsidy
if (!hasDiscountedPrice && canRequestSubsidy) {
return (
@@ -113,14 +125,13 @@ const CourseSidebarPrice = () => {
});
}
}
- const discountedPriceDisplay = `${numberWithPrecision(coursePrice.discounted)} ${currency}`;
-
+ const discountedPriceDisplay = `${getContentPriceDisplay(coursePrice.discounted)} ${currency}`;
return (
<>
0 || showOrigPrice })}>
{/* discounted > 0 means partial discount */}
{showOrigPrice && <>{crossedOutOriginalPrice}{' '}>}
- {coursePrice.discounted > 0 && (
+ {sumOfArray(coursePrice.discounted) > 0 && (
<>
individualPrice - (individualPrice * (discountValue / 100)),
+ );
}
if (discountType && discountType.toLowerCase() === SUBSIDY_DISCOUNT_TYPE_MAP.ABSOLUTE.toLowerCase()) {
- discountedPrice = Math.max(listPrice - discountValue, 0);
+ discountedPrice = onlyListPrice.listRange.map(
+ (individualPrice) => Math.max(individualPrice - discountValue, 0),
+ );
}
if (isDefinedAndNotNull(discountedPrice)) {
@@ -226,7 +231,7 @@ export const useCoursePriceForUserSubsidy = ({
}
return {
...onlyListPrice,
- discounted: onlyListPrice.list,
+ discounted: onlyListPrice.listRange,
};
}
@@ -631,6 +636,7 @@ export const useUserSubsidyApplicableToCourse = () => {
export function useCoursePrice() {
const { data: courseListPrice } = useCourseListPrice();
const { userSubsidyApplicableToCourse } = useUserSubsidyApplicableToCourse();
+ console.log(courseListPrice, userSubsidyApplicableToCourse);
return useCoursePriceForUserSubsidy({
userSubsidyApplicableToCourse,
listPrice: courseListPrice,
diff --git a/src/components/course/data/utils.jsx b/src/components/course/data/utils.jsx
index c19d769b6c..fa1c3fda64 100644
--- a/src/components/course/data/utils.jsx
+++ b/src/components/course/data/utils.jsx
@@ -154,6 +154,16 @@ export function getProgramIcon(type) {
export const numberWithPrecision = (number, precision = 2) => number.toFixed(precision);
+export const formatPrice = (price, options = {}) => {
+ const USDollar = new Intl.NumberFormat('en-US', {
+ style: 'currency',
+ currency: 'USD',
+ minimumFractionDigits: 0,
+ ...options,
+ });
+ return USDollar.format(Math.abs(price));
+};
+
/**
*
* @param couponCodes
@@ -817,10 +827,14 @@ export function getEntitlementPrice(entitlements) {
* @returns Price for the course run.
*/
export function getCoursePrice(course) {
+ console.log(course);
+ if (course.activeCourseRun?.fixedPriceUsd) {
+ return [course.activeCourseRun?.fixedPriceUsd];
+ }
if (course.activeCourseRun?.firstEnrollablePaidSeatPrice) {
- return course.activeCourseRun.firstEnrollablePaidSeatPrice;
+ return [course.activeCourseRun?.firstEnrollablePaidSeatPrice];
}
- return getEntitlementPrice(course.entitlements);
+ return [course.entitlements];
}
/**
diff --git a/src/utils/common.js b/src/utils/common.js
index 84774b0b28..e4a8f999e9 100644
--- a/src/utils/common.js
+++ b/src/utils/common.js
@@ -25,6 +25,9 @@ export const isNull = (value) => {
};
export const isDefinedAndNotNull = (value) => {
+ if (Array.isArray(value)) {
+ return value.every(item => isDefined(item) && !isNull(item));
+ }
const values = createArrayFromValue(value);
return values.every(item => isDefined(item) && !isNull(item));
};
@@ -39,6 +42,8 @@ export const hasTruthyValue = (value) => {
return values.every(item => !!item);
};
+export const sumOfArray = (values) => values.reduce((prev, next) => prev + next, 0);
+
export const hasValidStartExpirationDates = ({ startDate, expirationDate, endDate }) => {
const now = dayjs();
// Subscriptions use "expirationDate" while Codes use "endDate"