Skip to content

Commit

Permalink
Merge pull request #37879 from FitseTLT/fix-regression-splitbilll-tag…
Browse files Browse the repository at this point in the history
…-not-found

[CP staging] Fix - allow receipt split bill tag editing
  • Loading branch information
puneetlath authored Mar 10, 2024
2 parents 37f1c3a + 987444e commit 77375e8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,16 @@ const ROUTES = {
getUrlWithBackToParam(`${action}/${iouType}/scan/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAG: {
route: ':action/:iouType/tag/:tagIndex/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, tagIndex: number, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/tag/${tagIndex}/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/tag/:tagIndex/:transactionID/:reportID/:reportActionID?',
getRoute: (
action: ValueOf<typeof CONST.IOU.ACTION>,
iouType: ValueOf<typeof CONST.IOU.TYPE>,
tagIndex: number,
transactionID: string,
reportID: string,
backTo = '',
reportActionID?: string,
) => getUrlWithBackToParam(`${action}/${iouType}/tag/${tagIndex}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
},
MONEY_REQUEST_STEP_WAYPOINT: {
route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex',
Expand Down
1 change: 1 addition & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ function MoneyRequestConfirmationList(props) {
props.transaction.transactionID,
props.reportID,
Navigation.getActiveRouteWithoutParams(),
props.reportActionID,
),
);
return;
Expand Down
42 changes: 34 additions & 8 deletions src/pages/iou/request/step/IOURequestStepTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ const propTypes = {
policyTags: tagPropTypes,

/** The actions from the parent report */
parentReportActions: PropTypes.shape(reportActionPropTypes),
reportActions: PropTypes.shape(reportActionPropTypes),

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user accountID */
accountID: PropTypes.number,

/** Currently logged in user email */
email: PropTypes.string,
}).isRequired,
};

const defaultProps = {
Expand All @@ -57,7 +66,7 @@ const defaultProps = {
policyTags: null,
policyCategories: null,
transaction: {},
parentReportActions: {},
reportActions: {},
};

function IOURequestStepTag({
Expand All @@ -66,10 +75,11 @@ function IOURequestStepTag({
policyTags,
report,
route: {
params: {action, tagIndex: rawTagIndex, transactionID, backTo, iouType},
params: {action, tagIndex: rawTagIndex, transactionID, backTo, iouType, reportActionID},
},
transaction,
parentReportActions,
reportActions,
session,
}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand All @@ -80,12 +90,14 @@ function IOURequestStepTag({
const tag = TransactionUtils.getTag(transaction, tagIndex);
const isEditing = action === CONST.IOU.ACTION.EDIT;
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT;
const reportAction = reportActions[report.parentReportActionID || reportActionID];
const canEditSplitBill = isSplitBill && reportAction && session.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction);
const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);
const parentReportAction = parentReportActions[report.parentReportActionID];

const shouldShowTag = ReportUtils.isGroupPolicy(report) && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists));

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = !shouldShowTag || (isEditing && !canEditMoneyRequest(parentReportAction));
const shouldShowNotFoundPage = !shouldShowTag || (isEditing && (isSplitBill ? !canEditSplitBill : !canEditMoneyRequest(reportAction)));

const navigateBack = () => {
Navigation.goBack(backTo);
Expand Down Expand Up @@ -154,9 +166,23 @@ export default compose(
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
},
parentReportActions: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
reportActions: {
key: ({
report,
route: {
params: {action, iouType},
},
}) => {
let reportID = '0';
if (action === CONST.IOU.ACTION.EDIT) {
reportID = iouType === CONST.IOU.TYPE.SPLIT ? report.reportID : report.parentReportID;
}
return `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`;
},
canEvict: false,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(IOURequestStepTag);

0 comments on commit 77375e8

Please sign in to comment.