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 @@ -1212,6 +1212,7 @@ const CONST = {

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

Expand Down
17 changes: 15 additions & 2 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 {useEffect} from 'react';
import {useEffect, useMemo} 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 @@ -17,8 +18,18 @@ function isMacOSWeb() {
}

function DeeplinkWrapper({children}) {
const isUnsupportedDeeplinkRoute = useMemo(
() =>
// According to the design, we don't support unlink in Desktop app https://github.com/Expensify/App/issues/19681#issuecomment-1610353099
_.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.

Why do we need to memorize this?

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 think it's an expensive calculator (loop through array and do regex) so I prefer memo it to prevent it rerun every time the component re-render.

Copy link
Collaborator

Choose a reason for hiding this comment

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

1 value in array I don't think its expensive. Let's just have a definition and use it.

Copy link
Contributor Author

@hoangzinh hoangzinh Aug 10, 2023

Choose a reason for hiding this comment

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

I just updated the PR. Please help me review it again. Thanks


useEffect(() => {
if (!isMacOSWeb() || CONFIG.ENVIRONMENT === CONST.ENVIRONMENT.DEV) {
if (!isMacOSWeb() || isUnsupportedDeeplinkRoute || CONFIG.ENVIRONMENT === CONST.ENVIRONMENT.DEV) {
return;
}

Expand All @@ -32,6 +43,8 @@ function DeeplinkWrapper({children}) {
}

App.beginDeepLinkRedirect();
// We only want this to run on mount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return children;
Expand Down
37 changes: 33 additions & 4 deletions src/pages/UnlinkLoginPage.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
import React from 'react';
import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import {propTypes as validateLinkPropTypes, defaultProps as validateLinkDefaultProps} from './ValidateLoginPage/validateLinkPropTypes';
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
import Navigation from '../libs/Navigation/Navigation';
import * as Session from '../libs/actions/Session';
import ROUTES from '../ROUTES';
import usePrevious from '../hooks/usePrevious';
import ONYXKEYS from '../ONYXKEYS';

const propTypes = {
/** The accountID and validateCode are passed via the URL */
route: validateLinkPropTypes,

/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether a sign is loading */
isLoading: PropTypes.bool,
}),
};

const defaultProps = {
route: validateLinkDefaultProps,
account: {
isLoading: false,
},
};

function UnlinkLoginPage(props) {
const accountID = lodashGet(props.route.params, 'accountID', '');
const validateCode = lodashGet(props.route.params, 'validateCode', '');
const prevIsLoading = usePrevious(props.account.isLoading);

useEffect(() => {
Session.unlinkLogin(accountID, validateCode);
// We only want this to run on mount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
// Only navigate when the unlink login request is completed
if (!prevIsLoading || props.account.isLoading) {
return;
}

Navigation.navigate(ROUTES.HOME);
}, [prevIsLoading, props.account.isLoading]);
Copy link
Member

Choose a reason for hiding this comment

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

Hey, this line caused a bug - #36618

RCA is here.


Session.unlinkLogin(accountID, validateCode);
Navigation.navigate(ROUTES.HOME);
return <FullScreenLoadingIndicator />;
}

UnlinkLoginPage.propTypes = propTypes;
UnlinkLoginPage.defaultProps = defaultProps;
UnlinkLoginPage.displayName = 'UnlinkLoginPage';

export default UnlinkLoginPage;
export default withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
})(UnlinkLoginPage);
Loading