Skip to content

Commit 517ffaa

Browse files
authored
Merge pull request Expensify#50152 from waterim/feat-Delete-workspace-with-card-feed
Feat: Delete workspace with card feed or expensify card
2 parents 273b47e + 4155c32 commit 517ffaa

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

src/languages/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,7 @@ const translations = {
23042304
}),
23052305
settlementFrequency: 'Settlement frequency',
23062306
deleteConfirmation: 'Are you sure you want to delete this workspace?',
2307+
deleteWithCardsConfirmation: 'Are you sure you want to delete this workspace? This will remove all card feeds and assigned cards.',
23072308
unavailable: 'Unavailable workspace',
23082309
memberNotFound: 'Member not found. To invite a new member to the workspace, please use the invite button above.',
23092310
notAuthorized: `You don't have access to this page. If you're trying to join this workspace, just ask the workspace owner to add you as a member. Something else? Reach out to ${CONST.EMAIL.CONCIERGE}.`,

src/languages/es.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,7 @@ const translations = {
23252325
}),
23262326
settlementFrequency: 'Frecuencia de liquidación',
23272327
deleteConfirmation: '¿Estás seguro de que quieres eliminar este espacio de trabajo?',
2328+
deleteWithCardsConfirmation: '¿Estás seguro de que quieres eliminar este espacio de trabajo? Se eliminarán todos los datos de las tarjetas y las tarjetas asignadas.',
23282329
unavailable: 'Espacio de trabajo no disponible',
23292330
memberNotFound: 'Miembro no encontrado. Para invitar a un nuevo miembro al espacio de trabajo, por favor, utiliza el botón invitar que está arriba.',
23302331
notAuthorized: `No tienes acceso a esta página. Si estás intentando unirte a este espacio de trabajo, pide al dueño del espacio de trabajo que te añada como miembro. ¿Necesitas algo más? Comunícate con ${CONST.EMAIL.CONCIERGE}`,

src/pages/workspace/WorkspaceProfilePage.tsx

+13-17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import type {StackScreenProps} from '@react-navigation/stack';
33
import React, {useCallback, useState} from 'react';
44
import type {ImageStyle, StyleProp} from 'react-native';
55
import {Image, StyleSheet, View} from 'react-native';
6-
import type {OnyxEntry} from 'react-native-onyx';
7-
import {useOnyx, withOnyx} from 'react-native-onyx';
6+
import {useOnyx} from 'react-native-onyx';
87
import Avatar from '@components/Avatar';
98
import AvatarWithImagePicker from '@components/AvatarWithImagePicker';
109
import Button from '@components/Button';
@@ -34,27 +33,22 @@ import CONST from '@src/CONST';
3433
import ONYXKEYS from '@src/ONYXKEYS';
3534
import ROUTES from '@src/ROUTES';
3635
import type SCREENS from '@src/SCREENS';
37-
import type * as OnyxTypes from '@src/types/onyx';
3836
import {isEmptyObject} from '@src/types/utils/EmptyObject';
3937
import type {WithPolicyProps} from './withPolicy';
4038
import withPolicy from './withPolicy';
4139
import WorkspacePageWithSections from './WorkspacePageWithSections';
4240

43-
type WorkspaceProfilePageOnyxProps = {
44-
/** Constant, list of available currencies */
45-
currencyList: OnyxEntry<OnyxTypes.CurrencyList>;
46-
};
41+
type WorkspaceProfilePageProps = WithPolicyProps & StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.PROFILE>;
4742

48-
type WorkspaceProfilePageProps = WithPolicyProps & WorkspaceProfilePageOnyxProps & StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.PROFILE>;
49-
50-
function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {}, route}: WorkspaceProfilePageProps) {
43+
function WorkspaceProfilePage({policyDraft, policy: policyProp, route}: WorkspaceProfilePageProps) {
5144
const styles = useThemeStyles();
5245
const {translate} = useLocalize();
5346
const {shouldUseNarrowLayout} = useResponsiveLayout();
5447
const illustrations = useThemeIllustrations();
5548
const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace();
5649
const {canUseSpotnanaTravel} = usePermissions();
5750

51+
const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST);
5852
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID});
5953

6054
// 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.
@@ -63,6 +57,12 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
6357
const currencySymbol = currencyList?.[outputCurrency]?.symbol ?? '';
6458
const formattedCurrency = !isEmptyObject(policy) && !isEmptyObject(currencyList) ? `${outputCurrency} - ${currencySymbol}` : '';
6559

60+
// We need this to update translation for deleting a workspace when it has third party card feeds or expensify card assigned.
61+
const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policy?.id ?? '-1');
62+
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
63+
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);
64+
const hasCardFeedOrExpensifyCard = !isEmptyObject(cardFeeds) || !isEmptyObject(cardsList);
65+
6666
const [street1, street2] = (policy?.address?.addressStreet ?? '').split('\n');
6767
const formattedAddress =
6868
!isEmptyObject(policy) && !isEmptyObject(policy.address)
@@ -285,11 +285,11 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
285285
)}
286286
</Section>
287287
<ConfirmModal
288-
title={translate('common.delete')}
288+
title={translate('workspace.common.delete')}
289289
isVisible={isDeleteModalOpen}
290290
onConfirm={confirmDeleteAndHideModal}
291291
onCancel={() => setIsDeleteModalOpen(false)}
292-
prompt={translate('workspace.common.deleteConfirmation')}
292+
prompt={hasCardFeedOrExpensifyCard ? translate('workspace.common.deleteWithCardsConfirmation') : translate('workspace.common.deleteConfirmation')}
293293
confirmText={translate('common.delete')}
294294
cancelText={translate('common.cancel')}
295295
danger
@@ -302,8 +302,4 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
302302

303303
WorkspaceProfilePage.displayName = 'WorkspaceProfilePage';
304304

305-
export default withPolicy(
306-
withOnyx<WorkspaceProfilePageProps, WorkspaceProfilePageOnyxProps>({
307-
currencyList: {key: ONYXKEYS.CURRENCY_LIST},
308-
})(WorkspaceProfilePage),
309-
);
305+
export default withPolicy(WorkspaceProfilePage);

src/pages/workspace/WorkspacesListPage.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ function WorkspacesListPage() {
120120
const [policyNameToDelete, setPolicyNameToDelete] = useState<string>();
121121
const isLessThanMediumScreen = isMediumScreenWidth || shouldUseNarrowLayout;
122122

123+
// We need this to update translation for deleting a workspace when it has third party card feeds or expensify card assigned.
124+
const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyIDToDelete ?? '-1');
125+
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`);
126+
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);
127+
const hasCardFeedOrExpensifyCard = !isEmptyObject(cardFeeds) || !isEmptyObject(cardsList);
128+
123129
const confirmDeleteAndHideModal = () => {
124130
if (!policyIDToDelete || !policyNameToDelete) {
125131
return;
@@ -431,7 +437,7 @@ function WorkspacesListPage() {
431437
isVisible={isDeleteModalOpen}
432438
onConfirm={confirmDeleteAndHideModal}
433439
onCancel={() => setIsDeleteModalOpen(false)}
434-
prompt={translate('workspace.common.deleteConfirmation')}
440+
prompt={hasCardFeedOrExpensifyCard ? translate('workspace.common.deleteWithCardsConfirmation') : translate('workspace.common.deleteConfirmation')}
435441
confirmText={translate('common.delete')}
436442
cancelText={translate('common.cancel')}
437443
danger

0 commit comments

Comments
 (0)