summaryrefslogtreecommitdiff
path: root/src-migrate/modules/footer-banner
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-06-26 11:19:27 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-06-26 11:19:27 +0700
commiteead8eec2e37a2edf3c431664cacdcc502a64364 (patch)
tree129633fc6aac6aea9250251ca566f7cc7a5cf89d /src-migrate/modules/footer-banner
parent98109d3da0a88dfa1a513be68a0debe2e626d331 (diff)
bug fix side & footer banner
Diffstat (limited to 'src-migrate/modules/footer-banner')
-rw-r--r--src-migrate/modules/footer-banner/index.tsx9
1 files changed, 6 insertions, 3 deletions
diff --git a/src-migrate/modules/footer-banner/index.tsx b/src-migrate/modules/footer-banner/index.tsx
index 7db1363c..b214493d 100644
--- a/src-migrate/modules/footer-banner/index.tsx
+++ b/src-migrate/modules/footer-banner/index.tsx
@@ -1,15 +1,19 @@
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({
queryKey: 'footerBanner',
queryFn: () => getBanner({ type: 'bottom-search-promotion' })
})
-
- const banner = fetchFooterBanner?.data?.[0] || false
+ // ubah dari static menjadid dynamic dengan menggunakan random index
+ const length = useMemo(() => fetchFooterBanner.data?.length, [fetchFooterBanner.data]);
+ const randomIndex = useMemo(() => getRandomInt(length), [length]);
+ const banner = fetchFooterBanner?.data?.[randomIndex] || false;
return banner && (
<>
@@ -25,5 +29,4 @@ const FooterBanner = () => {
</>
)
}
-
export default FooterBanner \ No newline at end of file