Skip to content

Commit

Permalink
adds share transaction view
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Mar 30, 2024
1 parent 904379f commit 4032202
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ const CONST = {
CREATE: 'create',
MOVE: 'move',
CATEGORIZE: 'categorize',
SHARE: 'share',
},
DEFAULT_AMOUNT: 0,
TYPE: {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/API/parameters/CategorizeTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type CategorizeTrackedExpenseParams = {
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
actionableWhisperReportActionID: string;
// making it optional for now
modifiedExpenseReportActionID?: string;
};

export default CategorizeTrackedExpenseParams;
12 changes: 12 additions & 0 deletions src/libs/API/parameters/ShareTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type ShareTrackedExpenseParams = {
policyID: string;
transactionID: string;
moneyRequestPreviewReportActionID: string;
moneyRequestReportID: string;
moneyRequestCreatedReportActionID: string;
actionableWhisperReportActionID: string;
// making it optional for now
modifiedExpenseReportActionID?: string;
};

export default ShareTrackedExpenseParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,5 @@ export type {default as SetPolicyCurrencyDefaultParams} from './SetPolicyCurrenc
export type {default as RenamePolicyTaxParams} from './RenamePolicyTaxParams';
export type {default as DismissTrackExpenseActionableWhisperParams} from './DismissTrackExpenseActionableWhisperParams';
export type {default as ConvertTrackedExpenseToRequestParams} from './ConvertTrackedExpenseToRequestParams';
export type {default as ShareTrackedExpenseParams} from './ShareTrackedExpenseParams';
export type {default as CategorizeTrackedExpenseParams} from './CategorizeTrackedExpenseParams';
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const WRITE_COMMANDS = {
DISMISS_ACTIONABLE_WHISPER: 'DismissActionableWhisper',
CONVERT_TRACKED_EXPENSE_TO_REQUEST: 'ConvertTrackedExpenseToRequest',
CATEGORIZE_TRACKED_TRANSACTION: 'CategorizeTrackedExpense',
SHARE_TRACKED_TRANSACTION: 'ShareTrackedExpense',
} as const;

type WriteCommand = ValueOf<typeof WRITE_COMMANDS>;
Expand Down Expand Up @@ -394,6 +395,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.DISMISS_ACTIONABLE_WHISPER]: Parameters.DismissTrackExpenseActionableWhisperParams;
[WRITE_COMMANDS.CONVERT_TRACKED_EXPENSE_TO_REQUEST]: Parameters.ConvertTrackedExpenseToRequestParams;
[WRITE_COMMANDS.CATEGORIZE_TRACKED_TRANSACTION]: Parameters.CategorizeTrackedExpenseParams;
[WRITE_COMMANDS.SHARE_TRACKED_TRANSACTION]: Parameters.ShareTrackedExpenseParams;
};

