1
1
import { fetchService } from "@/services" ;
2
2
import { ApiResponse , CATEGORIES_API_ENDPOINT , Category } from "@/types" ;
3
3
import { useSnackbar } from "notistack" ;
4
- import { useMutation , useQueryClient } from "react-query" ;
4
+ import { useMutation , useQueryClient } from "@tanstack/ react-query" ;
5
5
6
6
interface UseUpdateCategoryProps {
7
7
hideSuccessMessage ?: boolean ;
@@ -13,8 +13,8 @@ export const useUpdateCategory = ({
13
13
const { enqueueSnackbar } = useSnackbar ( ) ;
14
14
const queryClient = useQueryClient ( ) ;
15
15
16
- const { mutateAsync : updateCategory , isLoading } = useMutation (
17
- async ( category : Category ) => {
16
+ const { mutateAsync : updateCategory , isPending } = useMutation ( {
17
+ mutationFn : async ( category : Category ) => {
18
18
const response : ApiResponse < Category > = await fetchService (
19
19
`${ CATEGORIES_API_ENDPOINT } /${ category . id } ` ,
20
20
{
@@ -30,23 +30,23 @@ export const useUpdateCategory = ({
30
30
throw new Error ( response . error ) ;
31
31
}
32
32
33
- await queryClient . invalidateQueries ( CATEGORIES_API_ENDPOINT ) ;
33
+ await queryClient . invalidateQueries ( {
34
+ queryKey : [ CATEGORIES_API_ENDPOINT ] ,
35
+ } ) ;
34
36
35
37
return response . data ;
36
38
} ,
37
- {
38
- onSuccess : ( ) => {
39
- if ( ! hideSuccessMessage ) {
40
- enqueueSnackbar ( "Category updated successfully" , {
41
- variant : "success" ,
42
- } ) ;
43
- }
44
- } ,
45
- onError : ( error : Error ) => {
46
- enqueueSnackbar ( error . message , { variant : "error" } ) ;
47
- } ,
48
- }
49
- ) ;
39
+ onSuccess : ( ) => {
40
+ if ( ! hideSuccessMessage ) {
41
+ enqueueSnackbar ( "Category updated successfully" , {
42
+ variant : "success" ,
43
+ } ) ;
44
+ }
45
+ } ,
46
+ onError : ( error : Error ) => {
47
+ enqueueSnackbar ( error . message , { variant : "error" } ) ;
48
+ } ,
49
+ } ) ;
50
50
51
- return { updateCategory, isLoading } ;
51
+ return { updateCategory, isPending } ;
52
52
} ;
0 commit comments