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 @@ -4,8 +4,7 @@ import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePrevious from '@hooks/usePrevious';
import {setMoneyRequestAmount, setMoneyRequestMerchant, setMoneyRequestPendingFields} from '@libs/actions/IOU';
import {setCustomUnitRateID} from '@libs/actions/IOU/MoneyRequest';
import {setCustomUnitRateID, setMoneyRequestAmount, setMoneyRequestMerchant, setMoneyRequestPendingFields} from '@libs/actions/IOU/MoneyRequest';
import {setSplitShares} from '@libs/actions/IOU/Split';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import type {MileageRate} from '@libs/DistanceRequestUtils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import {setMoneyRequestTag} from '@libs/actions/IOU';
import {setMoneyRequestCategory} from '@libs/actions/IOU/MoneyRequest';
import {setMoneyRequestCategory, setMoneyRequestTag} from '@libs/actions/IOU/MoneyRequest';
import {insertTagIntoTransactionTagsString} from '@libs/IOUUtils';
import {getTag} from '@libs/TransactionUtils';
import type {Policy, PolicyCategories, PolicyTagLists, Transaction} from '@src/types/onyx';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useThemeStyles from '@hooks/useThemeStyles';
import {clearMoneyRequestAmount, setMoneyRequestAmount} from '@libs/actions/IOU';
import {getMoneyRequestParticipantsFromReport} from '@libs/actions/IOU/MoneyRequest';
import {clearMoneyRequestAmount, getMoneyRequestParticipantsFromReport, setMoneyRequestAmount} from '@libs/actions/IOU/MoneyRequest';
import {convertToBackendAmount, convertToFrontendAmountAsString, getLocalizedCurrencySymbol} from '@libs/CurrencyUtils';
import {calculateAmount} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import {setMoneyRequestDescription} from '@libs/actions/IOU';
import {setMoneyRequestDescription} from '@libs/actions/IOU/MoneyRequest';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import {getDescription, hasReceipt} from '@libs/TransactionUtils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import {clearMoneyRequestMerchant, setMoneyRequestMerchant} from '@libs/actions/IOU';
import {clearMoneyRequestMerchant, setMoneyRequestMerchant} from '@libs/actions/IOU/MoneyRequest';
import Navigation from '@libs/Navigation/Navigation';
import {getMerchant, hasReceipt} from '@libs/TransactionUtils';
import {isInvalidMerchantValue, isValidInputLength} from '@libs/ValidationUtils';
Expand Down
10 changes: 8 additions & 2 deletions src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import useLocalize from '@hooks/useLocalize';
import useOnboardingMessages from '@hooks/useOnboardingMessages';
import useOnyx from '@hooks/useOnyx';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import {setMoneyRequestAmount, setMoneyRequestCreated, setMoneyRequestDescription, setMoneyRequestMerchant} from '@libs/actions/IOU';
import {initMoneyRequest, setMoneyRequestParticipants} from '@libs/actions/IOU/MoneyRequest';
import {
initMoneyRequest,
setMoneyRequestAmount,
setMoneyRequestCreated,
setMoneyRequestDescription,
setMoneyRequestMerchant,
setMoneyRequestParticipants,
} from '@libs/actions/IOU/MoneyRequest';
import {setMoneyRequestReceipt} from '@libs/actions/IOU/Receipt';
import {verifyTestDriveRecipient} from '@libs/actions/Onboarding';
import setTestReceipt from '@libs/actions/setTestReceipt';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useParticipantSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import {findSelfDMReportID, generateReportID, isInvoiceRoomWithID} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {isDistanceRequest} from '@libs/TransactionUtils';
import {setMoneyRequestTag} from '@userActions/IOU';
import {
resetDraftTransactionsCustomUnit,
setCustomUnitRateID,
setMoneyRequestCategory,
setMoneyRequestParticipants,
setMoneyRequestParticipantsFromReport,
setMoneyRequestTag,
} from '@userActions/IOU/MoneyRequest';
import {setSplitShares} from '@userActions/IOU/Split';
import {createDraftWorkspace, generateDefaultWorkspaceName} from '@userActions/Policy/Policy';
Expand Down
11 changes: 9 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import {getBankAccountFromID} from './actions/BankAccounts';
import {getUserAccountID, setMoneyRequestReportID} from './actions/IOU';
import {getUserAccountID} from './actions/IOU';
import type {IOURequestType} from './actions/IOU';
import {unholdRequest} from './actions/IOU/Hold';
import {createDraftTransaction, setMoneyRequestParticipants, setMoneyRequestParticipantsFromReport, startDistanceRequest, startMoneyRequest} from './actions/IOU/MoneyRequest';
import {
createDraftTransaction,
setMoneyRequestParticipants,
setMoneyRequestParticipantsFromReport,
setMoneyRequestReportID,
startDistanceRequest,
startMoneyRequest,
} from './actions/IOU/MoneyRequest';
import {canApproveIOU, canIOUBePaid, canSubmitReport, getBadgeFromIOUReport, getIOUReportActionWithBadge} from './actions/IOU/ReportWorkflow';
import {createDraftWorkspace} from './actions/Policy/Policy';
import hasCreditBankAccount from './actions/ReimbursementAccount/hasCreditBankAccount';
Expand Down
101 changes: 99 additions & 2 deletions src/libs/actions/IOU/MoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ import type {
TransactionViolation,
} from '@src/types/onyx';
import type {ReportAttributes, ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
import type {Participant} from '@src/types/onyx/IOU';
import type {Accountant, Attendee, Participant} from '@src/types/onyx/IOU';
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
import type {Unit} from '@src/types/onyx/Policy';
import type {Comment, Receipt, WaypointCollection} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {GpsPoint, IOURequestType} from './index';
import {getAllTransactionDrafts, setMoneyRequestMerchant, setMoneyRequestPendingFields} from './index';
import {getAllTransactionDrafts} from './index';
import {createDistanceRequest, resetSplitShares, startSplitBill} from './Split';
import {submitWithDismissFirst} from './submitWithDismissFirst';
import type {WriteOverrides} from './submitWithDismissFirst';
Expand Down Expand Up @@ -1337,6 +1337,87 @@ function setMoneyRequestDistanceRate(currentTransaction: OnyxEntry<Transaction>,
});
}

