diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-22 08:35:08 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-22 08:35:08 +0700 |
| commit | 50f5a2d8897020acc11f2a20469ffdd42ca7c31b (patch) | |
| tree | d47f95de1d9710ca8b4d173abd5edc2797704a87 /src/lib/wishlist | |
| parent | 82954ee3cfa38f21f677b9aa2c1c6c3c88004050 (diff) | |
| parent | 036e72780ddb7a510795b329919ff9dd957af6d7 (diff) | |
Merge branch 'refactor' of bitbucket.org:altafixco/next-indoteknik into refactor
Diffstat (limited to 'src/lib/wishlist')
| -rw-r--r-- | src/lib/wishlist/api/wishlistsApi.js | 10 | ||||
| -rw-r--r-- | src/lib/wishlist/components/Wishlists.jsx | 47 | ||||
| -rw-r--r-- | src/lib/wishlist/hooks/useWishlists.js | 14 |
3 files changed, 71 insertions, 0 deletions
diff --git a/src/lib/wishlist/api/wishlistsApi.js b/src/lib/wishlist/api/wishlistsApi.js new file mode 100644 index 00000000..49ef56ee --- /dev/null +++ b/src/lib/wishlist/api/wishlistsApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const wishlistsApi = async ({ limit, offset }) => { + const auth = getAuth() + const dataWishlists = await odooApi('GET', `/api/v1/user/${auth.id}/wishlist?limit=${limit}&offset=${offset}`) + return dataWishlists +} + +export default wishlistsApi
\ No newline at end of file diff --git a/src/lib/wishlist/components/Wishlists.jsx b/src/lib/wishlist/components/Wishlists.jsx new file mode 100644 index 00000000..4bb63933 --- /dev/null +++ b/src/lib/wishlist/components/Wishlists.jsx @@ -0,0 +1,47 @@ +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" + +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 ( + <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} data={product} /> + ))} + </div> + + <div className="mt-6"> + <Pagination currentPage={page} pageCount={pageCount} url={`/my/wishlist`} /> + </div> + </div> + ) +} + +export default Wishlists
\ No newline at end of file diff --git a/src/lib/wishlist/hooks/useWishlists.js b/src/lib/wishlist/hooks/useWishlists.js new file mode 100644 index 00000000..a219ab69 --- /dev/null +++ b/src/lib/wishlist/hooks/useWishlists.js @@ -0,0 +1,14 @@ +import { useQuery } from "react-query" +import wishlistsApi from "../api/wishlistsApi" + +const useWishlists = ({ page, limit }) => { + const offset = (page - 1) * limit + const fetchWishlists = async () => await wishlistsApi({ limit, offset }) + const { data, isLoading } = useQuery(`wishlists-${limit}-${offset}`, fetchWishlists) + + return { + wishlists: { data, isLoading } + } +} + +export default useWishlists
\ No newline at end of file |
