|
| 1 | +"use client" |
| 2 | + |
| 3 | +import type React from "react" |
| 4 | +import { useState } from "react" |
| 5 | +import Link from "next/link" |
| 6 | +import Image from "next/image" |
| 7 | +import { motion } from "motion/react" |
| 8 | +import { toast } from "sonner" |
| 9 | + |
| 10 | +import { Button } from "@/components/ui/button" |
| 11 | +import { Input } from "@/components/ui/input" |
| 12 | +import { Label } from "@/components/ui/label" |
| 13 | +import { Textarea } from "@/components/ui/textarea" |
| 14 | +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" |
| 15 | +import { AuroraBackground } from "@/components/ui/aurora-background" |
| 16 | +import LandingPageNavbar from "@/components/landingPage/LandingPageNavbar" |
| 17 | +import Footer from "@/components/footer" |
| 18 | +import logo from "@/public/dark-logo.png" |
| 19 | + |
| 20 | +const formFields = [ |
| 21 | + { name: "name", label: "Name", type: "text", placeholder: "Your name" }, |
| 22 | + { name: "email", label: "Email", type: "email", placeholder: "you@example.com" }, |
| 23 | + { name: "phone", label: "Phone", type: "tel", placeholder: "Your phone number" }, |
| 24 | +] as const |
| 25 | + |
| 26 | +export default function ContactPage() { |
| 27 | + const [formData, setFormData] = useState({ name: "", email: "", message: "", phone: "" }) |
| 28 | + const [loading, setLoading] = useState(false) |
| 29 | + |
| 30 | + const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { |
| 31 | + setFormData({ ...formData, [e.target.name]: e.target.value }) |
| 32 | + } |
| 33 | + |
| 34 | + const handleSubmit = async (e: React.FormEvent) => { |
| 35 | + e.preventDefault() |
| 36 | + if (loading) return |
| 37 | + setLoading(true) |
| 38 | + |
| 39 | + try { |
| 40 | + const response = await fetch("/api/contact-us", { |
| 41 | + method: "POST", |
| 42 | + headers: { "Content-Type": "application/json" }, |
| 43 | + body: JSON.stringify(formData), |
| 44 | + }) |
| 45 | + |
| 46 | + if (!response.ok) throw new Error("Failed to send mail") |
| 47 | + |
| 48 | + await response.json() |
| 49 | + toast.success("Mail sent successfully!", { |
| 50 | + description: "Thank you for reaching out! We'll get back to you soon.", |
| 51 | + }) |
| 52 | + setFormData({ name: "", email: "", message: "", phone: "" }) |
| 53 | + } catch (error: any) { |
| 54 | + toast.error("Failed to send mail", { |
| 55 | + description: error?.message || "Something went wrong. Please try again.", |
| 56 | + }) |
| 57 | + } finally { |
| 58 | + setLoading(false) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return ( |
| 63 | + <> |
| 64 | + <LandingPageNavbar /> |
| 65 | + <AuroraBackground> |
| 66 | + <div className="relative grid min-h-screen w-full grid-cols-1 items-start justify-center gap-8 px-4 pt-24 md:grid-cols-2 md:items-center md:px-8 md:pt-0 lg:px-16"> |
| 67 | + |
| 68 | + {/* Left Column: Brand Messaging */} |
| 69 | + <motion.div |
| 70 | + initial={{ opacity: 0, x: -40 }} |
| 71 | + whileInView={{ opacity: 1, x: 0 }} |
| 72 | + transition={{ delay: 0.2, duration: 0.8, ease: "easeInOut" }} |
| 73 | + className="hidden flex-col justify-center gap-4 md:flex" |
| 74 | + > |
| 75 | + <Link href="/"> |
| 76 | + <Image src={logo} alt="Script AI" width={80} height={80} className="mb-4" /> |
| 77 | + </Link> |
| 78 | + <h1 className="text-4xl lg:text-5xl font-bold text-slate-900"> |
| 79 | + We'd Love to Hear From You. |
| 80 | + </h1> |
| 81 | + <p className="max-w-md text-lg text-slate-600"> |
| 82 | + Got questions, feedback, or ideas? Our team is always ready to collaborate and support your AI-powered creative journey. |
| 83 | + </p> |
| 84 | + </motion.div> |
| 85 | + |
| 86 | + {/* Right Column: Contact Form */} |
| 87 | + <motion.div |
| 88 | + initial={{ opacity: 0, y: 40 }} |
| 89 | + whileInView={{ opacity: 1, y: 0 }} |
| 90 | + transition={{ delay: 0.3, duration: 0.8, ease: "easeInOut" }} |
| 91 | + className="flex w-full justify-center md:justify-end" |
| 92 | + > |
| 93 | + <Card className="w-full max-w-md bg-white/20 dark:bg-black/20 backdrop-blur-lg border border-white/30 shadow-2xl rounded-2xl"> |
| 94 | + <CardHeader className="space-y-1 pt-6"> |
| 95 | + <div className="flex justify-center md:hidden"> |
| 96 | + <Image src={logo} alt="Script AI" width={60} height={60} /> |
| 97 | + </div> |
| 98 | + <CardTitle className="text-2xl text-center text-slate-900 dark:text-white"> |
| 99 | + Send Us a Message |
| 100 | + </CardTitle> |
| 101 | + </CardHeader> |
| 102 | + |
| 103 | + <CardContent> |
| 104 | + <form onSubmit={handleSubmit} className="space-y-4"> |
| 105 | + {formFields.map((field) => ( |
| 106 | + <div key={field.name} className="space-y-2"> |
| 107 | + <Label htmlFor={field.name} className="dark:text-slate-200">{field.label}</Label> |
| 108 | + <Input |
| 109 | + id={field.name} |
| 110 | + type={field.type} |
| 111 | + name={field.name} |
| 112 | + placeholder={field.placeholder} |
| 113 | + value={formData[field.name as keyof typeof formData]} |
| 114 | + onChange={handleChange} |
| 115 | + required |
| 116 | + className="bg-white/30 dark:bg-black/30 placeholder:text-slate-500 dark:placeholder:text-slate-400 focus-visible:ring-pink-500" |
| 117 | + /> |
| 118 | + </div> |
| 119 | + ))} |
| 120 | + |
| 121 | + <div className="space-y-2"> |
| 122 | + <Label htmlFor="message" className="dark:text-slate-200">Message</Label> |
| 123 | + <Textarea |
| 124 | + id="message" |
| 125 | + name="message" |
| 126 | + value={formData.message} |
| 127 | + onChange={handleChange} |
| 128 | + required |
| 129 | + rows={4} |
| 130 | + placeholder="Write your message here..." |
| 131 | + className="bg-white/30 dark:bg-black/30 placeholder:text-slate-500 dark:placeholder:text-slate-400 focus-visible:ring-pink-500" |
| 132 | + /> |
| 133 | + </div> |
| 134 | + |
| 135 | + <Button |
| 136 | + type="submit" |
| 137 | + className="w-full bg-slate-900 text-white hover:bg-slate-800 shadow-md" |
| 138 | + disabled={loading} |
| 139 | + > |
| 140 | + {loading ? "Sending..." : "Send Message"} |
| 141 | + </Button> |
| 142 | + </form> |
| 143 | + </CardContent> |
| 144 | + </Card> |
| 145 | + </motion.div> |
| 146 | + </div> |
| 147 | + </AuroraBackground> |
| 148 | + <Footer /> |
| 149 | + </> |
| 150 | + ) |
| 151 | +} |
0 commit comments