From bb6d159e59a339cbb22ca015b389fe470f3ce684 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 2 Aug 2024 12:55:31 +0800 Subject: [PATCH 1/3] revert avatarURL when delete fails --- src/libs/actions/Policy/Policy.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 1bce525e22bf..9513ac99d82f 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -319,6 +319,7 @@ function deleteWorkspace(policyID: string, policyName: string) { }); }); + const policy = getPolicy(policyID); // Restore the old report stateNum and statusNum const failureData: OnyxUpdate[] = [ { @@ -328,6 +329,13 @@ function deleteWorkspace(policyID: string, policyName: string) { errors: reimbursementAccount?.errors ?? null, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + avatarURL: policy?.avatarURL, + }, + }, ]; reportsToArchive.forEach((report) => { From 639c0d48c8a49f093c8ee46cc47339f49bb86135 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 2 Aug 2024 13:07:28 +0800 Subject: [PATCH 2/3] only show delete workspace button to the owner --- src/pages/workspace/WorkspaceProfilePage.tsx | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/pages/workspace/WorkspaceProfilePage.tsx b/src/pages/workspace/WorkspaceProfilePage.tsx index 1bf3ef068a1b..025cc9587bf6 100644 --- a/src/pages/workspace/WorkspaceProfilePage.tsx +++ b/src/pages/workspace/WorkspaceProfilePage.tsx @@ -4,7 +4,7 @@ import React, {useCallback, useState} from 'react'; import type {ImageStyle, StyleProp} from 'react-native'; import {Image, StyleSheet, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import Avatar from '@components/Avatar'; import AvatarWithImagePicker from '@components/AvatarWithImagePicker'; import Button from '@components/Button'; @@ -55,6 +55,8 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = { const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace(); const {canUseSpotnanaTravel} = usePermissions(); + const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID}); + // When we create a new workspace, the policy prop will be empty on the first render. Therefore, we have to use policyDraft until policy has been set in Onyx. const policy = policyDraft?.id ? policyDraft : policyProp; const outputCurrency = policy?.outputCurrency ?? ''; @@ -84,6 +86,7 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = { }), ); const readOnly = !PolicyUtils.isPolicyAdmin(policy); + const isOwner = PolicyUtils.isPolicyOwner(policy, currentUserAccountID); const imageStyle: StyleProp = shouldUseNarrowLayout ? [styles.mhv12, styles.mhn5, styles.mbn5] : [styles.mhv8, styles.mhn8, styles.mbn5]; const shouldShowAddress = !readOnly || formattedAddress; @@ -270,14 +273,16 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = { medium icon={Expensicons.QrCode} /> -