Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ const CONST = {
TRACK_FLOWS: 'trackFlows',
EUR_BILLING: 'eurBilling',
MANUAL_DISTANCE: 'manualDistance',
NO_OPTIMISTIC_TRANSACTION_THREADS: 'noOptimisticTransactionThreads',
VACATION_DELEGATE: 'vacationDelegate',
},
BUTTON_STATES: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CreatePerDiemRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type CreatePerDiemRequestParams = {
createdChatReportActionID?: string;
createdIOUReportActionID?: string;
reportPreviewReportActionID: string;
transactionThreadReportID: string;
transactionThreadReportID?: string;
createdReportActionIDForThread: string | undefined;
billable?: boolean;
reimbursable?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type RequestMoneyParams = {
taxAmount: number;
billable?: boolean;
receiptGpsPoints?: string;
transactionThreadReportID: string;
transactionThreadReportID?: string;
createdReportActionIDForThread: string | undefined;
reimbursable?: boolean;
description?: string;
Expand Down
27 changes: 22 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@
| 'delegateAccountID'
> & {reportID?: string};

type OptimisticMoneyRequestEntities = {
type BaseOptimisticMoneyRequestEntities = {
iouReport: Report;
type: ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>;
amount: number;
Expand All @@ -655,6 +655,10 @@
optimisticCreatedReportActionID?: string;
};

type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & {shouldGenerateTransactionThreadReport?: boolean};
type OptimisticMoneyRequestEntitiesWithTransactionThreadFlag = BaseOptimisticMoneyRequestEntities & {shouldGenerateTransactionThreadReport: boolean};
type OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag = BaseOptimisticMoneyRequestEntities;

type OptimisticTaskReport = SetRequired<
Pick<
Report,
Expand Down Expand Up @@ -893,7 +897,7 @@
// to prevent unnecessary parsing when the report action is not changed/modified.
// Example case: when we need to get a report name of a thread which is dependent on a report action message.
const parsedReportActionMessageCache: Record<string, string> = {};

Check warning on line 900 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let conciergeReportID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.CONCIERGE_REPORT_ID,
Expand All @@ -901,7 +905,7 @@
conciergeReportID = value;
},
});

Check warning on line 908 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({
key: ONYXKEYS.SESSION,
Expand All @@ -919,7 +923,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];

Check warning on line 926 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
Expand All @@ -931,14 +935,14 @@
allPersonalDetailLogins = Object.values(allPersonalDetails).map((personalDetail) => personalDetail?.login ?? '');
},
});

Check warning on line 938 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

Check warning on line 945 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let allPolicies: OnyxCollection<Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
Expand All @@ -946,7 +950,7 @@
callback: (value) => (allPolicies = value),
});

let allReports: OnyxCollection<Report>;

Check warning on line 953 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -987,14 +991,14 @@
}, {});
},
});

Check warning on line 994 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),
});

let allTransactions: OnyxCollection<Transaction> = {};

Check warning on line 1001 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
Expand All @@ -1020,7 +1024,7 @@
}, {});
},
});

Check warning on line 1027 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
Expand All @@ -1033,7 +1037,7 @@
},
});

let allReportMetadata: OnyxCollection<ReportMetadata>;

Check warning on line 1040 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
const allReportMetadataKeyValue: Record<string, ReportMetadata> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_METADATA,
Expand Down Expand Up @@ -7820,6 +7824,12 @@
* 4. Transaction Thread linked to the IOU action via `parentReportActionID`
* 5. CREATED action for the Transaction Thread
*/
function buildOptimisticMoneyRequestEntities(
optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag,
): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null];
function buildOptimisticMoneyRequestEntities(
optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithTransactionThreadFlag,
): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport | undefined, OptimisticCreatedReportAction | null];
function buildOptimisticMoneyRequestEntities({
iouReport,
type,
Expand All @@ -7837,7 +7847,14 @@
existingTransactionThreadReportID,
linkedTrackedExpenseReportAction,
optimisticCreatedReportActionID,
}: OptimisticMoneyRequestEntities): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] {
shouldGenerateTransactionThreadReport = true,
}: OptimisticMoneyRequestEntities): [
OptimisticCreatedReportAction,
OptimisticCreatedReportAction,
OptimisticIOUReportAction,
OptimisticChatReport | undefined,
OptimisticCreatedReportAction | null,
] {
const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail, undefined, optimisticCreatedReportActionID);

