@@ -13,7 +13,7 @@ import {
1313 ModalOverlay ,
1414} from "@chakra-ui/react"
1515import { type SubmitHandler , useForm } from "react-hook-form"
16- import { useMutation , useQueryClient } from "react-query"
16+ import { useMutation , useQueryClient } from "@tanstack/ react-query"
1717
1818import { type ApiError , type ItemCreate , ItemsService } from "../../client"
1919import useCustomToast from "../../hooks/useCustomToast"
@@ -40,23 +40,22 @@ const AddItem = ({ isOpen, onClose }: AddItemProps) => {
4040 } ,
4141 } )
4242
43- const mutation = useMutation (
44- ( data : ItemCreate ) => ItemsService . createItem ( { requestBody : data } ) ,
45- {
46- onSuccess : ( ) => {
47- showToast ( "Success!" , "Item created successfully." , "success" )
48- reset ( )
49- onClose ( )
50- } ,
51- onError : ( err : ApiError ) => {
52- const errDetail = ( err . body as any ) ?. detail
53- showToast ( "Something went wrong." , `${ errDetail } ` , "error" )
54- } ,
55- onSettled : ( ) => {
56- queryClient . invalidateQueries ( "items" )
57- } ,
43+ const mutation = useMutation ( {
44+ mutationFn : ( data : ItemCreate ) =>
45+ ItemsService . createItem ( { requestBody : data } ) ,
46+ onSuccess : ( ) => {
47+ showToast ( "Success!" , "Item created successfully." , "success" )
48+ reset ( )
49+ onClose ( )
5850 } ,
59- )
51+ onError : ( err : ApiError ) => {
52+ const errDetail = ( err . body as any ) ?. detail
53+ showToast ( "Something went wrong." , `${ errDetail } ` , "error" )
54+ } ,
55+ onSettled : ( ) => {
56+ queryClient . invalidateQueries ( { queryKey : [ "items" ] } )
57+ } ,
58+ } )
6059
6160 const onSubmit : SubmitHandler < ItemCreate > = ( data ) => {
6261 mutation . mutate ( data )
0 commit comments