Skip to content

Commit

Permalink
Merge pull request #1 from judygab/1.6-customizations
Browse files Browse the repository at this point in the history
1.6 customizations
  • Loading branch information
judygab authored Oct 10, 2023
2 parents 0db5d90 + 2e99720 commit a240578
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 61 deletions.
17 changes: 11 additions & 6 deletions src/app/api/send/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import { NextResponse } from "next/server";
import { Resend } from "resend";

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

export async function POST() {
export async function POST(req, res) {
const { email, subject, message } = await req.json();
console.log(email, subject, message);
try {
const data = await resend.emails.send({
from: "",
to: [""],
subject: "Hello world",
from: fromEmail,
to: [fromEmail, email],
subject: subject,
react: (
<>
<p>Email Body</p>
<h1>{subject}</h1>
<p>Thank you for contacting us!</p>
<p>New message submitted:</p>
<p>{message}</p>
</>
),
});

return NextResponse.json(data);
} catch (error) {
return NextResponse.json({ error });
Expand Down
148 changes: 95 additions & 53 deletions src/app/components/EmailSection.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import React from "react";
"use client";
import React, { useState } from "react";
import GithubIcon from "../../../public/github-icon.svg";
import LinkedinIcon from "../../../public/linkedin-icon.svg";
import Link from "next/link";
import Image from "next/image";

const EmailSection = () => {
const [emailSubmitted, setEmailSubmitted] = useState(false);

const handleSubmit = async (e) => {
e.preventDefault();
const data = {
email: e.target.email.value,
subject: e.target.subject.value,
message: e.target.message.value,
};
const JSONdata = JSON.stringify(data);
const endpoint = "/api/send";

// Form the request for sending data to the server.
const options = {
// The method is POST because we are sending data.
method: "POST",
// Tell the server we're sending JSON.
headers: {
"Content-Type": "application/json",
},
// Body of the request is the JSON data we created above.
body: JSONdata,
};

const response = await fetch(endpoint, options);
const resData = await response.json();

if (response.status === 200) {
console.log("Message sent.");
setEmailSubmitted(true);
}
};

return (
<section
id="contact"
Expand All @@ -30,59 +64,67 @@ const EmailSection = () => {
</Link>
</div>
</div>
<div className="z-10">
<form className="flex flex-col">
<div className="mb-6">
<label
htmlFor="email"
className="text-white block mb-2 text-sm font-medium"
>
Your email
</label>
<input
type="email"
id="email"
required
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="[email protected]"
/>
</div>
<div className="mb-6">
<label
htmlFor="subject"
className="text-white block text-sm mb-2 font-medium"
>
Subject
</label>
<input
type="text"
id="subject"
required
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="Just saying hi"
/>
</div>
<div className="mb-6">
<label
htmlFor="message"
className="text-white block text-sm mb-2 font-medium"
<div>
{emailSubmitted ? (
<p className="text-green-500 text-sm mt-2">
Email sent successfully!
</p>
) : (
<form className="flex flex-col" onSubmit={handleSubmit}>
<div className="mb-6">
<label
htmlFor="email"
className="text-white block mb-2 text-sm font-medium"
>
Your email
</label>
<input
name="email"
type="email"
id="email"
required
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="[email protected]"
/>
</div>
<div className="mb-6">
<label
htmlFor="subject"
className="text-white block text-sm mb-2 font-medium"
>
Subject
</label>
<input
name="subject"
type="text"
id="subject"
required
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="Just saying hi"
/>
</div>
<div className="mb-6">
<label
htmlFor="message"
className="text-white block text-sm mb-2 font-medium"
>
Message
</label>
<textarea
name="message"
id="message"
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="Let's talk about..."
/>
</div>
<button
type="submit"
className="bg-primary-500 hover:bg-primary-600 text-white font-medium py-2.5 px-5 rounded-lg w-full"
>
Message
</label>
<textarea
name="message"
id="message"
className="bg-[#18191E] border border-[#33353F] placeholder-[#9CA2A9] text-gray-100 text-sm rounded-lg block w-full p-2.5"
placeholder="Let's talk about..."
/>
</div>
<button
type="submit"
className="bg-primary-500 hover:bg-primary-600 text-white font-medium py-2.5 px-5 rounded-lg w-full"
>
Send Message
</button>
</form>
Send Message
</button>
</form>
)}
</div>
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Home() {
return (
<main className="flex min-h-screen flex-col bg-[#121212]">
<Navbar />
<div class="container mt-24 mx-auto px-12 py-4">
<div className="container mt-24 mx-auto px-12 py-4">
<HeroSection />
<AchievementsSection />
<AboutSection />
Expand Down
1 change: 0 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('tailwindcss').Config} */
const colors = require("tailwindcss/colors");

module.exports = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
Expand Down

0 comments on commit a240578

Please sign in to comment.