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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ function ReviewDuplicatesPrimaryAction({reportID, chatReportID}: SimpleActionPro
} else {
const transactionID = duplicateTransaction.transactionID;
const iouAction = getIOUActionForReportID(moneyRequestReport?.reportID, transactionID);
const createdTransactionThreadReport = createTransactionThreadReport(introSelected, email ?? '', accountID, betas, moneyRequestReport, iouAction);
const createdTransactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserLogin: email ?? '',
currentUserAccountID: accountID,
betas,
iouReport: moneyRequestReport,
iouReportAction: iouAction,
});
threadID = createdTransactionThreadReport?.reportID;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,15 @@ function MoneyRequestReportTransactionList({

if (!reportIDToNavigate) {
const transaction = sortedTransactions.find((t) => t.transactionID === activeTransactionID);
const transactionThreadReport = createTransactionThreadReport(
const transactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserDetails.email ?? '',
currentUserDetails.accountID,
currentUserLogin: currentUserDetails.email ?? '',
currentUserAccountID: currentUserDetails.accountID,
betas,
report,
iouAction,
iouReport: report,
iouReportAction: iouAction,
transaction,
);
});
if (transactionThreadReport) {
reportIDToNavigate = transactionThreadReport.reportID;
routeParams.reportID = reportIDToNavigate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, isFromR
}
// The transaction thread doesn't exist yet, so we should create it
if (!nextThreadReportID) {
const transactionThreadReport = createTransactionThreadReport(
const transactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserEmail ?? '',
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
parentReport,
nextParentReportAction,
nextTransaction,
);
iouReport: parentReport,
iouReportAction: nextParentReportAction,
transaction: nextTransaction,
});
navigationParams.reportID = transactionThreadReport?.reportID;
}
// Wait for the next frame to ensure Onyx has processed the optimistic data updates from setOptimisticTransactionThread or createTransactionThreadReport before navigating
Expand Down Expand Up @@ -172,15 +172,15 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, isFromR
}
// The transaction thread doesn't exist yet, so we should create it
if (!prevThreadReportID) {
const transactionThreadReport = createTransactionThreadReport(
const transactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserEmail ?? '',
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
parentReport,
prevParentReportAction,
prevTransaction,
);
iouReport: parentReport,
iouReportAction: prevParentReportAction,
transaction: prevTransaction,
});
navigationParams.reportID = transactionThreadReport?.reportID;
}
// Wait for the next frame to ensure Onyx has processed the optimistic data updates from setOptimisticTransactionThread or createTransactionThreadReport before navigating
Expand Down
9 changes: 8 additions & 1 deletion src/components/ReportActionItem/MoneyRequestAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ function MoneyRequestAction({
const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : CONST.DEFAULT_NUMBER_ID;

if (!action?.childReportID && transactionID && action.reportActionID) {
const transactionThreadReport = createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, iouReport, action);
const transactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
iouReport,
iouReportAction: action,
});
if (shouldOpenReportInRHP) {
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo: Navigation.getActiveRoute()}));
return;
Expand Down
8 changes: 6 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11595,8 +11595,11 @@ type PrepareOnboardingOnyxDataParams = {
selectedInterestedFeatures?: string[];
isInvitedAccountant?: boolean;
onboardingPurposeSelected?: OnboardingPurpose;
isSelfTourViewed?: boolean;
betas: OnyxEntry<Beta[]>;
// TODO: isSelfTourViewed will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
isSelfTourViewed?: boolean;
// TODO: hasCompletedGuidedSetupFlow will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;
};

function getBespokeWelcomeMessage(companySize: OnboardingCompanySize | undefined, userReportedIntegration?: OnboardingAccounting): string {
Expand Down Expand Up @@ -11652,6 +11655,7 @@ function prepareOnboardingOnyxData({
onboardingPurposeSelected,
isSelfTourViewed,
betas,
hasCompletedGuidedSetupFlow,
}: PrepareOnboardingOnyxDataParams) {
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) {
// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -12208,7 +12212,7 @@ function prepareOnboardingOnyxData({
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_ONBOARDING,
value: {hasCompletedGuidedSetupFlow: onboarding?.hasCompletedGuidedSetupFlow ?? null},
value: {hasCompletedGuidedSetupFlow: hasCompletedGuidedSetupFlow ?? onboarding?.hasCompletedGuidedSetupFlow ?? null},
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2519,16 +2519,16 @@ function createAndOpenSearchTransactionThread(
const transaction = shouldPassTransactionData ? getTransactionFromTransactionListItem(item) : undefined;
const transactionViolations = shouldPassTransactionData ? item.violations : undefined;
const reportActionToPass = iouReportAction ?? item.reportAction ?? ({reportActionID} as OnyxTypes.ReportAction);
transactionThreadReport = createTransactionThreadReport(
transactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserLogin ?? '',
currentUserLogin: currentUserLogin ?? '',
currentUserAccountID,
betas,
getReportOrDraftReport(item.reportID) ?? item.report,
reportActionToPass,
iouReport: getReportOrDraftReport(item.reportID) ?? item.report,
iouReportAction: reportActionToPass,
transaction,
transactionViolations,
);
});
}

