From 682cf8bde6cb8acc72f1062a0711c918bb5eb133 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 23 Jun 2025 13:08:27 +0200 Subject: [PATCH 1/7] Remove initialValue from useOnyx --- src/components/ArchivedReportFooter.tsx | 2 +- src/components/FloatingActionButton.tsx | 2 +- src/components/MoneyReportHeader.tsx | 3 +-- src/components/MoneyRequestHeader.tsx | 2 +- .../MoneyRequestReportView.tsx | 2 +- src/components/ProductTrainingContext/index.tsx | 2 +- .../Reactions/MiniQuickEmojiReactions.tsx | 4 ++-- .../BaseQuickEmojiReactions.tsx | 4 ++-- .../SelectionList/Search/ReportListItem.tsx | 2 +- src/hooks/useOnboardingFlow.ts | 2 +- src/hooks/useSidebarOrderedReports.tsx | 4 ++-- src/pages/AddUnreportedExpense.tsx | 1 - src/pages/ConciergePage.tsx | 2 +- src/pages/GroupChatNameEditPage.tsx | 2 +- src/pages/ReportAvatar.tsx | 2 +- .../Search/SearchMoneyRequestReportPage.tsx | 2 +- src/pages/home/ReportScreen.tsx | 6 +++--- .../SilentCommentUpdater/index.android.tsx | 16 +++++++--------- .../SilentCommentUpdater/index.tsx | 16 ++++++---------- .../home/report/ReportActionItemMessageEdit.tsx | 2 +- src/pages/home/report/ReportFooter.tsx | 2 +- src/pages/home/sidebar/SidebarLinksData.tsx | 4 ++-- .../routes/ProfileAvatarModalContent.tsx | 2 +- .../routes/ReportAvatarModalContent.tsx | 2 +- .../routes/WorkspaceAvatarModalContent.tsx | 2 +- .../Contacts/ContactMethodDetailsPage.tsx | 2 +- src/pages/settings/Profile/DisplayNamePage.tsx | 2 +- .../Profile/PersonalDetails/DateOfBirthPage.tsx | 2 +- .../Profile/PersonalDetails/LegalNamePage.tsx | 2 +- .../Profile/PersonalDetails/PhoneNumberPage.tsx | 2 +- src/pages/settings/Profile/ProfileAvatar.tsx | 2 +- .../settings/Wallet/WalletPage/WalletPage.tsx | 10 +++++----- src/pages/workspace/AccessOrNotFoundWrapper.tsx | 2 +- .../workspace/withPolicyAndFullscreenLoading.tsx | 2 +- 34 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/components/ArchivedReportFooter.tsx b/src/components/ArchivedReportFooter.tsx index 75f9ac985966..8c5737c09a7d 100644 --- a/src/components/ArchivedReportFooter.tsx +++ b/src/components/ArchivedReportFooter.tsx @@ -21,7 +21,7 @@ function ArchivedReportFooter({report}: ArchivedReportFooterProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {initialValue: {}}); + const [personalDetails = {}] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, selector: ReportActionsUtils.getLastClosedReportAction}); const originalMessage = ReportActionsUtils.isClosedAction(reportClosedAction) ? ReportActionsUtils.getOriginalMessage(reportClosedAction) : null; const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT; diff --git a/src/components/FloatingActionButton.tsx b/src/components/FloatingActionButton.tsx index 1e2472710d90..ff3668c0ee0f 100644 --- a/src/components/FloatingActionButton.tsx +++ b/src/components/FloatingActionButton.tsx @@ -46,7 +46,7 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role, isTo const borderRadius = styles.floatingActionButton.borderRadius; const fabPressable = useRef(null); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {initialValue: false, canBeMissing: true}); + const [isSidebarLoaded = false] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {canBeMissing: true}); const isHomeRouteActive = useIsHomeRouteActive(shouldUseNarrowLayout); const {renderProductTrainingTooltip, shouldShowProductTrainingTooltip, hideProductTrainingTooltip} = useProductTrainingContext( CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.GLOBAL_CREATE_TOOLTIP, diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index acc97a7154c6..840178f4f600 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -168,13 +168,12 @@ function MoneyReportHeader({ }, [reportActions, transactionThreadReport?.parentReportActionID]); const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => reportTransactionsSelector(_transactions, moneyRequestReport?.reportID), - initialValue: [], canBeMissing: true, }); const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${isMoneyRequestAction(requestParentReportAction) && getOriginalMessage(requestParentReportAction)?.IOUTransactionID}`, { canBeMissing: true, }); - const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true, canBeMissing: true}); + const [dismissedHoldUseExplanation = true, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: true}); const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult); const isExported = isExportedUtils(reportActions); diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 5af8ba1b6a3e..137b94dcbba6 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -81,7 +81,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const [downloadErrorModalVisible, setDownloadErrorModalVisible] = useState(false); - const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true, canBeMissing: false}); + const [dismissedHoldUseExplanation = true, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: false}); const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true}); const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult); const styles = useThemeStyles(); diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index 9309c30a94cb..a065a1f25c3d 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -90,7 +90,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe const reportID = report?.reportID; const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); - const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {initialValue: false, canBeMissing: true}); + const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {canBeMissing: true}); const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`, {canBeMissing: true}); diff --git a/src/components/ProductTrainingContext/index.tsx b/src/components/ProductTrainingContext/index.tsx index a6efeb4774d2..79996712a3aa 100644 --- a/src/components/ProductTrainingContext/index.tsx +++ b/src/components/ProductTrainingContext/index.tsx @@ -49,7 +49,7 @@ const ProductTrainingContext = createContext({ }); function ProductTrainingContextProvider({children}: ChildrenProps) { - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: true}); const hasBeenAddedToNudgeMigration = !!tryNewDot?.nudgeMigration?.timestamp; const [isOnboardingCompleted = true, isOnboardingCompletedMetadata] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { diff --git a/src/components/Reactions/MiniQuickEmojiReactions.tsx b/src/components/Reactions/MiniQuickEmojiReactions.tsx index ef0519f3bc1e..058a08dd4ea5 100644 --- a/src/components/Reactions/MiniQuickEmojiReactions.tsx +++ b/src/components/Reactions/MiniQuickEmojiReactions.tsx @@ -37,8 +37,8 @@ function MiniQuickEmojiReactions({reportAction, reportActionID, onEmojiSelected, const StyleUtils = useStyleUtils(); const ref = useRef(null); const {translate, preferredLocale} = useLocalize(); - const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE}); - const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}}); + const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); + const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); const openEmojiPicker = () => { onPressOpenPicker(); diff --git a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx index fb16f7cf4a1c..304bbae2ac8f 100644 --- a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx +++ b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx @@ -23,8 +23,8 @@ function BaseQuickEmojiReactions({ }: BaseQuickEmojiReactionsProps) { const styles = useThemeStyles(); const {preferredLocale} = useLocalize(); - const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE}); - const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}}); + const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); + const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); return ( diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 93a8c41c0c63..dcb651c2f5b6 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -38,7 +38,7 @@ function ReportListItem({ const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: true}); + const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true}); const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportItem?.policyID}`]; const isEmptyReport = reportItem.transactions.length === 0; const isDisabledOrEmpty = isEmptyReport || isDisabled; diff --git a/src/hooks/useOnboardingFlow.ts b/src/hooks/useOnboardingFlow.ts index 3462ff52f023..539b7457e55e 100644 --- a/src/hooks/useOnboardingFlow.ts +++ b/src/hooks/useOnboardingFlow.ts @@ -17,7 +17,7 @@ import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; * Warning: This hook should be used only once in the app */ function useOnboardingFlowRouter() { - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const [onboardingValues, isOnboardingCompletedMetadata] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { canBeMissing: true, }); diff --git a/src/hooks/useSidebarOrderedReports.tsx b/src/hooks/useSidebarOrderedReports.tsx index cc8b2b3d333e..56cabe92eae6 100644 --- a/src/hooks/useSidebarOrderedReports.tsx +++ b/src/hooks/useSidebarOrderedReports.tsx @@ -53,13 +53,13 @@ function SidebarOrderedReportsContextProvider({ */ currentReportIDForTests, }: SidebarOrderedReportsContextProviderProps) { - const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {initialValue: CONST.PRIORITY_MODE.DEFAULT, canBeMissing: true}); + const [priorityMode = CONST.PRIORITY_MODE.DEFAULT] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true}); const [chatReports, {sourceValue: reportUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); const [policies, {sourceValue: policiesUpdates}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector), canBeMissing: true}); const [transactions, {sourceValue: transactionsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); const [transactionViolations, {sourceValue: transactionViolationsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const [reportNameValuePairs, {sourceValue: reportNameValuePairsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true}); - const [, {sourceValue: reportsDraftsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {initialValue: {}, canBeMissing: true}); + const [reportsDrafts = {}, {sourceValue: reportsDraftsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true}); const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: (value) => value?.reports, canBeMissing: true}); const [currentReportsToDisplay, setCurrentReportsToDisplay] = useState({}); diff --git a/src/pages/AddUnreportedExpense.tsx b/src/pages/AddUnreportedExpense.tsx index cdfd56500142..7b8127dbc351 100644 --- a/src/pages/AddUnreportedExpense.tsx +++ b/src/pages/AddUnreportedExpense.tsx @@ -51,7 +51,6 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => getUnreportedTransactions(_transactions), - initialValue: [], canBeMissing: true, }); diff --git a/src/pages/ConciergePage.tsx b/src/pages/ConciergePage.tsx index 7d59b98de71f..3cde73f37693 100644 --- a/src/pages/ConciergePage.tsx +++ b/src/pages/ConciergePage.tsx @@ -23,7 +23,7 @@ function ConciergePage() { const styles = useThemeStyles(); const isUnmounted = useRef(false); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); - const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true, canBeMissing: true}); + const [isLoadingReportData = true] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true}); const route = useRoute(); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true}); diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 1c8ee7a9df87..11f6bfac9e7a 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -31,7 +31,7 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { // In this case its better to use empty string as the reportID if there is no reportID const reportID = report?.reportID; const isUpdatingExistingReport = !!reportID; - const [groupChatDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {initialValue: getGroupChatDraft(), canBeMissing: true}); + const [groupChatDraft = getGroupChatDraft()] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); const styles = useThemeStyles(); const {translate} = useLocalize(); diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 53e0e5db6950..92c9322cdc7b 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -16,7 +16,7 @@ function ReportAvatar({route}: ReportAvatarProps) { const {reportID, policyID} = route.params; const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true}); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const attachment = useMemo(() => { if (isGroupChat(report) && !isThread(report)) { diff --git a/src/pages/Search/SearchMoneyRequestReportPage.tsx b/src/pages/Search/SearchMoneyRequestReportPage.tsx index 8dee241f6a43..2dcf88868cc5 100644 --- a/src/pages/Search/SearchMoneyRequestReportPage.tsx +++ b/src/pages/Search/SearchMoneyRequestReportPage.tsx @@ -40,7 +40,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) { const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true, allowStaleData: true}); - const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: false}); + const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 0889c192b6a5..7ef99bb50170 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -148,14 +148,14 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const currentReportIDValue = useCurrentReportID(); const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: false}); - const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false, canBeMissing: true}); + const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {canBeMissing: true}); const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {canBeMissing: true}); const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(accountManagerReportID)}`, {canBeMissing: true}); - const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false, canBeMissing: true}); + const [userLeavingStatus = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {canBeMissing: true}); const [reportOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportNameValuePairsOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true, allowStaleData: true}); - const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: false}); + const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportOnyx?.parentReportID)}`, { canEvict: false, selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID), diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx index 8df4ba4a0c26..1e1b9ae1eb29 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx @@ -1,7 +1,7 @@ import {useEffect} from 'react'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {SilentCommentUpdaterOnyxProps, SilentCommentUpdaterProps} from './types'; +import type {SilentCommentUpdaterProps} from './types'; /** * Adding .android component to disable updating comment when prev comment is different @@ -13,9 +13,11 @@ import type {SilentCommentUpdaterOnyxProps, SilentCommentUpdaterProps} from './t * It is connected to the actual draft comment in onyx. The comment in onyx might updates multiple times, and we want to avoid * re-rendering a UI component for that. That's why the side effect was moved down to a separate component. */ -function SilentCommentUpdater({comment, updateComment}: SilentCommentUpdaterProps) { +function SilentCommentUpdater({updateComment, reportID}: SilentCommentUpdaterProps) { + const [comment = ''] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, {canBeMissing: true}); + useEffect(() => { - updateComment(comment ?? ''); + updateComment(comment); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- We need to run this on mount }, []); @@ -24,8 +26,4 @@ function SilentCommentUpdater({comment, updateComment}: SilentCommentUpdaterProp SilentCommentUpdater.displayName = 'SilentCommentUpdater'; -export default withOnyx({ - comment: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, - }, -})(SilentCommentUpdater); +export default SilentCommentUpdater; diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx index 6cce050710c7..e7d39faa5a59 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx @@ -1,23 +1,24 @@ import {useEffect} from 'react'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import usePrevious from '@hooks/usePrevious'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {SilentCommentUpdaterOnyxProps, SilentCommentUpdaterProps} from './types'; +import type {SilentCommentUpdaterProps} from './types'; /** * This component doesn't render anything. It runs a side effect to update the comment of a report under certain conditions. * It is connected to the actual draft comment in onyx. The comment in onyx might updates multiple times, and we want to avoid * re-rendering a UI component for that. That's why the side effect was moved down to a separate component. */ -function SilentCommentUpdater({comment, commentRef, reportID, value, updateComment, isCommentPendingSaved}: SilentCommentUpdaterProps) { +function SilentCommentUpdater({commentRef, reportID, value, updateComment, isCommentPendingSaved}: SilentCommentUpdaterProps) { + const [comment = ''] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, {canBeMissing: true}); const prevCommentProp = usePrevious(comment); const prevReportId = usePrevious(reportID); const {preferredLocale} = useLocalize(); const prevPreferredLocale = usePrevious(preferredLocale); useEffect(() => { - updateComment(comment ?? ''); + updateComment(comment); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- We need to run this on mount }, []); @@ -41,9 +42,4 @@ function SilentCommentUpdater({comment, commentRef, reportID, value, updateComme SilentCommentUpdater.displayName = 'SilentCommentUpdater'; -export default withOnyx({ - comment: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, - initialValue: '', - }, -})(SilentCommentUpdater); +export default SilentCommentUpdater; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index 59e02699c911..7a2e239d5578 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -85,7 +85,7 @@ function ReportActionItemMessageEdit( {action, draftMessage, reportID, policyID, index, isGroupPolicyReport, shouldDisableEmojiPicker = false}: ReportActionItemMessageEditProps, forwardedRef: ForwardedRef, ) { - const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE, canBeMissing: true}); + const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index 03fcea1e72e6..d93ca2b9a18d 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -85,7 +85,7 @@ function ReportFooter({ const {windowWidth} = useWindowDimensions(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [shouldShowComposeInput] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, {initialValue: false, canBeMissing: true}); + const [shouldShowComposeInput = false] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, {canBeMissing: true}); const [isAnonymousUser = false] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS, canBeMissing: false}); const [isBlockedFromChat] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CHAT, { selector: (dateString) => { diff --git a/src/pages/home/sidebar/SidebarLinksData.tsx b/src/pages/home/sidebar/SidebarLinksData.tsx index 89b37e13a28d..78903c64ca25 100644 --- a/src/pages/home/sidebar/SidebarLinksData.tsx +++ b/src/pages/home/sidebar/SidebarLinksData.tsx @@ -19,8 +19,8 @@ function SidebarLinksData({insets}: SidebarLinksDataProps) { const isFocused = useIsFocused(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); - const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {initialValue: CONST.PRIORITY_MODE.DEFAULT, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); + const [priorityMode = CONST.PRIORITY_MODE.DEFAULT] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true}); const {orderedReports, currentReportID} = useSidebarOrderedReports(); diff --git a/src/pages/media/AttachmentModalScreen/routes/ProfileAvatarModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/ProfileAvatarModalContent.tsx index c4c368eda6bd..6711ab9b08e1 100644 --- a/src/pages/media/AttachmentModalScreen/routes/ProfileAvatarModalContent.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/ProfileAvatarModalContent.tsx @@ -19,7 +19,7 @@ function ProfileAvatarModalContent({navigation, route}: AttachmentModalScreenPro const [personalDetailsMetadata] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_METADATA, {canBeMissing: false}); const avatarURL = personalDetail?.avatar ?? ''; const displayName = getDisplayNameOrDefault(personalDetail); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); useEffect(() => { if (!isValidAccountRoute(accountID)) { diff --git a/src/pages/media/AttachmentModalScreen/routes/ReportAvatarModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/ReportAvatarModalContent.tsx index c3bdd4236759..cfe2ee1043f3 100644 --- a/src/pages/media/AttachmentModalScreen/routes/ReportAvatarModalContent.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/ReportAvatarModalContent.tsx @@ -13,7 +13,7 @@ function ReportAvatarModalContent({navigation, route}: AttachmentModalScreenProp const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true}); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const attachment = useMemo(() => { if (isGroupChat(report) && !isThread(report)) { diff --git a/src/pages/media/AttachmentModalScreen/routes/WorkspaceAvatarModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/WorkspaceAvatarModalContent.tsx index d9477b302dc6..7a74fd9e5bd7 100644 --- a/src/pages/media/AttachmentModalScreen/routes/WorkspaceAvatarModalContent.tsx +++ b/src/pages/media/AttachmentModalScreen/routes/WorkspaceAvatarModalContent.tsx @@ -11,7 +11,7 @@ function WorkspaceAvatarModalContent({navigation, route}: AttachmentModalScreenP const {policyID} = route.params; const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: false}); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const avatarURL = policy?.avatarURL ?? '' ?? getDefaultWorkspaceAvatar(policy?.name ?? ''); diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx index 6de3aa90fe6d..72cece66476d 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx @@ -56,7 +56,7 @@ function ContactMethodDetailsPage({route}: ContactMethodDetailsPageProps) { const [session, sessionResult] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); const [myDomainSecurityGroups, myDomainSecurityGroupsResult] = useOnyx(ONYXKEYS.MY_DOMAIN_SECURITY_GROUPS, {canBeMissing: true}); const [securityGroups, securityGroupsResult] = useOnyx(ONYXKEYS.COLLECTION.SECURITY_GROUP, {canBeMissing: true}); - const [isLoadingReportData, isLoadingReportDataResult] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true, canBeMissing: true}); + const [isLoadingReportData = true, isLoadingReportDataResult] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true}); const [isValidateCodeFormVisible, setIsValidateCodeFormVisible] = useState(true); const {isActingAsDelegate, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext); const isLoadingOnyxValues = isLoadingOnyxValue(loginListResult, sessionResult, myDomainSecurityGroupsResult, securityGroupsResult, isLoadingReportDataResult); diff --git a/src/pages/settings/Profile/DisplayNamePage.tsx b/src/pages/settings/Profile/DisplayNamePage.tsx index 767b69bbba0c..3140c2837f54 100644 --- a/src/pages/settings/Profile/DisplayNamePage.tsx +++ b/src/pages/settings/Profile/DisplayNamePage.tsx @@ -34,7 +34,7 @@ const updateDisplayName = (values: FormOnyxValues { function LegalNamePage() { const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP); const styles = useThemeStyles(); const {translate} = useLocalize(); diff --git a/src/pages/settings/Profile/PersonalDetails/PhoneNumberPage.tsx b/src/pages/settings/Profile/PersonalDetails/PhoneNumberPage.tsx index cc5fbb123a26..7ce3c8cb0517 100644 --- a/src/pages/settings/Profile/PersonalDetails/PhoneNumberPage.tsx +++ b/src/pages/settings/Profile/PersonalDetails/PhoneNumberPage.tsx @@ -24,7 +24,7 @@ import type {PrivatePersonalDetails} from '@src/types/onyx'; function PhoneNumberPage() { const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true}); + const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP); const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); diff --git a/src/pages/settings/Profile/ProfileAvatar.tsx b/src/pages/settings/Profile/ProfileAvatar.tsx index bc251bd0bd94..1b938e73127d 100644 --- a/src/pages/settings/Profile/ProfileAvatar.tsx +++ b/src/pages/settings/Profile/ProfileAvatar.tsx @@ -18,7 +18,7 @@ type ProfileAvatarProps = PlatformStackScreenProps, ref: ForwardedRef, ) { - const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true}); + const [isLoadingReportData = true] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); if ((isLoadingPolicy || isLoadingReportData) && isEmpty(policy) && isEmpty(policyDraft)) { From 731dce44601fc13129319d53d88ceec4079b56ee Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 25 Jun 2025 11:45:51 +0200 Subject: [PATCH 2/7] Lint and TS fixes --- src/hooks/useSidebarOrderedReports.tsx | 2 +- .../SilentCommentUpdater/index.android.tsx | 2 +- .../SilentCommentUpdater/index.tsx | 2 +- .../ReportActionCompose/SilentCommentUpdater/types.ts | 11 ++--------- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/hooks/useSidebarOrderedReports.tsx b/src/hooks/useSidebarOrderedReports.tsx index 56cabe92eae6..43ef03d65e0b 100644 --- a/src/hooks/useSidebarOrderedReports.tsx +++ b/src/hooks/useSidebarOrderedReports.tsx @@ -59,7 +59,7 @@ function SidebarOrderedReportsContextProvider({ const [transactions, {sourceValue: transactionsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); const [transactionViolations, {sourceValue: transactionViolationsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const [reportNameValuePairs, {sourceValue: reportNameValuePairsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true}); - const [reportsDrafts = {}, {sourceValue: reportsDraftsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true}); + const [, {sourceValue: reportsDraftsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true}); const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: (value) => value?.reports, canBeMissing: true}); const [currentReportsToDisplay, setCurrentReportsToDisplay] = useState({}); diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx index 1e1b9ae1eb29..26b0d4095113 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx @@ -1,7 +1,7 @@ import {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {SilentCommentUpdaterProps} from './types'; +import type SilentCommentUpdaterProps from './types'; /** * Adding .android component to disable updating comment when prev comment is different diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx index e7d39faa5a59..50e46748cc50 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx @@ -3,7 +3,7 @@ import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import usePrevious from '@hooks/usePrevious'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {SilentCommentUpdaterProps} from './types'; +import type SilentCommentUpdaterProps from './types'; /** * This component doesn't render anything. It runs a side effect to update the comment of a report under certain conditions. diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/types.ts b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/types.ts index 6f9e8b8a6d42..2768dfc1250a 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/types.ts +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/types.ts @@ -1,11 +1,4 @@ -import type {OnyxEntry} from 'react-native-onyx'; - -type SilentCommentUpdaterOnyxProps = { - /** The comment of the report */ - comment: OnyxEntry; -}; - -type SilentCommentUpdaterProps = SilentCommentUpdaterOnyxProps & { +type SilentCommentUpdaterProps = { /** Updates the comment */ updateComment: (comment: string) => void; @@ -22,4 +15,4 @@ type SilentCommentUpdaterProps = SilentCommentUpdaterOnyxProps & { isCommentPendingSaved: React.RefObject; }; -export type {SilentCommentUpdaterProps, SilentCommentUpdaterOnyxProps}; +export default SilentCommentUpdaterProps; From 80cff7cb025d68f605816f6fac46277403f20d1c Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 8 Jul 2025 16:17:01 +0200 Subject: [PATCH 3/7] Add stable default values references --- src/components/ArchivedReportFooter.tsx | 5 +++-- src/components/KYCWall/BaseKYCWall.tsx | 4 +++- src/components/MoneyReportHeader.tsx | 3 ++- .../Reactions/MiniQuickEmojiReactions.tsx | 4 +++- .../BaseQuickEmojiReactions.tsx | 4 +++- src/components/Search/SearchAutocompleteList.tsx | 7 +++++-- .../Search/SearchPageHeader/SearchFiltersBar.tsx | 4 +++- .../Search/TransactionGroupListItem.tsx | 5 ++++- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 5 +++-- src/hooks/usePaymentOptions.ts | 8 ++++---- src/hooks/useSearchTypeMenu.tsx | 5 ++++- src/hooks/useTransactionViolations.ts | 5 +++-- src/hooks/useTripTransactions.ts | 5 +++-- src/pages/AddUnreportedExpense.tsx | 3 ++- .../OnboardingPurpose/BaseOnboardingPurpose.tsx | 3 ++- src/pages/Search/AdvancedSearchFilters.tsx | 12 ++++++------ .../SearchFiltersTagPage.tsx | 4 +++- src/pages/Search/SearchMoneyRequestReportPage.tsx | 5 ++++- src/pages/Search/SearchPage.tsx | 5 +++-- src/pages/home/ReportScreen.tsx | 10 ++++++---- .../IOURequestStepScan/ReceiptViewModal/index.tsx | 3 ++- .../step/IOURequestStepScan/index.native.tsx | 4 +++- .../settings/Preferences/PreferencesPage.tsx | 4 +++- .../settings/Wallet/ActivatePhysicalCardPage.tsx | 5 +++-- src/pages/settings/Wallet/PaymentMethodList.tsx | 10 +++++----- .../settings/Wallet/WalletPage/WalletPage.tsx | 15 ++++++++------- src/pages/signin/SignInPage.tsx | 3 ++- src/pages/workspace/WorkspaceOverviewPage.tsx | 5 +++-- .../WorkspaceCompanyCardsListHeaderButtons.tsx | 5 +++-- .../companyCards/WorkspaceCompanyCardsPage.tsx | 5 +++-- .../companyCards/addNew/SelectCountryStep.tsx | 4 +++- .../companyCards/assignCard/ConfirmationStep.tsx | 5 +++-- src/types/utils/EmptyObject.ts | 8 +++++++- src/types/utils/getEmptyArray.ts | 7 +++++++ 34 files changed, 124 insertions(+), 65 deletions(-) create mode 100644 src/types/utils/getEmptyArray.ts diff --git a/src/components/ArchivedReportFooter.tsx b/src/components/ArchivedReportFooter.tsx index 058c9d06d3b1..ce38b2ee3369 100644 --- a/src/components/ArchivedReportFooter.tsx +++ b/src/components/ArchivedReportFooter.tsx @@ -9,7 +9,8 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Report} from '@src/types/onyx'; +import type {PersonalDetailsList, Report} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import Banner from './Banner'; type ArchivedReportFooterProps = { @@ -21,7 +22,7 @@ function ArchivedReportFooter({report}: ArchivedReportFooterProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const [personalDetails = {}] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const [personalDetails = getEmptyObject()] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, selector: ReportActionsUtils.getLastClosedReportAction}); const originalMessage = ReportActionsUtils.isClosedAction(reportClosedAction) ? ReportActionsUtils.getOriginalMessage(reportClosedAction) : null; const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT; diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index d2597b93746d..7f399546ad9d 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -17,7 +17,9 @@ import {setKYCWallSource} from '@userActions/Wallet'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {BankAccountList} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import viewRef from '@src/types/utils/viewRef'; import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types'; @@ -48,7 +50,7 @@ function KYCWall({ const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: true}); const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true}); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); - const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); + const [bankAccountList = getEmptyObject()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true}); const anchorRef = useRef(null); diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 64ad7207a003..a8a69efb1f2a 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -85,6 +85,7 @@ import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import type IconAsset from '@src/types/utils/IconAsset'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import BrokenConnectionDescription from './BrokenConnectionDescription'; @@ -167,7 +168,7 @@ function MoneyReportHeader({ } return reportActions.find((action): action is OnyxTypes.ReportAction => action.reportActionID === transactionThreadReport.parentReportActionID); }, [reportActions, transactionThreadReport?.parentReportActionID]); - const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { + const [transactions = getEmptyArray()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => reportTransactionsSelector(_transactions, moneyRequestReport?.reportID), canBeMissing: true, }); diff --git a/src/components/Reactions/MiniQuickEmojiReactions.tsx b/src/components/Reactions/MiniQuickEmojiReactions.tsx index 74913cc379e9..f95ad29a027e 100644 --- a/src/components/Reactions/MiniQuickEmojiReactions.tsx +++ b/src/components/Reactions/MiniQuickEmojiReactions.tsx @@ -16,6 +16,8 @@ import {emojiPickerRef, showEmojiPicker} from '@userActions/EmojiPickerAction'; import {callFunctionIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {ReportActionReactions} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import type {BaseQuickEmojiReactionsProps} from './QuickEmojiReactions/types'; type MiniQuickEmojiReactionsProps = BaseQuickEmojiReactionsProps & { @@ -38,7 +40,7 @@ function MiniQuickEmojiReactions({reportAction, reportActionID, onEmojiSelected, const ref = useRef(null); const {translate, preferredLocale} = useLocalize(); const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); - const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); + const [emojiReactions = getEmptyObject()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); const openEmojiPicker = () => { onPressOpenPicker(); diff --git a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx index 19ed41cd25b0..65669311112c 100644 --- a/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx +++ b/src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx @@ -11,6 +11,8 @@ import {getLocalizedEmojiName, getPreferredEmojiCode} from '@libs/EmojiUtils'; import {callFunctionIfActionIsAllowed} from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {ReportActionReactions} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import type {BaseQuickEmojiReactionsProps} from './types'; function BaseQuickEmojiReactions({ @@ -24,7 +26,7 @@ function BaseQuickEmojiReactions({ const styles = useThemeStyles(); const {preferredLocale} = useLocalize(); const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); - const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); + const [emojiReactions = getEmptyObject()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); return ( diff --git a/src/components/Search/SearchAutocompleteList.tsx b/src/components/Search/SearchAutocompleteList.tsx index 6f9caa4595db..fe737e6dd91c 100644 --- a/src/components/Search/SearchAutocompleteList.tsx +++ b/src/components/Search/SearchAutocompleteList.tsx @@ -1,6 +1,7 @@ import {Str} from 'expensify-common'; import type {ForwardedRef} from 'react'; import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react'; +import type {OnyxCollection} from 'react-native-onyx'; import * as Expensicons from '@components/Icon/Expensicons'; import {usePersonalDetails} from '@components/OnyxProvider'; import {useOptionsList} from '@components/OptionListContextProvider'; @@ -39,7 +40,9 @@ import StringUtils from '@libs/StringUtils'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {Policy, Report} from '@src/types/onyx'; import type PersonalDetails from '@src/types/onyx/PersonalDetails'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import {getSubstitutionMapKey} from './SearchRouter/getQueryWithSubstitutions'; import type {SearchFilterKey, UserFriendlyKey} from './types'; @@ -154,7 +157,7 @@ function SearchAutocompleteList( const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true}); const personalDetails = usePersonalDetails(); - const [reports = {}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); + const [reports = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); const taxRates = getAllTaxRates(); const {options, areOptionsInitialized} = useOptionsList(); @@ -248,7 +251,7 @@ function SearchAutocompleteList( return getAutocompleteRecentCategories(allRecentCategories); }, [allRecentCategories]); - const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); + const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email, canBeMissing: false}); const workspaceList = useMemo( diff --git a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx index 2438946ebdec..e95974f3ccfd 100644 --- a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx +++ b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx @@ -39,6 +39,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {SearchAdvancedFiltersForm} from '@src/types/form'; import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm'; +import type {CurrencyList} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import type {SearchHeaderOptionValue} from './SearchPageHeader'; type SearchFiltersBarProps = { @@ -66,7 +68,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const [policyTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: true}); const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {canBeMissing: true}); const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true}); diff --git a/src/components/SelectionList/Search/TransactionGroupListItem.tsx b/src/components/SelectionList/Search/TransactionGroupListItem.tsx index 9b688afdb214..4f2e896e4f19 100644 --- a/src/components/SelectionList/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionList/Search/TransactionGroupListItem.tsx @@ -1,5 +1,6 @@ import React, {useMemo} from 'react'; import {View} from 'react-native'; +import type {OnyxCollection} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {SearchGroupBy} from '@components/Search/types'; import BaseListItem from '@components/SelectionList/BaseListItem'; @@ -27,6 +28,8 @@ import {setActiveTransactionThreadIDs} from '@userActions/TransactionThreadNavig import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Policy} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import CardListItemHeader from './CardListItemHeader'; import MemberListItemHeader from './MemberListItemHeader'; import ReportListItemHeader from './ReportListItemHeader'; @@ -48,7 +51,7 @@ function TransactionGroupListItem({ const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true}); + const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true}); const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${groupItem?.policyID}`]; const isEmpty = groupItem.transactions.length === 0; const isDisabledOrEmpty = isEmpty || isDisabled; diff --git a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx index 28c384cbdcb1..02db17743caa 100644 --- a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -23,8 +23,9 @@ import {clearValidateCodeActionError} from '@userActions/User'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {Account} from '@src/types/onyx'; import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; type ValidateCodeFormHandle = { focus: () => void; @@ -112,7 +113,7 @@ function BaseValidateCodeForm({ const [formError, setFormError] = useState({}); const [validateCode, setValidateCode] = useState(''); const inputValidateCodeRef = useRef(null); - const [account = {}] = useOnyx(ONYXKEYS.ACCOUNT, { + const [account = getEmptyObject()] = useOnyx(ONYXKEYS.ACCOUNT, { canBeMissing: true, }); diff --git a/src/hooks/usePaymentOptions.ts b/src/hooks/usePaymentOptions.ts index dac7e9559c77..40dc90c922d9 100644 --- a/src/hooks/usePaymentOptions.ts +++ b/src/hooks/usePaymentOptions.ts @@ -15,8 +15,8 @@ import Navigation from '@navigation/Navigation'; import {isCurrencySupportedForDirectReimbursement} from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {LastPaymentMethodType} from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import type {BankAccountList, FundList, LastPaymentMethodType} from '@src/types/onyx'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; @@ -80,8 +80,8 @@ function usePaymentOptions({ }); const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult); - const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); - const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); + const [bankAccountList = getEmptyObject()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); + const [fundList = getEmptyObject()] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); const lastPaymentMethodRef = useRef(lastPaymentMethod); useEffect(() => { diff --git a/src/hooks/useSearchTypeMenu.tsx b/src/hooks/useSearchTypeMenu.tsx index e8668329043b..4354b0e06f45 100644 --- a/src/hooks/useSearchTypeMenu.tsx +++ b/src/hooks/useSearchTypeMenu.tsx @@ -1,5 +1,6 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {InteractionManager} from 'react-native'; +import type {OnyxCollection} from 'react-native-onyx'; import {usePersonalDetails} from '@components/OnyxProvider'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import type {SearchQueryJSON} from '@components/Search/types'; @@ -16,6 +17,8 @@ import * as Expensicons from '@src/components/Icon/Expensicons'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Report} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import useDeleteSavedSearch from './useDeleteSavedSearch'; import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; @@ -35,7 +38,7 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) { const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const personalDetails = usePersonalDetails(); - const [reports = {}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); + const [reports = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); const taxRates = getAllTaxRates(); const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true}); diff --git a/src/hooks/useTransactionViolations.ts b/src/hooks/useTransactionViolations.ts index 2596046763e2..ebd601243552 100644 --- a/src/hooks/useTransactionViolations.ts +++ b/src/hooks/useTransactionViolations.ts @@ -1,14 +1,15 @@ import {useMemo} from 'react'; import {isViolationDismissed} from '@libs/TransactionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {TransactionViolations} from '@src/types/onyx'; +import type {TransactionViolation, TransactionViolations} from '@src/types/onyx'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import useOnyx from './useOnyx'; function useTransactionViolations(transactionID?: string): TransactionViolations { const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, { canBeMissing: true, }); - const [transactionViolations = []] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, { + const [transactionViolations = getEmptyArray()] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, { canBeMissing: true, }); diff --git a/src/hooks/useTripTransactions.ts b/src/hooks/useTripTransactions.ts index b235e3ace089..bf15ec0876fe 100644 --- a/src/hooks/useTripTransactions.ts +++ b/src/hooks/useTripTransactions.ts @@ -1,5 +1,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Transaction} from '@src/types/onyx'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import useOnyx from './useOnyx'; /** @@ -13,13 +14,13 @@ import useOnyx from './useOnyx'; * @returns Transactions linked to the specified trip room. */ function useTripTransactions(reportID: string | undefined): Transaction[] { - const [tripTransactionReportIDs = []] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { + const [tripTransactionReportIDs = getEmptyArray()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { selector: (reports) => Object.values(reports ?? {}) .filter((report) => report && report.chatReportID === reportID) .map((report) => report?.reportID), }); - const [tripTransactions = []] = useOnyx( + const [tripTransactions = getEmptyArray()] = useOnyx( ONYXKEYS.COLLECTION.TRANSACTION, { selector: (transactions) => { diff --git a/src/pages/AddUnreportedExpense.tsx b/src/pages/AddUnreportedExpense.tsx index c874041992e6..8b2f1500bce8 100644 --- a/src/pages/AddUnreportedExpense.tsx +++ b/src/pages/AddUnreportedExpense.tsx @@ -27,6 +27,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type Transaction from '@src/types/onyx/Transaction'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import NewChatSelectorPage from './NewChatSelectorPage'; import UnreportedExpenseListItem from './UnreportedExpenseListItem'; @@ -52,7 +53,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { return Object.values(transactions || {}).filter((item) => item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === ''); } - const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { + const [transactions = getEmptyArray()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => getUnreportedTransactions(_transactions), canBeMissing: true, }); diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 006fbdd88381..683bb4956a74 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -25,6 +25,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {OnboardingPurpose} from '@src/types/onyx'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type {BaseOnboardingPurposeProps} from './types'; @@ -63,7 +64,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro const paddingHorizontal = onboardingIsMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5; - const [customChoices = []] = useOnyx(ONYXKEYS.ONBOARDING_CUSTOM_CHOICES, {canBeMissing: true}); + const [customChoices = getEmptyArray()] = useOnyx(ONYXKEYS.ONBOARDING_CUSTOM_CHOICES, {canBeMissing: true}); const onboardingChoices = getOnboardingChoices(customChoices); diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 7a37ad63b59b..cc078c2e0d0c 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -36,10 +36,10 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {SearchAdvancedFiltersForm} from '@src/types/form'; import {DATE_FILTER_KEYS} from '@src/types/form/SearchAdvancedFiltersForm'; -import type {CardList, PersonalDetailsList, Policy, PolicyTagLists, Report, WorkspaceCardsList} from '@src/types/onyx'; +import type {CardList, PersonalDetailsList, Policy, PolicyCategories, PolicyTagLists, Report, WorkspaceCardsList} from '@src/types/onyx'; import type {PolicyFeatureName} from '@src/types/onyx/Policy'; import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; type SectionType = { titleTranslationKey: TranslationPaths; @@ -536,7 +536,7 @@ function AdvancedSearchFilters() { const waitForNavigate = useWaitForNavigation(); const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true}); - const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true}); + const [searchAdvancedFilters = getEmptyObject()] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true}); const groupBy = searchAdvancedFilters.groupBy; const policyID = searchAdvancedFilters.policyID; @@ -546,8 +546,8 @@ function AdvancedSearchFilters() { const taxRates = getAllTaxRates(); const personalDetails = usePersonalDetails(); - const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); - const [allPolicyCategories = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, { + const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); + const [allPolicyCategories = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, { canBeMissing: false, selector: (policyCategories) => Object.fromEntries( @@ -558,7 +558,7 @@ function AdvancedSearchFilters() { ), }); const singlePolicyCategories = allPolicyCategories[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]; - const [allPolicyTagLists = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: false}); + const [allPolicyTagLists = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: false}); const singlePolicyTagLists = allPolicyTagLists[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`]; const tagListsUnpacked = Object.values(allPolicyTagLists ?? {}) .filter((item): item is NonNullable => !!item) diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx index 7cddf2a3ae43..5598c0b285b0 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage.tsx @@ -1,5 +1,6 @@ import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; +import type {OnyxCollection} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SearchMultipleSelectionPicker from '@components/Search/SearchMultipleSelectionPicker'; @@ -13,6 +14,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {PolicyTagLists} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; function SearchFiltersTagPage() { const styles = useThemeStyles(); @@ -26,7 +28,7 @@ function SearchFiltersTagPage() { return {name: getCleanedTagName(tag), value: tag}; }); const policyID = searchAdvancedFiltersForm?.policyID; - const [allPolicyTagLists = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: true}); + const [allPolicyTagLists = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: true}); const singlePolicyTagLists = allPolicyTagLists[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`]; const tagItems = useMemo(() => { diff --git a/src/pages/Search/SearchMoneyRequestReportPage.tsx b/src/pages/Search/SearchMoneyRequestReportPage.tsx index 9546883813a0..359e731d2b2e 100644 --- a/src/pages/Search/SearchMoneyRequestReportPage.tsx +++ b/src/pages/Search/SearchMoneyRequestReportPage.tsx @@ -2,6 +2,7 @@ import {PortalHost} from '@gorhom/portal'; import React, {useEffect, useMemo, useRef, useState} from 'react'; import type {FlatList} from 'react-native'; import {View} from 'react-native'; +import type {OnyxCollection} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import DragAndDropProvider from '@components/DragAndDrop/Provider'; import MoneyRequestReportView from '@components/MoneyRequestReportView/MoneyRequestReportView'; @@ -21,6 +22,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {ActionListContextType, ScrollPosition} from '@src/pages/home/ReportScreenContext'; import {ActionListContext} from '@src/pages/home/ReportScreenContext'; import type SCREENS from '@src/SCREENS'; +import type {Policy} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; type SearchMoneyRequestPageProps = PlatformStackScreenProps; @@ -40,7 +43,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) { const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID); const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true, allowStaleData: true}); - const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); + const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 82e5dfe08b3c..00497d0fc21e 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -54,7 +54,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {SearchResults, Transaction} from '@src/types/onyx'; +import type {LastPaymentMethod, SearchResults, Transaction} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import SearchPageNarrow from './SearchPageNarrow'; type SearchPageProps = PlatformStackScreenProps; @@ -70,7 +71,7 @@ function SearchPage({route}: SearchPageProps) { const {selectedTransactions, clearSelectedTransactions, selectedReports, lastSearchType, setLastSearchType, isExportMode, setExportMode} = useSearchContext(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [selectionMode] = useOnyx(ONYXKEYS.MOBILE_SELECTION_MODE, {canBeMissing: true}); - const [lastPaymentMethods = {}] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true}); + const [lastPaymentMethods = getEmptyObject()] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true}); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false}); const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 0080874a2fca..476ff0b5181f 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -4,7 +4,7 @@ import {deepEqual} from 'fast-equals'; import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'; import type {FlatList, ViewStyle} from 'react-native'; import {DeviceEventEmitter, InteractionManager, View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Banner from '@components/Banner'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import DragAndDropProvider from '@components/DragAndDrop/Provider'; @@ -86,7 +86,7 @@ import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import HeaderView from './HeaderView'; import ReactionListWrapper from './ReactionListWrapper'; import ReportActionsView from './report/ReportActionsView'; @@ -155,7 +155,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const [reportOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportNameValuePairsOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true}); const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true, allowStaleData: true}); - const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); + const [policies = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false}); const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportOnyx?.parentReportID)}`, { canEvict: false, selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID), @@ -303,7 +303,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) { }); const reportTransactionIDs = reportTransactions?.map((transaction) => transaction.transactionID); const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, reportActions ?? [], isOffline, reportTransactionIDs); - const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, {canBeMissing: true}); + const [transactionThreadReportActions = getEmptyObject()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, { + canBeMissing: true, + }); const combinedReportActions = getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions)); const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => canEditReportAction(action) && !isMoneyRequestAction(action)); const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; diff --git a/src/pages/iou/request/step/IOURequestStepScan/ReceiptViewModal/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/ReceiptViewModal/index.tsx index 9b38067cbe87..45be73b1118b 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/ReceiptViewModal/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/ReceiptViewModal/index.tsx @@ -18,6 +18,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import type {Receipt} from '@src/types/onyx/Transaction'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; type ReceiptWithTransactionIDAndSource = Receipt & ReceiptFile; @@ -40,7 +41,7 @@ function ReceiptViewModal({route}: ReceiptViewModalProps) { const [page, setPage] = useState(-1); const [isDeleteReceiptConfirmModalVisible, setIsDeleteReceiptConfirmModalVisible] = useState(false); - const [receipts = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, { + const [receipts = getEmptyArray()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, { selector: (items) => Object.values(items ?? {}) .map((transaction) => (transaction?.receipt ? {...transaction?.receipt, transactionID: transaction.transactionID} : undefined)) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 804335e8d50a..c9f97fe81d97 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -36,6 +36,7 @@ import {readFileAsync, showCameraPermissionsAlert} from '@libs/fileDownload/File import getPhotoSource from '@libs/fileDownload/getPhotoSource'; import getCurrentPosition from '@libs/getCurrentPosition'; import getPlatform from '@libs/getPlatform'; +import type Platform from '@libs/getPlatform/types'; import getReceiptsUploadFolderPath from '@libs/getReceiptsUploadFolderPath'; import HapticFeedback from '@libs/HapticFeedback'; import {navigateToParticipantPage, shouldStartLocationPermissionFlow} from '@libs/IOUUtils'; @@ -70,6 +71,7 @@ import type {Policy} from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import type Transaction from '@src/types/onyx/Transaction'; import type {Receipt} from '@src/types/onyx/Transaction'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; import CameraPermission from './CameraPermission'; import NavigationAwareCamera from './NavigationAwareCamera/Camera'; import ReceiptPreviews from './ReceiptPreviews'; @@ -110,7 +112,7 @@ function IOURequestStepScan({ const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true}); const [dismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true}); const platform = getPlatform(true); - const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS, {canBeMissing: true}); + const [mutedPlatforms = getEmptyObject>>()] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS, {canBeMissing: true}); const isPlatformMuted = mutedPlatforms[platform]; const [cameraPermissionStatus, setCameraPermissionStatus] = useState(null); const [didCapturePhoto, setDidCapturePhoto] = useState(false); diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index c4274e2375e2..5ecbe872dcb1 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -17,18 +17,20 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {togglePlatformMute, updateNewsletterSubscription} from '@libs/actions/User'; import {getCurrencySymbol} from '@libs/CurrencyUtils'; import getPlatform from '@libs/getPlatform'; +import type Platform from '@libs/getPlatform/types'; import Navigation from '@libs/Navigation/Navigation'; import {getPersonalPolicy} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import {isFullySupportedLocale, LOCALE_TO_LANGUAGE_STRING} from '@src/CONST/LOCALES'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; function PreferencesPage() { const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true}); const platform = getPlatform(true); - const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS, {canBeMissing: true}); + const [mutedPlatforms = getEmptyObject>>()] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS, {canBeMissing: true}); const isPlatformMuted = mutedPlatforms[platform]; const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME, {canBeMissing: true}); diff --git a/src/pages/settings/Wallet/ActivatePhysicalCardPage.tsx b/src/pages/settings/Wallet/ActivatePhysicalCardPage.tsx index ddcfd3dbcfdf..0757707b4e85 100644 --- a/src/pages/settings/Wallet/ActivatePhysicalCardPage.tsx +++ b/src/pages/settings/Wallet/ActivatePhysicalCardPage.tsx @@ -24,7 +24,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import type {CardList} from '@src/types/onyx'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; type ActivatePhysicalCardPageProps = PlatformStackScreenProps; @@ -41,7 +42,7 @@ function ActivatePhysicalCardPage({ const {isExtraSmallScreenHeight} = useResponsiveLayout(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); - const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST); + const [cardList = getEmptyObject()] = useOnyx(ONYXKEYS.CARD_LIST); const [formError, setFormError] = useState(''); const [lastFourDigits, setLastFourDigits] = useState(''); diff --git a/src/pages/settings/Wallet/PaymentMethodList.tsx b/src/pages/settings/Wallet/PaymentMethodList.tsx index 9a24497f3879..0d81d4d66b3c 100644 --- a/src/pages/settings/Wallet/PaymentMethodList.tsx +++ b/src/pages/settings/Wallet/PaymentMethodList.tsx @@ -29,12 +29,12 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {AccountData, Card, CompanyCardFeed} from '@src/types/onyx'; +import type {AccountData, BankAccountList, Card, CardList, CompanyCardFeed} from '@src/types/onyx'; import type {BankIcon} from '@src/types/onyx/Bank'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import type PaymentMethod from '@src/types/onyx/PaymentMethod'; import type {FilterMethodPaymentType} from '@src/types/onyx/WalletTransfer'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; type PaymentMethodPressHandler = ( @@ -200,13 +200,13 @@ function PaymentMethodList({ const illustrations = useThemeIllustrations(); const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true}); - const [bankAccountList = {}, bankAccountListResult] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); + const [bankAccountList = getEmptyObject(), bankAccountListResult] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: true}); const isLoadingBankAccountList = isLoadingOnyxValue(bankAccountListResult); - const [cardList = {}, cardListResult] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); + const [cardList = getEmptyObject(), cardListResult] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); const isLoadingCardList = isLoadingOnyxValue(cardListResult); // Temporarily disabled because P2P debit cards are disabled. - // const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST); + // const [fundList = getEmptyObject()] = useOnyx(ONYXKEYS.FUND_LIST); const [isLoadingPaymentMethods = true, isLoadingPaymentMethodsResult] = useOnyx(ONYXKEYS.IS_LOADING_PAYMENT_METHODS, {canBeMissing: true}); const isLoadingPaymentMethodsOnyx = isLoadingOnyxValue(isLoadingPaymentMethodsResult); diff --git a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx index 5c61c8d5c3e4..ce3e14c06ff4 100644 --- a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx +++ b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx @@ -48,7 +48,8 @@ import {clearWalletError, clearWalletTermsError, deletePaymentCard, makeDefaultP import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {AccountData, Card} from '@src/types/onyx'; +import type * as OnyxTypes from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; type WalletPageProps = { /** Listen for window resize event on web and desktop. */ @@ -56,12 +57,12 @@ type WalletPageProps = { }; function WalletPage({shouldListenForResize = false}: WalletPageProps) { - const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); - const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); - const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); + const [bankAccountList = getEmptyObject()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true}); + const [cardList = getEmptyObject()] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); + const [fundList = getEmptyObject()] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); const [isLoadingPaymentMethods = true] = useOnyx(ONYXKEYS.IS_LOADING_PAYMENT_METHODS, {canBeMissing: true}); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: true}); - const [walletTerms = {}] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true}); + const [walletTerms = getEmptyObject()] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true}); const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false}); const [userAccount] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true}); const isUserValidated = userAccount?.validated ?? false; @@ -140,7 +141,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) { const paymentMethodPressed = ( nativeEvent?: GestureResponderEvent | KeyboardEvent, accountType?: string, - account?: AccountData, + account?: OnyxTypes.AccountData, icon?: FormattedSelectedPaymentMethodIcon, isDefault?: boolean, methodID?: string | number, @@ -200,7 +201,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) { setMenuPosition(); }; - const assignedCardPressed = (nativeEvent?: GestureResponderEvent | KeyboardEvent, cardData?: Card, icon?: FormattedSelectedPaymentMethodIcon, cardID?: number) => { + const assignedCardPressed = (nativeEvent?: GestureResponderEvent | KeyboardEvent, cardData?: OnyxTypes.Card, icon?: FormattedSelectedPaymentMethodIcon, cardID?: number) => { if (shouldShowAddPaymentMenu) { setShouldShowAddPaymentMenu(false); return; diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index c7b2f3f7a6ca..ccddac958a1b 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -26,6 +26,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Account, Credentials} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; import ChooseSSOOrMagicCode from './ChooseSSOOrMagicCode'; import EmailDeliveryFailurePage from './EmailDeliveryFailurePage'; import LoginForm from './LoginForm'; @@ -163,7 +164,7 @@ function SignInPage({shouldEnableMaxHeight = true}: SignInPageInnerProps, ref: F every time the leader client changes. We use that function to prevent repeating code that checks which client is the leader. */ - const [activeClients = []] = useOnyx(ONYXKEYS.ACTIVE_CLIENTS, {canBeMissing: true}); + const [activeClients = getEmptyArray()] = useOnyx(ONYXKEYS.ACTIVE_CLIENTS, {canBeMissing: true}); const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {canBeMissing: true}); /** This state is needed to keep track of if user is using recovery code instead of 2fa code, diff --git a/src/pages/workspace/WorkspaceOverviewPage.tsx b/src/pages/workspace/WorkspaceOverviewPage.tsx index c09964d5cc7e..11fd87e1c321 100644 --- a/src/pages/workspace/WorkspaceOverviewPage.tsx +++ b/src/pages/workspace/WorkspaceOverviewPage.tsx @@ -45,7 +45,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import type {CurrencyList} from '@src/types/onyx'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import type {WithPolicyProps} from './withPolicy'; import withPolicy from './withPolicy'; import WorkspacePageWithSections from './WorkspacePageWithSections'; @@ -59,7 +60,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa const illustrations = useThemeIllustrations(); const backTo = route.params.backTo; - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, { selector: (session) => session?.accountID, canBeMissing: true, diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx index 85c04b7f694b..28b4dd07e725 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx @@ -36,7 +36,8 @@ import {setAddNewCompanyCardStepAndData, setAssignCardStepAndData} from '@userAc import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {CompanyCardFeed} from '@src/types/onyx'; +import type {CompanyCardFeed, CurrencyList} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; type WorkspaceCompanyCardsListHeaderButtonsProps = { /** Current policy id */ @@ -63,7 +64,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed, shouldS const [cardFeeds] = useCardFeeds(policyID); const policy = usePolicy(policyID); const [allFeedsCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`, {canBeMissing: false}); - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const [countryByIp] = useOnyx(ONYXKEYS.COUNTRY, {canBeMissing: false}); const shouldChangeLayout = isMediumScreenWidth || shouldUseNarrowLayout; const formattedFeedName = getCustomOrFormattedFeedName(selectedFeed, cardFeeds?.settings?.companyCardNicknames); diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx index 5b1cdd6effcc..e1f1629c350d 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx @@ -36,8 +36,9 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import type {CurrencyList} from '@src/types/onyx'; import type {AssignCardData, AssignCardStep} from '@src/types/onyx/AssignCard'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import WorkspaceCompanyCardPageEmptyState from './WorkspaceCompanyCardPageEmptyState'; import WorkspaceCompanyCardsFeedPendingPage from './WorkspaceCompanyCardsFeedPendingPage'; import WorkspaceCompanyCardsList from './WorkspaceCompanyCardsList'; @@ -57,7 +58,7 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) { const selectedFeed = getSelectedFeed(lastSelectedFeed, cardFeeds); const [cardsList] = useCardsList(policyID, selectedFeed); const [countryByIp] = useOnyx(ONYXKEYS.COUNTRY, {canBeMissing: false}); - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const hasNoAssignedCard = Object.keys(cardsList ?? {}).length === 0; diff --git a/src/pages/workspace/companyCards/addNew/SelectCountryStep.tsx b/src/pages/workspace/companyCards/addNew/SelectCountryStep.tsx index f01d4257b85e..b4769b6bc144 100644 --- a/src/pages/workspace/companyCards/addNew/SelectCountryStep.tsx +++ b/src/pages/workspace/companyCards/addNew/SelectCountryStep.tsx @@ -24,6 +24,8 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; +import type {CurrencyList} from '@src/types/onyx'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; type CountryStepProps = { policyID?: string; @@ -34,7 +36,7 @@ function SelectCountryStep({policyID}: CountryStepProps) { const route = useRoute>(); const styles = useThemeStyles(); const policy = usePolicy(policyID); - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const [countryByIp] = useOnyx(ONYXKEYS.COUNTRY, {canBeMissing: false}); const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: true}); diff --git a/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx b/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx index 3bca5807c581..0b6b3859e404 100644 --- a/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx +++ b/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx @@ -22,8 +22,9 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import type {CompanyCardFeed} from '@src/types/onyx'; +import type {CompanyCardFeed, CurrencyList} from '@src/types/onyx'; import type {AssignCardStep} from '@src/types/onyx/AssignCard'; +import {getEmptyObject} from '@src/types/utils/EmptyObject'; type ConfirmationStepProps = { /** Current policy id */ @@ -41,7 +42,7 @@ function ConfirmationStep({policyID, backTo}: ConfirmationStepProps) { const [assignCard] = useOnyx(ONYXKEYS.ASSIGN_CARD, {canBeMissing: false}); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: false}); const [countryByIp] = useOnyx(ONYXKEYS.COUNTRY, {canBeMissing: false}); - const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); + const [currencyList = getEmptyObject()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true}); const feed = assignCard?.data?.bankName as CompanyCardFeed | undefined; const [cardFeeds] = useCardFeeds(policyID); diff --git a/src/types/utils/EmptyObject.ts b/src/types/utils/EmptyObject.ts index 1d2a2ed6baec..8774d515a8e2 100644 --- a/src/types/utils/EmptyObject.ts +++ b/src/types/utils/EmptyObject.ts @@ -1,3 +1,5 @@ +import CONST from '@src/CONST'; + type EmptyObject = Record; type EmptyValue = EmptyObject | null | undefined; @@ -6,5 +8,9 @@ function isEmptyObject(obj: T | EmptyValue): obj is EmptyValue { return Object.keys(obj ?? {}).length === 0; } -export {isEmptyObject}; +function getEmptyObject(): T { + return CONST.EMPTY_OBJECT as T; +} + +export {isEmptyObject, getEmptyObject}; export type {EmptyObject}; diff --git a/src/types/utils/getEmptyArray.ts b/src/types/utils/getEmptyArray.ts new file mode 100644 index 000000000000..2933684bb04a --- /dev/null +++ b/src/types/utils/getEmptyArray.ts @@ -0,0 +1,7 @@ +import CONST from '@src/CONST'; + +function getEmptyArray(): T[] { + return CONST.EMPTY_ARRAY as unknown as T[]; +} + +export default getEmptyArray; From 2e1bd9f448d8820903587cf5c3fd7507025585b1 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 8 Jul 2025 16:19:08 +0200 Subject: [PATCH 4/7] Minor improvement --- .../MoneyRequestReportTransactionsNavigation.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx index c933e04678f1..1dd4ad4ede4c 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx @@ -5,17 +5,17 @@ import useOnyx from '@hooks/useOnyx'; import {clearActiveTransactionThreadIDs} from '@libs/actions/TransactionThreadNavigation'; import Navigation from '@navigation/Navigation'; import navigationRef from '@navigation/navigationRef'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +import getEmptyArray from '@src/types/utils/getEmptyArray'; type MoneyRequestReportRHPNavigationButtonsProps = { currentReportID: string; }; function MoneyRequestReportTransactionsNavigation({currentReportID}: MoneyRequestReportRHPNavigationButtonsProps) { - const [reportIDsList = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, { + const [reportIDsList = getEmptyArray()] = useOnyx(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, { canBeMissing: true, }); From d9230b1ece7c6185969b1dc45efd03ff2ab50d1e Mon Sep 17 00:00:00 2001 From: VickyStash Date: Tue, 8 Jul 2025 17:11:34 +0200 Subject: [PATCH 5/7] Remove unnecessary default value --- src/components/MoneyReportHeader.tsx | 2 +- src/components/MoneyRequestHeader.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index a8a69efb1f2a..bda1f8fb8893 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -175,7 +175,7 @@ function MoneyReportHeader({ const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${isMoneyRequestAction(requestParentReportAction) && getOriginalMessage(requestParentReportAction)?.IOUTransactionID}`, { canBeMissing: true, }); - const [dismissedHoldUseExplanation = true, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: true}); + const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: true}); const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult); const [invoiceReceiverPolicy] = useOnyx( `${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`, diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 1b1b581f0b20..7717abcd2d3b 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -82,7 +82,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const [downloadErrorModalVisible, setDownloadErrorModalVisible] = useState(false); - const [dismissedHoldUseExplanation = true, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: false}); + const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: false}); const shouldShowLoadingBar = useLoadingBarVisibility(); const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult); const styles = useThemeStyles(); From badced379123d58e77797b3845b14a586dc686e2 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 9 Jul 2025 10:16:05 +0200 Subject: [PATCH 6/7] Fix useOnyx import --- .../ReportActionCompose/SilentCommentUpdater/index.android.tsx | 2 +- .../report/ReportActionCompose/SilentCommentUpdater/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx index 26b0d4095113..b64672b28f9f 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.android.tsx @@ -1,5 +1,5 @@ import {useEffect} from 'react'; -import {useOnyx} from 'react-native-onyx'; +import useOnyx from '@hooks/useOnyx'; import ONYXKEYS from '@src/ONYXKEYS'; import type SilentCommentUpdaterProps from './types'; diff --git a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx index 50e46748cc50..38063912becf 100644 --- a/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx +++ b/src/pages/home/report/ReportActionCompose/SilentCommentUpdater/index.tsx @@ -1,6 +1,6 @@ import {useEffect} from 'react'; -import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; +import useOnyx from '@hooks/useOnyx'; import usePrevious from '@hooks/usePrevious'; import ONYXKEYS from '@src/ONYXKEYS'; import type SilentCommentUpdaterProps from './types'; From a773a37f4a9ec7b67a98869544a05bc7b6417407 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 9 Jul 2025 15:35:12 +0200 Subject: [PATCH 7/7] Remove unused imports --- src/pages/Search/SearchPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index be83e0378cd1..3d66d5646bf1 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -55,8 +55,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {LastPaymentMethod, SearchResults, Transaction} from '@src/types/onyx'; -import {getEmptyObject} from '@src/types/utils/EmptyObject'; +import type {SearchResults, Transaction} from '@src/types/onyx'; import SearchPageNarrow from './SearchPageNarrow'; type SearchPageProps = PlatformStackScreenProps;