Skip to content

Commit

Permalink
[MM-56654] Turn off landing page for Desktop App token flow, cleanup …
Browse files Browse the repository at this point in the history
…check for landing page (mattermost#26126)
  • Loading branch information
devinbinnie authored Feb 12, 2024
1 parent 41081b9 commit c723bf3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 16 deletions.
3 changes: 3 additions & 0 deletions webapp/channels/src/components/root/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function mapStateToProps(state: GlobalState) {
telemetryEnabled: config.DiagnosticsEnabled === 'true',
noAccounts: config.NoAccounts === 'true',
telemetryId: config.DiagnosticId,
iosDownloadLink: config.IosAppDownloadLink,
androidDownloadLink: config.AndroidAppDownloadLink,
appDownloadLink: config.AppDownloadLink,
permalinkRedirectTeamName: permalinkRedirectTeam ? permalinkRedirectTeam.name : '',
showTermsOfService,
plugins,
Expand Down
40 changes: 40 additions & 0 deletions webapp/channels/src/components/root/root.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,44 @@ describe('components/Root', () => {
wrapper.unmount();
});
});

describe('showLandingPageIfNecessary', () => {
const landingProps = {
...baseProps,
iosDownloadLink: 'http://iosapp.com',
androidDownloadLink: 'http://androidapp.com',
appDownloadLink: 'http://desktopapp.com',
...{
location: {
pathname: '/',
search: '',
},
} as RouteComponentProps,
history: {
push: jest.fn(),
} as unknown as RouteComponentProps['history'],
};

test('should show for normal cases', () => {
const wrapper = shallow(<Root {...landingProps}/>);
(wrapper.instance() as any).onConfigLoaded();
expect(landingProps.history.push).toHaveBeenCalledWith('/landing#/');
wrapper.unmount();
});

test('should not show for Desktop App login flow', () => {
const props = {
...landingProps,
...{
location: {
pathname: '/login/desktop',
},
} as RouteComponentProps,
};
const wrapper = shallow(<Root {...props}/>);
(wrapper.instance() as any).onConfigLoaded();
expect(props.history.push).not.toHaveBeenCalled();
wrapper.unmount();
});
});
});
72 changes: 56 additions & 16 deletions webapp/channels/src/components/root/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ type Props = {
theme: Theme;
telemetryEnabled: boolean;
telemetryId?: string;
iosDownloadLink?: string;
androidDownloadLink?: string;
appDownloadLink?: string;
noAccounts: boolean;
showTermsOfService: boolean;
permalinkRedirectTeamName: string;
Expand Down Expand Up @@ -292,28 +295,65 @@ export default class Root extends React.PureComponent<Props, State> {
this.props.actions.migrateRecentEmojis();
store.dispatch(loadRecentlyUsedCustomEmojis());

const iosDownloadLink = getConfig(store.getState()).IosAppDownloadLink;
const androidDownloadLink = getConfig(store.getState()).AndroidAppDownloadLink;
const desktopAppDownloadLink = getConfig(store.getState()).AppDownloadLink;
this.showLandingPageIfNecessary();

const toResetPasswordScreen = this.props.location.pathname === '/reset_password_complete';
Utils.applyTheme(this.props.theme);
};

private showLandingPageIfNecessary = () => {
// We have nothing to redirect to if we're already on Desktop App
// Chromebook has no Desktop App to switch to
if (UserAgent.isDesktopApp() || UserAgent.isChromebook()) {
return;
}

// redirect to the mobile landing page if the user hasn't seen it before
let landing;
if (UserAgent.isAndroidWeb()) {
landing = androidDownloadLink;
} else if (UserAgent.isIosWeb()) {
landing = iosDownloadLink;
} else {
landing = desktopAppDownloadLink;
// Nothing to link to if we've removed the Android App download link
if (UserAgent.isAndroidWeb() && !this.props.androidDownloadLink) {
return;
}

if (landing && !this.props.isCloud && !BrowserStore.hasSeenLandingPage() && !toResetPasswordScreen && !this.props.location.pathname.includes('/landing') && !window.location.hostname?.endsWith('.test.mattermost.com') && !UserAgent.isDesktopApp() && !UserAgent.isChromebook()) {
this.props.history.push('/landing#' + this.props.location.pathname + this.props.location.search);
BrowserStore.setLandingPageSeen(true);
// Nothing to link to if we've removed the iOS App download link
if (UserAgent.isIosWeb() && !this.props.iosDownloadLink) {
return;
}

Utils.applyTheme(this.props.theme);
// Nothing to link to if we've removed the Desktop App download link
if (!this.props.appDownloadLink) {
return;
}

// Only show the landing page once
if (BrowserStore.hasSeenLandingPage()) {
return;
}

// We don't want to show when resetting the password
if (this.props.location.pathname === '/reset_password_complete') {
return;
}

// We don't want to show when we're doing Desktop App external login
if (this.props.location.pathname === '/login/desktop') {
return;
}

// Stop this infinitely redirecting
if (this.props.location.pathname.includes('/landing')) {
return;
}

// Disabled to avoid breaking the CWS flow
if (this.props.isCloud) {
return;
}

// Disable for Rainforest tests
if (window.location.hostname?.endsWith('.test.mattermost.com')) {
return;
}

this.props.history.push('/landing#' + this.props.location.pathname + this.props.location.search);
BrowserStore.setLandingPageSeen(true);
};

componentDidUpdate(prevProps: Props) {
Expand Down

0 comments on commit c723bf3

Please sign in to comment.