Skip to content

Commit

Permalink
build: add 2K plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jul 1, 2019
1 parent 0fb3153 commit 8e07209
Showing 1 changed file with 20 additions and 36 deletions.
56 changes: 20 additions & 36 deletions src/components/elements/PricePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -54,15 +42,11 @@ export default class extends Component {
<Select
mx='auto'
width={['3.2rem', '3.8rem']}
value={this.state.reqs}
value={this.state.humanReqsPerDay}
onChange={this.handleChange}
>
{Object.keys(PLANS).map(plan => (
<option
key={plan}
value={plan}
children={PLANS[plan].humanReqsPerDay}
/>
<option key={plan}>{PLANS[plan].humanReqsPerDay}</option>
))}
</Select>
<Label ml={1} display='inline' children=' reqs' suffix='/day' />
Expand Down

0 comments on commit 8e07209

Please sign in to comment.