Skip to content

Commit efcc72b

Browse files
authored
Merge pull request #68 from blockfuselabs/frontend-newsletter-subscription
Implement Newsletter Subscription
2 parents 277a5ab + bf5e371 commit efcc72b

File tree

4 files changed

+79
-18
lines changed

4 files changed

+79
-18
lines changed

blockfuse-website/services/http.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class BaseUrl {
105105
}
106106
}
107107

108-
async httpPostContactUs(data) {
108+
async httpPostContactUs(data: any) {
109109
try {
110110
const response = await AxiosInstance.post(routes.CONTACTUS, data);
111111
console.log("API Response:", response.data);
@@ -116,7 +116,7 @@ class BaseUrl {
116116
}
117117
}
118118

119-
async httpSubmitWeb2Application(formData) {
119+
async httpSubmitWeb2Application(formData: any) {
120120
try {
121121
const response = await AxiosInstance.post(routes.WEB2, formData, {
122122
headers: { 'Content-Type': 'multipart/form-data' },
@@ -128,10 +128,10 @@ class BaseUrl {
128128
}
129129
}
130130

131-
async httpSubmitWeb3Application(formData) {
131+
async httpSubmitWeb3Application(formData: any) {
132132
try {
133133
const response = await AxiosInstance.post(routes.WEB3, formData, {
134-
headers: { 'Content-Type': 'multipart/form-data' },
134+
headers: { 'Content-Type': 'application/json' },
135135
});
136136
return response.data;
137137
} catch (error) {
@@ -191,6 +191,18 @@ class BaseUrl {
191191
throw error;
192192
}
193193
};
194+
195+
async httpNewsletterSubscription(formData: any) {
196+
try {
197+
const response = await AxiosInstance.post(routes.NEWSLETTER, formData, {
198+
headers: { 'Content-Type': 'application/json' },
199+
});
200+
return response;
201+
} catch (error) {
202+
console.error('Submission error:', error);
203+
throw error;
204+
}
205+
}
194206
}
195207

196208
export default new BaseUrl();

blockfuse-website/services/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export default Object.freeze({
1313
TEAMARTICLES: "team/articles",
1414
CONTACTUS: "/contact-us",
1515
WEB2: "/web2",
16-
WEB3: "/web3"
16+
WEB3: "/web3",
17+
NEWSLETTER: "/newsletter/"
1718
});

blockfuse-website/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import ScrollToTopButton, { useScrollToTop } from './components/ScrollToTopButto
3131

3232
import { Web3Provider } from "./components/WalletConnect/Web3Provider";
3333
import { ConnectKitButton } from "connectkit";
34+
import { ToastContainer } from 'react-toastify';
3435

3536

3637

@@ -43,6 +44,7 @@ function App() {
4344
<ScrollToTopButton />
4445
<Router>
4546
<div className="App noise dark:bg-[#131316] bg-[#fafafa] flex flex-col min-h-screen">
47+
<ToastContainer />
4648
{/* Navbar */}
4749
<Navbar />
4850

blockfuse-website/src/pages/Hero.tsx

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { FormEvent, useState } from "react";
22
import Button from "../components/Buttons";
33
import { MoveRight, ChevronLeft, ChevronRight } from "lucide-react";
44
import Imageone from "../assets/images/Frame-10.png";
@@ -12,20 +12,40 @@ import Diamond from "../assets/svgs/diamond.svg";
1212
import Testimonial from "../assets/images/Frame-3676.png";
1313
import TestimonialsSection from "../components/TestimonialCarousel";
1414
import Zigzag from "../assets/svgs/zigzag.svg";
15-
import useFAQSQuery from "../../hooks/useFaqsQuery";
1615
import { Helmet } from "react-helmet";
1716
import PartnerCarousel from "../components/PartnerCarousel"
18-
17+
import BaseUrl from "../../services/http";
18+
import { toast } from "react-toastify";
19+
import { Loader2 } from "lucide-react";
1920

2021

2122
const Hero = () => {
2223
const [email, setEmail] = useState("");
24+
const [isSubmitting, setIsSubmitting] = useState(false);
25+
26+
const handleSubmit = async() => {
27+
setIsSubmitting(true);
28+
try {
29+
console.log("Subscription submitted:", email);
30+
if(!email) {
31+
throw new Error("Please submit an email.")
32+
}
2333

24-
const handleSubmit = (e) => {
25-
e.preventDefault();
26-
console.log("Subscription submitted:", email);
27-
setEmail("");
34+
const response = await BaseUrl.httpNewsletterSubscription({email});
35+
if (response.status === 200 || response.status === 201) {
36+
toast.success("You have successfully subscribed to our newsletter.");
37+
setEmail("");
38+
} else {
39+
toast.error(response.statusText);
40+
}
41+
return;
42+
} catch(error) {
43+
toast.error(error as any)
44+
} finally {
45+
setIsSubmitting(false);
46+
}
2847
};
48+
2949
return (
3050
<>
3151
<Helmet>
@@ -495,7 +515,7 @@ const Hero = () => {
495515
</p>
496516
</div>
497517

498-
<form onSubmit={handleSubmit} className="space-y-3">
518+
<div className="space-y-3">
499519
<div className="flex justify-center">
500520
<input
501521
type="email"
@@ -507,17 +527,43 @@ const Hero = () => {
507527
/>
508528
</div>
509529
<div className="flex justify-center">
510-
<Button
511-
type="submit"
530+
<button
531+
type="button"
532+
onClick={(e) => {
533+
e.preventDefault();
534+
handleSubmit();
535+
}}
536+
className={`
537+
bg-gradient-to-r from-purple-600 to-purple-400
538+
hover:from-purple-700 hover:to-purple-500
539+
text-white
540+
py-3 px-6
541+
w-72
542+
transition-colors
543+
duration-300
544+
ease-in-out
545+
flex
546+
gap-3
547+
items-center
548+
justify-center
549+
`}
550+
disabled={isSubmitting}
512551
style={{
513552
width: "100%",
514553
maxWidth: "800px",
515554
}}
516555
>
517-
Subscribe
518-
</Button>
556+
{isSubmitting ? (
557+
<>
558+
<Loader2 className="animate-spin duration-300" style={{ animationDuration: '0.5s' }} size={18} />
559+
Submitting
560+
</>
561+
) : (
562+
"Subscribe"
563+
)}
564+
</button>
519565
</div>
520-
</form>
566+
</div>
521567
</div>
522568
</section>
523569
</main>

0 commit comments

Comments
 (0)