From 115d69ecd2a037c95d58a8b0d6f1bf9c666d0c74 Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:37:33 +0100 Subject: [PATCH 1/8] hide pending deleted workspace from change workspace list --- src/hooks/useWorkspaceList.ts | 8 ++++---- src/pages/ReportChangeWorkspacePage.tsx | 2 +- src/pages/WorkspaceSwitcherPage/index.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hooks/useWorkspaceList.ts b/src/hooks/useWorkspaceList.ts index ed7dbb2e6c82..5aefb6ab4f7a 100644 --- a/src/hooks/useWorkspaceList.ts +++ b/src/hooks/useWorkspaceList.ts @@ -19,7 +19,7 @@ type WorkspaceListItem = { type UseWorkspaceListParams = { policies: OnyxCollection; currentUserLogin: string | undefined; - isOffline: boolean; + shouldShowPendingDeletePolicy: boolean; selectedPolicyID: string | undefined; searchTerm: string; additionalFilter?: (policy: OnyxEntry) => boolean; @@ -41,7 +41,7 @@ function useWorkspaceList({ currentUserLogin, selectedPolicyID, searchTerm, - isOffline, + shouldShowPendingDeletePolicy, isWorkspaceSwitcher = false, hasUnreadData, getIndicatorTypeForPolicy, @@ -53,7 +53,7 @@ function useWorkspaceList({ } return Object.values(policies) - .filter((policy) => !!policy && shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending && (additionalFilter ? additionalFilter(policy) : true)) + .filter((policy) => !!policy && shouldShowPolicy(policy, shouldShowPendingDeletePolicy, currentUserLogin) && !policy?.isJoinRequestPending && (additionalFilter ? additionalFilter(policy) : true)) .map((policy) => ({ text: policy?.name ?? '', policyID: policy?.id, @@ -76,7 +76,7 @@ function useWorkspaceList({ brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id), }), })); - }, [policies, isOffline, currentUserLogin, additionalFilter, selectedPolicyID, getIndicatorTypeForPolicy, hasUnreadData, isWorkspaceSwitcher]); + }, [policies, shouldShowPendingDeletePolicy, currentUserLogin, additionalFilter, selectedPolicyID, getIndicatorTypeForPolicy, hasUnreadData, isWorkspaceSwitcher]); const filteredAndSortedUserWorkspaces = useMemo( () => diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index d07ed20513a4..978225ec92e1 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -51,7 +51,7 @@ function ReportChangeWorkspacePage({report}: ReportChangeWorkspacePageProps) { const {sections, shouldShowNoResultsFoundMessage, shouldShowSearchInput} = useWorkspaceList({ policies, currentUserLogin, - isOffline, + shouldShowPendingDeletePolicy: false, selectedPolicyID: report.policyID, searchTerm: debouncedSearchTerm, additionalFilter: (newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, oldPolicy, currentUserLogin), diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index a18a50073ceb..a63fa0fa6261 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -70,7 +70,7 @@ function WorkspaceSwitcherPage() { const {sections, shouldShowNoResultsFoundMessage, shouldShowSearchInput, shouldShowCreateWorkspace} = useWorkspaceList({ policies, - isOffline, + shouldShowPendingDeletePolicy: !!isOffline, currentUserLogin, selectedPolicyID: activeWorkspaceID, searchTerm: debouncedSearchTerm, From a10d9634678cf1a4e1707991c98a9f06a9436e4d Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 17:21:54 +0100 Subject: [PATCH 2/8] show a not found page for transaction thread --- src/pages/ReportChangeWorkspacePage.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 978225ec92e1..738ed362ff13 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -16,9 +16,11 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportChangeWorkspaceNavigatorParamList} from '@libs/Navigation/types'; import {isWorkspaceEligibleForReportChange} from '@libs/PolicyUtils'; +import {isExpenseReport} from '@libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import NotFoundPage from './ErrorPage/NotFoundPage'; import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound'; import withReportOrNotFound from './home/report/withReportOrNotFound'; @@ -57,6 +59,10 @@ function ReportChangeWorkspacePage({report}: ReportChangeWorkspacePageProps) { additionalFilter: (newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, oldPolicy, currentUserLogin), }); + if (!isExpenseReport(report)) { + return ; + } + return ( Date: Sun, 16 Mar 2025 17:23:34 +0100 Subject: [PATCH 3/8] Show not found page in the case of pending deletion report --- src/pages/ReportChangeWorkspacePage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 738ed362ff13..7d71d392af0f 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -16,7 +16,7 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportChangeWorkspaceNavigatorParamList} from '@libs/Navigation/types'; import {isWorkspaceEligibleForReportChange} from '@libs/PolicyUtils'; -import {isExpenseReport} from '@libs/ReportUtils'; +import {isExpenseReport, isMoneyRequestReportPendingDeletion} from '@libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; @@ -59,7 +59,7 @@ function ReportChangeWorkspacePage({report}: ReportChangeWorkspacePageProps) { additionalFilter: (newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, oldPolicy, currentUserLogin), }); - if (!isExpenseReport(report)) { + if (!isExpenseReport(report) || isMoneyRequestReportPendingDeletion(report)) { return ; } From 4202218a082235b12a04976a78d6b1c6578064b5 Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 18:33:09 +0100 Subject: [PATCH 4/8] Add error message when moving report fails --- src/libs/actions/Report.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 660926815b25..a12ede0c5f0b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -5042,15 +5042,19 @@ function changeReportPolicy(reportID: string, policyID: string) { key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove.reportID}`, value: { [optimisticMovedReportAction.reportActionID]: { - ...optimisticMovedReportAction, pendingAction: null, + errors: null, }, }, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove.reportID}`, - value: {[optimisticMovedReportAction.reportActionID]: null}, + value: { + [optimisticMovedReportAction.reportActionID]: { + errors: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + }, + }, }); // Call the ChangeReportPolicy API endpoint From ba3a5e1603e9ea5f004326ebb58f75cfbfa380b0 Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 20:51:57 +0100 Subject: [PATCH 5/8] Fix LHN for the old workspace chat after moving the report --- src/libs/actions/Report.ts | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a12ede0c5f0b..e68fbead7a16 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4942,7 +4942,9 @@ function changeReportPolicy(reportID: string, policyID: string) { // 2. If the old workspace had a workspace chat, mark the report preview action as deleted if (reportToMove?.parentReportID && reportToMove?.parentReportActionID) { - const oldReportPreviewAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`]?.[reportToMove?.parentReportActionID]; + const workspaceChatReportID = reportToMove.parentReportID; + const reportPreviewActionID = reportToMove.parentReportActionID; + const oldReportPreviewAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`]?.[reportPreviewActionID]; const deletedTime = DateUtils.getDBTime(); const firstMessage = Array.isArray(oldReportPreviewAction?.message) ? oldReportPreviewAction.message.at(0) : null; const updatedReportPreviewAction = { @@ -4968,13 +4970,40 @@ function changeReportPolicy(reportID: string, policyID: string) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`, - value: {[reportToMove?.parentReportActionID]: updatedReportPreviewAction}, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`, + value: {[reportPreviewActionID]: updatedReportPreviewAction}, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`, - value: {[reportToMove?.parentReportActionID]: oldReportPreviewAction}, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`, + value: {[reportPreviewActionID]: oldReportPreviewAction}, + }); + + // Update the workspace chat report + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`]; + const lastMessageText = getLastVisibleMessage( + workspaceChatReportID, + {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction}, + )?.lastMessageText; + const lastVisibleActionCreated = getReportLastMessage( + workspaceChatReportID, + {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction}, + )?.lastVisibleActionCreated; + + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`, + value: { + hasOutstandingChildRequest: false, + iouReportID: null, + lastMessageText, + lastVisibleActionCreated, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`, + value: chatReport, }); } From 017f8826b353ca7b768002aadeba002f58ee024b Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:13:12 +0100 Subject: [PATCH 6/8] Fix: Trabajo word is cut off --- src/components/ChangeWorkspaceMenuSectionList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ChangeWorkspaceMenuSectionList.tsx b/src/components/ChangeWorkspaceMenuSectionList.tsx index 2e159114264b..2bde7393a33e 100644 --- a/src/components/ChangeWorkspaceMenuSectionList.tsx +++ b/src/components/ChangeWorkspaceMenuSectionList.tsx @@ -46,7 +46,7 @@ function ChangeWorkspaceMenuSectionList() { src={section.icon} additionalStyles={[styles.mr4]} /> - + ${convertToLTR(translate(section.titleTranslationKey))}`} /> From 3335fa26c5af049107d25096e360ba639dc2b71d Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:16:58 +0100 Subject: [PATCH 7/8] prettier --- src/hooks/useWorkspaceList.ts | 8 +++++++- src/libs/actions/Report.ts | 10 ++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hooks/useWorkspaceList.ts b/src/hooks/useWorkspaceList.ts index 5aefb6ab4f7a..2d1a67b69ea3 100644 --- a/src/hooks/useWorkspaceList.ts +++ b/src/hooks/useWorkspaceList.ts @@ -53,7 +53,13 @@ function useWorkspaceList({ } return Object.values(policies) - .filter((policy) => !!policy && shouldShowPolicy(policy, shouldShowPendingDeletePolicy, currentUserLogin) && !policy?.isJoinRequestPending && (additionalFilter ? additionalFilter(policy) : true)) + .filter( + (policy) => + !!policy && + shouldShowPolicy(policy, shouldShowPendingDeletePolicy, currentUserLogin) && + !policy?.isJoinRequestPending && + (additionalFilter ? additionalFilter(policy) : true), + ) .map((policy) => ({ text: policy?.name ?? '', policyID: policy?.id, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e68fbead7a16..0b7fa684de20 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4981,14 +4981,8 @@ function changeReportPolicy(reportID: string, policyID: string) { // Update the workspace chat report const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`]; - const lastMessageText = getLastVisibleMessage( - workspaceChatReportID, - {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction}, - )?.lastMessageText; - const lastVisibleActionCreated = getReportLastMessage( - workspaceChatReportID, - {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction}, - )?.lastVisibleActionCreated; + const lastMessageText = getLastVisibleMessage(workspaceChatReportID, {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction})?.lastMessageText; + const lastVisibleActionCreated = getReportLastMessage(workspaceChatReportID, {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction})?.lastVisibleActionCreated; optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 92aaeb4d313c7ffde9c26e581a0d0d98fc5eef07 Mon Sep 17 00:00:00 2001 From: Rayane <77965000+rayane-d@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:49:22 +0100 Subject: [PATCH 8/8] don't allow a report with 0 total to be moved to another workspace --- src/pages/ReportChangeWorkspacePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 7d71d392af0f..f32299ffc0b8 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -59,7 +59,7 @@ function ReportChangeWorkspacePage({report}: ReportChangeWorkspacePageProps) { additionalFilter: (newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, oldPolicy, currentUserLogin), }); - if (!isExpenseReport(report) || isMoneyRequestReportPendingDeletion(report)) { + if (!isExpenseReport(report) || isMoneyRequestReportPendingDeletion(report) || (!report.total && !report.unheldTotal)) { return ; }