From a6d5e9b1f0f043e1f85137cf63093d6b421101a2 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Wed, 18 Mar 2026 17:17:14 +0100 Subject: [PATCH] Colocate upload mutation and remove promisifyMutation usage Move uploadAuditReportMutation into CreateAuditDialog and replace promisifyMutation with a Promise wrapper using native Relay callbacks. Signed-off-by: Bryan Frimin --- .../audits/dialogs/CreateAuditDialog.tsx | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/apps/console/src/pages/organizations/audits/dialogs/CreateAuditDialog.tsx b/apps/console/src/pages/organizations/audits/dialogs/CreateAuditDialog.tsx index f27211ba4..f70274f25 100644 --- a/apps/console/src/pages/organizations/audits/dialogs/CreateAuditDialog.tsx +++ b/apps/console/src/pages/organizations/audits/dialogs/CreateAuditDialog.tsx @@ -4,7 +4,6 @@ import { formatError, getAuditStateLabel, type GraphQLError, - promisifyMutation, } from "@probo/helpers"; import { useTranslate } from "@probo/i18n"; import { @@ -30,12 +29,28 @@ import { z } from "zod"; import type { CreateAuditDialogFrameworksQuery } from "#/__generated__/core/CreateAuditDialogFrameworksQuery.graphql"; import { ControlledField } from "#/components/form/ControlledField"; -import { - useCreateAudit, - uploadAuditReportMutation, -} from "#/hooks/graph/AuditGraph"; +import { useCreateAudit } from "#/hooks/graph/AuditGraph"; import { useFormWithSchema } from "#/hooks/useFormWithSchema"; +const uploadAuditReportMutation = graphql` + mutation CreateAuditDialogUploadReportMutation( + $input: UploadAuditReportInput! + ) { + uploadAuditReport(input: $input) { + audit { + id + report { + id + filename + downloadUrl + createdAt + } + updatedAt + } + } + } +`; + const frameworksQuery = graphql` query CreateAuditDialogFrameworksQuery($organizationId: ID!) { organization: node(id: $organizationId) { @@ -99,7 +114,6 @@ export function CreateAuditDialog({ const internalRef = useDialogRef(); const ref = externalRef ?? internalRef; const createAudit = useCreateAudit(connection); - // eslint-disable-next-line relay/generated-typescript-types const [uploadMutate] = useMutation(uploadAuditReportMutation); const onSubmit = async (data: z.infer) => { @@ -118,16 +132,20 @@ export function CreateAuditDialog({ if (file && auditId) { try { - await promisifyMutation(uploadMutate)({ - variables: { - input: { - auditId, - file: null, + await new Promise((resolve, reject) => { + uploadMutate({ + variables: { + input: { + auditId, + file: null, + }, }, - }, - uploadables: { - "input.file": file, - }, + uploadables: { + "input.file": file, + }, + onCompleted: () => resolve(), + onError: (error) => reject(error), + }); }); toast({ title: __("Success"),