summaryrefslogtreecommitdiff
path: root/src/lib/home/components/BannerSection.jsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-28 10:47:43 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-28 10:47:43 +0700
commit5bc7a6807847610b190ea9d5046021d2db15afc5 (patch)
treee895b02c65bf97e3c6c970bb8d777922120f4570 /src/lib/home/components/BannerSection.jsx
parent7ed3fd96322d08bd91434b8ec4dcbc542a610998 (diff)
parent952421c810b53ec4d25ad5ef605bae1bd1d5d616 (diff)
Merge branch 'new-release' into Feature/switch-account
Diffstat (limited to 'src/lib/home/components/BannerSection.jsx')
-rw-r--r--src/lib/home/components/BannerSection.jsx40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/lib/home/components/BannerSection.jsx b/src/lib/home/components/BannerSection.jsx
index f83c36fc..303b5c4b 100644
--- a/src/lib/home/components/BannerSection.jsx
+++ b/src/lib/home/components/BannerSection.jsx
@@ -1,18 +1,48 @@
import Link from '@/core/components/elements/Link/Link';
import Image from 'next/image';
+import { useEffect, useState } from 'react';
+import { bannerApi } from '../../../api/bannerApi';
const { useQuery } = require('react-query');
const { default: bannerSectionApi } = require('../api/bannerSectionApi');
const BannerSection = () => {
- const fetchBannerSection = async () => await bannerSectionApi();
- const bannerSection = useQuery('bannerSection', fetchBannerSection);
+ const [data, setData] = useState(null);
+ const [shouldFetch, setShouldFetch] = useState(false);
+ useEffect(() => {
+ const fetchCategoryData = async () => {
+ const res = await fetch('/api/banner-section');
+ const { data } = await res.json();
+ if (data) {
+ setData(data);
+ }
+ };
+
+ fetchCategoryData();
+ }, []);
+
+ // const fetchBannerSection = async () => await bannerSectionApi();
+ const getBannerSection = useQuery(
+ 'bannerSection',
+ bannerApi({ type: 'home-banner' }),
+ {
+ enabled: shouldFetch,
+ onSuccess: (data) => {
+ if (data) {
+ localStorage.setItem('Homepage_bannerSection', JSON.stringify(data));
+ setData(data);
+ }
+ },
+ }
+ );
+
+ const bannerSection = data;
return (
- bannerSection.data &&
- bannerSection.data?.length > 0 && (
+ bannerSection &&
+ bannerSection?.length > 0 && (
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
- {bannerSection.data?.map((banner) => (
+ {bannerSection?.map((banner) => (
<Link key={banner.id} href={banner.url}>
<Image
width={1024}