Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix App show error when open unlink in Desktop App #23738

Merged
merged 15 commits into from
Aug 11, 2023
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ const CONST = {

ROUTES: {
VALIDATE_LOGIN: /\/v($|(\/\/*))/,
UNLINK_LOGIN: /\/u($|(\/\/*))/,
},
},

Expand Down
13 changes: 13 additions & 0 deletions src/components/DeeplinkWrapper/index.website.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import {PureComponent} from 'react';
import Str from 'expensify-common/lib/str';
import _ from 'underscore';
import * as Browser from '../../libs/Browser';
import ROUTES from '../../ROUTES';
import * as App from '../../libs/actions/App';
Expand All @@ -18,6 +19,10 @@ class DeeplinkWrapper extends PureComponent {
return;
}

if (this.isUnsupportedDeeplinkRoute()) {
return;
}

// If the current url path is /transition..., meaning it was opened from oldDot, during this transition period:
// 1. The user session may not exist, because sign-in has not been completed yet.
// 2. There may be non-idempotent operations (e.g. create a new workspace), which obviously should not be executed again in the desktop app.
Expand All @@ -33,6 +38,14 @@ class DeeplinkWrapper extends PureComponent {
return !Browser.isMobile() && typeof navigator === 'object' && typeof navigator.userAgent === 'string' && /Mac/i.test(navigator.userAgent) && !/Electron/i.test(navigator.userAgent);
}

// A function to detect if current route should be opened in Web only.
isUnsupportedDeeplinkRoute() {
return _.some([CONST.REGEX.ROUTES.UNLINK_LOGIN], (unsupportRouteRegex) => {
const routeRegex = new RegExp(unsupportRouteRegex);
return routeRegex.test(window.location.pathname);
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name looks sufficient. Instead, we could have a comment inside explaining why the unlink login path was added here. Thoughts?

cc: @hoangzinh @francoisl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Personal preference) I don't mind the comment outside the function, even if the name sounds sufficient. But overall neutral, I'm ok if we keep it or remove it.

However, yes a comment inside explaining why the unlink route is there sounds like a good idea to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment inside this func. Please help me review it again. Thanks


render() {
return this.props.children;
}
Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Log from '../../Log';
import PushNotification from '../../Notification/PushNotification';
import Timing from '../Timing';
import CONST from '../../../CONST';
import * as Localize from '../../Localize';
import Timers from '../../Timers';
import * as Pusher from '../../Pusher/pusher';
import * as Authentication from '../../Authentication';
Expand Down Expand Up @@ -632,7 +631,7 @@ function unlinkLogin(accountID, validateCode) {
key: ONYXKEYS.ACCOUNT,
value: {
isLoading: false,
message: Localize.translateLocal('unlinkLoginForm.succesfullyUnlinkedLogin'),
message: 'unlinkLoginForm.succesfullyUnlinkedLogin',
},
},
{
Expand Down