Skip to content

Commit

Permalink
Merge pull request #23738 from hoangzinh/df/19681_2
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Aug 11, 2023
2 parents 9418b87 + 21f34cc commit 7aac7fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,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]);

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);

0 comments on commit 7aac7fa

Please sign in to comment.