From 8e07209a53dd67f9970d7ee346032a5276823637 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 1 Jul 2019 23:10:48 +0200 Subject: [PATCH] build: add 2K plan --- src/components/elements/PricePicker.js | 56 +++++++++----------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/src/components/elements/PricePicker.js b/src/components/elements/PricePicker.js index 3203b31de..414acf0d8 100644 --- a/src/components/elements/PricePicker.js +++ b/src/components/elements/PricePicker.js @@ -2,48 +2,36 @@ import React, { Component } from 'react' import { Box, Select, Label } from 'components/elements' import humanNumber from 'human-number' +const createReqsLabels = reqsPerDay => ({ + reqsPerDay, + humanReqsPerDay: humanNumber(reqsPerDay), + monthlyPrice: calculateMonthlyPrice(reqsPerDay) +}) + const calculateMonthlyPrice = reqsPerDay => (reqsPerDay / 1000) * BASE_PLAN_PRICE export const BASE_PLAN_PRICE = 12 -export const BASE_PLAN_REQS = 1000 - -export const DEFAULT_PLAN = { - planId: 'pro-1k-v2', - reqsPerDay: BASE_PLAN_REQS, - humanReqsPerDay: humanNumber(BASE_PLAN_REQS), - monthlyPrice: calculateMonthlyPrice(BASE_PLAN_REQS) -} +export const PLANS = [ + { planId: 'pro-1k-v2', ...createReqsLabels(1000) }, + { planId: 'pro-2k-v2', ...createReqsLabels(2000) }, + { planId: 'pro-3k-v2', ...createReqsLabels(3000) }, + { planId: 'pro-10k-v2', ...createReqsLabels(10000) }, + { planId: 'pro-50k-v2', ...createReqsLabels(50000) } +] -export const PLANS = [DEFAULT_PLAN] - .concat([ - { planId: 'pro-3k-v2', reqsPerDay: 3000 }, - { planId: 'pro-10k-v2', reqsPerDay: 10000 }, - { planId: 'pro-50k-v2', reqsPerDay: 50000 }, - { planId: 'pro-100k-v2', reqsPerDay: 100000 }, - { planId: 'pro-500k-v2', reqsPerDay: 500000 }, - { planId: 'pro-1m-v2', reqsPerDay: 1000000 } - ]) - .reduce( - (acc, { planId, reqsPerDay }) => ({ - ...acc, - [reqsPerDay]: { - planId, - humanReqsPerDay: humanNumber(reqsPerDay), - monthlyPrice: calculateMonthlyPrice(reqsPerDay) - } - }), - {} - ) +export const DEFAULT_PLAN = PLANS[1] export default class extends Component { state = { ...DEFAULT_PLAN } handleChange = event => { event.preventDefault() - const { value: reqsPerDay } = event.target - const newState = { reqsPerDay, ...PLANS[reqsPerDay] } + const { value: humanReqsPerDay } = event.target + const newState = PLANS.find( + plan => plan.humanReqsPerDay === humanReqsPerDay + ) this.setState(newState) this.props.onChange(newState) } @@ -54,15 +42,11 @@ export default class extends Component {