Batch signature and approval notifications via debounced worker

Replace the immediate per-document approval email and the manual
"send signing notifications" action with a single debounced worker that
batches pending requests per recipient and organization.

The worker (go.gearno.de/kit/worker) polls on an interval (default 5m)
and claims one (organization, recipient) group at a time, sending one
consolidated signing email and/or one approval email per recipient/org
that lists every document awaiting their signature or approval. The
claim is a conditional UPDATE that doubles as concurrency-safe dedup, so
several workers never email the same group twice.

Each request is notified once it has been pending past the debounce
delay (default 15m), then reminded at 1x, 2x and 3x the reminder
interval (default 1 day) after the previous email, after which it stops.
New last_notified_at and notification_count columns on signatures and
approval decisions drive the debounce, the widening reminder cadence and
the four-email cap.

Email copy lists each document with its title, type and a deep link to
the employee page. Removed the inline approval-on-publish email, the
SendSigningNotifications service method/mutation/MCP tool, its IAM action,
and the related console UI and n8n operation.

Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
Sacha Al Himdani
2026-06-15 09:13:31 +02:00
committed by Sacha Al Himdani
parent c9b74bac4a
commit f462b124e6
33 changed files with 1281 additions and 524 deletions

View File

@@ -17,7 +17,6 @@ import { graphql } from "relay-runtime";
import type { DocumentGraphBulkExportDocumentsMutation } from "#/__generated__/core/DocumentGraphBulkExportDocumentsMutation.graphql";
import type { DocumentGraphDeleteMutation } from "#/__generated__/core/DocumentGraphDeleteMutation.graphql";
import type { DocumentGraphSendSigningNotificationsMutation } from "#/__generated__/core/DocumentGraphSendSigningNotificationsMutation.graphql";
import { useMutationWithToasts } from "../useMutationWithToasts";
@@ -65,28 +64,6 @@ export function useBulkDeleteDocumentsMutation() {
});
}
const sendSigningNotificationsMutation = graphql`
mutation DocumentGraphSendSigningNotificationsMutation(
$input: SendSigningNotificationsInput!
) {
sendSigningNotifications(input: $input) {
success
}
}
`;
export function useSendSigningNotificationsMutation() {
const { __ } = useTranslate();
return useMutationWithToasts<DocumentGraphSendSigningNotificationsMutation>(
sendSigningNotificationsMutation,
{
successMessage: __("Signing notifications sent successfully."),
errorMessage: __("Failed to send signing notifications"),
},
);
}
const bulkExportDocumentsMutation = graphql`
mutation DocumentGraphBulkExportDocumentsMutation(
$input: BulkExportDocumentsInput!

View File

@@ -16,7 +16,6 @@ import { usePageTitle } from "@probo/hooks";
import { useTranslate } from "@probo/i18n";
import {
Button,
IconBell2,
IconPlusLarge,
PageHeader,
TabItem,
@@ -30,9 +29,6 @@ import {
import { ConnectionHandler, graphql } from "relay-runtime";
import type { DocumentsPageQuery } from "#/__generated__/core/DocumentsPageQuery.graphql";
import {
useSendSigningNotificationsMutation,
} from "#/hooks/graph/DocumentGraph";
import { useOrganizationId } from "#/hooks/useOrganizationId";
import { CreateDocumentDialog } from "./_components/CreateDocumentDialog";
@@ -66,11 +62,8 @@ export default function DocumentsPage(props: {
throw new Error("invalid type for node");
}
const [sendSigningNotifications] = useSendSigningNotificationsMutation();
usePageTitle(__("Documents"));
const [canSendAnySignatureNotifications, setCanSendAnySignatureNotifications] = useState(false);
const [tab, setTab] = useState<"ACTIVE" | "ARCHIVED">("ACTIVE");
const [documentListConnectionId, setDocumentListConnectionId] = useState(
ConnectionHandler.getConnectionID(
@@ -80,14 +73,6 @@ export default function DocumentsPage(props: {
),
);
const handleSendSigningNotifications = async () => {
await sendSigningNotifications({
variables: {
input: { organizationId },
},
});
};
return (
<div className="space-y-6">
<PageHeader
@@ -95,15 +80,6 @@ export default function DocumentsPage(props: {
description={__("Manage your organization's documents")}
>
<div className="flex gap-2">
{canSendAnySignatureNotifications && (
<Button
icon={IconBell2}
variant="secondary"
onClick={() => void handleSendSigningNotifications()}
>
{__("Send signing notifications")}
</Button>
)}
{organization.canCreateDocument && tab === "ACTIVE" && (
<CreateDocumentDialog
connection={documentListConnectionId}
@@ -125,7 +101,6 @@ export default function DocumentsPage(props: {
<DocumentList
fKey={organization}
onConnectionIdChange={setDocumentListConnectionId}
onCanSendNotificationsChange={setCanSendAnySignatureNotifications}
tab={tab}
/>
</div>

View File

@@ -59,7 +59,6 @@ const createDocumentMutation = graphql`
canRequestSignatures: permission(action: "core:document-version:request-signature")
canArchive: permission(action: "core:document:archive")
canUnarchive: permission(action: "core:document:unarchive")
canSendSigningNotifications: permission(action: "core:document:send-signing-notifications")
...DocumentListItemFragment
}
}

View File

@@ -72,9 +72,6 @@ const fragment = graphql`
)
canArchive: permission(action: "core:document:archive")
canUnarchive: permission(action: "core:document:unarchive")
canSendSigningNotifications: permission(
action: "core:document:send-signing-notifications"
)
...DocumentListItemFragment
}
}
@@ -115,10 +112,9 @@ const bulkUnarchiveMutation = graphql`
export function DocumentList(props: {
fKey: DocumentListFragment$key;
onConnectionIdChange: (connectionId: string) => void;
onCanSendNotificationsChange?: (can: boolean) => void;
tab: "ACTIVE" | "ARCHIVED";
}) {
const { fKey, onConnectionIdChange, onCanSendNotificationsChange, tab } = props;
const { fKey, onConnectionIdChange, tab } = props;
const organizationId = useOrganizationId();
const { email: defaultEmail } = use(CurrentUser);
@@ -170,19 +166,12 @@ export function DocumentList(props: {
const canRequestAnySignatures = documents.some(({ canRequestSignatures }) => canRequestSignatures);
const canArchiveAny = documents.some(({ canArchive }) => canArchive);
const canUnarchiveAny = documents.some(({ canUnarchive }) => canUnarchive);
const canSendAnySignatureNotifications = documents.some(
({ canSendSigningNotifications }) => canSendSigningNotifications,
);
const hasAnyAction = tab === "ARCHIVED" ? canUnarchiveAny || canDeleteAny : canArchiveAny || canDeleteAny || canUpdateAny;
useEffect(() => {
onConnectionIdChange(connectionId);
}, [connectionId, onConnectionIdChange]);
useEffect(() => {
onCanSendNotificationsChange?.(canSendAnySignatureNotifications);
}, [canSendAnySignatureNotifications, onCanSendNotificationsChange]);
const handleDocumentTypeFilterChange = (value: string) => {
const newType = value === "ALL" ? null : (value as DocumentType);
clear();