Skip to content

Commit

Permalink
Merge pull request Expensify#39956 from shubham1206agra/edit-track
Browse files Browse the repository at this point in the history
Edit track expense
  • Loading branch information
thienlnam authored Apr 22, 2024
2 parents b578c59 + 1c96919 commit 6fa2d06
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 58 deletions.
9 changes: 7 additions & 2 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ type AttachmentModalProps = AttachmentModalOnyxProps & {
/** Determines if download Button should be shown or not */
allowDownload?: boolean;

/** Determines if the receipt comes from track expense action */
isTrackExpenseAction?: boolean;

/** Title shown in the header of the modal */
headerTitle?: string;

Expand Down Expand Up @@ -145,6 +148,7 @@ function AttachmentModal({
originalFileName = '',
isAuthTokenRequired = false,
allowDownload = false,
isTrackExpenseAction = false,
report,
onModalShow = () => {},
onModalHide = () => {},
Expand Down Expand Up @@ -181,6 +185,7 @@ function AttachmentModal({
const nope = useSharedValue(false);
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const isOverlayModalVisible = (isReceiptAttachment && isDeleteReceiptConfirmModalVisible) || (!isReceiptAttachment && isAttachmentInvalid);
const iouType = useMemo(() => (isTrackExpenseAction ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT), [isTrackExpenseAction]);

const [file, setFile] = useState<FileObject | undefined>(
originalFileName
Expand Down Expand Up @@ -422,7 +427,7 @@ function AttachmentModal({
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
CONST.IOU.TYPE.SUBMIT,
iouType,
transaction?.transactionID ?? '',
report?.reportID ?? '',
Navigation.getActiveRouteWithoutParams(),
Expand All @@ -449,7 +454,7 @@ function AttachmentModal({
}
return menuItems;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isReceiptAttachment, parentReport, parentReportActions, policy, transaction, file, sourceState]);
}, [isReceiptAttachment, parentReport, parentReportActions, policy, transaction, file, sourceState, iouType]);

// There are a few things that shouldn't be set until we absolutely know if the file is a receipt or an attachment.
// props.isReceiptAttachment will be null until its certain what the file is, in which case it will then be true|false.
Expand Down
45 changes: 14 additions & 31 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ function MoneyRequestView({

const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTagList), [policyTagList]);

const isTrackExpense = ReportUtils.isTrackExpenseReport(report);
const iouType = isTrackExpense ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT;

// Flags for showing categories and tags
// transactionCategory can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -284,9 +287,7 @@ function MoneyRequestView({
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID))
}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))}
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
Expand All @@ -310,9 +311,7 @@ function MoneyRequestView({
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID))
}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))}
/>
</OfflineWithFeedback>
);
Expand Down Expand Up @@ -359,7 +358,7 @@ function MoneyRequestView({
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(
CONST.IOU.ACTION.EDIT,
CONST.IOU.TYPE.SUBMIT,
iouType,
transaction?.transactionID ?? '',
report.reportID,
Navigation.getActiveRouteWithoutParams(),
Expand All @@ -378,9 +377,7 @@ function MoneyRequestView({
titleStyle={styles.textHeadlineH2}
interactive={canEditAmount}
shouldShowRightIcon={canEditAmount}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID))
}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))}
brickRoadIndicator={getErrorForField('amount') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('amount')}
/>
Expand All @@ -393,11 +390,7 @@ function MoneyRequestView({
interactive={canEdit}
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID),
)
}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))}
wrapperStyle={[styles.pv2, styles.taskDescriptionMenuItem]}
brickRoadIndicator={getErrorForField('comment') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('comment')}
Expand All @@ -415,9 +408,7 @@ function MoneyRequestView({
shouldShowRightIcon={canEditMerchant}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID),
)
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))
}
brickRoadIndicator={getErrorForField('merchant') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('merchant')}
Expand All @@ -431,9 +422,7 @@ function MoneyRequestView({
interactive={canEditDate}
shouldShowRightIcon={canEditDate}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID))
}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DATE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))}
brickRoadIndicator={getErrorForField('date') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('date')}
/>
Expand All @@ -447,9 +436,7 @@ function MoneyRequestView({
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID),
)
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))
}
brickRoadIndicator={getErrorForField('category') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('category')}
Expand All @@ -470,7 +457,7 @@ function MoneyRequestView({
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, orderWeight, transaction?.transactionID ?? '', report.reportID),
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, iouType, orderWeight, transaction?.transactionID ?? '', report.reportID),
)
}
brickRoadIndicator={
Expand Down Expand Up @@ -503,9 +490,7 @@ function MoneyRequestView({
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID),
)
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))
}
brickRoadIndicator={getErrorForField('tax') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={getErrorForField('tax')}
Expand All @@ -522,9 +507,7 @@ function MoneyRequestView({
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.SUBMIT, transaction?.transactionID ?? '', report.reportID),
)
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))
}
/>
</OfflineWithFeedback>
Expand Down
36 changes: 24 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import type {
import type {Status} from '@src/types/onyx/PersonalDetails';
import type {NotificationPreference, Participants, PendingChatMember, Participant as ReportParticipant} from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type {Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {Comment, Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
Expand Down Expand Up @@ -2415,6 +2415,13 @@ function getTransactionDetails(transaction: OnyxEntry<Transaction>, createdDateF
};
}

function getTransactionCommentObject(transaction: OnyxEntry<Transaction>): Comment {
return {
...transaction?.comment,
waypoints: TransactionUtils.getWaypoints(transaction),
};
}

/**
* Can only edit if:
*
Expand All @@ -2440,19 +2447,16 @@ function canEditMoneyRequest(reportAction: OnyxEntry<ReportAction>): boolean {
return true;
}

// TODO: Uncomment this line when BE starts working properly (Editing Track Expense)
// if (reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK) {
// return true;
// }
const allowedReportActionType: Array<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>> = [CONST.IOU.REPORT_ACTION_TYPE.TRACK, CONST.IOU.REPORT_ACTION_TYPE.CREATE];

if (reportAction.originalMessage.type !== CONST.IOU.REPORT_ACTION_TYPE.CREATE) {
if (!allowedReportActionType.includes(reportAction.originalMessage.type)) {
return false;
}

const moneyRequestReportID = reportAction?.originalMessage?.IOUReportID ?? 0;

if (!moneyRequestReportID) {
return false;
return reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK;
}

const moneyRequestReport = getReport(String(moneyRequestReportID));
Expand Down Expand Up @@ -3050,6 +3054,9 @@ function getChatRoomSubtitle(report: OnyxEntry<Report>): string | undefined {
if (isChatThread(report)) {
return '';
}
if (isSelfDM(report)) {
return Localize.translateLocal('reportActionsView.yourSpace');
}
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
}
Expand Down Expand Up @@ -6085,16 +6092,20 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s

const linkedTrackedExpenseReportAction = Object.values(reportActions).find((action) => (action.originalMessage as IOUMessage)?.IOUTransactionID === transactionID);

const transactionAmount = Math.abs(transaction.amount);
const transactionCreated = format(new Date(transaction.created), CONST.DATE.FNS_FORMAT_STRING);
const {created, amount, currency, merchant, mccGroup} = getTransactionDetails(transaction) ?? {};
const comment = getTransactionCommentObject(transaction);

IOU.createDraftTransaction({
...transaction,
actionableWhisperReportActionID: reportActionID,
linkedTrackedExpenseReportAction,
linkedTrackedExpenseReportID: reportID,
amount: transactionAmount,
created: transactionCreated,
created,
amount,
currency,
comment,
merchant,
mccGroup,
} as Transaction);

Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(CONST.IOU.TYPE.SUBMIT, transactionID, reportID, undefined, actionName));
Expand All @@ -6109,8 +6120,9 @@ function getOutstandingChildRequest(iouReport: OnyxEntry<Report> | EmptyObject):
}

if (!isExpenseReport(iouReport)) {
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(iouReport);
return {
hasOutstandingChildRequest: iouReport.managerID === currentUserAccountID && iouReport.total !== 0,
hasOutstandingChildRequest: iouReport.managerID === currentUserAccountID && reimbursableSpend !== 0,
};
}

Expand Down
Loading

0 comments on commit 6fa2d06

Please sign in to comment.