|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState, useSyncExternalStore, useCallback } from "react"; |
| 4 | +import Link from "next/link"; |
| 5 | +import { X, Sparkles } from "lucide-react"; |
| 6 | + |
| 7 | +const STORAGE_KEY = "vcp_public_profile_intro_seen"; |
| 8 | + |
| 9 | +// Subscribe to localStorage changes (for cross-tab sync if needed) |
| 10 | +function subscribe(callback: () => void) { |
| 11 | + window.addEventListener("storage", callback); |
| 12 | + return () => window.removeEventListener("storage", callback); |
| 13 | +} |
| 14 | + |
| 15 | +function getSnapshot(): boolean { |
| 16 | + return localStorage.getItem(STORAGE_KEY) === "1"; |
| 17 | +} |
| 18 | + |
| 19 | +function getServerSnapshot(): boolean { |
| 20 | + return true; // On server, assume dismissed to avoid hydration mismatch |
| 21 | +} |
| 22 | + |
| 23 | +interface FirstTimePublicProfileBannerProps { |
| 24 | + /** Whether user's public profile is already enabled */ |
| 25 | + profileEnabled: boolean; |
| 26 | + /** Whether user has claimed a username */ |
| 27 | + hasUsername: boolean; |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Dismissible onboarding banner shown after first VCP generation. |
| 32 | + * Prompts users to enable their public profile. |
| 33 | + * Uses localStorage to track dismissal. |
| 34 | + */ |
| 35 | +export function FirstTimePublicProfileBanner({ |
| 36 | + profileEnabled, |
| 37 | + hasUsername, |
| 38 | +}: FirstTimePublicProfileBannerProps) { |
| 39 | + // Use useSyncExternalStore to safely read from localStorage |
| 40 | + const dismissedFromStorage = useSyncExternalStore( |
| 41 | + subscribe, |
| 42 | + getSnapshot, |
| 43 | + getServerSnapshot |
| 44 | + ); |
| 45 | + |
| 46 | + const [localDismissed, setLocalDismissed] = useState(false); |
| 47 | + const dismissed = dismissedFromStorage || localDismissed; |
| 48 | + |
| 49 | + const dismiss = useCallback(() => { |
| 50 | + localStorage.setItem(STORAGE_KEY, "1"); |
| 51 | + setLocalDismissed(true); |
| 52 | + }, []); |
| 53 | + |
| 54 | + // Don't render if dismissed or if profile already enabled |
| 55 | + if (dismissed || profileEnabled) { |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + return ( |
| 60 | + <div className="relative overflow-hidden rounded-2xl border border-violet-300/50 bg-gradient-to-r from-violet-100 via-indigo-50 to-violet-100 px-6 py-5 shadow-sm"> |
| 61 | + {/* Decorative sparkle */} |
| 62 | + <div className="absolute -right-4 -top-4 h-24 w-24 rounded-full bg-violet-200/30 blur-2xl" /> |
| 63 | + <div className="absolute -left-4 -bottom-4 h-20 w-20 rounded-full bg-indigo-200/30 blur-2xl" /> |
| 64 | + |
| 65 | + <div className="relative flex items-start gap-4"> |
| 66 | + <div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-violet-500 to-indigo-500 shadow-sm"> |
| 67 | + <Sparkles className="h-5 w-5 text-white" /> |
| 68 | + </div> |
| 69 | + |
| 70 | + <div className="min-w-0 flex-1"> |
| 71 | + <p className="font-semibold text-zinc-900"> |
| 72 | + Your Vibe Coding Profile is ready! |
| 73 | + </p> |
| 74 | + <p className="mt-1 text-sm text-zinc-600"> |
| 75 | + {hasUsername |
| 76 | + ? "Enable your public profile to share your VCP on Twitter, LinkedIn, and more." |
| 77 | + : "Claim a username and enable your public profile to share your VCP with the world."} |
| 78 | + </p> |
| 79 | + <div className="mt-3 flex flex-wrap items-center gap-3"> |
| 80 | + <Link |
| 81 | + href="/settings/public-profile" |
| 82 | + className="inline-flex items-center gap-1.5 rounded-full bg-gradient-to-r from-violet-600 to-indigo-500 px-4 py-2 text-sm font-semibold text-white shadow-sm transition hover:brightness-110" |
| 83 | + > |
| 84 | + {hasUsername ? "Enable Public Profile" : "Set Up Public Profile"} |
| 85 | + </Link> |
| 86 | + <button |
| 87 | + type="button" |
| 88 | + onClick={dismiss} |
| 89 | + className="text-sm font-medium text-zinc-500 hover:text-zinc-700" |
| 90 | + > |
| 91 | + Maybe later |
| 92 | + </button> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + |
| 96 | + <button |
| 97 | + type="button" |
| 98 | + onClick={dismiss} |
| 99 | + className="flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full text-zinc-400 transition hover:bg-zinc-200/50 hover:text-zinc-600" |
| 100 | + aria-label="Dismiss" |
| 101 | + > |
| 102 | + <X size={16} /> |
| 103 | + </button> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + ); |
| 107 | +} |
0 commit comments