From 700839e520c89b65ddc799857e2072f427a39a55 Mon Sep 17 00:00:00 2001 From: RS Date: Fri, 4 Oct 2024 04:49:36 +0530 Subject: [PATCH 1/4] all --- src/components/ui/Footer.module.css | 4 +- src/components/ui/Footer.tsx | 146 ++++++++++++++++++---------- src/pages/api/subscribe.ts | 45 +++++++++ 3 files changed, 143 insertions(+), 52 deletions(-) create mode 100644 src/pages/api/subscribe.ts diff --git a/src/components/ui/Footer.module.css b/src/components/ui/Footer.module.css index fa95a07..64512f3 100644 --- a/src/components/ui/Footer.module.css +++ b/src/components/ui/Footer.module.css @@ -75,7 +75,7 @@ outline: none; } -.newsletter-right-container > .newsletter-email-container > form > p{ +.newsletter-right-container > .newsletter-email-container > form > button{ color: white; height: 3rem; font-size: 1rem; @@ -86,7 +86,7 @@ box-shadow: 0 .7065919983928324px .7065919983928324px -.625px #00000026,0 1.8065619053231785px 1.8065619053231785px -1.25px #00000025,0 3.6217592146567767px 3.6217592146567767px -1.875px #00000023,0 6.8655999097303715px 6.8655999097303715px -2.5px #00000020,0 13.646761411524492px 13.646761411524492px -3.125px #0000001b,0 30px 30px -3.75px #0000000d; } -.newsletter-right-container > .newsletter-email-container > form > p:hover{ +.newsletter-right-container > .newsletter-email-container > form > button:hover{ background-color: var(--slate-black); cursor: pointer; } diff --git a/src/components/ui/Footer.tsx b/src/components/ui/Footer.tsx index 1d3e0c3..41ffc2f 100644 --- a/src/components/ui/Footer.tsx +++ b/src/components/ui/Footer.tsx @@ -1,54 +1,100 @@ -import styles from "./Footer.module.css" +"use client"; + +import { useState } from 'react'; +import styles from "./Footer.module.css"; import Link from "next/link"; export default function Footer() { - return ( - - ); + const [email, setEmail] = useState(''); + const [message, setMessage] = useState(''); + const [loading, setLoading] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setMessage(''); + setLoading(true); + + try { + const res = await fetch('/api/subscribe', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email }), // Only send the email + }); + + const data = await res.json(); + + if (res.status === 200) { + setMessage('Thank you for subscribing! A welcome email has been sent.'); + } else { + setMessage(data.error || 'Something went wrong'); + } + } catch (error) { + console.error(error); + setMessage('Something went wrong'); + } finally { + setLoading(false); + } + }; + + return ( +
+
+
+

Join the newsletter

+

Get the latest insights and updates straight to your inbox.

+
+
+
+
+ setEmail(e.target.value)} + required + /> + +
+ {message &&

{message}

} +
+

Your privacy is important. We never share your email.

+
+
+ + {/* Footer bottom section */} +
+ {/* Left part of the footer */} +
+

UTTARAKHAND CULTURE

+

Our aim is to ensure that this invaluable heritage is passed down to future generations.

+
+ + {/* Right part of the footer */} +
+
+

Socials

+ LinkedIn + Github + Contact us +
+
+

Contribution

+ Issues + About us + Contribution +
+
+
+ + {/* Copyright section */} +
+

© 2024 Uttarakhand Culture. All rights reserved.

+
+
+ ); } diff --git a/src/pages/api/subscribe.ts b/src/pages/api/subscribe.ts new file mode 100644 index 0000000..a44fedf --- /dev/null +++ b/src/pages/api/subscribe.ts @@ -0,0 +1,45 @@ +import nodemailer from 'nodemailer'; +import type { NextApiRequest, NextApiResponse } from 'next'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method === 'POST') { + const { email } = req.body; // Only expect the email + + if (!email) { + return res.status(400).json({ error: 'Missing email' }); + } + + try { + // Configure Nodemailer transport (SMTP settings) + const transporter = nodemailer.createTransport({ + host: 'smtp.gmail.com', + port: 587, + secure: false, + auth: { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASSWORD, + }, + }); + + // Email data + const mailOptions = { + from: process.env.SMTP_USER, + to: email, + subject: 'Welcome to our Uttarakhand Culture Newsletter!', + text: 'Thank you for subscribing to our Uttarakhand Culture! Stay tuned for updates...', + html: '

Thank you for subscribing to our newsletter! Stay tuned for updates.

', + }; + + // Send email + await transporter.sendMail(mailOptions); + res.status(200).json({ message: 'Email sent successfully' }); + + } catch (error) { + console.error('Error sending email:', error); + res.status(500).json({ error: 'Error sending email' }); + } + + } else { + res.status(405).json({ message: 'Method not allowed' }); + } +} From 21cfb58f4516876cf55f259c3fa2d4893bfa5b34 Mon Sep 17 00:00:00 2001 From: RS Date: Fri, 4 Oct 2024 04:53:33 +0530 Subject: [PATCH 2/4] finall --- src/components/ui/Footer.tsx | 2 +- src/pages/api/subscribe.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/ui/Footer.tsx b/src/components/ui/Footer.tsx index 41ffc2f..d5d2517 100644 --- a/src/components/ui/Footer.tsx +++ b/src/components/ui/Footer.tsx @@ -20,7 +20,7 @@ export default function Footer() { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ email }), // Only send the email + body: JSON.stringify({ email }), }); const data = await res.json(); diff --git a/src/pages/api/subscribe.ts b/src/pages/api/subscribe.ts index a44fedf..4feff29 100644 --- a/src/pages/api/subscribe.ts +++ b/src/pages/api/subscribe.ts @@ -3,14 +3,13 @@ import type { NextApiRequest, NextApiResponse } from 'next'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === 'POST') { - const { email } = req.body; // Only expect the email + const { email } = req.body; if (!email) { return res.status(400).json({ error: 'Missing email' }); } try { - // Configure Nodemailer transport (SMTP settings) const transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', port: 587, @@ -21,7 +20,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, }); - // Email data const mailOptions = { from: process.env.SMTP_USER, to: email, @@ -30,7 +28,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) html: '

