From eb4ae7be05ed97bd02b7f3e9cc56393f435188e2 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 14 Jun 2023 13:22:20 +0700 Subject: layout promotion program di detail product dan layout modal popup --- src/lib/promotinProgram/api/homepageApi.js | 11 + src/lib/promotinProgram/components/HomePage.jsx | 152 +++++++----- .../promotinProgram/components/PromotionType.jsx | 254 +++++++++++++++------ 3 files changed, 301 insertions(+), 116 deletions(-) create mode 100644 src/lib/promotinProgram/api/homepageApi.js (limited to 'src/lib/promotinProgram') diff --git a/src/lib/promotinProgram/api/homepageApi.js b/src/lib/promotinProgram/api/homepageApi.js new file mode 100644 index 00000000..d839101a --- /dev/null +++ b/src/lib/promotinProgram/api/homepageApi.js @@ -0,0 +1,11 @@ +import odooApi from "@/core/api/odooApi" + +export const getPromotionHome = async () => { + const response = await odooApi('GET', '/api/v1/promotion/home') + return response +} + +export const getProductPromotionHome = async ({id}) => { + const response = await odooApi('GET', `/api/v1/promotion/home/${id}`) + return response +} \ No newline at end of file diff --git a/src/lib/promotinProgram/components/HomePage.jsx b/src/lib/promotinProgram/components/HomePage.jsx index 93134117..9ebd82dc 100644 --- a/src/lib/promotinProgram/components/HomePage.jsx +++ b/src/lib/promotinProgram/components/HomePage.jsx @@ -1,68 +1,116 @@ -import React, { useState } from 'react' +import React, { use, useEffect, useState } from 'react' import { Swiper, SwiperSlide } from 'swiper/react' import 'swiper/swiper.min.css' import Image from '@/core/components/elements/Image/Image' import useDevice from '@/core/hooks/useDevice' +import odooApi from '@/core/api/odooApi' +import { LazyLoadComponent } from 'react-lazy-load-image-component' +import ProductSlider from '@/lib/product/components/ProductSlider' +import ProductCard from '@/lib/product/components/ProductCard' +import { PopularProductSkeleton } from '@/components/skeleton/PopularProductSkeleton' + +const { useQuery } = require('react-query') +const { getPromotionHome } = require('../api/homepageApi') +const { getProductPromotionHome } = require('../api/homepageApi') const HomePage = () => { - const [activeTab, setActiveTab] = useState('Tab 1') + const [activeTab, setActiveTab] = useState(null) + const [activeId, setActiveId] = useState(null) + const [activeBanner, setActiveBanner] = useState(null) + const [parentPromotions, setparentPromotions] = useState(null) + + const { data: titlePromotion } = useQuery('titlePromotion', getPromotionHome) + const { data: productPromotion, refetch: productPromotionRefetch } = useQuery( + ['productPromotion', activeId], + async () => { + if (!activeId) return null + return await getProductPromotionHome({ id: activeId }) + } + ) + + useEffect(() => { + if (titlePromotion) { + setActiveTab(titlePromotion[0].name) + setActiveId(titlePromotion[0].id) + setparentPromotions(titlePromotion) + setActiveBanner(titlePromotion[0].banner) + productPromotionRefetch() + } + }, [titlePromotion]) + + useEffect(() => { + if (productPromotion) { + setparentPromotions(() => { + return parentPromotions.map((title) => { + if (title.id === activeId && title.products === undefined) { + return { + ...title, + products: productPromotion + } + } + return title + }) + }) + } + }, [productPromotion, parentPromotions, activeId]) const { isMobile, isDesktop } = useDevice() - const handleTabClick = (label) => { + const handleTabClick = (id, label, banner) => { setActiveTab(label) + setActiveId(id) + setActiveBanner(banner) } - const tabItems = [ - { label: 'Tab 1', content: 'Content for Tab 1' }, - { label: 'Tab 2', content: 'Content for Tab 2' }, - { label: 'Tab 3', content: 'Content for Tab 3' }, - { label: 'Tab 4', content: 'Content for Tab 4' }, - { label: 'Tab 5', content: 'Content for Tab 5' }, - { label: 'Tab 6', content: 'Content for Tab 6' }, - { label: 'Tab 7', content: 'Content for Tab 7' }, - { label: 'Tab 8', content: 'Content for Tab 8' }, - { label: 'Tab 9', content: 'Content for Tab 9' }, - { label: 'Tab 10', content: 'Content for Tab 10' } - ] - return ( -
-
-
{activeTab}
-
- - {tabItems.map((item, index) => ( - - - - ))} - - -
- {tabItems.map((item, index) => ( -
- {item.content} -
- ))} + activeBanner && ( +
+
+
{activeTab}
+
+
+ +
+ + {titlePromotion?.map((item, index) => ( + + + + ))} + +
+ {parentPromotions && + parentPromotions?.map((item, index) => ( +
+ {item.products ? ( + + ) : ( + + )} +
+ ))} +
-
+ ) ) } diff --git a/src/lib/promotinProgram/components/PromotionType.jsx b/src/lib/promotinProgram/components/PromotionType.jsx index 371aa952..a6382cb1 100644 --- a/src/lib/promotinProgram/components/PromotionType.jsx +++ b/src/lib/promotinProgram/components/PromotionType.jsx @@ -1,47 +1,72 @@ import React, { useEffect, useState } from 'react' import Image from '@/core/components/elements/Image/Image' +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import { Tabs } from 'flowbite-react' +import CountDown from '@/core/components/elements/CountDown/CountDown' +import CountDown2 from '@/core/components/elements/CountDown/CountDown2' -const PromotionType = ({ isModal = true }) => { +const PromotionType = ({ isModal = false }) => { const [selectedPromo, setSelectedPromo] = useState(null) + const [promotionType, setPromotionType] = useState(false) + const promos = [ { id: 1, - title: 'Promo 1', + title: 'Promo Bundling', description: 'Deskripsi Promo 1', - image: '/path/to/image1.jpg' + image: '/path/to/image1.jpg', + type: 'Promo Bundling' }, { id: 2, - title: 'Promo 2', + title: 'Promo Special', description: 'Deskripsi Promo 2', - image: '/path/to/image2.jpg' + image: '/path/to/image2.jpg', + type: 'Promo Special' }, { id: 3, - title: 'Promo 3', + title: 'Promo Free Merchandise', description: 'Deskripsi Promo 3', - image: '/path/to/image3.jpg' + image: '/path/to/image3.jpg', + type: 'Promo Free Merchandise' }, { id: 4, - title: 'Promo 1', + title: 'Promo 4', description: 'Deskripsi Promo 1', - image: '/path/to/image1.jpg' + image: '/path/to/image1.jpg', + type: 'Promo Bundling' }, { id: 5, - title: 'Promo 2', + title: 'Promo 5', description: 'Deskripsi Promo 2', - image: '/path/to/image2.jpg' + image: '/path/to/image2.jpg', + type: 'Promo Bundling' }, { id: 6, - title: 'Promo 3', + title: 'Promo 6', description: 'Deskripsi Promo 3', - image: '/path/to/image3.jpg' + image: '/path/to/image3.jpg', + type: 'Promo Special' } ] + + const [activeTitle, setActiveTitle] = useState(promos[0].type) + + const groupingData = promos.reduce((groups, item) => { + const promoType = item.type + if (!groups[promoType]) { + groups[promoType] = [] + } + groups[promoType].push(item) + + return groups + }, {}) + const handlePromoClick = (promoId) => { if (promoId == selectedPromo) { setSelectedPromo(null) @@ -49,60 +74,161 @@ const PromotionType = ({ isModal = true }) => { setSelectedPromo(promoId) } } + + const handlePopUp = () => { + if(isModal == false){ + setPromotionType(true) + } + } return ( -
- {promos.map((promo) => ( -
handlePromoClick(promo.id)} - className={`p-2 rounded-lg border border-solid border-gray-300 mb-5 w-full hover:cursor-pointer ${ - selectedPromo - ? selectedPromo === promo.id - ? 'opacity-100 border-red-500 bg-red-100' - : 'opacity-50 pointer-events-none' - : 'opacity-100' - } `} - > -
-
- -
-
-

{promo.title}

- {isModal == true &&

{promo.description}

} +
+
+ +
+ Promo Tersedia + +
+
+
+ {isModal === true ? ( +
+
+ {Object.keys(groupingData).map((index) => { + return ( + <> + + + ) + })}
+ {activeTitle && + groupingData[activeTitle].map((item, i) => ( +
handlePromoClick(item.id)} + className={`border border-solid bg-white mb-5 w-full hover:cursor-pointer ${ + selectedPromo + ? selectedPromo === item.id + ? 'opacity-100 border-red-500 bg-red-100' + : 'opacity-50 pointer-events-none' + : 'opacity-100' + } `} + > +
+
+ +
+
+
+
Waktu Tersisa
+
+ +
+
+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut nibh at arcu + commodo auctor. Maecenas efficitur, ipsum sed mollis fermentum, nulla sem ada lah ini ditu kamu dia merek +

+
Rp. 999.000
+
+
+
+ ))}
-
- //
handlePromoClick(promo.id)} - // className={`p-2 rounded-lg border border-solid border-gray-300 mb-5 w-full hover:cursor-pointer ${ - // selectedPromo - // ? selectedPromo === promo.id - // ? 'opacity-100 border-red-400 bg-red-100' - // : 'opacity-50 pointer-events-none' - // : 'opacity-100' - // } `} - // > - //
- //
- // - //
- //
- //

{promo.title}

- // {/*

{promo.description}

*/} - //
- //
- //
- ))} + ) : ( + promos.map((promo, index) => { + if (index > 2) { + return null + } else { + if (index === 2) { + return ( + <> +
setPromotionType(true)} + className={` border border-solid bg-white mb-5 w-full hover:cursor-pointer opacity-100 flex flex-col justify-center items-center`} + > +
+
+ +
+
+ + Lihat Promo Lainya +
+ + ) + } + return ( + <> +
setPromotionType(true)} + className={`border border-solid bg-white mb-5 w-full hover:cursor-pointer`} + > +
+
+ +
+
+
{promo.title}
+

Lorem ipsum dolor sit amet, consectetur ...

+
999900
+
+ +
+
+
+
+ + ) + } + }) + )} + setPromotionType(false)} + > +
+ +
+
+
) } -- cgit v1.2.3