// The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat.
Expand All @@ -7862,11 +7879,11 @@
});

// Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined
const transactionThread = buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID);
const createdActionForTransactionThread = existingTransactionThreadReportID ? null : buildOptimisticCreatedReportAction(payeeEmail);
const transactionThread = shouldGenerateTransactionThreadReport ? buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID) : undefined;
const createdActionForTransactionThread = !!existingTransactionThreadReportID || !shouldGenerateTransactionThreadReport ? null : buildOptimisticCreatedReportAction(payeeEmail);

// The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together
iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread.reportID;
iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread?.reportID;

return [createdActionForChat, createdActionForIOUReport, iouAction, transactionThread, createdActionForTransactionThread];
}
Expand Down
118 changes: 70 additions & 48 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ type MoneyRequestInformation = {
createdChatReportActionID?: string;
createdIOUReportActionID?: string;
reportPreviewAction: OnyxTypes.ReportAction;
transactionThreadReportID: string;
transactionThreadReportID?: string;
createdReportActionIDForThread: string | undefined;
onyxData: OnyxData;
billable?: boolean;
Expand Down Expand Up @@ -444,6 +444,7 @@ type RequestMoneyInformation = {
optimisticCreatedReportActionID?: string;
optimisticIOUReportID?: string;
optimisticReportPreviewActionID?: string;
shouldGenerateTransactionThreadReport: boolean;
};

type MoneyRequestInformationParams = {
Expand All @@ -461,6 +462,7 @@ type MoneyRequestInformationParams = {
optimisticCreatedReportActionID?: string;
optimisticIOUReportID?: string;
optimisticReportPreviewActionID?: string;
shouldGenerateTransactionThreadReport?: boolean;
};

type MoneyRequestOptimisticParams = {
Expand All @@ -476,7 +478,7 @@ type MoneyRequestOptimisticParams = {
};
transactionParams: {
transaction: OnyxTypes.Transaction;
transactionThreadReport: OptimisticChatReport | null;
transactionThreadReport?: OptimisticChatReport | null;
transactionThreadCreatedReportAction: OptimisticCreatedReportAction | null;
};
policyRecentlyUsed: {
Expand All @@ -499,6 +501,7 @@ type BuildOnyxDataForMoneyRequestParams = {
optimisticParams: MoneyRequestOptimisticParams;
retryParams?: StartSplitBilActionParams | CreateTrackExpenseParams | RequestMoneyInformation | ReplaceReceipt;
participant?: Participant;
shouldGenerateTransactionThreadReport?: boolean;
};

type DistanceRequestTransactionParams = BaseTransactionParams & {
Expand Down Expand Up @@ -1423,6 +1426,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
optimisticParams,
retryParams,
participant,
shouldGenerateTransactionThreadReport = true,
} = moneyRequestParams;
const {policy, policyCategories, policyTagList} = policyParams;
const {
Expand Down Expand Up @@ -1525,22 +1529,27 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
[iou.action.reportActionID]: iou.action as OnyxTypes.ReportAction,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
...transactionThreadReport,
pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
);

if (shouldGenerateTransactionThreadReport) {
optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
...transactionThreadReport,
pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`,
value: {
isOptimisticReport: true,
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`,
value: {
isOptimisticReport: true,
},
},
},
);
);
}

if (isNewChatReport) {
optimisticData.push({
Expand All @@ -1562,7 +1571,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
});
}

