summaryrefslogtreecommitdiff
path: root/src/lib/home/components/CategoryDynamicMobile.jsx
blob: a550bd6280293b1d836c7fb62af0382b48bf0dc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { useEffect, useState } from 'react';
import {fetchProductManagementSolr} from '../hooks/useCategoryManagement';
import NextImage from 'next/image';
import Link from "next/link"
import router from 'next/router';
import { createSlug } from '@/core/utils/slug'
import { Swiper, SwiperProps, SwiperSlide }  from 'swiper/react';
import 'swiper/css';

const CategoryDynamicMobile =    () => {
  const [promoItems, setPromoItems] = useState([]);
  useEffect(() => {
    const loadPromo = async () => {
      
      try {
        const items = await fetchProductManagementSolr();
        setPromoItems(items);

      } catch (loadError) {
        // console.error("Error loading promo items:", loadError)
      }
    }
      loadPromo()

  },[]);

  console.log("promoItems",promoItems)

  return (
    <div className='p-4'>
      {/* <div className='font-semibold sm:text-h-lg mb-2 px-4 sm:px-0'>Kategori Pilihan</div> */}
      {/* Render category data */}
      {promoItems && promoItems.map((category) => (
        <div key={category.id}>
          <div className='bagian-judul flex flex-row justify-between items-center gap-3 mb-4 mt-4'>
              <div className='font-semibold sm:text-h-sm mr-2'>{category.name}</div>
                <Link href={createSlug('/shop/category/', category?.name, category?.category_id)} className="!text-red-500 font-semibold text-sm">Lihat Semua</Link>
          </div>
          <Swiper slidesPerView={2.3} spaceBetween={10}>
          {category.category_id2.map((index)=> (
            <SwiperSlide>
              <div key={index.id} className='border justify-start items-start'>
                <div className='p-3'>
                    <div className='flex flex-row border mb-2 justify-start items-center'>
                      <NextImage
                        src={index.image? index.image : "https://erp.indoteknik.com/api/image/product.template/image_256/120726?ratio=square"}
                        alt={index.name}
                        width={90}
                        height={30}
                        className='object-fit'
                      />
                      <div className='bagian-judul flex flex-col justify-center items-start gap-2 ml-2'>
                          <div className='font-semibold text-lg mr-2'>{index.name}</div>
                          <p className='text-gray_r-10 text-sm'>999 rb+ Produk</p>
                          <Link href={createSlug('/shop/category/', index?.name, index?.id_level_2)} className="!text-red-500 font-semibold">Lihat Semua</Link>
                      </div>
                    </div>
                </div>
              </div>
            </SwiperSlide>
            ))}
          </Swiper>
        </div>
      ))}
    </div>
  );
}

export default CategoryDynamicMobile;