summaryrefslogtreecommitdiff
path: root/src-migrate/modules/footer-banner
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-06-21 16:16:34 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-06-21 16:16:34 +0700
commit8b7db0f3ef5058f6e41996fd162a805ab9147cc6 (patch)
treef5beaacebd84d48208b36345bc3d1cd8ee66ecaa /src-migrate/modules/footer-banner
parent3ada88f0faf901e05bd56ecff8c4bcb209c06787 (diff)
<iman> update side banner & footer banner search
Diffstat (limited to 'src-migrate/modules/footer-banner')
-rw-r--r--src-migrate/modules/footer-banner/index.tsx6
1 files changed, 5 insertions, 1 deletions
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 && (
<>