Add bulk mutation for Documents
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
787fcf60cb
commit
75656b1ae1
@@ -39,6 +39,8 @@ import { sprintf, getDocumentTypeLabel } from "@probo/helpers";
|
||||
import { CreateDocumentDialog } from "./dialogs/CreateDocumentDialog";
|
||||
import type { DocumentsPageRowFragment$key } from "./__generated__/DocumentsPageRowFragment.graphql";
|
||||
import { SortableTable, SortableTh } from "/components/SortableTable";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts.ts";
|
||||
import { usePeople } from "/hooks/graph/PeopleGraph.ts";
|
||||
|
||||
const documentsFragment = graphql`
|
||||
fragment DocumentsPageListFragment on Organization
|
||||
@@ -71,6 +73,36 @@ const documentsFragment = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
const documentsPublishMutation = graphql`
|
||||
mutation DocumentsPagePublishMutation(
|
||||
$input: BulkPublishDocumentVersionsInput!
|
||||
) {
|
||||
bulkPublishDocumentVersions(input: $input) {
|
||||
documentEdges {
|
||||
node {
|
||||
id
|
||||
...DocumentsPageRowFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const documentsSignatureMutation = graphql`
|
||||
mutation DocumentsPageSignatureMutation(
|
||||
$input: BulkRequestSignaturesInput!
|
||||
) {
|
||||
bulkRequestSignatures(input: $input) {
|
||||
documentVersionSignatureEdges {
|
||||
node {
|
||||
id
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
queryRef: PreloadedQuery<DocumentGraphListQuery>;
|
||||
};
|
||||
@@ -92,8 +124,16 @@ export default function DocumentsPage(props: Props) {
|
||||
const [sendSigningNotifications] = useSendSigningNotificationsMutation();
|
||||
const { list: selection, toggle, clear, reset } = useList<string>([]);
|
||||
|
||||
// TODO : Add mutation to handle publishing multiple documents and request multiple signatures
|
||||
const [publishMutation, isPublishing] = useMutationWithToasts(documentsPublishMutation, {
|
||||
successMessage: sprintf(__("%s documents published"), selection.length),
|
||||
errorMessage: sprintf(__("Failed to publish %s documents"), selection.length),
|
||||
})
|
||||
|
||||
const [signatureMutation, isSigning] = useMutationWithToasts(documentsSignatureMutation, {
|
||||
successMessage: __("Signature request send successfully"),
|
||||
errorMessage: __("Failed to send signature requests"),
|
||||
})
|
||||
const people = usePeople(organization.id);
|
||||
usePageTitle(__("Documents"));
|
||||
|
||||
const handleSendSigningNotifications = () => {
|
||||
@@ -104,6 +144,30 @@ export default function DocumentsPage(props: Props) {
|
||||
});
|
||||
};
|
||||
|
||||
const publish = async () => {
|
||||
await publishMutation({
|
||||
variables: {
|
||||
input: {
|
||||
documentIds: selection,
|
||||
changelog: '',
|
||||
}
|
||||
}
|
||||
})
|
||||
clear();
|
||||
}
|
||||
|
||||
const requestSignatures = async () => {
|
||||
await signatureMutation({
|
||||
variables: {
|
||||
input: {
|
||||
documentIds: selection,
|
||||
signatoryIds: people.map(p => p.id),
|
||||
}
|
||||
}
|
||||
})
|
||||
clear();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<PageHeader
|
||||
@@ -157,8 +221,8 @@ export default function DocumentsPage(props: Props) {
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button icon={IconCheckmark1}>{__("Publish")}</Button>
|
||||
<Button variant="secondary" icon={IconSignature}>
|
||||
<Button icon={IconCheckmark1} onClick={publish} disabled={isPublishing}>{__("Publish")}</Button>
|
||||
<Button variant="secondary" icon={IconSignature} onClick={requestSignatures} disabled={isSigning}>
|
||||
{__("Request signature")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
303
apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts
generated
Normal file
303
apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* @generated SignedSource<<ceff42181ddc76c55b97c976cfb1b697>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
import { FragmentRefs } from "relay-runtime";
|
||||
export type BulkPublishDocumentVersionsInput = {
|
||||
changelog: string;
|
||||
documentIds: ReadonlyArray<string>;
|
||||
};
|
||||
export type DocumentsPagePublishMutation$variables = {
|
||||
input: BulkPublishDocumentVersionsInput;
|
||||
};
|
||||
export type DocumentsPagePublishMutation$data = {
|
||||
readonly bulkPublishDocumentVersions: {
|
||||
readonly documentEdges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly id: string;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"DocumentsPageRowFragment">;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
};
|
||||
export type DocumentsPagePublishMutation = {
|
||||
response: DocumentsPagePublishMutation$data;
|
||||
variables: DocumentsPagePublishMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
v2 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "DocumentsPagePublishMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v1/*: any*/),
|
||||
"concreteType": "BulkPublishDocumentVersionsPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "bulkPublishDocumentVersions",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "documentEdges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Document",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"args": null,
|
||||
"kind": "FragmentSpread",
|
||||
"name": "DocumentsPageRowFragment"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "DocumentsPagePublishMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v1/*: any*/),
|
||||
"concreteType": "BulkPublishDocumentVersionsPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "bulkPublishDocumentVersions",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "documentEdges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Document",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "title",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "description",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "documentType",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "updatedAt",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "People",
|
||||
"kind": "LinkedField",
|
||||
"name": "owner",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "fullName",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 1
|
||||
}
|
||||
],
|
||||
"concreteType": "DocumentVersionConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "versions",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersionEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersion",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "status",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 100
|
||||
}
|
||||
],
|
||||
"concreteType": "DocumentVersionSignatureConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "signatures",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersionSignatureEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersionSignature",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "state",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "signatures(first:100)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "versions(first:1)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "7cd29425535c6d30017201fee219447b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "DocumentsPagePublishMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation DocumentsPagePublishMutation(\n $input: BulkPublishDocumentVersionsInput!\n) {\n bulkPublishDocumentVersions(input: $input) {\n documentEdges {\n node {\n id\n ...DocumentsPageRowFragment\n }\n }\n }\n}\n\nfragment DocumentsPageRowFragment on Document {\n id\n title\n description\n documentType\n updatedAt\n owner {\n id\n fullName\n }\n versions(first: 1) {\n edges {\n node {\n id\n status\n signatures(first: 100) {\n edges {\n node {\n id\n state\n }\n }\n }\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "baea3e7dce61a42bf5bf2caefda998ea";
|
||||
|
||||
export default node;
|
||||
128
apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts
generated
Normal file
128
apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @generated SignedSource<<4c3514470041046f80f410ea5a3275d6>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type DocumentVersionSignatureState = "REQUESTED" | "SIGNED";
|
||||
export type BulkRequestSignaturesInput = {
|
||||
documentIds: ReadonlyArray<string>;
|
||||
signatoryIds: ReadonlyArray<string>;
|
||||
};
|
||||
export type DocumentsPageSignatureMutation$variables = {
|
||||
input: BulkRequestSignaturesInput;
|
||||
};
|
||||
export type DocumentsPageSignatureMutation$data = {
|
||||
readonly bulkRequestSignatures: {
|
||||
readonly documentVersionSignatureEdges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly id: string;
|
||||
readonly state: DocumentVersionSignatureState;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
};
|
||||
export type DocumentsPageSignatureMutation = {
|
||||
response: DocumentsPageSignatureMutation$data;
|
||||
variables: DocumentsPageSignatureMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "BulkRequestSignaturesPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "bulkRequestSignatures",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersionSignatureEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "documentVersionSignatureEdges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "DocumentVersionSignature",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "state",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "DocumentsPageSignatureMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "DocumentsPageSignatureMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "a61a828bc67d8b569c38f4826b42d00f",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "DocumentsPageSignatureMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation DocumentsPageSignatureMutation(\n $input: BulkRequestSignaturesInput!\n) {\n bulkRequestSignatures(input: $input) {\n documentVersionSignatureEdges {\n node {\n id\n state\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "1cb2b7dfa938b35cf75b09b51cdd2dca";
|
||||
|
||||
export default node;
|
||||
Reference in New Issue
Block a user