diff --git a/src/components/NewDatePicker/index.js b/src/components/NewDatePicker/index.js
index 75d1520293f4..0b6346c93897 100644
--- a/src/components/NewDatePicker/index.js
+++ b/src/components/NewDatePicker/index.js
@@ -56,6 +56,13 @@ class NewDatePicker extends React.Component {
this.defaultValue = props.defaultValue ? moment(props.defaultValue).format(CONST.DATE.MOMENT_FORMAT_STRING) : '';
}
+ componentDidUpdate(prevProps) {
+ if (prevProps.value === this.props.value) {
+ return;
+ }
+ this.setDate(this.props.value);
+ }
+
/**
* Trigger the `onInputChange` handler when the user input has a complete date or is cleared
* @param {string} selectedDate
diff --git a/src/hooks/usePrivatePersonalDetails.js b/src/hooks/usePrivatePersonalDetails.js
new file mode 100644
index 000000000000..37eb63dcd0fd
--- /dev/null
+++ b/src/hooks/usePrivatePersonalDetails.js
@@ -0,0 +1,17 @@
+import {useEffect, useContext} from 'react';
+import * as PersonalDetails from '../libs/actions/PersonalDetails';
+import {NetworkContext} from '../components/OnyxProvider';
+
+/**
+ * Hook for fetching private personal details
+ */
+export default function usePrivatePersonalDetails() {
+ const {isOffline} = useContext(NetworkContext);
+
+ useEffect(() => {
+ if (isOffline || Boolean(PersonalDetails.getPrivatePersonalDetails())) {
+ return;
+ }
+ PersonalDetails.openPersonalDetailsPage();
+ }, [isOffline]);
+}
diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js
index 9cf64e44038b..50c47eae340a 100644
--- a/src/libs/actions/PersonalDetails.js
+++ b/src/libs/actions/PersonalDetails.js
@@ -26,6 +26,12 @@ Onyx.connect({
callback: (val) => (allPersonalDetails = val),
});
+let privatePersonalDetails;
+Onyx.connect({
+ key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
+ callback: (val) => (privatePersonalDetails = val),
+});
+
/**
* Returns the displayName for a user
*
@@ -325,7 +331,37 @@ function updateSelectedTimezone(selectedTimezone) {
* Fetches additional personal data like legal name, date of birth, address
*/
function openPersonalDetailsPage() {
- API.read('OpenPersonalDetailsPage');
+ const optimisticData = [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
+ value: {
+ isLoading: true,
+ },
+ },
+ ];
+
+ const successData = [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
+ value: {
+ isLoading: false,
+ },
+ },
+ ];
+
+ const failureData = [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
+ value: {
+ isLoading: false,
+ },
+ },
+ ];
+
+ API.read('OpenPersonalDetailsPage', {}, {optimisticData, successData, failureData});
}
/**
@@ -478,6 +514,14 @@ function clearAvatarErrors() {
});
}
+/**
+ * Get private personal details value
+ * @returns {Object}
+ */
+function getPrivatePersonalDetails() {
+ return privatePersonalDetails;
+}
+
export {
getDisplayName,
getDisplayNameForTypingIndicator,
@@ -495,4 +539,5 @@ export {
updateAutomaticTimezone,
updateSelectedTimezone,
getCountryISO,
+ getPrivatePersonalDetails,
};
diff --git a/src/pages/settings/Profile/PersonalDetails/AddressPage.js b/src/pages/settings/Profile/PersonalDetails/AddressPage.js
index 121065ae4097..2777b09cff7c 100644
--- a/src/pages/settings/Profile/PersonalDetails/AddressPage.js
+++ b/src/pages/settings/Profile/PersonalDetails/AddressPage.js
@@ -21,6 +21,8 @@ import CountryPicker from '../../../../components/CountryPicker';
import StatePicker from '../../../../components/StatePicker';
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
+import usePrivatePersonalDetails from '../../../../hooks/usePrivatePersonalDetails';
+import FullscreenLoadingIndicator from '../../../../components/FullscreenLoadingIndicator';
const propTypes = {
/* Onyx Props */
@@ -61,6 +63,7 @@ function updateAddress(values) {
}
function AddressPage(props) {
+ usePrivatePersonalDetails();
const {translate} = props;
const [countryISO, setCountryISO] = useState(PersonalDetails.getCountryISO(lodashGet(props.privatePersonalDetails, 'address.country')) || CONST.COUNTRY.US);
const isUSAForm = countryISO === CONST.COUNTRY.US;
@@ -117,6 +120,10 @@ function AddressPage(props) {
return errors;
}, []);
+ if (lodashGet(props.privatePersonalDetails, 'isLoading', true)) {
+ return ;
+ }
+
return (
;
+ }
+
return (
{
};
function LegalNamePage(props) {
+ usePrivatePersonalDetails();
const legalFirstName = lodashGet(props.privatePersonalDetails, 'legalFirstName', '');
const legalLastName = lodashGet(props.privatePersonalDetails, 'legalLastName', '');
@@ -63,6 +66,10 @@ function LegalNamePage(props) {
return errors;
}, []);
+ if (lodashGet(props.privatePersonalDetails, 'isLoading', true)) {
+ return ;
+ }
+
return (
{
- if (props.network.isOffline) {
- return;
- }
- PersonalDetails.openPersonalDetailsPage();
- }, [props.network.isOffline]);
-
+ usePrivatePersonalDetails();
const privateDetails = props.privatePersonalDetails || {};
const address = privateDetails.address || {};
const legalName = `${privateDetails.legalFirstName || ''} ${privateDetails.legalLastName || ''}`.trim();
@@ -87,6 +83,10 @@ function PersonalDetailsInitialPage(props) {
return formattedAddress.trim().replace(/,$/, '');
};
+ if (lodashGet(props.privatePersonalDetails, 'isLoading', true)) {
+ return ;
+ }
+
return (