diff --git a/frontend/src/lib/gql/mutations.ts b/frontend/src/lib/gql/mutations.ts index 73997f8d0..97499bd42 100644 --- a/frontend/src/lib/gql/mutations.ts +++ b/frontend/src/lib/gql/mutations.ts @@ -1,4 +1,4 @@ -import type { $OpResult, DeleteUserByAdminOrSelfInput, DeleteUserByAdminOrSelfMutation, SoftDeleteProjectMutation } from './types'; +import type { $OpResult, DeleteUserByAdminOrSelfInput, DeleteUserByAdminOrSelfMutation, SoftDeleteProjectMutation, DeleteDraftProjectMutation } from './types'; import { getClient } from './gql-client'; import { graphql } from './generated'; @@ -55,3 +55,30 @@ export async function _deleteProject(projectId: string): $OpResult { + //language=GraphQL + const result = await getClient() + .mutation( + graphql(` + mutation DeleteDraftProject($input: DeleteDraftProjectInput!) { + deleteDraftProject(input: $input) { + draftProject { + id, + } + errors { + ... on Error { + message + } + } + } + } + `), + { + input: { draftProjectId } + }, + { additionalTypenames: ['Projects'] }, + ); + + return result; +} diff --git a/frontend/src/routes/(authenticated)/admin/AdminProjects.svelte b/frontend/src/routes/(authenticated)/admin/AdminProjects.svelte index 8a99bc991..8efdfac92 100644 --- a/frontend/src/routes/(authenticated)/admin/AdminProjects.svelte +++ b/frontend/src/routes/(authenticated)/admin/AdminProjects.svelte @@ -15,7 +15,7 @@ import {DialogResponse} from '$lib/components/modals'; import ConfirmDeleteModal from '$lib/components/modals/ConfirmDeleteModal.svelte'; import {Button} from '$lib/forms'; - import {_deleteProject} from '$lib/gql/mutations'; + import {_deleteProject, _deleteDraftProject} from '$lib/gql/mutations'; import t, {number} from '$lib/i18n'; import {TrashIcon} from '$lib/icons'; import {useNotifications} from '$lib/notify'; @@ -59,7 +59,7 @@ $: shownProjects = limitResults ? limit(filteredProjects, lastLoadUsedActiveFilter ? DEFAULT_PAGE_SIZE : 10) : filteredProjects; let deleteProjectModal: ConfirmDeleteModal; - async function softDeleteProject(project: ProjectItemWithDraftStatus): Promise { + async function softDeleteProject(project: ProjectItem): Promise { const result = await deleteProjectModal.open(project.name, async () => { const { error } = await _deleteProject(project.id); return error?.message; @@ -68,6 +68,22 @@ notifyWarning($t('delete_project_modal.success', { name: project.name, code: project.code })); } } + async function deleteDraftProject(project: DraftProject): Promise { + const result = await deleteProjectModal.open(project.name, async () => { + const { error } = await _deleteDraftProject(project.id); + return error?.message; + }); + if (result.response === DialogResponse.Submit) { + notifyWarning($t('delete_project_modal.success', { name: project.name, code: project.code })); + } + } + function deleteProjectOrDraft(project: ProjectItemWithDraftStatus): Promise { + if (project.isDraft) { + return deleteDraftProject(project) + } else { + return softDeleteProject(project); + } + } @@ -117,7 +133,7 @@