summaryrefslogtreecommitdiff
path: root/src/lib/wishlist/components/Wishlists.jsx
blob: e13c61e577e501e0597f373e7936e7dd3093ad4d (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
import Alert from '@/core/components/elements/Alert/Alert'
import Pagination from '@/core/components/elements/Pagination/Pagination'
import Spinner from '@/core/components/elements/Spinner/Spinner'
import ProductCard from '@/lib/product/components/ProductCard'
import { useRouter } from 'next/router'
import useWishlists from '../hooks/useWishlists'
import MobileView from '@/core/components/views/MobileView'
import DesktopView from '@/core/components/views/DesktopView'
import Menu from '@/lib/auth/components/Menu'

const Wishlists = () => {
  const router = useRouter()
  const { page = 1 } = router.query
  const limit = 30
  const { wishlists } = useWishlists({ page, limit })

  const pageCount = Math.ceil(wishlists.data?.productTotal / limit)

  if (wishlists.isLoading) {
    return (
      <div className='flex justify-center my-6'>
        <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' />
      </div>
    )
  }

  return (
    <>
      <MobileView>
        <div className='px-4 py-6'>
          {wishlists.data?.products?.length == 0 && (
            <Alert type='info' className='text-center'>
              Wishlist anda masih kosong
            </Alert>
          )}

          <div className='grid grid-cols-2 gap-3'>
            {wishlists.data?.products.map((product) => (
              <ProductCard key={product.id} product={product} />
            ))}
          </div>

          <div className='mt-6'>
            <Pagination currentPage={page} pageCount={pageCount} url={`/my/wishlist`} />
          </div>
        </div>
      </MobileView>

      <DesktopView>
        <div className='container mx-auto flex py-10'>
          <div className='w-3/12 pr-4'>
            <Menu />
          </div>
          <div className='w-9/12'>
            <div className='grid grid-cols-5 gap-3'>
              {wishlists.data?.products.map((product) => (
                <ProductCard key={product.id} product={product} />
              ))}
            </div>

            <div className='mt-6'>
              <Pagination currentPage={page} pageCount={pageCount} url={`/my/wishlist`} />
            </div>
          </div>
        </div>
      </DesktopView>
    </>
  )
}

export default Wishlists