Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use server'

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

export async function sendContactEmail(formData: FormData) {
const company = formData.get('company') as string;
const name = formData.get('name') as string;
const email = formData.get('email') as string;
const phone = formData.get('phone') as string;
const message = formData.get('message') as string;

try {
const data = await resend.emails.send({
from: 'onboarding@resend.dev', // Use this default until you verify your own domain
to: 'shivampandey5106@gmail.com',
subject: `New Contact Form Submission from ${name}`,
html: `
<h2>New Inquiry</h2>
<p><strong>Company:</strong> ${company}</p>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Phone:</strong> ${phone}</p>
<p><strong>Message:</strong></p>
<p>${message}</p>
`,
});

return { success: true, data };
} catch (error) {
return { success: false, error };
}
}
57 changes: 42 additions & 15 deletions components/contact/page.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
"use client"; // Required for handling form submission

import Image from "next/image";
import { useState } from "react";
import { sendContactEmail } from "@/app/action"; // Adjust path if needed

export default function ContactPage() {
const [status, setStatus] = useState<"idle" | "submitting" | "success" | "error">("idle");

async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setStatus("submitting");

const formData = new FormData(event.currentTarget);
const result = await sendContactEmail(formData);

if (result.success) {
setStatus("success");
(event.target as HTMLFormElement).reset(); // Clear form
} else {
setStatus("error");
}
}

return (
<section className="relative min-h-screen bg-white py-10">

{/* WHITE FOREGROUND */}
<div className="relative mx-auto max-w-7xl overflow-hidden rounded-3xl bg-white border-25 border-red-600 shadow-xl">
<div className="flex flex-col lg:flex-row rounded-4xl">

{/* LEFT IMAGE SECTION */}
<div className="relative w-full lg:w-1/2 h-[300px] lg:h-auto">
<Image
src="/img-1.jpg" // put image in public folder
src="/img-1.jpg" // Ensure this image exists in /public
alt="Customer Support"
fill
className="object-cover"
priority
/>

{/* subtle red overlay */}
<div className="absolute inset-0 bg-red-600/10" />
</div>

{/* RIGHT FORM SECTION */}
<div className="w-full lg:w-1/2 flex items-center justify-center px-8 lg:px-16 py-14 bg-red-50">
<div className="w-full max-w-lg">

<h1 className="text-3xl font-bold text-red-600 mb-2">
Contact Us
</h1>
Expand All @@ -34,11 +51,11 @@ export default function ContactPage() {
filling out the form below.
</p>

<form className="space-y-5">

<form onSubmit={handleSubmit} className="space-y-5">
{/* Company Name */}
<input
type="text"
name="company" // Added name attribute
placeholder="Company Name *"
className="w-full rounded-full px-5 py-3 text-red-500 bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-red-500"
required
Expand All @@ -48,50 +65,60 @@ export default function ContactPage() {
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<input
type="text"
name="name" // Added name attribute
placeholder="Your Name *"
className="rounded-full px-5 py-3 text-red-500 bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-red-500"
required
/>
<input
type="email"
name="email" // Added name attribute
placeholder="Your Email *"
className="rounded-full px-5 py-3 text-red-500 bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-red-500"
required
/>
</div>

{/* Phone + Fax */}
<div className="grid grid-cols-1 gap-10">
{/* Phone */}
<div className="grid grid-cols-1 gap-10">
<input
type="tel"
name="phone" // Added name attribute
placeholder="Phone Number *"
className="rounded-full px-5 py-3 text-red-500 bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-red-500"
required
/>

</div>

{/* Message */}
<textarea
name="message" // Added name attribute
placeholder="Your Message"
rows={4}
className="w-full rounded-2xl px-5 py-3 text-red-500 bg-white border border-gray-300 focus:outline-none focus:ring-2 focus:ring-red-500"
/>

{/* Status Messages */}
{status === "success" && (
<p className="text-green-600 font-medium">Message sent successfully!</p>
)}
{status === "error" && (
<p className="text-red-600 font-medium">Failed to send message. Please try again.</p>
)}

{/* Submit Button */}
<button
type="submit"
className="w-full rounded-full bg-red-600 py-3 text-red-500 font-semibold text-white transition hover:bg-red-700"
disabled={status === "submitting"}
className="w-full rounded-full bg-red-600 py-3 text-white font-semibold transition hover:bg-red-700 disabled:opacity-50 disabled:cursor-not-allowed"
>
Send Message
{status === "submitting" ? "Sending..." : "Send Message"}
</button>

</form>
</div>
</div>

</div>
</div>
</section>
);
}
}
Loading