MCPcopy Create free account
hub / github.com/dailydotdev/apps / UpgradeToPlus

Function UpgradeToPlus

packages/shared/src/components/UpgradeToPlus.tsx:26–87  ·  view source on GitHub ↗
({
  className,
  color,
  size,
  iconOnly = false,
  target,
  variant,
  ...attrs
}: Props)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

useAuthContextFunction · 0.90
useViewSizeFunction · 0.90
usePlusSubscriptionFunction · 0.90
useConditionalFeatureFunction · 0.90

Tested by

no test coverage detected