@open-workspace/email 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/alchemy/index.ts +130 -2
- package/drizzle/mailbox/0002_good_komodo.sql +2 -0
- package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
- package/drizzle/mailbox/meta/0002_snapshot.json +1017 -0
- package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
- package/drizzle/mailbox/meta/_journal.json +14 -0
- package/drizzle/mailbox/migrations.js +5 -1
- package/migrations/0001_overrated_ricochet.sql +2 -0
- package/migrations/0002_after_0_4_2.sql +35 -0
- package/migrations/meta/0001_snapshot.json +564 -0
- package/migrations/meta/0002_snapshot.json +807 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +23 -7
- package/shared/attachment-preview.ts +18 -8
- package/shared/folder-order.ts +31 -6
- package/shared/mail-headers.ts +3 -3
- package/shared/mail-html.ts +25 -0
- package/shared/mail-import.ts +0 -7
- package/shared/mail-received.ts +4 -4
- package/shared/mail-rule-actions.ts +47 -0
- package/shared/mail.ts +70 -4
- package/shared/office-preview.ts +0 -4
- package/shared/pdfjs-assets.ts +1 -3
- package/shared/rich-content.ts +35 -0
- package/shared/signature.ts +15 -0
- package/src/admin/address-auto-reply.tsx +49 -0
- package/src/admin/blocked-senders.tsx +86 -66
- package/src/admin/forward-destinations.tsx +140 -0
- package/src/admin/mail-archive.tsx +134 -0
- package/src/admin/team-signature.tsx +90 -0
- package/src/client.tsx +130 -16
- package/src/mail/attachment-preview-dialog.tsx +13 -5
- package/src/mail/auto-reply-banner.tsx +61 -0
- package/src/mail/blocked-senders.tsx +124 -91
- package/src/mail/compose-window-chrome.tsx +20 -8
- package/src/mail/compose-window.tsx +387 -365
- package/src/mail/composer-asset-bookmarks.ts +47 -12
- package/src/mail/composer-attachment-list.tsx +42 -17
- package/src/mail/composer-editor-document.ts +54 -10
- package/src/mail/composer-editor.tsx +44 -44
- package/src/mail/composer-link-text.ts +42 -0
- package/src/mail/composer-recipient-fields.tsx +25 -16
- package/src/mail/composer-recipients.ts +62 -16
- package/src/mail/composer-session.ts +107 -23
- package/src/mail/composer-toolbar.tsx +15 -1
- package/src/mail/composer-upload-client.ts +29 -1
- package/src/mail/composer-upload-progress.ts +2 -2
- package/src/mail/conversation-actions-model.ts +56 -0
- package/src/mail/conversation-list.tsx +263 -128
- package/src/mail/conversation-loading-skeleton.tsx +165 -90
- package/src/mail/conversation-message.tsx +257 -102
- package/src/mail/conversation-order.ts +12 -0
- package/src/mail/conversation-reply.tsx +313 -189
- package/src/mail/conversation-selection-toolbar.tsx +188 -143
- package/src/mail/conversation-view.tsx +320 -85
- package/src/mail/delivery-indicator.tsx +33 -12
- package/src/mail/draft-attachments.ts +194 -0
- package/src/mail/email-html-body.tsx +97 -53
- package/src/mail/folder-cleanup-bar.tsx +193 -0
- package/src/mail/folder-glyph.tsx +5 -0
- package/src/mail/folder-manager.tsx +71 -38
- package/src/mail/mail-app-bar.tsx +15 -3
- package/src/mail/mail-dock.tsx +19 -3
- package/src/mail/mail-focus.ts +48 -0
- package/src/mail/mail-folders.ts +14 -2
- package/src/mail/mail-layout.css +20 -0
- package/src/mail/mail-mailbox-sheet.tsx +22 -69
- package/src/mail/mail-nav-rail.tsx +7 -4
- package/src/mail/mail-nav.tsx +66 -46
- package/src/mail/mail-prefetch.ts +30 -9
- package/src/mail/mail-primitives.tsx +6 -4
- package/src/mail/mail-queries.ts +122 -20
- package/src/mail/mail-query-cache.ts +1085 -173
- package/src/mail/mail-search-params.ts +35 -0
- package/src/mail/mail-shell.tsx +32 -9
- package/src/mail/mailbox-ai-settings.tsx +56 -42
- package/src/mail/mailbox-realtime.tsx +4 -12
- package/src/mail/mailbox-rules.tsx +898 -0
- package/src/mail/message-actions.tsx +38 -26
- package/src/mail/message-attachments.tsx +20 -12
- package/src/mail/message-body.ts +53 -0
- package/src/mail/message-format.ts +8 -2
- package/src/mail/message-header.tsx +3 -1
- package/src/mail/message-translation.tsx +34 -67
- package/src/mail/original-message-sheet.tsx +63 -50
- package/src/mail/original-message.ts +6 -6
- package/src/mail/pane-splitter.tsx +3 -3
- package/src/mail/pdf-preview.tsx +70 -62
- package/src/mail/plain-message-text.tsx +28 -0
- package/src/mail/print-message.ts +31 -36
- package/src/mail/reader-pane.tsx +134 -102
- package/src/mail/recipient-combobox.tsx +52 -29
- package/src/mail/recipient-field-row.tsx +3 -0
- package/src/mail/rich-content.ts +128 -0
- package/src/mail/sanitize-email-html.ts +57 -33
- package/src/mail/sender-actions.tsx +49 -39
- package/src/mail/sender-authentication.tsx +1 -1
- package/src/mail/sender-dialogs.tsx +67 -43
- package/src/mail/sender-security.tsx +9 -10
- package/src/mail/signature.ts +43 -0
- package/src/mail/translation-html.ts +3 -3
- package/src/mail/types.ts +12 -0
- package/src/mail/use-composer-attachment-preflight.ts +23 -60
- package/src/mail/use-composer-core.ts +286 -0
- package/src/mail/use-composer-navigation.ts +120 -0
- package/src/mail/use-composer-submission.ts +154 -19
- package/src/mail/use-conversation-actions.ts +292 -0
- package/src/mail/use-conversation-position.ts +51 -0
- package/src/mail/use-conversation-selection.ts +192 -89
- package/src/mail/use-draft-autosave.ts +394 -0
- package/src/mail/use-drafts.ts +194 -0
- package/src/mail/use-mail-controller.ts +754 -213
- package/src/mail/use-mail-data.ts +210 -100
- package/src/mail/use-mail-safety.ts +19 -38
- package/src/mail/use-mail-send.ts +18 -6
- package/src/mail/use-pdf-translation.ts +1 -1
- package/src/mail/use-reply-cc.ts +61 -0
- package/src/mail/use-visible-message-read.ts +128 -64
- package/src/pwa/push-key.ts +18 -0
- package/src/pwa/push-subscription.ts +88 -26
- package/src/settings/auto-reply-editor.tsx +454 -0
- package/src/settings/auto-reply-page.tsx +59 -0
- package/src/settings/mail-apps-page.tsx +52 -43
- package/src/settings/notifications-page.tsx +82 -67
- package/src/settings/rich-content-editor.tsx +182 -0
- package/src/settings/settings-queries.ts +57 -0
- package/src/settings/signature-editor.tsx +142 -0
- package/src/settings/signature-page.tsx +70 -0
- package/worker/admin/blocked-sender-routes.ts +10 -16
- package/worker/backups/eml.ts +185 -0
- package/worker/backups/file-parts.ts +140 -0
- package/worker/backups/mail-backup.ts +644 -0
- package/worker/backups/settings-backup.ts +866 -0
- package/worker/backups/stream-eml.ts +73 -0
- package/worker/db/schema.ts +98 -2
- package/worker/jmap/attachment-blobs.ts +113 -0
- package/worker/jmap/blobs.ts +162 -0
- package/worker/jmap/draft-content.ts +42 -0
- package/worker/jmap/drafts.ts +70 -0
- package/worker/jmap/email-body.ts +152 -0
- package/worker/jmap/email-methods.ts +1223 -0
- package/worker/jmap/eventsource.ts +9 -8
- package/worker/jmap/import-methods.ts +205 -0
- package/worker/jmap/mailbox-methods.ts +187 -0
- package/worker/jmap/method-core.ts +379 -0
- package/worker/jmap/methods.ts +108 -1815
- package/worker/jmap/push-subscription-methods.ts +373 -0
- package/worker/jmap/push-types.ts +46 -2
- package/worker/jmap/push.ts +24 -31
- package/worker/jmap/routes.ts +144 -153
- package/worker/jmap/submission-methods.ts +395 -0
- package/worker/mail/access.ts +35 -12
- package/worker/mail/ai-classification.ts +2 -2
- package/worker/mail/archive-object.ts +96 -0
- package/worker/mail/archive-routes.ts +35 -0
- package/worker/mail/archive.ts +682 -0
- package/worker/mail/auth-headers.ts +48 -40
- package/worker/mail/auto-reply-routes.ts +255 -0
- package/worker/mail/auto-reply.ts +243 -0
- package/worker/mail/bimi.ts +53 -36
- package/worker/mail/bootstrap.ts +11 -3
- package/worker/mail/capabilities.ts +69 -0
- package/worker/mail/classification-signals.ts +1 -1
- package/worker/mail/confusables-data.ts +9 -0
- package/worker/mail/conversation-cursor.ts +6 -15
- package/worker/mail/delivery-events.ts +9 -7
- package/worker/mail/delivery-facts.ts +1 -1
- package/worker/mail/demo-routes.ts +3 -3
- package/worker/mail/doh.ts +3 -3
- package/worker/mail/download-links.ts +153 -0
- package/worker/mail/downloads.ts +2 -6
- package/worker/mail/draft-routes.ts +473 -0
- package/worker/mail/draft-sender.ts +54 -0
- package/worker/mail/edge-cache.ts +41 -55
- package/worker/mail/email-routing.ts +123 -0
- package/worker/mail/forward-destinations.ts +114 -0
- package/worker/mail/forward-downloads.ts +115 -0
- package/worker/mail/forward-html.ts +85 -0
- package/worker/mail/header-metadata.ts +2 -5
- package/worker/mail/impersonation.ts +102 -101
- package/worker/mail/import-routes.ts +29 -82
- package/worker/mail/import.ts +130 -0
- package/worker/mail/inbound-delivery.ts +6 -5
- package/worker/mail/inbound.ts +58 -28
- package/worker/mail/ip-intel.ts +8 -17
- package/worker/mail/isolate-cache.ts +1 -1
- package/worker/mail/mailbox-deletion.ts +33 -12
- package/worker/mail/mailbox-directory.ts +39 -65
- package/worker/mail/mailing-list.ts +29 -58
- package/worker/mail/message-security.ts +3 -3
- package/worker/mail/message-view.ts +12 -10
- package/worker/mail/office-conversion.ts +3 -5
- package/worker/mail/office-preview-container.ts +3 -8
- package/worker/mail/outbound-content.ts +139 -65
- package/worker/mail/outbound-delivery.ts +20 -17
- package/worker/mail/outbound-service.ts +34 -9
- package/worker/mail/outbound.ts +146 -75
- package/worker/mail/outgoing-context.ts +60 -30
- package/worker/mail/participants.ts +10 -15
- package/worker/mail/plain-body.ts +39 -0
- package/worker/mail/push-endpoint.ts +17 -0
- package/worker/mail/push-notifications.ts +87 -43
- package/worker/mail/quote-parser.ts +107 -25
- package/worker/mail/r2-presigned-urls.ts +7 -0
- package/worker/mail/receive.ts +146 -39
- package/worker/mail/recipients.ts +1 -1
- package/worker/mail/remote-proxy.ts +3 -3
- package/worker/mail/repeat.ts +1 -1
- package/worker/mail/reply-plan.ts +124 -26
- package/worker/mail/rfc.ts +15 -7
- package/worker/mail/rich-content.ts +207 -0
- package/worker/mail/routes.ts +696 -304
- package/worker/mail/routing.ts +274 -0
- package/worker/mail/rules.ts +230 -0
- package/worker/mail/safety-routes.ts +88 -80
- package/worker/mail/schemas.ts +222 -31
- package/worker/mail/search.ts +25 -2
- package/worker/mail/security-settings.ts +4 -10
- package/worker/mail/send-message.ts +238 -0
- package/worker/mail/sender-intel.ts +12 -20
- package/worker/mail/signature-routes.ts +201 -0
- package/worker/mail/signatures.ts +195 -0
- package/worker/mail/spamhaus.ts +28 -16
- package/worker/mail/storage-keys.ts +35 -0
- package/worker/mail/unsubscribe.ts +19 -41
- package/worker/mail/uploads.ts +193 -80
- package/worker/mail/webhook-source.ts +3 -2
- package/worker/mail/workspace-safety.ts +194 -60
- package/worker/mailbox/demo.ts +13 -15
- package/worker/mailbox/email-index.ts +92 -13
- package/worker/mailbox/folder-model.ts +0 -20
- package/worker/mailbox/import-placement.ts +21 -36
- package/worker/mailbox/inbound-decision.ts +114 -0
- package/worker/mailbox/inbox-counts.ts +45 -25
- package/worker/mailbox/index.ts +843 -2888
- package/worker/mailbox/jmap-change-log.ts +195 -0
- package/worker/mailbox/jmap-email-rows.ts +186 -0
- package/worker/mailbox/jmap-mailboxes.ts +116 -0
- package/worker/mailbox/jmap-placement.ts +139 -0
- package/worker/mailbox/jmap-query-filter.ts +231 -0
- package/worker/mailbox/jmap-store.ts +167 -299
- package/worker/mailbox/mailbox-auto-reply.ts +301 -0
- package/worker/mailbox/mailbox-backup.ts +538 -0
- package/worker/mailbox/mailbox-drafts.ts +417 -0
- package/worker/mailbox/mailbox-folders.ts +242 -0
- package/worker/mailbox/mailbox-import.ts +450 -0
- package/worker/mailbox/mailbox-inbound.ts +934 -0
- package/worker/mailbox/mailbox-jmap.ts +294 -0
- package/worker/mailbox/mailbox-outbound.ts +413 -0
- package/worker/mailbox/mailbox-rules.ts +336 -0
- package/worker/mailbox/mailbox-senders.ts +294 -0
- package/worker/mailbox/mailbox-storage.ts +438 -0
- package/worker/mailbox/mailbox-views.ts +891 -0
- package/worker/mailbox/model.ts +1 -0
- package/worker/mailbox/office-preview-jobs.ts +59 -47
- package/worker/mailbox/placement.ts +933 -0
- package/worker/mailbox/restore-thread.ts +52 -0
- package/worker/mailbox/retention.ts +36 -0
- package/worker/mailbox/schema.ts +211 -1
- package/worker/mailbox/senders.ts +216 -178
- package/worker/mailbox/spam-undo-filing.ts +138 -0
- package/worker/mailbox/spam-undo.ts +240 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +156 -0
- package/worker/mcp/mail-compose-tools.ts +8 -2
- package/worker/mcp/mail-safety-tools.ts +4 -4
- package/worker/module.ts +23 -2
- package/src/mail/use-compose-submission.ts +0 -208
- package/src/mail/use-reply-submission.ts +0 -114
- package/worker/mail/capped-body.ts +0 -36
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSerializer,
|
|
3
|
+
parseAsBoolean,
|
|
4
|
+
parseAsString,
|
|
5
|
+
parseAsStringLiteral,
|
|
6
|
+
} from "nuqs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The mail screen's search params. `q`, `compose`, `match` and `quote` stay
|
|
10
|
+
* across its pages. Opening a sheet adds a history entry, so Back closes it.
|
|
11
|
+
*/
|
|
12
|
+
export const mailSearchParams = {
|
|
13
|
+
q: parseAsString.withDefault(""),
|
|
14
|
+
/**
|
|
15
|
+
* The open composer: `new-<draft id>` for a window opened here, whose
|
|
16
|
+
* draft may not be saved yet, else a saved draft's id. React Router
|
|
17
|
+
* sets it (see useMailController).
|
|
18
|
+
*/
|
|
19
|
+
compose: parseAsString,
|
|
20
|
+
/** The search hit a conversation opened from search shows first. */
|
|
21
|
+
match: parseAsString,
|
|
22
|
+
/** The hit is in quoted text. */
|
|
23
|
+
quote: parseAsBoolean.withDefault(false),
|
|
24
|
+
sheet: parseAsStringLiteral(["mailboxes"]).withOptions({ history: "push" }),
|
|
25
|
+
/** The message whose original is shown. */
|
|
26
|
+
original: parseAsString.withOptions({ history: "push" }),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** A mail href with these search params set (null drops one); others drop. */
|
|
30
|
+
export const mailHref = createSerializer(mailSearchParams);
|
|
31
|
+
|
|
32
|
+
/** An unsaved window may have no row yet when history reopens it. */
|
|
33
|
+
export function composeDraftId(value: string | null) {
|
|
34
|
+
return value?.startsWith("new-drf_") ? value.slice(4) : value;
|
|
35
|
+
}
|
package/src/mail/mail-shell.tsx
CHANGED
|
@@ -2,15 +2,19 @@ import { cn } from "@open-workspace/core/ui";
|
|
|
2
2
|
import { lazy, Suspense, useRef, useState } from "react";
|
|
3
3
|
import type { CSSProperties } from "react";
|
|
4
4
|
|
|
5
|
+
import { AutoReplyBanner } from "./auto-reply-banner";
|
|
5
6
|
import { ConversationList } from "./conversation-list";
|
|
6
7
|
import { FolderManager } from "./folder-manager";
|
|
7
8
|
import { AppBar } from "./mail-app-bar";
|
|
8
9
|
import { MobileDock } from "./mail-dock";
|
|
10
|
+
import { CONVERSATION_LIST_ID } from "./mail-focus";
|
|
9
11
|
import type { MailRoute } from "./mail-location";
|
|
10
12
|
import { NavTree } from "./mail-nav";
|
|
11
13
|
import { NavRail } from "./mail-nav-rail";
|
|
12
14
|
import { PaneSplitter, useListWidth } from "./pane-splitter";
|
|
13
15
|
import { ReaderPane } from "./reader-pane";
|
|
16
|
+
import { ComposerLeaveChecks } from "./use-composer-navigation";
|
|
17
|
+
import type { MailController } from "./use-mail-controller";
|
|
14
18
|
import { useMailController } from "./use-mail-controller";
|
|
15
19
|
|
|
16
20
|
const ComposeWindow = lazy(async () => {
|
|
@@ -26,16 +30,25 @@ const ComposeWindow = lazy(async () => {
|
|
|
26
30
|
* it is one pane at a time with a bottom dock of every folder.
|
|
27
31
|
*/
|
|
28
32
|
/** The list pane's width, as the CSS variable the layout reads. */
|
|
29
|
-
function listWidthStyle(
|
|
30
|
-
|
|
31
|
-
): CSSProperties & Record<"--mail-list-w", string> {
|
|
32
|
-
return {
|
|
33
|
+
function listWidthStyle(width: number) {
|
|
34
|
+
const style: CSSProperties & Record<"--mail-list-w", string> = {
|
|
33
35
|
"--mail-list-w": `clamp(20rem, ${width}px, calc(100% - 26.625rem))`,
|
|
34
36
|
};
|
|
37
|
+
|
|
38
|
+
return style;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export function MailShell({ route }: { route: MailRoute }) {
|
|
38
|
-
const mail = useMailController(route
|
|
42
|
+
const mail = useMailController(route);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ComposerLeaveChecks value={mail.registerComposerLeaveCheck}>
|
|
46
|
+
<MailLayout mail={mail} />
|
|
47
|
+
</ComposerLeaveChecks>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function MailLayout({ mail }: { mail: MailController }) {
|
|
39
52
|
/** Folder settings opened from the phone's dock. */
|
|
40
53
|
const [managingFolders, setManagingFolders] = useState(false);
|
|
41
54
|
const reading = Boolean(mail.conversationId);
|
|
@@ -45,6 +58,9 @@ export function MailShell({ route }: { route: MailRoute }) {
|
|
|
45
58
|
return (
|
|
46
59
|
<div className="bg-background text-foreground flex h-dvh min-h-0 flex-col gap-1.5 overflow-hidden p-2 pt-1 text-[13px] lg:gap-2 lg:p-2.5 lg:pt-1.5">
|
|
47
60
|
<AppBar mail={mail} />
|
|
61
|
+
{mail.mailbox?.kind === "personal" && (
|
|
62
|
+
<AutoReplyBanner mailbox={mail.mailbox} />
|
|
63
|
+
)}
|
|
48
64
|
|
|
49
65
|
<div className="flex min-h-0 flex-1 gap-2.5">
|
|
50
66
|
<aside
|
|
@@ -66,9 +82,12 @@ export function MailShell({ route }: { route: MailRoute }) {
|
|
|
66
82
|
className="flex min-w-0 flex-1"
|
|
67
83
|
>
|
|
68
84
|
<section
|
|
85
|
+
id={CONVERSATION_LIST_ID}
|
|
86
|
+
// Focus lands here when an action leaves no row to take it.
|
|
87
|
+
tabIndex={-1}
|
|
69
88
|
aria-label="Conversation list"
|
|
70
89
|
className={cn(
|
|
71
|
-
"mail-pane min-w-0 flex-col overflow-hidden lg:flex lg:w-(--mail-list-w) lg:shrink-0",
|
|
90
|
+
"mail-pane min-w-0 flex-col overflow-hidden outline-none lg:flex lg:w-(--mail-list-w) lg:shrink-0",
|
|
72
91
|
reading ? "hidden" : "flex flex-1 lg:flex-none"
|
|
73
92
|
)}
|
|
74
93
|
>
|
|
@@ -101,6 +120,7 @@ export function MailShell({ route }: { route: MailRoute }) {
|
|
|
101
120
|
<FolderManager
|
|
102
121
|
key={mail.mailbox.id}
|
|
103
122
|
mailboxId={mail.mailbox.id}
|
|
123
|
+
canOrganize={mail.mailbox.canOrganize}
|
|
104
124
|
activeFolderId={mail.folder}
|
|
105
125
|
folders={mail.folders ?? []}
|
|
106
126
|
onSelectFolder={mail.selectFolder}
|
|
@@ -111,12 +131,15 @@ export function MailShell({ route }: { route: MailRoute }) {
|
|
|
111
131
|
/>
|
|
112
132
|
)}
|
|
113
133
|
|
|
114
|
-
{mail.
|
|
134
|
+
{mail.mailbox && mail.composer && (
|
|
115
135
|
<Suspense fallback={null}>
|
|
116
136
|
<ComposeWindow
|
|
117
|
-
key={
|
|
137
|
+
key={mail.composer.draftId}
|
|
118
138
|
mailbox={mail.mailbox}
|
|
119
|
-
forwardedMessage={mail.
|
|
139
|
+
forwardedMessage={mail.composer.forwarded}
|
|
140
|
+
draft={mail.composer.draft}
|
|
141
|
+
draftId={mail.composer.draftId}
|
|
142
|
+
discarded={mail.composerDiscarded}
|
|
120
143
|
onClose={mail.closeComposer}
|
|
121
144
|
/>
|
|
122
145
|
</Suspense>
|
|
@@ -4,17 +4,20 @@ import {
|
|
|
4
4
|
DialogFooter,
|
|
5
5
|
Input,
|
|
6
6
|
Label,
|
|
7
|
+
PlaceholderFrame,
|
|
7
8
|
Skeleton,
|
|
8
9
|
Textarea,
|
|
10
|
+
queryErrorBlocksContent,
|
|
9
11
|
responseJson,
|
|
12
|
+
useDelayedPending,
|
|
10
13
|
} from "@open-workspace/core/ui";
|
|
11
14
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
12
15
|
import { LoaderCircle, Save } from "lucide-react";
|
|
13
|
-
import {
|
|
14
|
-
import type { FormEvent } from "react";
|
|
16
|
+
import { useForm } from "react-hook-form";
|
|
15
17
|
import { toast } from "sonner";
|
|
16
18
|
|
|
17
19
|
import { mailApi } from "../lib/mail-api";
|
|
20
|
+
import { mailboxAiQuery } from "./mail-queries";
|
|
18
21
|
import type {
|
|
19
22
|
MailboxAiConfiguration,
|
|
20
23
|
MailboxAiSettings as MailboxAiSettingsValue,
|
|
@@ -23,31 +26,28 @@ import type {
|
|
|
23
26
|
export function MailboxAiSettings({
|
|
24
27
|
mailboxId,
|
|
25
28
|
active,
|
|
29
|
+
canEdit,
|
|
26
30
|
}: {
|
|
27
31
|
mailboxId: string;
|
|
28
32
|
active: boolean;
|
|
33
|
+
/** False for a shared inbox to someone who doesn't manage teams. */
|
|
34
|
+
canEdit: boolean;
|
|
29
35
|
}) {
|
|
30
|
-
const settings = useQuery({
|
|
31
|
-
|
|
32
|
-
queryFn: async () =>
|
|
33
|
-
responseJson(
|
|
34
|
-
await mailApi.api.mail.mailboxes[":id"].ai.$get({
|
|
35
|
-
param: { id: mailboxId },
|
|
36
|
-
})
|
|
37
|
-
),
|
|
38
|
-
enabled: active,
|
|
39
|
-
});
|
|
36
|
+
const settings = useQuery({ ...mailboxAiQuery(mailboxId), enabled: active });
|
|
37
|
+
const skeleton = useDelayedPending(settings.isLoading);
|
|
40
38
|
|
|
41
|
-
if (settings.isLoading) {
|
|
39
|
+
if (settings.isLoading || skeleton) {
|
|
42
40
|
return (
|
|
43
|
-
<
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
<PlaceholderFrame shown={skeleton}>
|
|
42
|
+
<div className="space-y-4 py-2">
|
|
43
|
+
<Skeleton className="h-14 w-full" />
|
|
44
|
+
<Skeleton className="h-28 w-full" />
|
|
45
|
+
</div>
|
|
46
|
+
</PlaceholderFrame>
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
if (settings
|
|
50
|
+
if (queryErrorBlocksContent(settings)) {
|
|
51
51
|
return (
|
|
52
52
|
<div className="border-border/70 flex items-center justify-between gap-4 border-y py-4">
|
|
53
53
|
<p className="text-muted-foreground text-sm">
|
|
@@ -66,9 +66,10 @@ export function MailboxAiSettings({
|
|
|
66
66
|
|
|
67
67
|
return settings.data ? (
|
|
68
68
|
<MailboxAiSettingsForm
|
|
69
|
-
key={
|
|
69
|
+
key={mailboxId}
|
|
70
70
|
mailboxId={mailboxId}
|
|
71
71
|
initial={settings.data.settings}
|
|
72
|
+
canEdit={canEdit}
|
|
72
73
|
/>
|
|
73
74
|
) : null;
|
|
74
75
|
}
|
|
@@ -76,12 +77,26 @@ export function MailboxAiSettings({
|
|
|
76
77
|
function MailboxAiSettingsForm({
|
|
77
78
|
mailboxId,
|
|
78
79
|
initial,
|
|
80
|
+
canEdit,
|
|
79
81
|
}: {
|
|
80
82
|
mailboxId: string;
|
|
81
83
|
initial: MailboxAiSettingsValue;
|
|
84
|
+
canEdit: boolean;
|
|
82
85
|
}) {
|
|
83
86
|
const client = useQueryClient();
|
|
84
|
-
|
|
87
|
+
|
|
88
|
+
const {
|
|
89
|
+
formState: { isDirty },
|
|
90
|
+
getValues,
|
|
91
|
+
handleSubmit,
|
|
92
|
+
register,
|
|
93
|
+
reset,
|
|
94
|
+
setValue,
|
|
95
|
+
} = useForm({
|
|
96
|
+
defaultValues: initial.configuration,
|
|
97
|
+
// The compiler keeps register's refs, so a reset keeps them too.
|
|
98
|
+
resetOptions: { keepFieldsRef: true },
|
|
99
|
+
});
|
|
85
100
|
|
|
86
101
|
const save = useMutation({
|
|
87
102
|
mutationFn: async (input: MailboxAiConfiguration) =>
|
|
@@ -91,21 +106,30 @@ function MailboxAiSettingsForm({
|
|
|
91
106
|
json: input,
|
|
92
107
|
})
|
|
93
108
|
),
|
|
94
|
-
onSuccess: async (result) => {
|
|
95
|
-
|
|
109
|
+
onSuccess: async (result, submitted) => {
|
|
110
|
+
const saved = result.settings.configuration;
|
|
111
|
+
|
|
112
|
+
// Apply the server's trimmed text only while it still matches the submission.
|
|
113
|
+
if (getValues("instructions") === submitted.instructions) {
|
|
114
|
+
setValue("instructions", saved.instructions);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
reset(saved, { keepValues: true });
|
|
96
118
|
toast.success("Mailbox AI rules updated");
|
|
97
119
|
await client.invalidateQueries({ queryKey: ["mailbox-ai", mailboxId] });
|
|
98
120
|
},
|
|
99
121
|
onError: (error) => toast.error(error.message),
|
|
100
122
|
});
|
|
101
123
|
|
|
102
|
-
|
|
103
|
-
event.preventDefault();
|
|
104
|
-
save.mutate(configuration);
|
|
105
|
-
}
|
|
124
|
+
const submit = handleSubmit((submitted) => save.mutate(submitted));
|
|
106
125
|
|
|
107
126
|
return (
|
|
108
127
|
<form className="space-y-5" onSubmit={submit}>
|
|
128
|
+
{canEdit ? null : (
|
|
129
|
+
<p className="text-muted-foreground text-sm">
|
|
130
|
+
Only people who manage teams change a shared inbox's AI sorting.
|
|
131
|
+
</p>
|
|
132
|
+
)}
|
|
109
133
|
<div className="border-border/70 flex items-start justify-between gap-4 border-y py-4">
|
|
110
134
|
<div>
|
|
111
135
|
<p className="text-sm font-medium">Processing status</p>
|
|
@@ -132,13 +156,8 @@ function MailboxAiSettingsForm({
|
|
|
132
156
|
max={100}
|
|
133
157
|
step={5}
|
|
134
158
|
required
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
setConfiguration({
|
|
138
|
-
...configuration,
|
|
139
|
-
confidenceThreshold: Number(event.target.value),
|
|
140
|
-
})
|
|
141
|
-
}
|
|
159
|
+
readOnly={!canEdit}
|
|
160
|
+
{...register("confidenceThreshold", { valueAsNumber: true })}
|
|
142
161
|
/>
|
|
143
162
|
<span className="text-muted-foreground text-sm">%</span>
|
|
144
163
|
</div>
|
|
@@ -155,14 +174,9 @@ function MailboxAiSettingsForm({
|
|
|
155
174
|
id={`mailbox-ai-instructions-${mailboxId}`}
|
|
156
175
|
className="min-h-32 resize-y"
|
|
157
176
|
maxLength={4000}
|
|
177
|
+
readOnly={!canEdit}
|
|
158
178
|
placeholder="For example: partnership requests go to Product. Treat newsletters as spam only when clearly unsolicited."
|
|
159
|
-
|
|
160
|
-
onChange={(event) =>
|
|
161
|
-
setConfiguration({
|
|
162
|
-
...configuration,
|
|
163
|
-
instructions: event.target.value,
|
|
164
|
-
})
|
|
165
|
-
}
|
|
179
|
+
{...register("instructions")}
|
|
166
180
|
/>
|
|
167
181
|
<p className="text-muted-foreground text-xs">
|
|
168
182
|
Refer to custom folders by the names shown in navigation. If nothing
|
|
@@ -170,8 +184,8 @@ function MailboxAiSettingsForm({
|
|
|
170
184
|
</p>
|
|
171
185
|
</div>
|
|
172
186
|
|
|
173
|
-
<DialogFooter>
|
|
174
|
-
<Button type="submit" disabled={save.isPending}>
|
|
187
|
+
<DialogFooter hidden={!canEdit}>
|
|
188
|
+
<Button type="submit" disabled={save.isPending || !isDirty}>
|
|
175
189
|
{save.isPending ? (
|
|
176
190
|
<LoaderCircle className="animate-spin" />
|
|
177
191
|
) : (
|
|
@@ -4,6 +4,7 @@ import { useEffect, useRef } from "react";
|
|
|
4
4
|
import { useLocation } from "react-router";
|
|
5
5
|
|
|
6
6
|
import { parseMailboxRealtimeUpdate } from "../../shared/mail";
|
|
7
|
+
import { parseMailPath } from "../../shared/mail-path";
|
|
7
8
|
import { noteMailboxVersion, watchMailboxVersions } from "./mail-query-cache";
|
|
8
9
|
import { useMailboxes } from "./use-mail-data";
|
|
9
10
|
|
|
@@ -27,21 +28,12 @@ function realtimeUrl(mailboxId: string, visibility: "visible" | "hidden") {
|
|
|
27
28
|
return url;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/** The mailbox the page shows: any of its folders or conversations, or the first at the root. */
|
|
30
32
|
function mailboxFromPath(pathname: string, mailboxIds: string[]) {
|
|
31
33
|
if (pathname === "/") return mailboxIds[0] ?? null;
|
|
32
|
-
const
|
|
34
|
+
const mailboxId = parseMailPath(pathname)?.mailboxId;
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (encoded === undefined) return null;
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const mailboxId = decodeURIComponent(encoded);
|
|
40
|
-
|
|
41
|
-
return mailboxIds.includes(mailboxId) ? mailboxId : null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
36
|
+
return mailboxId && mailboxIds.includes(mailboxId) ? mailboxId : null;
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
export function MailboxRealtimeConnections() {
|