@@ -22,8 +22,9 @@ const information = [
2222
2323export default function TopFooter ( ) {
2424 const [ email , setEmail ] = useState ( '' ) ;
25+ const [ status , setStatus ] = useState ( 'idle' ) ; // 'idle' | 'loading' | 'success'
2526
26- const handleSubmit = ( e ) => {
27+ const handleSubmit = async ( e ) => {
2728 e . preventDefault ( ) ;
2829
2930 const isValidEmail = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( email . trim ( ) ) ;
@@ -33,15 +34,27 @@ export default function TopFooter() {
3334 return ;
3435 }
3536
36- // Simulate subscription success (e.g., API call here)
37- console . log ( 'Subscribed:' , email ) ;
37+ setStatus ( 'loading' ) ;
3838
39- // Show success toast notification
40- toast . success (
41- 'Thank you for subscribing! Your email has been received. You’ll now get our latest deals and discounts.'
42- ) ;
39+ try {
40+ // Simulate API call
41+ await new Promise ( ( res ) => setTimeout ( res , 2000 ) ) ;
4342
44- setEmail ( '' ) ;
43+ console . log ( 'Subscribed:' , email ) ;
44+ toast . success (
45+ 'Thank you for subscribing! Your email has been received. You’ll now get our latest deals and discounts.'
46+ ) ;
47+
48+ setStatus ( 'success' ) ;
49+ setEmail ( '' ) ;
50+
51+ // Reset back to normal button after 2 seconds
52+ setTimeout ( ( ) => setStatus ( 'idle' ) , 2000 ) ;
53+ } catch ( error ) {
54+ console . error ( error ) ;
55+ toast . error ( 'Something went wrong. Please try again.' ) ;
56+ setStatus ( 'idle' ) ;
57+ }
4558 } ;
4659
4760 return (
@@ -171,10 +184,51 @@ export default function TopFooter() {
171184 </ div >
172185 < button
173186 type = "submit"
174- className = "p-2 m-2 rounded-full bg-white text-neutral-900 transition cursor-pointer flex items-center justify-center"
187+ disabled = { status === 'loading' || status === 'success' }
188+ className = { `p-2 m-2 rounded-full bg-white text-neutral-900 transition-all duration-300 ease-in-out cursor-pointer flex items-center justify-center
189+ ${ status !== 'idle' ? 'w-10 h-10 p-0' : '' }
190+ ` }
175191 aria-label = "Subscribe"
176192 >
177- < ArrowRight className = "w-5 h-5 text-neutral-900" />
193+ { status === 'loading' ? (
194+ < svg
195+ className = "animate-spin h-5 w-5 text-neutral-900"
196+ xmlns = "http://www.w3.org/2000/svg"
197+ fill = "none"
198+ viewBox = "0 0 24 24"
199+ >
200+ < circle
201+ className = "opacity-25"
202+ cx = "12"
203+ cy = "12"
204+ r = "10"
205+ stroke = "currentColor"
206+ strokeWidth = "4"
207+ > </ circle >
208+ < path
209+ className = "opacity-75"
210+ fill = "currentColor"
211+ d = "M4 12a8 8 0 018-8v8H4z"
212+ > </ path >
213+ </ svg >
214+ ) : status === 'success' ? (
215+ < svg
216+ className = "h-5 w-5 text-neutral-900"
217+ xmlns = "http://www.w3.org/2000/svg"
218+ fill = "none"
219+ viewBox = "0 0 24 24"
220+ stroke = "currentColor"
221+ >
222+ < path
223+ strokeLinecap = "round"
224+ strokeLinejoin = "round"
225+ strokeWidth = "3"
226+ d = "M5 13l4 4L19 7"
227+ />
228+ </ svg >
229+ ) : (
230+ < ArrowRight className = "w-5 h-5 text-neutral-900" />
231+ ) }
178232 </ button >
179233 </ div >
180234 < p className = "mt-2 text-xs" >
0 commit comments