Skip to content

Commit 2b3746a

Browse files
authored
Merge pull request #39 from whysosaket/main
Added Newsletter Service
2 parents c888fa2 + 0b01040 commit 2b3746a

12 files changed

+250
-21
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/.env
2+
**/.DS_Store
3+
**/node_modules

Diff for: my-app/package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: my-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"react-carousel-minimal": "^1.3.4",
1414
"react-dom": "^18.1.0",
1515
"react-helmet": "^6.1.0",
16+
"react-icons": "^5.3.0",
1617
"react-router-dom": "^6.3.0",
1718
"react-scripts": "5.0.1",
1819
"react-secure-storage": "^1.2.2",

Diff for: my-app/src/App.jsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ import Community from "./pages/Community";
66
import ContactForm from "./pages/Contact";
77
import Events from "./pages/Events";
88
import Base from "./layouts/Base";
9+
import Subscribe from "./components/Subscribe";
10+
import { useState } from "react";
911

1012
export default function App() {
13+
const [isVisible, setIsVisible] = useState(false);
14+
15+
const handleSetVisible = (value)=>{
16+
setIsVisible(value);
17+
};
18+
1119
return (
1220
<div className="bg-primary">
21+
{isVisible&&<Subscribe handle={handleSetVisible} />}
1322
<BrowserRouter>
1423
<Base>
1524
<Routes>
16-
<Route path="/" element={<Home />} />
17-
<Route path="/about-us" element={<About />} />
25+
<Route path="/" element={<Home handle={handleSetVisible} />} />
26+
<Route path="/about-us" element={<About handle={handleSetVisible} />} />
1827
<Route path="/community" element={<Community />} />
1928
<Route path="/events" element={<Events />} />
2029
<Route path="/contact-us" element={<ContactForm />} />

Diff for: my-app/src/components/Newsletter.jsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import React from "react";
2-
import siteConfig from "../site.config";
32

4-
export default function Newsletter() {
3+
export default function Newsletter(props) {
54
return (
5+
<>
66
<section className="py-16 lg:py-32 bg-[#0c1b38]">
77
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
88
<div className="max-w-xl mx-auto text-center">
99
<h1 className="text-4xl tracking-tight font-extrabold text-pastel sm:text-5xl mb-8">
1010
Join our monthly newsletter
1111
</h1>
12-
<a
13-
href={siteConfig.newsletterUrl}
12+
<button
1413
className="w-full max-w-sm mx-auto flex items-center justify-center px-8 py-2 border border-transparent text-lg font-semibold rounded-lg text-slate-800 bg-secondary hover:scale-105 will-change-transform transition-transform md:py-4 md:text-lg md:px-10"
15-
target="_blank"
16-
rel="noreferrer"
14+
onClick={()=>props.handle(true)}
1715
>
1816
Subscribe
19-
</a>
17+
</button>
2018
</div>
2119
</div>
2220
</section>
21+
</>
2322
);
2423
}

Diff for: my-app/src/components/Subscribe.jsx

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import React, { useState } from 'react'
2+
import Toastify from "toastify-js";
3+
import "toastify-js/src/toastify.css";
4+
import { RxCross2 } from "react-icons/rx";
5+
import {motion} from "framer-motion";
6+
import { API_URL } from '../lib/constants';
7+
8+
const Subscribe = (props) => {
9+
const [name, setName] = useState("");
10+
const [email, setEmail] = useState("");
11+
const [reg, setReg] = useState("");
12+
13+
const handleSend = async () => {
14+
if (name === "" || email === "" || reg === "") {
15+
Toastify({
16+
text: "Form can't be empty!",
17+
duration: 3000,
18+
backgroundColor: "#56ccf2",
19+
stopOnFocus: true,
20+
position: "right",
21+
}).showToast();
22+
return;
23+
}
24+
25+
try {
26+
const response = await fetch(`${API_URL}/subscribe/subscribe`, {
27+
method: "POST",
28+
body: JSON.stringify({
29+
name: name,
30+
email: email,
31+
reg: reg,
32+
}),
33+
headers: {
34+
"Content-type": "application/json; charset=UTF-8",
35+
},
36+
});
37+
38+
if (response.status === 200) {
39+
const result = await response.json(); // Assuming the response is in JSON format
40+
Toastify({
41+
text: result.message || "Subscription successful!", // Adjust according to your API response
42+
duration: 3000,
43+
backgroundColor: "#56ccf2",
44+
stopOnFocus: true,
45+
position: "right",
46+
}).showToast();
47+
setName("");
48+
setEmail("");
49+
setReg("");
50+
props.handle(false);
51+
} else {
52+
Toastify({
53+
text: "Something went wrong!",
54+
duration: 3000,
55+
backgroundColor: "#ff0000",
56+
stopOnFocus: true,
57+
position: "right",
58+
}).showToast();
59+
}
60+
} catch (err) {
61+
console.error(err);
62+
Toastify({
63+
text: "An error occurred!",
64+
duration: 3000,
65+
backgroundColor: "#ff0000",
66+
stopOnFocus: true,
67+
position: "right",
68+
}).showToast();
69+
}
70+
};
71+
72+
73+
return (
74+
<div
75+
className='bg-black/10 backdrop-blur-xl flex justify-center align-middle text-white fixed h-screen w-screen z-50'>
76+
<motion.div
77+
initial={{opacity: 0, scale: 0.8}}
78+
animate={{opacity: 1, scale: 1}}
79+
transition={{duration: 0.2}}
80+
className='m-auto w-5/6 md:w-full'>
81+
<div className='flex justify-end md:w-1/2 mx-auto'>
82+
<RxCross2 onClick={()=> props.handle(false)} size={32} className="cursor-pointer hover:scale-[1.2] a" />
83+
</div>
84+
<h1 className='text-4xl text-center my-4'>Subscribe to Our Newsletter</h1>
85+
<div className="grid grid-cols-1 gap-6 lg:w-1/2 mx-auto">
86+
<label className="block">
87+
<span className="text-slate-400">Full name</span>
88+
<input
89+
type="text"
90+
className="mt-1 block w-full rounded-md border-secondary text-pastel shadow-sm focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
91+
placeholder="John Doe"
92+
value={name}
93+
onChange={(e) => setName(e.target.value)}
94+
/>
95+
</label>
96+
<label className="block">
97+
<span className="text-slate-400">Email address</span>
98+
<input
99+
type="email"
100+
className="mt-1 block w-full rounded-md border-secondary shadow-sm text-pastel focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
101+
placeholder="[email protected]"
102+
value={email}
103+
onChange={(e) => setEmail(e.target.value)}
104+
/>
105+
</label>
106+
<label className="block">
107+
<span className="text-slate-400">Registration Number</span>
108+
<input
109+
type="text"
110+
className="mt-1 block w-full rounded-md border-secondary shadow-sm text-pastel focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
111+
placeholder="214100****"
112+
value={reg}
113+
onChange={(e) => setReg(e.target.value)}
114+
/>
115+
</label>
116+
<button
117+
onClick={handleSend}
118+
className="w-full mx-auto flex items-center justify-center px-8 py-2 border border-transparent text-lg font-semibold rounded-lg text-slate-800 bg-secondary hover:scale-105 will-change-transform transition-transform md:py-3 md:text-lg md:px-10"
119+
>
120+
Subscribe
121+
</button>
122+
</div>
123+
</motion.div>
124+
</div>
125+
)
126+
}
127+
128+
export default Subscribe

Diff for: my-app/src/index.css

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ body{
1111
background-color: #0d1026
1212
}
1313

14+
.a{
15+
transition: all 0.4s;
16+
}
17+
18+
html {
19+
overflow: scroll;
20+
overflow-x: hidden;
21+
}
22+
::-webkit-scrollbar {
23+
width: 0; /* Remove scrollbar space */
24+
background: transparent; /* Optional: just make scrollbar invisible */
25+
}
26+
/* Optional: show position indicator in red */
27+
::-webkit-scrollbar-thumb {
28+
background: #131313;
29+
}
30+
1431
@tailwind components;
1532
@tailwind utilities;
1633

Diff for: my-app/src/pages/About.jsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from "react";
22
import GroupMembers from "../assets/images/about2.png";
3-
import siteConfig from "../site.config";
43

5-
const About = () => {
4+
const About = (props) => {
65
return (
76
<section className="pb-12">
87
<div className="flex items-center justify-center">
@@ -30,14 +29,12 @@ const About = () => {
3029
<h2 className="mb-6 text-3xl text-center tracking-tight font-bold sm:text-4xl text-white mt-28">
3130
Join our monthly newsletter
3231
</h2>
33-
<a
34-
href={siteConfig.newsletterUrl}
32+
<button
33+
onClick={()=>props.handle(true)}
3534
className="w-full max-w-xs mx-auto flex items-center justify-center px-8 py-2 border border-transparent text-lg font-semibold rounded-lg text-slate-800 bg-secondary hover:scale-105 will-change-transform transition-transform md:py-3 md:text-lg md:px-4"
36-
target="_blank"
37-
rel="noreferrer"
3835
>
3936
Subscribe
40-
</a>
37+
</button>
4138
</div>
4239
</div>
4340
</section>

Diff for: my-app/src/pages/Home.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import Newsletter from "../components/Newsletter";
44
import Statistics from "../components/Statistics";
55
import Testimonial from "../components/Testimonial";
66

7-
const Home = () => {
7+
const Home = (props) => {
88
return (
99
<>
1010
<Hero />
1111
<Statistics />
1212
<Testimonial />
13-
<Newsletter />
13+
<Newsletter handle={props.handle} />
1414
</>
1515
);
1616
};

Diff for: my-app/src/site.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const siteConfig = {
1515
titleTemplate: "%s - Codex",
1616
description: shared.description,
1717
stats: {
18-
members: 100,
19-
commits: 2.1,
20-
projects: 35,
18+
members: 120,
19+
commits: 2.3,
20+
projects: 38,
2121
workshops: 18,
2222
},
2323
newsletterUrl: "https://docs.google.com/forms/d/e/1FAIpQLSdOp_wsPsjwFvxhSRECAxBsUGeL2s4cjJ1SghNLgNPg7f8bHQ/viewform",

Diff for: package-lock.json

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"react-icons": "^5.3.0"
4+
}
5+
}

0 commit comments

Comments
 (0)