Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/theme/Footer/Layout/enhanced-footer.css
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,17 @@ html[data-theme='light'] .enhanced-footer {
font-weight: 500;
}

.newsletter-input.input-error {
border-color: #e53e3e;
}

.error-text {
margin-top: 4px;
font-size: 0.85rem;
color: #e53e3e;
}


/* Responsive Design */
@media (max-width: 1200px) {
.footer-links-grid {
Expand Down
66 changes: 39 additions & 27 deletions src/theme/Footer/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, {type ReactNode, useState, useEffect} from 'react';
import React, { type ReactNode, useState, useEffect } from "react";
import Link from "@docusaurus/Link";
import type {Props} from '@theme/Footer/Layout';
import './enhanced-footer.css';
import Counter from './Counter';
import type { Props } from "@theme/Footer/Layout";
import "./enhanced-footer.css";
import Counter from "./Counter";
import { createPortal } from "react-dom";


// Dynamic stats interface
interface FooterStats {
activeUsers: string;
Expand All @@ -22,14 +21,15 @@ export default function FooterLayout({
}: Props): ReactNode {
const [currentYear, setCurrentYear] = useState(new Date().getFullYear());
const [stats, setStats] = useState<FooterStats>({
activeUsers: '50K+',
tutorials: '200+',
successRate: '95%',
supportHours: '24/7'
activeUsers: "50K+",
tutorials: "200+",
successRate: "95%",
supportHours: "24/7",
});
const [email, setEmail] = useState('');
const [email, setEmail] = useState("");
const [isSubscribed, setIsSubscribed] = useState(false);
const [showToast, setShowToast] = useState(false);
const [error, setError] = useState("");

useEffect(() => {
// Simulate real-time stats updates
Expand All @@ -44,10 +44,10 @@ export default function FooterLayout({
activeUsers: `${Math.floor((baseUsers + randomGrowth) / 1000)}K+`,
tutorials: `${baseTutorials + Math.floor(randomGrowth / 10)}+`,
successRate: `${95 + Math.floor(Math.random() * 3)}%`,
supportHours: '24/7'
supportHours: "24/7",
});
} catch (error) {
console.log('Using fallback stats');
console.log("Using fallback stats");
}
};

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

const handleSubscribe = (e: React.FormEvent) => {
e.preventDefault();
if (email) {
setIsSubscribed(true);
setShowToast(true);

// Hide toast after 3 seconds
setTimeout(() => {
setShowToast(false);
}, 3000);

// Reset form after 3 seconds
setTimeout(() => {
setIsSubscribed(false);
setEmail('');
}, 3000);
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email regex pattern is defined inside the event handler and will be recreated on every form submission. Consider moving it outside the component or using a more comprehensive email validation library for better performance and accuracy.

Copilot uses AI. Check for mistakes.

if (!email) {
setError("Email is required");
return;
}

if (!emailRegex.test(email)) {
setError("Please enter a valid email address");
return;
}

setError("");
setIsSubscribed(true);
setShowToast(true);

// Hide toast after 3 seconds
setTimeout(() => {
setShowToast(false);
}, 3000);

// Reset form after 3 seconds
setTimeout(() => {
setIsSubscribed(false);
setEmail("");
}, 3000);
};

return (
Expand Down Expand Up @@ -355,6 +366,7 @@ export default function FooterLayout({
>
{isSubscribed ? "✓ Subscribed!" : "Subscribe Now →"}
</button>
{error && <p className="error-text">{error}</p>}
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is not being cleared when the user starts typing in the email field. Consider adding an onChange handler that clears the error state to provide immediate feedback when the user begins correcting their input.

Copilot uses AI. Check for mistakes.
</form>
<div className="newsletter-stats">
<span className="newsletter-stat">
Expand Down Expand Up @@ -461,4 +473,4 @@ export default function FooterLayout({
</div>
</footer>
);
}
}
Loading