@@ -7,8 +7,8 @@ const useAddSwagToCart = () => {
7
7
const { auth, logout } = useAuth ( ) ;
8
8
const queryClient = useQueryClient ( ) ;
9
9
10
- return useMutation (
11
- async ( cartItems ) => {
10
+ return useMutation ( {
11
+ mutationFn : async ( cartItems ) => {
12
12
const response = await publicAxios . post ( "/cart/swaggs/" , cartItems , {
13
13
headers : {
14
14
"Content-Type" : "application/json" ,
@@ -17,28 +17,26 @@ const useAddSwagToCart = () => {
17
17
} ) ;
18
18
return response . data ;
19
19
} ,
20
- {
21
- onSuccess : ( data ) => {
22
- console . log ( "Added to cart: " , data ) ;
23
- queryClient . invalidateQueries ( [ "productsInCart" ] ) ;
24
- } ,
25
- onError : ( error ) => {
26
- // eslint-disable-next-line no-console
27
- console . error ( "Unable to add availability" ) ;
28
- if ( error . response . status === 401 ) {
29
- logout ( ) ;
30
- }
31
- } ,
32
- }
33
- ) ;
20
+ onSuccess : ( data ) => {
21
+ console . log ( "Added to cart: " , data ) ;
22
+ queryClient . invalidateQueries ( { queryKey : [ "productsInCart" ] } ) ;
23
+ } ,
24
+ onError : ( error ) => {
25
+ // eslint-disable-next-line no-console
26
+ console . error ( "Unable to add availability" ) ;
27
+ if ( error . response . status === 401 ) {
28
+ logout ( ) ;
29
+ }
30
+ } ,
31
+ } ) ;
34
32
} ;
35
33
36
34
const useDeleteSwag = ( ) => {
37
35
const { auth, logout } = useAuth ( ) ;
38
36
const queryClient = useQueryClient ( ) ;
39
37
40
- return useMutation (
41
- async ( id ) => {
38
+ return useMutation ( {
39
+ mutationFn : async ( id ) => {
42
40
const response = await publicAxios . delete ( `/cart/swaggs/${ id } /` , {
43
41
headers : {
44
42
"Content-Type" : "application/json" ,
@@ -48,20 +46,18 @@ const useDeleteSwag = () => {
48
46
console . log ( "response " , response . data ) ;
49
47
return response . data ;
50
48
} ,
51
- {
52
- onSuccess : ( data ) => {
53
- console . log ( "Successfully deleted " , data ) ;
54
- queryClient . invalidateQueries ( [ "productsInCart" ] ) ;
55
- } ,
56
- onError : ( error ) => {
57
- // eslint-disable-next-line no-console
58
- console . error ( "Unable to delete swag" ) ;
59
- if ( error . response . status === 401 ) {
60
- logout ( ) ;
61
- }
62
- } ,
63
- }
64
- ) ;
49
+ onSuccess : ( data ) => {
50
+ console . log ( "Successfully deleted " , data ) ;
51
+ queryClient . invalidateQueries ( { queryKey : [ "productsInCart" ] } ) ;
52
+ } ,
53
+ onError : ( error ) => {
54
+ // eslint-disable-next-line no-console
55
+ console . error ( "Unable to delete swag" ) ;
56
+ if ( error . response . status === 401 ) {
57
+ logout ( ) ;
58
+ }
59
+ } ,
60
+ } ) ;
65
61
} ;
66
62
67
63
export { useAddSwagToCart , useDeleteSwag } ;
0 commit comments