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

Adds Client-side Violations when creating money requests #32528

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e4135d1
Possible solution to not passing down tags and categories
cdanwards Nov 21, 2023
8fe667d
Updated withPolicy with new properties and also passed through to IOU…
cdanwards Nov 28, 2023
1cd0e08
Added some logs for testing -- remove these
cdanwards Nov 28, 2023
22ee011
Fixed merge conflicts
cdanwards Nov 29, 2023
441788c
Merge branch 'trevor-coleman/violations/violation-utils' of github.co…
cdanwards Nov 30, 2023
0cf233c
Fixed merge conflicts
cdanwards Dec 5, 2023
6f84a87
remove unused export
cdanwards Dec 5, 2023
57f2aa8
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Dec 5, 2023
f6f9cac
Remove console.log statements and fix import path
cdanwards Dec 5, 2023
9a041cc
Remove unused function getPolicyTags
cdanwards Dec 5, 2023
150487e
Fixed withOnyx call
cdanwards Dec 6, 2023
5b8bcc5
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Dec 6, 2023
b2128e5
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Dec 8, 2023
6c30158
Update src/libs/actions/IOU.js
cdanwards Dec 11, 2023
705329c
Update src/pages/workspace/withPolicy.tsx
cdanwards Dec 11, 2023
c93a59d
Update src/pages/iou/steps/MoneyRequestConfirmPage.js
cdanwards Dec 11, 2023
b6e959f
Update src/pages/workspace/withPolicy.tsx
cdanwards Dec 11, 2023
f0c609b
Update src/pages/workspace/withPolicy.tsx
cdanwards Dec 11, 2023
dbf3e5a
Update src/pages/workspace/withPolicy.tsx
cdanwards Dec 11, 2023
9783c47
Update src/libs/actions/IOU.js
cdanwards Dec 11, 2023
66d2767
Merge branch 'main' of github.com:infinitered/ExpensifyApp into cdanw…
cdanwards Dec 13, 2023
3c0b52c
Updated proptypes and reimplemented the second withonyx
cdanwards Dec 13, 2023
1547445
Merge branch 'cdanwards/violations/money-request-violations' of githu…
cdanwards Dec 13, 2023
6c3a853
Merge branch 'main' into cdanwards/violations/money-request-violations
lindboe Dec 14, 2023
633199b
Fix withOnyx references
lindboe Dec 15, 2023
919f967
Add policy data to new verison of money request confirmation screen
lindboe Dec 18, 2023
9885e31
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
lindboe Dec 18, 2023
4b6f463
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
lindboe Dec 19, 2023
0f91f22
Fix hook dependencies
lindboe Dec 19, 2023
e5b607e
Fix transaction violation storage
lindboe Dec 19, 2023
a8741ab
Use SET instead
lindboe Dec 19, 2023
8d417a9
Check policy violations locally for distance requests
lindboe Dec 20, 2023
34c080e
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
lindboe Jan 2, 2024
ab06fbe
Use policy arg for fetching paid policy info
lindboe Jan 3, 2024
da3469e
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
lindboe Jan 3, 2024
9b2fb39
Merge remote-tracking branch 'upstream/main' into cdanwards/violation…
lindboe Jan 4, 2024
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
Prev Previous commit
Next Next commit
Updated withPolicy with new properties and also passed through to IOU…
… functions
  • Loading branch information
cdanwards committed Nov 28, 2023
commit 8fe667dcce7a3ef6500ea4d553b442ff700469a9
60 changes: 35 additions & 25 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as UserUtils from '@libs/UserUtils';
import ViolationsUtils from '@libs/ViolationsUtils';
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -78,19 +78,19 @@ Onyx.connect({
},
});

let allPolicyTags = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
allPolicyTags = {};
return;
}
// let allPolicyTags = {};
// Onyx.connect({
// key: ONYXKEYS.COLLECTION.POLICY_TAGS,
// waitForCollectionCallback: true,
// callback: (value) => {
// if (!value) {
// allPolicyTags = {};
// return;
// }

allPolicyTags = value;
},
});
// allPolicyTags = value;
// },
// });

