Files
OpenCut/apps/web/src/components/landing/hero.tsx
T

150 lines
4.9 KiB
TypeScript
Raw Normal View History

2025-06-28 12:38:31 +02:00
"use client";
import { motion } from "motion/react";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { ArrowRight } from "lucide-react";
2025-07-16 00:44:42 +01:00
import { useState, useEffect } from "react";
2025-07-14 17:42:00 +02:00
import { toast } from "sonner";
2025-06-28 12:38:31 +02:00
import Image from "next/image";
2025-07-09 17:30:37 +05:30
import { Handlebars } from "./handlebars";
2025-06-28 12:38:31 +02:00
2025-07-15 23:26:04 +02:00
export function Hero() {
2025-06-28 12:38:31 +02:00
const [email, setEmail] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
2025-07-16 00:44:42 +01:00
const [csrfToken, setCsrfToken] = useState<string | null>(null);
useEffect(() => {
2025-07-16 01:05:42 +01:00
let isMounted = true;
2025-07-16 00:44:42 +01:00
fetch("/api/waitlist/token", {
credentials: "include",
})
.then((res) => res.json())
.then((data) => {
2025-07-16 01:05:42 +01:00
if (isMounted && data.token) {
2025-07-16 00:44:42 +01:00
setCsrfToken(data.token);
}
})
2025-07-16 01:05:42 +01:00
.catch((err) => {
console.error("Failed to fetch CSRF token:", err);
if (isMounted) {
toast.error("Security initialization failed", {
description: "Please refresh the page to continue.",
});
}
});
2025-07-16 00:44:42 +01:00
}, []);
2025-06-28 12:38:31 +02:00
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!email.trim()) {
2025-07-14 17:42:00 +02:00
toast.error("Email required", {
2025-06-28 12:38:31 +02:00
description: "Please enter your email address.",
});
return;
}
2025-07-16 00:44:42 +01:00
if (!csrfToken) {
toast.error("Security error", {
description: "Please refresh the page and try again.",
});
return;
}
2025-06-28 12:38:31 +02:00
setIsSubmitting(true);
try {
const response = await fetch("/api/waitlist", {
method: "POST",
headers: {
"Content-Type": "application/json",
2025-07-16 00:44:42 +01:00
"X-CSRF-Token": csrfToken,
2025-06-28 12:38:31 +02:00
},
2025-07-16 00:44:42 +01:00
credentials: "include",
2025-06-28 12:38:31 +02:00
body: JSON.stringify({ email: email.trim() }),
});
const data = (await response.json()) as { error: string };
2025-06-28 12:38:31 +02:00
if (response.ok) {
2025-07-14 17:42:00 +02:00
toast.success("Welcome to the waitlist! 🎉", {
2025-06-28 12:38:31 +02:00
description: "You'll be notified when we launch.",
});
setEmail("");
2025-07-16 00:44:42 +01:00
fetch("/api/waitlist/token", { credentials: "include" })
.then((res) => res.json())
.then((data) => {
if (data.token) setCsrfToken(data.token);
2025-07-16 01:05:42 +01:00
})
.catch((err) => {
console.error("Failed to refresh CSRF token:", err);
2025-07-16 00:44:42 +01:00
});
2025-06-28 12:38:31 +02:00
} else {
2025-07-14 17:42:00 +02:00
toast.error("Oops!", {
2025-07-16 00:44:42 +01:00
description: (data as { error: string }).error || "Something went wrong. Please try again.",
2025-06-28 12:38:31 +02:00
});
}
} catch (error) {
2025-07-14 17:42:00 +02:00
toast.error("Network error", {
2025-06-28 12:38:31 +02:00
description: "Please check your connection and try again.",
});
} finally {
setIsSubmitting(false);
}
};
return (
2025-06-29 19:38:30 +02:00
<div className="min-h-[calc(100vh-4.5rem)] supports-[height:100dvh]:min-h-[calc(100dvh-4.5rem)] flex flex-col justify-between items-center text-center px-4">
2025-07-16 00:44:42 +01:00
<Image className="absolute top-0 left-0 -z-50 size-full object-cover" src="/landing-page-bg.png" height={1903.5} width={1269} alt="landing-page.bg" />
2025-06-28 12:38:31 +02:00
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 1 }}
className="max-w-3xl mx-auto w-full flex-1 flex flex-col justify-center"
>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2, duration: 0.8 }}
className="inline-block font-bold tracking-tighter text-4xl md:text-[4rem]"
>
<h1>The Open Source</h1>
2025-07-09 17:30:37 +05:30
<Handlebars>Video Editor</Handlebars>
2025-06-28 12:38:31 +02:00
</motion.div>
<motion.p
className="mt-10 text-base sm:text-xl text-muted-foreground font-light tracking-wide max-w-xl mx-auto"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.4, duration: 0.8 }}
>
2025-07-16 00:44:42 +01:00
A simple but powerful video editor that gets the job done. Works on any platform.
2025-06-28 12:38:31 +02:00
</motion.p>
2025-07-16 00:44:42 +01:00
<motion.div className="mt-12 flex gap-8 justify-center" initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ delay: 0.6, duration: 0.8 }}>
<form onSubmit={handleSubmit} className="flex gap-3 w-full max-w-lg flex-col sm:flex-row">
2025-07-11 14:50:51 +02:00
<div className="relative w-full">
<Input
type="email"
placeholder="Enter your email"
className="h-11 text-base flex-1"
value={email}
onChange={(e) => setEmail(e.target.value)}
2025-07-16 00:44:42 +01:00
disabled={isSubmitting || !csrfToken}
2025-07-11 14:50:51 +02:00
required
/>
</div>
2025-07-16 00:44:42 +01:00
<Button type="submit" size="lg" className="px-6 h-11 text-base !bg-foreground" disabled={isSubmitting || !csrfToken}>
<span className="relative z-10">{isSubmitting ? "Joining..." : "Join waitlist"}</span>
2025-06-28 12:38:31 +02:00
<ArrowRight className="relative z-10 ml-0.5 h-4 w-4 inline-block" />
</Button>
</form>
</motion.div>
</motion.div>
</div>
);
}