Skip to content

Commit

Permalink
WIP update
Browse files Browse the repository at this point in the history
Partway through updating code, realizing that `updateMoneyRequest` is
now a completely dead code branch
  • Loading branch information
lindboe committed Feb 6, 2024
1 parent 32d6617 commit 28a1f95
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
24 changes: 12 additions & 12 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ function buildOnyxDataForMoneyRequest(
optimisticPolicyRecentlyUsedTags: OnyxTypes.RecentlyUsedTags,
isNewChatReport: boolean,
shouldCreateNewMoneyRequestReport: boolean,
policy: OnyxTypes.Policy | EmptyObject = {},
policyTags: OnyxTypes.PolicyTagList = {},
policyCategories: OnyxTypes.PolicyCategories | EmptyObject = {},
policy?: OnyxEntry<OnyxTypes.Policy>,
policyTags?: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>,
needsToBeManuallySubmitted = true,
): [OnyxUpdate[], OnyxUpdate[], OnyxUpdate[]] {
const isScanRequest = TransactionUtils.isScanRequest(transaction);
Expand Down Expand Up @@ -699,9 +699,9 @@ function getMoneyRequestInformation(
category: string | undefined,
tag: string | undefined,
billable: boolean | undefined,
policy: OnyxTypes.Policy | EmptyObject | undefined,
policyTags: OnyxTypes.PolicyTagList,
policyCategories: OnyxTypes.PolicyCategories | EmptyObject,
policy: OnyxEntry<OnyxTypes.Policy> | undefined,
policyTags: OnyxEntry<OnyxTypes.PolicyTagList> | undefined,
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories> | undefined,
payeeAccountID = userAccountID,
payeeEmail = currentUserEmail,
moneyRequestReportID = '',
Expand Down Expand Up @@ -913,9 +913,9 @@ function createDistanceRequest(
merchant: string,
billable: boolean | undefined,
validWaypoints: WaypointCollection,
policy: OnyxTypes.Policy | EmptyObject | undefined,
policyTags: OnyxTypes.PolicyTagList,
policyCategories: OnyxTypes.PolicyCategories,
policy: OnyxEntry<OnyxTypes.Policy>,
policyTags: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
) {
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
Expand Down Expand Up @@ -1347,9 +1347,9 @@ function requestMoney(
taxCode = '',
taxAmount = 0,
billable?: boolean,
policy: OnyxTypes.Policy | EmptyObject = {},
policyTags: OnyxTypes.PolicyTagList = {},
policyCategories: OnyxTypes.PolicyCategories | EmptyObject = {},
policy?: OnyxEntry<OnyxTypes.Policy>,
policyTags?: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>,
) {
// 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 Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const propTypes = {
};
const defaultProps = {
personalDetails: {},
policy: {},
policyCategories: {},
policyTags: {},
policy: null,
policyCategories: null,
policyTags: null,
report: {},
transaction: {},
...withCurrentUserPersonalDetailsDefaultProps,
Expand Down
23 changes: 21 additions & 2 deletions src/pages/iou/request/step/IOURequestStepTag.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import PropTypes from 'prop-types';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import categoryPropTypes from '@components/categoryPropTypes';
import TagPicker from '@components/TagPicker';
import tagPropTypes from '@components/tagPropTypes';
import Text from '@components/Text';
Expand All @@ -11,6 +13,7 @@ import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import reportPropTypes from '@pages/reportPropTypes';
import {policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -31,17 +34,27 @@ const propTypes = {
/** The report currently being used */
report: reportPropTypes,

/** The policy of the report */
policy: policyPropTypes.policy,

/** The category configuration of the report's policy */
policyCategories: PropTypes.objectOf(categoryPropTypes),

/** Collection of tags attached to a policy */
policyTags: tagPropTypes,
};

const defaultProps = {
report: {},
policyTags: {},
policy: null,
policyTags: null,
policyCategories: null,
transaction: {},
};

function IOURequestStepTag({
policy,
policyCategories,
policyTags,
report,
route: {
Expand Down Expand Up @@ -75,7 +88,7 @@ function IOURequestStepTag({
return;
}
if (isEditing) {
IOU.updateMoneyRequestTag(transactionID, report.reportID, updatedTag);
IOU.updateMoneyRequestTag(transactionID, report.reportID, updatedTag, policy, policyTags, policyCategories);
Navigation.dismissModal();
return;
}
Expand Down Expand Up @@ -114,6 +127,12 @@ export default compose(
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
},
policyCategories: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
},
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
},
Expand Down
28 changes: 12 additions & 16 deletions src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ type PolicyTag = {

type PolicyTags = Record<string, PolicyTag>;

// When queried from Onyx, if there is no matching policy tag list, the data
// returned will be an empty object, represented by Record<string, undefined>.
type PolicyTagList<T extends string = string> =
| Record<
T,
{
/** Name of the tag list */
name: T;

/** Flag that determines if tags are required */
required: boolean;

tags: PolicyTags;
}
>
| Record<string, undefined>;
type PolicyTagList<T extends string = string> = Record<
T,
{
/** Name of the tag list */
name: T;

/** Flag that determines if tags are required */
required: boolean;

tags: PolicyTags;
}
>;

export type {PolicyTag, PolicyTags, PolicyTagList};

0 comments on commit 28a1f95

Please sign in to comment.