diff --git a/.env b/.env new file mode 100644 index 0000000..33b4b24 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +ZOHO_PASS=qKppXZmPRR8q \ No newline at end of file diff --git a/app/api/health/route.ts b/app/api/health/route.ts deleted file mode 100644 index e8fd8c5..0000000 --- a/app/api/health/route.ts +++ /dev/null @@ -1,3 +0,0 @@ -export async function GET() { - return Response.json({ status: "ok" }) -} diff --git a/app/api/routes/mailTransporter.ts b/app/api/routes/mailTransporter.ts new file mode 100644 index 0000000..2a388d3 --- /dev/null +++ b/app/api/routes/mailTransporter.ts @@ -0,0 +1,21 @@ +const nodemailer = require("nodemailer") + +export interface MailOptions { + from: string + to: string +} + +export const transporter = nodemailer.createTransport({ + host: "smtp.zoho.com", + port: 465, + secure: true, + auth: { + user: "keshawa.vizolelabs.com", + pass: process.env.ZOHO_PASS, + }, +}) + +export const mailOptions: MailOptions = { + from: "Keshawa Anuhas ", + to: "Keshawa Anuhas ", +} diff --git a/app/api/routes/route.ts b/app/api/routes/route.ts new file mode 100644 index 0000000..6cbd43a --- /dev/null +++ b/app/api/routes/route.ts @@ -0,0 +1,19 @@ +import { mailOptions, transporter } from "./mailTransporter" + +import { NextResponse } from "next/server" + +export async function post(req: any) { + const data = await req.json() + + try { + await transporter.sendMail({ + ...mailOptions, + subject: data.subject, + text: `Email: ${data.email}\n\n${data.message}`, + }) + return NextResponse.json({ success: true }) + } catch (error: any) { + console.error(error) + return NextResponse.json({ error: error.message }, { status: error.status }) + } +} diff --git a/components/Button/Button.tsx b/components/Button/Button.tsx index 980e86c..a8d8b69 100644 --- a/components/Button/Button.tsx +++ b/components/Button/Button.tsx @@ -88,7 +88,7 @@ const button = cva(["inline-flex", "items-center", "rounded-xl", "text-center", export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { underline?: boolean - href: string + href?: string } export function Button({ className, intent, size, underline, ...props }: ButtonProps) { diff --git a/components/ContactUs/ContactUs.tsx b/components/ContactUs/ContactUs.tsx index c4ae774..dc9a2d9 100644 --- a/components/ContactUs/ContactUs.tsx +++ b/components/ContactUs/ContactUs.tsx @@ -1,6 +1,58 @@ +"use client" + import { Button } from "components/Button/Button" +import { useState } from "react" import MoveUpWhenVisible from "utils/ScrollAnimations/MoveUpOnScroll" + +interface ResponseData { + success: boolean + error: string +} + export default function ContactUs() { + const [formData, setFormData] = useState({ + email: "", + subject: "", + message: "", + }) + + const [submiting, setSubmiting] = useState(false) + + const handleInputChange = (e: React.ChangeEvent) => { + const { name, value } = e.target + + setFormData({ + ...formData, + [name]: value, + }) + } + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + setSubmiting(true) + + const response = await fetch("/api/mail", { + method: "POST", + headers: { + "Content-Type": "application/json", + accept: "application/json", + }, + body: JSON.stringify(formData), + }) + + //const { success, error }: { success: any; error: any } = await response.json() + + const { success, error } = (await response.json()) as ResponseData + + if (success) { + alert("Message sent!") + } else { + alert(error) + } + + setSubmiting(false) + } + return (
@@ -15,7 +67,7 @@ export default function ContactUs() {

-
+