({
className,
color,
size,
iconOnly = false,
target,
variant,
...attrs
}: Props)
| 23 | } & WithClassNameProps; |
| 24 | |
| 25 | export const UpgradeToPlus = ({ |
| 26 | className, |
| 27 | color, |
| 28 | size, |
| 29 | iconOnly = false, |
| 30 | target, |
| 31 | variant, |
| 32 | ...attrs |
| 33 | }: Props): ReactElement | null => { |
| 34 | const { isLoggedIn, showLogin } = useAuthContext(); |
| 35 | const isLaptop = useViewSize(ViewSize.Laptop); |
| 36 | const isLaptopXL = useViewSize(ViewSize.LaptopXL); |
| 37 | const isFullCTAText = !isLaptop || isLaptopXL; |
| 38 | const { isPlus, logSubscriptionEvent } = usePlusSubscription(); |
| 39 | const ctaCopy = { full: 'Get API Access', short: 'API access' }; |
| 40 | const content = isFullCTAText ? ctaCopy.full : ctaCopy.short; |
| 41 | const defaultColor = ButtonColor.Bacon; |
| 42 | |
| 43 | const onClick = useCallback( |
| 44 | (e: React.MouseEvent) => { |
| 45 | if (!isLoggedIn) { |
| 46 | e.preventDefault(); |
| 47 | showLogin({ trigger: AuthTriggers.Plus }); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | logSubscriptionEvent({ |
| 52 | event_name: LogEvent.UpgradeSubscription, |
| 53 | target_id: target, |
| 54 | }); |
| 55 | }, |
| 56 | [isLoggedIn, logSubscriptionEvent, showLogin, target], |
| 57 | ); |
| 58 | |
| 59 | if (isPlus) { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | return ( |
| 64 | <Link passHref href={plusUrl}> |
| 65 | <Button |
| 66 | tag="a" |
| 67 | className={classNames(!iconOnly && 'flex-1', className)} |
| 68 | icon={<DevPlusIcon />} |
| 69 | size={size} |
| 70 | color={defaultColor} |
| 71 | variant={ButtonVariant.Primary} |
| 72 | onClick={onClick} |
| 73 | {...(variant && { variant, color })} |
| 74 | {...attrs} |
| 75 | > |
| 76 | {iconOnly ? null : content} |
| 77 | </Button> |
| 78 | </Link> |
| 79 | ); |
| 80 | }; |
nothing calls this directly
no test coverage detected