if (!isEmptyObject(transactionThreadCreatedReportAction)) {
if (shouldGenerateTransactionThreadReport && !isEmptyObject(transactionThreadCreatedReportAction)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`,
Expand Down Expand Up @@ -1740,22 +1749,6 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
isOptimisticReport: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
participants: redundantParticipants,
pendingFields: null,
errorFields: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`,
value: {
isOptimisticReport: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
Expand Down Expand Up @@ -1810,7 +1803,28 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
},
);

if (!isEmptyObject(transactionThreadCreatedReportAction)) {
if (shouldGenerateTransactionThreadReport) {
successData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
participants: redundantParticipants,
pendingFields: null,
errorFields: null,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`,
value: {
isOptimisticReport: false,
},
},
);
}

if (shouldGenerateTransactionThreadReport && !isEmptyObject(transactionThreadCreatedReportAction)) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`,
Expand Down Expand Up @@ -1855,18 +1869,6 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
pendingFields: null,
errorFields: existingTransactionThreadReport
? null
: {
createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
Expand Down Expand Up @@ -1924,6 +1926,21 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
},
);

if (shouldGenerateTransactionThreadReport) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.reportID}`,
value: {
pendingFields: null,
errorFields: existingTransactionThreadReport
? null
: {
createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'),
},
},
});
}

if (!isOneOnOneSplit) {
optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
Expand All @@ -1941,7 +1958,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
});
}

if (!isEmptyObject(transactionThreadCreatedReportAction)) {
if (shouldGenerateTransactionThreadReport && !isEmptyObject(transactionThreadCreatedReportAction)) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`,
Expand Down Expand Up @@ -3298,6 +3315,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
optimisticCreatedReportActionID,
optimisticIOUReportID,
optimisticReportPreviewActionID,
shouldGenerateTransactionThreadReport = true,
} = moneyRequestInformation;
const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams;
const {policy, policyCategories, policyTagList} = policyParams;
Expand Down Expand Up @@ -3443,6 +3461,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
existingTransactionThreadReportID: linkedTrackedExpenseReportAction?.childReportID,
optimisticCreatedReportActionID,
linkedTrackedExpenseReportAction,
shouldGenerateTransactionThreadReport,
});

let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID);
Expand Down Expand Up @@ -3481,6 +3500,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
participant,
isNewChatReport,
shouldCreateNewMoneyRequestReport,
shouldGenerateTransactionThreadReport,
policyParams: {
policy,
policyCategories,
Expand Down Expand Up @@ -5045,7 +5065,7 @@ type ConvertTrackedExpenseToRequestParams = {
merchant: string;
created: string;
attendees?: Attendee[];
transactionThreadReportID: string;
transactionThreadReportID?: string;
};
chatParams: {
reportID: string;
Expand Down Expand Up @@ -5469,6 +5489,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
optimisticCreatedReportActionID,
optimisticIOUReportID,
optimisticReportPreviewActionID,
shouldGenerateTransactionThreadReport,
} = requestMoneyInformation;
const {payeeAccountID} = participantParams;
const parsedComment = getParsedComment(transactionParams.comment ?? '');
Expand Down Expand Up @@ -5552,6 +5573,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
optimisticCreatedReportActionID,
optimisticIOUReportID,
optimisticReportPreviewActionID,
shouldGenerateTransactionThreadReport,
});
const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport.reportID;

Expand Down
5 changes: 5 additions & 0 deletions src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useFilesValidation from '@hooks/useFilesValidation';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import useThemeStyles from '@hooks/useThemeStyles';
import type {GpsPoint} from '@libs/actions/IOU';
import {getIOURequestPolicyID, getMoneyRequestParticipantsFromReport, initMoneyRequest, requestMoney, trackExpense, updateLastLocationPermissionPrompt} from '@libs/actions/IOU';
Expand Down Expand Up @@ -58,6 +59,9 @@ function SubmitDetailsPage({
const [errorTitle, setErrorTitle] = useState<string | undefined>(undefined);
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);

const {isBetaEnabled} = usePermissions();
const shouldGenerateTransactionThreadReport = !isBetaEnabled(CONST.BETAS.NO_OPTIMISTIC_TRANSACTION_THREADS);

const [validFilesToUpload, setValidFilesToUpload] = useState<FileObject[]>([]);
const {validateFiles} = useFilesValidation(setValidFilesToUpload);

Expand Down Expand Up @@ -153,6 +157,7 @@ function SubmitDetailsPage({
linkedTrackedExpenseReportAction: transaction.linkedTrackedExpenseReportAction,
linkedTrackedExpenseReportID: transaction.linkedTrackedExpenseReportID,
},
shouldGenerateTransactionThreadReport,
});
}
};
Expand Down
Loading
Loading