Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
[MM-36235] - Do not allow to downgrade cloud plans (#8268)
Browse files Browse the repository at this point in the history
* MM-36341 - order plan lists

* [MM-36235] - Do not allow to downgrade cloud plans

* update purchase_modal.tsx

* rem console.log

Co-authored-by: Pablo Velez Vidal <pablo.velez@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 13, 2021
1 parent adbbd3e commit 9585d86
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions components/purchase_modal/purchase_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ import 'components/payment_form/payment_form.scss';

let stripePromise: Promise<Stripe | null>;

type Option = {
key: string;
value: string;
price: number;
};

type ProductOptions = Option[];

type Props = {
customer: CloudCustomer | undefined;
show: boolean;
Expand Down Expand Up @@ -184,26 +192,36 @@ export default class PurchaseModal extends React.PureComponent<Props, State> {
</a>
);

onPlanSelected = (e: React.ChangeEvent<HTMLInputElement>) => {
onPlanSelected = (e: React.ChangeEvent<HTMLInputElement>): void => {
const selectedPlan = findProductInDictionary(this.props.products, e.target.value);

this.setState({selectedProduct: selectedPlan});
}

listPlans = () => {
listPlans = (): JSX.Element => {
const products = this.props.products!;
const flatFeeProducts: any = [];
const userBasedProducts: any = [];
const flatFeeProducts: ProductOptions = [];
const userBasedProducts: ProductOptions = [];
Object.keys(products).forEach((key: string) => {
const tempEl = {key: products[key].name, value: products[key].id, price: products[key].price_per_seat};
const tempEl: Option = {key: products[key].name, value: products[key].id, price: products[key].price_per_seat};
if (products[key].billing_scheme === BillingSchemes.FLAT_FEE) {
flatFeeProducts.push(tempEl);
} else {
userBasedProducts.push(tempEl);
}
});

const options = [...flatFeeProducts.sort((a: any, b: any) => a.price - b.price), ...userBasedProducts.sort((a: any, b: any) => a.price - b.price)];
let options = [...flatFeeProducts.sort((a: Option, b: Option) => a.price - b.price), ...userBasedProducts.sort((a: Option, b: Option) => a.price - b.price)];

const currentPrice = this.state.currentProduct?.price_per_seat;

// if not on trial, only show current plan and those higher than it in terms of price
if (!this.props.isFreeTrial && currentPrice) {
options = options.filter((option: Option) => {
return option.price >= currentPrice;
});
}

const sideLegendTitle = (
<FormattedMessage
defaultMessage={'(Current Plan)'}
Expand All @@ -218,7 +236,7 @@ export default class PurchaseModal extends React.PureComponent<Props, State> {
values={options!}
value={this.state.selectedProduct?.id as string}
sideLegend={{matchVal: this.state.currentProduct?.id as string, text: sideLegendTitle}}
onChange={(e: any) => this.onPlanSelected(e)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => this.onPlanSelected(e)}
/>
</div>
);
Expand Down Expand Up @@ -397,7 +415,7 @@ export default class PurchaseModal extends React.PureComponent<Props, State> {
</div>
<div className='RHS'>
<div className='price-container'>
{(this.props.isFreeTrial && this.props.products && Object.keys(this.props.products).length > 1) &&
{(this.props.products && Object.keys(this.props.products).length > 1) &&
<div className='select-plan'>
<div className='title'>
<FormattedMessage
Expand Down

0 comments on commit 9585d86

Please sign in to comment.