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
9 changes: 8 additions & 1 deletion 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 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,7 +19,13 @@ function isMacOSWeb() {

function DeeplinkWrapper({children}) {
useEffect(() => {
if (!isMacOSWeb() || CONFIG.ENVIRONMENT === CONST.ENVIRONMENT.DEV) {
// According to the design, we don't support unlink in Desktop app https://github.com/Expensify/App/issues/19681#issuecomment-1610353099
const isUnsupportedDeeplinkRoute = _.some([CONST.REGEX.ROUTES.UNLINK_LOGIN], (unsupportRouteRegex) => {
const routeRegex = new RegExp(unsupportRouteRegex);
return routeRegex.test(window.location.pathname);
});

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

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