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
17 changes: 14 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
canUserPerformWriteAction,
formatReportLastMessageText,
getAllReportErrors,
getChatByParticipants,
getChatRoomSubtitle,
getDeletedParentActionMessageForChatReport,
getDisplayNameForParticipant,
Expand All @@ -97,7 +98,6 @@ import {
getReportAutomaticallySubmittedMessage,
getReportLastMessage,
getReportName,
getReportNameValuePairs,
getReportNotificationPreference,
getReportOrDraftReport,
getReportParticipantsTitle,
Expand Down Expand Up @@ -355,6 +355,15 @@ Onyx.connect({
},
});

let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairs = value;
},
});

const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
Expand Down Expand Up @@ -859,7 +868,7 @@ function createOption(
result.participantsList = personalDetailList;
result.isOptimisticPersonalDetail = personalDetail?.isOptimisticPersonalDetail;
if (report) {
const reportNameValuePairs = getReportNameValuePairs(report.reportID);
const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`];
result.isChatRoom = reportUtilsIsChatRoom(report);
result.isDefaultRoom = isDefaultRoom(report);
result.private_isArchived = reportNameValuePairs?.private_isArchived;
Expand Down Expand Up @@ -2300,7 +2309,9 @@ function shouldUseBoldText(report: OptionData): boolean {

function getManagerMcTestParticipant(): Participant | undefined {
const managerMcTestPersonalDetails = Object.values(allPersonalDetails ?? {}).find((personalDetails) => personalDetails?.login === CONST.EMAIL.MANAGER_MCTEST);
return managerMcTestPersonalDetails ? getParticipantsOption(managerMcTestPersonalDetails, allPersonalDetails) : undefined;
const managerMcTestReport =
managerMcTestPersonalDetails?.accountID && currentUserAccountID ? getChatByParticipants([managerMcTestPersonalDetails?.accountID, currentUserAccountID]) : undefined;
return managerMcTestPersonalDetails ? {...getParticipantsOption(managerMcTestPersonalDetails, allPersonalDetails), reportID: managerMcTestReport?.reportID} : undefined;
}

export {
Expand Down
18 changes: 13 additions & 5 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ import {
getOutstandingChildRequest,
getParsedComment,
getPersonalDetailsForAccountID,
getReportNameValuePairs,
getReportNotificationPreference,
getReportOrDraftReport,
getReportTransactions,
Expand Down Expand Up @@ -667,6 +666,15 @@ Onyx.connect({
},
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we change this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh It seems the old funciton is deprecated

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairs = value;
},
});

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({
Expand Down Expand Up @@ -937,8 +945,8 @@ function setMoneyRequestBillable(transactionID: string, billable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {billable});
}

function setMoneyRequestParticipants(transactionID: string, participants: Participant[] = []) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants});
function setMoneyRequestParticipants(transactionID: string, participants: Participant[] = [], shouldUpdateReportID = false) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants, reportID: shouldUpdateReportID ? participants.at(0)?.reportID : undefined});
}

function setSplitPayer(transactionID: string, payerAccountID: number) {
Expand Down Expand Up @@ -8674,7 +8682,7 @@ function canApproveIOU(iouReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report> |
const isOpenExpenseReport = isOpenExpenseReportReportUtils(iouReport);
const isApproved = isReportApproved({report: iouReport});
const iouSettled = isSettled(iouReport);
const reportNameValuePairs = getReportNameValuePairs(iouReport?.reportID);
const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport?.reportID}`];
const isArchivedExpenseReport = isArchivedReport(reportNameValuePairs);
const reportTransactions = getReportTransactions(iouReport?.reportID);
const hasOnlyPendingCardOrScanningTransactions = reportTransactions.length > 0 && reportTransactions.every(isPendingCardOrScanningTransaction);
Expand Down Expand Up @@ -8709,7 +8717,7 @@ function canIOUBePaid(
shouldCheckApprovedState = true,
) {
const isPolicyExpenseChat = isPolicyExpenseChatReportUtil(chatReport);
const reportNameValuePairs = chatReportRNVP ?? getReportNameValuePairs(chatReport?.reportID);
const reportNameValuePairs = chatReportRNVP ?? allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${chatReport?.reportID}`];
const isChatReportArchived = isArchivedReport(reportNameValuePairs);
const iouSettled = isSettled(iouReport);

Expand Down
43 changes: 27 additions & 16 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Navigation from '@libs/Navigation/Navigation';
import {getIsUserSubmittedExpenseOrScannedReceipt, getManagerMcTestParticipant, getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import Permissions from '@libs/Permissions';
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import {generateReportID, getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getDefaultTaxCode} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -94,15 +94,15 @@ function IOURequestStepScan({
const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false);
const [fileResize, setFileResize] = useState<null | FileObject>(null);
const [fileSource, setFileSource] = useState('');
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`, {canBeMissing: true});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false});
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
const platform = getPlatform(true);
const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS);
const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS, {canBeMissing: true});
const isPlatformMuted = mutedPlatforms[platform];
const [cameraPermissionStatus, setCameraPermissionStatus] = useState<string | null>(null);
const [didCapturePhoto, setDidCapturePhoto] = useState(false);
Expand Down Expand Up @@ -255,7 +255,7 @@ function IOURequestStepScan({
}, [iouType, reportID, transactionID]);

