diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 0a21cb17df7e..d6d08211a79e 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -291,6 +291,9 @@ const ONYXKEYS = { /** Indicates whether an forced upgrade is required */ UPDATE_REQUIRED: 'updateRequired', + /** Indicates whether an forced reset is required. Used in emergency situations where we must completely erase the Onyx data in the client because it is in a bad state. This will clear Oynx data without signing the user out. */ + RESET_REQUIRED: 'resetRequired', + /** Stores the logs of the app for debugging purposes */ LOGS: 'logs', @@ -638,6 +641,7 @@ type OnyxValuesMapping = { [ONYXKEYS.LAST_VISITED_PATH]: string | undefined; [ONYXKEYS.RECENTLY_USED_REPORT_FIELDS]: OnyxTypes.RecentlyUsedReportFields; [ONYXKEYS.UPDATE_REQUIRED]: boolean; + [ONYXKEYS.RESET_REQUIRED]: boolean; [ONYXKEYS.PLAID_CURRENT_EVENT]: string; [ONYXKEYS.LOGS]: OnyxTypes.CapturedLogs; [ONYXKEYS.SHOULD_STORE_LOGS]: boolean; diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 11bbc5c12f53..ba2ea750542e 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -26,6 +26,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as SessionUtils from '@libs/SessionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {OnyxKey} from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; @@ -77,6 +78,38 @@ Onyx.connect({ }, }); +const KEYS_TO_PRESERVE: OnyxKey[] = [ + ONYXKEYS.ACCOUNT, + ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, + ONYXKEYS.IS_LOADING_APP, + ONYXKEYS.IS_SIDEBAR_LOADED, + ONYXKEYS.MODAL, + ONYXKEYS.NETWORK, + ONYXKEYS.SESSION, + ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, + ONYXKEYS.NVP_TRY_FOCUS_MODE, + ONYXKEYS.PREFERRED_THEME, + ONYXKEYS.NVP_PREFERRED_LOCALE, + ONYXKEYS.CREDENTIALS, +]; + +Onyx.connect({ + key: ONYXKEYS.RESET_REQUIRED, + callback: (isResetRequired) => { + if (!isResetRequired) { + return; + } + + Onyx.clear(KEYS_TO_PRESERVE).then(() => { + // Set this to false to reset the flag for this client + Onyx.set(ONYXKEYS.RESET_REQUIRED, false); + + // eslint-disable-next-line @typescript-eslint/no-use-before-define + openApp(); + }); + }, +}); + let resolveIsReadyPromise: () => void; const isReadyToOpenApp = new Promise((resolve) => { resolveIsReadyPromise = resolve; @@ -527,4 +560,5 @@ export { savePolicyDraftByNewWorkspace, createWorkspaceWithPolicyDraftAndNavigateToIt, updateLastVisitedPath, + KEYS_TO_PRESERVE, }; diff --git a/src/pages/settings/AboutPage/TroubleshootPage.tsx b/src/pages/settings/AboutPage/TroubleshootPage.tsx index 0e192540ebd2..5d4d85a68d24 100644 --- a/src/pages/settings/AboutPage/TroubleshootPage.tsx +++ b/src/pages/settings/AboutPage/TroubleshootPage.tsx @@ -22,25 +22,9 @@ import * as App from '@userActions/App'; import * as Report from '@userActions/Report'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {OnyxKey} from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -const keysToPreserve: OnyxKey[] = [ - ONYXKEYS.ACCOUNT, - ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, - ONYXKEYS.IS_LOADING_APP, - ONYXKEYS.IS_SIDEBAR_LOADED, - ONYXKEYS.MODAL, - ONYXKEYS.NETWORK, - ONYXKEYS.SESSION, - ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, - ONYXKEYS.NVP_TRY_FOCUS_MODE, - ONYXKEYS.PREFERRED_THEME, - ONYXKEYS.NVP_PREFERRED_LOCALE, - ONYXKEYS.CREDENTIALS, -]; - type BaseMenuItem = { translationKey: TranslationPaths; icon: React.FC; @@ -128,7 +112,7 @@ function TroubleshootPage({shouldStoreLogs}: TroubleshootPageProps) { isVisible={isConfirmationModalVisible} onConfirm={() => { setIsConfirmationModalVisible(false); - Onyx.clear(keysToPreserve).then(() => { + Onyx.clear(App.KEYS_TO_PRESERVE).then(() => { App.openApp(); }); }}