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

Commit

Permalink
[MM-50534] - Consume modified API for getting license renewal/expand …
Browse files Browse the repository at this point in the history
…status (#12263)

* [MM-50534] - Consume modified API for getting license renewal/expand status

* rename reducer

* missing client func

* add meaningful names

* use renamed endpoint
  • Loading branch information
AGMETEOR authored Mar 3, 2023
1 parent 40e42e3 commit 630b3dc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {LicenseLinks, OverActiveUserLimits, Preferences, StatTypes} from 'utils/
import {renderWithIntlAndStore} from 'tests/react_testing_utils';
import {savePreferences} from 'mattermost-redux/actions/preferences';
import {trackEvent} from 'actions/telemetry_actions';
import {getLicenseExpandStatus} from 'mattermost-redux/actions/cloud';
import {getLicenseSelfServeStatus} from 'mattermost-redux/actions/cloud';
import {TestHelper} from 'utils/test_helper';
import {generateId} from 'utils/utils';

Expand All @@ -34,7 +34,7 @@ jest.mock('mattermost-redux/actions/preferences', () => ({
}));

jest.mock('mattermost-redux/actions/cloud', () => ({
getLicenseExpandStatus: jest.fn(),
getLicenseSelfServeStatus: jest.fn(),
}));

jest.mock('actions/telemetry_actions', () => ({
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('components/overage_users_banner', () => {
renderComponent();

expect(screen.queryByText('Your workspace user count has exceeded your paid license seat count by', {exact: false})).not.toBeInTheDocument();
expect(getLicenseExpandStatus).not.toBeCalled();
expect(getLicenseSelfServeStatus).not.toBeCalled();
});

it('should not render the banner because we are not admins', () => {
Expand All @@ -152,7 +152,7 @@ describe('components/overage_users_banner', () => {
});

expect(screen.queryByText('Your workspace user count has exceeded your paid license seat count by', {exact: false})).not.toBeInTheDocument();
expect(getLicenseExpandStatus).not.toBeCalled();
expect(getLicenseSelfServeStatus).not.toBeCalled();
});

it('should not render the banner because it\'s cloud licenese', () => {
Expand All @@ -168,7 +168,7 @@ describe('components/overage_users_banner', () => {
});

expect(screen.queryByText('Your workspace user count has exceeded your paid license seat count by', {exact: false})).not.toBeInTheDocument();
expect(getLicenseExpandStatus).not.toBeCalled();
expect(getLicenseSelfServeStatus).not.toBeCalled();
});

it('should not render the 5% banner because we have dissmised it', () => {
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('components/overage_users_banner', () => {
});

expect(screen.queryByText(text5PercentageState)).not.toBeInTheDocument();
expect(getLicenseExpandStatus).not.toBeCalled();
expect(getLicenseSelfServeStatus).not.toBeCalled();
});

it('should render the banner because we are over 5% and we don\'t have any preferences', () => {
Expand Down
26 changes: 13 additions & 13 deletions components/common/hooks/useExpandOverageUsersCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {useIntl} from 'react-intl';
import {useDispatch, useSelector} from 'react-redux';

import {GlobalState} from 'types/store';
import {LicenseExpandReducer} from '@mattermost/types/cloud';

import {trackEvent} from 'actions/telemetry_actions.jsx';
import {getExpandSeatsLink} from 'selectors/cloud';
import {getLicenseExpandStatus} from 'mattermost-redux/actions/cloud';
import {getLicenseSelfServeStatus} from 'mattermost-redux/actions/cloud';

import {LicenseSelfServeStatusReducer} from '@mattermost/types/cloud';

type UseExpandOverageUsersCheckArgs = {
isWarningState: boolean;
Expand All @@ -26,18 +28,16 @@ export const useExpandOverageUsersCheck = ({
}: UseExpandOverageUsersCheckArgs) => {
const {formatMessage} = useIntl();
const dispatch = useDispatch();
const {getRequestState, is_expandable: isExpandable}: LicenseExpandReducer = useSelector((state: GlobalState) => state.entities.cloud.subscriptionStats || {is_expandable: false, getRequestState: 'IDLE'});
const {getRequestState, is_expandable: isExpandable}: LicenseSelfServeStatusReducer = useSelector((state: GlobalState) => state.entities.cloud.subscriptionStats || {is_expandable: false, getRequestState: 'IDLE'});
const expandableLink = useSelector(getExpandSeatsLink);

const cta = useMemo(() => (isExpandable ?
formatMessage({
id: 'licensingPage.overageUsersBanner.ctaExpandSeats',
defaultMessage: 'Purchase additional seats',
}) :
formatMessage({
id: 'licensingPage.overageUsersBanner.cta',
defaultMessage: 'Contact Sales',
})
const cta = useMemo(() => (isExpandable ? formatMessage({
id: 'licensingPage.overageUsersBanner.ctaExpandSeats',
defaultMessage: 'Purchase additional seats',
}) : formatMessage({
id: 'licensingPage.overageUsersBanner.cta',
defaultMessage: 'Contact Sales',
})
), [isExpandable]);

const trackEventFn = (cta: 'Contact Sales' | 'Self Serve') => {
Expand All @@ -49,7 +49,7 @@ export const useExpandOverageUsersCheck = ({

useEffect(() => {
if (shouldRequest && licenseId && getRequestState === 'IDLE') {
dispatch(getLicenseExpandStatus());
dispatch(getLicenseSelfServeStatus());
}
}, [dispatch, getRequestState, licenseId, shouldRequest]);

Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/client4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
NotifyAdminRequest,
Subscription,
ValidBusinessEmail,
LicenseExpandStatus,
LicenseSelfServeStatus,
CreateSubscriptionRequest,
Feedback,
WorkspaceDeletionRequest,
Expand Down Expand Up @@ -3905,9 +3905,9 @@ export default class Client4 {
);
}

getLicenseExpandStatus = () => {
return this.doFetch<LicenseExpandStatus>(
`${this.getCloudRoute()}/subscription/expand`, {method: 'get'},
getLicenseSelfServeStatus = () => {
return this.doFetch<LicenseSelfServeStatus>(
`${this.getCloudRoute()}/subscription/self-serve-status`, {method: 'get'},
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/mattermost-redux/src/action_types/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ export default keyMirror({
RECEIVED_FILES_USAGE: null,
RECEIVED_BOARDS_USAGE: null,
RECEIVED_TEAMS_USAGE: null,
RECEIVED_CLOUD_EXPAND_STATS: null,
RECEIVED_LICENSE_SELF_SERVE_STATS: null,

CLOUD_CUSTOMER_FAILED: null,
CLOUD_INVOICES_FAILED: null,
CLOUD_LIMITS_FAILED: null,
CLOUD_PRODUCTS_FAILED: null,
CLOUD_SUBSCRIPTION_FAILED: null,
CLOUD_EXPAND_STATS_FAILED: null,
LICENSE_SELF_SERVE_STATS_FAILED: null,

CLOUD_CUSTOMER_REQUEST: null,
CLOUD_INVOICES_REQUEST: null,
CLOUD_LIMITS_REQUEST: null,
CLOUD_PRODUCTS_REQUEST: null,
CLOUD_SUBSCRIPTION_REQUEST: null,
CLOUD_EXPAND_STATS_REQUEST: null,
LICENSE_SELF_SERVE_STATS_REQUEST: null,
RECEIVED_SELF_HOSTED_SIGNUP_PROGRESS: null,
});
10 changes: 5 additions & 5 deletions packages/mattermost-redux/src/actions/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export function getCloudCustomer(): ActionFunc {
});
}

export function getLicenseExpandStatus(): ActionFunc {
export function getLicenseSelfServeStatus(): ActionFunc {
return bindClientFunc({
clientFunc: Client4.getLicenseExpandStatus,
onRequest: CloudTypes.CLOUD_EXPAND_STATS_REQUEST,
onSuccess: [CloudTypes.RECEIVED_CLOUD_EXPAND_STATS],
onFailure: CloudTypes.CLOUD_EXPAND_STATS_FAILED,
clientFunc: Client4.getLicenseSelfServeStatus,
onRequest: CloudTypes.LICENSE_SELF_SERVE_STATS_REQUEST,
onSuccess: [CloudTypes.RECEIVED_LICENSE_SELF_SERVE_STATS],
onFailure: CloudTypes.LICENSE_SELF_SERVE_STATS_FAILED,
});
}

Expand Down
10 changes: 5 additions & 5 deletions packages/mattermost-redux/src/reducers/entities/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {ValueOf} from '@mattermost/types/utilities';
import {CloudTypes} from 'mattermost-redux/action_types';

import {GenericAction} from 'mattermost-redux/types/actions';
import {Product, Subscription, CloudCustomer, Invoice, Limits, SelfHostedSignupProgress, LicenseExpandReducer} from '@mattermost/types/cloud';
import {Product, Subscription, CloudCustomer, Invoice, Limits, SelfHostedSignupProgress, LicenseSelfServeStatusReducer} from '@mattermost/types/cloud';

export function subscription(state: Subscription | null = null, action: GenericAction) {
switch (action.type) {
Expand All @@ -29,21 +29,21 @@ function customer(state: CloudCustomer | null = null, action: GenericAction) {
}
}

export function subscriptionStats(state: LicenseExpandReducer | null = null, action: GenericAction): LicenseExpandReducer | null {
export function subscriptionStats(state: LicenseSelfServeStatusReducer | null = null, action: GenericAction): LicenseSelfServeStatusReducer | null {
switch (action.type) {
case CloudTypes.CLOUD_EXPAND_STATS_REQUEST: {
case CloudTypes.LICENSE_SELF_SERVE_STATS_REQUEST: {
return {
getRequestState: 'LOADING',
...action.data,
};
}
case CloudTypes.RECEIVED_CLOUD_EXPAND_STATS: {
case CloudTypes.RECEIVED_LICENSE_SELF_SERVE_STATS: {
return {
getRequestState: 'OK',
is_expandable: action.data,
};
}
case CloudTypes.CLOUD_EXPAND_STATS_FAILED: {
case CloudTypes.LICENSE_SELF_SERVE_STATS_FAILED: {
return {
getRequestState: 'ERROR',
is_expandable: false,
Expand Down
9 changes: 5 additions & 4 deletions packages/types/src/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type CloudState = {
products?: Record<string, Product>;
customer?: CloudCustomer;
invoices?: Record<string, Invoice>;
subscriptionStats?: LicenseExpandReducer;
subscriptionStats?: LicenseSelfServeStatusReducer;
limits: {
limitsLoaded: boolean;
limits: Limits;
Expand Down Expand Up @@ -99,12 +99,13 @@ export type CloudCustomer = {
payment_method: PaymentMethod;
} & CustomerMetadataGatherWireTransfer

export type LicenseExpandStatus = {
is_expandable: boolean;
export type LicenseSelfServeStatus = {
is_expandable?: boolean;
is_renewable?: boolean;
}

type RequestState = 'IDLE' | 'LOADING' | 'ERROR' | 'OK'
export interface LicenseExpandReducer extends LicenseExpandStatus {
export interface LicenseSelfServeStatusReducer extends LicenseSelfServeStatus {
getRequestState: RequestState;
}

Expand Down

0 comments on commit 630b3dc

Please sign in to comment.