From 8b7db0f3ef5058f6e41996fd162a805ab9147cc6 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 21 Jun 2024 16:16:34 +0700
Subject: <iman> update side banner & footer banner search

---
 src-migrate/modules/footer-banner/index.tsx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'src-migrate/modules/footer-banner/index.tsx')

diff --git a/src-migrate/modules/footer-banner/index.tsx b/src-migrate/modules/footer-banner/index.tsx
index 7db1363c..c829b91e 100644
--- a/src-migrate/modules/footer-banner/index.tsx
+++ b/src-migrate/modules/footer-banner/index.tsx
@@ -1,7 +1,9 @@
 import Link from "next/link"
+import React, { useMemo } from "react";
 import { useQuery } from "react-query"
 import Image from "~/components/ui/image"
 import { getBanner } from "~/services/banner"
+import { getRandomInt } from '@/utils/getRandomInt'
 
 const FooterBanner = () => {
   const fetchFooterBanner = useQuery({
@@ -9,7 +11,9 @@ const FooterBanner = () => {
     queryFn: () => getBanner({ type: 'bottom-search-promotion' })
   })
 
-  const banner = fetchFooterBanner?.data?.[0] || false
+  const length = useMemo(() => fetchFooterBanner.data?.length, [fetchFooterBanner.data]);
+  const randomIndex = useMemo(() => getRandomInt(length), [length]);
+  const banner = fetchFooterBanner?.data?.[randomIndex] || false;
 
   return banner && (
     <>
-- 
cgit v1.2.3

