Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price summary updates #1857

Merged
merged 5 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions support-frontend/assets/components/priceLabel/priceLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,35 @@
// ----- Imports ----- //

import React from 'react';
import { showPrice, applyDiscount, hasDiscount, type Price, type Promotion } from 'helpers/productPrice/productPrices';
import {
getAppliedPromo,
hasDiscount,
type ProductPrice,
showPrice,
} from 'helpers/productPrice/productPrices';
import type { BillingPeriod } from 'helpers/billingPeriods';
import { billingPeriodNoun } from 'helpers/billingPeriods';
import { getPriceDescription } from 'helpers/productPrice/priceDescriptions';

export type PropTypes = {
productPrice: Price,
promotion: ?Promotion,
productPrice: ProductPrice,
billingPeriod: BillingPeriod,
}
const displayPriceForPeriod = (productPrice: Price, billingPeriod: BillingPeriod) =>
`${showPrice(productPrice)}/${billingPeriodNoun(billingPeriod).toLowerCase()}`;

function PriceLabel({
productPrice, promotion, billingPeriod, ...props
productPrice, billingPeriod, ...props
}: PropTypes) {
const description = getPriceDescription(productPrice, billingPeriod, true);

const promotion = getAppliedPromo(productPrice.promotions);

if (hasDiscount(promotion)) {
return (
<span {...props}>
<del aria-hidden="true">{showPrice(productPrice)}</del>{' '}
{displayPriceForPeriod(applyDiscount(productPrice, promotion), billingPeriod)}
{description}
</span>);
}
return (<span {...props}>{displayPriceForPeriod(productPrice, billingPeriod)}</span>);
return (<span {...props}>{description}</span>);
}

export { PriceLabel };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { IsoCountry } from 'helpers/internationalisation/country';
import { fixDecimals } from 'helpers/subscriptions';
import type { Option } from 'helpers/types/option';
import { GBPCountries } from 'helpers/internationalisation/countryGroup';
import { getPromotion, regularPrice } from 'helpers/productPrice/productPrices';
import { getPromotion, getProductPrice } from 'helpers/productPrice/productPrices';

