diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 13920d1c6dd4..241695b0780c 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -31,14 +31,11 @@ import MainDrawerNavigator from './MainDrawerNavigator'; // Modal Stack Navigators import * as ModalStackNavigators from './ModalStackNavigators'; import SCREENS from '../../../SCREENS'; -import Timers from '../../Timers'; import ValidateLoginPage from '../../../pages/ValidateLoginPage'; import defaultScreenOptions from './defaultScreenOptions'; import * as App from '../../actions/App'; import * as Session from '../../actions/Session'; import LogOutPreviousUserPage from '../../../pages/LogOutPreviousUserPage'; -import networkPropTypes from '../../../components/networkPropTypes'; -import {withNetwork} from '../../../components/OnyxProvider'; let currentUserEmail; Onyx.connect({ @@ -88,9 +85,6 @@ const modalScreenListeners = { }; const propTypes = { - /** Information about the network */ - network: networkPropTypes.isRequired, - ...windowDimensionsPropTypes, }; @@ -122,18 +116,6 @@ class AuthScreens extends React.Component { App.fixAccountAndReloadData(); App.setUpPoliciesAndNavigate(this.props.session); - - // Refresh the personal details, timezone and betas every 30 minutes - // There is no pusher event that sends updated personal details data yet - // See https://github.com/Expensify/ReactNativeChat/issues/468 - this.interval = Timers.register(setInterval(() => { - if (this.props.network.isOffline) { - return; - } - PersonalDetails.fetchPersonalDetails(); - User.getBetas(); - }, 1000 * 60 * 30)); - Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH; @@ -333,7 +315,6 @@ class AuthScreens extends React.Component { AuthScreens.propTypes = propTypes; export default compose( withWindowDimensions, - withNetwork(), withOnyx({ session: { key: ONYXKEYS.SESSION, diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index d5eafab203ba..f1e5426deb8d 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -9,7 +9,6 @@ import CONST from '../../CONST'; import Log from '../Log'; import Performance from '../Performance'; import Timing from './Timing'; -import * as PersonalDetails from './PersonalDetails'; import * as Report from './Report'; import * as BankAccounts from './BankAccounts'; import * as Policy from './Policy'; @@ -98,7 +97,6 @@ function getAppData(shouldSyncPolicyList = true) { // We should update the syncing indicator when personal details and reports are both done fetching. return Promise.all([ - PersonalDetails.fetchPersonalDetails(), Report.fetchAllReports(true, true), ]); } diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 636073e1ff68..bcb939a1b2f1 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -117,27 +117,6 @@ function formatPersonalDetails(personalDetailsList) { return formattedResult; } -/** - * Get the personal details for our organization - * @returns {Promise} - */ -function fetchPersonalDetails() { - return DeprecatedAPI.Get({ - returnValueList: 'personalDetailsList', - }) - .then((data) => { - // If personalDetailsList does not have the current user ensure we initialize their details with an empty - // object at least - const personalDetailsList = _.isEmpty(data.personalDetailsList) ? {} : data.personalDetailsList; - if (!personalDetailsList[currentUserEmail]) { - personalDetailsList[currentUserEmail] = {}; - } - - const allPersonalDetails = formatPersonalDetails(personalDetailsList); - Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, allPersonalDetails); - }); -} - /** * Gets the first and last name from the user's personal details. * If the login is the same as the displayName, then they don't exist, @@ -327,7 +306,6 @@ function deleteAvatar(defaultAvatarURL) { } export { - fetchPersonalDetails, formatPersonalDetails, getFromReportParticipants, getDisplayName, diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index 77d19c5eaa1a..ce8e41f18122 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -81,14 +81,7 @@ describe('actions/Report', () => { User.subscribeToUserEvents(); return waitForPromisesToResolve(); }) - .then(() => TestHelper.fetchPersonalDetailsForTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN, { - [TEST_USER_LOGIN]: { - accountID: TEST_USER_ACCOUNT_ID, - email: TEST_USER_LOGIN, - firstName: 'Test', - lastName: 'User', - }, - })) + .then(() => TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID)) .then(() => { // This is a fire and forget response, but once it completes we should be able to verify that we // have an "optimistic" report action in Onyx. @@ -183,14 +176,7 @@ describe('actions/Report', () => { // GIVEN a test user with initial data return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN) - .then(() => TestHelper.fetchPersonalDetailsForTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN, { - [TEST_USER_LOGIN]: { - accountID: TEST_USER_ACCOUNT_ID, - email: TEST_USER_LOGIN, - firstName: 'Test', - lastName: 'User', - }, - })) + .then(() => TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID)) .then(() => { global.fetch = TestHelper.getGlobalFetchMock(); @@ -243,14 +229,7 @@ describe('actions/Report', () => { User.subscribeToUserEvents(); return waitForPromisesToResolve(); }) - .then(() => TestHelper.fetchPersonalDetailsForTestUser(USER_1_ACCOUNT_ID, USER_1_LOGIN, { - [USER_1_LOGIN]: { - accountID: USER_1_ACCOUNT_ID, - email: USER_1_LOGIN, - firstName: 'Test', - lastName: 'User', - }, - })) + .then(() => TestHelper.setPersonalDetails(USER_1_LOGIN, USER_1_ACCOUNT_ID)) .then(() => { // When a Pusher event is handled for a new report comment channel.emit(Pusher.TYPE.ONYX_API_UPDATE, [ diff --git a/tests/utils/TestHelper.js b/tests/utils/TestHelper.js index 9cee105e64b7..d619e9d72ab2 100644 --- a/tests/utils/TestHelper.js +++ b/tests/utils/TestHelper.js @@ -1,7 +1,10 @@ +import Onyx from 'react-native-onyx'; +import CONST from '../../src/CONST'; import * as Session from '../../src/libs/actions/Session'; -import * as PersonalDetails from '../../src/libs/actions/PersonalDetails'; import HttpUtils from '../../src/libs/HttpUtils'; +import ONYXKEYS from '../../src/ONYXKEYS'; import waitForPromisesToResolve from './waitForPromisesToResolve'; +import * as ReportUtils from '../../src/libs/ReportUtils'; /** * Simulate signing in and make sure all API calls in this flow succeed. Every time we add @@ -51,32 +54,6 @@ function signInWithTestUser(accountID = 1, login = 'test@user.com', password = ' }); } -/** - * Fetch and set personal details with provided personalDetailsList - * - * @param {Number} accountID - * @param {String} email - * @param {Object} personalDetailsList - * @returns {Promise} - */ -function fetchPersonalDetailsForTestUser(accountID, email, personalDetailsList) { - const originalXHR = HttpUtils.xhr; - HttpUtils.xhr = jest.fn(); - - HttpUtils.xhr - .mockImplementationOnce(() => Promise.resolve({ - accountID, - email, - personalDetailsList, - })); - - PersonalDetails.fetchPersonalDetails(); - return waitForPromisesToResolve() - .then(() => { - HttpUtils.xhr = originalXHR; - }); -} - /** * Use for situations where fetch() is required. * @@ -98,8 +75,34 @@ function getGlobalFetchMock() { }); } +/** + * @param {String} login + * @param {Number} accountID + * @returns {Promise} + */ +function setPersonalDetails(login, accountID) { + const avatar = ReportUtils.getDefaultAvatar(login); + const details = { + accountID, + login, + avatar, + displayName: 'Test User', + firstName: 'Test', + lastName: 'User', + pronouns: '', + timezone: CONST.DEFAULT_TIME_ZONE, + payPalMeAddress: '', + phoneNumber: '', + avatarHighResolution: avatar, + }; + Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, { + [login]: details, + }); + return waitForPromisesToResolve(); +} + export { getGlobalFetchMock, signInWithTestUser, - fetchPersonalDetailsForTestUser, + setPersonalDetails, };