summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-detail/components/Breadcrumb.tsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-01-16 16:08:43 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-01-16 16:08:43 +0700
commita70fd5b6d9c7a769ac1aaa22a7d037ba3be27a05 (patch)
tree825d6b5de089bb22003bb2a517d371dc291f1962 /src-migrate/modules/product-detail/components/Breadcrumb.tsx
parentd9dafa74857959974e9d379dc1a3abfbaf2af83d (diff)
Update improve product detail performance
Diffstat (limited to 'src-migrate/modules/product-detail/components/Breadcrumb.tsx')
-rw-r--r--src-migrate/modules/product-detail/components/Breadcrumb.tsx40
1 files changed, 40 insertions, 0 deletions
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..0ee5b115
--- /dev/null
+++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx
@@ -0,0 +1,40 @@
+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)
+ })
+
+ const breadcrumbs = query.data || []
+
+ return (
+ <div className='line-clamp-3 md:line-clamp-1 leading-7'>
+ <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