1- import React , { useState } from "react" ;
1+ import React , { FormEvent , useState } from "react" ;
22import Button from "../components/Buttons" ;
33import { MoveRight , ChevronLeft , ChevronRight } from "lucide-react" ;
44import Imageone from "../assets/images/Frame-10.png" ;
@@ -12,20 +12,40 @@ import Diamond from "../assets/svgs/diamond.svg";
1212import Testimonial from "../assets/images/Frame-3676.png" ;
1313import TestimonialsSection from "../components/TestimonialCarousel" ;
1414import Zigzag from "../assets/svgs/zigzag.svg" ;
15- import useFAQSQuery from "../../hooks/useFaqsQuery" ;
1615import { Helmet } from "react-helmet" ;
1716import 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
2122const 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