function setMoneyRequestReceiptState(transactionID: string, isDraft: boolean, shouldStopSmartscan = false) {
if (!isDraft || !shouldStopSmartscan) {
return;
}
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {receipt: {state: CONST.IOU.RECEIPT_STATE.OPEN}});
}

function setMoneyRequestAmount(transactionID: string, amount: number, currency: string, shouldShowOriginalAmount = false, shouldStopSmartscan = false) {
// Mark that the user has explicitly set the amount. This is used by the new manual expense flow to distinguish
// a default amount of 0 (field empty) from a user-entered 0 (valid $0 expense).
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency, shouldShowOriginalAmount, isAmountSet: true});
setMoneyRequestReceiptState(transactionID, true, shouldStopSmartscan);
}

/**
* Clears the amount field back to an empty/unset state in the new manual expense flow.
* Called when the user deletes all characters from the amount input so that the field
* shows as empty and submission is blocked until a value is entered again.
*/
function clearMoneyRequestAmount(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount: 0, isAmountSet: false});
}

function clearMoneyRequestMerchant(transactionID: string, isDraft = true) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant: '', isMerchantSet: false});
}

function setMoneyRequestCreated(transactionID: string, created: string, isDraft: boolean, shouldStopSmartscan = false) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {created});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}

function setMoneyRequestDateAttribute(transactionID: string, start: string, end: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {comment: {customUnit: {attributes: {dates: {start, end}}}}});
}

function setMoneyRequestCurrency(transactionID: string, currency: string, isEditing = false) {
const fieldToUpdate = isEditing ? 'modifiedCurrency' : 'currency';
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {[fieldToUpdate]: currency});
}

function setMoneyRequestDescription(transactionID: string, comment: string, isDraft: boolean, shouldStopSmartscan = false) {
// Trim only when persisting to the real transaction (not a draft) to avoid
// stripping trailing spaces/newlines while the user is still typing.
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {comment: isDraft ? comment : comment.trim()}});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}

function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraft: boolean, shouldStopSmartscan = false) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant, isMerchantSet: true});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}

function setMoneyRequestAttendees(transactionID: string, attendees: Attendee[], isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {attendees}});
}

function setMoneyRequestAccountant(transactionID: string, accountant: Accountant, isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {accountant});
}

function setMoneyRequestPendingFields(transactionID: string, pendingFields: Transaction['pendingFields']) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {pendingFields});
}

function setMoneyRequestTag(transactionID: string, tag: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {tag});
}

function setMoneyRequestBillable(transactionID: string, billable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {billable});
}

function setMoneyRequestReimbursable(transactionID: string, reimbursable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {reimbursable});
}

function setMoneyRequestReportID(transactionID: string, reportID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {reportID});
}

export {
createTransaction,
handleMoneyRequestStepScanParticipants,
Expand Down Expand Up @@ -1366,5 +1447,21 @@ export {
setCustomUnitID,
setMoneyRequestDistance,
setMoneyRequestDistanceRate,
setMoneyRequestReceiptState,
setMoneyRequestAmount,
clearMoneyRequestAmount,
clearMoneyRequestMerchant,
setMoneyRequestCreated,
setMoneyRequestDateAttribute,
setMoneyRequestCurrency,
setMoneyRequestDescription,
setMoneyRequestMerchant,
setMoneyRequestAttendees,
setMoneyRequestAccountant,
setMoneyRequestPendingFields,
setMoneyRequestTag,
setMoneyRequestBillable,
setMoneyRequestReimbursable,
setMoneyRequestReportID,
};
export type {MoneyRequestStepScanParticipantsFlowParams};
97 changes: 1 addition & 96 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {UpdateMoneyRequestParams} from '@libs/API/parameters';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type {Accountant, Attendee, Participant} from '@src/types/onyx/IOU';
import type {Attendee, Participant} from '@src/types/onyx/IOU';
import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
import type {OnyxData} from '@src/types/onyx/Request';
import type {Receipt} from '@src/types/onyx/Transaction';
Expand Down Expand Up @@ -266,102 +266,7 @@ function getMoneyRequestPolicyTags({
return getPolicyTagsData(iouReportPolicyID) ?? {};
}

function setMoneyRequestReceiptState(transactionID: string, isDraft: boolean, shouldStopSmartscan = false) {
if (!isDraft || !shouldStopSmartscan) {
return;
}
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {receipt: {state: CONST.IOU.RECEIPT_STATE.OPEN}});
}

function setMoneyRequestAmount(transactionID: string, amount: number, currency: string, shouldShowOriginalAmount = false, shouldStopSmartscan = false) {
// Mark that the user has explicitly set the amount. This is used by the new manual expense flow to distinguish
// a default amount of 0 (field empty) from a user-entered 0 (valid $0 expense).
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency, shouldShowOriginalAmount, isAmountSet: true});
setMoneyRequestReceiptState(transactionID, true, shouldStopSmartscan);
}

