import { useWaitlist, useFanfareAuth } from "@waitify-io/fanfare-sdk-react";
function WaitlistPage() {
const { isAuthenticated, guest } = useFanfareAuth();
const { status, isEntered, enteredAt, isLoading, error, enter, leave } = useWaitlist("waitlist_123");
const handleJoin = async () => {
if (!isAuthenticated) {
await guest();
}
try {
await enter();
} catch (err) {
console.error("Failed to join:", err);
}
};
if (error) {
return <div className="error">Error: {error.message}</div>;
}
return (
<div className="waitlist-page">
<h1>Join Our Waitlist</h1>
<p>Be the first to know when we launch!</p>
{status === "available" && (
<button onClick={handleJoin} disabled={isLoading}>
{isLoading ? "Joining..." : "Join Waitlist"}
</button>
)}
{status === "entered" && (
<div className="entered-state">
<div className="success-icon">You are on the list!</div>
<p>Joined: {enteredAt?.toLocaleDateString()}</p>
<button onClick={leave} className="secondary">
Leave Waitlist
</button>
</div>
)}
</div>
);
}