0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Added discount to Account/Plan page

no refs.
- moved discount calculation to util
- added discount to account/plan page to make it consistent with signup
This commit is contained in:
Peter Zimon 2020-07-29 12:35:19 +02:00
parent 6af7ab674a
commit 9efede024a
4 changed files with 16 additions and 3 deletions

View file

@ -143,7 +143,7 @@ export default class App extends React.Component {
showPopup: true,
site: Fixtures.site,
member: Fixtures.member.paid,
page: 'links'
page: 'accountPlan'
};
}
return {};

View file

@ -1,6 +1,7 @@
import AppContext from '../../AppContext';
import ActionButton from '../common/ActionButton';
import PlansSection from '../common/PlansSection';
import CalculateDiscount from '../../utils/discount';
const React = require('react');
@ -123,6 +124,7 @@ export default class AccountPlanPage extends React.Component {
renderPlanChooser() {
const {plans} = this.context.site;
const discount = CalculateDiscount(plans.monthly, plans.yearly);
const plansData = [
{
type: 'month',
@ -134,7 +136,8 @@ export default class AccountPlanPage extends React.Component {
type: 'year',
price: plans.yearly,
currency: plans.currency_symbol,
name: 'Yearly'
name: 'Yearly',
discount
}
];
return (

View file

@ -3,6 +3,7 @@ import AppContext from '../../AppContext';
import PlansSection from '../common/PlansSection';
import InputForm from '../common/InputForm';
import {ValidateInputForm} from '../../utils/form';
import CalculateDiscount from '../../utils/discount';
const React = require('react');
@ -170,7 +171,7 @@ class SignupPage extends React.Component {
} = this.context.site;
const plansData = [];
const discount = plans.monthly ? 100 - Math.round((plans.yearly / 12 * 100) / plans.monthly) : 0;
const discount = CalculateDiscount(plans.monthly, plans.yearly);
const stripePlans = [
{
type: 'month',

View file

@ -0,0 +1,9 @@
function calculateDiscount(monthly, yearly) {
if (isNaN(monthly) || isNaN(yearly)) {
return 0;
}
return monthly ? 100 - Math.round((yearly / 12 * 100) / monthly) : 0;
}
module.exports = calculateDiscount;