Skip to content

Commit

Permalink
Merge pull request Expensify#51997 from Expensify/vit-removeCompanyCa…
Browse files Browse the repository at this point in the history
…rdsBeta

[NoQA] Remove direct and company cards betas
  • Loading branch information
robertjchen authored Nov 6, 2024
2 parents 92f5c54 + f6278ef commit 7bd88ac
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 118 deletions.
10 changes: 0 additions & 10 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ function canUseSpotnanaTravel(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.SPOTNANA_TRAVEL) || canUseAllBetas(betas);
}

function canUseCompanyCardFeeds(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.COMPANY_CARD_FEEDS) || canUseAllBetas(betas);
}

function canUseDirectFeeds(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.DIRECT_FEEDS) || canUseAllBetas(betas);
}

function canUseNetSuiteUSATax(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.NETSUITE_USA_TAX) || canUseAllBetas(betas);
}
Expand Down Expand Up @@ -62,8 +54,6 @@ export default {
canUseDupeDetection,
canUseP2PDistanceRequests,
canUseSpotnanaTravel,
canUseCompanyCardFeeds,
canUseDirectFeeds,
canUseNetSuiteUSATax,
canUseCombinedTrackSubmit,
canUseCategoryAndTagApprovers,
Expand Down
48 changes: 21 additions & 27 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Section from '@components/Section';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CardUtils from '@libs/CardUtils';
Expand Down Expand Up @@ -63,7 +62,6 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {translate} = useLocalize();
const {canUseCompanyCardFeeds} = usePermissions();
const hasAccountingConnection = !isEmptyObject(policy?.connections);
const isAccountingEnabled = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections);
const isSyncTaxEnabled =
Expand Down Expand Up @@ -120,31 +118,27 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
},
];

if (canUseCompanyCardFeeds) {
spendItems.push({
icon: Illustrations.CompanyCard,
titleTranslationKey: 'workspace.moreFeatures.companyCards.title',
subtitleTranslationKey: 'workspace.moreFeatures.companyCards.subtitle',
isActive: policy?.areCompanyCardsEnabled ?? false,
pendingAction: policy?.pendingFields?.areCompanyCardsEnabled,
disabled: !isEmptyObject(CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds?.settings?.companyCards)),
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (isEnabled && !isControlPolicy(policy)) {
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.companyCards.alias, ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)),
);
return;
}
Policy.enableCompanyCards(policyID, isEnabled);
},
disabledAction: () => {
setIsDisableCompanyCardsWarningModalOpen(true);
},
});
}
spendItems.push({
icon: Illustrations.CompanyCard,
titleTranslationKey: 'workspace.moreFeatures.companyCards.title',
subtitleTranslationKey: 'workspace.moreFeatures.companyCards.subtitle',
isActive: policy?.areCompanyCardsEnabled ?? false,
pendingAction: policy?.pendingFields?.areCompanyCardsEnabled,
disabled: !isEmptyObject(CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds?.settings?.companyCards)),
action: (isEnabled: boolean) => {
if (!policyID) {
return;
}
if (isEnabled && !isControlPolicy(policy)) {
Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.companyCards.alias, ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)));
return;
}
Policy.enableCompanyCards(policyID, isEnabled);
},
disabledAction: () => {
setIsDisableCompanyCardsWarningModalOpen(true);
},
});

