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