Skip to content

Commit

Permalink
[MM-28714] Check if subscription is paid before showing any upgrade w…
Browse files Browse the repository at this point in the history
…arnings (mattermost#6705)

Co-authored-by: marianunez <[email protected]>
  • Loading branch information
nickmisasi and marianunez committed Oct 12, 2020
1 parent 476d05c commit bf35a10
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions components/announcement_bar/cloud_announcement_bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general
import {GenericAction} from 'mattermost-redux/types/actions';
import {getStandardAnalytics} from 'mattermost-redux/actions/admin';
import {makeGetCategory} from 'mattermost-redux/selectors/entities/preferences';
import {getCloudSubscription} from 'mattermost-redux/actions/cloud';

import {getCurrentUser, isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users';

Expand All @@ -28,6 +29,7 @@ function mapStateToProps(state: GlobalState) {
userIsAdmin: isCurrentUserSystemAdmin(state),
currentUser: getCurrentUser(state),
isCloud: getLicense(state).Cloud === 'true',
subscription: state.entities.cloud.subscription,
preferences: getCategory(state, Preferences.CLOUD_UPGRADE_BANNER),
};
}
Expand All @@ -39,6 +41,7 @@ function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
savePreferences,
getStandardAnalytics,
openModal,
getCloudSubscription,
},
dispatch,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {PreferenceType} from 'mattermost-redux/types/preferences';
import {UserProfile} from 'mattermost-redux/types/users';
import {Dictionary} from 'mattermost-redux/types/utilities';
import {AnalyticsRow} from 'mattermost-redux/types/admin';
import {Subscription} from 'mattermost-redux/types/cloud';
import {isEmpty} from 'lodash';

import {t} from 'utils/i18n';
Expand All @@ -28,10 +29,12 @@ type Props = {
preferences: PreferenceType[];
isCloud: boolean;
analytics?: Dictionary<number | AnalyticsRow[]>;
subscription?: Subscription;
actions: {
savePreferences: (userId: string, preferences: PreferenceType[]) => void;
getStandardAnalytics: () => void;
openModal: (modalData: {modalId: string; dialogType: any; dialogProps?: any}) => void;
getCloudSubscription: () => void;
openModal: (modalData: { modalId: string; dialogType: any; dialogProps?: any }) => void;
};
};

Expand All @@ -40,6 +43,10 @@ export default class UserLimitAnnouncementBar extends React.PureComponent<Props>
if (isEmpty(this.props.analytics)) {
await this.props.actions.getStandardAnalytics();
}

if (isEmpty(this.props.subscription)) {
await this.props.actions.getCloudSubscription();
}
}

handleButtonClick = () => {
Expand All @@ -56,7 +63,17 @@ export default class UserLimitAnnouncementBar extends React.PureComponent<Props>
}

shouldShowBanner = () => {
const {userLimit, analytics, userIsAdmin, isCloud} = this.props;
const {userLimit, analytics, userIsAdmin, isCloud, subscription} = this.props;

// Prevents banner flashes if the subscription hasn't been loaded yet
if (subscription === null) {
return false;
}

if (subscription?.is_paid_tier === 'true') {
return false;
}

if (!isCloud) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions components/main_menu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {haveITeamPermission, haveICurrentTeamPermission, haveISystemPermission} from 'mattermost-redux/selectors/entities/roles';
import {Permissions} from 'mattermost-redux/constants';
import {getCloudSubscription} from 'mattermost-redux/actions/cloud';

import {isAdmin} from 'utils/utils.jsx';

Expand Down Expand Up @@ -103,6 +104,7 @@ function mapStateToProps(state) {
showGettingStarted: showOnboarding(state),
showNextStepsTips: showNextStepsTips(state),
showNextSteps: showNextSteps(state),
subscription: state.entities.cloud.subscription,
};
}

Expand All @@ -115,6 +117,7 @@ function mapDispatchToProps(dispatch) {
closeRightHandSide,
closeRhsMenu,
unhideNextSteps,
getCloudSubscription,
}, dispatch),
};
}
Expand Down
13 changes: 12 additions & 1 deletion components/main_menu/main_menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import React from 'react';
import {injectIntl} from 'react-intl';
import {Permissions} from 'mattermost-redux/constants';

import {isEmpty} from 'lodash';

import * as GlobalActions from 'actions/global_actions.jsx';
import {Constants, ModalIdentifiers} from 'utils/constants';
import {intlShape} from 'utils/react_intl';
Expand Down Expand Up @@ -66,13 +68,15 @@ class MainMenu extends React.PureComponent {
showGettingStarted: PropTypes.bool.isRequired,
intl: intlShape.isRequired,
showNextStepsTips: PropTypes.bool,
subscription: PropTypes.object,
actions: PropTypes.shape({
openModal: PropTypes.func.isRequred,
showMentions: PropTypes.func,
showFlaggedPosts: PropTypes.func,
closeRightHandSide: PropTypes.func.isRequired,
closeRhsMenu: PropTypes.func.isRequired,
unhideNextSteps: PropTypes.func.isRequired,
getCloudSubscription: PropTypes.func,
}).isRequired,
};

Expand All @@ -87,8 +91,11 @@ class MainMenu extends React.PureComponent {
GlobalActions.toggleShortcutsModal();
}

componentDidMount() {
async componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown);
if (isEmpty(this.props.subscription)) {
await this.props.actions.getCloudSubscription();
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -123,6 +130,10 @@ class MainMenu extends React.PureComponent {
}

shouldShowUpgradeModal = () => {
if (this.props.subscription?.is_paid_tier === 'true') { // eslint-disable-line camelcase
return false;
}

return (this.props.currentUsers >= this.props.userLimit) && (this.props.userLimit !== '0') && this.props.userIsAdmin;
}

Expand Down

0 comments on commit bf35a10

Please sign in to comment.