Skip to content

Commit

Permalink
feat: removed the Localized Currency for subscription (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazadar authored Jun 7, 2023
1 parent 737e3e2 commit 75104bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/payment/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export const localizedCurrencySelector = () => {
*/
export const getPropsToRemoveFractionZeroDigits = ({ price, shouldRemoveFractionZeroDigits }) => {
let props = {};
if (shouldRemoveFractionZeroDigits) {
if (shouldRemoveFractionZeroDigits && price !== null && price !== undefined) {
const fractionValue = price.toString().split('.')[1];
if (!fractionValue || parseInt(fractionValue, 10) === 0) {
// don't show 0's if fraction is 0
Expand Down
11 changes: 3 additions & 8 deletions src/subscription/details/SubscriptionDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
} from '@edx/frontend-platform/i18n';

import messages from '../../payment/cart/Cart.messages';
import { detailsSelector, currencyDisclaimerSelector } from '../data/details/selectors';
import { detailsSelector } from '../data/details/selectors';

import { CurrencyDisclaimer } from '../../payment/cart/CurrencyDisclaimer';
import OrderSummary from '../../payment/cart/OrderSummary';
import ProductLineItem from '../../payment/cart/ProductLineItem';

Expand All @@ -34,7 +33,6 @@ export const SubscriptionDetails = () => {
price,
programType,
currency,
isCurrencyConverted,
totalPrice,
isTrialEligible,
programUuid,
Expand Down Expand Up @@ -80,15 +78,12 @@ export const SubscriptionDetails = () => {
<SubscriptionSummaryTablePrice
price={price}
isTrialEligible={isTrialEligible}
currency={currency}
/>
<SubscriptionTotalTable
total={totalPrice}
currency={currency}
/>
{
isCurrencyConverted
? <CurrencyDisclaimer currencyDisclaimerSelector={currencyDisclaimerSelector} />
: null
}
</OrderSummary>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { FormattedMessage, FormattedNumber } from '@edx/frontend-platform/i18n';

import LocalizedPrice from '../../../payment/cart/LocalizedPrice';
import { getPropsToRemoveFractionZeroDigits } from '../../../payment/data/utils';

export const SubscriptionSummaryTablePrice = ({ price, isTrialEligible }) => (
export const SubscriptionSummaryTablePrice = ({ price, isTrialEligible, currency }) => (
<div className="summary-row d-flex">
<h4 className="flex-grow-1">
<FormattedMessage
Expand All @@ -14,7 +14,15 @@ export const SubscriptionSummaryTablePrice = ({ price, isTrialEligible }) => (
/>
</h4>
<h4 className="summary-price">
<LocalizedPrice amount={price} shouldRemoveFractionZeroDigits />
<FormattedNumber
value={price}
style="currency" // eslint-disable-line react/style-prop-object
currency={currency}
{...getPropsToRemoveFractionZeroDigits({
price,
shouldRemoveFractionZeroDigits: true,
})}
/>
{ isTrialEligible
? (
<FormattedMessage
Expand All @@ -37,10 +45,12 @@ export const SubscriptionSummaryTablePrice = ({ price, isTrialEligible }) => (
SubscriptionSummaryTablePrice.propTypes = {
price: PropTypes.number,
isTrialEligible: PropTypes.bool,
currency: PropTypes.string,
};
SubscriptionSummaryTablePrice.defaultProps = {
price: undefined,
isTrialEligible: false,
currency: 'USD',
};

export default SubscriptionSummaryTablePrice;
20 changes: 15 additions & 5 deletions src/subscription/details/total-table/SubscriptionTotalTable.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { FormattedMessage, FormattedNumber } from '@edx/frontend-platform/i18n';

import LocalizedPrice from '../../../payment/cart/LocalizedPrice';
import { getPropsToRemoveFractionZeroDigits } from '../../../payment/data/utils';

export const SubscriptionTotalTable = ({ total }) => (
export const SubscriptionTotalTable = ({ total, currency }) => (
<div className="summary-row font-weight-bold d-flex">
<FormattedMessage
id="subscription.summary.table.label.total.to.pay"
Expand All @@ -14,16 +14,26 @@ export const SubscriptionTotalTable = ({ total }) => (
{ text => <h4 className="flex-grow-1">{text}</h4>}
</FormattedMessage>
<h4 className="text-right">
<LocalizedPrice amount={total} shouldRemoveFractionZeroDigits />
<FormattedNumber
value={total}
style="currency" // eslint-disable-line react/style-prop-object
currency={currency}
{...getPropsToRemoveFractionZeroDigits({
price: total,
shouldRemoveFractionZeroDigits: true,
})}
/>
</h4>
</div>
);

SubscriptionTotalTable.propTypes = {
total: PropTypes.number,
currency: PropTypes.string,
};
SubscriptionTotalTable.defaultProps = {
total: undefined,
total: 0,
currency: 'USD',
};

export default SubscriptionTotalTable;

0 comments on commit 75104bc

Please sign in to comment.