From 4c8d08def514cb441007c0bd2bc78e105e6d0153 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Wed, 4 Dec 2024 11:50:21 +0700 Subject: cr popup information method --- src-migrate/modules/popup-information/index.tsx | 61 +++++++++++++++++----- src/components/ui/HeroBanner.jsx | 2 +- .../components/elements/Navbar/NavbarDesktop.jsx | 12 ++++- .../product/components/Product/ProductDesktop.jsx | 1 + .../product/components/Product/ProductMobile.jsx | 1 + src/lib/product/components/ProductCard.jsx | 6 ++- src/lib/product/components/ProductSlider.jsx | 2 +- src/pages/api/hero-banner.js | 2 + 8 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx index 0d36f8e9..20afa902 100644 --- a/src-migrate/modules/popup-information/index.tsx +++ b/src-migrate/modules/popup-information/index.tsx @@ -1,33 +1,66 @@ import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; -import { Modal } from "~/components/ui/modal"; +import Image from 'next/image'; +import Link from 'next/link'; +import { Modal } from '~/components/ui/modal'; import { getAuth } from '~/libs/auth'; -import PageContent from '../page-content'; -const PagePopupInformation = () => { +const PagePopupInformation = ({data} : {data: any[]}) => { const router = useRouter(); const isHomePage = router.pathname === '/'; const auth = getAuth(); const [active, setActive] = useState(false); + // const [data, setData] = useState(null); useEffect(() => { - if (isHomePage && !auth) setActive(true); + // const getData = async () => { + // const res = await fetch(`/api/hero-banner?type=popup-banner`); + // const { data } = await res.json(); + // if (data) { + // setData(data); + // } + // }; + + if (isHomePage && !auth) { + setActive(true); + // getData(); + } }, [isHomePage, auth]); return (
- setActive(false)} - mode='desktop' - > -
setActive(false)}> - -
-
+ {data && ( + setActive(false)} + mode='desktop' + > +
setActive(false)} + > + + {data[0]?.name} + +
+
+ )}
); }; +export async function getServerSideProps() { + const res = await fetch(`/api/hero-banner?type=popup-banner`); + const { data } = await res.json(); + return { props: { data } }; +} + export default PagePopupInformation; diff --git a/src/components/ui/HeroBanner.jsx b/src/components/ui/HeroBanner.jsx index 3025fc1e..6f1ef641 100644 --- a/src/components/ui/HeroBanner.jsx +++ b/src/components/ui/HeroBanner.jsx @@ -55,7 +55,7 @@ const HeroBanner = () => { return heroBanner.map((banner, index) => ( - + {banner.name} {