-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnavbar-subscribe-cta.tsx
More file actions
36 lines (31 loc) · 1.12 KB
/
Copy pathnavbar-subscribe-cta.tsx
File metadata and controls
36 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use client";
import { useUserProfile } from "@/hooks/use-user-profile";
import { isSubscribed } from "@/lib/user-identity";
import { ArrowRightIcon } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
export default function NavbarSubscribeCta() {
const { profile } = useUserProfile();
const pathname = usePathname();
const [subscribed, setSubscribed] = useState(false);
// Re-read the localStorage hint on every navigation. The navbar lives in
// the layout so it doesn't unmount on client-side route changes; without
// this hook the pill would linger until full reload after a successful
// subscribe.
useEffect(() => {
setSubscribed(isSubscribed());
}, [pathname]);
if (profile) return null;
if (subscribed) return null;
return (
<Link
href="/subscribe"
data-navbar-subscribe-cta
className="inline-flex items-center rounded-full bg-gold-hue px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-gold-shade"
>
Subscribe
<ArrowRightIcon className="ml-2 h-4 w-4" aria-hidden="true" />
</Link>
);
}