summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-detail/components/ProductDetail.tsx
blob: 08ad7d51b989263ef0a951c0ec71d37e3523cfad (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import style from '../styles/product-detail.module.css'

import React, { useEffect } from 'react'
import Link from 'next/link'
import { MessageCircleIcon } from 'lucide-react'
import { Button } from '@chakra-ui/react'

import { IProductDetail } from '~/types/product'

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 useDevice from '@/core/hooks/useDevice'
import PriceAction from './PriceAction'
import { whatsappUrl } from '~/libs/whatsappUrl'
import { useRouter } from 'next/router'
import { useProductDetail } from '../stores/useProductDetail'
import ProductPromoSection from '~/modules/product-promo/components/Section'

type Props = {
  product: IProductDetail
}

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='md:w-9/12 md:flex md:flex-col md:pr-4'>
          <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-4' />

              <Button
                as={Link}
                href={askAdminUrl}
                variant='link'
                target='_blank'
                colorScheme='red'
                leftIcon={<MessageCircleIcon size={18} />}
              >
                Ask Admin
              </Button>
            </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} />

            <AddToWishlist />

            <div className='h-8' />

            <div className={style['heading']}>
              Produk Serupa
            </div>

            <div className='h-4' />

            <SimilarSide product={product} />
          </div>
        )}

        <div className='md:w-full py-0 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