export type PropTypes = {
productPrices: ProductPrices,
Expand Down Expand Up @@ -73,7 +73,7 @@ function discountSummary(
function PromotionSummary(props: PropTypes) {
if (props.country) {
const { country } = props;
const productPrice = regularPrice(props.productPrices, country, props.billingPeriod);
const productPrice = getProductPrice(props.productPrices, country, props.billingPeriod);
const promotion = getPromotion(props.productPrices, country, props.billingPeriod);
if (promotion &&
promotion.discountedPrice &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type { IsoCountry } from 'helpers/internationalisation/country';
import type { FulfilmentOptions } from 'helpers/productPrice/fulfilmentOptions';
import { NoFulfilmentOptions } from 'helpers/productPrice/fulfilmentOptions';
import type { Action } from 'helpers/subscriptionsForms/formActions';
import { extendedGlyphForCountry } from 'helpers/internationalisation/currency';
import {
getAppliedPromoDescription,
getPriceDescription,
Expand Down Expand Up @@ -48,7 +47,6 @@ function BillingPeriodSelector(props: PropTypes) {
: <RadioInputWithHelper
text={billingPeriodTitle(billingPeriod)}
helper={getPriceDescription(
extendedGlyphForCountry(props.billingCountry),
productPrice,
billingPeriod,
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// @flow

import React, { Component } from 'react';
import { hasDiscount, type Price, type Promotion } from 'helpers/productPrice/productPrices';
import {
getAppliedPromo,
hasDiscount,
type ProductPrice,
type Promotion,
} from 'helpers/productPrice/productPrices';
import type { BillingPeriod } from 'helpers/billingPeriods';
import styles from './summary.module.scss';
import { PriceLabel } from 'components/priceLabel/priceLabel';
Expand All @@ -23,8 +28,7 @@ type PropTypes = {|
dataList: DataListItem[],
description: ?string,
image: $Call<GridImageType, GridImg>,
productPrice: Price,
promotion: ?Promotion,
productPrice: ProductPrice,
title: string,
// eslint-disable-next-line react/no-unused-prop-types
product: SubscriptionProduct,
Expand Down Expand Up @@ -99,10 +103,9 @@ const TabletAndDesktop = (props: PropTypes) => (
<PriceLabel
className={styles.pricing}
productPrice={props.productPrice}
promotion={props.promotion}
billingPeriod={props.billingPeriod}
/>
<PromotionDiscount promotion={props.promotion} />
<PromotionDiscount promotion={getAppliedPromo(props.productPrice.promotions)} />
{props.dataList ?
<DataList dataList={props.dataList} />
: null}
Expand All @@ -122,8 +125,7 @@ TabletAndDesktop.defaultProps = {
const HideDropDown = (props: {
billingPeriod: BillingPeriod,
onClick: Function,
productPrice: Price,
promotion: ?Promotion,
productPrice: ProductPrice,
showDropDown: boolean,
title: string,
paper: boolean,
Expand All @@ -138,7 +140,6 @@ const HideDropDown = (props: {
<PriceLabel
className={styles.pricing}
productPrice={props.productPrice}
promotion={props.promotion}
billingPeriod={props.billingPeriod}
/>
{props.paper ?
Expand Down Expand Up @@ -170,7 +171,6 @@ const ShowDropDown = (props: {
<PriceLabel
className={styles.data}
productPrice={props.productPrice}
promotion={props.promotion}
billingPeriod={props.billingPeriod}
/>
</div>
Expand Down
11 changes: 1 addition & 10 deletions support-frontend/assets/helpers/internationalisation/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { getQueryParameter } from 'helpers/url';
import {
type CountryGroup,
type CountryGroupId,
countryGroups, fromCountry, GBPCountries,
countryGroups,
} from './countryGroup';
import type { IsoCountry } from 'helpers/internationalisation/country';


// ----- Types ----- //

Expand Down Expand Up @@ -133,12 +131,6 @@ function detect(countryGroup: CountryGroupId): IsoCurrency {
const glyph = (c: IsoCurrency): string => currencies[c].glyph;
const extendedGlyph = (c: IsoCurrency): string => currencies[c].extendedGlyph;

const extendedGlyphForCountry = (country: IsoCountry) => {
const currency = fromCountryGroupId(fromCountry(country) || GBPCountries);
return extendedGlyph(currency || 'GBP');
};


// ----- Exports ----- //

export {
Expand All @@ -148,5 +140,4 @@ export {
currencies,
glyph,
extendedGlyph,
extendedGlyphForCountry,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('getPriceDescription', () => {
it('should return a price based on inputs', () => {
const gwAnnual = {
price: 150,
currency: 'GBP',
promotions: [
{
name: '10% Off Annual Guardian Weekly Subs',
Expand All @@ -23,15 +24,16 @@ describe('getPriceDescription', () => {
discount: { amount: 10, durationMonths: 12 },
}],
};
expect(getPriceDescription('£', gwAnnual, Annual))
expect(getPriceDescription(gwAnnual, Annual))
.toEqual('£135 for 1 year, then standard rate (£150 every year)');

const gwQuarterly = { price: 37.5, promotions: [] };
expect(getPriceDescription('£', gwQuarterly, Quarterly))
const gwQuarterly = { price: 37.5, currency: 'GBP', promotions: [] };
expect(getPriceDescription(gwQuarterly, Quarterly))
.toEqual('£37.50 every quarter');

const gwQuarterlyWithPromo = {
price: 37.5,
currency: 'GBP',
promotions: [
{
name: '15% discount - WJWGEX9A8',
Expand All @@ -40,19 +42,23 @@ describe('getPriceDescription', () => {
discountedPrice: 31.87,
numberOfDiscountedPeriods: 1,
discount: { amount: 15, durationMonths: 3 },
},
}],
};
expect(getPriceDescription(gwQuarterlyWithPromo, Quarterly))
.toEqual('£31.87 for 1 quarter, then standard rate (£37.50 every quarter)');

const gwSixWeekly = {
price: 81.30,
currency: 'USD',
promotions: [
{
name: 'Six For Six',
description: 'Introductory offer',
promoCode: '6FOR6',
introductoryPrice: { price: 6, periodLength: 6, periodType: 'issue' },
}],
};
expect(getPriceDescription('£', gwQuarterlyWithPromo, Quarterly))
.toEqual('£31.87 for 1 quarter, then standard rate (£37.50 every quarter)');

const gwSixWeekly = { price: 81.30, promotions: [] };
expect(getPriceDescription('US$', gwSixWeekly, SixWeekly))
expect(getPriceDescription(gwSixWeekly, SixWeekly))
.toEqual('US$6 for the first 6 issues (then US$81.30 every quarter)');
});
});
Loading