File tree 2 files changed +32
-8
lines changed
2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -37,4 +37,22 @@ const useSingleSwag = (id) =>
37
37
refetchOnWindowFocus : false ,
38
38
} ) ;
39
39
40
- export { useSingleSwag , useSwagList } ;
40
+ const fetchSwagCategories = async ( ) => {
41
+ try {
42
+ const response = await publicAxios . get ( "/product-categories" ) ;
43
+ return response . data ;
44
+ } catch ( error ) {
45
+ console . log ( error ) ;
46
+ toast . error ( "Error fetching swag list" ) ;
47
+ throw error ;
48
+ }
49
+ } ;
50
+
51
+ const useSwagCategory = ( ) =>
52
+ useQuery ( {
53
+ queryKey : [ "swagCategory" ] ,
54
+ queryFn : ( ) => fetchSwagCategories ( ) ,
55
+ refetchOnWindowFocus : false ,
56
+ } ) ;
57
+
58
+ export { useSingleSwag , useSwagList , useSwagCategory } ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { Link, useParams } from "react-router-dom";
3
3
import SearchInput from "../../../components/shop/SearchInput" ;
4
4
import SectionWrapper from "../../../components/shop/SectionWrapper" ;
5
5
import SortItems from "../../../components/shop/SortItems" ;
6
- import { categories } from "../data " ;
6
+ import { useSwagCategory } from "@/hooks/Queries/shop/useSwagList " ;
7
7
8
8
function FilterSection ( ) {
9
9
return (
@@ -27,22 +27,28 @@ function FilterSection() {
27
27
}
28
28
29
29
function Categories ( ) {
30
+ const { data, isSuccess } = useSwagCategory ( ) ;
30
31
return (
31
32
< div className = "flex gap-4 flex-wrap " >
32
- { categories . map ( ( item ) => (
33
- < CategoryItem key = { crypto . randomUUID ( ) } name = { item . name } />
34
- ) ) }
33
+ { isSuccess &&
34
+ data ?. map ( ( item ) => (
35
+ < CategoryItem
36
+ key = { crypto . randomUUID ( ) }
37
+ name = { item . name }
38
+ slug = { item . slug }
39
+ />
40
+ ) ) }
35
41
</ div >
36
42
) ;
37
43
}
38
44
39
- function CategoryItem ( { name } ) {
45
+ function CategoryItem ( { name, slug } ) {
40
46
const params = useParams ( ) ;
41
- const category = params . category === name ;
47
+ const category = params . category === slug ;
42
48
43
49
return (
44
50
< Link
45
- to = { `/shop/category/${ name } ` }
51
+ to = { `/shop/category/${ slug } ` }
46
52
className = { `rounded-3xl flex items-center border shadow-sm py-2 px-4 ${ category ? "bg-green-dark" : " hover:bg-gray-500/20 " } ` }
47
53
>
48
54
< p
You can’t perform that action at this time.
0 commit comments