Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions apps/console/src/hooks/graph/DocumentGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useTranslate } from "@probo/i18n";
import { graphql } from "relay-runtime";

import type { DocumentGraphBulkExportDocumentsMutation } from "#/__generated__/core/DocumentGraphBulkExportDocumentsMutation.graphql";
import type { DocumentGraphDeleteDraftMutation } from "#/__generated__/core/DocumentGraphDeleteDraftMutation.graphql";
import type { DocumentGraphDeleteMutation } from "#/__generated__/core/DocumentGraphDeleteMutation.graphql";
import type { DocumentGraphSendSigningNotificationsMutation } from "#/__generated__/core/DocumentGraphSendSigningNotificationsMutation.graphql";

Expand Down Expand Up @@ -47,29 +46,6 @@ export function useDeleteDocumentMutation() {
);
}

const deleteDraftDocumentVersionMutation = graphql`
mutation DocumentGraphDeleteDraftMutation(
$input: DeleteDraftDocumentVersionInput!
$connections: [ID!]!
) {
deleteDraftDocumentVersion(input: $input) {
deletedDocumentVersionId @deleteEdge(connections: $connections)
}
}
`;

export function useDeleteDraftDocumentVersionMutation() {
const { __ } = useTranslate();

return useMutationWithToasts<DocumentGraphDeleteDraftMutation>(
deleteDraftDocumentVersionMutation,
{
successMessage: __("Draft deleted successfully."),
errorMessage: __("Failed to delete draft"),
},
);
}

const bulkDeleteDocumentsMutation = graphql`
mutation DocumentGraphBulkDeleteDocumentsMutation(
$input: BulkDeleteDocumentsInput!
Expand Down
29 changes: 23 additions & 6 deletions apps/console/src/pages/organizations/documents/DocumentLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ export function DocumentLayout(props: { queryRef: PreloadedQuery<DocumentLayoutQ

const publishDialogRef = useRef<PublishDialogRef>(null);
const [approvalRequestedAt, setApprovalRequestedAt] = useState(0);
const [versionChangedAt, setVersionChangedAt] = useState(0);

const handlePublishOrApproval = useCallback(() => {
onRefetch();
setApprovalRequestedAt(Date.now());
}, [onRefetch]);

const handleVersionChanged = useCallback(() => {
onRefetch();
setVersionChangedAt(Date.now());
}, [onRefetch]);

const { document, version } = usePreloadedQuery<DocumentLayoutQuery>(documentLayoutQuery, queryRef);
if (document.__typename !== "Document" || (version && version.__typename !== "DocumentVersion")) {
throw new Error("invalid node type");
Expand Down Expand Up @@ -178,13 +184,20 @@ export function DocumentLayout(props: { queryRef: PreloadedQuery<DocumentLayoutQ
<DocumentActionsDropdown
documentFragmentRef={document}
versionFragmentRef={currentVersion}
onRefetch={onRefetch}
onVersionChanged={handleVersionChanged}
/>
</div>
</div>

<PageHeader
title={<DocumentTitleForm fKey={currentVersion} />}
title={(
<DocumentTitleForm
fKey={currentVersion}
documentId={document.id}
documentStatus={document.status}
onVersionChanged={handleVersionChanged}
/>
)}
/>

<Tabs>
Expand All @@ -207,18 +220,22 @@ export function DocumentLayout(props: { queryRef: PreloadedQuery<DocumentLayoutQ
<TabLink to={`${urlPrefix}/signatures`}>
{__("Signatures")}
<TabBadge>
{currentVersion.signedSignatures.totalCount}
{currentVersion.signedSignatures?.totalCount ?? 0}
/
{currentVersion.signatures.totalCount}
{currentVersion.signatures?.totalCount ?? 0}
</TabBadge>
</TabLink>
)}
</Tabs>

<Outlet context={{ onRefetch, approvalRequestedAt }} />
<Outlet context={{ onRefetch, approvalRequestedAt, versionChangedAt }} />
</div>

<DocumentLayoutDrawer documentFragmentRef={document} versionFragmentRef={currentVersion} />
<DocumentLayoutDrawer
documentFragmentRef={document}
versionFragmentRef={currentVersion}
onVersionChanged={handleVersionChanged}
/>

<PublishDialog
ref={publishDialogRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function DocumentLayoutQueryLoader() {
const onRefetch = useCallback(() => {
loadQuery(
{ documentId, versionId: versionId ?? "", versionSpecified: !!versionId },
{ fetchPolicy: "network-only" },
{ fetchPolicy: "store-and-network" },
);
}, [documentId, versionId, loadQuery]);

Expand Down
Loading
Loading