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 <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-18 17:17:14 +01:00
parent b4a6618736
commit a6d5e9b1f0

View File

@@ -4,7 +4,6 @@ import {
formatError, formatError,
getAuditStateLabel, getAuditStateLabel,
type GraphQLError, type GraphQLError,
promisifyMutation,
} from "@probo/helpers"; } from "@probo/helpers";
import { useTranslate } from "@probo/i18n"; import { useTranslate } from "@probo/i18n";
import { import {
@@ -30,12 +29,28 @@ import { z } from "zod";
import type { CreateAuditDialogFrameworksQuery } from "#/__generated__/core/CreateAuditDialogFrameworksQuery.graphql"; import type { CreateAuditDialogFrameworksQuery } from "#/__generated__/core/CreateAuditDialogFrameworksQuery.graphql";
import { ControlledField } from "#/components/form/ControlledField"; import { ControlledField } from "#/components/form/ControlledField";
import { import { useCreateAudit } from "#/hooks/graph/AuditGraph";
useCreateAudit,
uploadAuditReportMutation,
} from "#/hooks/graph/AuditGraph";
import { useFormWithSchema } from "#/hooks/useFormWithSchema"; 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` const frameworksQuery = graphql`
query CreateAuditDialogFrameworksQuery($organizationId: ID!) { query CreateAuditDialogFrameworksQuery($organizationId: ID!) {
organization: node(id: $organizationId) { organization: node(id: $organizationId) {
@@ -99,7 +114,6 @@ export function CreateAuditDialog({
const internalRef = useDialogRef(); const internalRef = useDialogRef();
const ref = externalRef ?? internalRef; const ref = externalRef ?? internalRef;
const createAudit = useCreateAudit(connection); const createAudit = useCreateAudit(connection);
// eslint-disable-next-line relay/generated-typescript-types
const [uploadMutate] = useMutation(uploadAuditReportMutation); const [uploadMutate] = useMutation(uploadAuditReportMutation);
const onSubmit = async (data: z.infer<typeof schema>) => { const onSubmit = async (data: z.infer<typeof schema>) => {
@@ -118,7 +132,8 @@ export function CreateAuditDialog({
if (file && auditId) { if (file && auditId) {
try { try {
await promisifyMutation(uploadMutate)({ await new Promise<void>((resolve, reject) => {
uploadMutate({
variables: { variables: {
input: { input: {
auditId, auditId,
@@ -128,6 +143,9 @@ export function CreateAuditDialog({
uploadables: { uploadables: {
"input.file": file, "input.file": file,
}, },
onCompleted: () => resolve(),
onError: (error) => reject(error),
});
}); });
toast({ toast({
title: __("Success"), title: __("Success"),