Skip to content

Commit

Permalink
Merge pull request #57218 from ikevin127/ikevin127-expensifyCardBanne…
Browse files Browse the repository at this point in the history
…rDisplay

Expensify Card promotion banner conditional display
  • Loading branch information
mountiny authored Feb 25, 2025
2 parents eaa3be4 + 085633d commit d97f1b4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 68 deletions.
9 changes: 9 additions & 0 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ function checkIfFeedConnectionIsBroken(feedCards: Record<string, Card> | undefin
return Object.values(feedCards).some((card) => card.bank !== feedToExclude && card.lastScrapeResult !== 200);
}

/**
* Checks if an Expensify Card was issued for a given workspace.
*/
function hasIssuedExpensifyCard(workspaceAccountID: number, allCardList: OnyxCollection<WorkspaceCardsList> = allWorkspaceCards): boolean {
const cards = getAllCardsForWorkspace(workspaceAccountID, allCardList);
return Object.values(cards).some((card) => card.bank === CONST.EXPENSIFY_CARD.BANK);
}

function hasCardListObject(workspaceAccountID: number, feedName: CompanyCardFeed): boolean {
const workspaceCards = allWorkspaceCards?.[`cards_${workspaceAccountID}_${feedName}`] ?? {};
return !!workspaceCards.cardList;
Expand Down Expand Up @@ -559,5 +567,6 @@ export {
getFeedType,
flatAllCardsList,
checkIfFeedConnectionIsBroken,
hasIssuedExpensifyCard,
hasCardListObject,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ import {useOnyx} from 'react-native-onyx';
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
import FeatureList from '@components/FeatureList';
import type {FeatureListItem} from '@components/FeatureList';
import * as Illustrations from '@components/Icon/Illustrations';
import {CompanyCardsEmptyState, CreditCardsNew, HandCard, MagnifyingGlassMoney} from '@components/Icon/Illustrations';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {hasIssuedExpensifyCard} from '@libs/CardUtils';
import Navigation from '@libs/Navigation/Navigation';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import colors from '@styles/theme/colors';
import {clearAddNewCardFlow} from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import WorkspaceCompanyCardExpensifyCardPromotionBanner from './WorkspaceCompanyCardExpensifyCardPromotionBanner';

const companyCardFeatures: FeatureListItem[] = [
{
icon: Illustrations.CreditCardsNew,
icon: CreditCardsNew,
translationKey: 'workspace.moreFeatures.companyCards.feed.features.support',
},
{
icon: Illustrations.HandCard,
icon: HandCard,
translationKey: 'workspace.moreFeatures.companyCards.feed.features.assignCards',
},
{
icon: Illustrations.MagnifyingGlassMoney,
icon: MagnifyingGlassMoney,
translationKey: 'workspace.moreFeatures.companyCards.feed.features.automaticImport',
},
];
Expand All @@ -36,9 +38,10 @@ function WorkspaceCompanyCardPageEmptyState({policy}: WithPolicyAndFullscreenLoa
const {translate} = useLocalize();
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();

const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate});
const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false);
const [allWorkspaceCards] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST);
const shouldShowExpensifyCardPromotionBanner = !hasIssuedExpensifyCard(policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID, allWorkspaceCards);

const handleCtaPress = useCallback(() => {
if (!policy?.id) {
Expand All @@ -54,7 +57,7 @@ function WorkspaceCompanyCardPageEmptyState({policy}: WithPolicyAndFullscreenLoa

return (
<View style={[styles.mt3, shouldUseNarrowLayout ? styles.workspaceSectionMobile : styles.workspaceSection]}>
<WorkspaceCompanyCardExpensifyCardPromotionBanner policy={policy} />
{shouldShowExpensifyCardPromotionBanner && <WorkspaceCompanyCardExpensifyCardPromotionBanner policy={policy} />}
<FeatureList
menuItems={companyCardFeatures}
title={translate('workspace.moreFeatures.companyCards.feed.title')}
Expand All @@ -63,7 +66,7 @@ function WorkspaceCompanyCardPageEmptyState({policy}: WithPolicyAndFullscreenLoa
ctaAccessibilityLabel={translate('workspace.companyCards.addCards')}
onCtaPress={handleCtaPress}
illustrationBackgroundColor={colors.blue700}
illustration={Illustrations.CompanyCardsEmptyState}
illustration={CompanyCardsEmptyState}
illustrationStyle={styles.emptyStateCardIllustration}
illustrationContainerStyle={[styles.emptyStateCardIllustrationContainer, styles.justifyContentStart]}
titleStyles={styles.textHeadlineH1}
Expand Down
Loading

0 comments on commit d97f1b4

Please sign in to comment.