From f78cd44af61b9ed99a04149b25f6c0bb1029e165 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 19 Sep 2018 12:29:07 +0200 Subject: SONARCLOUD-121 display coupon's billing info (#720) --- server/sonar-web/src/main/js/app/types.ts | 12 +++++ .../apps/create/organization/BillingFormShim.tsx | 4 +- .../js/apps/create/organization/CouponForm.tsx | 56 ++++++++++++++++++---- .../__snapshots__/CouponForm-test.tsx.snap | 2 + 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/server/sonar-web/src/main/js/app/types.ts b/server/sonar-web/src/main/js/app/types.ts index 1ddd5c5e0d5..435f7206b0f 100644 --- a/server/sonar-web/src/main/js/app/types.ts +++ b/server/sonar-web/src/main/js/app/types.ts @@ -161,6 +161,18 @@ export interface CoveredFile { coveredLines: number; } +export interface Coupon { + billing?: { + address?: string; + country?: string; + email?: string; + name?: string; + use?: string; + }; + maxNcloc: number; + planActiveUntil: string; +} + export interface CurrentUser { isLoggedIn: boolean; permissions?: { global: string[] }; diff --git a/server/sonar-web/src/main/js/apps/create/organization/BillingFormShim.tsx b/server/sonar-web/src/main/js/apps/create/organization/BillingFormShim.tsx index 8c83ec676b3..bfa9c544027 100644 --- a/server/sonar-web/src/main/js/apps/create/organization/BillingFormShim.tsx +++ b/server/sonar-web/src/main/js/apps/create/organization/BillingFormShim.tsx @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import { CurrentUser, SubscriptionPlan } from '../../../app/types'; +import { CurrentUser, SubscriptionPlan, Coupon } from '../../../app/types'; interface ChildrenProps { alertError: string | undefined; @@ -45,7 +45,9 @@ interface Props { currentUser: CurrentUser; onClose: () => void; onCommit: () => void; + onCouponUpdate?: (coupon?: Coupon) => void; organizationKey: string | (() => Promise); + skipBraintreeInit?: boolean; subscriptionPlans: SubscriptionPlan[]; } diff --git a/server/sonar-web/src/main/js/apps/create/organization/CouponForm.tsx b/server/sonar-web/src/main/js/apps/create/organization/CouponForm.tsx index 4747165561d..f4ff3832680 100644 --- a/server/sonar-web/src/main/js/apps/create/organization/CouponForm.tsx +++ b/server/sonar-web/src/main/js/apps/create/organization/CouponForm.tsx @@ -21,7 +21,7 @@ import * as React from 'react'; import * as classNames from 'classnames'; import BillingFormShim from './BillingFormShim'; import { withCurrentUser } from './withCurrentUser'; -import { CurrentUser } from '../../../app/types'; +import { CurrentUser, Coupon } from '../../../app/types'; import { translate } from '../../../helpers/l10n'; import DocTooltip from '../../../components/docs/DocTooltip'; @@ -31,11 +31,39 @@ interface Props { onSubmit: () => void; } -export class CouponForm extends React.PureComponent { +interface State { + coupon?: Coupon; +} + +export class CouponForm extends React.PureComponent { + state: State = {}; + handleClose = () => { // do nothing }; + handleCouponUpdate = (coupon?: Coupon) => { + this.setState({ coupon }); + }; + + renderBillingInformation() { + if (!this.state.coupon || !this.state.coupon.billing) { + return null; + } + const { billing } = this.state.coupon; + return ( +
+

{translate('billing.upgrade.billing_info')}

+
    + {Boolean(billing.name) &&
  • {billing.name}
  • } + {Boolean(billing.address) &&
  • {billing.address}
  • } + {Boolean(billing.country) &&
  • {billing.country}
  • } + {Boolean(billing.email) &&
  • {billing.email}
  • } +
+
+ ); + } + render() { return (
@@ -43,11 +71,12 @@ export class CouponForm extends React.PureComponent { currentUser={this.props.currentUser} onClose={this.handleClose} onCommit={this.props.onSubmit} + onCouponUpdate={this.handleCouponUpdate} organizationKey={this.props.createOrganization} + skipBraintreeInit={true} subscriptionPlans={[]}> {form => (
-
{form.renderBraintreeClient()}
{form.renderCouponInput( )} -

{translate('billing.upgrade.billing_info')}

- {form.renderEmailInput()} - {form.renderTypeOfUseSelect()} - {form.renderBillingNameInput()} - {form.renderCountrySelect()} - {form.renderAdditionalInfo()} + {this.renderBillingInformation()} + {this.state.coupon && + !this.state.coupon.billing && ( + <> +

{translate('billing.upgrade.billing_info')}

+ {form.renderEmailInput()} + {form.renderTypeOfUseSelect()} + {form.renderBillingNameInput()} + {form.renderCountrySelect()} + {form.renderAdditionalInfo()} + + )} + {this.state.coupon && ( +
{form.renderNextCharge()}
+ )} {form.alertError &&

{form.alertError}

}
{form.renderSpinner()} diff --git a/server/sonar-web/src/main/js/apps/create/organization/__tests__/__snapshots__/CouponForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/create/organization/__tests__/__snapshots__/CouponForm-test.tsx.snap index 738f9080adb..b9a3b2a5356 100644 --- a/server/sonar-web/src/main/js/apps/create/organization/__tests__/__snapshots__/CouponForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/create/organization/__tests__/__snapshots__/CouponForm-test.tsx.snap @@ -12,7 +12,9 @@ exports[`should render 1`] = ` } onClose={[Function]} onCommit={[MockFunction]} + onCouponUpdate={[Function]} organizationKey={[MockFunction]} + skipBraintreeInit={true} subscriptionPlans={Array []} />
-- cgit v1.2.3