Skip to content

Commit 36eb604

Browse files
Add error handling for newsletter subscription and enhance footer styles
1 parent 7cfe0fb commit 36eb604

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

src/theme/Footer/Layout/enhanced-footer.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,17 @@ html[data-theme='light'] .enhanced-footer {
13841384
font-weight: 500;
13851385
}
13861386

1387+
.newsletter-input.input-error {
1388+
border-color: #e53e3e;
1389+
}
1390+
1391+
.error-text {
1392+
margin-top: 4px;
1393+
font-size: 0.85rem;
1394+
color: #e53e3e;
1395+
}
1396+
1397+
13871398
/* Responsive Design */
13881399
@media (max-width: 1200px) {
13891400
.footer-links-grid {

src/theme/Footer/Layout/index.tsx

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React, {type ReactNode, useState, useEffect} from 'react';
1+
import React, { type ReactNode, useState, useEffect } from "react";
22
import Link from "@docusaurus/Link";
3-
import type {Props} from '@theme/Footer/Layout';
4-
import './enhanced-footer.css';
5-
import Counter from './Counter';
3+
import type { Props } from "@theme/Footer/Layout";
4+
import "./enhanced-footer.css";
5+
import Counter from "./Counter";
66
import { createPortal } from "react-dom";
77

8-
98
// Dynamic stats interface
109
interface FooterStats {
1110
activeUsers: string;
@@ -22,14 +21,15 @@ export default function FooterLayout({
2221
}: Props): ReactNode {
2322
const [currentYear, setCurrentYear] = useState(new Date().getFullYear());
2423
const [stats, setStats] = useState<FooterStats>({
25-
activeUsers: '50K+',
26-
tutorials: '200+',
27-
successRate: '95%',
28-
supportHours: '24/7'
24+
activeUsers: "50K+",
25+
tutorials: "200+",
26+
successRate: "95%",
27+
supportHours: "24/7",
2928
});
30-
const [email, setEmail] = useState('');
29+
const [email, setEmail] = useState("");
3130
const [isSubscribed, setIsSubscribed] = useState(false);
3231
const [showToast, setShowToast] = useState(false);
32+
const [error, setError] = useState("");
3333

3434
useEffect(() => {
3535
// Simulate real-time stats updates
@@ -44,10 +44,10 @@ export default function FooterLayout({
4444
activeUsers: `${Math.floor((baseUsers + randomGrowth) / 1000)}K+`,
4545
tutorials: `${baseTutorials + Math.floor(randomGrowth / 10)}+`,
4646
successRate: `${95 + Math.floor(Math.random() * 3)}%`,
47-
supportHours: '24/7'
47+
supportHours: "24/7",
4848
});
4949
} catch (error) {
50-
console.log('Using fallback stats');
50+
console.log("Using fallback stats");
5151
}
5252
};
5353

@@ -59,21 +59,32 @@ export default function FooterLayout({
5959

6060
const handleSubscribe = (e: React.FormEvent) => {
6161
e.preventDefault();
62-
if (email) {
63-
setIsSubscribed(true);
64-
setShowToast(true);
65-
66-
// Hide toast after 3 seconds
67-
setTimeout(() => {
68-
setShowToast(false);
69-
}, 3000);
70-
71-
// Reset form after 3 seconds
72-
setTimeout(() => {
73-
setIsSubscribed(false);
74-
setEmail('');
75-
}, 3000);
62+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
63+
64+
if (!email) {
65+
setError("Email is required");
66+
return;
67+
}
68+
69+
if (!emailRegex.test(email)) {
70+
setError("Please enter a valid email address");
71+
return;
7672
}
73+
74+
setError("");
75+
setIsSubscribed(true);
76+
setShowToast(true);
77+
78+
// Hide toast after 3 seconds
79+
setTimeout(() => {
80+
setShowToast(false);
81+
}, 3000);
82+
83+
// Reset form after 3 seconds
84+
setTimeout(() => {
85+
setIsSubscribed(false);
86+
setEmail("");
87+
}, 3000);
7788
};
7889

7990
return (
@@ -355,6 +366,7 @@ export default function FooterLayout({
355366
>
356367
{isSubscribed ? "✓ Subscribed!" : "Subscribe Now →"}
357368
</button>
369+
{error && <p className="error-text">{error}</p>}
358370
</form>
359371
<div className="newsletter-stats">
360372
<span className="newsletter-stat">
@@ -461,4 +473,4 @@ export default function FooterLayout({
461473
</div>
462474
</footer>
463475
);
464-
}
476+
}

0 commit comments

Comments
 (0)