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

Add policy summaries to Onyx #3353

Merged
merged 6 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default {
REPORT_ACTIONS_DRAFTS: 'reportActionsDrafts_',
REPORT_USER_IS_TYPING: 'reportUserIsTyping_',
REPORT_IOUS: 'reportIOUs_',
POLICY: 'policy_',
},

// Indicates which locale should be used
Expand Down
12 changes: 12 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ function GetIOUReport(parameters) {
return Network.post(commandName, parameters);
}

/**
* @returns {Promise}
*/
function GetPolicySummaryList() {
const commandName = 'Get';
const parameters = {
returnValueList: 'policySummaryList',
};
return Network.post(commandName, parameters);
}

/**
* @returns {Promise}
*/
Expand Down Expand Up @@ -808,6 +819,7 @@ export {
Get,
GetAccountStatus,
GetIOUReport,
GetPolicySummaryList,
GetRequestCountryCode,
Graphite_Timer,
Log,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Navigation from '../Navigation';
import * as User from '../../actions/User';
import {setModalVisibility} from '../../actions/Modal';
import NameValuePair from '../../actions/NameValuePair';
import {getPolicySummaries} from '../../actions/Policy';
import modalCardStyleInterpolator from './modalCardStyleInterpolator';
import createCustomModalStackNavigator from './createCustomModalStackNavigator';

Expand Down Expand Up @@ -122,6 +123,7 @@ class AuthScreens extends React.Component {
fetchAllReports(true, true, true);
fetchCountryCodeByRequestIP();
UnreadIndicatorUpdater.listenForReportChanges();
getPolicySummaries();

// Refresh the personal details, timezone and betas every 30 minutes
// There is no pusher event that sends updated personal details data yet
Expand Down
36 changes: 36 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import {GetPolicySummaryList} from '../API';
import ONYXKEYS from '../../ONYXKEYS';

/**
* Takes a full policy summary that is returned from the policySummaryList and simplifies it so we are only storing
* the pieces of data that we need to in Onyx
*
* @param {Object} fullPolicy
* @param {String} fullPolicy.name
* @returns {Object}
*/
function getSimplifiedPolicyObject(fullPolicy) {
return {
name: fullPolicy.name,
};
}

function getPolicySummaries() {
GetPolicySummaryList()
.then((data) => {
if (data.jsonCode === 200) {
const policyDataToStore = _.reduce(data.policySummaryList, (memo, policy) => ({
...memo,
[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedPolicyObject(policy),
}), {});
Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, policyDataToStore);
}
});
}

export {
// eslint-disable-next-line import/prefer-default-export
getPolicySummaries,
};