/**
* Clears the amount field back to an empty/unset state in the new manual expense flow.
* Called when the user deletes all characters from the amount input so that the field
* shows as empty and submission is blocked until a value is entered again.
*/
function clearMoneyRequestAmount(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount: 0, isAmountSet: false});
}

function clearMoneyRequestMerchant(transactionID: string, isDraft = true) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant: '', isMerchantSet: false});
}

function setMoneyRequestCreated(transactionID: string, created: string, isDraft: boolean, shouldStopSmartscan = false) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {created});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}

function setMoneyRequestDateAttribute(transactionID: string, start: string, end: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {comment: {customUnit: {attributes: {dates: {start, end}}}}});
}

function setMoneyRequestCurrency(transactionID: string, currency: string, isEditing = false) {
const fieldToUpdate = isEditing ? 'modifiedCurrency' : 'currency';
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {[fieldToUpdate]: currency});
}

function setMoneyRequestDescription(transactionID: string, comment: string, isDraft: boolean, shouldStopSmartscan = false) {
// Trim only when persisting to the real transaction (not a draft) to avoid
// stripping trailing spaces/newlines while the user is still typing.
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {comment: isDraft ? comment : comment.trim()}});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}

function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraft: boolean, shouldStopSmartscan = false) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant, isMerchantSet: true});
setMoneyRequestReceiptState(transactionID, isDraft, shouldStopSmartscan);
}
function setMoneyRequestAttendees(transactionID: string, attendees: Attendee[], isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {attendees}});
}

function setMoneyRequestAccountant(transactionID: string, accountant: Accountant, isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {accountant});
}

function setMoneyRequestPendingFields(transactionID: string, pendingFields: OnyxTypes.Transaction['pendingFields']) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {pendingFields});
}

function setMoneyRequestTag(transactionID: string, tag: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {tag});
}

function setMoneyRequestBillable(transactionID: string, billable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {billable});
}

function setMoneyRequestReimbursable(transactionID: string, reimbursable: boolean) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {reimbursable});
}

function setMoneyRequestReportID(transactionID: string, reportID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {reportID});
}

export {
setMoneyRequestAmount,
clearMoneyRequestAmount,
clearMoneyRequestMerchant,
setMoneyRequestAttendees,
setMoneyRequestAccountant,
setMoneyRequestBillable,
setMoneyRequestCreated,
setMoneyRequestDateAttribute,
setMoneyRequestCurrency,
setMoneyRequestDescription,
setMoneyRequestMerchant,
setMoneyRequestReportID,
setMoneyRequestPendingFields,
setMoneyRequestTag,
setMoneyRequestReimbursable,
getAllPersonalDetails,
getAllTransactions,
getAllTransactionViolations,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
import useReportOrReportDraft from '@hooks/useReportOrReportDraft';
import useThemeStyles from '@hooks/useThemeStyles';
import type {GpsPoint} from '@libs/actions/IOU';
import {setMoneyRequestBillable, setMoneyRequestReimbursable} from '@libs/actions/IOU';
import {
getIOURequestPolicyID,
getMoneyRequestParticipantsFromReport,
initMoneyRequest,
setMoneyRequestBillable,
setMoneyRequestParticipantsFromReport,
setMoneyRequestReimbursable,
updateLastLocationPermissionPrompt,
} from '@libs/actions/IOU/MoneyRequest';
import {setMoneyRequestReceipt} from '@libs/actions/IOU/Receipt';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepAccountant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLastWorkspaceNumber from '@hooks/useLastWorkspaceNumber';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import {setMoneyRequestAccountant} from '@libs/actions/IOU';
import {setMoneyRequestAccountant} from '@libs/actions/IOU/MoneyRequest';
import {generateDefaultWorkspaceName} from '@libs/actions/Policy/Policy';
import Navigation from '@libs/Navigation/Navigation';
import {createDraftWorkspaceAndNavigateToConfirmationScreen} from '@libs/ReportUtils';
Expand Down
Loading
Loading