Thank you for subscribing to our newsletter! Stay tuned for updates.

', }; - // Send email + await transporter.sendMail(mailOptions); res.status(200).json({ message: 'Email sent successfully' }); From b2370ec2872f9ef0a038fa7002cae93ad47d13a1 Mon Sep 17 00:00:00 2001 From: Ritesh Sharma <119002315+RiteshS1@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:40:50 +0530 Subject: [PATCH 3/4] Update package-lock.json --- package-lock.json | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/package-lock.json b/package-lock.json index 76c4947..67c5e5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,15 @@ "version": "0.1.0", "dependencies": { "@vercel/speed-insights": "^1.0.12", + "axios": "^1.7.7", "next": "14.2.5", + "nodemailer": "^6.9.15", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@types/node": "^20", + "@types/nodemailer": "^6.4.16", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", @@ -386,6 +389,16 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/nodemailer": { + "version": "6.4.16", + "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.16.tgz", + "integrity": "sha512-uz6hN6Pp0upXMcilM61CoKyjT7sskBoOWpptkjjJp8jIMlTdc3xG01U7proKkXzruMS4hS0zqtHNkNPFB20rKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/prop-types": { "version": "15.7.12", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", @@ -820,6 +833,12 @@ "integrity": "sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -844,6 +863,17 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.1.1.tgz", @@ -978,6 +1008,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1150,6 +1192,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -1916,6 +1967,26 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -1941,6 +2012,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2888,6 +2973,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2996,6 +3102,15 @@ } } }, + "node_modules/nodemailer": { + "version": "6.9.15", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.15.tgz", + "integrity": "sha512-AHf04ySLC6CIfuRtRiEYtGEXgRfa6INgWGluDhnxTZhHSKvrBu7lc1VVchQ0d8nPc4cFaZoPq8vkyNoZr0TpGQ==", + "license": "MIT-0", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -3322,6 +3437,12 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", From f24aabed8743a254a0c5a35174cb71e218a44c33 Mon Sep 17 00:00:00 2001 From: Ritesh Sharma <119002315+RiteshS1@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:41:19 +0530 Subject: [PATCH 4/4] Update package.json --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 98266d6..445260a 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,15 @@ }, "dependencies": { "@vercel/speed-insights": "^1.0.12", + "axios": "^1.7.7", "next": "14.2.5", + "nodemailer": "^6.9.15", "react": "^18", "react-dom": "^18" }, "devDependencies": { "@types/node": "^20", + "@types/nodemailer": "^6.4.16", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8",