11import { useState } from 'react' ;
22import { Link } from 'react-router-dom' ;
33import emailjs from '@emailjs/browser' ;
4+ import toast from 'react-hot-toast' ;
45import {
56 FaGithub ,
67 FaTwitter ,
@@ -13,33 +14,38 @@ import {
1314
1415function Footer ( ) {
1516 const [ email , setEmail ] = useState ( '' ) ;
16-
17+ const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
1718 const handleSubscribe = async (
1819 e : React . FormEvent < HTMLFormElement >
1920) => {
2021 e . preventDefault ( ) ;
2122
2223 if ( ! email ) {
23- alert ( 'Please enter a valid email' ) ;
24+ toast . error ( 'Please enter a valid email' ) ;
2425 return ;
2526 }
2627
28+ setIsSubmitting ( true ) ;
29+
2730 try {
28- await emailjs . send (
29- import . meta. env . VITE_EMAILJS_SERVICE_ID ,
30- import . meta. env . VITE_EMAILJS_TEMPLATE_ID ,
31- {
32- user_email : email ,
33- } ,
34- {
35- publicKey : import . meta. env . VITE_EMAILJS_PUBLIC_KEY ,
36- }
37- ) ;
38- alert ( 'Subscribed successfully!' ) ;
31+ await emailjs . send (
32+ import . meta. env . VITE_EMAILJS_SERVICE_ID ,
33+ import . meta. env . VITE_EMAILJS_TEMPLATE_ID ,
34+ {
35+ user_email : email ,
36+ } ,
37+ {
38+ publicKey : import . meta. env . VITE_EMAILJS_PUBLIC_KEY ,
39+ }
40+ ) ;
41+
42+ toast . success ( 'Subscribed successfully!' ) ;
3943 setEmail ( '' ) ;
4044 } catch ( error ) {
4145 console . error ( error ) ;
42- alert ( 'Subscription failed. Please try again.' ) ;
46+ toast . error ( 'Subscription failed. Please try again.' ) ;
47+ } finally {
48+ setIsSubmitting ( false ) ;
4349 }
4450} ;
4551
@@ -142,23 +148,27 @@ function Footer() {
142148 transition-all
143149 "
144150 />
145-
146- < button
147- type = "submit"
148- className = "
149- px-5 py-3 text-sm font-bold
150- bg-blue-600 hover:bg-blue-700
151- text-white rounded-xl shadow-sm
152- active:scale-[0.98]
153- transition-all duration-300
154- hover:shadow-lg hover:shadow-blue-500/20
155- flex items-center justify-center gap-1.5
156- whitespace-nowrap
157- "
158- >
159- < span > Subscribe</ span >
160- < FaArrowRight className = "h-3.5 w-3.5" />
161- </ button >
151+ < button
152+ type = "submit"
153+ disabled = { isSubmitting }
154+ className = "
155+ px-5 py-3 text-sm font-bold
156+ bg-blue-600 hover:bg-blue-700
157+ text-white rounded-xl shadow-sm
158+ active:scale-[0.98]
159+ transition-all duration-300
160+ hover:shadow-lg hover:shadow-blue-500/20
161+ flex items-center justify-center gap-1.5
162+ whitespace-nowrap
163+ disabled:opacity-50 disabled:cursor-not-allowed
164+ "
165+ >
166+ < span >
167+ { isSubmitting ? 'Subscribing...' : 'Subscribe' }
168+ </ span >
169+
170+ < FaArrowRight className = "h-3.5 w-3.5" />
171+ </ button >
162172 </ form >
163173 </ div >
164174 </ div >
0 commit comments