@@ -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 || ! 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-12 py-12 font-sans text-white dark:from-[#070114] dark:to-[#1F0234]" >
@@ -95,9 +120,31 @@ export default function Footer() {
95120 >
96121 < Mail /> codechefvit@gmail.com
97122 </ Link >
123+
124+ < div className = "mt-4 flex flex-col gap-2 w-full max-w-xs" >
125+ < h3 htmlFor = "email" className = "font-jost text-2xl font-semibold" >
126+ Subscribe For Updates:
127+ </ h3 >
128+ < div className = "relative w-full" >
129+ < Input
130+ id = "email"
131+ type = "email"
132+ placeholder = "Enter Your Email"
133+ className = "pr-24"
134+ value = { email }
135+ onChange = { ( e ) => setEmail ( e . target . value ) }
136+ />
137+ < Button
138+ onClick = { handleSubscribe }
139+ className = "absolute right-0 top-0 h-full rounded-l-none rounded-r-md bg-[#562EE7] px-4 text-white hover:bg-[#4531b3]"
140+ >
141+ Subscribe!
142+ </ Button >
143+ </ div >
144+ </ div >
98145 </ div >
99146 </ div >
100- < p className = "font-play mt-4 border-t border-[#130E1F] pt-12 text-center text-lg text-black dark:border-white/10 dark:text-white" >
147+ < p className = "font-play mt-8 border-t border-[#130E1F] pt-12 text-center text-lg text-black dark:border-white/10 dark:text-white" >
101148 Made with ❤️ by Codechef-VIT
102149 </ p >
103150 </ footer >
0 commit comments