-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export { | ||
useGetProductsQuery, | ||
useGetProductByIdQuery, | ||
useAddProductMutation, | ||
useUpdateProductMutation, | ||
} from './useProduct'; | ||
export { useGetProductsQuery } from './useGetProductsQuery'; | ||
export { useGetProductByIdQuery } from './useGetProductByIdQuery'; | ||
export { useAddProductMutation } from './useAddProductMutation'; | ||
export { useUpdateProductMutation } from './useUpdateProductMutation'; |
16 changes: 16 additions & 0 deletions
16
src/advanced/features/product/model/useAddProductMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { addProduct, UpdateProduct } from '@advanced/entities/product'; | ||
|
||
export const useAddProductMutation = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationKey: ['/api/products'], | ||
mutationFn: (product: UpdateProduct) => addProduct(product), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ['/api/products'], | ||
exact: false, | ||
}); | ||
}, | ||
}); | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/advanced/features/product/model/useGetProductByIdQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { getProductById } from '@advanced/entities/product'; | ||
|
||
export const useGetProductByIdQuery = (productId: string) => { | ||
return useSuspenseQuery({ | ||
queryKey: ['/api/products', productId], | ||
queryFn: () => getProductById(productId), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { getProducts } from '@advanced/entities/product'; | ||
|
||
export const useGetProductsQuery = () => { | ||
return useSuspenseQuery({ | ||
queryKey: ['/api/products'], | ||
queryFn: () => getProducts(), | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/advanced/features/product/model/useUpdateProductMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { updateProduct, UpdateProduct } from '@advanced/entities/product'; | ||
|
||
export const useUpdateProductMutation = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationKey: ['/api/products'], | ||
mutationFn: ({ | ||
productId, | ||
product, | ||
}: { | ||
productId: string; | ||
product: Partial<UpdateProduct>; | ||
}) => updateProduct(productId, product), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ['/api/products'], | ||
exact: false, | ||
}); | ||
}, | ||
}); | ||
}; |