const READ_COMMANDS = {
Expand Down
80 changes: 55 additions & 25 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ function buildOnyxDataForTrackExpense(
return [optimisticData, successData, failureData];
}

function getDeleteTrackExpenseInformation(chatReportID: string, transactionID: string, reportAction: OnyxTypes.ReportAction) {
function getDeleteTrackExpenseInformation(chatReportID: string, transactionID: string, reportAction: OnyxTypes.ReportAction, shouldDeleteTransactionFromOnyx = true) {
// STEP 1: Get all collections we're updating
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] ?? null;
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
Expand Down Expand Up @@ -1037,13 +1037,15 @@ function getDeleteTrackExpenseInformation(chatReportID: string, transactionID: s
const reportLastMessageText = ReportActionsUtils.getLastVisibleMessage(chatReport?.reportID ?? '', updatedReportAction).lastMessageText;

// STEP 4: Build Onyx data
const optimisticData: OnyxUpdate[] = [
{
const optimisticData: OnyxUpdate[] = [];

if (shouldDeleteTransactionFromOnyx) {
optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: null,
},
];
});
}

if (Permissions.canUseViolations(betas)) {
optimisticData.push({
Expand Down Expand Up @@ -1097,13 +1099,15 @@ function getDeleteTrackExpenseInformation(chatReportID: string, transactionID: s
},
];

const failureData: OnyxUpdate[] = [
{
const failureData: OnyxUpdate[] = [];

if (shouldDeleteTransactionFromOnyx) {
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: transaction,
},
];
});
}

if (Permissions.canUseViolations(betas)) {
failureData.push({
Expand Down Expand Up @@ -1339,8 +1343,12 @@ function getMoneyRequestInformation(
optimisticNextStep,
);

if(shouldDeleteLinkedTrackedExpense && linkedTrackedExpenseReportAction && linkedTrackedExpenseReportID) {
const {optimisticData: deleteOptimisticData, successData: deleteSuccessData, failureData: deleteFailureData} = getDeleteTrackExpenseInformation(linkedTrackedExpenseReportID, optimisticTransaction.transactionID, linkedTrackedExpenseReportAction);
if (shouldDeleteLinkedTrackedExpense && linkedTrackedExpenseReportAction && linkedTrackedExpenseReportID) {
const {
optimisticData: deleteOptimisticData,
successData: deleteSuccessData,
failureData: deleteFailureData,
} = getDeleteTrackExpenseInformation(linkedTrackedExpenseReportID, optimisticTransaction.transactionID, linkedTrackedExpenseReportAction, false);
optimisticData.push(...deleteOptimisticData);
successData.push(...deleteSuccessData);
failureData.push(...deleteFailureData);
Expand Down Expand Up @@ -2259,8 +2267,7 @@ function requestMoney(
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
const moneyRequestReportID = isMoneyRequestReport ? report.reportID : '';
const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created);
const isConvertingFromTrackExpenseToRequest = action === CONST.IOU.ACTION.MOVE;
const isCategorizing = action === CONST.IOU.ACTION.CATEGORIZE;
const isMovingTransactionFromTrackExpense = [CONST.IOU.ACTION.MOVE, CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(action);

Check failure on line 2270 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'ValueOf<{ readonly EDIT: "edit"; readonly CREATE: "create"; readonly MOVE: "move"; readonly CATEGORIZE: "categorize"; readonly SHARE: "share"; }> | undefined' is not assignable to parameter of type '"move" | "categorize" | "share"'.

const {
payerAccountID,
Expand All @@ -2276,15 +2283,15 @@ function requestMoney(
createdReportActionIDForThread,
onyxData,
} = getMoneyRequestInformation(
isConvertingFromTrackExpenseToRequest || isCategorizing ? {} : currentChatReport,
isMovingTransactionFromTrackExpense ? {} : currentChatReport,
participant,
comment,
amount,
currency,
currentCreated,
merchant,
receipt,
isConvertingFromTrackExpenseToRequest || isCategorizing ? (linkedTrackedExpenseReportAction?.originalMessage as IOUMessage)?.IOUTransactionID : undefined,
isMovingTransactionFromTrackExpense ? (linkedTrackedExpenseReportAction?.originalMessage as IOUMessage)?.IOUTransactionID : undefined,
category,
tag,
billable,
Expand All @@ -2296,7 +2303,7 @@ function requestMoney(
moneyRequestReportID,
linkedTrackedExpenseReportAction,
linkedTrackedExpenseReportID,
isConvertingFromTrackExpenseToRequest || isCategorizing,
isMovingTransactionFromTrackExpense,
);

const activeReportID = isMoneyRequestReport ? report.reportID : chatReport.reportID;
Expand All @@ -2305,31 +2312,47 @@ function requestMoney(
case CONST.IOU.ACTION.MOVE: {
const parameters = {
payerAccountID,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
transactionID: transaction.transactionID,
reportActionID: iouAction.reportActionID,
transactionID: (linkedTrackedExpenseReportAction?.originalMessage as IOUMessage)?.IOUTransactionID,
actionableWhisperReportActionID,
createdChatReportActionID,
createdIOUReportActionID,
reportPreviewReportActionID: reportPreviewAction.reportActionID,
moneyRequestReportID: iouReport.reportID,
moneyRequestCreatedReportActionID: createdIOUReportActionID,
moneyRequestPreviewReportActionID: reportPreviewAction.reportActionID,
// modifiedExpenseReportActionID - not sure what need to be done here maybe `buildOptimisticModifiedExpenseReportAction` with transaction changes
};

API.write(WRITE_COMMANDS.CONVERT_TRACKED_EXPENSE_TO_REQUEST, parameters, onyxData);

Check failure on line 2325 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ payerAccountID: number; chatReportID: string; transactionID: string | undefined; actionableWhisperReportActionID: string | undefined; createdChatReportActionID: string; moneyRequestReportID: string; moneyRequestCreatedReportActionID: string; moneyRequestPreviewReportActionID: string; }' is not assignable to parameter of type 'ConvertTrackedExpenseToRequestParams'.
break;
}
case CONST.IOU.ACTION.CATEGORIZE: {
const parameters = {
policyID: chatReport.policyID,
transactionID: (linkedTrackedExpenseReportAction?.originalMessage as IOUMessage)?.IOUTransactionID,
actionableWhisperReportActionID,
moneyRequestPreviewReportActionID: reportPreviewAction.reportActionID,
moneyRequestReportID: iouReport.reportID,
moneyRequestCreatedReportActionID: createdChatReportActionID,
moneyRequestCreatedReportActionID: createdIOUReportActionID,
actionableWhisperReportActionID,
// modifiedExpenseReportActionID - not sure what need to be done here maybe `buildOptimisticModifiedExpenseReportAction` with transaction changes
};

console.log('Categorizing tracked expense', parameters);
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.CATEGORIZE_TRACKED_TRANSACTION, parameters, onyxData);

Check failure on line 2339 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ policyID: string | undefined; transactionID: string | undefined; moneyRequestPreviewReportActionID: string; moneyRequestReportID: string; moneyRequestCreatedReportActionID: string; actionableWhisperReportActionID: string | undefined; }' is not assignable to parameter of type 'CategorizeTrackedExpenseParams'.
break;
}
case CONST.IOU.ACTION.SHARE: {
const parameters = {
policyID: chatReport.policyID,
transactionID: (linkedTrackedExpenseReportAction?.originalMessage as IOUMessage)?.IOUTransactionID,
moneyRequestPreviewReportActionID: reportPreviewAction.reportActionID,
moneyRequestReportID: iouReport.reportID,
moneyRequestCreatedReportActionID: createdIOUReportActionID,
actionableWhisperReportActionID,
// modifiedExpenseReportActionID - not sure what need to be done here maybe `buildOptimisticModifiedExpenseReportAction` with transaction changes
};
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.SHARE_TRACKED_TRANSACTION, parameters, onyxData);

Check failure on line 2353 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type '{ policyID: string | undefined; transactionID: string | undefined; moneyRequestPreviewReportActionID: string; moneyRequestReportID: string; moneyRequestCreatedReportActionID: string; actionableWhisperReportActionID: string | undefined; }' is not assignable to parameter of type 'ShareTrackedExpenseParams'.
break;
}
default: {
const parameters: RequestMoneyParams = {
debtorEmail: payerEmail,
Expand Down Expand Up @@ -2364,7 +2387,14 @@ function requestMoney(
resetMoneyRequestInfo();
}
}

Navigation.dismissModal(activeReportID);
if (action === CONST.IOU.ACTION.SHARE) {
// not sure the correct way to navigate to the share should it be instant? todo: ask for clarification
setTimeout(() => {
Navigation.navigate(ROUTES.ROOM_MEMBERS.getRoute(activeReportID));
}, 1000);
}
Report.notifyNewAction(activeReportID, payeeAccountID);
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function ReportActionItem({
{
text: 'actionableMentionTrackExpense.share',
key: `${action.reportActionID}-actionableMentionTrackExpense-share`,
onPress: () => console.log('Share'),
onPress: () => ReportUtils.createDraftTransactionAndNavigateToParticipantSelector(transactionID, report.reportID, CONST.IOU.ACTION.SHARE, action.reportActionID),
isMediumSized: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
// sees the option to request money from their admin on their own Workspace Chat.
iouType === CONST.IOU.TYPE.REQUEST && iouAction !== CONST.IOU.ACTION.MOVE,

(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && iouAction !== CONST.IOU.ACTION.CATEGORIZE,
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && iouAction !== CONST.IOU.ACTION.CATEGORIZE && iouAction !== CONST.IOU.ACTION.SHARE,
false,
{},
[],
Expand Down Expand Up @@ -188,7 +188,20 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
}

return [newSections, chatOptions];
}, [didScreenTransitionEnd, reports, personalDetails, betas, debouncedSearchTerm, participants, iouType, canUseP2PDistanceRequests, iouRequestType, maxParticipantsReached, translate, iouAction]);
}, [
didScreenTransitionEnd,
reports,
personalDetails,
betas,
debouncedSearchTerm,
participants,
iouType,
canUseP2PDistanceRequests,
iouRequestType,
maxParticipantsReached,
translate,
iouAction,
]);

/**
* Adds a single participant to the request
Expand Down Expand Up @@ -266,7 +279,11 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({
// the app from crashing on native when you try to do this, we'll going to hide the button if you have a workspace and other participants
const hasPolicyExpenseChatParticipant = _.some(participants, (participant) => participant.isPolicyExpenseChat);
const shouldShowSplitBillErrorMessage = participants.length > 1 && hasPolicyExpenseChatParticipant;
const isAllowedToSplit = (canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) && iouType !== CONST.IOU.TYPE.SEND;
const isAllowedToSplit =
(canUseP2PDistanceRequests || iouRequestType !== CONST.IOU.REQUEST_TYPE.DISTANCE) &&
iouType !== CONST.IOU.TYPE.SEND &&
![CONST.IOU.ACTION.SHARE, CONST.IOU.ACTION.MOVE, CONST.IOU.ACTION.CATEGORIZE].includes(iouAction) &&
!shouldShowSplitBillErrorMessage;

const handleConfirmSelection = useCallback(
(keyEvent, option) => {
Expand Down Expand Up @@ -376,7 +393,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({

const isAllSectionsEmpty = _.every(sections, (section) => section.data.length === 0);

if (iouAction === CONST.IOU.ACTION.CATEGORIZE && isAllSectionsEmpty && didScreenTransitionEnd && searchTerm.trim() === '') {
if ([CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(iouAction) && isAllSectionsEmpty && didScreenTransitionEnd && searchTerm.trim() === '') {
return renderEmptyWorkspaceView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function (WrappedComponent) {
const transactionID = lodashGet(route, 'params.transactionID', 0);
const userAction = lodashGet(route, 'params.action', CONST.IOU.ACTION.CREATE);
return `${
[CONST.IOU.ACTION.CREATE, CONST.IOU.ACTION.MOVE, CONST.IOU.ACTION.CATEGORIZE].includes(userAction)
[CONST.IOU.ACTION.CREATE, CONST.IOU.ACTION.MOVE, CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].includes(userAction)
? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT
: ONYXKEYS.COLLECTION.TRANSACTION
}${transactionID}`;
Expand Down

0 comments on commit 4032202

Please sign in to comment.