summaryrefslogtreecommitdiff
path: root/src/pages/index.js
blob: 65999ff6e91d2405903e21779e603a5338e45585 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { useEffect, useState } from "react";
import { Pagination, Autoplay } from "swiper";
import axios from "axios";
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import "swiper/css/pagination";
import "swiper/css/autoplay";

// Helpers
import apiOdoo from "@/core/utils/apiOdoo";

// Components
import Header from "@/components/layouts/Header";
import ProductSlider from "@/components/products/ProductSlider";
import Layout from "@/components/layouts/Layout";
import ManufactureCard from "@/components/manufactures/ManufactureCard";
import Footer from "@/components/layouts/Footer";
import Image from "@/components/elements/Image";
import ProductCategories from "@/components/products/ProductCategories";

const swiperBanner = {
  pagination: { dynamicBullets: true },
  autoplay: {
    delay: 6000,
    disableOnInteraction: false
  },
  modules: [Pagination, Autoplay]
}

export async function getServerSideProps() {
  const heroBanners = await apiOdoo('GET', `/api/v1/banner?type=index-a-1`);

  return { props: { heroBanners } };
}

export default function Home({ heroBanners }) {
  const [manufactures, setManufactures] = useState(null);
  const [popularProducts, setPopularProducts] = useState(null);

  useEffect(() => {
    const getManufactures = async () => {
      const dataManufactures = await apiOdoo('GET', `/api/v1/manufacture?level=prioritas`);
      setManufactures(dataManufactures);
    }
    getManufactures();

    const getPopularProducts = async () => {
      const dataPopularProducts = await axios(`${process.env.SELF_HOST}/api/shop/search?q=*&page=1&order_by=popular`);
      setPopularProducts(dataPopularProducts.data.response);
    }
    getPopularProducts();
  }, []);

  return (
    <>
      <Header title='Home - Indoteknik' />
      <Layout>
        <Swiper 
          slidesPerView={1} 
          pagination={swiperBanner.pagination} 
          modules={swiperBanner.modules}
          autoplay={swiperBanner.autoplay}
        >
          {
            heroBanners?.map((banner, index) => (
              <SwiperSlide key={index}>
                <Image
                  src={banner.image} 
                  alt={banner.name} 
                  className="w-full h-auto"
                />
              </SwiperSlide>
            ))
          }
        </Swiper>
        <div className="mt-6 px-4">
          <h2 className="mb-3">Brand Pilihan</h2>
          <Swiper slidesPerView={4} freeMode={true} spaceBetween={16}>
            {
              manufactures?.manufactures?.map((manufacture, index) => (
                <SwiperSlide key={index}>
                  <ManufactureCard data={manufacture} key={index} />
                </SwiperSlide>
              ))
            }
          </Swiper>
        </div>
        <div className="my-6 p-4 py-0">
          <h2 className="mb-4">Produk Populer</h2>
          <ProductSlider products={popularProducts} simpleProductTitleLine />
        </div>

        <ProductCategories />

        <div className="px-4">
          <h5 className="h2 mb-2">Platform Belanja B2B Alat Teknik & Industri di Indonesia</h5>
          <p className="text-gray_r-11 leading-6 text-caption-2 mb-4">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est 
          </p>
        </div>
        
        <Footer />
      </Layout>
    </>
  )
}