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:
@@ -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,16 +132,20 @@ export function CreateAuditDialog({
|
|||||||
|
|
||||||
if (file && auditId) {
|
if (file && auditId) {
|
||||||
try {
|
try {
|
||||||
await promisifyMutation(uploadMutate)({
|
await new Promise<void>((resolve, reject) => {
|
||||||
variables: {
|
uploadMutate({
|
||||||
input: {
|
variables: {
|
||||||
auditId,
|
input: {
|
||||||
file: null,
|
auditId,
|
||||||
|
file: null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
uploadables: {
|
||||||
uploadables: {
|
"input.file": file,
|
||||||
"input.file": file,
|
},
|
||||||
},
|
onCompleted: () => resolve(),
|
||||||
|
onError: (error) => reject(error),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
toast({
|
toast({
|
||||||
title: __("Success"),
|
title: __("Success"),
|
||||||
|
|||||||
Reference in New Issue
Block a user