Skip to content

Commit

Permalink
Merge pull request #39244 from FitseTLT/fix-ecard-transaction-date-fi…
Browse files Browse the repository at this point in the history
…eld-editable

Fix - Domain Card - User can edit the date in expenses related to the assigned domain card
  • Loading branch information
robertjchen authored May 6, 2024
2 parents ab1e924 + 6363886 commit 90b67a5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ const ROUTES = {
getUrlWithBackToParam(`${action as string}/${iouType as string}/currency/${transactionID}/${reportID}/${pageIndex}?currency=${currency}`, backTo),
},
MONEY_REQUEST_STEP_DATE: {
route: ':action/:iouType/date/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action as string}/${iouType as string}/date/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/date/:transactionID/:reportID/:reportActionID?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '', reportActionID?: string) =>
getUrlWithBackToParam(`${action as string}/${iouType as string}/date/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
},
MONEY_REQUEST_STEP_DESCRIPTION: {
route: ':action/:iouType/description/:transactionID/:reportID/:reportActionID?',
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ function MoneyRequestConfirmationList({
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams(), reportActionID));
}}
disabled={didConfirm}
interactive={!isReadOnly}
Expand Down
1 change: 1 addition & 0 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ function MoneyRequestView({
description={translate('iou.card')}
title={cardProgramName}
titleStyle={styles.flex1}
interactive={false}
/>
</OfflineWithFeedback>
)}
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ type MoneyRequestNavigatorParamList = {
transactionID: string;
reportID: string;
backTo: Routes;
reportActionID?: string;
};
[SCREENS.MONEY_REQUEST.STEP_DESCRIPTION]: {
action: IOUAction;
Expand Down
21 changes: 11 additions & 10 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2615,18 +2615,19 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxEntry<ReportAction>, field
return false;
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT || fieldToEdit === CONST.EDIT_REQUEST_FIELD.CURRENCY) {
if (TransactionUtils.isCardTransaction(transaction)) {
return false;
}
if (
(fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT || fieldToEdit === CONST.EDIT_REQUEST_FIELD.CURRENCY || fieldToEdit === CONST.EDIT_REQUEST_FIELD.DATE) &&
TransactionUtils.isCardTransaction(transaction)
) {
return false;
}

if (TransactionUtils.isDistanceRequest(transaction)) {
const policy = getPolicy(moneyRequestReport?.reportID ?? '');
const isAdmin = isExpenseReport(moneyRequestReport) && policy.role === CONST.POLICY.ROLE.ADMIN;
const isManager = isExpenseReport(moneyRequestReport) && currentUserAccountID === moneyRequestReport?.managerID;
if ((fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT || fieldToEdit === CONST.EDIT_REQUEST_FIELD.CURRENCY) && TransactionUtils.isDistanceRequest(transaction)) {
const policy = getPolicy(moneyRequestReport?.reportID ?? '');
const isAdmin = isExpenseReport(moneyRequestReport) && policy.role === CONST.POLICY.ROLE.ADMIN;
const isManager = isExpenseReport(moneyRequestReport) && currentUserAccountID === moneyRequestReport?.managerID;

return isAdmin || isManager;
}
return isAdmin || isManager;
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT) {
Expand Down
44 changes: 40 additions & 4 deletions src/pages/iou/request/step/IOURequestStepDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
Expand All @@ -26,6 +27,12 @@ type IOURequestStepDateOnyxProps = {
/** The draft transaction that holds data to be persisted on the current transaction */
splitDraftTransaction: OnyxEntry<OnyxTypes.Transaction>;

/** The actions from the parent report */
reportActions: OnyxEntry<OnyxTypes.ReportActions>;

/** Session info for the currently logged in user. */
session: OnyxEntry<OnyxTypes.Session>;

/** The policy of the report */
policy: OnyxEntry<OnyxTypes.Policy>;

Expand All @@ -37,27 +44,39 @@ type IOURequestStepDateOnyxProps = {
};

type IOURequestStepDateProps = IOURequestStepDateOnyxProps &
WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT> & {
/** Holds data related to Expense view state, rather than the underlying Expense data. */
WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_DATE> & {
/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
transaction: OnyxEntry<OnyxTypes.Transaction>;

/** The report linked to the transaction */
report: OnyxEntry<Report>;
};

function IOURequestStepDate({
route: {
params: {action, iouType, reportID, backTo},
params: {action, iouType, reportID, backTo, reportActionID},
},
transaction,
splitDraftTransaction,
policy,
policyTags,
policyCategories,
reportActions,
report,
session,
}: IOURequestStepDateProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const isEditing = action === CONST.IOU.ACTION.EDIT;
// In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value
const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && isEditing;
const currentCreated = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? TransactionUtils.getCreated(splitDraftTransaction) : TransactionUtils.getCreated(transaction);
const parentReportAction = reportActions?.[(isEditingSplitBill ? reportActionID : report?.parentReportActionID) ?? 0];
const canEditingSplitBill =
isEditingSplitBill && session && parentReportAction && session.accountID === parentReportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction);
const canEditMoneyRequest = isEditing && ReportUtils.canEditFieldOfMoneyRequest(parentReportAction ?? null, CONST.EDIT_REQUEST_FIELD.DATE);
// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFound = !IOUUtils.isValidMoneyRequestType(iouType) || (isEditing && !canEditMoneyRequest && !canEditingSplitBill);

const navigateBack = () => {
Navigation.goBack(backTo);
Expand Down Expand Up @@ -94,7 +113,7 @@ function IOURequestStepDate({
<StepScreenWrapper
headerTitle={translate('common.date')}
onBackButtonPress={navigateBack}
shouldShowNotFoundPage={!IOUUtils.isValidMoneyRequestType(iouType)} // TODO: Check why is this even here
shouldShowNotFoundPage={shouldShowNotFound}
shouldShowWrapper
testID={IOURequestStepDate.displayName}
>
Expand Down Expand Up @@ -127,6 +146,20 @@ const IOURequestStepDateWithOnyx = withOnyx<IOURequestStepDateProps, IOURequestS
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`;
},
},
reportActions: {
key: ({
route: {
params: {action, iouType},
},
report,
}) => {
let reportID;
if (action === CONST.IOU.ACTION.EDIT) {
reportID = iouType === CONST.IOU.TYPE.SPLIT ? report?.reportID : report?.parentReportID;
}
return `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID ?? '0'}`;
},
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
},
Expand All @@ -136,6 +169,9 @@ const IOURequestStepDateWithOnyx = withOnyx<IOURequestStepDateProps, IOURequestS
policyTags: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
},
session: {
key: ONYXKEYS.SESSION,
},
})(IOURequestStepDate);

// eslint-disable-next-line rulesdir/no-negated-variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type MoneyRequestRouteName =
| typeof SCREENS.MONEY_REQUEST.STEP_AMOUNT
| typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT
| typeof SCREENS.MONEY_REQUEST.STEP_DESCRIPTION
| typeof SCREENS.MONEY_REQUEST.STEP_DATE
| typeof SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT
| typeof SCREENS.MONEY_REQUEST.STEP_PARTICIPANTS
| typeof SCREENS.MONEY_REQUEST.STEP_MERCHANT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WithWritableReportOrNotFoundOnyxProps = {
type MoneyRequestRouteName =
| typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT
| typeof SCREENS.MONEY_REQUEST.STEP_DESCRIPTION
| typeof SCREENS.MONEY_REQUEST.STEP_DATE
| typeof SCREENS.MONEY_REQUEST.STEP_CATEGORY
| typeof SCREENS.MONEY_REQUEST.STEP_DISTANCE_RATE
| typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION
Expand Down

0 comments on commit 90b67a5

Please sign in to comment.