let userAccountID = '';
let currentUserEmail = '';
Expand Down Expand Up @@ -155,7 +155,9 @@ function buildOnyxDataForMoneyRequest(
optimisticPolicyRecentlyUsedTags,
isNewChatReport,
isNewIOUReport,
policyID,
policy,
policyTags,
policyCategories,
) {
const optimisticData = [
{
Expand Down Expand Up @@ -382,12 +384,9 @@ function buildOnyxDataForMoneyRequest(
},
];

if (!policyID) {
if (!policy.id) {
return [optimisticData, successData, failureData];
}
const policy = ReportUtils.getPolicy(policyID);
const policyTags = ReportUtils.getPolicyTags(policyID);
const policyCategories = ReportUtils.getPolicyCategories(policyID);

const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories);
cdanwards marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -425,7 +424,9 @@ function buildOnyxDataForMoneyRequest(
* @param {String} [category]
* @param {String} [tag]
* @param {Boolean} [billable]
* @param {String} [policyID]
* @param {Object} [policy]
* @param {Object} [policyTags]
* @param {Object} [policyCategories]
* @returns {Object} data
* @returns {String} data.payerEmail
* @returns {Object} data.iouReport
Expand Down Expand Up @@ -455,7 +456,9 @@ function getMoneyRequestInformation(
category = undefined,
tag = undefined,
billable = undefined,
policyID = undefined,
policy = undefined,
policyTags = undefined,
policyCategories = undefined,
) {
const payerEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login);
const payerAccountID = Number(participant.accountID);
Expand Down Expand Up @@ -531,7 +534,8 @@ function getMoneyRequestInformation(
}

const optimisticPolicyRecentlyUsedTags = {};
const policyTags = allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${iouReport.policyID}`];
// TODO: Remove the following line once everything is tested
// const policyTags = allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${iouReport.policyID}`];
const recentlyUsedPolicyTags = allRecentlyUsedTags[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`];

if (policyTags) {
Expand Down Expand Up @@ -618,7 +622,9 @@ function getMoneyRequestInformation(
optimisticPolicyRecentlyUsedTags,
isNewChatReport,
isNewIOUReport,
policyID,
policy,
policyTags,
policyCategories,
);

return {
Expand Down Expand Up @@ -866,7 +872,7 @@ function updateDistanceRequest(transactionID, transactionThreadReportID, transac
* @param {String} [category]
* @param {String} [tag]
* @param {Boolean} [billable]
* @param {String} [policyID]
* @param {Object} [policy]
* @param {Object} [policyTags]
* @param {Object} [policyCategories]
*/
Expand All @@ -884,7 +890,9 @@ function requestMoney(
category = undefined,
tag = undefined,
billable = undefined,
policyID = undefined,
policy = undefined,
policyTags = undefined,
policyCategories = undefined,
) {
// If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
Expand All @@ -905,7 +913,9 @@ function requestMoney(
category,
tag,
billable,
policyID,
policy,
policyTags,
policyCategories,
);

API.write(
Expand Down
28 changes: 16 additions & 12 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import {iouDefaultProps, iouPropTypes} from '@pages/iou/propTypes';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import reportPropTypes from '@pages/reportPropTypes';
import {policyDefaultProps, policyPropTypes} from '@pages/workspace/withPolicy';
import useThemeStyles from '@styles/useThemeStyles';
import * as IOU from '@userActions/IOU';
import * as Policy from '@userActions/Policy';
Expand Down Expand Up @@ -51,18 +52,16 @@ const propTypes = {
personalDetails: personalDetailsPropType,

/** The policy of the current report */
cdanwards marked this conversation as resolved.
Show resolved Hide resolved
policy: PropTypes.shape({
/** Whether the policy requires a tag */
requiresTag: PropTypes.bool,
policy: policyPropTypes,

/** Whether the policy requires a category */
requiresCategory: PropTypes.bool,

/** Whether there is more than one list of tags */
hasMultipleTagLists: PropTypes.bool,
policyTags: PropTypes.shape({
/** List of tags */
tags: PropTypes.arrayOf(PropTypes.string),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this and categories should be objects. They're {} in defaultProps, and in Onyx they're objects as well
image
image

}),

/** Whether the policy has enable tax tracking */
isTrackingTaxEnabled: PropTypes.bool,
policyCategories: PropTypes.shape({
/** List of categories */
categories: PropTypes.arrayOf(PropTypes.string),
}),

...withCurrentUserPersonalDetailsPropTypes,
Expand All @@ -74,6 +73,7 @@ const defaultProps = {
policyCategories: {},
policyTags: {},
iou: iouDefaultProps,
policy: policyDefaultProps,
...withCurrentUserPersonalDetailsDefaultProps,
};

Expand Down Expand Up @@ -190,7 +190,9 @@ function MoneyRequestConfirmPage(props) {
props.iou.category,
props.iou.tag,
props.iou.billable,
props.policy.id,
props.policy,
props.policyTags,
props.policyCategories,
);
},
[
Expand All @@ -204,7 +206,9 @@ function MoneyRequestConfirmPage(props) {
props.iou.category,
props.iou.tag,
props.iou.billable,
props.policy.id,
props.policy,
props.policyTags,
props.policyCategories,
],
);

Expand Down
14 changes: 14 additions & 0 deletions src/pages/workspace/withPolicy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ const policyPropTypes = {
* }
*/
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),

/** Whether or not the policy requires tags */
requiresTags: PropTypes.bool,
cdanwards marked this conversation as resolved.
Show resolved Hide resolved

/** Whether or not the policy requires categories */
requiresCategories: PropTypes.bool,
cdanwards marked this conversation as resolved.
Show resolved Hide resolved

/** Whether or not the policy has multiple tag lists */
hasMultipleTagLists: PropTypes.bool,

/** Whether or not the policy has tax tracking enabled */
isTrackingTaxEnabled: PropTypes.bool,
cdanwards marked this conversation as resolved.
Show resolved Hide resolved

/** */
cdanwards marked this conversation as resolved.
Show resolved Hide resolved
}),

/** The employee list of this policy */
Expand Down