-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
building out cart modal • clean up • changes to cart service
- Loading branch information
1 parent
c1f9bf4
commit 60f0479
Showing
14 changed files
with
196 additions
and
68 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
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
3 changes: 0 additions & 3 deletions
3
libs/features/src/lib/cart/cart.modal/cart.modal.interface.ts
This file was deleted.
Oops, something went wrong.
34 changes: 27 additions & 7 deletions
34
libs/features/src/lib/cart/cart.modal/cart.modal.module.css
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
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
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
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
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,21 +1,42 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { clearCart, deleteCartItem, updateCart } from './api.cart.service'; | ||
|
||
export function useUpdateCart() { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (data: any) => updateCart(data), | ||
onSettled: async (_, error) => { | ||
if (!error) { | ||
await queryClient.invalidateQueries({ queryKey: ['cart'] }); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export function useDeleteCartItem() { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (id: number) => deleteCartItem(id), | ||
onSettled: async (_, error) => { | ||
if (!error) { | ||
await queryClient.invalidateQueries({ queryKey: ['cart'] }); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export function useClearCart() { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: () => clearCart(), | ||
onSettled: async (_, error) => { | ||
if (!error) { | ||
await queryClient.invalidateQueries({ queryKey: ['cart'] }); | ||
} | ||
}, | ||
}); | ||
} |
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
Oops, something went wrong.