import * as React from 'react'; import { Link } from 'react-router-dom'; import { Card, HelperText, PageSection, SplitItem, Title } from '@patternfly/react-core'; import { useLocalStorage } from '~/shared/hooks/useLocalStorage'; import { CloseButton } from '../../shared'; import ExternalLink from '../../shared/components/links/ExternalLink'; import { ButtonWithAccessTooltip } from '../ButtonWithAccessTooltip'; import './WhatsNextSection.scss'; export type WhatsNextItem = { id: number; title: string; description: string; icon: React.ComponentType>; helpId?: string; noAction?: boolean; helpLink?: string; helpText?: string; cta?: { label: string; href?: string; external?: boolean; onClick?: () => void; disabled?: boolean; disabledTooltip?: string; testId?: string; analytics?: React.ComponentProps['analytics']; }; }; type WhatsNextSectionProps = { whatsNextItems: WhatsNextItem[]; }; const DISMISSED_CARD_STORAGE_KEY = 'dismissedCards'; const WhatsNextSection: React.FunctionComponent> = ({ whatsNextItems, }) => { const [localStorageItem, setLocalStorageItem] = useLocalStorage( DISMISSED_CARD_STORAGE_KEY, ); const handleCardDismissal = React.useCallback( (id: number) => { const dismissedCards = Array.isArray(localStorageItem) ? localStorageItem : []; setLocalStorageItem([id, ...dismissedCards]); }, [localStorageItem, setLocalStorageItem], ); if (localStorageItem?.length === whatsNextItems.length) return null; return ( What's next? {whatsNextItems.map((item) => { const ItemIcon = item.icon; return ( !localStorageItem?.includes(item?.id) && ( {item.title} {item.description} {item.cta && ( , } : { component: 'a', href: item.cta.href, target: '_blank', rel: 'noreferrer', })} isDisabled={item.cta.disabled} tooltip={item.cta.disabledTooltip} variant="secondary" analytics={item.cta.analytics} > {item.cta.label} )} {item.helpLink && ( {item.helpText ?? 'Learn more'} )} { handleCardDismissal(item.id); }} /> ) ); })} ); }; export default WhatsNextSection;