Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/hooks/useDeleteTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import passthroughPolicyTagListSelector from '@selectors/PolicyTagList';
import {useCallback} from 'react';

import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useDelegateAccountID from './useDelegateAccountID';
import useEnvironment from './useEnvironment';
import useNetwork from './useNetwork';
import useOnyx from './useOnyx';
Expand Down Expand Up @@ -80,6 +81,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [allSnapshots] = useOnyx(ONYXKEYS.COLLECTION.SNAPSHOT);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const delegateAccountID = useDelegateAccountID();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
Expand Down Expand Up @@ -320,6 +322,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
transactionReport: report,
expenseReport,
isOffline,
delegateAccountID,
});
}

Expand Down Expand Up @@ -392,6 +395,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
isOffline,
isProduction,
personalPolicy?.outputCurrency,
delegateAccountID,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useTransactionInlineEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {useCallback, useRef} from 'react';
// eslint-disable-next-line no-restricted-imports -- Need original useOnyx to avoid reading partial Search snapshot policy data.
import {useOnyx as originalUseOnyx} from 'react-native-onyx';

import useDelegateAccountID from './useDelegateAccountID';
import useDistanceRateOriginalPolicy from './useDistanceRateOriginalPolicy';
import useNetwork from './useNetwork';
import useOnyx from './useOnyx';
Expand Down Expand Up @@ -79,6 +80,7 @@ type UseTransactionInlineEditReturn = {
};

function useTransactionInlineEdit({transactionID, hash, linkedReportAction}: UseTransactionInlineEditParams): UseTransactionInlineEditReturn {
const delegateAccountID = useDelegateAccountID();
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);

const reportID = transaction?.reportID;
Expand Down Expand Up @@ -182,6 +184,7 @@ function useTransactionInlineEdit({transactionID, hash, linkedReportAction}: Use
isSelfTourViewed: guidedSetupAndTourStatus?.isSelfTourViewed ?? false,
hasCompletedGuidedSetupFlow: guidedSetupAndTourStatus?.hasCompletedGuidedSetupFlow ?? false,
distanceOriginalPolicy,
delegateAccountID,
};
};

Expand Down
69 changes: 37 additions & 32 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ type CreateSplitsAndOnyxDataParams = {
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
// TODO: delegateAccountID will be made required in PR 11 when all callers pass the value (https://github.com/Expensify/App/issues/66425)
delegateAccountID?: number | undefined;
delegateAccountID: number | undefined;
};

type StartSplitBilActionParams = {
Expand All @@ -197,6 +196,21 @@ type StartSplitBilActionParams = {
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
policyRecentlyUsedCurrencies: string[];
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
delegateAccountID: number | undefined;
};

type CompleteSplitBillActionParams = {
chatReportID: string;
reportAction: OnyxEntry<OnyxTypes.ReportAction>;
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>;
sessionAccountID: number;
isASAPSubmitBetaEnabled: boolean;
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
delegateAccountID: number | undefined;
sessionEmail?: string;
};

type SplitBillActionsParams = {
Expand Down Expand Up @@ -229,8 +243,7 @@ type SplitBillActionsParams = {
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
shouldHandleNavigation?: boolean;
shouldDeferForSearch?: boolean;
// TODO: delegateAccountID will be made required in PR 11 when all callers pass the value (https://github.com/Expensify/App/issues/66425)
delegateAccountID?: number | undefined;
delegateAccountID: number | undefined;
};

/**
Expand Down Expand Up @@ -485,6 +498,7 @@ function startSplitBill({
participantsPolicyTags,
shouldHandleNavigation = true,
shouldDeferForSearch = false,
delegateAccountID,
}: StartSplitBilActionParams) {
const currentUserEmailForIOUSplit = addSMSDomainIfPhoneNumber(currentUserLogin);
const participantAccountIDs = participants.map((participant) => Number(participant.accountID));
Expand Down Expand Up @@ -526,8 +540,7 @@ function startSplitBill({
transactionID: splitTransaction.transactionID,
isOwnPolicyExpenseChat,
iouReportID: splitChatReport.reportID,
// delegateAccountIDParam: will be threaded in PR 11; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
delegateAccountIDParam: undefined,
delegateAccountIDParam: delegateAccountID,
});

splitChatReport.lastReadTime = DateUtils.getDBTime();
Expand Down Expand Up @@ -676,6 +689,7 @@ function startSplitBill({
policyRecentlyUsedCurrencies,
policyRecentlyUsedTags,
participantsPolicyTags,
delegateAccountID,
};

if (existingSplitChatReport) {
Expand Down Expand Up @@ -855,26 +869,20 @@ function startSplitBill({
return {splitTransactionID: splitTransaction.transactionID};
}

/** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above.
*
* @param chatReportID - The group chat or workspace reportID
* @param reportAction - The split action that lives in the chatReport above
* @param updatedTransaction - The updated **draft** split transaction
* @param sessionAccountID - accountID of the current user
* @param sessionEmail - email of the current user
*/
function completeSplitBill(
chatReportID: string,
reportAction: OnyxEntry<OnyxTypes.ReportAction>,
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>,
sessionAccountID: number,
isASAPSubmitBetaEnabled: boolean,
quickAction: OnyxEntry<OnyxTypes.QuickAction>,
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>,
betas: OnyxEntry<OnyxTypes.Beta[]>,
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>,
sessionEmail?: string,
) {
/** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above. */
function completeSplitBill({
chatReportID,
reportAction,
updatedTransaction,
sessionAccountID,
isASAPSubmitBetaEnabled,
quickAction,
transactionViolations,
betas,
personalDetails,
delegateAccountID,
sessionEmail,
}: CompleteSplitBillActionParams) {
if (!reportAction) {
return;
}
Expand Down Expand Up @@ -1077,16 +1085,14 @@ function completeSplitBill(
participants: [participant],
transactionID: oneOnOneTransaction.transactionID,
currentUserAccountID: sessionAccountID,
// delegateAccountIDParam: will be threaded in PR 11; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
delegateAccountIDParam: undefined,
delegateAccountIDParam: delegateAccountID,
});

let oneOnOneReportPreviewAction = getReportPreviewAction(oneOnOneChatReport?.reportID, oneOnOneIOUReport?.reportID);
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction);
} else {
// delegateAccountID: will be threaded in PR 11; buildOptimisticReportPreview falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, undefined);
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction, undefined, undefined, delegateAccountID);
}
const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, sessionAccountID, sessionEmail ?? '');

