@jsb188/graphql 1.1.11 → 1.1.13
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/LICENSE +21 -0
- package/audience.d.ts +205 -0
- package/cache/config.ts +65 -28
- package/cache/index.helpers.ts +96 -0
- package/cache/index.ts +364 -808
- package/cache/mounted-queries.ts +33 -0
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +107 -22
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +13 -39
- package/client/index.ts +4 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +122 -232
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +156 -0
- package/gql/fragments/aiChatFragments.ts +35 -11
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +76 -0
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +49 -21
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +12 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +574 -145
- package/gql/fragments/sheetFragments.ts +86 -424
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +32 -4
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +64 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +34 -4
- package/gql/mutations/audienceMutations.ts +58 -0
- package/gql/mutations/authMutations.ts +24 -28
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +10 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +389 -417
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +1 -1
- package/gql/mutations/workflowMutations.ts +94 -0
- package/gql/queries/agentMemoryQueries.ts +12 -2
- package/gql/queries/agentNoteQueries.ts +86 -0
- package/gql/queries/aiChatQueries.ts +63 -12
- package/gql/queries/audienceQueries.ts +104 -0
- package/gql/queries/authQueries.ts +20 -4
- package/gql/queries/billingQueries.ts +114 -9
- package/gql/queries/dataTableQueries.ts +43 -75
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +48 -64
- package/gql/queries/emailReplyReportQueries.ts +127 -0
- package/gql/queries/fieldDocQueries.ts +128 -98
- package/gql/queries/inboundContactQueries.ts +15 -4
- package/gql/queries/index.ts +5 -3
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +86 -12
- package/gql/queries/organizationQueries.ts +44 -12
- package/gql/queries/qrCodeQueries.ts +27 -0
- package/gql/queries/scheduleQueries.ts +401 -278
- package/gql/queries/sheetQueries.ts +94 -165
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +61 -12
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +920 -715
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +89 -0
- package/hooks/use-agentNote-qry.ts +162 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +57 -0
- package/hooks/use-aiChat-mtn.ts +104 -115
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +254 -387
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +170 -0
- package/hooks/use-audience-qry.helpers.ts +39 -0
- package/hooks/use-audience-qry.ts +245 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +69 -914
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +44 -174
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +231 -348
- package/hooks/use-schedule-qry.ts +208 -139
- package/hooks/use-schedule-reactive.ts +218 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +88 -237
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +84 -23
- package/hooks/use-workflow-qry.ts +60 -61
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +45 -0
- package/libs/sheet-realtime-packet.ts +53 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/emailPreference.ts +69 -0
- package/loaders/rest.ts +12 -0
- package/package.json +77 -25
- package/schedule.d.ts +1183 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/types.d.ts +48 -25
- package/cache/index.test.ts +0 -881
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-managed-session.test.ts +0 -574
- package/client/request-no-store.test.ts +0 -157
- package/client/sse-ticket.test.ts +0 -26
- package/deno.lock +0 -170
- package/deno.test.json +0 -10
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/fragments/campaignFragments.ts +0 -277
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/mutations/campaignMutations.ts +0 -215
- package/gql/queries/agentDocQueries.ts +0 -120
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -127
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-campaign-mtn.ts +0 -377
- package/hooks/use-campaign-qry.ts +0 -257
- package/loaders/campaign.ts +0 -137
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
+
import { setInboundEmailSenderBlockedMtn } from '../gql/mutations/emailMutations.ts';
|
|
4
|
+
import { useMutation } from './index.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Block or unblock the sender of one inbound email for the organization's agent inbox.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function useSetInboundEmailSenderBlocked(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
11
|
+
const { onCompleted, ...rest } = params;
|
|
12
|
+
|
|
13
|
+
const [setInboundEmailSenderBlocked, mtnValues, mtnHandlers] = useMutation(setInboundEmailSenderBlockedMtn, {
|
|
14
|
+
openModalPopUp,
|
|
15
|
+
onCompleted: (data, error, variables) => {
|
|
16
|
+
onCompleted?.(data?.setInboundEmailSenderBlocked, error, variables);
|
|
17
|
+
},
|
|
18
|
+
...rest,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
setInboundEmailSenderBlocked,
|
|
23
|
+
...mtnValues,
|
|
24
|
+
...mtnHandlers,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EmailMessagesFilterInput } from '@jsb188/mday/types/email.d.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Whitelist GraphQL input fields, trim searches, and preserve false observation filters.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeEmailMessagesFilter(filter?: EmailMessagesFilterInput | null): EmailMessagesFilterInput | null {
|
|
7
|
+
return filter
|
|
8
|
+
? {
|
|
9
|
+
startDate: filter.startDate || null,
|
|
10
|
+
endDate: filter.endDate || null,
|
|
11
|
+
query: filter.query?.trim() || null,
|
|
12
|
+
directions: filter.directions?.length ? filter.directions : null,
|
|
13
|
+
kinds: filter.kinds?.length ? filter.kinds : null,
|
|
14
|
+
statusGroups: filter.statusGroups?.length ? filter.statusGroups : null,
|
|
15
|
+
statuses: filter.statuses?.length ? filter.statuses : null,
|
|
16
|
+
emailOutreachId: filter.emailOutreachId || null,
|
|
17
|
+
emailAddress: filter.emailAddress?.trim() || null,
|
|
18
|
+
fromEmail: filter.fromEmail?.trim() || null,
|
|
19
|
+
toEmail: filter.toEmail?.trim() || null,
|
|
20
|
+
subject: filter.subject?.trim() || null,
|
|
21
|
+
delivered: filter.delivered ?? null,
|
|
22
|
+
opened: filter.opened ?? null,
|
|
23
|
+
}
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Keep detail cache records inside the currently requested organization and email.
|
|
29
|
+
*/
|
|
30
|
+
export function getScopedEmailRecord<T extends { id: string; organizationId: string }>(
|
|
31
|
+
email: T | null | undefined,
|
|
32
|
+
organizationId: string | null | undefined,
|
|
33
|
+
emailId: string | null | undefined,
|
|
34
|
+
skip: boolean,
|
|
35
|
+
): T | null {
|
|
36
|
+
return !skip && organizationId && emailId && email?.organizationId === organizationId && email.id === emailId ? email : null;
|
|
37
|
+
}
|
package/hooks/use-email-qry.ts
CHANGED
|
@@ -1,227 +1,97 @@
|
|
|
1
1
|
import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
InboundEmailsSortEnum,
|
|
5
|
-
OutboundEmailGQL,
|
|
6
|
-
OutboundEmailsSortEnum,
|
|
7
|
-
} from '@jsb188/mday/types/email.d.ts';
|
|
8
|
-
import {
|
|
9
|
-
inboundEmailQry,
|
|
10
|
-
inboundEmailsQry,
|
|
11
|
-
outboundEmailQry,
|
|
12
|
-
outboundEmailsQry,
|
|
13
|
-
} from '../gql/queries/emailQueries.ts';
|
|
2
|
+
import type { EmailMessageGQL, EmailMessagesFilterInput, EmailMessagesSortEnum } from '@jsb188/mday/types/email.d.ts';
|
|
3
|
+
import { emailMessageConversationPageQry, emailMessageQry, emailMessagesQry } from '../gql/queries/emailQueries.ts';
|
|
14
4
|
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
5
|
+
import { getScopedEmailRecord, normalizeEmailMessagesFilter } from './use-email-qry.helpers.ts';
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* Constants
|
|
18
9
|
*/
|
|
19
10
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
type EmailListFilter =
|
|
23
|
-
| {
|
|
24
|
-
startDate?: string | null;
|
|
25
|
-
endDate?: string | null;
|
|
26
|
-
query?: string | null;
|
|
27
|
-
statuses?: string[] | null;
|
|
28
|
-
}
|
|
29
|
-
| null
|
|
30
|
-
| undefined;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Keep email list filters aligned with the GraphQL input shape.
|
|
34
|
-
*/
|
|
35
|
-
function normalizeEmailsFilter(filter?: EmailListFilter) {
|
|
36
|
-
return filter
|
|
37
|
-
? {
|
|
38
|
-
startDate: filter.startDate || null,
|
|
39
|
-
endDate: filter.endDate || null,
|
|
40
|
-
query: filter.query || null,
|
|
41
|
-
statuses: filter.statuses || null,
|
|
42
|
-
}
|
|
43
|
-
: null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Return true when one email record should be fetched from the server.
|
|
48
|
-
*/
|
|
49
|
-
function shouldFetchEmailRecord(
|
|
50
|
-
variables: {
|
|
51
|
-
organizationId?: string | null;
|
|
52
|
-
},
|
|
53
|
-
emailId?: string | null,
|
|
54
|
-
cachedEmail?: InboundEmailGQL | OutboundEmailGQL | null,
|
|
55
|
-
params: UseQueryParams = {},
|
|
56
|
-
) {
|
|
57
|
-
return (
|
|
58
|
-
!!variables.organizationId && !!emailId && !cachedEmail && !params.skip
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Return one email fragment cache key.
|
|
64
|
-
*/
|
|
65
|
-
function getEmailFragmentKey(fragmentName: string, emailId: string) {
|
|
66
|
-
return `$${fragmentName}:${emailId}`;
|
|
67
|
-
}
|
|
11
|
+
const EMAIL_MESSAGES_LIST_LIMIT = 250;
|
|
68
12
|
|
|
69
13
|
/*
|
|
70
|
-
* Fetch one inbound email.
|
|
14
|
+
* Fetch one inbound or outbound email message.
|
|
71
15
|
*/
|
|
72
16
|
|
|
73
|
-
export function
|
|
17
|
+
export function useEmailMessage(
|
|
74
18
|
variables: {
|
|
75
19
|
organizationId?: string | null;
|
|
76
|
-
|
|
20
|
+
emailMessageId?: string | null;
|
|
77
21
|
},
|
|
78
22
|
params: UseQueryParams = {},
|
|
79
23
|
) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const shouldFetchInboundEmail = shouldFetchEmailRecord(
|
|
85
|
-
variables,
|
|
86
|
-
variables.inboundEmailId,
|
|
87
|
-
cachedInboundEmail,
|
|
88
|
-
params,
|
|
89
|
-
);
|
|
90
|
-
const { data, ...rest } = useQuery(inboundEmailQry, {
|
|
24
|
+
const skip = !variables.organizationId || !variables.emailMessageId || !!params.skip;
|
|
25
|
+
const cachedEmailMessage = useReactiveEmailMessageFragment(variables.emailMessageId || '', null);
|
|
26
|
+
// Reuse the cached modal request; a list fragment alone still needs its details and conversation.
|
|
27
|
+
const { data, ...rest } = useQuery(emailMessageQry, {
|
|
91
28
|
...params,
|
|
29
|
+
revalidateOnMount: params.revalidateOnMount ?? false,
|
|
92
30
|
variables,
|
|
93
|
-
skip
|
|
31
|
+
skip,
|
|
94
32
|
});
|
|
95
|
-
|
|
33
|
+
const currentData = rest.queryKey === `#${rest.queryName}:${rest.variablesKey}` ? data : null;
|
|
34
|
+
const record =
|
|
35
|
+
currentData?.emailMessage === null
|
|
36
|
+
? null
|
|
37
|
+
: getScopedEmailRecord<EmailMessageGQL>(currentData?.emailMessage, variables.organizationId, variables.emailMessageId, skip) ||
|
|
38
|
+
getScopedEmailRecord<EmailMessageGQL>(cachedEmailMessage, variables.organizationId, variables.emailMessageId, skip);
|
|
39
|
+
|
|
40
|
+
const emailMessage = record && { ...record, ...record.details };
|
|
96
41
|
return {
|
|
97
|
-
|
|
98
|
-
initialLoading:
|
|
42
|
+
emailMessage,
|
|
43
|
+
initialLoading: !skip && !emailMessage && !rest.error && currentData?.emailMessage === undefined,
|
|
99
44
|
...rest,
|
|
100
45
|
};
|
|
101
46
|
}
|
|
102
47
|
|
|
103
48
|
/**
|
|
104
|
-
* Fetch inbound
|
|
49
|
+
* Fetch inbound and outbound email messages as one list.
|
|
105
50
|
*/
|
|
106
51
|
|
|
107
|
-
export function
|
|
52
|
+
export function useEmailMessages(
|
|
108
53
|
variables: PaginationArgs & {
|
|
109
54
|
organizationId?: string | null;
|
|
110
|
-
filter?:
|
|
111
|
-
sort?:
|
|
55
|
+
filter?: EmailMessagesFilterInput | null;
|
|
56
|
+
sort?: EmailMessagesSortEnum | null;
|
|
112
57
|
},
|
|
113
58
|
params: UseQueryParams = {},
|
|
114
59
|
) {
|
|
115
|
-
const { data, ...rest } = useQuery(
|
|
60
|
+
const { data, ...rest } = useQuery(emailMessagesQry, {
|
|
116
61
|
...params,
|
|
117
62
|
variables: {
|
|
118
63
|
...variables,
|
|
119
|
-
filter:
|
|
120
|
-
cursor: null,
|
|
121
|
-
after: true,
|
|
122
|
-
limit:
|
|
64
|
+
filter: normalizeEmailMessagesFilter(variables.filter),
|
|
65
|
+
cursor: variables.cursor ?? null,
|
|
66
|
+
after: variables.after ?? true,
|
|
67
|
+
limit: variables.limit ?? EMAIL_MESSAGES_LIST_LIMIT,
|
|
123
68
|
},
|
|
124
69
|
skip: !variables.organizationId || params.skip,
|
|
125
70
|
});
|
|
126
71
|
|
|
127
72
|
return {
|
|
128
|
-
|
|
73
|
+
emailMessages: data?.emailMessages,
|
|
129
74
|
...rest,
|
|
130
75
|
};
|
|
131
76
|
}
|
|
132
77
|
|
|
133
|
-
|
|
134
|
-
*
|
|
78
|
+
/**
|
|
79
|
+
* Get reactive email message fragment.
|
|
135
80
|
*/
|
|
136
81
|
|
|
137
|
-
export function
|
|
138
|
-
|
|
139
|
-
organizationId?: string | null;
|
|
140
|
-
outboundEmailId?: string | null;
|
|
141
|
-
},
|
|
142
|
-
params: UseQueryParams = {},
|
|
143
|
-
) {
|
|
144
|
-
const cachedOutboundEmail = useReactiveOutboundEmailFragment(
|
|
145
|
-
variables.outboundEmailId || '',
|
|
146
|
-
null,
|
|
147
|
-
);
|
|
148
|
-
const shouldFetchOutboundEmail = shouldFetchEmailRecord(
|
|
149
|
-
variables,
|
|
150
|
-
variables.outboundEmailId,
|
|
151
|
-
cachedOutboundEmail,
|
|
152
|
-
params,
|
|
153
|
-
);
|
|
154
|
-
const { data, ...rest } = useQuery(outboundEmailQry, {
|
|
155
|
-
...params,
|
|
156
|
-
variables,
|
|
157
|
-
skip: !shouldFetchOutboundEmail,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
outboundEmail: cachedOutboundEmail || data?.outboundEmail,
|
|
162
|
-
initialLoading: shouldFetchOutboundEmail && !data,
|
|
163
|
-
...rest,
|
|
164
|
-
};
|
|
82
|
+
export function useReactiveEmailMessageFragment(emailMessageId: string, currentData?: any, queryCount?: number) {
|
|
83
|
+
return useReactiveFragment(currentData, [`$emailMessageFragment:${emailMessageId}`], queryCount);
|
|
165
84
|
}
|
|
166
85
|
|
|
167
|
-
|
|
168
|
-
*
|
|
86
|
+
/*
|
|
87
|
+
* Read a continuation of the open conversation without fetching the selected message's details again.
|
|
169
88
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
organizationId?: string | null;
|
|
174
|
-
filter?: EmailListFilter;
|
|
175
|
-
sort?: OutboundEmailsSortEnum | null;
|
|
176
|
-
},
|
|
177
|
-
params: UseQueryParams = {},
|
|
178
|
-
) {
|
|
179
|
-
const { data, ...rest } = useQuery(outboundEmailsQry, {
|
|
180
|
-
...params,
|
|
181
|
-
variables: {
|
|
182
|
-
...variables,
|
|
183
|
-
filter: normalizeEmailsFilter(variables.filter),
|
|
184
|
-
cursor: null,
|
|
185
|
-
after: true,
|
|
186
|
-
limit: EMAILS_LIST_LIMIT,
|
|
187
|
-
},
|
|
188
|
-
skip: !variables.organizationId || params.skip,
|
|
189
|
-
});
|
|
190
|
-
|
|
89
|
+
export function useEmailMessageConversationPage(variables: { organizationId: string; emailMessageId: string; cursor: string }) {
|
|
90
|
+
const { data, ...rest } = useQuery(emailMessageConversationPageQry, { variables, revalidateOnMount: false });
|
|
91
|
+
const current = rest.queryKey === `#${rest.queryName}:${rest.variablesKey}` ? data?.emailMessageConversationPage : null;
|
|
191
92
|
return {
|
|
192
|
-
|
|
93
|
+
conversation: getScopedEmailRecord<EmailMessageGQL>(current, variables.organizationId, variables.emailMessageId, false)
|
|
94
|
+
?.conversation,
|
|
193
95
|
...rest,
|
|
194
96
|
};
|
|
195
97
|
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Get reactive inbound email fragment.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
export function useReactiveInboundEmailFragment(
|
|
202
|
-
inboundEmailId: string,
|
|
203
|
-
currentData?: any,
|
|
204
|
-
queryCount?: number,
|
|
205
|
-
) {
|
|
206
|
-
return useReactiveFragment(
|
|
207
|
-
currentData,
|
|
208
|
-
[getEmailFragmentKey('inboundEmailFragment', inboundEmailId)],
|
|
209
|
-
queryCount,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Get reactive outbound email fragment.
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
export function useReactiveOutboundEmailFragment(
|
|
218
|
-
outboundEmailId: string,
|
|
219
|
-
currentData?: any,
|
|
220
|
-
queryCount?: number,
|
|
221
|
-
) {
|
|
222
|
-
return useReactiveFragment(
|
|
223
|
-
currentData,
|
|
224
|
-
[getEmailFragmentKey('outboundEmailFragment', outboundEmailId)],
|
|
225
|
-
queryCount,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEmailOutreachDraftMtn,
|
|
3
|
+
editEmailOutreachDraftMtn,
|
|
4
|
+
sendEmailOutreachMtn,
|
|
5
|
+
rescheduleEmailOutreachMtn,
|
|
6
|
+
sendEmailOutreachTestMtn,
|
|
7
|
+
updateEmailOutreachReplyInstructionsMtn,
|
|
8
|
+
duplicateEmailOutreachMtn,
|
|
9
|
+
finalizeEmailOutreachImageUploadMtn,
|
|
10
|
+
} from '../gql/mutations/emailOutreachMutations.ts';
|
|
11
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
12
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
13
|
+
import {
|
|
14
|
+
archiveEmailOutreachMtn,
|
|
15
|
+
cancelEmailOutreachMtn,
|
|
16
|
+
retryEmailOutreachMtn,
|
|
17
|
+
unarchiveEmailOutreachMtn,
|
|
18
|
+
} from '../gql/mutations/emailOutreachMutations.ts';
|
|
19
|
+
import { useMutation } from './index.ts';
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Cancel a SCHEDULED outreach. The input echoes the outreach's deliveryVersion as
|
|
23
|
+
* expectedDeliveryVersion; the full returned record updates the shared fragment.
|
|
24
|
+
*/
|
|
25
|
+
export function useCancelEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
26
|
+
const { onCompleted, ...rest } = params;
|
|
27
|
+
const [cancelEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(cancelEmailOutreachMtn, {
|
|
28
|
+
openModalPopUp,
|
|
29
|
+
/*
|
|
30
|
+
* Unwrap the cancelled outreach for hook consumers.
|
|
31
|
+
*/
|
|
32
|
+
onCompleted: (data, error, variables) => {
|
|
33
|
+
onCompleted?.(data?.cancelEmailOutreach, error, variables);
|
|
34
|
+
},
|
|
35
|
+
...rest,
|
|
36
|
+
});
|
|
37
|
+
return { cancelEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Re-send the definitely failed deliveries of an outreach. The input echoes the
|
|
42
|
+
* outreach's deliveryVersion as expectedDeliveryVersion.
|
|
43
|
+
*/
|
|
44
|
+
export function useRetryEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
45
|
+
const { onCompleted, ...rest } = params;
|
|
46
|
+
const [retryEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(retryEmailOutreachMtn, {
|
|
47
|
+
openModalPopUp,
|
|
48
|
+
/*
|
|
49
|
+
* Unwrap the retried outreach for hook consumers.
|
|
50
|
+
*/
|
|
51
|
+
onCompleted: (data, error, variables) => {
|
|
52
|
+
onCompleted?.(data?.retryEmailOutreach, error, variables);
|
|
53
|
+
},
|
|
54
|
+
...rest,
|
|
55
|
+
});
|
|
56
|
+
return { retryEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Archive one outreach that is not scheduled or sending; archiving twice changes nothing.
|
|
61
|
+
*/
|
|
62
|
+
export function useArchiveEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
63
|
+
const { onCompleted, ...rest } = params;
|
|
64
|
+
const [archiveEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(archiveEmailOutreachMtn, {
|
|
65
|
+
openModalPopUp,
|
|
66
|
+
/*
|
|
67
|
+
* Unwrap the archived outreach for hook consumers.
|
|
68
|
+
*/
|
|
69
|
+
onCompleted: (data, error, variables) => {
|
|
70
|
+
onCompleted?.(data?.archiveEmailOutreach, error, variables);
|
|
71
|
+
},
|
|
72
|
+
...rest,
|
|
73
|
+
});
|
|
74
|
+
return { archiveEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
* Restore one archived outreach; restoring a current outreach changes nothing.
|
|
79
|
+
*/
|
|
80
|
+
export function useUnarchiveEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
81
|
+
const { onCompleted, ...rest } = params;
|
|
82
|
+
const [unarchiveEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(unarchiveEmailOutreachMtn, {
|
|
83
|
+
openModalPopUp,
|
|
84
|
+
/*
|
|
85
|
+
* Unwrap the restored outreach for hook consumers.
|
|
86
|
+
*/
|
|
87
|
+
onCompleted: (data, error, variables) => {
|
|
88
|
+
onCompleted?.(data?.unarchiveEmailOutreach, error, variables);
|
|
89
|
+
},
|
|
90
|
+
...rest,
|
|
91
|
+
});
|
|
92
|
+
return { unarchiveEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Create an incomplete editor draft. */
|
|
96
|
+
export function useCreateEmailOutreachDraft(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
97
|
+
const { onCompleted, ...rest } = params;
|
|
98
|
+
const [createEmailOutreachDraft, mtnValues, mtnHandlers, updateObservers] = useMutation(createEmailOutreachDraftMtn, {
|
|
99
|
+
openModalPopUp,
|
|
100
|
+
/* Return the shared record from the mutation response. */
|
|
101
|
+
onCompleted: (data, error, variables) => {
|
|
102
|
+
onCompleted?.(data?.createEmailOutreachDraft, error, variables);
|
|
103
|
+
},
|
|
104
|
+
...rest,
|
|
105
|
+
});
|
|
106
|
+
return { createEmailOutreachDraft, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Save the whole document under its acknowledged edit version. */
|
|
110
|
+
export function useEditEmailOutreachDraft(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
111
|
+
const { onCompleted, ...rest } = params;
|
|
112
|
+
const [editEmailOutreachDraft, mtnValues, mtnHandlers, updateObservers] = useMutation(editEmailOutreachDraftMtn, {
|
|
113
|
+
openModalPopUp,
|
|
114
|
+
/* Return the shared record from the mutation response. */
|
|
115
|
+
onCompleted: (data, error, variables) => {
|
|
116
|
+
onCompleted?.(data?.editEmailOutreachDraft, error, variables);
|
|
117
|
+
},
|
|
118
|
+
...rest,
|
|
119
|
+
});
|
|
120
|
+
return { editEmailOutreachDraft, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Approve and send the exact draft version shown in the editor. */
|
|
124
|
+
export function useSendEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
125
|
+
const { onCompleted, ...rest } = params;
|
|
126
|
+
const [sendEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(sendEmailOutreachMtn, {
|
|
127
|
+
openModalPopUp,
|
|
128
|
+
/* Return the shared record from the mutation response. */
|
|
129
|
+
onCompleted: (data, error, variables) => {
|
|
130
|
+
onCompleted?.(data?.sendEmailOutreach, error, variables);
|
|
131
|
+
},
|
|
132
|
+
...rest,
|
|
133
|
+
});
|
|
134
|
+
return { sendEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* Move a scheduled send under its delivery version fence. */
|
|
138
|
+
export function useRescheduleEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
139
|
+
const { onCompleted, ...rest } = params;
|
|
140
|
+
const [rescheduleEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(rescheduleEmailOutreachMtn, {
|
|
141
|
+
openModalPopUp,
|
|
142
|
+
/* Return the shared record from the mutation response. */
|
|
143
|
+
onCompleted: (data, error, variables) => {
|
|
144
|
+
onCompleted?.(data?.rescheduleEmailOutreach, error, variables);
|
|
145
|
+
},
|
|
146
|
+
...rest,
|
|
147
|
+
});
|
|
148
|
+
return { rescheduleEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Send a saved preview to the verified requester or an authorized organization member. */
|
|
152
|
+
export function useSendEmailOutreachTest(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
153
|
+
const { onCompleted, ...rest } = params;
|
|
154
|
+
const [sendEmailOutreachTest, mtnValues, mtnHandlers, updateObservers] = useMutation(sendEmailOutreachTestMtn, {
|
|
155
|
+
openModalPopUp,
|
|
156
|
+
/* Return the shared record from the mutation response. */
|
|
157
|
+
onCompleted: (data, error, variables) => {
|
|
158
|
+
onCompleted?.(data?.sendEmailOutreachTest, error, variables);
|
|
159
|
+
},
|
|
160
|
+
...rest,
|
|
161
|
+
});
|
|
162
|
+
return { sendEmailOutreachTest, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* Update reply handling while preserving sent content. */
|
|
166
|
+
export function useUpdateEmailOutreachReplyInstructions(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
167
|
+
const { onCompleted, ...rest } = params;
|
|
168
|
+
const [updateEmailOutreachReplyInstructions, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
169
|
+
updateEmailOutreachReplyInstructionsMtn,
|
|
170
|
+
{
|
|
171
|
+
openModalPopUp,
|
|
172
|
+
/* Return the shared record from the mutation response. */
|
|
173
|
+
onCompleted: (data, error, variables) => {
|
|
174
|
+
onCompleted?.(data?.updateEmailOutreachReplyInstructions, error, variables);
|
|
175
|
+
},
|
|
176
|
+
...rest,
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
return { updateEmailOutreachReplyInstructions, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Copy an outreach into a new unscheduled draft. */
|
|
183
|
+
export function useDuplicateEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
184
|
+
const { onCompleted, ...rest } = params;
|
|
185
|
+
const [duplicateEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(duplicateEmailOutreachMtn, {
|
|
186
|
+
openModalPopUp,
|
|
187
|
+
/* Return the shared record from the mutation response. */
|
|
188
|
+
onCompleted: (data, error, variables) => {
|
|
189
|
+
onCompleted?.(data?.duplicateEmailOutreach, error, variables);
|
|
190
|
+
},
|
|
191
|
+
...rest,
|
|
192
|
+
});
|
|
193
|
+
return { duplicateEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* Finalize a browser image upload before attaching it to the editor. */
|
|
197
|
+
export function useFinalizeEmailOutreachImageUpload(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
198
|
+
const { onCompleted, ...rest } = params;
|
|
199
|
+
const [finalizeEmailOutreachImageUpload, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
200
|
+
finalizeEmailOutreachImageUploadMtn,
|
|
201
|
+
{
|
|
202
|
+
openModalPopUp,
|
|
203
|
+
/* Return the shared record from the mutation response. */
|
|
204
|
+
onCompleted: (data, error, variables) => {
|
|
205
|
+
onCompleted?.(data?.finalizeEmailOutreachImageUpload, error, variables);
|
|
206
|
+
},
|
|
207
|
+
...rest,
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
return { finalizeEmailOutreachImageUpload, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
211
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Keep outreach data scoped to the active organization, outreach and filters while
|
|
3
|
+
* the shared query client retains an earlier response during navigation.
|
|
4
|
+
*/
|
|
5
|
+
export function getEmailOutreachQueryData<T>(
|
|
6
|
+
result: {
|
|
7
|
+
data?: T | null;
|
|
8
|
+
queryKey: string;
|
|
9
|
+
queryName: string;
|
|
10
|
+
variablesKey: string;
|
|
11
|
+
},
|
|
12
|
+
skipped: boolean,
|
|
13
|
+
): T | null {
|
|
14
|
+
return !skipped && result.queryKey === `#${result.queryName}:${result.variablesKey}` ? (result.data ?? null) : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Return only the requested outreach; its owning organization remains available to the page's login guard.
|
|
19
|
+
*/
|
|
20
|
+
export function getScopedEmailOutreach<T extends { id: string }>(
|
|
21
|
+
outreach: T | null | undefined,
|
|
22
|
+
emailOutreachId: string | null | undefined,
|
|
23
|
+
): T | null {
|
|
24
|
+
return emailOutreachId && outreach?.id === emailOutreachId ? outreach : null;
|
|
25
|
+
}
|