summaryrefslogtreecommitdiff
path: root/src-migrate
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-07-13 10:37:34 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-07-13 10:37:34 +0700
commit3fe75f5dcaf75e71d29d50f3fb0aa1b5fb443224 (patch)
treef35ba29c86893f42768348fb498c4901cb406cea /src-migrate
parent46769b859bb56807d47053c3b99810455db12803 (diff)
<iman> update revisi banner all promotion
Diffstat (limited to 'src-migrate')
-rw-r--r--src-migrate/modules/promo/components/Hero.tsx33
-rw-r--r--src-migrate/services/promotionProgram.ts9
-rw-r--r--src-migrate/types/promotionProgram.ts2
3 files changed, 27 insertions, 17 deletions
diff --git a/src-migrate/modules/promo/components/Hero.tsx b/src-migrate/modules/promo/components/Hero.tsx
index 2701250d..b6e27270 100644
--- a/src-migrate/modules/promo/components/Hero.tsx
+++ b/src-migrate/modules/promo/components/Hero.tsx
@@ -4,14 +4,18 @@ import Image from 'next/image';
import { useEffect, useMemo } from 'react';
import { useQuery } from 'react-query';
import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react';
-
-import { getBanner } from '~/services/banner';
import style from '../styles/hero.module.css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import { Navigation, Pagination, Autoplay } from 'swiper';
import MobileView from '../../../../src/core/components/views/MobileView';
import DesktopView from '@/core/components/views/DesktopView';
+import { getPromotionProgramSolr } from '~/services/promotionProgram';
+
+interface IPromotionProgram {
+ banner_s: string;
+ name_s: string;
+}
const swiperBanner: SwiperProps = {
modules:[Navigation, Pagination, Autoplay],
@@ -39,18 +43,13 @@ const swiperBannerMob = {
const Hero = () => {
const bannerQuery = useQuery({
queryKey: ['banner.all-promo'],
- queryFn: () => getBanner({ type: 'banner-promotion' })
- })
-
- const banners = useMemo(() => bannerQuery.data || [], [bannerQuery.data]);
+ queryFn: getPromotionProgramSolr,
+ });
- useEffect(() => {
- if (banners.length > 1) {
- swiperBanner.slidesPerView = 1.1;
- swiperBanner.loop = true;
- swiperBannerMobile.loop = true;
- }
- }, [banners]);
+ const banners: IPromotionProgram[] = useMemo(
+ () => bannerQuery.data?.response?.docs || [],
+ [bannerQuery.data]
+ );
const swiperBannerMobile = {
...swiperBannerMob,
@@ -72,8 +71,8 @@ const Hero = () => {
{banners.map((banner, index) => (
<SwiperSlide key={index}>
<Image
- src={banner.image}
- alt={banner.name}
+ src={banner.banner_s}
+ alt={banner.name_s}
width={666}
height={450}
quality={100}
@@ -92,8 +91,8 @@ const Hero = () => {
width={439}
height={150}
quality={100}
- src={banner.image}
- alt={banner.name}
+ src={banner.banner_s}
+ alt={banner.name_s}
className='w-full h-full object-cover object-center rounded-2xl'
/>
</SwiperSlide>
diff --git a/src-migrate/services/promotionProgram.ts b/src-migrate/services/promotionProgram.ts
index c8c46c65..92c60943 100644
--- a/src-migrate/services/promotionProgram.ts
+++ b/src-migrate/services/promotionProgram.ts
@@ -6,3 +6,12 @@ export const getPromotionProgram = async (
const url = `/api/promotion-program/${programId}`;
return await fetch(url).then((res) => res.json());
};
+
+export const getPromotionProgramSolr = async () => {
+ console.log(`/solr/promotion-program/select?q=*:*`)
+ const response = await fetch(`/solr/promotion_programs/select?indent=true&q.op=OR&q=*:*&fq=banner_s:[* TO *]`);
+ if (!response.ok) {
+ throw new Error('Network response was not ok');
+ }
+ return response.json();
+};
diff --git a/src-migrate/types/promotionProgram.ts b/src-migrate/types/promotionProgram.ts
index 205884b6..c02cbfd0 100644
--- a/src-migrate/types/promotionProgram.ts
+++ b/src-migrate/types/promotionProgram.ts
@@ -5,4 +5,6 @@ export type IPromotionProgram = {
end_time: string;
applies_to: string;
time_left: number;
+ image:string;
+ banner:string;
};