Expand Down Expand Up @@ -1122,8 +1128,7 @@ function completeSplitBill(
},
quickAction,
personalDetails,
// delegateAccountID: will be threaded in PR 11; buildOptimisticIOUReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
delegateAccountID: undefined,
delegateAccountID,
});

splits.push({
Expand Down
10 changes: 6 additions & 4 deletions src/libs/actions/IOU/SplitTransactionUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type UpdateSplitTransactionsParams = {
transactionReport: OnyxEntry<OnyxTypes.Report>;
expenseReport: OnyxEntry<OnyxTypes.Report>;
isOffline: boolean;
delegateAccountID: number | undefined;
};

function updateSplitTransactions({
Expand Down Expand Up @@ -135,6 +136,7 @@ function updateSplitTransactions({
transactionReport,
expenseReport: expenseReportFromParams,
isOffline,
delegateAccountID,
}: UpdateSplitTransactionsParams) {
const parentTransactionReport = getReportOrDraftReport(transactionReport?.parentReportID);
// For selfDM-origin splits the caller can't resolve a real `expenseReport` (the draft/source
Expand Down Expand Up @@ -590,6 +592,7 @@ function updateSplitTransactions({
policyRecentlyUsedCurrencies,
betas,
personalDetails,
delegateAccountID,
} as MoneyRequestInformationParams;

if (isReverseSplitOperation) {
Expand Down Expand Up @@ -702,6 +705,7 @@ function updateSplitTransactions({
policyRecentlyUsedCurrencies,
betas,
personalDetails,
delegateAccountID,
});

let updateMoneyRequestParamsOnyxData: OnyxData<UpdateMoneyRequestDataKeys> = {};
Expand Down Expand Up @@ -796,8 +800,7 @@ function updateSplitTransactions({
isSplitTransaction: true,
isSelfDMSplit,
isOffline,
// delegateAccountID: will be threaded in PR 11; buildOptimisticModifiedExpenseReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
delegateAccountID: undefined,
delegateAccountID,
});
if (currentSplit) {
currentSplit.modifiedExpenseReportActionID = params.reportActionID;
Expand Down Expand Up @@ -872,13 +875,12 @@ function updateSplitTransactions({
const failureDataComments: Array<OnyxUpdate<BuildOnyxDataForMoneyRequestKeys>> = [];
const addCommentToSplitTransactionThread = (commentAction: OnyxTypes.ReportAction) => {
const newReportActionID = rand64();
// delegateAccountIDParam: will be threaded in PR 11; buildOptimisticAddCommentReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
const reportComment = buildOptimisticAddCommentReportAction({
text: '',
actorAccountID: commentAction.actorAccountID,
reportID: transactionThreadReportID,
reportActionID: newReportActionID,
delegateAccountIDParam: undefined,
delegateAccountIDParam: delegateAccountID,
});
const reportActionComment = {
...reportComment.reportAction,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/TransactionInlineEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type GetIouParamsInput = {
isSelfTourViewed: boolean | undefined;
hasCompletedGuidedSetupFlow: boolean | undefined;
distanceOriginalPolicy?: OnyxEntry<Policy>;
delegateAccountID: number | undefined;
};

type TransactionInlineEditParams = GetIouParamsInput & {
Expand Down Expand Up @@ -218,6 +219,7 @@ function getIouParamsForTransaction({
parentReportNextStep,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
delegateAccountID,
}: GetIouParamsInput) {
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
Expand Down Expand Up @@ -279,8 +281,7 @@ function getIouParamsForTransaction({
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
isASAPSubmitBetaEnabled: Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas),
// delegateAccountID: will be threaded in PR 11; updateMoneyRequest* falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
delegateAccountID: undefined,
delegateAccountID,
// Field-specific extras
transaction,
policyTagList: policyTags,
Expand Down
29 changes: 22 additions & 7 deletions src/pages/iou/DynamicSplitBillDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationLi
import MoneyRequestHeaderStatusBar from '@components/MoneyRequestHeaderStatusBar';
import ScreenWrapper from '@components/ScreenWrapper';

import useDelegateAccountID from '@hooks/useDelegateAccountID';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -90,22 +91,36 @@ function DynamicSplitBillDetailsPage({report, reportAction}: SplitBillDetailsPag
const [isConfirmed, setIsConfirmed] = useState(false);

const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const delegateAccountID = useDelegateAccountID();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const onConfirm = useCallback(() => {
setIsConfirmed(true);
completeSplitBill(
reportID,
completeSplitBill({
chatReportID: reportID,
reportAction,
draftTransaction,
session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
updatedTransaction: draftTransaction,
sessionAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
isASAPSubmitBetaEnabled,
quickAction,
transactionViolations,
betas,
personalDetails,
session?.email,
);
}, [reportID, reportAction, draftTransaction, session?.accountID, session?.email, isASAPSubmitBetaEnabled, quickAction, transactionViolations, betas, personalDetails]);
delegateAccountID,
sessionEmail: session?.email,
});
}, [
reportID,
reportAction,
draftTransaction,
session?.accountID,
session?.email,
isASAPSubmitBetaEnabled,
quickAction,
transactionViolations,
betas,
personalDetails,
delegateAccountID,
]);

return (
<ScreenWrapper testID="DynamicSplitBillDetailsPage">
Expand Down
3 changes: 3 additions & 0 deletions src/pages/iou/SplitExpensePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useAllTransactions from '@hooks/useAllTransactions';
import useConfirmModal from '@hooks/useConfirmModal';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDelegateAccountID from '@hooks/useDelegateAccountID';
import useEnvironment from '@hooks/useEnvironment';
import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAction';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -95,6 +96,7 @@ const TAB_NAVIGATOR_HEIGHT_LANDSCAPE = variables.tabSelectorButtonHeight + varia
function SplitExpensePage({route}: SplitExpensePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const delegateAccountID = useDelegateAccountID();

const {reportID, transactionID, splitExpenseTransactionID, backTo} = route.params;

Expand Down Expand Up @@ -381,6 +383,7 @@ function SplitExpensePage({route}: SplitExpensePageProps) {
transactionReport: draftTransactionReport,
expenseReport,
isOffline,
delegateAccountID,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useFullScreenLoaderActions} from '@components/FullScreenLoaderContext';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';

import useDelegateAccountID from '@hooks/useDelegateAccountID';
import useFilesValidation from '@hooks/useFilesValidation';
import useOnyx from '@hooks/useOnyx';
import useOptimisticDraftTransactions from '@hooks/useOptimisticDraftTransactions';
Expand Down Expand Up @@ -75,6 +76,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID,
const selfDMReport = useSelfDMReport();
const reportAttributesDerived = useReportAttributes();
const {isBetaEnabled} = usePermissions();
const delegateAccountID = useDelegateAccountID();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
Expand Down Expand Up @@ -204,6 +206,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID,
policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
policyRecentlyUsedTags: undefined,
participantsPolicyTags,
delegateAccountID,
};

submitWithDismissFirst({
Expand Down
Loading
Loading