-
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.
feat: introduce some write hooks for client, invites, and projects (#21)
- Loading branch information
Showing
9 changed files
with
701 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
|
||
import { | ||
acceptInviteMutationOptions, | ||
rejectInviteMutationOptions, | ||
requestCancelInviteMutationOptions, | ||
sendInviteMutationOptions, | ||
} from '../lib/react-query/invites.js' | ||
import { useClientApi } from './client.js' | ||
import { useSingleProject } from './projects.js' | ||
|
||
/** | ||
* Accept an invite that has been received. | ||
*/ | ||
export function useAcceptInvite() { | ||
const queryClient = useQueryClient() | ||
const clientApi = useClientApi() | ||
|
||
const { mutate, status, reset } = useMutation( | ||
acceptInviteMutationOptions({ clientApi, queryClient }), | ||
) | ||
|
||
return { mutate, reset, status } | ||
} | ||
|
||
/** | ||
* Reject an invite that has been received. | ||
*/ | ||
export function useRejectInvite() { | ||
const queryClient = useQueryClient() | ||
const clientApi = useClientApi() | ||
|
||
const { mutate, status, reset } = useMutation( | ||
rejectInviteMutationOptions({ clientApi, queryClient }), | ||
) | ||
|
||
return { mutate, reset, status } | ||
} | ||
|
||
/** | ||
* Send an invite for a project. | ||
* | ||
* @param opts.projectId Public ID of project to send the invite on behalf of. | ||
*/ | ||
export function useSendInvite({ projectId }: { projectId: string }) { | ||
const queryClient = useQueryClient() | ||
const { data: projectApi } = useSingleProject({ projectId }) | ||
|
||
const { mutate, status, reset } = useMutation( | ||
sendInviteMutationOptions({ projectApi, projectId, queryClient }), | ||
) | ||
|
||
return { mutate, reset, status } | ||
} | ||
|
||
/** | ||
* Request a cancellation of an invite sent to another device. | ||
* | ||
* @param opts.projectId Public ID of project to request the invite cancellation for. | ||
*/ | ||
export function useRequestCancelInvite({ projectId }: { projectId: string }) { | ||
const queryClient = useQueryClient() | ||
const { data: projectApi } = useSingleProject({ projectId }) | ||
|
||
const { mutate, status, reset } = useMutation( | ||
requestCancelInviteMutationOptions({ projectApi, queryClient }), | ||
) | ||
|
||
return { mutate, reset, status } | ||
} |
Oops, something went wrong.