From 33da0fcb718335eb1d077af4321ac65e0146a2d6 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 22 May 2023 11:58:05 +0700
Subject: Refactoring hero banner feature

---
 src/components/ui/HeroBannerSecondary.jsx | 35 +++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 src/components/ui/HeroBannerSecondary.jsx

(limited to 'src/components/ui/HeroBannerSecondary.jsx')

diff --git a/src/components/ui/HeroBannerSecondary.jsx b/src/components/ui/HeroBannerSecondary.jsx
new file mode 100644
index 00000000..a3227002
--- /dev/null
+++ b/src/components/ui/HeroBannerSecondary.jsx
@@ -0,0 +1,35 @@
+import Link from '@/core/components/elements/Link/Link'
+import { getRandomInt } from '@/utils/getRandomInt'
+import Image from 'next/image'
+import { useMemo } from 'react'
+import { useQuery } from 'react-query'
+import { HeroBannerSkeleton } from '../skeleton/BannerSkeleton'
+import { BannerApi } from '@/api/BannerApi'
+
+const HeroBannerSecondary = () => {
+  const heroBannerSecondary = useQuery('heroBannerSecondary', BannerApi({ type: 'index-a-2' }))
+
+  const randomIndex = useMemo(() => {
+    if (!heroBannerSecondary.data) return null
+    const length = heroBannerSecondary.data?.length
+    return getRandomInt(length)
+  }, [heroBannerSecondary.data])
+
+  if (heroBannerSecondary.isLoading) return <HeroBannerSkeleton />
+
+  return (
+    heroBannerSecondary.data && (
+      <Link href={heroBannerSecondary.data[randomIndex].url} className='h-full'>
+        <Image
+          src={heroBannerSecondary.data[randomIndex].image}
+          width={512}
+          height={1024}
+          alt={heroBannerSecondary.data[randomIndex].name}
+          className='object-cover object-center h-full'
+        />
+      </Link>
+    )
+  )
+}
+
+export default HeroBannerSecondary
-- 
cgit v1.2.3

