From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src/pages/shop/brands/[slug].js | 178 -------------------- src/pages/shop/brands/[slug].jsx | 23 +++ src/pages/shop/brands/index.js | 79 --------- src/pages/shop/cart.js | 282 -------------------------------- src/pages/shop/cart.jsx | 10 ++ src/pages/shop/checkout/finish.js | 47 ------ src/pages/shop/checkout/index.js | 325 ------------------------------------- src/pages/shop/product/[slug].js | 305 ---------------------------------- src/pages/shop/product/[slug].jsx | 29 ++++ src/pages/shop/quotation/finish.js | 39 ----- src/pages/shop/quotation/index.js | 140 ---------------- src/pages/shop/search.js | 125 -------------- src/pages/shop/search.jsx | 19 +++ 13 files changed, 81 insertions(+), 1520 deletions(-) delete mode 100644 src/pages/shop/brands/[slug].js create mode 100644 src/pages/shop/brands/[slug].jsx delete mode 100644 src/pages/shop/brands/index.js delete mode 100644 src/pages/shop/cart.js create mode 100644 src/pages/shop/cart.jsx delete mode 100644 src/pages/shop/checkout/finish.js delete mode 100644 src/pages/shop/checkout/index.js delete mode 100644 src/pages/shop/product/[slug].js create mode 100644 src/pages/shop/product/[slug].jsx delete mode 100644 src/pages/shop/quotation/finish.js delete mode 100644 src/pages/shop/quotation/index.js delete mode 100644 src/pages/shop/search.js create mode 100644 src/pages/shop/search.jsx (limited to 'src/pages/shop') diff --git a/src/pages/shop/brands/[slug].js b/src/pages/shop/brands/[slug].js deleted file mode 100644 index a387e55d..00000000 --- a/src/pages/shop/brands/[slug].js +++ /dev/null @@ -1,178 +0,0 @@ -import axios from "axios"; -import { useEffect, useState } from "react"; -import Filter from "@/components/elements/Filter"; -import Footer from "@/components/layouts/Footer"; -import Header from "@/components/layouts/Header"; -import Layout from "@/components/layouts/Layout"; -import Pagination from "@/components/elements/Pagination"; -import ProductCard from "@/components/products/ProductCard"; -import { getIdFromSlug, getNameFromSlug } from "@/core/utils/slug"; -import FilterIcon from "@/icons/filter.svg"; -import apiOdoo from "@/core/utils/apiOdoo"; -import { Swiper, SwiperSlide } from "swiper/react"; -import "swiper/css"; -import "swiper/css/pagination"; -import "swiper/css/autoplay"; -import { Pagination as SwiperPagination } from "swiper"; -import Image from "@/components/elements/Image"; -import LineDivider from "@/components/elements/LineDivider"; - -export async function getServerSideProps(context) { - const { - slug, - page = 1, - category = '', - price_from = '', - price_to = '', - order_by = '', - } = context.query; - - let urlParameter = [ - 'q=*', - `page=${page}`, - `brand=${getNameFromSlug(slug)}`, - `category=${category}`, - `price_from=${price_from}`, - `price_to=${price_to}`, - `order_by=${order_by}` - ].join('&'); - let searchResults = await axios(`${process.env.SELF_HOST}/api/shop/search?${urlParameter}`); - searchResults = searchResults.data; - - const manufacture = await apiOdoo('GET', `/api/v1/manufacture/${getIdFromSlug(slug)}`); - - return { - props: { - searchResults, - page, - slug, - category, - price_from, - price_to, - order_by, - manufacture - } - }; -} - -export default function BrandDetail({ - searchResults, - page, - slug, - category, - price_from, - price_to, - order_by, - manufacture -}) { - const pageCount = Math.ceil(searchResults.response.numFound / searchResults.responseHeader.params.rows); - const productStart = searchResults.responseHeader.params.start; - const productRows = searchResults.responseHeader.params.rows; - const productFound = searchResults.response.numFound; - - const [activeFilter, setActiveFilter] = useState(false); - const [filterCount, setFilterCount] = useState(0); - - const route = () => { - let route = `/shop/brands/${slug}`; - if (category) route += `&category=${category}`; - if (price_from) route += `&price_from=${price_from}`; - if (price_to) route += `&price_to=${price_to}`; - if (order_by) route += `&order_by=${order_by}`; - return route; - } - - useEffect(() => { - let calculateFilterCount = 0; - if (category) calculateFilterCount++; - if (price_from || price_to) calculateFilterCount++; - if (order_by) calculateFilterCount++; - setFilterCount(calculateFilterCount); - }, [category, price_from, price_to, order_by]); - - return ( - <> -
- setActiveFilter(false)} - defaultPriceFrom={price_from} - defaultPriceTo={price_to} - defaultBrand='' - defaultCategory={category} - defaultOrderBy={order_by} - searchResults={searchResults} - disableFilter={['brand']} - /> - - - { - manufacture.banners?.map((banner, index) => ( - - {`Banner - - )) - } - -
-
-

Produk dari brand:

- { manufacture.logo ? ( -
- {manufacture.name} -
- ) : ( -

{ manufacture.name }

- ) } -
-
-

Jumlah Produk:

-

{ searchResults.response.numFound }

-
-
- - - -
-

Produk

-
- {productFound > 0 ? ( - <> - Menampilkan  - {pageCount > 1 ? ( - <> - {productStart + 1}-{ - (productStart + productRows) > productFound ? productFound : productStart + productRows - } -  dari  - - ) : ''} - {searchResults.response.numFound} -  produk untuk brand {getNameFromSlug(slug)} - - ) : 'Mungkin yang anda cari'} -
- -
- {searchResults.response.products.map((product) => ( - - ))} -
- -
- -
-
- -