const manageItems: Item[] = [
{
Expand Down
56 changes: 19 additions & 37 deletions src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {useOnyx} from 'react-native-onyx';
import usePermissions from '@hooks/usePermissions';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import CONST from '@src/CONST';
Expand All @@ -17,44 +16,27 @@ import SelectFeedType from './SelectFeedType';
function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
const policyID = policy?.id;
const [addNewCardFeed] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const {canUseDirectFeeds} = usePermissions();

const {currentStep} = addNewCardFeed ?? {};

if (canUseDirectFeeds) {
switch (currentStep) {
case CONST.COMPANY_CARDS.STEP.SELECT_BANK:
return <SelectBankStep />;
case CONST.COMPANY_CARDS.STEP.SELECT_FEED_TYPE:
return <SelectFeedType />;
case CONST.COMPANY_CARDS.STEP.CARD_TYPE:
return <CardTypeStep />;
case CONST.COMPANY_CARDS.STEP.BANK_CONNECTION:
return <BankConnection policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS:
return <CardInstructionsStep policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_NAME:
return <CardNameStep />;
case CONST.COMPANY_CARDS.STEP.CARD_DETAILS:
return <DetailsStep policyID={policy?.id ?? '-1'} />;
case CONST.COMPANY_CARDS.STEP.AMEX_CUSTOM_FEED:
return <AmexCustomFeed />;
default:
return <SelectBankStep />;
}
} else {
switch (currentStep) {
case CONST.COMPANY_CARDS.STEP.CARD_TYPE:
return <CardTypeStep />;
case CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS:
return <CardInstructionsStep />;
case CONST.COMPANY_CARDS.STEP.CARD_NAME:
return <CardNameStep />;
case CONST.COMPANY_CARDS.STEP.CARD_DETAILS:
return <DetailsStep policyID={policy?.id ?? '-1'} />;
default:
return <CardTypeStep />;
}
switch (currentStep) {
case CONST.COMPANY_CARDS.STEP.SELECT_BANK:
return <SelectBankStep />;
case CONST.COMPANY_CARDS.STEP.SELECT_FEED_TYPE:
return <SelectFeedType />;
case CONST.COMPANY_CARDS.STEP.CARD_TYPE:
return <CardTypeStep />;
case CONST.COMPANY_CARDS.STEP.BANK_CONNECTION:
return <BankConnection policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS:
return <CardInstructionsStep policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_NAME:
return <CardNameStep />;
case CONST.COMPANY_CARDS.STEP.CARD_DETAILS:
return <DetailsStep policyID={policy?.id ?? '-1'} />;
case CONST.COMPANY_CARDS.STEP.AMEX_CUSTOM_FEED:
return <AmexCustomFeed />;
default:
return <SelectBankStep />;
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/pages/workspace/companyCards/addNew/CardInstructionsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CardUtils from '@libs/CardUtils';
import Parser from '@libs/Parser';
Expand All @@ -26,7 +25,6 @@ function CardInstructionsStep({policyID}: CardInstructionsStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {canUseDirectFeeds} = usePermissions();

const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);

Expand All @@ -40,12 +38,12 @@ function CardInstructionsStep({policyID}: CardInstructionsStepProps) {
const buttonTranslation = isStripeFeedProvider ? translate('common.submit') : translate('common.next');

const submit = () => {
if (canUseDirectFeeds && isStripeFeedProvider) {
if (isStripeFeedProvider) {
Card.updateSelectedFeed(feedProvider, policyID ?? '-1');
Navigation.goBack();
return;
}
if (!canUseDirectFeeds || isOtherBankSelected) {
if (isOtherBankSelected) {
CompanyCards.setAddNewCompanyCardStepAndData({
step: CONST.COMPANY_CARDS.STEP.CARD_NAME,
});
Expand All @@ -57,13 +55,13 @@ function CardInstructionsStep({policyID}: CardInstructionsStepProps) {
};

const handleBackButtonPress = () => {
if (canUseDirectFeeds && isAmexFeedProvider) {
if (isAmexFeedProvider) {
CompanyCards.setAddNewCompanyCardStepAndData({
step: CONST.COMPANY_CARDS.STEP.AMEX_CUSTOM_FEED,
});
return;
}
if (canUseDirectFeeds && isStripeFeedProvider) {
if (isStripeFeedProvider) {
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK});
return;
}
Expand Down
40 changes: 5 additions & 35 deletions src/pages/workspace/companyCards/addNew/CardTypeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@navigation/Navigation';
import variables from '@styles/variables';
import * as CompanyCards from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CardFeedProvider} from '@src/types/onyx/CardFeeds';

type AvailableCompanyCardTypes = {
isAmexAvailable?: boolean;
translate: LocaleContextProps['translate'];
typeSelected?: CardFeedProvider;
styles: StyleProp<ViewStyle>;
};

function getAvailableCompanyCardTypes({isAmexAvailable, translate, typeSelected, styles}: AvailableCompanyCardTypes) {
const defaultTypes = [
function getAvailableCompanyCardTypes({translate, typeSelected, styles}: AvailableCompanyCardTypes) {
return [
{
value: CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD,
text: translate('workspace.companyCards.addNewCard.cardProviders.cdf'),
Expand Down Expand Up @@ -59,38 +56,15 @@ function getAvailableCompanyCardTypes({isAmexAvailable, translate, typeSelected,
),
},
];

if (!isAmexAvailable) {
return defaultTypes;
}

return [
{
value: CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX,
text: translate('workspace.companyCards.addNewCard.cardProviders.gl1025'),
keyForList: CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX,
isSelected: typeSelected === CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX,
leftElement: (
<Icon
src={Illustrations.AmexCardCompanyCardDetail}
height={variables.iconSizeExtraLarge}
width={variables.iconSizeExtraLarge}
additionalStyles={styles}
/>
),
},
...defaultTypes,
];
}

function CardTypeStep() {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [typeSelected, setTypeSelected] = useState<CardFeedProvider>();
const {canUseDirectFeeds} = usePermissions();
const [isError, setIsError] = useState(false);
const data = getAvailableCompanyCardTypes({isAmexAvailable: !canUseDirectFeeds, translate, typeSelected, styles: styles.mr3});
const data = getAvailableCompanyCardTypes({translate, typeSelected, styles: styles.mr3});
const {bankName, selectedBank, feedType} = addNewCard?.data ?? {};
const isOtherBankSelected = selectedBank === CONST.COMPANY_CARDS.BANKS.OTHER;
const isNewCardTypeSelected = typeSelected !== feedType;
Expand All @@ -103,7 +77,7 @@ function CardTypeStep() {
step: CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS,
data: {
feedType: typeSelected,
bankName: isNewCardTypeSelected && (!canUseDirectFeeds || isOtherBankSelected) ? '' : bankName,
bankName: isNewCardTypeSelected && isOtherBankSelected ? '' : bankName,
},
isEditing: false,
});
Expand All @@ -115,11 +89,7 @@ function CardTypeStep() {
}, [addNewCard?.data.feedType]);

const handleBackButtonPress = () => {
if (canUseDirectFeeds) {
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK});
} else {
Navigation.goBack();
}
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK});
};

return (
Expand Down
4 changes: 1 addition & 3 deletions src/pages/workspace/companyCards/addNew/DetailsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import TextInput from '@components/TextInput';
import TextLink from '@components/TextLink';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ValidationUtils from '@libs/ValidationUtils';
Expand All @@ -36,7 +35,6 @@ function DetailsStep({policyID}: DetailsStepProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {inputCallbackRef} = useAutoFocusInput();
const {canUseDirectFeeds} = usePermissions();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`);
const feedProvider = addNewCard?.data?.feedType;
Expand All @@ -61,7 +59,7 @@ function DetailsStep({policyID}: DetailsStepProps) {
};

const handleBackButtonPress = () => {
if (!canUseDirectFeeds || isOtherBankSelected) {
if (isOtherBankSelected) {
CompanyCards.setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.CARD_NAME});
return;
}
Expand Down

0 comments on commit 7bd88ac

Please sign in to comment.