diff --git a/__mocks__/react-native-permissions.ts b/__mocks__/react-native-permissions.ts index 67b7db830d94..d98b7f32a611 100644 --- a/__mocks__/react-native-permissions.ts +++ b/__mocks__/react-native-permissions.ts @@ -35,30 +35,30 @@ const requestNotifications: jest.Mock = jest.fn((options: Record notificationOptions.includes(option)) - .reduce((acc: NotificationSettings, option: string) => ({...acc, [option]: true}), { - lockScreen: true, - notificationCenter: true, - }), + .reduce( + (acc: NotificationSettings, option: string) => { + acc[option] = true; + return acc; + }, + { + lockScreen: true, + notificationCenter: true, + }, + ), })); const checkMultiple: jest.Mock = jest.fn((permissions: string[]) => - permissions.reduce( - (acc: ResultsCollection, permission: string) => ({ - ...acc, - [permission]: RESULTS.GRANTED, - }), - {}, - ), + permissions.reduce((acc: ResultsCollection, permission: string) => { + acc[permission] = RESULTS.GRANTED; + return acc; + }, {}), ); const requestMultiple: jest.Mock = jest.fn((permissions: string[]) => - permissions.reduce( - (acc: ResultsCollection, permission: string) => ({ - ...acc, - [permission]: RESULTS.GRANTED, - }), - {}, - ), + permissions.reduce((acc: ResultsCollection, permission: string) => { + acc[permission] = RESULTS.GRANTED; + return acc; + }, {}), ); export { diff --git a/package-lock.json b/package-lock.json index 042fd696bc84..05371cd33615 100644 --- a/package-lock.json +++ b/package-lock.json @@ -208,7 +208,7 @@ "electron-builder": "24.13.2", "eslint": "^7.6.0", "eslint-config-airbnb-typescript": "^17.1.0", - "eslint-config-expensify": "^2.0.47", + "eslint-config-expensify": "^2.0.49", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-jest": "^24.1.0", @@ -19371,9 +19371,9 @@ } }, "node_modules/eslint-config-expensify": { - "version": "2.0.48", - "resolved": "https://registry.npmjs.org/eslint-config-expensify/-/eslint-config-expensify-2.0.48.tgz", - "integrity": "sha512-PFegJ9Wfsiu5tgevhjA1toCxsZ8Etfk6pIjtXAnwpmVj7q4CtB3QDRusJoUDyJ3HrZr8AsFKViz7CU/CBTfwOw==", + "version": "2.0.49", + "resolved": "https://registry.npmjs.org/eslint-config-expensify/-/eslint-config-expensify-2.0.49.tgz", + "integrity": "sha512-3yGQuOsjvtWh/jYSJKIJgmwULhrVMCiYkWGzLOKpm/wCzdiP4l0T/gJMWOkvGhTtyqxsP7ZUTwPODgcE3extxA==", "dev": true, "dependencies": { "@lwc/eslint-plugin-lwc": "^1.7.2", diff --git a/package.json b/package.json index 6825857c5cf3..47210063c631 100644 --- a/package.json +++ b/package.json @@ -260,7 +260,7 @@ "electron-builder": "24.13.2", "eslint": "^7.6.0", "eslint-config-airbnb-typescript": "^17.1.0", - "eslint-config-expensify": "^2.0.47", + "eslint-config-expensify": "^2.0.49", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-jest": "^24.1.0", diff --git a/src/components/Icon/__mocks__/Expensicons.ts b/src/components/Icon/__mocks__/Expensicons.ts index e268b109f0a5..b808271cd39c 100644 --- a/src/components/Icon/__mocks__/Expensicons.ts +++ b/src/components/Icon/__mocks__/Expensicons.ts @@ -3,10 +3,11 @@ import type {SvgProps} from 'react-native-svg'; const Expensicons = jest.requireActual>>('../Expensicons'); -module.exports = Object.keys(Expensicons).reduce((prev, curr) => { +module.exports = Object.keys(Expensicons).reduce((acc: Record void>, curr) => { // We set the name of the anonymous mock function here so we can dynamically build the list of mocks and access the // "name" property to use in accessibility hints for element querying const fn = () => ''; Object.defineProperty(fn, 'name', {value: curr}); - return {...prev, [curr]: fn}; + acc[curr] = fn; + return acc; }, {}); diff --git a/src/hooks/useStepFormSubmit.ts b/src/hooks/useStepFormSubmit.ts index 0a0503516127..d825b12a4701 100644 --- a/src/hooks/useStepFormSubmit.ts +++ b/src/hooks/useStepFormSubmit.ts @@ -1,7 +1,8 @@ import {useCallback} from 'react'; import type {FormOnyxKeys, FormOnyxValues} from '@components/Form/types'; import * as FormActions from '@userActions/FormActions'; -import type {OnyxFormKey, OnyxFormValuesMapping} from '@src/ONYXKEYS'; +import type {OnyxFormKey, OnyxFormValuesMapping, OnyxValues} from '@src/ONYXKEYS'; +import type {BaseForm} from '@src/types/form/Form'; import type {SubStepProps} from './useSubStep/types'; type UseStepFormSubmitParams = Pick & { @@ -22,13 +23,10 @@ export default function useStepFormSubmit return useCallback( (values: FormOnyxValues) => { if (shouldSaveDraft) { - const stepValues = fieldIds.reduce( - (acc, key) => ({ - ...acc, - [key]: values[key], - }), - {}, - ); + const stepValues = fieldIds.reduce((acc, key) => { + acc[key] = values[key]; + return acc; + }, {} as Record<(typeof fieldIds)[number], OnyxValues[T][Exclude]>); FormActions.setDraftValues(formId, stepValues); } diff --git a/src/libs/ErrorUtils.ts b/src/libs/ErrorUtils.ts index 3487f05b9c05..577e858f3f42 100644 --- a/src/libs/ErrorUtils.ts +++ b/src/libs/ErrorUtils.ts @@ -122,7 +122,7 @@ function getLatestErrorFieldForAnyField getLatestErrorField(onyxData, fieldName)); - return latestErrorFields.reduce((acc, error) => ({...acc, ...error}), {}); + return latestErrorFields.reduce((acc, error) => Object.assign(acc, error), {}); } /** diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index e74280cf1036..60bb4ad322a9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -516,10 +516,13 @@ function getSearchText( function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry): OnyxCommon.Errors { const reportErrors = report?.errors ?? {}; const reportErrorFields = report?.errorFields ?? {}; - const reportActionErrors: OnyxCommon.ErrorFields = Object.values(reportActions ?? {}).reduce( - (prevReportActionErrors, action) => (!action || isEmptyObject(action.errors) ? prevReportActionErrors : {...prevReportActionErrors, ...action.errors}), - {}, - ); + const reportActionErrors: OnyxCommon.ErrorFields = Object.values(reportActions ?? {}).reduce((prevReportActionErrors, action) => { + if (!action || isEmptyObject(action.errors)) { + return prevReportActionErrors; + } + + return Object.assign(prevReportActionErrors, action.errors); + }, {}); const parentReportAction: OnyxEntry = !report?.parentReportID || !report?.parentReportActionID ? null : allReportActions?.[report.parentReportID ?? '']?.[report.parentReportActionID ?? ''] ?? null; @@ -543,7 +546,13 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< ...reportActionErrors, }; // Combine all error messages keyed by microtime into one object - const allReportErrors = Object.values(errorSources)?.reduce((prevReportErrors, errors) => (isEmptyObject(errors) ? prevReportErrors : {...prevReportErrors, ...errors}), {}); + const allReportErrors = Object.values(errorSources)?.reduce((prevReportErrors, errors) => { + if (isEmptyObject(errors)) { + return prevReportErrors; + } + + return Object.assign(prevReportErrors, errors); + }, {}); return allReportErrors; } diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 79e73f1585d2..7b328458c0ac 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -605,12 +605,12 @@ function getValidWaypoints(waypoints: WaypointCollection | undefined, reArrangeI return acc; } - const validatedWaypoints: WaypointCollection = {...acc, [`waypoint${reArrangeIndexes ? waypointIndex + 1 : index}`]: currentWaypoint}; + acc[`waypoint${reArrangeIndexes ? waypointIndex + 1 : index}`] = currentWaypoint; lastWaypointIndex = index; waypointIndex += 1; - return validatedWaypoints; + return acc; }, {}); } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 41e684a5c579..0c69e848ab11 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6571,28 +6571,24 @@ function setSplitShares(transaction: OnyxEntry, amount: n // If this is called from an existing group chat, it'll be included. So we manually add them to account for both cases. const accountIDs = [...new Set([userAccountID, ...newAccountIDs, ...oldAccountIDs])]; - const splitShares: SplitShares = accountIDs.reduce((result: SplitShares, accountID): SplitShares => { + const splitShares: SplitShares = accountIDs.reduce((acc: SplitShares, accountID): SplitShares => { // We want to replace the contents of splitShares to contain only `newAccountIDs` entries // In the case of going back to the participants page and removing a participant // a simple merge will have the previous participant still present in the splitshares object // So we manually set their entry to null if (!newAccountIDs.includes(accountID) && accountID !== userAccountID) { - return { - ...result, - [accountID]: null, - }; + acc[accountID] = null; + return acc; } const isPayer = accountID === userAccountID; const participantsLength = newAccountIDs.includes(userAccountID) ? newAccountIDs.length - 1 : newAccountIDs.length; const splitAmount = IOUUtils.calculateAmount(participantsLength, amount, currency, isPayer); - return { - ...result, - [accountID]: { - amount: splitAmount, - isModified: false, - }, + acc[accountID] = { + amount: splitAmount, + isModified: false, }; + return acc; }, {}); Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares}); @@ -6644,14 +6640,12 @@ function adjustRemainingSplitShares(transaction: NonNullable { + const splitShares: SplitShares = unmodifiedSharesAccountIDs.reduce((acc: SplitShares, accountID: number, index: number): SplitShares => { const splitAmount = IOUUtils.calculateAmount(unmodifiedSharesAccountIDs.length - 1, remainingTotal, transaction.currency, index === 0); - return { - ...result, - [accountID]: { - amount: splitAmount, - }, + acc[accountID] = { + amount: splitAmount, }; + return acc; }, {}); Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares}); diff --git a/src/libs/actions/OnyxUpdateManager/utils/DeferredOnyxUpdates.ts b/src/libs/actions/OnyxUpdateManager/utils/DeferredOnyxUpdates.ts index 451de2ed8a5c..8a7b67db30c6 100644 --- a/src/libs/actions/OnyxUpdateManager/utils/DeferredOnyxUpdates.ts +++ b/src/libs/actions/OnyxUpdateManager/utils/DeferredOnyxUpdates.ts @@ -39,13 +39,12 @@ function getUpdates(options?: GetDeferredOnyxUpdatesOptiosn) { return deferredUpdates; } - return Object.entries(deferredUpdates).reduce( - (accUpdates, [lastUpdateID, update]) => ({ - ...accUpdates, - ...(Number(lastUpdateID) > (options.minUpdateID ?? 0) ? {[Number(lastUpdateID)]: update} : {}), - }), - {}, - ); + return Object.entries(deferredUpdates).reduce((acc, [lastUpdateID, update]) => { + if (Number(lastUpdateID) > (options.minUpdateID ?? 0)) { + acc[Number(lastUpdateID)] = update; + } + return acc; + }, {}); } /** diff --git a/src/libs/actions/OnyxUpdateManager/utils/index.ts b/src/libs/actions/OnyxUpdateManager/utils/index.ts index be062b1e0921..ffc8cbd989df 100644 --- a/src/libs/actions/OnyxUpdateManager/utils/index.ts +++ b/src/libs/actions/OnyxUpdateManager/utils/index.ts @@ -67,14 +67,12 @@ function detectGapsAndSplit(updates: DeferredUpdatesDictionary, clientLastUpdate let updatesAfterGaps: DeferredUpdatesDictionary = {}; if (gapExists) { - updatesAfterGaps = Object.entries(updates).reduce( - (accUpdates, [lastUpdateID, update]) => ({ - ...accUpdates, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...(Number(lastUpdateID) >= firstUpdateAfterGapWithFallback ? {[Number(lastUpdateID)]: update} : {}), - }), - {}, - ); + updatesAfterGaps = Object.entries(updates).reduce((acc, [lastUpdateID, update]) => { + if (Number(lastUpdateID) >= firstUpdateAfterGapWithFallback) { + acc[Number(lastUpdateID)] = update; + } + return acc; + }, {}); } return {applicableUpdates, updatesAfterGaps, latestMissingUpdateID}; diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 82bca6dc7c22..294712666bdf 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -64,40 +64,31 @@ Onyx.connect({ }); function buildOptimisticPolicyCategories(policyID: string, categories: readonly string[]) { - const optimisticCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - name: category, - enabled: true, - errors: null, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }), - {}, - ); + const optimisticCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + name: category, + enabled: true, + errors: null, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + return acc; + }, {}); - const successCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - errors: null, - pendingAction: null, - }, - }), - {}, - ); + const successCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + errors: null, + pendingAction: null, + }; + return acc; + }, {}); - const failureCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'), - pendingAction: null, - }, - }), - {}, - ); + const failureCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'), + pendingAction: null, + }; + return acc; + }, {}); const onyxData: OnyxData = { optimisticData: [ diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 68814cbd78c0..0e28fca2fc3e 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -72,6 +72,7 @@ import type { InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, + PolicyCategory, PolicyEmployee, PolicyOwnershipChangeChecks, PolicyTag, @@ -86,7 +87,7 @@ import type { } from '@src/types/onyx'; import type {ErrorFields, Errors, OnyxValueWithOfflineFeedback, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {OriginalMessageJoinPolicyChangeLog} from '@src/types/onyx/OriginalMessage'; -import type {Attributes, CompanyAddress, CustomUnit, Rate, Unit} from '@src/types/onyx/Policy'; +import type {Attributes, CompanyAddress, CustomUnit, Rate, TaxRate, Unit} from '@src/types/onyx/Policy'; import type {OnyxData} from '@src/types/onyx/Request'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -2095,40 +2096,31 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol } function buildOptimisticPolicyCategories(policyID: string, categories: readonly string[]) { - const optimisticCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - name: category, - enabled: true, - errors: null, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }), - {}, - ); + const optimisticCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + name: category, + enabled: true, + errors: null, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + return acc; + }, {}); - const successCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - errors: null, - pendingAction: null, - }, - }), - {}, - ); + const successCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + errors: null, + pendingAction: null, + }; + return acc; + }, {}); - const failureCategoryMap = categories.reduce( - (acc, category) => ({ - ...acc, - [category]: { - errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'), - pendingAction: null, - }, - }), - {}, - ); + const failureCategoryMap = categories.reduce>>((acc, category) => { + acc[category] = { + errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.createFailureMessage'), + pendingAction: null, + }; + return acc; + }, {}); const onyxData: OnyxData = { optimisticData: [ @@ -2499,17 +2491,14 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyID}`, - value: CONST.POLICY.DEFAULT_CATEGORIES.reduce( - (acc, category) => ({ - ...acc, - [category]: { - name: category, - enabled: true, - errors: null, - }, - }), - {}, - ), + value: CONST.POLICY.DEFAULT_CATEGORIES.reduce>((acc, category) => { + acc[category] = { + name: category, + enabled: true, + errors: null, + }; + return acc; + }, {}), }, ]; @@ -3819,16 +3808,13 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) { taxRates: { ...defaultTaxRates, taxes: { - ...Object.keys(defaultTaxRates.taxes).reduce( - (prevTaxesData, taxKey) => ({ - ...prevTaxesData, - [taxKey]: { - ...defaultTaxRates.taxes[taxKey], - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }), - {}, - ), + ...Object.keys(defaultTaxRates.taxes).reduce((acc, taxKey) => { + acc[taxKey] = { + ...defaultTaxRates.taxes[taxKey], + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + return acc; + }, {} as Record), }, }, }, @@ -3841,13 +3827,10 @@ function enablePolicyTaxes(policyID: string, enabled: boolean) { value: { taxRates: { taxes: { - ...Object.keys(defaultTaxRates.taxes).reduce( - (prevTaxesData, taxKey) => ({ - ...prevTaxesData, - [taxKey]: {pendingAction: null}, - }), - {}, - ), + ...Object.keys(defaultTaxRates.taxes).reduce((acc, taxKey) => { + acc[taxKey] = {pendingAction: null}; + return acc; + }, {} as Record), }, }, }, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 44411b486525..03a95748c773 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3194,8 +3194,7 @@ function completeOnboarding( })); const tasksForOptimisticData = tasksData.reduce((acc, {currentTask, taskCreatedAction, taskReportAction, taskDescription, completedTaskReportAction}) => { - const tasksForOptimisticDataAcc: OnyxUpdate[] = [ - ...acc, + acc.push( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, @@ -3225,10 +3224,10 @@ function completeOnboarding( [taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction, }, }, - ]; + ); if (completedTaskReportAction) { - tasksForOptimisticDataAcc.push({ + acc.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, value: { @@ -3236,7 +3235,7 @@ function completeOnboarding( }, }); - tasksForOptimisticDataAcc.push({ + acc.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`, value: { @@ -3246,12 +3245,11 @@ function completeOnboarding( }); } - return tasksForOptimisticDataAcc; + return acc; }, []); const tasksForFailureData = tasksData.reduce((acc, {currentTask, taskReportAction}) => { - const tasksForFailureDataAcc: OnyxUpdate[] = [ - ...acc, + acc.push( { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, @@ -3271,9 +3269,9 @@ function completeOnboarding( key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, value: null, }, - ]; + ); - return tasksForFailureDataAcc; + return acc; }, []); const optimisticData: OnyxUpdate[] = [ diff --git a/src/libs/migrations/RenameCardIsVirtual.ts b/src/libs/migrations/RenameCardIsVirtual.ts index 5929b39dfe72..751c11d70eac 100644 --- a/src/libs/migrations/RenameCardIsVirtual.ts +++ b/src/libs/migrations/RenameCardIsVirtual.ts @@ -26,20 +26,20 @@ export default function () { } Log.info('[Migrate Onyx] Running RenameCardIsVirtual migration'); - const dataToSave: Record> = cardsWithIsVirtualProp.reduce((result, card) => { + const dataToSave = cardsWithIsVirtualProp.reduce((acc, card) => { if (!card) { - return result; + return acc; } - return { - ...result, - [card.cardID]: { - nameValuePairs: { - isVirtual: card?.nameValuePairs?.isVirtual, - }, - isVirtual: undefined, + + acc[card.cardID] = { + nameValuePairs: { + isVirtual: card?.nameValuePairs?.isVirtual, }, + isVirtual: undefined, }; - }, {}); + + return acc; + }, {} as Record>); // eslint-disable-next-line rulesdir/prefer-actions-set-data Onyx.merge(ONYXKEYS.CARD_LIST, dataToSave).then(() => { diff --git a/src/libs/migrations/RenameReceiptFilename.ts b/src/libs/migrations/RenameReceiptFilename.ts index b867024fc74e..bb873ee0ea21 100644 --- a/src/libs/migrations/RenameReceiptFilename.ts +++ b/src/libs/migrations/RenameReceiptFilename.ts @@ -30,19 +30,17 @@ export default function () { return resolve(); } Log.info('[Migrate Onyx] Running RenameReceiptFilename migration'); - const dataToSave: Record> = transactionsWithReceipt?.reduce((result, transaction) => { + const dataToSave = transactionsWithReceipt?.reduce((acc, transaction) => { if (!transaction) { - return result; + return acc; } Log.info(`[Migrate Onyx] Renaming receiptFilename ${transaction.receiptFilename} to filename`); - return { - ...result, - [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: { - filename: transaction.receiptFilename, - receiptFilename: null, - }, + acc[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`] = { + filename: transaction.receiptFilename, + receiptFilename: null, }; - }, {}); + return acc; + }, {} as Record>); // eslint-disable-next-line rulesdir/prefer-actions-set-data Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, dataToSave).then(() => { diff --git a/src/pages/EnablePayments/utils/getSubstepValues.ts b/src/pages/EnablePayments/utils/getSubstepValues.ts index d1fdda5fcbc1..2eb80ed1b2ee 100644 --- a/src/pages/EnablePayments/utils/getSubstepValues.ts +++ b/src/pages/EnablePayments/utils/getSubstepValues.ts @@ -7,14 +7,11 @@ function getSubstepValues( inputKeys: Record, walletAdditionalDetailsDraft: OnyxEntry, walletAdditionalDetails: OnyxEntry, -): {[K in T]: WalletAdditionalDetailsForm[K]} { - return Object.entries(inputKeys).reduce( - (acc, [, value]) => ({ - ...acc, - [value]: walletAdditionalDetailsDraft?.[value] ?? walletAdditionalDetails?.[value as keyof PersonalInfoStepProps] ?? '', - }), - {} as {[K in T]: WalletAdditionalDetailsForm[K]}, - ); +): {[K in T]: WalletAdditionalDetailsForm[K] | string} { + return Object.entries(inputKeys).reduce((acc, [, value]) => { + acc[value] = walletAdditionalDetailsDraft?.[value] ?? walletAdditionalDetails?.[value as keyof PersonalInfoStepProps] ?? ''; + return acc; + }, {} as {[K in T]: WalletAdditionalDetailsForm[K] | string}); } export default getSubstepValues; diff --git a/src/pages/ReimbursementAccount/BeneficialOwnersStep.tsx b/src/pages/ReimbursementAccount/BeneficialOwnersStep.tsx index 10b05e58deb7..393846413a27 100644 --- a/src/pages/ReimbursementAccount/BeneficialOwnersStep.tsx +++ b/src/pages/ReimbursementAccount/BeneficialOwnersStep.tsx @@ -68,13 +68,10 @@ function BeneficialOwnersStep({reimbursementAccount, reimbursementAccountDraft, const submit = () => { const beneficialOwnerFields = ['firstName', 'lastName', 'dob', 'ssnLast4', 'street', 'city', 'state', 'zipCode']; const beneficialOwners = beneficialOwnerKeys.map((ownerKey) => - beneficialOwnerFields.reduce( - (acc, fieldName) => ({ - ...acc, - [fieldName]: reimbursementAccountDraft ? reimbursementAccountDraft[`beneficialOwner_${ownerKey}_${fieldName}`] : undefined, - }), - {}, - ), + beneficialOwnerFields.reduce((acc, fieldName) => { + acc[fieldName] = reimbursementAccountDraft ? reimbursementAccountDraft[`beneficialOwner_${ownerKey}_${fieldName}`] : undefined; + return acc; + }, {} as Record), ); BankAccounts.updateBeneficialOwnersForBankAccount( diff --git a/src/pages/ReimbursementAccount/utils/getSubstepValues.ts b/src/pages/ReimbursementAccount/utils/getSubstepValues.ts index 8007218b41bb..f89625c613f7 100644 --- a/src/pages/ReimbursementAccount/utils/getSubstepValues.ts +++ b/src/pages/ReimbursementAccount/utils/getSubstepValues.ts @@ -3,18 +3,19 @@ import type {ReimbursementAccountForm} from '@src/types/form'; import type {ReimbursementAccount} from '@src/types/onyx'; import type {ACHData} from '@src/types/onyx/ReimbursementAccount'; -function getSubstepValues( - inputKeys: Record, +type SubstepValues = { + [TKey in TProps]: ReimbursementAccountForm[TKey]; +}; + +function getSubstepValues( + inputKeys: Record, reimbursementAccountDraft: OnyxEntry, reimbursementAccount: OnyxEntry, -): {[K in T]: ReimbursementAccountForm[K]} { - return Object.entries(inputKeys).reduce( - (acc, [, value]) => ({ - ...acc, - [value]: reimbursementAccountDraft?.[value] ?? reimbursementAccount?.achData?.[value as keyof ACHData] ?? '', - }), - {} as {[K in T]: ReimbursementAccountForm[K]}, - ); +): SubstepValues { + return Object.entries(inputKeys).reduce((acc, [, value]) => { + acc[value] = (reimbursementAccountDraft?.[value] ?? reimbursementAccount?.achData?.[value as keyof ACHData] ?? '') as ReimbursementAccountForm[TProps]; + return acc; + }, {} as SubstepValues); } export default getSubstepValues; diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index c537ee50d19b..56c9603dec4a 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -98,16 +98,13 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft, * Get filtered personalDetails list with current employeeList */ const filterPersonalDetails = (members: OnyxEntry, details: OnyxEntry): PersonalDetailsList => - Object.keys(members ?? {}).reduce((result, key) => { + Object.keys(members ?? {}).reduce((acc, key) => { const memberAccountIdKey = policyMemberEmailsToAccountIDs[key] ?? ''; if (details?.[memberAccountIdKey]) { - return { - ...result, - [memberAccountIdKey]: details[memberAccountIdKey], - }; + acc[memberAccountIdKey] = details[memberAccountIdKey]; } - return result; - }, {}); + return acc; + }, {} as PersonalDetailsList); /** * Get members for the current workspace */ diff --git a/src/types/onyx/PolicyCategory.ts b/src/types/onyx/PolicyCategory.ts index d65d50765671..d4162bfdcddf 100644 --- a/src/types/onyx/PolicyCategory.ts +++ b/src/types/onyx/PolicyCategory.ts @@ -5,23 +5,23 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{ name: string; /** Unencoded name of a category */ - unencodedName: string; + unencodedName?: string; /** Flag that determines if a category is active and able to be selected */ enabled: boolean; /** If true, not adding a comment to a transaction with this category will trigger a violation */ - areCommentsRequired: boolean; + areCommentsRequired?: boolean; /** "General Ledger code" that corresponds to this category in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention 'GL Code'?: string; /** An ID for this category from an external accounting system */ - externalID: string; + externalID?: string; /** The external accounting service that this category comes from */ - origin: string; + origin?: string; /** The old category name of the category when we edit the category name */ previousCategoryName?: string; diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 11befebea340..832c3e8b3336 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -214,7 +214,12 @@ function buildTestReportComment(created: string, actorAccountID: number, actionI } function assertFormDataMatchesObject(formData: FormData, obj: Report) { - expect(Array.from(formData.entries()).reduce((memo, x) => ({...memo, [x[0]]: x[1]}), {})).toEqual(expect.objectContaining(obj)); + expect( + Array.from(formData.entries()).reduce((acc, [key, val]) => { + acc[key] = val; + return acc; + }, {} as Record), + ).toEqual(expect.objectContaining(obj)); } /**