@@ -4,6 +4,7 @@ import Link from "next/link";
44import { useTheme } from "next-themes" ;
55import { useEffect , useState } from "react" ;
66import { Button } from "./ui/button" ;
7+ import { Input } from "@/components/ui/input" ;
78import {
89 FaFacebook ,
910 FaGithub ,
@@ -13,16 +14,40 @@ import {
1314 FaYoutube ,
1415} from "react-icons/fa6" ;
1516import { Mail } from "lucide-react" ;
16-
17+ import toast from "react-hot-toast" ;
1718export default function Footer ( ) {
1819 const { theme } = useTheme ( ) ;
1920 const [ isDarkMode , setIsDarkMode ] = useState < boolean | null > ( true ) ;
20-
21+ const [ email , setEmail ] = useState ( "" ) ;
2122 useEffect ( ( ) => {
2223 if ( theme ) {
2324 setIsDarkMode ( theme === "dark" ) ;
2425 }
2526 } , [ theme ] ) ;
27+ const handleSubscribe = async ( ) => {
28+ if ( ! email ?. includes ( "@" ) ) {
29+ toast . error ( "Please Enter A Valid Email." ) ;
30+ return ;
31+ }
32+
33+ await toast . promise (
34+ fetch ( "/api/subscribe" , {
35+ method : "POST" ,
36+ headers : { "Content-Type" : "application/json" } ,
37+ body : JSON . stringify ( { email } ) ,
38+ } ) . then ( ( res ) => {
39+ if ( ! res . ok ) throw new Error ( "Network response was not ok." ) ;
40+ return res . json ( ) ;
41+ } ) ,
42+ {
43+ loading : "Subscribing..." ,
44+ success : "You've Successfully Subscribed!" ,
45+ error : "Something went wrong. Try again later." ,
46+ } ,
47+ ) ;
48+
49+ setEmail ( "" ) ;
50+ } ;
2651
2752 return (
2853 < footer className = "w-full overflow-hidden bg-gradient-to-b from-[#F3F5FF] to-[#A599CE] px-6 py-10 text-white dark:from-[#070114] dark:to-[#1F0234]" >
@@ -96,11 +121,33 @@ export default function Footer() {
96121 < Mail size = { 18 } />
97122 < span > codechefvit@gmail.com</ span >
98123 </ Link >
124+
125+ < div className = "mt-4 flex w-full max-w-xs flex-col gap-2" >
126+ < h3 className = "font-jost text-2xl font-semibold" >
127+ Subscribe For Updates:
128+ </ h3 >
129+ < div className = "relative w-full" >
130+ < Input
131+ id = "email"
132+ type = "email"
133+ placeholder = "Enter Your Email"
134+ className = "pr-24"
135+ value = { email }
136+ onChange = { ( e ) => setEmail ( e . target . value ) }
137+ />
138+ < Button
139+ onClick = { handleSubscribe }
140+ className = "absolute right-0 top-0 h-full rounded-l-none rounded-r-md bg-[#562EE7] px-4 text-white hover:bg-[#4531b3]"
141+ >
142+ Subscribe!
143+ </ Button >
144+ </ div >
145+ </ div >
99146 </ div >
100147 </ div >
101148
102- < p className = "mt-10 border-t pt-6 text-center text-sm text-black dark:border-white/10 dark:text-white" >
103- Made with ❤️ by CodeChef -VIT
149+ < p className = "mt-8 border-t border-[#130E1F] pt-12 text-center font-play text-lg text-black dark:border-white/10 dark:text-white" >
150+ Made with ❤️ by Codechef -VIT
104151 </ p >
105152 </ footer >
106153 ) ;
0 commit comments