summaryrefslogtreecommitdiff
path: root/src-migrate/modules
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-01-19 02:32:43 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-01-19 02:32:43 +0000
commit8bcadf6d43a44169c422305522784424c30c7b02 (patch)
tree4666802b65784a949db4acad665a81de7297fc74 /src-migrate/modules
parent065396828266e2de42cb0182c81ea2d7a5b00e2b (diff)
parent91086d8b1af2e1c0ca9db38d037f6331c9e6131a (diff)
Merged in Feature/perf/product-detail (pull request #127)
Feature/perf/product detail
Diffstat (limited to 'src-migrate/modules')
-rw-r--r--src-migrate/modules/account-activation/components/FormEmail.tsx6
-rw-r--r--src-migrate/modules/account-activation/components/FormOTP.tsx6
-rw-r--r--src-migrate/modules/account-activation/components/FormToken.tsx6
-rw-r--r--src-migrate/modules/cart/components/Detail.tsx2
-rw-r--r--src-migrate/modules/cart/components/Item.tsx4
-rw-r--r--src-migrate/modules/cart/components/ItemAction.tsx4
-rw-r--r--src-migrate/modules/cart/components/ItemPromo.tsx2
-rw-r--r--src-migrate/modules/cart/components/ItemSelect.tsx7
-rw-r--r--src-migrate/modules/cart/components/Summary.tsx4
-rw-r--r--src-migrate/modules/cart/stores/useCartStore.ts2
-rw-r--r--src-migrate/modules/cart/styles/detail.module.css3
-rw-r--r--src-migrate/modules/cart/styles/item-promo.module.css2
-rw-r--r--src-migrate/modules/header/components/HeaderDesktop.tsx2
-rw-r--r--src-migrate/modules/page-content/index.tsx19
-rw-r--r--src-migrate/modules/popup-information/index.tsx4
-rw-r--r--src-migrate/modules/product-card/components/ProductCard.tsx106
-rw-r--r--src-migrate/modules/product-card/index.tsx3
-rw-r--r--src-migrate/modules/product-card/styles/product-card.module.css54
-rw-r--r--src-migrate/modules/product-detail/components/AddToCart.tsx79
-rw-r--r--src-migrate/modules/product-detail/components/AddToWishlist.tsx61
-rw-r--r--src-migrate/modules/product-detail/components/Breadcrumb.tsx41
-rw-r--r--src-migrate/modules/product-detail/components/Image.tsx99
-rw-r--r--src-migrate/modules/product-detail/components/Information.tsx56
-rw-r--r--src-migrate/modules/product-detail/components/PriceAction.tsx76
-rw-r--r--src-migrate/modules/product-detail/components/ProductDetail.tsx178
-rw-r--r--src-migrate/modules/product-detail/components/SimilarBottom.tsx21
-rw-r--r--src-migrate/modules/product-detail/components/SimilarSide.tsx34
-rw-r--r--src-migrate/modules/product-detail/components/VariantList.tsx117
-rw-r--r--src-migrate/modules/product-detail/index.ts3
-rw-r--r--src-migrate/modules/product-detail/stores/useProductDetail.ts31
-rw-r--r--src-migrate/modules/product-detail/styles/image.module.css35
-rw-r--r--src-migrate/modules/product-detail/styles/information.module.css19
-rw-r--r--src-migrate/modules/product-detail/styles/price-action.module.css24
-rw-r--r--src-migrate/modules/product-detail/styles/product-detail.module.css15
-rw-r--r--src-migrate/modules/product-detail/styles/side-similar.module.css3
-rw-r--r--src-migrate/modules/product-detail/styles/variant-list.module.css35
-rw-r--r--src-migrate/modules/product-promo/components/AddToCart.tsx4
-rw-r--r--src-migrate/modules/product-promo/components/Card.tsx8
-rw-r--r--src-migrate/modules/product-promo/components/CardCountdown.tsx4
-rw-r--r--src-migrate/modules/product-promo/components/CategoryTab.tsx4
-rw-r--r--src-migrate/modules/product-promo/components/Item.tsx6
-rw-r--r--src-migrate/modules/product-promo/components/Modal.tsx2
-rw-r--r--src-migrate/modules/product-promo/components/ModalContent.tsx2
-rw-r--r--src-migrate/modules/product-promo/components/Section.tsx11
-rw-r--r--src-migrate/modules/product-promo/stores/useModalStore.ts2
-rw-r--r--src-migrate/modules/product-similar/hooks/useProductSimilar.tsx15
-rw-r--r--src-migrate/modules/product-slider/components/ProductSlider.tsx42
-rw-r--r--src-migrate/modules/product-slider/index.ts3
-rw-r--r--src-migrate/modules/register/components/Form.tsx4
-rw-r--r--src-migrate/modules/register/components/FormCaptcha.tsx4
-rw-r--r--src-migrate/modules/register/components/TermCondition.tsx4
-rw-r--r--src-migrate/modules/register/stores/useRegisterStore.ts60
52 files changed, 1284 insertions, 54 deletions
diff --git a/src-migrate/modules/account-activation/components/FormEmail.tsx b/src-migrate/modules/account-activation/components/FormEmail.tsx
index ec300ba4..f7925481 100644
--- a/src-migrate/modules/account-activation/components/FormEmail.tsx
+++ b/src-migrate/modules/account-activation/components/FormEmail.tsx
@@ -3,9 +3,9 @@ import Link from "next/link"
import { useRouter } from "next/router"
import { ChangeEvent, useEffect, useState } from "react"
import { useMutation } from "react-query"
-import Modal from "~/common/components/elements/Modal"
-import { useRegisterStore } from "~/common/stores/useRegisterStore"
-import { ActivationReqProps } from "~/common/types/auth"
+import { Modal } from "~/components/ui/modal"
+import { useRegisterStore } from "~/modules/register/stores/useRegisterStore"
+import { ActivationReqProps } from "~/types/auth"
import { activationReq } from "~/services/auth"
const FormEmail = () => {
diff --git a/src-migrate/modules/account-activation/components/FormOTP.tsx b/src-migrate/modules/account-activation/components/FormOTP.tsx
index 6815a088..cf4da2db 100644
--- a/src-migrate/modules/account-activation/components/FormOTP.tsx
+++ b/src-migrate/modules/account-activation/components/FormOTP.tsx
@@ -3,9 +3,9 @@ import { useRouter } from "next/router"
import { useEffect, useState } from "react"
import { useMutation } from "react-query"
import { useCountdown } from "usehooks-ts"
-import Modal from '~/common/components/elements/Modal'
-import { setAuth } from "~/common/libs/auth"
-import { ActivationOtpProps, ActivationReqProps } from "~/common/types/auth"
+import { Modal } from "~/components/ui/modal"
+import { setAuth } from "~/libs/auth"
+import { ActivationOtpProps, ActivationReqProps } from "~/types/auth"
import { activationReq, activationUserOTP } from "~/services/auth"
const FormOTP = () => {
diff --git a/src-migrate/modules/account-activation/components/FormToken.tsx b/src-migrate/modules/account-activation/components/FormToken.tsx
index b68b244f..2835ec0e 100644
--- a/src-migrate/modules/account-activation/components/FormToken.tsx
+++ b/src-migrate/modules/account-activation/components/FormToken.tsx
@@ -4,10 +4,10 @@ import { useEffect, useState } from "react"
import Link from "next/link"
import { useMutation } from "react-query"
-import Modal from "~/common/components/elements/Modal"
-import { ActivationTokenProps } from "~/common/types/auth"
+import { Modal } from "~/components/ui/modal"
+import { ActivationTokenProps } from "~/types/auth"
import { activationUserToken } from "~/services/auth"
-import { setAuth } from "~/common/libs/auth"
+import { setAuth } from "~/libs/auth"
const FormToken = () => {
const router = useRouter()
diff --git a/src-migrate/modules/cart/components/Detail.tsx b/src-migrate/modules/cart/components/Detail.tsx
index 99fe4c91..b1532729 100644
--- a/src-migrate/modules/cart/components/Detail.tsx
+++ b/src-migrate/modules/cart/components/Detail.tsx
@@ -4,7 +4,7 @@ import React, { useEffect, useMemo } from 'react'
import Link from 'next/link'
import { Button, Tooltip } from '@chakra-ui/react'
-import { getAuth } from '~/common/libs/auth'
+import { getAuth } from '~/libs/auth'
import { useCartStore } from '../stores/useCartStore'
import CartItem from './Item'
diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx
index baf48bb6..08823d19 100644
--- a/src-migrate/modules/cart/components/Item.tsx
+++ b/src-migrate/modules/cart/components/Item.tsx
@@ -7,8 +7,8 @@ import { InfoIcon } from 'lucide-react'
import { PROMO_CATEGORY } from '~/constants/promotion'
-import formatCurrency from '~/common/libs/formatCurrency'
-import { CartItem as CartItemProps } from '~/common/types/cart'
+import formatCurrency from '~/libs/formatCurrency'
+import { CartItem as CartItemProps } from '~/types/cart'
import CartItemPromo from './ItemPromo'
import CartItemAction from './ItemAction'
diff --git a/src-migrate/modules/cart/components/ItemAction.tsx b/src-migrate/modules/cart/components/ItemAction.tsx
index 3e264aef..859c758c 100644
--- a/src-migrate/modules/cart/components/ItemAction.tsx
+++ b/src-migrate/modules/cart/components/ItemAction.tsx
@@ -5,8 +5,8 @@ import React, { useEffect, useState } from 'react'
import { Spinner, Tooltip } from '@chakra-ui/react'
import { MinusIcon, PlusIcon, Trash2Icon } from 'lucide-react'
-import { CartItem } from '~/common/types/cart'
-import { getAuth } from '~/common/libs/auth'
+import { CartItem } from '~/types/cart'
+import { getAuth } from '~/libs/auth'
import { deleteUserCart, upsertUserCart } from '~/services/cart'
import { useDebounce } from 'usehooks-ts'
diff --git a/src-migrate/modules/cart/components/ItemPromo.tsx b/src-migrate/modules/cart/components/ItemPromo.tsx
index bb286e8b..bc507578 100644
--- a/src-migrate/modules/cart/components/ItemPromo.tsx
+++ b/src-migrate/modules/cart/components/ItemPromo.tsx
@@ -3,7 +3,7 @@ import style from '../styles/item-promo.module.css'
import Image from 'next/image'
import React from 'react'
-import { CartProduct } from '~/common/types/cart'
+import { CartProduct } from '~/types/cart'
type Props = {
product: CartProduct
diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
index 96e7c713..1d8886a2 100644
--- a/src-migrate/modules/cart/components/ItemSelect.tsx
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -1,8 +1,8 @@
import { Checkbox, Spinner } from '@chakra-ui/react'
import React, { useState } from 'react'
-import { getAuth } from '~/common/libs/auth'
-import { CartItem } from '~/common/types/cart'
+import { getAuth } from '~/libs/auth'
+import { CartItem } from '~/types/cart'
import { upsertUserCart } from '~/services/cart'
import { useCartStore } from '../stores/useCartStore'
@@ -27,10 +27,11 @@ const CartItemSelect = ({ item }: Props) => {
}
return (
- <div className='w-5 my-auto'>
+ <div className='w-6 my-auto'>
{isLoad && (
<Spinner className='my-auto' size='sm' />
)}
+
{!isLoad && (
<Checkbox
borderColor='gray.600'
diff --git a/src-migrate/modules/cart/components/Summary.tsx b/src-migrate/modules/cart/components/Summary.tsx
index a835bca9..2e55c8df 100644
--- a/src-migrate/modules/cart/components/Summary.tsx
+++ b/src-migrate/modules/cart/components/Summary.tsx
@@ -1,8 +1,8 @@
import style from '../styles/summary.module.css'
import React from 'react'
-import formatCurrency from '~/common/libs/formatCurrency'
-import clsxm from '~/common/libs/clsxm'
+import formatCurrency from '~/libs/formatCurrency'
+import clsxm from '~/libs/clsxm'
import { Skeleton } from '@chakra-ui/react'
import _ from 'lodash'
diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts
index 0643b8e6..3d9a0aed 100644
--- a/src-migrate/modules/cart/stores/useCartStore.ts
+++ b/src-migrate/modules/cart/stores/useCartStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand';
-import { CartProps } from '~/common/types/cart';
+import { CartProps } from '~/types/cart';
import { getUserCart } from '~/services/cart';
type State = {
diff --git a/src-migrate/modules/cart/styles/detail.module.css b/src-migrate/modules/cart/styles/detail.module.css
deleted file mode 100644
index 42d492bb..00000000
--- a/src-migrate/modules/cart/styles/detail.module.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.wrapper {
- @apply flex flex-wrap;
-}
diff --git a/src-migrate/modules/cart/styles/item-promo.module.css b/src-migrate/modules/cart/styles/item-promo.module.css
index 5bc192c0..15bf8146 100644
--- a/src-migrate/modules/cart/styles/item-promo.module.css
+++ b/src-migrate/modules/cart/styles/item-promo.module.css
@@ -1,5 +1,5 @@
.wrapper {
- @apply md:ml-12 ml-8 mt-4 flex;
+ @apply md:ml-16 ml-8 mt-4 flex;
}
.imageWrapper {
diff --git a/src-migrate/modules/header/components/HeaderDesktop.tsx b/src-migrate/modules/header/components/HeaderDesktop.tsx
index 3860bded..8f5a8efa 100644
--- a/src-migrate/modules/header/components/HeaderDesktop.tsx
+++ b/src-migrate/modules/header/components/HeaderDesktop.tsx
@@ -8,7 +8,7 @@ import Link from 'next/link'
import SearchBar from "./SearchBar";
// Constants
-import { SECONDARY_MENU_ITEMS } from "~/common/constants/menu";
+import { SECONDARY_MENU_ITEMS } from "~/constants/menu";
const LOGO_WIDTH = 210;
const LOGO_HEIGHT = LOGO_WIDTH / 3;
diff --git a/src-migrate/modules/page-content/index.tsx b/src-migrate/modules/page-content/index.tsx
index 608079f8..547b1957 100644
--- a/src-migrate/modules/page-content/index.tsx
+++ b/src-migrate/modules/page-content/index.tsx
@@ -1,7 +1,6 @@
import { useMemo } from "react"
import { useQuery } from "react-query"
-import PageContentSkeleton from "~/common/components/skeleton/PageContentSkeleton"
-import { PageContentProps } from "~/common/types/pageContent"
+import { PageContentProps } from "~/types/pageContent"
import { getPageContent } from "~/services/pageContent"
type Props = {
@@ -26,4 +25,20 @@ const PageContent = ({ path }: Props) => {
)
}
+const PageContentSkeleton = () => (
+ <div className="animate-pulse grid gap-y-4">
+ <div className="w-full h-10 bg-gray-300 rounded" />
+ <div className="h-2" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-8/12 h-4 bg-gray-300 rounded" />
+ <div className="h-2" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-full h-4 bg-gray-300 rounded" />
+ <div className="w-1/2 h-4 bg-gray-300 rounded" />
+ </div>
+)
+
export default PageContent \ No newline at end of file
diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx
index cd1fd5f2..3d537236 100644
--- a/src-migrate/modules/popup-information/index.tsx
+++ b/src-migrate/modules/popup-information/index.tsx
@@ -1,7 +1,7 @@
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
-import Modal from '~/common/components/elements/Modal';
-import { getAuth } from '~/common/libs/auth';
+import { Modal } from "~/components/ui/modal"
+import { getAuth } from '~/libs/auth';
import PageContent from '../page-content';
import Link from 'next/link';
diff --git a/src-migrate/modules/product-card/components/ProductCard.tsx b/src-migrate/modules/product-card/components/ProductCard.tsx
new file mode 100644
index 00000000..0a97b344
--- /dev/null
+++ b/src-migrate/modules/product-card/components/ProductCard.tsx
@@ -0,0 +1,106 @@
+import style from '../styles/product-card.module.css'
+
+import Link from 'next/link'
+import React from 'react'
+import Image from '~/components/ui/image'
+import clsxm from '~/libs/clsxm'
+import formatCurrency from '~/libs/formatCurrency'
+import { formatToShortText } from '~/libs/formatNumber'
+import { createSlug } from '~/libs/slug'
+import { IProduct } from '~/types/product'
+
+type Props = {
+ product: IProduct
+ layout?: 'vertical' | 'horizontal'
+}
+
+const ProductCard = ({ product, layout = 'vertical' }: Props) => {
+ const URL = {
+ product: createSlug('/shop/product/', product.name, product.id.toString()),
+ manufacture: createSlug('/shop/brands/', product.manufacture.name, product.manufacture.id.toString()),
+ }
+
+ return (
+ <div className={clsxm(style['wrapper'], {
+ [style['wrapper-v']]: layout === 'vertical',
+ [style['wrapper-h']]: layout === 'horizontal',
+ })}
+ >
+ <div className={clsxm('relative', {
+ [style['image-v']]: layout === 'vertical',
+ [style['image-h']]: layout === 'horizontal',
+ })}>
+ <Link href={URL.product}>
+ <Image
+ src={product.image || '/images/noimage.jpeg'}
+ alt={product.name}
+ width={128}
+ height={128}
+ className='object-contain object-center h-full w-full'
+ />
+ {product.variant_total > 1 && (
+ <div className={style['variant-badge']}>{product.variant_total} Varian</div>
+ )}
+ </Link>
+ </div>
+
+ <div className={clsxm({
+ [style['content-v']]: layout === 'vertical',
+ [style['content-h']]: layout === 'horizontal',
+ })}>
+ <Link
+ href={URL.manufacture}
+ className={style['brand']}
+ >
+ {product.manufacture.name}
+ </Link>
+
+ <div className='h-0.5' />
+
+ <Link
+ href={URL.product}
+ className={clsxm(style['name'], {
+ [style['name-v']]: layout === 'vertical',
+ [style['name-h']]: layout === 'horizontal',
+ })}
+ >
+ {product.name}
+ </Link>
+ <div className='h-1.5' />
+
+ <div className={style['price']}>
+ Rp {formatCurrency(product.lowest_price.price)}
+ </div>
+
+ <div className='h-1.5' />
+
+ <div className={style['price-inc']}>
+ Inc PPN:
+ Rp {formatCurrency(Math.round(product.lowest_price.price * 1.11))}
+ </div>
+
+ <div className='h-1' />
+
+ <div className='flex items-center gap-x-2.5'>
+ {product.stock_total > 0 && (
+ <div className={style['ready-stock']}>
+ Ready Stock
+ </div>
+ )}
+ {product.qty_sold > 0 && (
+ <div className={style['sold']}>
+ {formatToShortText(product.qty_sold)} Terjual
+ </div>
+ )}
+ </div>
+
+ </div>
+ </div>
+ )
+}
+
+const classPrefix = ({ layout }: Props) => {
+
+}
+
+export default ProductCard \ No newline at end of file
diff --git a/src-migrate/modules/product-card/index.tsx b/src-migrate/modules/product-card/index.tsx
new file mode 100644
index 00000000..c87167bc
--- /dev/null
+++ b/src-migrate/modules/product-card/index.tsx
@@ -0,0 +1,3 @@
+import ProductCard from "./components/ProductCard";
+
+export default ProductCard \ No newline at end of file
diff --git a/src-migrate/modules/product-card/styles/product-card.module.css b/src-migrate/modules/product-card/styles/product-card.module.css
new file mode 100644
index 00000000..653bf2ca
--- /dev/null
+++ b/src-migrate/modules/product-card/styles/product-card.module.css
@@ -0,0 +1,54 @@
+.wrapper {
+ @apply w-full flex;
+}
+.wrapper-v {
+ @apply flex-col border border-gray-300 rounded-md h-[350px];
+}
+.wrapper-h {
+ @apply flex-row gap-x-2 pt-4;
+}
+
+.image-v {
+ @apply w-full h-48 px-4 border-b border-gray-300;
+}
+.image-h {
+ @apply w-4/12 h-24 px-1;
+}
+
+.content-v {
+ @apply w-full p-2;
+}
+.content-h {
+ @apply w-8/12;
+}
+
+.brand {
+ @apply text-danger-500 font-medium block;
+}
+
+.name {
+ @apply text-gray-700 font-medium line-clamp-3;
+}
+.name-v {
+ @apply min-h-[64px];
+}
+.name-h {
+ @apply min-h-[32px];
+}
+
+.price {
+ @apply text-danger-500 font-medium;
+}
+
+.ready-stock {
+ @apply bg-danger-500 text-white text-[11px] px-2 py-1 rounded-md whitespace-nowrap;
+}
+
+.price-inc,
+.sold {
+ @apply text-gray-600 text-[11px];
+}
+
+.variant-badge {
+ @apply bg-gray-500/20 backdrop-blur-md absolute rounded-md bottom-2 left-2 px-2 py-1 text-caption-2;
+}
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx
new file mode 100644
index 00000000..4accab17
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/AddToCart.tsx
@@ -0,0 +1,79 @@
+import React from 'react'
+import { Button, useToast } from '@chakra-ui/react'
+import { getAuth } from '~/libs/auth'
+import { useRouter } from 'next/router'
+import Link from 'next/link'
+import { upsertUserCart } from '~/services/cart'
+
+type Props = {
+ variantId: number | null,
+ quantity?: number;
+ source?: 'buy' | 'add_to_cart';
+}
+
+const AddToCart = ({
+ variantId,
+ quantity = 1,
+ source = 'add_to_cart'
+}: Props) => {
+ const auth = getAuth()
+ const router = useRouter()
+ const toast = useToast({
+ position: 'top',
+ isClosable: true
+ })
+
+ const handleClick = async () => {
+ if (typeof auth !== 'object') {
+ const currentUrl = encodeURIComponent(router.asPath)
+ toast({
+ title: 'Masuk Akun',
+ description: <>
+ Masuk akun untuk dapat menambahkan barang ke keranjang belanja. {' '}
+ <Link className='underline' href={`/login?next=${currentUrl}`}>Klik disini</Link>
+ </>,
+ status: 'error',
+ duration: 4000,
+ })
+ return;
+ }
+
+ if (
+ !variantId ||
+ isNaN(quantity) ||
+ typeof auth !== 'object'
+ ) return;
+
+ toast.promise(
+ upsertUserCart(auth.id, 'product', variantId, quantity, true, source),
+ {
+ loading: { title: 'Menambahkan ke keranjang', description: 'Mohon tunggu...' },
+ success: { title: 'Menambahkan ke keranjang', description: 'Berhasil menambahkan ke keranjang belanja' },
+ error: { title: 'Menambahkan ke keranjang', description: 'Gagal menambahkan ke keranjang belanja' },
+ }
+ )
+
+ if (source === 'buy') {
+ router.push('/shop/checkout?source=buy')
+ }
+ }
+
+ const btnConfig = {
+ 'add_to_cart': {
+ colorScheme: 'yellow',
+ text: 'Keranjang'
+ },
+ 'buy': {
+ colorScheme: 'red',
+ text: 'Beli'
+ }
+ }
+
+ return (
+ <Button onClick={handleClick} colorScheme={btnConfig[source].colorScheme} className='w-full'>
+ {btnConfig[source].text}
+ </Button>
+ )
+}
+
+export default AddToCart \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/AddToWishlist.tsx b/src-migrate/modules/product-detail/components/AddToWishlist.tsx
new file mode 100644
index 00000000..697b2d5c
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/AddToWishlist.tsx
@@ -0,0 +1,61 @@
+import { Button, useToast } from '@chakra-ui/react'
+import { HeartIcon } from 'lucide-react'
+import React from 'react'
+import { useQuery } from 'react-query'
+import { getAuth } from '~/libs/auth'
+import clsxm from '~/libs/clsxm'
+import { getUserWishlist, upsertUserWishlist } from '~/services/wishlist'
+
+type Props = {
+ productId: number
+}
+
+const AddToWishlist = ({ productId }: Props) => {
+ const auth = getAuth()
+ const toast = useToast({
+ position: 'top',
+ isClosable: true
+ })
+
+ const searchParams = { product_id: productId.toString() }
+ const query = useQuery({
+ queryKey: ['wishlist', searchParams, auth],
+ queryFn: () => {
+ if (typeof auth !== 'object') return null;
+ return getUserWishlist(auth.id, searchParams)
+ },
+ refetchOnWindowFocus: false
+ })
+
+ const isAdded = query.data?.product_total ? query.data.product_total > 0 : false;
+
+ const toggleWishlist = async () => {
+ if (typeof auth !== 'object') return;
+ await upsertUserWishlist(auth.id, productId)
+ await query.refetch()
+ }
+
+ const handleClick = async () => {
+ toast.promise(toggleWishlist(), {
+ loading: { title: 'Update Wishlist', description: 'Mohon tunggu...' },
+ success: { title: 'Update Wishlist', description: 'Berhasil update wishlist' },
+ error: { title: 'Update Wishlist', description: 'Gagal update wishlist' },
+ })
+ }
+
+ return (
+ <Button
+ variant='link'
+ colorScheme='gray'
+ onClick={handleClick}
+ leftIcon={<HeartIcon size={18} className={clsxm('transition-colors', {
+ 'text-danger-500 fill-danger-500': isAdded,
+ 'fill-transparent': !isAdded
+ })} />}
+ >
+ Wishlist
+ </Button>
+ )
+}
+
+export default AddToWishlist \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/Breadcrumb.tsx b/src-migrate/modules/product-detail/components/Breadcrumb.tsx
new file mode 100644
index 00000000..f41859a9
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx
@@ -0,0 +1,41 @@
+import React, { Fragment } from 'react'
+import { useQuery } from 'react-query'
+import { getProductCategoryBreadcrumb } from '~/services/product'
+import Link from 'next/link'
+import { createSlug } from '~/libs/slug'
+
+type Props = {
+ id: number,
+ name: string
+}
+
+const Breadcrumb = ({ id, name }: Props) => {
+ const query = useQuery({
+ queryKey: ['product-category-breadcrumb'],
+ queryFn: () => getProductCategoryBreadcrumb(id),
+ refetchOnWindowFocus: false
+ })
+
+ const breadcrumbs = query.data || []
+
+ return (
+ <div className='line-clamp-2 md:line-clamp-1 leading-7 text-caption-1'>
+ <Link href='/' className='text-danger-500'>Home</Link>
+ <span className='mx-2'>/</span>
+ {breadcrumbs.map((category, index) => (
+ <Fragment key={index}>
+ <Link
+ href={createSlug('/shop/category/', category.name, category.id.toString())}
+ className='text-danger-500'
+ >
+ {category.name}
+ </Link>
+ <span className='mx-2'>/</span>
+ </Fragment>
+ ))}
+ <span>{name}</span>
+ </div>
+ )
+}
+
+export default Breadcrumb \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/Image.tsx b/src-migrate/modules/product-detail/components/Image.tsx
new file mode 100644
index 00000000..2ab3ff59
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/Image.tsx
@@ -0,0 +1,99 @@
+import style from '../styles/image.module.css';
+
+import React, { useEffect, useState } from 'react'
+import { InfoIcon } from 'lucide-react'
+import { Tooltip } from '@chakra-ui/react'
+
+import { IProductDetail } from '~/types/product'
+import ImageUI from '~/components/ui/image'
+import moment from 'moment';
+
+type Props = {
+ product: IProductDetail
+}
+
+const Image = ({ product }: Props) => {
+ const flashSale = product.flash_sale
+
+ const [count, setCount] = useState(flashSale?.remaining_time || 0);
+
+ useEffect(() => {
+ let interval: NodeJS.Timeout;
+
+ if (flashSale?.remaining_time && flashSale.remaining_time > 0) {
+ setCount(flashSale.remaining_time);
+
+ interval = setInterval(() => {
+ setCount((prevCount) => prevCount - 1);
+ }, 1000);
+ }
+
+ return () => {
+ clearInterval(interval);
+ };
+ }, [flashSale?.remaining_time]);
+
+ const duration = moment.duration(count, 'seconds')
+
+ return (
+ <div className={style['wrapper']}>
+ <ImageUI
+ src={product.image || '/images/noimage.jpeg'}
+ alt={product.name}
+ width={256}
+ height={256}
+ className={style['image']}
+ loading='eager'
+ priority
+ />
+
+ <div className={style['absolute-info']}>
+ <Tooltip
+ placement='bottom-end'
+ label='Gambar atau foto berperan sebagai ilustrasi produk. Kadang tidak sesuai dengan kondisi terbaru dengan berbagai perubahan dan perbaikan. Hubungi admin kami untuk informasi yang lebih baik perihal gambar.'
+ >
+ <div className="text-gray-600">
+ <InfoIcon size={20} />
+ </div>
+ </Tooltip>
+ </div>
+
+ {flashSale.remaining_time > 0 && (
+ <div className='absolute bottom-0 w-full h-14'>
+ <div className="relative w-full h-full">
+ <ImageUI
+ src='/images/GAMBAR-BG-FLASH-SALE.jpg'
+ alt='Flash Sale Indoteknik'
+ width={200}
+ height={100}
+ className={style['flashsale-bg']}
+ />
+
+ <div className={style['flashsale']}>
+ <div className='flex items-center gap-x-3'>
+ <div className={style['disc-badge']}>{Math.floor(product.lowest_price.discount_percentage)}%</div>
+ <div className={style['flashsale-text']}>
+ <ImageUI
+ src='/images/ICON_FLASH_SALE_WEBSITE_INDOTEKNIK.svg'
+ alt='Icon Flash Sale'
+ width={20}
+ height={20}
+ />
+ {product.flash_sale.tag}
+ </div>
+ </div>
+ <div className={style['countdown']}>
+ <span>{duration.hours().toString().padStart(2, '0')}</span>
+ <span>{duration.minutes().toString().padStart(2, '0')}</span>
+ <span>{duration.seconds().toString().padStart(2, '0')}</span>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
+
+export default Image \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx
new file mode 100644
index 00000000..52eb6b88
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/Information.tsx
@@ -0,0 +1,56 @@
+import style from '../styles/information.module.css'
+
+import React from 'react'
+import dynamic from 'next/dynamic'
+import Link from 'next/link'
+import { useQuery } from 'react-query'
+
+import { IProductDetail } from '~/types/product'
+import { IProductVariantSLA } from '~/types/productVariant'
+import { createSlug } from '~/libs/slug'
+import { getVariantSLA } from '~/services/productVariant'
+import { formatToShortText } from '~/libs/formatNumber'
+
+const Skeleton = dynamic(() => import('@chakra-ui/react').then((mod) => mod.Skeleton))
+
+type Props = {
+ product: IProductDetail
+}
+
+const Information = ({ product }: Props) => {
+ const querySLA = useQuery<IProductVariantSLA>({
+ queryKey: ['variant-sla', product.variants[0].id],
+ queryFn: () => getVariantSLA(product.variants[0].id),
+ enabled: product.variant_total === 1
+ })
+
+ const sla = querySLA?.data
+
+ return (
+ <div className={style['wrapper']}>
+ <div className={style['row']}>
+ <div className={style['label']}>SKU Number</div>
+ <div className={style['value']}>SKU-{product.id}</div>
+ </div>
+ <div className={style['row']}>
+ <div className={style['label']}>Manufacture</div>
+ <div className={style['value']}>
+ {!!product.manufacture.name ? (
+ <Link
+ href={createSlug('/shop/brands/', product.manufacture.name, product.manufacture.id.toString())}
+ className='text-danger-500 hover:underline'
+ >
+ {product.manufacture.name}
+ </Link>
+ ) : '-'}
+ </div>
+ </div>
+ <div className={style['row']}>
+ <div className={style['label']}>Terjual</div>
+ <div className={style['value']}>{product.qty_sold > 0 ? formatToShortText(product.qty_sold) : '-'}</div>
+ </div>
+ </div>
+ )
+}
+
+export default Information \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx
new file mode 100644
index 00000000..f25847a5
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/PriceAction.tsx
@@ -0,0 +1,76 @@
+import style from '../styles/price-action.module.css'
+
+import React, { useEffect } from 'react'
+import formatCurrency from '~/libs/formatCurrency'
+import { IProductDetail } from '~/types/product'
+import { useProductDetail } from '../stores/useProductDetail'
+import AddToCart from './AddToCart'
+import Link from 'next/link'
+
+type Props = {
+ product: IProductDetail
+}
+
+const PriceAction = ({ product }: Props) => {
+ const {
+ activePrice,
+ setActive,
+ activeVariantId,
+ quantityInput,
+ setQuantityInput,
+ askAdminUrl
+ } = useProductDetail()
+
+ useEffect(() => {
+ setActive(product.variants[0])
+ }, [product, setActive]);
+
+ return (
+ <div className='block md:sticky top-[150px] bg-white py-0 md:py-6 z-10' id='price-section'>
+ {!!activePrice && activePrice.price > 0 && (
+ <>
+ <div className='flex items-end gap-x-2'>
+ {activePrice.discount_percentage > 0 && (
+ <>
+ <div className={style['disc-badge']}>
+ {Math.floor(activePrice.discount_percentage)}%
+ </div>
+ <div className={style['disc-price']}>
+ Rp {formatCurrency(activePrice.price || 0)}
+ </div>
+ </>
+ )}
+ <div className={style['main-price']}>
+ Rp {formatCurrency(activePrice.price_discount || 0)}
+ </div>
+ </div>
+ <div className='h-1' />
+ <div className={style['secondary-text']}>
+ Termasuk PPN: {' '}
+ Rp {formatCurrency(Math.round(activePrice.price_discount * 1.11))}
+ </div>
+ </>
+ )}
+
+ {!!activePrice && activePrice.price === 0 && (
+ <span>
+ Hubungi kami untuk dapatkan harga terbaik,{' '}
+ <Link href={askAdminUrl} target='_blank' className={style['contact-us']}>
+ klik disini
+ </Link>
+ </span>
+ )}
+
+ <div className='h-4' />
+
+ <div className={style['action-wrapper']}>
+ <label htmlFor="quantity" className='hidden'>Quantity</label>
+ <input type='number' id='quantity' value={quantityInput} onChange={(e) => setQuantityInput(e.target.value)} className={style['quantity-input']} />
+ <AddToCart variantId={activeVariantId} quantity={Number(quantityInput)} />
+ <AddToCart source='buy' variantId={activeVariantId} quantity={Number(quantityInput)} />
+ </div>
+ </div>
+ )
+}
+
+export default PriceAction \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx
new file mode 100644
index 00000000..80f43aea
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx
@@ -0,0 +1,178 @@
+import style from '../styles/product-detail.module.css'
+
+import React, { useEffect } from 'react'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+
+import { MessageCircleIcon, Share2Icon } from 'lucide-react'
+import { Button } from '@chakra-ui/react'
+
+import { IProductDetail } from '~/types/product'
+import useDevice from '@/core/hooks/useDevice'
+import { whatsappUrl } from '~/libs/whatsappUrl'
+
+import { useProductDetail } from '../stores/useProductDetail'
+
+import { RWebShare } from 'react-web-share'
+import ProductImage from './Image'
+import Information from './Information'
+import AddToWishlist from './AddToWishlist'
+import VariantList from './VariantList'
+import SimilarSide from './SimilarSide'
+import SimilarBottom from './SimilarBottom'
+import PriceAction from './PriceAction'
+import ProductPromoSection from '~/modules/product-promo/components/Section'
+import Breadcrumb from './Breadcrumb'
+
+type Props = {
+ product: IProductDetail
+}
+
+const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST
+
+const ProductDetail = ({ product }: Props) => {
+ const { isDesktop, isMobile } = useDevice()
+ const router = useRouter()
+ const { setAskAdminUrl, askAdminUrl, activeVariantId } = useProductDetail()
+
+ useEffect(() => {
+ const createdAskUrl = whatsappUrl({
+ template: 'product',
+ payload: {
+ manufacture: product.manufacture.name,
+ productName: product.name,
+ url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath
+ },
+ fallbackUrl: router.asPath
+ })
+
+ setAskAdminUrl(createdAskUrl)
+ }, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl])
+
+ return (
+ <>
+ <div className='md:flex md:flex-wrap'>
+ <div className="w-full mb-4 md:mb-0 px-4 md:px-0">
+ <Breadcrumb id={product.id} name={product.name} />
+ </div>
+ <div className='md:w-9/12 md:flex md:flex-col md:pr-4 md:pt-6'>
+ <div className='md:flex md:flex-wrap'>
+ <div className="md:w-4/12">
+ <ProductImage product={product} />
+ </div>
+
+ <div className='md:w-8/12 px-4 md:pl-6'>
+ <div className='h-6 md:h-0' />
+
+ <h1 className={style['title']}>
+ {product.name}
+ </h1>
+
+ <div className='h-6 md:h-8' />
+
+ <Information product={product} />
+
+ <div className='h-6' />
+
+ <div className="flex gap-x-5">
+ <Button
+ as={Link}
+ href={askAdminUrl}
+ variant='link'
+ target='_blank'
+ colorScheme='gray'
+ leftIcon={<MessageCircleIcon size={18} />}
+ >
+ Ask Admin
+ </Button>
+
+ <AddToWishlist productId={product.id} />
+
+ <RWebShare
+ data={{
+ text: 'Check out this product',
+ title: `${product.name} - Indoteknik.com`,
+ url: SELF_HOST + router.asPath
+ }}
+ >
+ <Button
+ variant='link'
+ colorScheme='gray'
+ leftIcon={<Share2Icon size={18} />}
+ >
+ Share
+ </Button>
+ </RWebShare>
+ </div>
+
+ </div>
+ </div>
+
+ <div className='h-full'>
+ {isMobile && (
+ <div className='px-4 pt-6'>
+ <PriceAction product={product} />
+ </div>
+ )}
+
+ <div className='h-4 md:h-10' />
+ {!!activeVariantId && (
+ <ProductPromoSection productId={activeVariantId} />
+ )}
+
+ <div className={style['section-card']}>
+ <h2 className={style['heading']}>
+ Variant ({product.variant_total})
+ </h2>
+ <div className='h-4' />
+ <VariantList variants={product.variants} />
+ </div>
+
+ <div className='h-0 md:h-6' />
+
+ <div className={style['section-card']}>
+ <h2 className={style['heading']}>
+ Informasi Produk
+ </h2>
+ <div className='h-4' />
+ <div
+ className={style['description']}
+ dangerouslySetInnerHTML={{ __html: !product.description || product.description == '<p><br></p>' ? 'Belum ada deskripsi' : product.description }}
+ />
+ </div>
+ </div>
+ </div>
+
+ {isDesktop && (
+ <div className="md:w-3/12">
+ <PriceAction product={product} />
+
+ <div className='h-6' />
+
+ <div className={style['heading']}>
+ Produk Serupa
+ </div>
+
+ <div className='h-4' />
+
+ <SimilarSide product={product} />
+ </div>
+ )}
+
+ <div className='md:w-full pt-4 md:py-10 px-4 md:px-0'>
+ <div className={style['heading']}>
+ Kamu Mungkin Juga Suka
+ </div>
+
+ <div className='h-6' />
+
+ <SimilarBottom product={product} />
+ </div>
+
+ <div className='h-6 md:h-0' />
+ </div>
+ </>
+ )
+}
+
+export default ProductDetail \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/SimilarBottom.tsx b/src-migrate/modules/product-detail/components/SimilarBottom.tsx
new file mode 100644
index 00000000..9a12a6ef
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/SimilarBottom.tsx
@@ -0,0 +1,21 @@
+import React from 'react'
+import useProductSimilar from '~/modules/product-similar/hooks/useProductSimilar'
+import ProductSlider from '~/modules/product-slider'
+import { IProductDetail } from '~/types/product'
+
+type Props = {
+ product: IProductDetail
+}
+
+const SimilarBottom = ({ product }: Props) => {
+ const productSimilar = useProductSimilar({
+ name: product.name,
+ except: { productId: product.id }
+ })
+
+ const products = productSimilar.data?.products || []
+
+ return <ProductSlider products={products} productLayout='vertical' />;
+}
+
+export default SimilarBottom \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/SimilarSide.tsx b/src-migrate/modules/product-detail/components/SimilarSide.tsx
new file mode 100644
index 00000000..646a1c51
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/SimilarSide.tsx
@@ -0,0 +1,34 @@
+import style from '../styles/side-similar.module.css'
+
+import React from 'react'
+
+import ProductCard from '~/modules/product-card'
+import useProductSimilar from '~/modules/product-similar/hooks/useProductSimilar'
+import { IProductDetail } from '~/types/product'
+
+type Props = {
+ product: IProductDetail
+}
+
+const SimilarSide = ({ product }: Props) => {
+ const productSimilar = useProductSimilar({
+ name: product.name,
+ except: { productId: product.id, manufactureId: product.manufacture.id },
+ })
+
+ const products = productSimilar.data?.products || []
+
+ return (
+ <div className={style['wrapper']}>
+ {products.map((product) => (
+ <ProductCard
+ key={product.id}
+ product={product}
+ layout='horizontal'
+ />
+ ))}
+ </div>
+ )
+}
+
+export default SimilarSide \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/components/VariantList.tsx b/src-migrate/modules/product-detail/components/VariantList.tsx
new file mode 100644
index 00000000..3d5b9b74
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/VariantList.tsx
@@ -0,0 +1,117 @@
+import style from '../styles/variant-list.module.css'
+
+import React from 'react'
+import { Button, Skeleton } from '@chakra-ui/react'
+
+import formatCurrency from '~/libs/formatCurrency'
+import clsxm from '~/libs/clsxm'
+import { IProductVariantDetail, IProductVariantSLA } from '~/types/productVariant'
+import { useProductDetail } from '../stores/useProductDetail'
+import { LazyLoadComponent } from 'react-lazy-load-image-component';
+import { getVariantSLA } from '~/services/productVariant'
+import { useQuery } from 'react-query'
+import useDevice from '@/core/hooks/useDevice'
+
+type Props = {
+ variants: IProductVariantDetail[]
+}
+
+const VariantList = ({ variants }: Props) => {
+ return (
+ <div className='overflow-auto'>
+ <div className={style['wrapper']}>
+ <div className={style['header']}>
+ <div className="w-2/12">Part Number</div>
+ <div className="w-2/12">Variant</div>
+ <div className="w-1/12">Stock</div>
+ <div className="w-2/12">Masa Persiapan</div>
+ <div className="w-1/12">Berat</div>
+ <div className="w-3/12">Harga</div>
+ <div className='w-1/12 sticky right-0 bg-gray-200'></div>
+ </div>
+ {variants.map((variant) => (
+ <LazyLoadComponent key={variant.id}>
+ <Row variant={variant} />
+ </LazyLoadComponent>
+ ))}
+ </div>
+ </div>
+ )
+}
+
+const Row = ({ variant }: { variant: IProductVariantDetail }) => {
+ const { isMobile } = useDevice()
+
+ const { activeVariantId, setActive } = useProductDetail()
+ const querySLA = useQuery<IProductVariantSLA>({
+ queryKey: ['variant-sla', variant.id],
+ queryFn: () => getVariantSLA(variant.id),
+ refetchOnWindowFocus: false,
+ })
+
+ const sla = querySLA?.data
+
+ const handleSelect = (variant: IProductVariantDetail) => {
+ const priceSectionEl = document.getElementById('price-section')
+ if (isMobile && priceSectionEl) {
+ window.scrollTo({
+ top: priceSectionEl.offsetTop - 120,
+ behavior: 'smooth'
+ })
+ }
+ setActive(variant)
+ }
+
+ return (
+ <div className={style['row']}>
+ <div className='w-2/12'>{variant.code}</div>
+ <div className='w-2/12'>{variant.attributes.join(', ') || '-'}</div>
+ <div className='w-1/12'>
+ <Skeleton isLoaded={querySLA.isSuccess} h='21px' w={16}>
+ {sla?.qty !== undefined && (
+ <div className={clsxm('text-center rounded-md', {
+ [style['stock-empty']]: sla.qty == 0,
+ [style['stock-ready']]: sla.qty > 0,
+ })}
+ >
+ {sla.qty > 0 && sla.qty}
+ {sla.qty == 0 && '-'}
+ </div>
+ )}
+ </Skeleton>
+ </div>
+ <div className='w-2/12'>
+ <Skeleton isLoaded={querySLA.isSuccess} h='21px' w={16}>
+ {sla?.sla_date}
+ </Skeleton>
+ </div>
+ <div className='w-1/12'>
+ {variant.weight > 0 ? `${variant.weight} Kg` : '-'}
+ </div>
+ <div className='w-3/12'>
+ {variant.price.discount_percentage > 0 && (
+ <div className='flex items-center gap-x-1'>
+ <div className={style['disc-badge']}>{Math.floor(variant.price.discount_percentage)}%</div>
+ <div className={style['disc-price']}>Rp {formatCurrency(variant.price.price)}</div>
+ </div>
+ )}
+ {variant.price.price_discount > 0 && `Rp ${formatCurrency(variant.price.price_discount)}`}
+ {variant.price.price_discount === 0 && '-'}
+ </div>
+ <div className='w-1/12 sticky right-0 bg-white md:bg-transparent'>
+ <Button
+ onClick={() => handleSelect(variant)}
+ size='sm'
+ w='100%'
+ className={clsxm(style['select-btn'], {
+ [style['select-btn--active']]: variant.id === activeVariantId
+ })}
+ >
+ Pilih
+ </Button>
+ </div>
+ </div>
+ )
+}
+
+export default VariantList \ No newline at end of file
diff --git a/src-migrate/modules/product-detail/index.ts b/src-migrate/modules/product-detail/index.ts
new file mode 100644
index 00000000..246bc06a
--- /dev/null
+++ b/src-migrate/modules/product-detail/index.ts
@@ -0,0 +1,3 @@
+import ProductDetail from './components/ProductDetail';
+
+export default ProductDetail;
diff --git a/src-migrate/modules/product-detail/stores/useProductDetail.ts b/src-migrate/modules/product-detail/stores/useProductDetail.ts
new file mode 100644
index 00000000..794f0346
--- /dev/null
+++ b/src-migrate/modules/product-detail/stores/useProductDetail.ts
@@ -0,0 +1,31 @@
+import { create } from 'zustand';
+import { IProductVariantDetail } from '~/types/productVariant';
+
+type State = {
+ activeVariantId: number | null;
+ activePrice: IProductVariantDetail['price'] | null;
+ quantityInput: string;
+ askAdminUrl: string;
+};
+
+type Action = {
+ setActive: (variant: IProductVariantDetail) => void;
+ setQuantityInput: (value: string) => void;
+ setAskAdminUrl: (url: string) => void;
+};
+
+export const useProductDetail = create<State & Action>((set, get) => ({
+ activeVariantId: null,
+ activePrice: null,
+ quantityInput: '1',
+ askAdminUrl: '',
+ setActive: (variant) => {
+ set({ activeVariantId: variant.id, activePrice: variant.price });
+ },
+ setQuantityInput: (value: string) => {
+ set({ quantityInput: value });
+ },
+ setAskAdminUrl: (url: string) => {
+ set({ askAdminUrl: url });
+ },
+}));
diff --git a/src-migrate/modules/product-detail/styles/image.module.css b/src-migrate/modules/product-detail/styles/image.module.css
new file mode 100644
index 00000000..e472fe8d
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/image.module.css
@@ -0,0 +1,35 @@
+.wrapper {
+ @apply h-[250px] md:h-[340px] flex items-center justify-center border border-gray-200 rounded-lg p-4 relative;
+}
+
+.image {
+ @apply object-contain object-center h-full w-full;
+}
+
+.absolute-info {
+ @apply absolute hidden md:block top-4 right-4;
+}
+
+.disc-badge {
+ @apply bg-warning-500 py-1 px-3 w-fit font-semibold rounded-full;
+}
+
+.countdown {
+ @apply flex gap-x-1;
+}
+
+.countdown span {
+ @apply py-0.5 w-8 bg-warning-500 rounded-md text-center;
+}
+
+.flashsale-text {
+ @apply flex items-center gap-x-2 text-white font-medium text-caption-1;
+}
+
+.flashsale-bg {
+ @apply absolute top-0 w-full h-full object-cover object-center z-10;
+}
+
+.flashsale {
+ @apply absolute top-0 w-full h-full z-20 flex items-center justify-between px-3;
+}
diff --git a/src-migrate/modules/product-detail/styles/information.module.css b/src-migrate/modules/product-detail/styles/information.module.css
new file mode 100644
index 00000000..c9b29020
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/information.module.css
@@ -0,0 +1,19 @@
+.wrapper {
+ @apply grid grid-cols-1;
+}
+
+.row {
+ @apply flex p-3 rounded;
+}
+
+.row:nth-child(odd) {
+ @apply bg-gray-100;
+}
+
+.label {
+ @apply w-1/2 md:w-1/3 font-medium text-gray-500;
+}
+
+.value {
+ @apply w-1/2 md:w-3/4 text-gray-950;
+}
diff --git a/src-migrate/modules/product-detail/styles/price-action.module.css b/src-migrate/modules/product-detail/styles/price-action.module.css
new file mode 100644
index 00000000..651de958
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/price-action.module.css
@@ -0,0 +1,24 @@
+.secondary-text {
+ @apply font-medium text-gray-500;
+}
+.main-price {
+ @apply font-medium text-danger-500 text-title-md;
+}
+.action-wrapper {
+ @apply flex gap-x-2.5;
+}
+.quantity-input {
+ @apply px-2 rounded text-center border border-gray-300 w-14 h-10 focus:outline-none;
+}
+
+.contact-us {
+ @apply text-danger-500 font-medium underline;
+}
+
+.disc-badge {
+ @apply bg-danger-500 px-2 py-1.5 rounded text-white text-caption-2;
+}
+
+.disc-price {
+ @apply line-through text-gray-600 text-caption-2;
+}
diff --git a/src-migrate/modules/product-detail/styles/product-detail.module.css b/src-migrate/modules/product-detail/styles/product-detail.module.css
new file mode 100644
index 00000000..c668167c
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/product-detail.module.css
@@ -0,0 +1,15 @@
+.title {
+ @apply font-medium text-h-lg leading-8 md:text-title-md md:leading-10;
+}
+
+.section-card {
+ @apply p-4 md:p-6 md:bg-gray-50 rounded-xl;
+}
+
+.heading {
+ @apply text-h-md md:text-h-lg font-medium;
+}
+
+.description {
+ @apply leading-relaxed text-gray-700;
+}
diff --git a/src-migrate/modules/product-detail/styles/side-similar.module.css b/src-migrate/modules/product-detail/styles/side-similar.module.css
new file mode 100644
index 00000000..08692efa
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/side-similar.module.css
@@ -0,0 +1,3 @@
+.wrapper {
+ @apply max-h-[500px] overflow-auto grid grid-cols-1 gap-y-4 divide-y divide-gray-300 border border-gray-300 rounded-lg;
+}
diff --git a/src-migrate/modules/product-detail/styles/variant-list.module.css b/src-migrate/modules/product-detail/styles/variant-list.module.css
new file mode 100644
index 00000000..6d46df84
--- /dev/null
+++ b/src-migrate/modules/product-detail/styles/variant-list.module.css
@@ -0,0 +1,35 @@
+.wrapper {
+ @apply grid grid-cols-1 w-[200%] md:w-full;
+}
+
+.header {
+ @apply flex py-2.5 pl-4 font-medium bg-gray-200 rounded-md;
+}
+
+.row {
+ @apply flex items-center py-2.5 pl-4 text-gray-800;
+}
+
+.select-btn {
+ @apply !bg-gray-200 hover:!bg-danger-500 hover:!text-white;
+}
+
+.select-btn--active {
+ @apply !text-white !bg-danger-500 hover:!text-white;
+}
+
+.stock-empty {
+ @apply bg-red-50 border border-red-500 text-red-800;
+}
+
+.stock-ready {
+ @apply bg-green-50 border border-green-500 text-green-800;
+}
+
+.disc-badge {
+ @apply bg-danger-500 p-1 rounded text-white text-caption-2;
+}
+
+.disc-price {
+ @apply text-caption-2 line-through text-gray-600;
+}
diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx
index 58bb2ad7..3bac3c66 100644
--- a/src-migrate/modules/product-promo/components/AddToCart.tsx
+++ b/src-migrate/modules/product-promo/components/AddToCart.tsx
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react'
import { CheckIcon, PlusIcon } from 'lucide-react'
-import { IPromotion } from '~/common/types/promotion'
+import { IPromotion } from '~/types/promotion'
import { upsertUserCart } from '~/services/cart'
-import { getAuth } from '~/common/libs/auth'
+import { getAuth } from '~/libs/auth'
import { Button, Spinner, useToast } from '@chakra-ui/react'
import Link from 'next/link'
import { useRouter } from 'next/router'
diff --git a/src-migrate/modules/product-promo/components/Card.tsx b/src-migrate/modules/product-promo/components/Card.tsx
index e894c143..59110098 100644
--- a/src-migrate/modules/product-promo/components/Card.tsx
+++ b/src-migrate/modules/product-promo/components/Card.tsx
@@ -6,11 +6,11 @@ import { Skeleton, Tooltip } from '@chakra-ui/react'
import { motion } from "framer-motion"
import { PROMO_CATEGORY } from "~/constants/promotion"
-import { getVariantById } from "~/services/variant"
+import { getVariantById } from "~/services/productVariant"
-import { IProductVariantPromo, IPromotion } from '~/common/types/promotion'
-import formatCurrency from '~/common/libs/formatCurrency'
-import clsxm from '~/common/libs/clsxm'
+import { IProductVariantPromo, IPromotion } from '~/types/promotion'
+import formatCurrency from '~/libs/formatCurrency'
+import clsxm from '~/libs/clsxm'
import ProductPromoItem from './Item'
import ProductPromoAddToCart from "./AddToCart"
diff --git a/src-migrate/modules/product-promo/components/CardCountdown.tsx b/src-migrate/modules/product-promo/components/CardCountdown.tsx
index e398a390..b61ad115 100644
--- a/src-migrate/modules/product-promo/components/CardCountdown.tsx
+++ b/src-migrate/modules/product-promo/components/CardCountdown.tsx
@@ -6,8 +6,8 @@ import { ClockIcon } from 'lucide-react'
import { Skeleton } from '@chakra-ui/react'
import moment from 'moment'
-import clsxm from '~/common/libs/clsxm'
-import { IPromotion } from '~/common/types/promotion'
+import clsxm from '~/libs/clsxm'
+import { IPromotion } from '~/types/promotion'
import { getPromotionProgram } from '~/services/promotionProgram'
type Props = {
diff --git a/src-migrate/modules/product-promo/components/CategoryTab.tsx b/src-migrate/modules/product-promo/components/CategoryTab.tsx
index edc4aa92..c8e698c2 100644
--- a/src-migrate/modules/product-promo/components/CategoryTab.tsx
+++ b/src-migrate/modules/product-promo/components/CategoryTab.tsx
@@ -1,8 +1,8 @@
import React from 'react'
import style from '../styles/category-tab.module.css'
import { useModalStore } from '../stores/useModalStore'
-import clsxm from '~/common/libs/clsxm'
-import { ICategoryPromo } from '~/common/types/promotion'
+import clsxm from '~/libs/clsxm'
+import { ICategoryPromo } from '~/types/promotion'
const TABS: ICategoryPromo[] = [
{ value: 'bundling', label: 'Bundling' },
diff --git a/src-migrate/modules/product-promo/components/Item.tsx b/src-migrate/modules/product-promo/components/Item.tsx
index 15ca4878..8012c17e 100644
--- a/src-migrate/modules/product-promo/components/Item.tsx
+++ b/src-migrate/modules/product-promo/components/Item.tsx
@@ -1,9 +1,9 @@
import style from '../styles/item.module.css'
import React from 'react'
-import Image from 'next/image'
+import Image from '~/components/ui/image'
-import { IProductVariantPromo } from '~/common/types/promotion'
+import { IProductVariantPromo } from '~/types/promotion'
type Props = {
variant: IProductVariantPromo,
@@ -17,7 +17,7 @@ const ProductPromoItem = ({
return (
<div className={style.item}>
<div className={style.image}>
- <Image src={variant.image} alt={variant.display_name} width={120} height={120} quality={100} />
+ <Image src={variant.image || '/images/noimage.jpeg'} alt={variant.display_name} width={120} height={120} quality={100} />
<div className={style.quantity}>
{variant.qty} pcs {isFree ? '(free)' : ''}
</div>
diff --git a/src-migrate/modules/product-promo/components/Modal.tsx b/src-migrate/modules/product-promo/components/Modal.tsx
index 598b7bbe..0de672c2 100644
--- a/src-migrate/modules/product-promo/components/Modal.tsx
+++ b/src-migrate/modules/product-promo/components/Modal.tsx
@@ -1,5 +1,5 @@
import React from 'react'
-import Modal from '~/common/components/elements/Modal'
+import { Modal } from "~/components/ui/modal"
import { useModalStore } from '../stores/useModalStore'
import ProductPromoCategoryTab from './CategoryTab'
import ProductPromoModalContent from './ModalContent'
diff --git a/src-migrate/modules/product-promo/components/ModalContent.tsx b/src-migrate/modules/product-promo/components/ModalContent.tsx
index 90cf79e7..ab5129f8 100644
--- a/src-migrate/modules/product-promo/components/ModalContent.tsx
+++ b/src-migrate/modules/product-promo/components/ModalContent.tsx
@@ -1,7 +1,7 @@
import { useQuery } from "react-query"
import { Skeleton } from "@chakra-ui/react"
-import { getVariantPromoByCategory } from "~/services/variant"
+import { getVariantPromoByCategory } from "~/services/productVariant"
import { useModalStore } from "../stores/useModalStore"
import ProductPromoCard from "./Card"
diff --git a/src-migrate/modules/product-promo/components/Section.tsx b/src-migrate/modules/product-promo/components/Section.tsx
index 47e1de29..b6753be7 100644
--- a/src-migrate/modules/product-promo/components/Section.tsx
+++ b/src-migrate/modules/product-promo/components/Section.tsx
@@ -5,9 +5,10 @@ import { useQuery } from 'react-query'
import { Button, Skeleton } from '@chakra-ui/react'
import ProductPromoCard from './Card'
-import { IPromotion } from '~/common/types/promotion'
+import { IPromotion } from '~/types/promotion'
import ProductPromoModal from "./Modal"
import { useModalStore } from "../stores/useModalStore"
+import clsxm from "~/libs/clsxm"
type Props = {
productId: number
@@ -36,7 +37,13 @@ const ProductPromoSection = ({ productId }: Props) => {
</div>
)}
- <Skeleton isLoaded={promotionsQuery.isSuccess} className="flex gap-x-4 overflow-x-auto min-h-[340px] px-4 md:px-0">
+ <Skeleton
+ isLoaded={promotionsQuery.isSuccess}
+ className={clsxm(
+ "flex gap-x-4 overflow-x-auto px-4 md:px-0", {
+ "min-h-[340px]": promotions?.data && promotions?.data.length > 0
+ })}
+ >
{promotions?.data.map((promotion) => (
<div key={promotion.id} className="min-w-[400px] max-w-[400px]">
<ProductPromoCard promotion={promotion} />
diff --git a/src-migrate/modules/product-promo/stores/useModalStore.ts b/src-migrate/modules/product-promo/stores/useModalStore.ts
index bbb2b1fb..464bb598 100644
--- a/src-migrate/modules/product-promo/stores/useModalStore.ts
+++ b/src-migrate/modules/product-promo/stores/useModalStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand';
-import { CategoryPromo } from '~/common/types/promotion';
+import { CategoryPromo } from '~/types/promotion';
type State = {
active: boolean;
diff --git a/src-migrate/modules/product-similar/hooks/useProductSimilar.tsx b/src-migrate/modules/product-similar/hooks/useProductSimilar.tsx
new file mode 100644
index 00000000..f2c49472
--- /dev/null
+++ b/src-migrate/modules/product-similar/hooks/useProductSimilar.tsx
@@ -0,0 +1,15 @@
+import { useQuery } from 'react-query'
+import { GetProductSimilarProps, getProductSimilar } from '~/services/product'
+
+type Props = GetProductSimilarProps
+
+const useProductSimilar = (props: Props) => {
+ const similarQuery = useQuery({
+ queryKey: ['product-similar', props],
+ queryFn: () => getProductSimilar(props),
+ })
+
+ return similarQuery
+}
+
+export default useProductSimilar \ No newline at end of file
diff --git a/src-migrate/modules/product-slider/components/ProductSlider.tsx b/src-migrate/modules/product-slider/components/ProductSlider.tsx
new file mode 100644
index 00000000..3d6e7593
--- /dev/null
+++ b/src-migrate/modules/product-slider/components/ProductSlider.tsx
@@ -0,0 +1,42 @@
+import 'swiper/css'
+
+import React from 'react'
+import { Swiper, SwiperSlide } from 'swiper/react'
+import { FreeMode } from 'swiper'
+
+import ProductCard from '~/modules/product-card'
+import { IProduct } from '~/types/product'
+import useDevice from '@/core/hooks/useDevice'
+
+type Props = {
+ products: IProduct[],
+ productLayout?: 'vertical' | 'horizontal',
+}
+
+const ProductSlider = ({ products, productLayout }: Props) => {
+ const { isDesktop } = useDevice()
+
+ return (
+ <div>
+ <Swiper
+ slidesPerView={isDesktop ? 6.7 : 1.85}
+ spaceBetween={isDesktop ? 16 : 12}
+ prefix='product-slider'
+ modules={[FreeMode]}
+ freeMode={{ enabled: true, sticky: false }}
+ className='!pb-0.5'
+ >
+ {products.map((product) => (
+ <SwiperSlide key={product.id}>
+ <ProductCard
+ product={product}
+ layout={productLayout}
+ />
+ </SwiperSlide>
+ ))}
+ </Swiper>
+ </div >
+ )
+}
+
+export default ProductSlider \ No newline at end of file
diff --git a/src-migrate/modules/product-slider/index.ts b/src-migrate/modules/product-slider/index.ts
new file mode 100644
index 00000000..1593a543
--- /dev/null
+++ b/src-migrate/modules/product-slider/index.ts
@@ -0,0 +1,3 @@
+import ProductSlider from './components/ProductSlider';
+
+export default ProductSlider;
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx
index dc9107b2..b834f97a 100644
--- a/src-migrate/modules/register/components/Form.tsx
+++ b/src-migrate/modules/register/components/Form.tsx
@@ -1,7 +1,7 @@
import { ChangeEvent, useMemo } from "react";
import { useMutation } from "react-query";
-import { useRegisterStore } from "~/common/stores/useRegisterStore";
-import { RegisterProps } from "~/common/types/auth";
+import { useRegisterStore } from "../stores/useRegisterStore";
+import { RegisterProps } from "~/types/auth";
import { registerUser } from "~/services/auth";
import TermCondition from "./TermCondition";
import FormCaptcha from "./FormCaptcha";
diff --git a/src-migrate/modules/register/components/FormCaptcha.tsx b/src-migrate/modules/register/components/FormCaptcha.tsx
index 967be017..fbea2b10 100644
--- a/src-migrate/modules/register/components/FormCaptcha.tsx
+++ b/src-migrate/modules/register/components/FormCaptcha.tsx
@@ -1,5 +1,5 @@
-import ReCaptcha from '~/common/components/elements/ReCaptcha'
-import { useRegisterStore } from '~/common/stores/useRegisterStore'
+import { ReCaptcha } from '~/components/ui/re-captcha'
+import { useRegisterStore } from "../stores/useRegisterStore";
const FormCaptcha = () => {
const { updateValidCaptcha } = useRegisterStore()
diff --git a/src-migrate/modules/register/components/TermCondition.tsx b/src-migrate/modules/register/components/TermCondition.tsx
index 6b95ba19..b7729deb 100644
--- a/src-migrate/modules/register/components/TermCondition.tsx
+++ b/src-migrate/modules/register/components/TermCondition.tsx
@@ -1,7 +1,7 @@
import { Checkbox } from '@chakra-ui/react'
import React from 'react'
-import Modal from '~/common/components/elements/Modal'
-import { useRegisterStore } from '~/common/stores/useRegisterStore'
+import { Modal } from '~/components/ui/modal'
+import { useRegisterStore } from "../stores/useRegisterStore";
import PageContent from '~/modules/page-content'
const TermCondition = () => {
diff --git a/src-migrate/modules/register/stores/useRegisterStore.ts b/src-migrate/modules/register/stores/useRegisterStore.ts
new file mode 100644
index 00000000..d8abf52b
--- /dev/null
+++ b/src-migrate/modules/register/stores/useRegisterStore.ts
@@ -0,0 +1,60 @@
+import { create } from 'zustand';
+import { RegisterProps } from '~/types/auth';
+import { registerSchema } from '~/validations/auth';
+import { ZodError } from 'zod';
+
+type State = {
+ form: RegisterProps;
+ errors: {
+ [key in keyof RegisterProps]?: string;
+ };
+ isCheckedTNC: boolean;
+ isOpenTNC: boolean;
+ isValidCaptcha: boolean;
+};
+
+type Action = {
+ updateForm: (name: string, value: string) => void;
+ updateValidCaptcha: (value: boolean) => void;
+ toggleCheckTNC: () => void;
+ openTNC: () => void;
+ closeTNC: () => void;
+ validate: () => void;
+};
+
+export const useRegisterStore = create<State & Action>((set, get) => ({
+ form: {
+ company: '',
+ name: '',
+ email: '',
+ password: '',
+ phone: '',
+ },
+ updateForm: (name, value) =>
+ set((state) => ({ form: { ...state.form, [name]: value } })),
+
+ errors: {},
+ validate: () => {
+ try {
+ registerSchema.parse(get().form);
+ set({ errors: {} });
+ } catch (error) {
+ if (error instanceof ZodError) {
+ const errors: State['errors'] = {};
+ error.errors.forEach(
+ (e) => (errors[e.path[0] as keyof RegisterProps] = e.message)
+ );
+ set({ errors });
+ }
+ }
+ },
+ isCheckedTNC: false,
+ toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })),
+
+ isOpenTNC: false,
+ openTNC: () => set(() => ({ isOpenTNC: true })),
+ closeTNC: () => set(() => ({ isOpenTNC: false })),
+
+ isValidCaptcha: false,
+ updateValidCaptcha: (value) => set(() => ({ isValidCaptcha: value })),
+}));