-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to invalidateQueries through meta in mutation cache
- Loading branch information
Showing
9 changed files
with
38 additions
and
49 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
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,27 +1,22 @@ | ||
import type { UpdateOrderData } from 'features/kanban/shared/types' | ||
|
||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { toast } from 'sonner' | ||
|
||
import { BoardCacheKeys } from 'features/kanban/board/config' | ||
|
||
import { cardService } from '../card.service' | ||
import { CardCacheKeys } from '../config' | ||
|
||
export const useUpdateCardsOrder = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
export const useUpdateCardsOrder = () => | ||
useMutation({ | ||
mutationKey: [CardCacheKeys.UpdateCardsOrder], | ||
mutationFn: ({ columnId, ids }: UpdateOrderData & { columnId: string }) => | ||
cardService.updateCardsOrder(columnId, { ids }), | ||
onSuccess() { | ||
queryClient.invalidateQueries({ queryKey: [BoardCacheKeys.Board] }) | ||
}, | ||
meta: { invalidates: [[BoardCacheKeys.Board]] }, | ||
onError() { | ||
toast.error( | ||
'Unexpected error during cards reordering. We apologize for the inconvenience. Please try again later.' | ||
) | ||
} | ||
}) | ||
} |
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,30 +1,21 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { useMutation } from '@tanstack/react-query' | ||
|
||
import { BoardCacheKeys } from 'features/kanban/board/config' | ||
import { useGetParamBoardId } from 'features/kanban/board/hooks' | ||
import { useDragAndDrop } from 'features/kanban/dnd/hooks' | ||
|
||
import { columnService } from '../column.service' | ||
import { ColumnCacheKeys } from '../config' | ||
|
||
export const useDeleteColumn = () => { | ||
const queryClient = useQueryClient() | ||
|
||
const { setColumns, setCards } = useDragAndDrop() | ||
|
||
const { boardId } = useGetParamBoardId() | ||
|
||
return useMutation({ | ||
mutationKey: [ColumnCacheKeys.DeleteColumn], | ||
mutationFn: (columnId: string) => columnService.deleteColumn(columnId), | ||
meta: { invalidates: [[BoardCacheKeys.Board]] }, | ||
onMutate: async columnId => { | ||
setColumns(prevColumns => prevColumns?.filter(c => c.id !== columnId)) | ||
setCards(prevCards => prevCards?.filter(c => c.columnId !== columnId)) | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [BoardCacheKeys.Board, boardId] | ||
}) | ||
} | ||
}) | ||
} |
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