From fd3dac22f82fbef3c1079589ed5964dac43354b6 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 10 Sep 2024 10:26:18 +0530 Subject: [PATCH 01/70] fix: Distance rates - Enabled distance rate changes to Disabled after deleting it. Signed-off-by: krishna2323 --- src/libs/actions/Policy/Category.ts | 3 ++- src/libs/actions/Policy/Tag.ts | 8 ++++++-- src/libs/actions/TaxRate.ts | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 16d28481f06f..bbaca4104d55 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -790,7 +790,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`] ?? {}; const optimisticPolicyCategoriesData = categoryNamesToDelete.reduce>>((acc, categoryName) => { - acc[categoryName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; + acc[categoryName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false}; return acc; }, {}); const shouldDisableRequiresCategory = !OptionsListUtils.hasEnabledOptions( @@ -822,6 +822,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri acc[categoryName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.deleteFailureMessage'), + enabled: policyCategories?.[categoryName].enabled, }; return acc; }, {}), diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 49a285c12bbe..8441a32ea8d9 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -298,7 +298,7 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { [policyTag.name]: { tags: { ...tagsToDelete.reduce>>>((acc, tagName) => { - acc[tagName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; + acc[tagName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false}; return acc; }, {}), }, @@ -330,7 +330,11 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { [policyTag.name]: { tags: { ...tagsToDelete.reduce>>>((acc, tagName) => { - acc[tagName] = {pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage')}; + acc[tagName] = { + pendingAction: null, + errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage'), + enabled: policyTag?.tags[tagName].enabled, + }; return acc; }, {}), }, diff --git a/src/libs/actions/TaxRate.ts b/src/libs/actions/TaxRate.ts index 514b73915633..179d71743017 100644 --- a/src/libs/actions/TaxRate.ts +++ b/src/libs/actions/TaxRate.ts @@ -275,7 +275,7 @@ function setPolicyTaxesEnabled(policyID: string, taxesIDsToUpdate: string[], isE type TaxRateDeleteMap = Record< string, - | (Pick & { + | (Pick & { errors: OnyxCommon.Errors | null; }) | null @@ -304,7 +304,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) { pendingFields: {foreignTaxDefault: isForeignTaxRemoved ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : null}, foreignTaxDefault: isForeignTaxRemoved ? firstTaxID : foreignTaxDefault, taxes: taxesToDelete.reduce((acc, taxID) => { - acc[taxID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, errors: null}; + acc[taxID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, errors: null, isDisabled: true}; return acc; }, {}), }, @@ -337,6 +337,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) { acc[taxID] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.deleteFailureMessage'), + isDisabled: policyTaxRates?.[taxID].isDisabled, }; return acc; }, {}), From 62e9819f4467a0531e59c267955298df2bd49e17 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 17 Sep 2024 16:12:14 +0200 Subject: [PATCH 02/70] add consts --- src/CONST.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index c00b33be1c31..3d8ca3dc30b4 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5424,6 +5424,7 @@ const CONST = { INITIAL_URL: 'INITIAL_URL', ACTIVE_WORKSPACE_ID: 'ACTIVE_WORKSPACE_ID', RETRY_LAZY_REFRESHED: 'RETRY_LAZY_REFRESHED', + LAST_REFRESH_TIMESTAMP: 'LAST_REFRESH_TIMESTAMP', }, RESERVATION_TYPE: { @@ -5753,6 +5754,9 @@ const CONST = { CATEGORIES_ARTICLE_LINK: 'https://help.expensify.com/articles/expensify-classic/workspaces/Create-categories#import-custom-categories', }, + + // The timeout duration (1 minute) (in milliseconds) before the window reloads due to an error. + ERROR_WINDOW_RELOAD_TIMEOUT: 60000, } as const; type Country = keyof typeof CONST.ALL_COUNTRIES; From de80004ecc5ff296683065809bb27ecfa632b640 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 17 Sep 2024 16:12:47 +0200 Subject: [PATCH 03/70] integrate refresh or reload in GenericErrorPage --- src/pages/ErrorPage/GenericErrorPage.tsx | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/pages/ErrorPage/GenericErrorPage.tsx b/src/pages/ErrorPage/GenericErrorPage.tsx index 9f4186bc354f..4d7c2f649208 100644 --- a/src/pages/ErrorPage/GenericErrorPage.tsx +++ b/src/pages/ErrorPage/GenericErrorPage.tsx @@ -1,3 +1,4 @@ +import differenceInMilliseconds from 'date-fns/differenceInMilliseconds'; import React from 'react'; import {useErrorBoundary} from 'react-error-boundary'; import {View} from 'react-native'; @@ -23,9 +24,27 @@ function GenericErrorPage() { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); - const {resetBoundary} = useErrorBoundary(); + const refresh = () => { + const lastRefreshTimestamp = JSON.parse(sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP) ?? 'null') as string; + + if (lastRefreshTimestamp === null || differenceInMilliseconds(Date.now(), Number(lastRefreshTimestamp)) > CONST.ERROR_WINDOW_RELOAD_TIMEOUT) { + resetBoundary(); + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP, Date.now().toString()); + + return; + } + + window.location.reload(); + sessionStorage.removeItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP); + }; + + const refreshAndSignOut = () => { + Session.signOutAndRedirectToSignIn(); + refresh(); + }; + return ( {({paddingBottom}) => ( @@ -59,16 +78,13 @@ function GenericErrorPage() {