if (shouldNavigate) {
Expand Down
10 changes: 9 additions & 1 deletion src/libs/actions/IOU/BulkEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ function updateMultipleMoneyRequests({
// bulk-edit comments are visible immediately while still offline.
let didCreateThreadInThisIteration = false;
if (!transactionThreadReportID && iouReport?.reportID) {
const optimisticTransactionThread = createTransactionThreadReport(introSelected, currentUserLogin, currentUserAccountID, betas, iouReport, reportAction, transaction);
const optimisticTransactionThread = createTransactionThreadReport({
introSelected,
currentUserLogin,
currentUserAccountID,
betas,
iouReport,
iouReportAction: reportAction,
transaction,
});
if (optimisticTransactionThread?.reportID) {
transactionThreadReportID = optimisticTransactionThread.reportID;
transactionThread = optimisticTransactionThread;
Expand Down
79 changes: 65 additions & 14 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ type OpenReportActionParams = {
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
isSelfTourViewed?: boolean;

/** Whether the user has completed the guided setup flow */
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;

/** Beta features list */
betas: OnyxEntry<Beta[]>;
};
Expand Down Expand Up @@ -1306,9 +1310,11 @@ function getGuidedSetupDataForOpenReport(
betas: OnyxEntry<Beta[]>,
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
isSelfTourViewed?: boolean,
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean,
): GuidedSetupDataForOpenReport | undefined {
const isInviteOnboardingComplete = introSelected?.isInviteOnboardingComplete ?? false;
const isOnboardingCompleted = onboarding?.hasCompletedGuidedSetupFlow ?? false;
const isOnboardingCompleted = hasCompletedGuidedSetupFlow ?? onboarding?.hasCompletedGuidedSetupFlow ?? false;

// Some cases we can have two open report requests with guide setup data because isInviteOnboardingComplete is not updated completely.
// Then we need to check the list request and prevent the guided setup data from being duplicated.
Expand Down Expand Up @@ -1341,6 +1347,7 @@ function getGuidedSetupDataForOpenReport(
onboardingMessage,
companySize: introSelected?.companySize as OnboardingCompanySize,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
betas,
});

Expand Down Expand Up @@ -1388,6 +1395,7 @@ function openReport(params: OpenReportActionParams) {
currentUserLogin,
currentUserAccountID,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
betas,
} = params;
if (!reportID) {
Expand Down Expand Up @@ -1619,7 +1627,7 @@ function openReport(params: OpenReportActionParams) {
});
}

const guidedSetup = getGuidedSetupDataForOpenReport(introSelected, betas, isSelfTourViewed);
const guidedSetup = getGuidedSetupDataForOpenReport(introSelected, betas, isSelfTourViewed, hasCompletedGuidedSetupFlow);
if (guidedSetup) {
optimisticData.push(...guidedSetup.optimisticData);
successData.push(...guidedSetup.successData);
Expand Down Expand Up @@ -2022,18 +2030,59 @@ function getOptimisticChatReport(accountID: number, currentUserAccountID: number
});
}

function createTransactionThreadReport(
introSelected: OnyxEntry<IntroSelected>,
currentUserLogin: string,
currentUserAccountID: number,
betas: OnyxEntry<Beta[]>,
iouReport?: OnyxEntry<Report>,
iouReportAction?: OnyxEntry<ReportAction>,
transaction?: Transaction,
transactionViolations?: TransactionViolations,
type CreateTransactionThreadReportParams = {
/** The intro selected by the user */
introSelected: OnyxEntry<IntroSelected>;

/** The current user's login */
currentUserLogin: string;

/** The current user's account ID */
currentUserAccountID: number;

/** Beta features list */
betas: OnyxEntry<Beta[]>;

/** The IOU report that the transaction thread is being created from */
iouReport?: OnyxEntry<Report>;

/** The IOU report action that the transaction thread is being created from */
iouReportAction?: OnyxEntry<ReportAction>;

/** The transaction object for legacy transactions that don't have a transaction thread or money request preview yet */
transaction?: Transaction;

/** The violations for the transaction, if any */
transactionViolations?: TransactionViolations;

// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
personalDetails?: OnyxEntry<PersonalDetailsList>,
): OptimisticChatReport | undefined {
/** The personal details of the participants */
personalDetails?: OnyxEntry<PersonalDetailsList>;

/** Whether the user has seen the self tour */
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
isSelfTourViewed?: boolean;

/** Whether the user has completed the guided setup flow */
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;
};

function createTransactionThreadReport(params: CreateTransactionThreadReportParams): OptimisticChatReport | undefined {
const {
introSelected,
currentUserLogin,
currentUserAccountID,
betas,
iouReport,
iouReportAction,
transaction,
transactionViolations,
personalDetails,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
} = params;

// Determine if we need selfDM report (for track expenses or unreported transactions)
const isTrackExpense = !iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction);
const isUnreportedTransaction = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
Expand Down Expand Up @@ -2088,6 +2137,8 @@ function createTransactionThreadReport(
optimisticSelfDMReport,
currentUserLogin,
currentUserAccountID,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
betas,
});
return optimisticTransactionThread;
Expand Down Expand Up @@ -7669,7 +7720,7 @@ function clearConciergeThinkingKickoff() {
Onyx.set(ONYXKEYS.CONCIERGE_THINKING_KICKOFF, null);
}

export type {Video, GuidedSetupData, TaskForParameters, IntroSelected, OpenReportActionParams, ParticipantInfo};
export type {Video, GuidedSetupData, TaskForParameters, IntroSelected, OpenReportActionParams, ParticipantInfo, CreateTransactionThreadReportParams};

export {
addAttachmentWithComment,
Expand Down
19 changes: 17 additions & 2 deletions src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {

if (transactionThreadReportID === CONST.FAKE_REPORT_ID && oneTransactionID) {
const iouAction = getIOUActionForTransactionID(reportActions, oneTransactionID);
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, iouAction);
createTransactionThreadReport({
introSelected,
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
iouReport: report,
iouReportAction: iouAction,
});
return;
}

Expand Down Expand Up @@ -267,7 +274,15 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
hasCreatedLegacyThreadRef.current = true;

const violations = allReportViolations[transaction.transactionID] ?? snapshotViolations;
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, undefined, transaction, violations);
createTransactionThreadReport({
introSelected,
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
iouReport: report,
transaction,
transactionViolations: violations,
});
}, [
allReportTransactions,
allReportViolations,
Expand Down
19 changes: 17 additions & 2 deletions src/pages/inbox/ReportFetchHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ function ReportFetchHandler() {
);
const oneTransactionID = currentReportTransactions.at(0)?.transactionID;
const iouAction = getIOUActionForReportID(reportID, oneTransactionID);
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, iouAction, currentReportTransactions.at(0));
createTransactionThreadReport({
introSelected,
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
iouReport: report,
iouReportAction: iouAction,
transaction: currentReportTransactions.at(0),
});
});

const onUnmount = useEffectEvent(() => {
Expand Down Expand Up @@ -341,7 +349,14 @@ function ReportFetchHandler() {

// For legacy transactions, pass undefined as IOU action and the transaction object
// It will be created optimistically and in the backend when call openReport
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, undefined, transaction);
createTransactionThreadReport({
introSelected,
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
betas,
iouReport: report,
transaction,
});
}, [
introSelected,
currentUserEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ function ChatTransactionPreview({action, reportID, originalReportID, chatReportI

// If no childReportID exists, create transaction thread on-demand
if (!action.childReportID) {
const createdTransactionThreadReport = createTransactionThreadReport(introSelected, personalDetail.email ?? '', personalDetail.accountID, betas, iouReport, action);
const createdTransactionThreadReport = createTransactionThreadReport({
introSelected,
currentUserLogin: personalDetail.email ?? '',
currentUserAccountID: personalDetail.accountID,
betas,
iouReport,
iouReportAction: action,
});
if (createdTransactionThreadReport?.reportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(createdTransactionThreadReport.reportID, undefined, undefined, Navigation.getActiveRoute()));
return;
Expand Down
Loading
Loading