, policy: OnyxEntry, policy: OnyxEntry | undefined = undefined): string {
- const moneyRequestTotal = getMoneyRequestReimbursableTotal(report);
+ const moneyRequestTotal = getMoneyRequestSpendBreakdown(report).totalDisplaySpend;
const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency, hasOnlyDistanceRequestTransactions(report?.reportID));
const payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? '';
const payerPaidAmountMessage = Localize.translateLocal('iou.payerPaidAmount', {
@@ -2203,7 +2154,7 @@ function getReportPreviewMessage(
}
}
- const totalAmount = getMoneyRequestReimbursableTotal(report);
+ const totalAmount = getMoneyRequestSpendBreakdown(report).totalDisplaySpend;
const policyName = getPolicyName(report, false, policy);
const payerName = isExpenseReport(report) ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport);
@@ -2336,12 +2287,18 @@ function isChangeLogObject(originalMessage?: ChangeLog): ChangeLog | undefined {
*/
function getAdminRoomInvitedParticipants(parentReportAction: ReportAction | Record, parentReportActionMessage: string) {
if (!parentReportAction?.originalMessage) {
- return '';
+ return parentReportActionMessage || Localize.translateLocal('parentReportAction.deletedMessage');
}
const originalMessage = isChangeLogObject(parentReportAction.originalMessage);
const participantAccountIDs = originalMessage?.targetAccountIDs ?? [];
- const participants = participantAccountIDs.map((id) => getDisplayNameForParticipant(id));
+ const participants = participantAccountIDs.map((id) => {
+ const name = getDisplayNameForParticipant(id);
+ if (name && name?.length > 0) {
+ return name;
+ }
+ return Localize.translateLocal('common.hidden');
+ });
const users = participants.length > 1 ? participants.join(` ${Localize.translateLocal('common.and')} `) : participants[0];
if (!users) {
return parentReportActionMessage;
@@ -2792,7 +2749,7 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num
const report = getReport(iouReportID);
const amount =
type === CONST.IOU.REPORT_ACTION_TYPE.PAY
- ? CurrencyUtils.convertToDisplayString(getMoneyRequestReimbursableTotal(!isEmptyObject(report) ? report : null), currency)
+ ? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(!isEmptyObject(report) ? report : null).totalDisplaySpend, currency)
: CurrencyUtils.convertToDisplayString(total, currency);
let paymentMethodMessage;
@@ -2864,7 +2821,7 @@ function buildOptimisticIOUReportAction(
comment: string,
participants: Participant[],
transactionID: string,
- paymentType: DeepValueOf,
+ paymentType: PaymentMethodType,
iouReportID = '',
isSettlingUp = false,
isSendMoneyFlow = false,
@@ -4233,9 +4190,8 @@ function shouldDisableRename(report: OnyxEntry, policy: OnyxEntry): boolean {
);
}
+/**
+ * Assume any report without a reportID is unusable.
+ */
+function isValidReport(report?: OnyxEntry): boolean {
+ return Boolean(report?.reportID);
+}
+
+/**
+ * Check to see if we are a participant of this report.
+ */
+function isReportParticipant(accountID: number, report: OnyxEntry): boolean {
+ if (!accountID) {
+ return false;
+ }
+
+ // If we have a DM AND the accountID we are checking is the current user THEN we won't find them as a participant and must assume they are a participant
+ if (isDM(report) && accountID === currentUserAccountID) {
+ return true;
+ }
+
+ const possibleAccountIDs = report?.participantAccountIDs ?? [];
+ if (report?.ownerAccountID) {
+ possibleAccountIDs.push(report?.ownerAccountID);
+ }
+ if (report?.managerID) {
+ possibleAccountIDs.push(report?.managerID);
+ }
+ return possibleAccountIDs.includes(accountID);
+}
+
function shouldUseFullTitleToDisplay(report: OnyxEntry): boolean {
return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report);
}
@@ -4616,7 +4602,7 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry {
- type OpenAppParams = PolicyParamsForOpenOrReconnect & {
- enablePriorityModeFilter: boolean;
- };
-
const params: OpenAppParams = {enablePriorityModeFilter: true, ...policyParams};
- API.read('OpenApp', params, getOnyxDataForOpenOrReconnect(true));
+ API.read(READ_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true));
});
}
@@ -220,12 +222,6 @@ function openApp() {
function reconnectApp(updateIDFrom: OnyxEntry = 0) {
console.debug(`[OnyxUpdates] App reconnecting with updateIDFrom: ${updateIDFrom}`);
getPolicyParamsForOpenOrReconnect().then((policyParams) => {
- type ReconnectParams = {
- mostRecentReportActionLastModified?: string;
- updateIDFrom?: number;
- };
- type ReconnectAppParams = PolicyParamsForOpenOrReconnect & ReconnectParams;
-
const params: ReconnectAppParams = {...policyParams};
// When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID.
@@ -243,7 +239,7 @@ function reconnectApp(updateIDFrom: OnyxEntry = 0) {
params.updateIDFrom = updateIDFrom;
}
- API.write('ReconnectApp', params, getOnyxDataForOpenOrReconnect());
+ API.write(WRITE_COMMANDS.RECONNECT_APP, params, getOnyxDataForOpenOrReconnect());
});
}
@@ -255,8 +251,6 @@ function reconnectApp(updateIDFrom: OnyxEntry = 0) {
function finalReconnectAppAfterActivatingReliableUpdates(): Promise {
console.debug(`[OnyxUpdates] Executing last reconnect app with promise`);
return getPolicyParamsForOpenOrReconnect().then((policyParams) => {
- type ReconnectAppParams = PolicyParamsForOpenOrReconnect & {mostRecentReportActionLastModified?: string};
-
const params: ReconnectAppParams = {...policyParams};
// When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID.
@@ -273,7 +267,7 @@ function finalReconnectAppAfterActivatingReliableUpdates(): Promise {
console.debug(`[OnyxUpdates] Fetching missing updates updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`);
- type GetMissingOnyxMessagesParams = {
- updateIDFrom: number;
- updateIDTo: number | string;
- };
-
const parameters: GetMissingOnyxMessagesParams = {
updateIDFrom,
updateIDTo,
@@ -299,7 +288,7 @@ function getMissingOnyxUpdates(updateIDFrom = 0, updateIDTo: number | string = 0
// DO NOT FOLLOW THIS PATTERN!!!!!
// It was absolutely necessary in order to block OnyxUpdates while fetching the missing updates from the server or else the udpates aren't applied in the proper order.
// eslint-disable-next-line rulesdir/no-api-side-effects-method
- return API.makeRequestWithSideEffects('GetMissingOnyxMessages', parameters, getOnyxDataForOpenOrReconnect());
+ return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES, parameters, getOnyxDataForOpenOrReconnect());
}
/**
@@ -436,17 +425,13 @@ function openProfile(personalDetails: OnyxTypes.PersonalDetails) {
newTimezoneData = DateUtils.formatToSupportedTimezone(newTimezoneData);
- type OpenProfileParams = {
- timezone: string;
- };
-
const parameters: OpenProfileParams = {
timezone: JSON.stringify(newTimezoneData),
};
// We expect currentUserAccountID to be a number because it doesn't make sense to open profile if currentUserAccountID is not set
if (typeof currentUserAccountID === 'number') {
- API.write('OpenProfile', parameters, {
+ API.write(WRITE_COMMANDS.OPEN_PROFILE, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -489,14 +474,10 @@ function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true) {
return;
}
- type OpenOldDotLinkParams = {
- shouldRetry: boolean;
- };
-
const parameters: OpenOldDotLinkParams = {shouldRetry: false};
// eslint-disable-next-line rulesdir/no-api-side-effects-method
- API.makeRequestWithSideEffects('OpenOldDotLink', parameters, {}).then((response) => {
+ API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK, parameters, {}).then((response) => {
if (!response) {
Log.alert(
'Trying to redirect via deep link, but the response is empty. User likely not authenticated.',
@@ -518,13 +499,9 @@ function beginDeepLinkRedirectAfterTransition(shouldAuthenticateWithCurrentAccou
}
function handleRestrictedEvent(eventName: string) {
- type HandleRestrictedEventParams = {
- eventName: string;
- };
-
const parameters: HandleRestrictedEventParams = {eventName};
- API.write('HandleRestrictedEvent', parameters);
+ API.write(WRITE_COMMANDS.HANDLE_RESTRICTED_EVENT, parameters);
}
export {
diff --git a/src/libs/actions/AppUpdate.ts b/src/libs/actions/AppUpdate/index.ts
similarity index 71%
rename from src/libs/actions/AppUpdate.ts
rename to src/libs/actions/AppUpdate/index.ts
index 29ee2a4547ab..69c80a089831 100644
--- a/src/libs/actions/AppUpdate.ts
+++ b/src/libs/actions/AppUpdate/index.ts
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
+import updateApp from './updateApp';
function triggerUpdateAvailable() {
Onyx.set(ONYXKEYS.UPDATE_AVAILABLE, true);
@@ -9,4 +10,4 @@ function setIsAppInBeta(isBeta: boolean) {
Onyx.set(ONYXKEYS.IS_BETA, isBeta);
}
-export {triggerUpdateAvailable, setIsAppInBeta};
+export {triggerUpdateAvailable, setIsAppInBeta, updateApp};
diff --git a/src/libs/actions/AppUpdate/updateApp/index.android.ts b/src/libs/actions/AppUpdate/updateApp/index.android.ts
new file mode 100644
index 000000000000..7b0022b3e970
--- /dev/null
+++ b/src/libs/actions/AppUpdate/updateApp/index.android.ts
@@ -0,0 +1,6 @@
+import {Linking} from 'react-native';
+import CONST from '@src/CONST';
+
+export default function updateApp() {
+ Linking.openURL(CONST.APP_DOWNLOAD_LINKS.ANDROID);
+}
diff --git a/src/libs/actions/AppUpdate/updateApp/index.desktop.ts b/src/libs/actions/AppUpdate/updateApp/index.desktop.ts
new file mode 100644
index 000000000000..fb3a7d649baa
--- /dev/null
+++ b/src/libs/actions/AppUpdate/updateApp/index.desktop.ts
@@ -0,0 +1,6 @@
+import {Linking} from 'react-native';
+import CONST from '@src/CONST';
+
+export default function updateApp() {
+ Linking.openURL(CONST.APP_DOWNLOAD_LINKS.DESKTOP);
+}
diff --git a/src/libs/actions/AppUpdate/updateApp/index.ios.ts b/src/libs/actions/AppUpdate/updateApp/index.ios.ts
new file mode 100644
index 000000000000..59f25888de11
--- /dev/null
+++ b/src/libs/actions/AppUpdate/updateApp/index.ios.ts
@@ -0,0 +1,6 @@
+import {Linking} from 'react-native';
+import CONST from '@src/CONST';
+
+export default function updateApp() {
+ Linking.openURL(CONST.APP_DOWNLOAD_LINKS.IOS);
+}
diff --git a/src/libs/actions/AppUpdate/updateApp/index.ts b/src/libs/actions/AppUpdate/updateApp/index.ts
new file mode 100644
index 000000000000..8c2b191029a2
--- /dev/null
+++ b/src/libs/actions/AppUpdate/updateApp/index.ts
@@ -0,0 +1,6 @@
+/**
+ * On web or mWeb we can simply refresh the page and the user should have the new version of the app downloaded.
+ */
+export default function updateApp() {
+ window.location.reload();
+}
diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts
index 1ce6bc38191f..58509379b232 100644
--- a/src/libs/actions/BankAccounts.ts
+++ b/src/libs/actions/BankAccounts.ts
@@ -1,5 +1,20 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import type {
+ AddPersonalBankAccountParams,
+ BankAccountHandlePlaidErrorParams,
+ ConnectBankAccountManuallyParams,
+ ConnectBankAccountWithPlaidParams,
+ DeletePaymentBankAccountParams,
+ OpenReimbursementAccountPageParams,
+ UpdateCompanyInformationForBankAccountParams,
+ UpdatePersonalInformationForBankAccountParams,
+ ValidateBankAccountWithTransactionsParams,
+ VerifyIdentityForBankAccountParams,
+} from '@libs/API/parameters';
+import type UpdateBeneficialOwnersForBankAccountParams from '@libs/API/parameters/UpdateBeneficialOwnersForBankAccountParams';
+import type {BankAccountCompanyInformation} from '@libs/API/parameters/UpdateCompanyInformationForBankAccountParams';
+import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes';
@@ -8,7 +23,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount';
import type {BankAccountStep, BankAccountSubStep} from '@src/types/onyx/ReimbursementAccount';
-import type {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '@src/types/onyx/ReimbursementAccountDraft';
+import type {OnfidoData} from '@src/types/onyx/ReimbursementAccountDraft';
import type {OnyxData} from '@src/types/onyx/Request';
import * as ReimbursementAccount from './ReimbursementAccount';
@@ -27,8 +42,6 @@ export {
export {openPlaidBankAccountSelector, openPlaidBankLogin} from './Plaid';
export {openOnfidoFlow, answerQuestionsForWallet, verifyIdentity, acceptWalletTerms} from './Wallet';
-type BankAccountCompanyInformation = BankAccountStepProps & CompanyStepProps & ReimbursementAccountProps;
-
type ReimbursementAccountStep = BankAccountStep | '';
type ReimbursementAccountSubStep = BankAccountSubStep | '';
@@ -123,17 +136,6 @@ function getVBBADataForOnyx(currentStep?: BankAccountStep): OnyxData {
* Submit Bank Account step with Plaid data so php can perform some checks.
*/
function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAccount: PlaidBankAccount) {
- const commandName = 'ConnectBankAccountWithPlaid';
-
- type ConnectBankAccountWithPlaidParams = {
- bankAccountID: number;
- routingNumber: string;
- accountNumber: string;
- bank?: string;
- plaidAccountID: string;
- plaidAccessToken: string;
- };
-
const parameters: ConnectBankAccountWithPlaidParams = {
bankAccountID,
routingNumber: selectedPlaidBankAccount.routingNumber,
@@ -143,7 +145,7 @@ function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAcc
plaidAccessToken: selectedPlaidBankAccount.plaidAccessToken,
};
- API.write(commandName, parameters, getVBBADataForOnyx());
+ API.write(WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_WITH_PLAID, parameters, getVBBADataForOnyx());
}
/**
@@ -152,19 +154,6 @@ function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAcc
* TODO: offline pattern for this command will have to be added later once the pattern B design doc is complete
*/
function addPersonalBankAccount(account: PlaidBankAccount) {
- const commandName = 'AddPersonalBankAccount';
-
- type AddPersonalBankAccountParams = {
- addressName: string;
- routingNumber: string;
- accountNumber: string;
- isSavings: boolean;
- setupType: string;
- bank?: string;
- plaidAccountID: string;
- plaidAccessToken: string;
- };
-
const parameters: AddPersonalBankAccountParams = {
addressName: account.addressName,
routingNumber: account.routingNumber,
@@ -211,12 +200,10 @@ function addPersonalBankAccount(account: PlaidBankAccount) {
],
};
- API.write(commandName, parameters, onyxData);
+ API.write(WRITE_COMMANDS.ADD_PERSONAL_BANK_ACCOUNT, parameters, onyxData);
}
function deletePaymentBankAccount(bankAccountID: number) {
- type DeletePaymentBankAccountParams = {bankAccountID: number};
-
const parameters: DeletePaymentBankAccountParams = {bankAccountID};
const onyxData: OnyxData = {
@@ -239,7 +226,7 @@ function deletePaymentBankAccount(bankAccountID: number) {
],
};
- API.write('DeletePaymentBankAccount', parameters, onyxData);
+ API.write(WRITE_COMMANDS.DELETE_PAYMENT_BANK_ACCOUNT, parameters, onyxData);
}
/**
@@ -247,16 +234,11 @@ function deletePaymentBankAccount(bankAccountID: number) {
*
* This action is called by the requestor step in the Verified Bank Account flow
*/
-function updatePersonalInformationForBankAccount(params: RequestorStepProps) {
- API.write('UpdatePersonalInformationForBankAccount', params, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.REQUESTOR));
+function updatePersonalInformationForBankAccount(params: UpdatePersonalInformationForBankAccountParams) {
+ API.write(WRITE_COMMANDS.UPDATE_PERSONAL_INFORMATION_FOR_BANK_ACCOUNT, params, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.REQUESTOR));
}
function validateBankAccount(bankAccountID: number, validateCode: string) {
- type ValidateBankAccountWithTransactionsParams = {
- bankAccountID: number;
- validateCode: string;
- };
-
const parameters: ValidateBankAccountWithTransactionsParams = {
bankAccountID,
validateCode,
@@ -293,7 +275,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string) {
],
};
- API.write('ValidateBankAccountWithTransactions', parameters, onyxData);
+ API.write(WRITE_COMMANDS.VALIDATE_BANK_ACCOUNT_WITH_TRANSACTIONS, parameters, onyxData);
}
function clearReimbursementAccount() {
@@ -331,37 +313,29 @@ function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subS
],
};
- type OpenReimbursementAccountPageParams = {
- stepToOpen: ReimbursementAccountStep;
- subStep: ReimbursementAccountSubStep;
- localCurrentStep: ReimbursementAccountStep;
- };
-
const parameters: OpenReimbursementAccountPageParams = {
stepToOpen,
subStep,
localCurrentStep,
};
- return API.read('OpenReimbursementAccountPage', parameters, onyxData);
+ return API.read(READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE, parameters, onyxData);
}
/**
* Updates the bank account in the database with the company step data
*/
function updateCompanyInformationForBankAccount(bankAccount: BankAccountCompanyInformation, policyID: string) {
- type UpdateCompanyInformationForBankAccountParams = BankAccountCompanyInformation & {policyID: string};
-
const parameters: UpdateCompanyInformationForBankAccountParams = {...bankAccount, policyID};
- API.write('UpdateCompanyInformationForBankAccount', parameters, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.COMPANY));
+ API.write(WRITE_COMMANDS.UPDATE_COMPANY_INFORMATION_FOR_BANK_ACCOUNT, parameters, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.COMPANY));
}
/**
* Add beneficial owners for the bank account, accept the ACH terms and conditions and verify the accuracy of the information provided
*/
-function updateBeneficialOwnersForBankAccount(params: ACHContractStepProps) {
- API.write('UpdateBeneficialOwnersForBankAccount', params, getVBBADataForOnyx());
+function updateBeneficialOwnersForBankAccount(params: UpdateBeneficialOwnersForBankAccountParams) {
+ API.write(WRITE_COMMANDS.UPDATE_BENEFICIAL_OWNERS_FOR_BANK_ACCOUNT, params, getVBBADataForOnyx());
}
/**
@@ -369,13 +343,6 @@ function updateBeneficialOwnersForBankAccount(params: ACHContractStepProps) {
*
*/
function connectBankAccountManually(bankAccountID: number, accountNumber?: string, routingNumber?: string, plaidMask?: string) {
- type ConnectBankAccountManuallyParams = {
- bankAccountID: number;
- accountNumber?: string;
- routingNumber?: string;
- plaidMask?: string;
- };
-
const parameters: ConnectBankAccountManuallyParams = {
bankAccountID,
accountNumber,
@@ -383,29 +350,24 @@ function connectBankAccountManually(bankAccountID: number, accountNumber?: strin
plaidMask,
};
- API.write('ConnectBankAccountManually', parameters, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT));
+ API.write(WRITE_COMMANDS.CONNECT_BANK_ACCOUNT_MANUALLY, parameters, getVBBADataForOnyx(CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT));
}
/**
* Verify the user's identity via Onfido
*/
function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoData) {
- type VerifyIdentityForBankAccountParams = {
- bankAccountID: number;
- onfidoData: string;
- };
-
const parameters: VerifyIdentityForBankAccountParams = {
bankAccountID,
onfidoData: JSON.stringify(onfidoData),
};
- API.write('VerifyIdentityForBankAccount', parameters, getVBBADataForOnyx());
+ API.write(WRITE_COMMANDS.VERIFY_IDENTITY_FOR_BANK_ACCOUNT, parameters, getVBBADataForOnyx());
}
function openWorkspaceView() {
API.read(
- 'OpenWorkspaceView',
+ READ_COMMANDS.OPEN_WORKSPACE_VIEW,
{},
{
optimisticData: [
@@ -440,13 +402,6 @@ function openWorkspaceView() {
}
function handlePlaidError(bankAccountID: number, error: string, errorDescription: string, plaidRequestID: string) {
- type BankAccountHandlePlaidErrorParams = {
- bankAccountID: number;
- error: string;
- errorDescription: string;
- plaidRequestID: string;
- };
-
const parameters: BankAccountHandlePlaidErrorParams = {
bankAccountID,
error,
@@ -454,7 +409,7 @@ function handlePlaidError(bankAccountID: number, error: string, errorDescription
plaidRequestID,
};
- API.write('BankAccount_HandlePlaidError', parameters);
+ API.write(WRITE_COMMANDS.BANK_ACCOUNT_HANDLE_PLAID_ERROR, parameters);
}
/**
diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts
index aa892d3817aa..38a421409ade 100644
--- a/src/libs/actions/Card.ts
+++ b/src/libs/actions/Card.ts
@@ -1,6 +1,8 @@
import Onyx from 'react-native-onyx';
import type {OnyxUpdate} from 'react-native-onyx';
import * as API from '@libs/API';
+import type {ActivatePhysicalExpensifyCardParams, ReportVirtualExpensifyCardFraudParams, RequestReplacementExpensifyCardParams, RevealExpensifyCardDetailsParams} from '@libs/API/parameters';
+import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as Localize from '@libs/Localize';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
@@ -39,15 +41,11 @@ function reportVirtualExpensifyCardFraud(cardID: number) {
},
];
- type ReportVirtualExpensifyCardFraudParams = {
- cardID: number;
- };
-
const parameters: ReportVirtualExpensifyCardFraudParams = {
cardID,
};
- API.write('ReportVirtualExpensifyCardFraud', parameters, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.REPORT_VIRTUAL_EXPENSIFY_CARD_FRAUD, parameters, {optimisticData, successData, failureData});
}
/**
@@ -87,17 +85,12 @@ function requestReplacementExpensifyCard(cardID: number, reason: ReplacementReas
},
];
- type RequestReplacementExpensifyCardParams = {
- cardID: number;
- reason: string;
- };
-
const parameters: RequestReplacementExpensifyCardParams = {
cardID,
reason,
};
- API.write('RequestReplacementExpensifyCard', parameters, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.REQUEST_REPLACEMENT_EXPENSIFY_CARD, parameters, {optimisticData, successData, failureData});
}
/**
@@ -141,17 +134,12 @@ function activatePhysicalExpensifyCard(cardLastFourDigits: string, cardID: numbe
},
];
- type ActivatePhysicalExpensifyCardParams = {
- cardLastFourDigits: string;
- cardID: number;
- };
-
const parameters: ActivatePhysicalExpensifyCardParams = {
cardLastFourDigits,
cardID,
};
- API.write('ActivatePhysicalExpensifyCard', parameters, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.ACTIVATE_PHYSICAL_EXPENSIFY_CARD, parameters, {optimisticData, successData, failureData});
}
/**
@@ -173,12 +161,10 @@ function clearCardListErrors(cardID: number) {
*/
function revealVirtualCardDetails(cardID: number): Promise {
return new Promise((resolve, reject) => {
- type RevealExpensifyCardDetailsParams = {cardID: number};
-
const parameters: RevealExpensifyCardDetailsParams = {cardID};
// eslint-disable-next-line rulesdir/no-api-side-effects-method
- API.makeRequestWithSideEffects('RevealExpensifyCardDetails', parameters)
+ API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.REVEAL_EXPENSIFY_CARD_DETAILS, parameters)
.then((response) => {
if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
reject(Localize.translateLocal('cardPage.cardDetailsLoadingFailure'));
diff --git a/src/libs/actions/Chronos.ts b/src/libs/actions/Chronos.ts
index 0bb949687e6d..548b8398beec 100644
--- a/src/libs/actions/Chronos.ts
+++ b/src/libs/actions/Chronos.ts
@@ -1,6 +1,8 @@
import type {OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import type {ChronosRemoveOOOEventParams} from '@libs/API/parameters';
+import {WRITE_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ChronosOOOEvent} from '@src/types/onyx/OriginalMessage';
@@ -46,14 +48,12 @@ const removeEvent = (reportID: string, reportActionID: string, eventID: string,
},
];
- API.write(
- 'Chronos_RemoveOOOEvent',
- {
- googleEventID: eventID,
- reportActionID,
- },
- {optimisticData, successData, failureData},
- );
+ const parameters: ChronosRemoveOOOEventParams = {
+ googleEventID: eventID,
+ reportActionID,
+ };
+
+ API.write(WRITE_COMMANDS.CHRONOS_REMOVE_OOO_EVENT, parameters, {optimisticData, successData, failureData});
};
export {
diff --git a/src/libs/actions/FormActions.ts b/src/libs/actions/FormActions.ts
index 00ad3652c665..e32863cff0b1 100644
--- a/src/libs/actions/FormActions.ts
+++ b/src/libs/actions/FormActions.ts
@@ -1,5 +1,5 @@
import Onyx from 'react-native-onyx';
-import type {KeyValueMapping, NullishDeep} from 'react-native-onyx/lib/types';
+import type {KeyValueMapping, NullishDeep} from 'react-native-onyx';
import type {OnyxFormKeyWithoutDraft} from '@components/Form/types';
import FormUtils from '@libs/FormUtils';
import type {OnyxFormKey} from '@src/ONYXKEYS';
diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js
index eb9541edcad2..3d6664099866 100644
--- a/src/libs/actions/IOU.js
+++ b/src/libs/actions/IOU.js
@@ -1,15 +1,16 @@
import {format} from 'date-fns';
+import fastMerge from 'expensify-common/lib/fastMerge';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import lodashHas from 'lodash/has';
import Onyx from 'react-native-onyx';
-import OnyxUtils from 'react-native-onyx/lib/utils';
import _ from 'underscore';
import ReceiptGeneric from '@assets/images/receipt-generic.png';
import * as API from '@libs/API';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import DateUtils from '@libs/DateUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
+import * as FileUtils from '@libs/fileDownload/FileUtils';
import * as IOUUtils from '@libs/IOUUtils';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
@@ -311,6 +312,29 @@ function getReceiptError(receipt, filename, isScanRequest = true) {
: ErrorUtils.getMicroSecondOnyxErrorObject({error: CONST.IOU.RECEIPT_ERROR, source: receipt.source, filename});
}
+/**
+ * Return the object to update hasOutstandingChildRequest
+ * @param {Object} [policy]
+ * @param {Boolean} needsToBeManuallySubmitted
+ * @returns {Object}
+ */
+function getOutstandingChildRequest(policy, needsToBeManuallySubmitted) {
+ if (!needsToBeManuallySubmitted) {
+ return {
+ hasOutstandingChildRequest: false,
+ };
+ }
+
+ if (PolicyUtils.isPolicyAdmin(policy)) {
+ return {
+ hasOutstandingChildRequest: true,
+ };
+ }
+
+ // We don't need to update hasOutstandingChildRequest in this case
+ return {};
+}
+
/**
* Builds the Onyx data for a money request.
*
@@ -329,7 +353,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) {
* @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts)
* @param {Array} policyTags
* @param {Array} policyCategories
- * @param {Boolean} hasOutstandingChildRequest
+ * @param {Boolean} needsToBeManuallySubmitted
* @returns {Array} - An array containing the optimistic data, success data, and failure data.
*/
function buildOnyxDataForMoneyRequest(
@@ -348,9 +372,10 @@ function buildOnyxDataForMoneyRequest(
policy,
policyTags,
policyCategories,
- hasOutstandingChildRequest = false,
+ needsToBeManuallySubmitted = true,
) {
const isScanRequest = TransactionUtils.isScanRequest(transaction);
+ const outstandingChildRequest = getOutstandingChildRequest(needsToBeManuallySubmitted, policy);
const optimisticData = [
{
// Use SET for new reports because it doesn't exist yet, is faster and we need the data to be available when we navigate to the chat page
@@ -361,7 +386,7 @@ function buildOnyxDataForMoneyRequest(
lastReadTime: DateUtils.getDBTime(),
lastMessageTranslationKey: '',
iouReportID: iouReport.reportID,
- hasOutstandingChildRequest,
+ ...outstandingChildRequest,
...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}),
},
},
@@ -506,6 +531,7 @@ function buildOnyxDataForMoneyRequest(
iouReportID: chatReport.iouReportID,
lastReadTime: chatReport.lastReadTime,
pendingFields: null,
+ hasOutstandingChildRequest: chatReport.hasOutstandingChildRequest,
...(isNewChatReport
? {
errorFields: {
@@ -687,7 +713,7 @@ function getMoneyRequestInformation(
let iouReport = isNewIOUReport ? null : allReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`];
// Check if the Scheduled Submit is enabled in case of expense report
- let needsToBeManuallySubmitted = false;
+ let needsToBeManuallySubmitted = true;
let isFromPaidPolicy = false;
if (isPolicyExpenseChat) {
isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);
@@ -753,7 +779,7 @@ function getMoneyRequestInformation(
// to remind me to do this.
const existingTransaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`];
if (existingTransaction && existingTransaction.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) {
- optimisticTransaction = OnyxUtils.fastMerge(existingTransaction, optimisticTransaction);
+ optimisticTransaction = fastMerge(existingTransaction, optimisticTransaction);
}
// STEP 4: Build optimistic reportActions. We need:
@@ -806,10 +832,6 @@ function getMoneyRequestInformation(
}
: undefined;
- // The policy expense chat should have the GBR only when its a paid policy and the scheduled submit is turned off
- // so the employee has to submit to their manager manually.
- const hasOutstandingChildRequest = isPolicyExpenseChat && needsToBeManuallySubmitted;
-
// STEP 5: Build Onyx Data
const [optimisticData, successData, failureData] = buildOnyxDataForMoneyRequest(
chatReport,
@@ -827,7 +849,7 @@ function getMoneyRequestInformation(
policy,
policyTags,
policyCategories,
- hasOutstandingChildRequest,
+ needsToBeManuallySubmitted,
);
return {
@@ -870,6 +892,7 @@ function createDistanceRequest(report, participant, comment, created, category,
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
+ const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created);
const optimisticReceipt = {
source: ReceiptGeneric,
@@ -881,7 +904,7 @@ function createDistanceRequest(report, participant, comment, created, category,
comment,
amount,
currency,
- created,
+ currentCreated,
merchant,
userAccountID,
currentUserEmail,
@@ -906,7 +929,7 @@ function createDistanceRequest(report, participant, comment, created, category,
createdIOUReportActionID,
reportPreviewReportActionID: reportPreviewAction.reportActionID,
waypoints: JSON.stringify(validWaypoints),
- created,
+ created: currentCreated,
category,
tag,
billable,
@@ -1290,6 +1313,7 @@ function requestMoney(
// If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
+ const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created);
const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} =
getMoneyRequestInformation(
currentChatReport,
@@ -1297,7 +1321,7 @@ function requestMoney(
comment,
amount,
currency,
- created,
+ currentCreated,
merchant,
payeeAccountID,
payeeEmail,
@@ -1320,7 +1344,7 @@ function requestMoney(
amount,
currency,
comment,
- created,
+ created: currentCreated,
merchant,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
@@ -1823,6 +1847,9 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co
CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
receiptObject,
filename,
+ undefined,
+ category,
+ tag,
);
// Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat
@@ -2624,7 +2651,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
amount: CurrencyUtils.convertToDisplayString(updatedIOUReport.total, updatedIOUReport.currency),
});
updatedReportPreviewAction.message[0].text = messageText;
- updatedReportPreviewAction.message[0].html = messageText;
+ updatedReportPreviewAction.message[0].html = shouldDeleteIOUReport ? '' : messageText;
if (reportPreviewAction.childMoneyRequestCount > 0) {
updatedReportPreviewAction.childMoneyRequestCount = reportPreviewAction.childMoneyRequestCount - 1;
@@ -3698,6 +3725,32 @@ function getIOUReportID(iou, route) {
return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', '');
}
+/**
+ * @param {String} receiptFilename
+ * @param {String} receiptPath
+ * @param {Function} onSuccess
+ * @param {String} requestType
+ * @param {String} iouType
+ * @param {String} transactionID
+ * @param {String} reportID
+ */
+// eslint-disable-next-line rulesdir/no-negated-variables
+function navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID) {
+ if (!receiptFilename || !receiptPath) {
+ return;
+ }
+
+ const onFailure = () => {
+ setMoneyRequestReceipt(transactionID, '', '', true);
+ if (requestType === CONST.IOU.REQUEST_TYPE.MANUAL) {
+ Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
+ return;
+ }
+ IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID);
+ };
+ FileUtils.readFileAsync(receiptPath, receiptFilename, onSuccess, onFailure);
+}
+
export {
setMoneyRequestParticipants,
createDistanceRequest,
@@ -3757,4 +3810,5 @@ export {
detachReceipt,
getIOUReportID,
editMoneyRequest,
+ navigateToStartStepIfScanFileCannotBeRead,
};
diff --git a/src/libs/actions/Link.ts b/src/libs/actions/Link.ts
index 186c9beed970..ae95424f5776 100644
--- a/src/libs/actions/Link.ts
+++ b/src/libs/actions/Link.ts
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import asyncOpenURL from '@libs/asyncOpenURL';
import * as Environment from '@libs/Environment/Environment';
import Navigation from '@libs/Navigation/Navigation';
@@ -55,7 +56,7 @@ function openOldDotLink(url: string) {
// If shortLivedAuthToken is not accessible, fallback to opening the link without the token.
asyncOpenURL(
// eslint-disable-next-line rulesdir/no-api-side-effects-method
- API.makeRequestWithSideEffects('OpenOldDotLink', {}, {})
+ API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.OPEN_OLD_DOT_LINK, {}, {})
.then((response) => (response ? buildOldDotURL(url, response.shortLivedAuthToken) : buildOldDotURL(url)))
.catch(() => buildOldDotURL(url)),
(oldDotURL) => oldDotURL,
diff --git a/src/libs/actions/MapboxToken.ts b/src/libs/actions/MapboxToken.ts
index 54f99b58fbeb..3b98f79698ba 100644
--- a/src/libs/actions/MapboxToken.ts
+++ b/src/libs/actions/MapboxToken.ts
@@ -4,6 +4,7 @@ import {AppState} from 'react-native';
import Onyx from 'react-native-onyx';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import * as API from '@libs/API';
+import {READ_COMMANDS} from '@libs/API/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {MapboxAccessToken, Network} from '@src/types/onyx';
@@ -38,7 +39,7 @@ const setExpirationTimer = () => {
return;
}
console.debug(`[MapboxToken] Fetching a new token after waiting ${REFRESH_INTERVAL / 1000 / 60} minutes`);
- API.read('GetMapboxAccessToken', {}, {});
+ API.read(READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN, {}, {});
}, REFRESH_INTERVAL);
};
@@ -51,7 +52,7 @@ const clearToken = () => {
};
const fetchToken = () => {
- API.read('GetMapboxAccessToken', {}, {});
+ API.read(READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN, {}, {});
isCurrentlyFetchingToken = true;
};
diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.ts b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.ts
index 3e8c613187b4..15b9133f0aaf 100644
--- a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.ts
+++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.ts
@@ -1,5 +1,5 @@
import Onyx from 'react-native-onyx';
-import type {OnyxKey} from 'react-native-onyx/lib/types';
+import type {OnyxKey} from 'react-native-onyx';
import Log from '@libs/Log';
import ONYXKEYS from '@src/ONYXKEYS';
diff --git a/src/libs/actions/Modal.ts b/src/libs/actions/Modal.ts
index e1e73d425281..71ba850e721f 100644
--- a/src/libs/actions/Modal.ts
+++ b/src/libs/actions/Modal.ts
@@ -1,9 +1,10 @@
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
-const closeModals: Array<(isNavigating: boolean) => void> = [];
+const closeModals: Array<(isNavigating?: boolean) => void> = [];
let onModalClose: null | (() => void);
+let isNavigate: undefined | boolean;
/**
* Allows other parts of the app to call modal close function
@@ -21,6 +22,20 @@ function setCloseModal(onClose: () => void) {
};
}
+/**
+ * Close topmost modal
+ */
+function closeTop() {
+ if (closeModals.length === 0) {
+ return;
+ }
+ if (onModalClose) {
+ closeModals[closeModals.length - 1](isNavigate);
+ return;
+ }
+ closeModals[closeModals.length - 1]();
+}
+
/**
* Close modal in other parts of the app
*/
@@ -30,17 +45,21 @@ function close(onModalCloseCallback: () => void, isNavigating = true) {
return;
}
onModalClose = onModalCloseCallback;
- [...closeModals].reverse().forEach((onClose) => {
- onClose(isNavigating);
- });
+ isNavigate = isNavigating;
+ closeTop();
}
function onModalDidClose() {
if (!onModalClose) {
return;
}
+ if (closeModals.length) {
+ closeTop();
+ return;
+ }
onModalClose();
onModalClose = null;
+ isNavigate = undefined;
}
/**
@@ -58,4 +77,4 @@ function willAlertModalBecomeVisible(isVisible: boolean) {
Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible});
}
-export {setCloseModal, close, onModalDidClose, setModalVisibility, willAlertModalBecomeVisible};
+export {setCloseModal, close, onModalDidClose, setModalVisibility, willAlertModalBecomeVisible, closeTop};
diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts
index b9632d05d581..b4854562f7a8 100644
--- a/src/libs/actions/PaymentMethods.ts
+++ b/src/libs/actions/PaymentMethods.ts
@@ -1,12 +1,12 @@
import {createRef} from 'react';
import type {MutableRefObject} from 'react';
import type {GestureResponderEvent} from 'react-native';
-import type {OnyxUpdate} from 'react-native-onyx';
+import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
-import type {OnyxEntry} from 'react-native-onyx/lib/types';
-import type {ValueOf} from 'type-fest';
import type {TransferMethod} from '@components/KYCWall/types';
import * as API from '@libs/API';
+import type {AddPaymentCardParams, DeletePaymentCardParams, MakeDefaultPaymentMethodParams, PaymentCardParams, TransferWalletBalanceParams} from '@libs/API/parameters';
+import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as CardUtils from '@libs/CardUtils';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
@@ -63,7 +63,7 @@ function openWalletPage() {
];
return API.read(
- 'OpenPaymentsPage',
+ READ_COMMANDS.OPEN_PAYMENTS_PAGE,
{},
{
optimisticData,
@@ -134,24 +134,17 @@ function getMakeDefaultPaymentOnyxData(
*
*/
function makeDefaultPaymentMethod(bankAccountID: number, fundID: number, previousPaymentMethod: PaymentMethod, currentPaymentMethod: PaymentMethod) {
- type MakeDefaultPaymentMethodParams = {
- bankAccountID: number;
- fundID: number;
- };
-
const parameters: MakeDefaultPaymentMethodParams = {
bankAccountID,
fundID,
};
- API.write('MakeDefaultPaymentMethod', parameters, {
+ API.write(WRITE_COMMANDS.MAKE_DEFAULT_PAYMENT_METHOD, parameters, {
optimisticData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, true),
failureData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, false),
});
}
-type PaymentCardParams = {expirationDate: string; cardNumber: string; securityCode: string; nameOnCard: string; addressZipCode: string};
-
/**
* Calls the API to add a new card.
*
@@ -160,17 +153,6 @@ function addPaymentCard(params: PaymentCardParams) {
const cardMonth = CardUtils.getMonthFromExpirationDateString(params.expirationDate);
const cardYear = CardUtils.getYearFromExpirationDateString(params.expirationDate);
- type AddPaymentCardParams = {
- cardNumber: string;
- cardYear: string;
- cardMonth: string;
- cardCVV: string;
- addressName: string;
- addressZip: string;
- currency: ValueOf;
- isP2PDebitCard: boolean;
- };
-
const parameters: AddPaymentCardParams = {
cardNumber: params.cardNumber,
cardYear,
@@ -206,7 +188,7 @@ function addPaymentCard(params: PaymentCardParams) {
},
];
- API.write('AddPaymentCard', parameters, {
+ API.write(WRITE_COMMANDS.ADD_PAYMENT_CARD, parameters, {
optimisticData,
successData,
failureData,
@@ -232,9 +214,7 @@ function transferWalletBalance(paymentMethod: PaymentMethod) {
const paymentMethodIDKey =
paymentMethod.accountType === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT ? CONST.PAYMENT_METHOD_ID_KEYS.BANK_ACCOUNT : CONST.PAYMENT_METHOD_ID_KEYS.DEBIT_CARD;
- type TransferWalletBalanceParameters = Partial, number | undefined>>;
-
- const parameters: TransferWalletBalanceParameters = {
+ const parameters: TransferWalletBalanceParams = {
[paymentMethodIDKey]: paymentMethod.methodID,
};
@@ -272,7 +252,7 @@ function transferWalletBalance(paymentMethod: PaymentMethod) {
},
];
- API.write('TransferWalletBalance', parameters, {
+ API.write(WRITE_COMMANDS.TRANSFER_WALLET_BALANCE, parameters, {
optimisticData,
successData,
failureData,
@@ -358,10 +338,6 @@ function clearWalletTermsError() {
}
function deletePaymentCard(fundID: number) {
- type DeletePaymentCardParams = {
- fundID: number;
- };
-
const parameters: DeletePaymentCardParams = {
fundID,
};
@@ -374,7 +350,7 @@ function deletePaymentCard(fundID: number) {
},
];
- API.write('DeletePaymentCard', parameters, {
+ API.write(WRITE_COMMANDS.DELETE_PAYMENT_CARD, parameters, {
optimisticData,
});
}
diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts
index 508cca34fb88..e7d9b48c46e9 100644
--- a/src/libs/actions/PersonalDetails.ts
+++ b/src/libs/actions/PersonalDetails.ts
@@ -2,6 +2,18 @@ import Str from 'expensify-common/lib/str';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import type {
+ OpenPublicProfilePageParams,
+ UpdateAutomaticTimezoneParams,
+ UpdateDateOfBirthParams,
+ UpdateDisplayNameParams,
+ UpdateHomeAddressParams,
+ UpdateLegalNameParams,
+ UpdatePronounsParams,
+ UpdateSelectedTimezoneParams,
+ UpdateUserAvatarParams,
+} from '@libs/API/parameters';
+import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types';
import DateUtils from '@libs/DateUtils';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';
@@ -107,13 +119,9 @@ function getCountryISO(countryName: string): string {
function updatePronouns(pronouns: string) {
if (currentUserAccountID) {
- type UpdatePronounsParams = {
- pronouns: string;
- };
-
const parameters: UpdatePronounsParams = {pronouns};
- API.write('UpdatePronouns', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_PRONOUNS, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -133,14 +141,9 @@ function updatePronouns(pronouns: string) {
function updateDisplayName(firstName: string, lastName: string) {
if (currentUserAccountID) {
- type UpdateDisplayNameParams = {
- firstName: string;
- lastName: string;
- };
-
const parameters: UpdateDisplayNameParams = {firstName, lastName};
- API.write('UpdateDisplayName', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_DISPLAY_NAME, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -164,14 +167,9 @@ function updateDisplayName(firstName: string, lastName: string) {
}
function updateLegalName(legalFirstName: string, legalLastName: string) {
- type UpdateLegalNameParams = {
- legalFirstName: string;
- legalLastName: string;
- };
-
const parameters: UpdateLegalNameParams = {legalFirstName, legalLastName};
- API.write('UpdateLegalName', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -191,13 +189,9 @@ function updateLegalName(legalFirstName: string, legalLastName: string) {
* @param dob - date of birth
*/
function updateDateOfBirth({dob}: DateOfBirthForm) {
- type UpdateDateOfBirthParams = {
- dob?: string;
- };
-
const parameters: UpdateDateOfBirthParams = {dob};
- API.write('UpdateDateOfBirth', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_DATE_OF_BIRTH, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -213,16 +207,6 @@ function updateDateOfBirth({dob}: DateOfBirthForm) {
}
function updateAddress(street: string, street2: string, city: string, state: string, zip: string, country: string) {
- type UpdateHomeAddressParams = {
- homeAddressStreet: string;
- addressStreet2: string;
- homeAddressCity: string;
- addressState: string;
- addressZipCode: string;
- addressCountry: string;
- addressStateLong?: string;
- };
-
const parameters: UpdateHomeAddressParams = {
homeAddressStreet: street,
addressStreet2: street2,
@@ -238,7 +222,7 @@ function updateAddress(street: string, street2: string, city: string, state: str
parameters.addressStateLong = state;
}
- API.write('UpdateHomeAddress', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_HOME_ADDRESS, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -272,15 +256,12 @@ function updateAutomaticTimezone(timezone: Timezone) {
return;
}
- type UpdateAutomaticTimezoneParams = {
- timezone: string;
- };
const formatedTimezone = DateUtils.formatToSupportedTimezone(timezone);
const parameters: UpdateAutomaticTimezoneParams = {
timezone: JSON.stringify(formatedTimezone),
};
- API.write('UpdateAutomaticTimezone', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_AUTOMATIC_TIMEZONE, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -304,16 +285,12 @@ function updateSelectedTimezone(selectedTimezone: SelectedTimezone) {
selected: selectedTimezone,
};
- type UpdateSelectedTimezoneParams = {
- timezone: string;
- };
-
const parameters: UpdateSelectedTimezoneParams = {
timezone: JSON.stringify(timezone),
};
if (currentUserAccountID) {
- API.write('UpdateSelectedTimezone', parameters, {
+ API.write(WRITE_COMMANDS.UPDATE_SELECTED_TIMEZONE, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
@@ -365,11 +342,7 @@ function openPersonalDetailsPage() {
},
];
- type OpenPersonalDetailsPageParams = Record;
-
- const parameters: OpenPersonalDetailsPageParams = {};
-
- API.read('OpenPersonalDetailsPage', parameters, {optimisticData, successData, failureData});
+ API.read(READ_COMMANDS.OPEN_PERSONAL_DETAILS_PAGE, {}, {optimisticData, successData, failureData});
}
/**
@@ -414,13 +387,9 @@ function openPublicProfilePage(accountID: number) {
},
];
- type OpenPublicProfilePageParams = {
- accountID: number;
- };
-
const parameters: OpenPublicProfilePageParams = {accountID};
- API.read('OpenPublicProfilePage', parameters, {optimisticData, successData, failureData});
+ API.read(READ_COMMANDS.OPEN_PUBLIC_PROFILE_PAGE, parameters, {optimisticData, successData, failureData});
}
/**
@@ -481,13 +450,9 @@ function updateAvatar(file: File | CustomRNImageManipulatorResult) {
},
];
- type UpdateUserAvatarParams = {
- file: File | CustomRNImageManipulatorResult;
- };
-
const parameters: UpdateUserAvatarParams = {file};
- API.write('UpdateUserAvatar', parameters, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.UPDATE_USER_AVATAR, parameters, {optimisticData, successData, failureData});
}
/**
@@ -526,11 +491,7 @@ function deleteAvatar() {
},
];
- type DeleteUserAvatarParams = Record;
-
- const parameters: DeleteUserAvatarParams = {};
-
- API.write('DeleteUserAvatar', parameters, {optimisticData, failureData});
+ API.write(WRITE_COMMANDS.DELETE_USER_AVATAR, {}, {optimisticData, failureData});
}
/**
diff --git a/src/libs/actions/Plaid.ts b/src/libs/actions/Plaid.ts
index 8c35c391790a..78bc91618215 100644
--- a/src/libs/actions/Plaid.ts
+++ b/src/libs/actions/Plaid.ts
@@ -1,5 +1,7 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import type {OpenPlaidBankAccountSelectorParams, OpenPlaidBankLoginParams} from '@libs/API/parameters';
+import {READ_COMMANDS} from '@libs/API/types';
import getPlaidLinkTokenParameters from '@libs/getPlaidLinkTokenParameters';
import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes';
import ONYXKEYS from '@src/ONYXKEYS';
@@ -10,11 +12,13 @@ import ONYXKEYS from '@src/ONYXKEYS';
function openPlaidBankLogin(allowDebit: boolean, bankAccountID: number) {
// redirect_uri needs to be in kebab case convention because that's how it's passed to the backend
const {redirectURI} = getPlaidLinkTokenParameters();
- const params = {
+
+ const params: OpenPlaidBankLoginParams = {
redirectURI,
allowDebit,
bankAccountID,
};
+
const optimisticData = [
{
onyxMethod: Onyx.METHOD.SET,
@@ -35,51 +39,49 @@ function openPlaidBankLogin(allowDebit: boolean, bankAccountID: number) {
},
];
- API.read('OpenPlaidBankLogin', params, {optimisticData});
+ API.read(READ_COMMANDS.OPEN_PLAID_BANK_LOGIN, params, {optimisticData});
}
function openPlaidBankAccountSelector(publicToken: string, bankName: string, allowDebit: boolean, bankAccountID: number) {
- API.read(
- 'OpenPlaidBankAccountSelector',
- {
- publicToken,
- allowDebit,
- bank: bankName,
- bankAccountID,
- },
- {
- optimisticData: [
- {
- onyxMethod: Onyx.METHOD.MERGE,
- key: ONYXKEYS.PLAID_DATA,
- value: {
- isLoading: true,
- errors: null,
- bankName,
- },
+ const parameters: OpenPlaidBankAccountSelectorParams = {
+ publicToken,
+ allowDebit,
+ bank: bankName,
+ bankAccountID,
+ };
+
+ API.read(READ_COMMANDS.OPEN_PLAID_BANK_ACCOUNT_SELECTOR, parameters, {
+ optimisticData: [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PLAID_DATA,
+ value: {
+ isLoading: true,
+ errors: null,
+ bankName,
},
- ],
- successData: [
- {
- onyxMethod: Onyx.METHOD.MERGE,
- key: ONYXKEYS.PLAID_DATA,
- value: {
- isLoading: false,
- errors: null,
- },
+ },
+ ],
+ successData: [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PLAID_DATA,
+ value: {
+ isLoading: false,
+ errors: null,
},
- ],
- failureData: [
- {
- onyxMethod: Onyx.METHOD.MERGE,
- key: ONYXKEYS.PLAID_DATA,
- value: {
- isLoading: false,
- },
+ },
+ ],
+ failureData: [
+ {
+ onyxMethod: Onyx.METHOD.MERGE,
+ key: ONYXKEYS.PLAID_DATA,
+ value: {
+ isLoading: false,
},
- ],
- },
- );
+ },
+ ],
+ });
}
export {openPlaidBankAccountSelector, openPlaidBankLogin};
diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts
index b47891e64350..fbe92aeb378d 100644
--- a/src/libs/actions/Policy.ts
+++ b/src/libs/actions/Policy.ts
@@ -4,10 +4,26 @@ import Str from 'expensify-common/lib/str';
import {escapeRegExp} from 'lodash';
import lodashClone from 'lodash/clone';
import lodashUnion from 'lodash/union';
-import type {OnyxCollection, OnyxUpdate} from 'react-native-onyx';
+import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
-import type {NullishDeep, OnyxEntry} from 'react-native-onyx/lib/types';
import * as API from '@libs/API';
+import type {
+ AddMembersToWorkspaceParams,
+ CreateWorkspaceFromIOUPaymentParams,
+ CreateWorkspaceParams,
+ DeleteMembersFromWorkspaceParams,
+ DeleteWorkspaceAvatarParams,
+ DeleteWorkspaceParams,
+ OpenDraftWorkspaceRequestParams,
+ OpenWorkspaceInvitePageParams,
+ OpenWorkspaceMembersPageParams,
+ OpenWorkspaceParams,
+ OpenWorkspaceReimburseViewParams,
+ UpdateWorkspaceAvatarParams,
+ UpdateWorkspaceCustomUnitAndRateParams,
+ UpdateWorkspaceGeneralSettingsParams,
+} from '@libs/API/parameters';
+import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import Log from '@libs/Log';
@@ -276,13 +292,9 @@ function deleteWorkspace(policyID: string, reports: Report[], policyName: string
});
});
- type DeleteWorkspaceParams = {
- policyID: string;
- };
-
const params: DeleteWorkspaceParams = {policyID};
- API.write('DeleteWorkspace', params, {optimisticData, failureData});
+ API.write(WRITE_COMMANDS.DELETE_WORKSPACE, params, {optimisticData, failureData});
// Reset the lastAccessedWorkspacePolicyID
if (policyID === lastAccessedWorkspacePolicyID) {
@@ -492,17 +504,12 @@ function removeMembers(accountIDs: number[], policyID: string) {
});
});
- type DeleteMembersFromWorkspaceParams = {
- emailList: string;
- policyID: string;
- };
-
const params: DeleteMembersFromWorkspaceParams = {
emailList: accountIDs.map((accountID) => allPersonalDetails?.[accountID]?.login).join(','),
policyID,
};
- API.write('DeleteMembersFromWorkspace', params, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.DELETE_MEMBERS_FROM_WORKSPACE, params, {optimisticData, successData, failureData});
}
/**
@@ -669,13 +676,6 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record
...announceRoomMembers.onyxFailureData,
];
- type AddMembersToWorkspaceParams = {
- employees: string;
- welcomeNote: string;
- policyID: string;
- reportCreationData?: string;
- };
-
const params: AddMembersToWorkspaceParams = {
employees: JSON.stringify(logins.map((login) => ({email: login}))),
welcomeNote: new ExpensiMark().replace(welcomeNote),
@@ -684,7 +684,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record
if (!isEmptyObject(membersChats.reportCreationData)) {
params.reportCreationData = JSON.stringify(membersChats.reportCreationData);
}
- API.write('AddMembersToWorkspace', params, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.ADD_MEMBERS_TO_WORKSPACE, params, {optimisticData, successData, failureData});
}
/**
@@ -728,17 +728,12 @@ function updateWorkspaceAvatar(policyID: string, file: File) {
},
];
- type UpdateWorkspaceAvatarParams = {
- policyID: string;
- file: File;
- };
-
const params: UpdateWorkspaceAvatarParams = {
policyID,
file,
};
- API.write('UpdateWorkspaceAvatar', params, {optimisticData, finallyData, failureData});
+ API.write(WRITE_COMMANDS.UPDATE_WORKSPACE_AVATAR, params, {optimisticData, finallyData, failureData});
}
/**
@@ -783,13 +778,9 @@ function deleteWorkspaceAvatar(policyID: string) {
},
];
- type DeleteWorkspaceAvatarParams = {
- policyID: string;
- };
-
const params: DeleteWorkspaceAvatarParams = {policyID};
- API.write('DeleteWorkspaceAvatar', params, {optimisticData, finallyData, failureData});
+ API.write(WRITE_COMMANDS.DELETE_WORKSPACE_AVATAR, params, {optimisticData, finallyData, failureData});
}
/**
@@ -886,19 +877,13 @@ function updateGeneralSettings(policyID: string, name: string, currency: string)
},
];
- type UpdateWorkspaceGeneralSettingsParams = {
- policyID: string;
- workspaceName: string;
- currency: string;
- };
-
const params: UpdateWorkspaceGeneralSettingsParams = {
policyID,
workspaceName: name,
currency,
};
- API.write('UpdateWorkspaceGeneralSettings', params, {
+ API.write(WRITE_COMMANDS.UPDATE_WORKSPACE_GENERAL_SETTINGS, params, {
optimisticData,
finallyData,
failureData,
@@ -1018,21 +1003,14 @@ function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: C
const {pendingAction, errors, ...newRates} = newCustomUnitParam.rates ?? {};
newCustomUnitParam.rates = newRates;
- type UpdateWorkspaceCustomUnitAndRate = {
- policyID: string;
- lastModified: number;
- customUnit: string;
- customUnitRate: string;
- };
-
- const params: UpdateWorkspaceCustomUnitAndRate = {
+ const params: UpdateWorkspaceCustomUnitAndRateParams = {
policyID,
lastModified,
customUnit: JSON.stringify(newCustomUnitParam),
customUnitRate: JSON.stringify(newCustomUnitParam.rates),
};
- API.write('UpdateWorkspaceCustomUnitAndRate', params, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.UPDATE_WORKSPACE_CUSTOM_UNIT_AND_RATE, params, {optimisticData, successData, failureData});
}
/**
@@ -1417,22 +1395,6 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
},
];
- type CreateWorkspaceParams = {
- policyID: string;
- announceChatReportID: string;
- adminsChatReportID: string;
- expenseChatReportID: string;
- ownerEmail: string;
- makeMeAdmin: boolean;
- policyName: string;
- type: string;
- announceCreatedReportActionID: string;
- adminsCreatedReportActionID: string;
- expenseCreatedReportActionID: string;
- customUnitID: string;
- customUnitRateID: string;
- };
-
const params: CreateWorkspaceParams = {
policyID,
announceChatReportID,
@@ -1449,7 +1411,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
customUnitRateID,
};
- API.write('CreateWorkspace', params, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.CREATE_WORKSPACE, params, {optimisticData, successData, failureData});
return adminsChatReportID;
}
@@ -1480,13 +1442,9 @@ function openWorkspaceReimburseView(policyID: string) {
},
];
- type OpenWorkspaceReimburseViewParams = {
- policyID: string;
- };
-
const params: OpenWorkspaceReimburseViewParams = {policyID};
- API.read('OpenWorkspaceReimburseView', params, {successData, failureData});
+ API.read(READ_COMMANDS.OPEN_WORKSPACE_REIMBURSE_VIEW, params, {successData, failureData});
}
/**
@@ -1498,17 +1456,12 @@ function openWorkspace(policyID: string, clientMemberAccountIDs: number[]) {
return;
}
- type OpenWorkspaceParams = {
- policyID: string;
- clientMemberAccountIDs: string;
- };
-
const params: OpenWorkspaceParams = {
policyID,
clientMemberAccountIDs: JSON.stringify(clientMemberAccountIDs),
};
- API.read('OpenWorkspace', params);
+ API.read(READ_COMMANDS.OPEN_WORKSPACE, params);
}
function openWorkspaceMembersPage(policyID: string, clientMemberEmails: string[]) {
@@ -1517,17 +1470,12 @@ function openWorkspaceMembersPage(policyID: string, clientMemberEmails: string[]
return;
}
- type OpenWorkspaceMembersPageParams = {
- policyID: string;
- clientMemberEmails: string;
- };
-
const params: OpenWorkspaceMembersPageParams = {
policyID,
clientMemberEmails: JSON.stringify(clientMemberEmails),
};
- API.read('OpenWorkspaceMembersPage', params);
+ API.read(READ_COMMANDS.OPEN_WORKSPACE_MEMBERS_PAGE, params);
}
function openWorkspaceInvitePage(policyID: string, clientMemberEmails: string[]) {
@@ -1536,27 +1484,18 @@ function openWorkspaceInvitePage(policyID: string, clientMemberEmails: string[])
return;
}
- type OpenWorkspaceInvitePageParams = {
- policyID: string;
- clientMemberEmails: string;
- };
-
const params: OpenWorkspaceInvitePageParams = {
policyID,
clientMemberEmails: JSON.stringify(clientMemberEmails),
};
- API.read('OpenWorkspaceInvitePage', params);
+ API.read(READ_COMMANDS.OPEN_WORKSPACE_INVITE_PAGE, params);
}
function openDraftWorkspaceRequest(policyID: string) {
- type OpenDraftWorkspaceRequestParams = {
- policyID: string;
- };
-
const params: OpenDraftWorkspaceRequestParams = {policyID};
- API.read('OpenDraftWorkspaceRequest', params);
+ API.read(READ_COMMANDS.OPEN_DRAFT_WORKSPACE_REQUEST, params);
}
function setWorkspaceInviteMembersDraft(policyID: string, invitedEmailsToAccountIDs: Record) {
@@ -1667,12 +1606,12 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
const optimisticData: OnyxUpdate[] = [
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: newWorkspace,
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`,
value: {
[sessionAccountID]: {
@@ -1686,7 +1625,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
},
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${announceChatReportID}`,
value: {
pendingFields: {
@@ -1696,12 +1635,12 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
},
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceChatReportID}`,
value: announceReportActionData,
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`,
value: {
pendingFields: {
@@ -1711,12 +1650,12 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
},
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`,
value: adminsReportActionData,
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`,
value: {
pendingFields: {
@@ -1726,7 +1665,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
},
},
{
- onyxMethod: Onyx.METHOD.MERGE,
+ onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`,
value: workspaceChatReportActionData,
},
@@ -2018,26 +1957,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
value: {[movedReportAction.reportActionID]: null},
});
- type CreateWorkspaceFromIOUPayment = {
- policyID: string;
- announceChatReportID: string;
- adminsChatReportID: string;
- expenseChatReportID: string;
- ownerEmail: string;
- makeMeAdmin: boolean;
- policyName: string;
- type: string;
- announceCreatedReportActionID: string;
- adminsCreatedReportActionID: string;
- expenseCreatedReportActionID: string;
- customUnitID: string;
- customUnitRateID: string;
- iouReportID: string;
- memberData: string;
- reportActionID: string;
- };
-
- const params: CreateWorkspaceFromIOUPayment = {
+ const params: CreateWorkspaceFromIOUPaymentParams = {
policyID,
announceChatReportID,
adminsChatReportID,
@@ -2056,7 +1976,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report): string | undefined {
reportActionID: movedReportAction.reportActionID,
};
- API.write('CreateWorkspaceFromIOUPayment', params, {optimisticData, successData, failureData});
+ API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData});
return policyID;
}
diff --git a/src/libs/actions/PriorityMode.ts b/src/libs/actions/PriorityMode.ts
index 1d38d09e08a1..7ae174ac8606 100644
--- a/src/libs/actions/PriorityMode.ts
+++ b/src/libs/actions/PriorityMode.ts
@@ -3,6 +3,7 @@ import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as CollectionUtils from '@libs/CollectionUtils';
import Log from '@libs/Log';
+import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
@@ -120,7 +121,21 @@ function tryFocusModeUpdate() {
return;
}
- const reportCount = Object.keys(allReports ?? {}).length;
+ const validReports = [];
+ Object.keys(allReports ?? {}).forEach((key) => {
+ const report = allReports?.[key];
+ if (!report) {
+ return;
+ }
+
+ if (!ReportUtils.isValidReport(report) || !ReportUtils.isReportParticipant(currentUserAccountID ?? 0, report)) {
+ return;
+ }
+
+ validReports.push(report);
+ });
+
+ const reportCount = validReports.length;
if (reportCount < CONST.REPORT.MAX_COUNT_BEFORE_FOCUS_UPDATE) {
Log.info('Not switching user to optimized focus mode as they do not have enough reports', false, {reportCount});
return;
diff --git a/src/libs/actions/PushNotification.ts b/src/libs/actions/PushNotification.ts
index 888892fdc188..bc4d4eb05c5a 100644
--- a/src/libs/actions/PushNotification.ts
+++ b/src/libs/actions/PushNotification.ts
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
+import {WRITE_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';
import * as Device from './Device';
@@ -19,7 +20,7 @@ Onyx.connect({
*/
function setPushNotificationOptInStatus(isOptingIn: boolean) {
Device.getDeviceID().then((deviceID) => {
- const commandName = isOptingIn ? 'OptInToPushNotifications' : 'OptOutOfPushNotifications';
+ const commandName = isOptingIn ? WRITE_COMMANDS.OPT_IN_TO_PUSH_NOTIFICATIONS : WRITE_COMMANDS.OPT_OUT_OF_PUSH_NOTIFICATIONS;
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts
index 0ecda23c8d34..1f6905cfb8e0 100644
--- a/src/libs/actions/Report.ts
+++ b/src/libs/actions/Report.ts
@@ -3,13 +3,44 @@ import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import Str from 'expensify-common/lib/str';
import isEmpty from 'lodash/isEmpty';
import {DeviceEventEmitter, InteractionManager, Linking} from 'react-native';
-import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
+import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
-import type {NullishDeep} from 'react-native-onyx/lib/types';
import type {PartialDeep, ValueOf} from 'type-fest';
import type {Emoji} from '@assets/emojis/types';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import * as API from '@libs/API';
+import type {
+ AddCommentOrAttachementParams,
+ AddEmojiReactionParams,
+ AddWorkspaceRoomParams,
+ CompleteEngagementModalParams,
+ DeleteCommentParams,
+ ExpandURLPreviewParams,
+ FlagCommentParams,
+ GetNewerActionsParams,
+ GetOlderActionsParams,
+ GetReportPrivateNoteParams,
+ InviteToRoomParams,
+ LeaveRoomParams,
+ MarkAsUnreadParams,
+ OpenReportParams,
+ OpenRoomMembersPageParams,
+ ReadNewestActionParams,
+ ReconnectToReportParams,
+ RemoveEmojiReactionParams,
+ RemoveFromRoomParams,
+ ResolveActionableMentionWhisperParams,
+ SearchForReportsParams,
+ SetNameValuePairParams,
+ TogglePinnedChatParams,
+ UpdateCommentParams,
+ UpdatePolicyRoomNameParams,
+ UpdateReportNotificationPreferenceParams,
+ UpdateReportPrivateNoteParams,
+ UpdateReportWriteCapabilityParams,
+ UpdateWelcomeMessageParams,
+} from '@libs/API/parameters';
+import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as CollectionUtils from '@libs/CollectionUtils';
import DateUtils from '@libs/DateUtils';
import * as EmojiUtils from '@libs/EmojiUtils';
@@ -32,7 +63,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
-import type {PersonalDetails, PersonalDetailsList, ReportActionReactions, ReportUserIsTyping} from '@src/types/onyx';
+import type {PersonalDetails, PersonalDetailsList, ReportActionReactions, ReportMetadata, ReportUserIsTyping} from '@src/types/onyx';
import type {Decision, OriginalMessageIOU} from '@src/types/onyx/OriginalMessage';
import type {NotificationPreference, WriteCapability} from '@src/types/onyx/Report';
import type Report from '@src/types/onyx/Report';
@@ -125,6 +156,13 @@ Onyx.connect({
},
});
+let reportMetadata: OnyxCollection