Skip to content

Commit a3b8523

Browse files
authored
ref(admin): Convert contractSelect to a FC (#104505)
1 parent ac52c44 commit a3b8523

File tree

1 file changed

+67
-78
lines changed

1 file changed

+67
-78
lines changed

static/gsApp/views/amCheckout/steps/contractSelect.tsx

Lines changed: 67 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {Component} from 'react';
21
import styled from '@emotion/styled';
32

43
import {Alert} from 'sentry/components/core/alert';
@@ -16,75 +15,75 @@ import StepHeader from 'getsentry/views/amCheckout/components/stepHeader';
1615
import type {StepProps} from 'getsentry/views/amCheckout/types';
1716
import {formatPrice, getReservedPriceCents} from 'getsentry/views/amCheckout/utils';
1817

19-
type Props = StepProps;
20-
21-
class ContractSelect extends Component<Props> {
22-
get title() {
23-
return t('Contract Term & Discounts');
24-
}
18+
const isAnnual = (plan: Plan) => {
19+
return plan.billingInterval === ANNUAL;
20+
};
21+
22+
const getOptionName = (isAnnualPlan: boolean) => {
23+
return isAnnualPlan ? t('Annual Contract') : t('Monthly');
24+
};
25+
26+
const getPriceHeader = (isAnnualPlan: boolean) => {
27+
return tct('Per [billingInterval]', {
28+
billingInterval: isAnnualPlan ? 'year' : 'month',
29+
});
30+
};
31+
32+
function ContractSelect({
33+
formData,
34+
subscription,
35+
promotion,
36+
billingConfig,
37+
stepNumber,
38+
isActive,
39+
isCompleted,
40+
onUpdate,
41+
onEdit,
42+
onCompleteStep,
43+
}: StepProps) {
44+
const title = t('Contract Term & Discounts');
2545

2646
/**
2747
* Filter for monthly and annual billing intervals
2848
* of the same base plan. AM1 plans can either be
2949
* monthly or annual-up-front.
3050
*/
31-
get planOptions() {
32-
const {billingConfig, formData} = this.props;
51+
const getPlanOptions = () => {
3352
const basePlan = formData.plan.replace('_auf', '');
3453
const plans = billingConfig.planList.filter(({id}) => id.indexOf(basePlan) === 0);
3554

3655
if (!plans) {
3756
throw new Error('Cannot get billing interval options');
3857
}
3958
return plans;
40-
}
41-
42-
get annualContractWarning() {
43-
return (
44-
<ContractAlert type="info">
45-
{t(
46-
'You are currently on an annual contract so any subscription downgrades will take effect at the end of your contract period.'
47-
)}
48-
</ContractAlert>
49-
);
50-
}
51-
52-
isAnnual(plan: Plan) {
53-
return plan.billingInterval === ANNUAL;
54-
}
55-
56-
getOptionName(isAnnual: boolean) {
57-
return isAnnual ? t('Annual Contract') : t('Monthly');
58-
}
59+
};
5960

60-
getDescription(isAnnual: boolean) {
61-
const {billingConfig} = this.props;
61+
const annualContractWarning = (
62+
<ContractAlert type="info">
63+
{t(
64+
'You are currently on an annual contract so any subscription downgrades will take effect at the end of your contract period.'
65+
)}
66+
</ContractAlert>
67+
);
6268

63-
return isAnnual
69+
const getDescription = (isAnnualPlan: boolean) => {
70+
return isAnnualPlan
6471
? tct('Save an additional [annualDiscount]% by committing to a 12-month plan', {
6572
annualDiscount: billingConfig.annualDiscount * 100,
6673
})
6774
: t('Month-to-month contract');
68-
}
69-
70-
getPriceHeader(isAnnual: boolean) {
71-
return tct('Per [billingInterval]', {
72-
billingInterval: isAnnual ? 'year' : 'month',
73-
});
74-
}
75-
76-
renderBody = () => {
77-
const {onUpdate, formData, subscription, promotion} = this.props;
75+
};
7876

77+
const renderBody = () => {
7978
return (
80-
<PanelBody data-test-id={this.title}>
81-
{this.planOptions.map(plan => {
79+
<PanelBody data-test-id={title}>
80+
{getPlanOptions().map(plan => {
8281
const isSelected = plan.id === formData.plan;
8382

84-
const isAnnual = this.isAnnual(plan);
85-
const name = this.getOptionName(isAnnual);
86-
const description = this.getDescription(isAnnual);
87-
const priceHeader = this.getPriceHeader(isAnnual);
83+
const isAnnualPlan = isAnnual(plan);
84+
const name = getOptionName(isAnnualPlan);
85+
const description = getDescription(isAnnualPlan);
86+
const priceHeader = getPriceHeader(isAnnualPlan);
8887

8988
const hasWarning =
9089
isSelected &&
@@ -128,7 +127,7 @@ class ContractSelect extends Component<Props> {
128127
planValue={plan.billingInterval}
129128
planContent={{description, features: {}}}
130129
priceHeader={priceHeader}
131-
planWarning={hasWarning ? this.annualContractWarning : undefined}
130+
planWarning={hasWarning ? annualContractWarning : undefined}
132131
shouldShowDefaultPayAsYouGo={false}
133132
shouldShowEventPrice={false}
134133
price={formattedPriceAfterDiscount}
@@ -139,36 +138,26 @@ class ContractSelect extends Component<Props> {
139138
);
140139
};
141140

142-
renderFooter = () => {
143-
const {stepNumber, onCompleteStep} = this.props;
144-
145-
return (
146-
<StepFooter data-test-id={this.title}>
147-
<Button priority="primary" onClick={() => onCompleteStep(stepNumber)}>
148-
{t('Continue')}
149-
</Button>
150-
</StepFooter>
151-
);
152-
};
153-
154-
render() {
155-
const {isActive, stepNumber, isCompleted, onEdit} = this.props;
156-
157-
return (
158-
<Panel>
159-
<StepHeader
160-
canSkip
161-
title={this.title}
162-
isActive={isActive}
163-
stepNumber={stepNumber}
164-
isCompleted={isCompleted}
165-
onEdit={onEdit}
166-
/>
167-
{isActive && this.renderBody()}
168-
{isActive && this.renderFooter()}
169-
</Panel>
170-
);
171-
}
141+
return (
142+
<Panel>
143+
<StepHeader
144+
canSkip
145+
title={title}
146+
isActive={isActive}
147+
stepNumber={stepNumber}
148+
isCompleted={isCompleted}
149+
onEdit={onEdit}
150+
/>
151+
{isActive && renderBody()}
152+
{isActive && (
153+
<StepFooter data-test-id={title}>
154+
<Button priority="primary" onClick={() => onCompleteStep(stepNumber)}>
155+
{t('Continue')}
156+
</Button>
157+
</StepFooter>
158+
)}
159+
</Panel>
160+
);
172161
}
173162

174163
const ContractAlert = styled(Alert)`

0 commit comments

Comments
 (0)