From 66415873eeafe0829296cc1132128bc487714e28 Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Wed, 25 Sep 2024 17:47:07 +0200 Subject: [PATCH 1/2] Refactor ActionBanner component to support multiple CTAs Use multiple CTAs on the upgrade banner --- components/ActionBanner.tsx | 95 +++++++++++++++--------- pages/[networkOrProduct]/sky/upgrade.tsx | 19 +++-- 2 files changed, 74 insertions(+), 40 deletions(-) diff --git a/components/ActionBanner.tsx b/components/ActionBanner.tsx index a48a462644..8a2c0b8a88 100644 --- a/components/ActionBanner.tsx +++ b/components/ActionBanner.tsx @@ -16,15 +16,16 @@ interface ActionBannerWithImage { icon?: never image?: string } +type CtaType = { + label: string + onClick?: () => void + targetBlank?: boolean + url?: string +} export type ActionBannerType = { closingSaveKey?: string - cta?: { - label: string - onClick?: () => void - targetBlank?: boolean - url?: string - } + cta?: CtaType | CtaType[] sx?: ThemeUIStyleObject title: string withClose?: boolean @@ -38,6 +39,59 @@ function getSessionStorageKey(suffix: string): string { return `action-banner-${kebabCase(suffix)}` } +const CtaComponent = ({ + cta, + customCtaVariant, + lightText, +}: { + cta: ActionBannerProps['cta'] + customCtaVariant: ActionBannerProps['customCtaVariant'] + lightText: ActionBannerProps['lightText'] +}) => { + if (Array.isArray(cta)) { + return ( + <> + {cta.map((ctaItem, index) => ( + + ))} + + ) + } + return cta ? ( + + {cta.url ? ( + + + + ) : ( + cta.onClick && ( + + ) + )} + + ) : null +} + export function ActionBanner({ closingSaveKey, children, @@ -87,34 +141,7 @@ export function ActionBanner({ )} - {cta && ( - - {cta.url ? ( - - - - ) : ( - cta.onClick && ( - - ) - )} - - )} + {cta && } {withClose && (