diff --git a/components/landing/footer-new.tsx b/components/landing/footer-new.tsx index cad84bc..f141bf9 100644 --- a/components/landing/footer-new.tsx +++ b/components/landing/footer-new.tsx @@ -14,10 +14,31 @@ import Link from "next/link"; import { useTranslations } from "next-intl"; import { useEffect, useState } from "react"; import Image from "next/image"; +import { error, success } from "@/config/swal"; +import { subscription } from "@/service/subscribe"; export default function FooterNew(props: { margin?: boolean }) { - const t2 = useTranslations("Navbar"); - const t3 = useTranslations("LandingInformasiPublik"); + const [emailValue, setEmailValue] = useState(""); + + const doSubscribe = async () => { + const isValidEmail = (email: string): boolean => { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); + }; + + if (!isValidEmail(emailValue)) { + error("Email tidak valid"); + return false; + } + + const res = await subscription({ email: emailValue }); + if (res?.error) { + error(res?.message); + return false; + } + + success("Sukses"); + }; return (
- // } + value={emailValue} + onValueChange={setEmailValue} /> -