Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement remote project deletion client side
- Loading branch information
1 parent
3b0b391
commit 7fabe38
Showing
2 changed files
with
35 additions
and
1 deletion.
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
29 changes: 29 additions & 0 deletions
29
src/components/projects/ProjectList/useDeleteRemoteProject.js
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,29 @@ | ||
// @flow | ||
|
||
import gql from 'graphql-tag'; | ||
|
||
import * as hooks from '../../misc/hooks'; | ||
|
||
import { type DeleteProject, type DeleteProjectVariables } from './__generated__/DeleteProject'; | ||
|
||
const useDeleteProjectMutation = hooks.makeMutation<DeleteProject, DeleteProjectVariables>(gql` | ||
mutation DeleteProject($projectId: ID!) { | ||
deleteProjectById(projectId: $projectId) | ||
} | ||
`); | ||
|
||
export default function useCreateRemoteProject(): string => Promise<string | null> { | ||
const [performDeleteProject, _deleteProjectResponse] = useDeleteProjectMutation(); | ||
|
||
async function deleteProject(projectId: string) { | ||
const result = await performDeleteProject({ variables: { projectId } }); | ||
|
||
// we're not passing `ignoreResults`, so there will be a result | ||
// eslint-disable-next-line no-throw-literal | ||
if (!result.data) throw 'unreachable'; | ||
|
||
return result.data.deleteProjectById ?? null; | ||
} | ||
|
||
return deleteProject; | ||
} |