fix: toast

This commit is contained in:
Maze Winther
2025-07-14 17:42:00 +02:00
parent 87215b31e9
commit 64b84ca041
+5 -13
View File
@@ -5,7 +5,7 @@ import { Button } from "../ui/button";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
import { ArrowRight } from "lucide-react"; import { ArrowRight } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import { useToast } from "@/hooks/use-toast"; import { toast } from "sonner";
import Image from "next/image"; import Image from "next/image";
import { Handlebars } from "./handlebars"; import { Handlebars } from "./handlebars";
@@ -17,16 +17,13 @@ interface HeroProps {
export function Hero({ signupCount }: HeroProps) { export function Hero({ signupCount }: HeroProps) {
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
const { toast } = useToast();
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
if (!email.trim()) { if (!email.trim()) {
toast({ toast.error("Email required", {
title: "Email required",
description: "Please enter your email address.", description: "Please enter your email address.",
variant: "destructive",
}); });
return; return;
} }
@@ -45,25 +42,20 @@ export function Hero({ signupCount }: HeroProps) {
const data = (await response.json()) as { error: string }; const data = (await response.json()) as { error: string };
if (response.ok) { if (response.ok) {
toast({ toast.success("Welcome to the waitlist! 🎉", {
title: "Welcome to the waitlist! 🎉",
description: "You'll be notified when we launch.", description: "You'll be notified when we launch.",
}); });
setEmail(""); setEmail("");
} else { } else {
toast({ toast.error("Oops!", {
title: "Oops!",
description: description:
(data as { error: string }).error || (data as { error: string }).error ||
"Something went wrong. Please try again.", "Something went wrong. Please try again.",
variant: "destructive",
}); });
} }
} catch (error) { } catch (error) {
toast({ toast.error("Network error", {
title: "Network error",
description: "Please check your connection and try again.", description: "Please check your connection and try again.",
variant: "destructive",
}); });
} finally { } finally {
setIsSubmitting(false); setIsSubmitting(false);