Fix navigations after document mutations
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { sprintf } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { ActionDropdown, DropdownItem, IconArrowDown, IconPencil, IconTrashCan, useConfirm } from "@probo/ui";
|
||||
import { use, useRef } from "react";
|
||||
import { loadQuery, useFragment } from "react-relay";
|
||||
import { useFragment } from "react-relay";
|
||||
import { useNavigate } from "react-router";
|
||||
import { graphql } from "relay-runtime";
|
||||
|
||||
@@ -10,14 +10,11 @@ import type { DocumentActionsDropdown_documentFragment$key } from "#/__generated
|
||||
import type { DocumentActionsDropdown_versionFragment$key } from "#/__generated__/core/DocumentActionsDropdown_versionFragment.graphql";
|
||||
import type { DocumentActionsDropdownn_exportVersionMutation } from "#/__generated__/core/DocumentActionsDropdownn_exportVersionMutation.graphql";
|
||||
import { PdfDownloadDialog, type PdfDownloadDialogRef } from "#/components/documents/PdfDownloadDialog";
|
||||
import { coreEnvironment } from "#/environments";
|
||||
import { useDeleteDocumentMutation, useDeleteDraftDocumentVersionMutation } from "#/hooks/graph/DocumentGraph";
|
||||
import { useMutationWithToasts } from "#/hooks/useMutationWithToasts";
|
||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||
import { CurrentUser } from "#/providers/CurrentUser";
|
||||
|
||||
import { documentLayoutQuery } from "../DocumentLayout";
|
||||
|
||||
import UpdateVersionDialog from "./UpdateVersionDialog";
|
||||
|
||||
const documentFragment = graphql`
|
||||
@@ -87,17 +84,13 @@ export function DocumentActionsDropdownn(props: {
|
||||
const handleDelete = () => {
|
||||
confirm(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
void deleteDocument({
|
||||
variables: {
|
||||
input: { documentId: document.id },
|
||||
},
|
||||
onSuccess() {
|
||||
void navigate(`/organizations/${organizationId}/documents`);
|
||||
resolve();
|
||||
},
|
||||
onError: () => resolve(),
|
||||
});
|
||||
deleteDocument({
|
||||
variables: {
|
||||
input: { documentId: document.id },
|
||||
},
|
||||
onSuccess() {
|
||||
void navigate(`/organizations/${organizationId}/documents`);
|
||||
},
|
||||
}),
|
||||
{
|
||||
message: sprintf(
|
||||
@@ -113,24 +106,14 @@ export function DocumentActionsDropdownn(props: {
|
||||
const handleDeleteDraft = () => {
|
||||
confirm(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
void deleteDraftDocumentVersion({
|
||||
variables: {
|
||||
input: { documentVersionId: version.id },
|
||||
connections: [document.versions.__id],
|
||||
},
|
||||
onSuccess() {
|
||||
loadQuery(
|
||||
coreEnvironment,
|
||||
documentLayoutQuery,
|
||||
{ documentId: document.id },
|
||||
{ fetchPolicy: "network-only" },
|
||||
);
|
||||
|
||||
resolve();
|
||||
},
|
||||
onError: () => resolve(),
|
||||
});
|
||||
deleteDraftDocumentVersion({
|
||||
variables: {
|
||||
input: { documentVersionId: version.id },
|
||||
connections: [document.versions.__id],
|
||||
},
|
||||
onSuccess() {
|
||||
window.location.href = `/organizations/${organizationId}/documents/${document.id}`;
|
||||
},
|
||||
}),
|
||||
{
|
||||
message: sprintf(
|
||||
|
||||
@@ -2,7 +2,7 @@ import { documentClassifications, documentTypes, formatDate, getDocumentClassifi
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Avatar, Badge, Button, Drawer, IconCheckmark1, IconCrossLargeX, IconPencil, PropertyRow } from "@probo/ui";
|
||||
import { useState } from "react";
|
||||
import { loadQuery, useFragment } from "react-relay";
|
||||
import { useFragment } from "react-relay";
|
||||
import { graphql } from "relay-runtime";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -13,13 +13,10 @@ import { ControlledField } from "#/components/form/ControlledField";
|
||||
import { DocumentClassificationOptions } from "#/components/form/DocumentClassificationOptions";
|
||||
import { DocumentTypeOptions } from "#/components/form/DocumentTypeOptions";
|
||||
import { PeopleSelectField } from "#/components/form/PeopleSelectField";
|
||||
import { coreEnvironment } from "#/environments";
|
||||
import { useFormWithSchema } from "#/hooks/useFormWithSchema";
|
||||
import { useMutationWithToasts } from "#/hooks/useMutationWithToasts";
|
||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||
|
||||
import { documentLayoutQuery } from "../DocumentLayout";
|
||||
|
||||
const documentFragment = graphql`
|
||||
fragment DocumentLayoutDrawer_documentFragment on Document {
|
||||
id
|
||||
@@ -129,12 +126,6 @@ export function DocumentLayoutDrawer(props: {
|
||||
},
|
||||
onSuccess: () => {
|
||||
setIsEditingType(false);
|
||||
loadQuery(
|
||||
coreEnvironment,
|
||||
documentLayoutQuery,
|
||||
{ documentId: document.id },
|
||||
{ fetchPolicy: "network-only" },
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -151,12 +142,6 @@ export function DocumentLayoutDrawer(props: {
|
||||
},
|
||||
onSuccess: () => {
|
||||
setIsEditingClassification(false);
|
||||
loadQuery(
|
||||
coreEnvironment,
|
||||
documentLayoutQuery,
|
||||
{ documentId: document.id },
|
||||
{ fetchPolicy: "network-only" },
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ import type { UpdateVersionDialogFragment$key } from "#/__generated__/core/Updat
|
||||
import type { UpdateVersionDialogUpdateMutation } from "#/__generated__/core/UpdateVersionDialogUpdateMutation.graphql";
|
||||
import { useFormWithSchema } from "#/hooks/useFormWithSchema";
|
||||
import { useMutationWithToasts } from "#/hooks/useMutationWithToasts";
|
||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||
|
||||
const fragment = graphql`
|
||||
fragment UpdateVersionDialogFragment on Document {
|
||||
@@ -90,6 +91,7 @@ const versionSchema = z.object({
|
||||
export default function UpdateVersionDialog(props: UpdateVersionDialogProps) {
|
||||
const { fKey, ref } = props;
|
||||
|
||||
const organizationId = useOrganizationId();
|
||||
const { __ } = useTranslate();
|
||||
const { toast } = useToast();
|
||||
const dialogRef = useDialogRef();
|
||||
@@ -172,6 +174,7 @@ export default function UpdateVersionDialog(props: UpdateVersionDialogProps) {
|
||||
},
|
||||
onSuccess: () => {
|
||||
dialogRef.current?.close();
|
||||
window.location.href = `/organizations/${organizationId}/documents/${document.id}`;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user