-
Notifications
You must be signed in to change notification settings - Fork 30
Feat: implementation logic for single claim model #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xdevcollins
merged 3 commits into
boundlessfi:main
from
Bosun-Josh121:feat/logic-implemention-for-single-claim-model
Feb 23, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,98 +1,111 @@ | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import { | ||
| bountiesApi, | ||
| type Bounty, | ||
| type CreateBountyInput, | ||
| type UpdateBountyInput, | ||
| type PaginatedResponse, | ||
| } from '@/lib/api'; | ||
| import { bountyKeys } from './use-bounties'; | ||
| bountiesApi, | ||
| type Bounty, | ||
| type CreateBountyInput, | ||
| type UpdateBountyInput, | ||
| type PaginatedResponse, | ||
| } from "@/lib/api"; | ||
| import { bountyKeys } from "./use-bounties"; | ||
|
|
||
| export function useCreateBounty() { | ||
| const queryClient = useQueryClient(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: (data: CreateBountyInput) => bountiesApi.create(data), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| return useMutation({ | ||
| mutationFn: (data: CreateBountyInput) => bountiesApi.create(data), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export function useUpdateBounty() { | ||
| const queryClient = useQueryClient(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: ({ id, data }: { id: string; data: UpdateBountyInput }) => | ||
| bountiesApi.update(id, data), | ||
| onMutate: async ({ id, data }) => { | ||
| await queryClient.cancelQueries({ queryKey: bountyKeys.detail(id) }); | ||
| const previous = queryClient.getQueryData<Bounty>(bountyKeys.detail(id)); | ||
| return useMutation({ | ||
| mutationFn: ({ id, data }: { id: string; data: UpdateBountyInput }) => | ||
| bountiesApi.update(id, data), | ||
| onMutate: async ({ id, data }) => { | ||
| await queryClient.cancelQueries({ queryKey: bountyKeys.detail(id) }); | ||
| const previous = queryClient.getQueryData<Bounty>(bountyKeys.detail(id)); | ||
|
|
||
| if (previous) { | ||
| queryClient.setQueryData<Bounty>(bountyKeys.detail(id), { | ||
| ...previous, | ||
| ...data, | ||
| updatedAt: new Date().toISOString(), | ||
| }); | ||
| } | ||
| if (previous) { | ||
| queryClient.setQueryData<Bounty>(bountyKeys.detail(id), { | ||
| ...previous, | ||
| ...data, | ||
| updatedAt: new Date().toISOString(), | ||
| }); | ||
| } | ||
|
|
||
| return { previous, id }; | ||
| }, | ||
| onError: (_err, _vars, context) => { | ||
| if (context?.previous) { | ||
| queryClient.setQueryData(bountyKeys.detail(context.id), context.previous); | ||
| } | ||
| }, | ||
| onSettled: (_data, _err, { id }) => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.detail(id) }); | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| return { previous, id }; | ||
| }, | ||
| onError: (_err, _vars, context) => { | ||
| if (context?.previous) { | ||
| queryClient.setQueryData( | ||
| bountyKeys.detail(context.id), | ||
| context.previous, | ||
| ); | ||
| } | ||
| }, | ||
| onSettled: (_data, _err, { id }) => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.detail(id) }); | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export function useDeleteBounty() { | ||
| const queryClient = useQueryClient(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: (id: string) => bountiesApi.delete(id), | ||
| onMutate: async (id) => { | ||
| await queryClient.cancelQueries({ queryKey: bountyKeys.lists() }); | ||
| return useMutation({ | ||
| mutationFn: (id: string) => bountiesApi.delete(id), | ||
| onMutate: async (id) => { | ||
| await queryClient.cancelQueries({ queryKey: bountyKeys.lists() }); | ||
|
|
||
| const previousLists = queryClient.getQueriesData<PaginatedResponse<Bounty>>({ | ||
| queryKey: bountyKeys.lists(), | ||
| }); | ||
| const previousLists = queryClient.getQueriesData< | ||
| PaginatedResponse<Bounty> | ||
| >({ | ||
| queryKey: bountyKeys.lists(), | ||
| }); | ||
|
|
||
| queryClient.setQueriesData<PaginatedResponse<Bounty>>( | ||
| { queryKey: bountyKeys.lists() }, | ||
| (old) => old ? { | ||
| ...old, | ||
| data: old.data.filter((b) => b.id !== id), | ||
| pagination: { ...old.pagination, total: old.pagination.total - 1 }, | ||
| } : old | ||
| ); | ||
| queryClient.setQueriesData<PaginatedResponse<Bounty>>( | ||
| { queryKey: bountyKeys.lists() }, | ||
| (old) => | ||
| old | ||
| ? { | ||
| ...old, | ||
| data: old.data.filter((b) => b.id !== id), | ||
| pagination: { | ||
| ...old.pagination, | ||
| total: old.pagination.total - 1, | ||
| }, | ||
| } | ||
| : old, | ||
| ); | ||
|
|
||
| return { previousLists }; | ||
| }, | ||
| onError: (_err, _id, context) => { | ||
| context?.previousLists.forEach(([key, data]) => { | ||
| queryClient.setQueryData(key, data); | ||
| }); | ||
| }, | ||
| onSettled: () => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| return { previousLists }; | ||
| }, | ||
| onError: (_err, _id, context) => { | ||
| context?.previousLists.forEach(([key, data]) => { | ||
| queryClient.setQueryData(key, data); | ||
| }); | ||
| }, | ||
| onSettled: () => { | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export function useClaimBounty() { | ||
| const queryClient = useQueryClient(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: (id: string) => bountiesApi.claim(id), | ||
| onSuccess: (data, id) => { | ||
| queryClient.setQueryData(bountyKeys.detail(id), data); | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| return useMutation({ | ||
| mutationFn: (id: string) => bountiesApi.claim(id), | ||
| onSuccess: (data, id) => { | ||
| queryClient.setQueryData<Bounty>(bountyKeys.detail(id), data); | ||
|
|
||
| // Invalidate the list view so the main bounties board updates | ||
| queryClient.invalidateQueries({ queryKey: bountyKeys.lists() }); | ||
| }, | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.