Skip to content

Commit

Permalink
Merge pull request #11627 from Expensify/techievivek_workspace_chat_f…
Browse files Browse the repository at this point in the history
…or_first_time_user

Updated code to remove dependency on IS_LOADING_POLICY_DATA for Welcome.js
  • Loading branch information
luacmartins authored Oct 20, 2022
2 parents f24c24c + 59f7091 commit df90010
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 70 deletions.
3 changes: 0 additions & 3 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ export default {
// Is report data loading?
IS_LOADING_REPORT_DATA: 'isLoadingReportData',

// Is policy data loading?
IS_LOADING_POLICY_DATA: 'isLoadingPolicyData',

// Is Keyboard shortcuts modal open?
IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen',

Expand Down
55 changes: 0 additions & 55 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,6 @@ function updateLastAccessedWorkspace(policyID) {
Onyx.set(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, policyID);
}

/**
* Used to update ALL of the policies at once. If a policy is present locally, but not in the policies object passed here it will be removed.
* @param {Object} policyCollection - object of policy key and partial policy object
*/
function updateAllPolicies(policyCollection) {
// Clear out locally cached policies that have been deleted (i.e. they exist locally but not in our new policy collection object)
_.each(allPolicies, (policy, key) => {
if (policyCollection[key]) {
return;
}

Onyx.set(key, null);
});

// Set all the policies
_.each(policyCollection, (policyData, key) => {
Onyx.merge(key, {...policyData, alertMessage: '', errors: null});
});
}

/**
* Delete the workspace
*
Expand Down Expand Up @@ -168,40 +148,6 @@ function deleteWorkspace(policyID, reports) {
}
}

/**
* Fetches policy list from the API and saves a simplified version in Onyx, optionally creating a new policy first.
*
* More specifically, this action will:
* 1. Optionally create a new policy.
* 2. Fetch policy summaries.
* 3. Optionally navigate to the new policy.
* 4. Then fetch full policies.
*
* This way, we ensure that there's no race condition between creating the new policy and fetching existing ones,
* and we also don't have to wait for full policies to load before navigating to the new policy.
*/
function getPolicyList() {
Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, true);
DeprecatedAPI.GetPolicySummaryList()
.then((data) => {
if (data.jsonCode !== 200) {
Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false);
return;
}

const policyCollection = _.reduce(data.policySummaryList, (memo, policy) => ({
...memo,
[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedPolicyObject(policy, false),
}), {});

if (!_.isEmpty(policyCollection)) {
updateAllPolicies(policyCollection);
}

Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false);
});
}

/**
* @param {String} policyID
*/
Expand Down Expand Up @@ -978,7 +924,6 @@ function openWorkspaceInvitePage(policyID, clientMemberEmails) {
}

export {
getPolicyList,
loadFullPolicy,
removeMembers,
addMembersToWorkspace,
Expand Down
14 changes: 2 additions & 12 deletions src/libs/actions/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let isReadyPromise = new Promise((resolve) => {

let isFirstTimeNewExpensifyUser;
let isLoadingReportData = true;
let isLoadingPolicyData = true;
let email = '';

/**
Expand All @@ -28,7 +27,7 @@ let email = '';
* - Whether we have loaded all reports the server knows about
*/
function checkOnReady() {
if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingPolicyData || isLoadingReportData) {
if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingReportData) {
return;
}

Expand All @@ -53,15 +52,6 @@ Onyx.connect({
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_POLICY_DATA,
initWithStoredValues: false,
callback: (val) => {
isLoadingPolicyData = val;
checkOnReady();
},
});

const allReports = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand All @@ -77,7 +67,7 @@ Onyx.connect({

const allPolicies = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!val || !key) {
return;
Expand Down

0 comments on commit df90010

Please sign in to comment.