const navigateToConfirmationPage = useCallback(
(isTestTransaction = false) => {
(isTestTransaction = false, reportIDParam: string | undefined = undefined) => {
switch (iouType) {
case CONST.IOU.TYPE.REQUEST:
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, transactionID, reportID));
Expand All @@ -265,7 +265,13 @@ function IOURequestStepScan({
break;
default:
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, isTestTransaction ? CONST.IOU.TYPE.SUBMIT : iouType, transactionID, reportID),
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
CONST.IOU.ACTION.CREATE,
isTestTransaction ? CONST.IOU.TYPE.SUBMIT : iouType,
transactionID,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
reportIDParam || reportID,
),
);
}
},
Expand Down Expand Up @@ -319,6 +325,17 @@ function IOURequestStepScan({
return;
}

if (isTestTransaction) {
const managerMcTestParticipant = getManagerMcTestParticipant() ?? {};
let reportIDParam = managerMcTestParticipant.reportID;
if (!managerMcTestParticipant.reportID && report?.reportID) {
reportIDParam = generateReportID();
}
setMoneyRequestParticipants(transactionID, [{...managerMcTestParticipant, reportID: reportIDParam, selected: true}], true);
navigateToConfirmationPage(true, reportIDParam);
return;
}

// If a reportID exists in the report object, it's because either:
// - The user started this flow from using the + button in the composer inside a report.
// - The user started this flow from using the global create menu by selecting the Track expense option.
Expand Down Expand Up @@ -451,12 +468,6 @@ function IOURequestStepScan({
);
});
} else {
if (isTestTransaction) {
const managerMcTestParticipant = getManagerMcTestParticipant() ?? {};
setMoneyRequestParticipants(transactionID, [{...managerMcTestParticipant, selected: true}]);
navigateToConfirmationPage(true);
return;
}
navigateToParticipantPage();
}
},
Expand Down
41 changes: 26 additions & 15 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Navigation from '@libs/Navigation/Navigation';
import {getIsUserSubmittedExpenseOrScannedReceipt, getManagerMcTestParticipant, getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import Permissions from '@libs/Permissions';
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import {generateReportID, getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getDefaultTaxCode} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -111,13 +111,13 @@ function IOURequestStepScan({
const [elementTop, setElementTop] = useState(0);

const getScreenshotTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`, {canBeMissing: true});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false});
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: false});
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);

const [videoConstraints, setVideoConstraints] = useState<MediaTrackConstraints>();
Expand Down Expand Up @@ -279,7 +279,7 @@ function IOURequestStepScan({
}, [iouType, reportID, transactionID]);

const navigateToConfirmationPage = useCallback(
(isTestTransaction = false) => {
(isTestTransaction = false, reportIDParam: string | undefined = undefined) => {
switch (iouType) {
case CONST.IOU.TYPE.REQUEST:
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, transactionID, reportID));
Expand All @@ -289,7 +289,13 @@ function IOURequestStepScan({
break;
default:
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, isTestTransaction ? CONST.IOU.TYPE.SUBMIT : iouType, transactionID, reportID),
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
CONST.IOU.ACTION.CREATE,
isTestTransaction ? CONST.IOU.TYPE.SUBMIT : iouType,
transactionID,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
reportIDParam || reportID,
),
);
}
},
Expand Down Expand Up @@ -343,6 +349,17 @@ function IOURequestStepScan({
return;
}

if (isTestTransaction) {
const managerMcTestParticipant = getManagerMcTestParticipant() ?? {};
let reportIDParam = managerMcTestParticipant.reportID;
if (!managerMcTestParticipant.reportID && report?.reportID) {
reportIDParam = generateReportID();
}
setMoneyRequestParticipants(transactionID, [{...managerMcTestParticipant, reportID: reportIDParam, selected: true}], true);
navigateToConfirmationPage(true, reportIDParam);
return;
}

// If a reportID exists in the report object, it's because either:
// - The user started this flow from using the + button in the composer inside a report.
// - The user started this flow from using the global create menu by selecting the Track expense option.
Expand Down Expand Up @@ -475,12 +492,6 @@ function IOURequestStepScan({
);
});
} else {
if (isTestTransaction) {
const managerMcTestParticipant = getManagerMcTestParticipant() ?? {};
setMoneyRequestParticipants(transactionID, [{...managerMcTestParticipant, selected: true}]);
navigateToConfirmationPage(true);
return;
}
navigateToParticipantPage();
}
},
Expand Down