@jsb188/graphql 1.1.10 → 1.1.12
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/audience.d.ts +343 -0
- package/cache/config.ts +98 -50
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +1017 -127
- package/cache/index.ts +1256 -1269
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +800 -0
- package/cache/store.ts +395 -0
- package/cache/value.helpers.ts +17 -0
- package/client/draft-persistence-indexed-db.ts +413 -0
- package/client/draft-persistence.ts +152 -0
- package/client/index.ts +3 -0
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +870 -164
- package/deno.lock +187 -0
- package/deno.test.json +10 -4
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentMemoryFragments.ts +23 -0
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +42 -0
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +566 -0
- package/gql/fragments/dataTableFragments.ts +50 -192
- package/gql/fragments/emailFragments.ts +32 -17
- package/gql/fragments/fieldDocFragments.ts +264 -0
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +101 -69
- package/gql/fragments/organizationFragments.ts +53 -5
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +667 -0
- package/gql/fragments/sheetFragments.ts +304 -63
- package/gql/fragments/storageFragments.ts +45 -0
- package/gql/fragments/workflowFragments.ts +41 -5
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentMemoryMutations.ts +68 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +49 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +203 -18
- package/gql/mutations/billingMutations.ts +17 -27
- package/gql/mutations/campaignMutations.ts +258 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +19 -54
- package/gql/mutations/fieldDocMutations.ts +173 -0
- package/gql/mutations/index.ts +10 -2
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +19 -4
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1121 -0
- package/gql/mutations/sheetMutations.ts +221 -60
- package/gql/mutations/storageMutations.ts +19 -0
- package/gql/mutations/workflowMutations.ts +60 -0
- package/gql/queries/agentMemoryQueries.ts +28 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +70 -2
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +47 -0
- package/gql/queries/billingQueries.ts +118 -6
- package/gql/queries/campaignQueries.ts +236 -0
- package/gql/queries/dataTableQueries.ts +61 -13
- package/gql/queries/emailQueries.ts +26 -17
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +166 -0
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +10 -2
- package/gql/queries/logQueries.ts +68 -30
- package/gql/queries/organizationQueries.ts +65 -1
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +691 -0
- package/gql/queries/sheetQueries.ts +244 -26
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +77 -2
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +2254 -982
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentMemory-mtn.ts +71 -0
- package/hooks/use-agentMemory-qry.ts +56 -0
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +220 -141
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +341 -237
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +435 -252
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +436 -0
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +834 -0
- package/hooks/use-dataTable-mtn.ts +37 -46
- package/hooks/use-dataTable-qry.ts +102 -128
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +56 -86
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +262 -0
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +212 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +62 -56
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +88 -59
- package/hooks/use-log-qry.ts +150 -73
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +155 -129
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +589 -0
- package/hooks/use-schedule-qry.ts +738 -0
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +157 -79
- package/hooks/use-sheet-qry.ts +221 -92
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +128 -14
- package/hooks/use-workflow-mtn.ts +72 -0
- package/hooks/use-workflow-qry.ts +184 -47
- 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/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/libs/request-managed-session.test.ts +574 -0
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/libs/sse-ticket.test.ts +26 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +110 -0
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +119 -71
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +70 -106
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/tsconfig.json +11 -10
- package/types.d.ts +77 -26
- package/utils.ts +78 -49
- package/gql/fragments/billingFragments.ts +0 -25
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
import { CAMPAIGN_GENERATION_PROGRESS_STAGES } from '@jsb188/mday/constants/campaign.ts';
|
|
2
|
+
import {
|
|
3
|
+
FRAGMENT_NAMES,
|
|
4
|
+
getFragmentBaseName,
|
|
5
|
+
makeFragmentKey,
|
|
6
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
7
|
+
import type {
|
|
8
|
+
CampaignEditSessionGQL,
|
|
9
|
+
CampaignGQL,
|
|
10
|
+
CampaignRecipientGQL,
|
|
11
|
+
CampaignRecipientOverviewGQL,
|
|
12
|
+
CampaignRecipientsFilterArgs,
|
|
13
|
+
CampaignResponsesFilterArgs,
|
|
14
|
+
CampaignSummaryGQL,
|
|
15
|
+
CampaignsFilterArgs,
|
|
16
|
+
CampaignsSortEnum,
|
|
17
|
+
CampaignTemplatesFilterArgs,
|
|
18
|
+
SystemCampaignTemplatesFilterArgs,
|
|
19
|
+
} from '@jsb188/mday/types/campaign.d.ts';
|
|
20
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
21
|
+
import {
|
|
22
|
+
useQuery,
|
|
23
|
+
useReactiveFragment,
|
|
24
|
+
useReactiveFragmentMap,
|
|
25
|
+
} from '../client/index.ts';
|
|
26
|
+
import {
|
|
27
|
+
campaignEditSessionQry,
|
|
28
|
+
campaignFormAccessSessionQry,
|
|
29
|
+
campaignRecipientOverviewQry,
|
|
30
|
+
campaignRecipientsQry,
|
|
31
|
+
campaignResponseOverviewQry,
|
|
32
|
+
campaignResponseQry,
|
|
33
|
+
campaignResponsesQry,
|
|
34
|
+
campaignsQry,
|
|
35
|
+
campaignTemplateEditSessionQry,
|
|
36
|
+
campaignTemplatesQry,
|
|
37
|
+
systemCampaignTemplatesQry,
|
|
38
|
+
} from '../gql/queries/campaignQueries.ts';
|
|
39
|
+
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
40
|
+
import { isTransientServerError } from '../utils.ts';
|
|
41
|
+
import {
|
|
42
|
+
applyCampaignArchive,
|
|
43
|
+
getCampaignQueryData,
|
|
44
|
+
} from './use-campaign-qry.helpers.ts';
|
|
45
|
+
import { useCampaignGenerationRecovery } from './use-campaign-generation-recovery.ts';
|
|
46
|
+
|
|
47
|
+
const FILE_CONSTANTS = {
|
|
48
|
+
campaignListsLimit: 100,
|
|
49
|
+
// Fixed first-page size for every campaigns list query; see useCampaigns().
|
|
50
|
+
campaignsLimit: 100,
|
|
51
|
+
campaignPeopleListLimit: 250,
|
|
52
|
+
emptyPublicFormCampaigns: [] as CampaignSummaryGQL[],
|
|
53
|
+
publicFormPickerFilter: {
|
|
54
|
+
archived: false,
|
|
55
|
+
kind: 'PUBLIC_FORM',
|
|
56
|
+
} as CampaignsFilterArgs,
|
|
57
|
+
generationProgressStages: new Set<unknown>(
|
|
58
|
+
CAMPAIGN_GENERATION_PROGRESS_STAGES,
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
interface PublicFormCampaignPickerPageState {
|
|
63
|
+
campaigns: CampaignSummaryGQL[];
|
|
64
|
+
queryKey: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Recover missed campaign events after reconnecting without remounting the editor.
|
|
69
|
+
* An HTTP snapshot fetched before the first socket connection can also miss events.
|
|
70
|
+
* Retain recovery while skipped so resuming the same session cannot serve stale data.
|
|
71
|
+
*/
|
|
72
|
+
function useCampaignSessionReconnect(
|
|
73
|
+
connected: boolean,
|
|
74
|
+
refetch: () => Promise<unknown>,
|
|
75
|
+
enabled: boolean,
|
|
76
|
+
) {
|
|
77
|
+
const connection = useRef({ connected, refreshPending: false });
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const previous = connection.current;
|
|
80
|
+
const refreshPending =
|
|
81
|
+
previous.refreshPending || (connected && !previous.connected);
|
|
82
|
+
connection.current = { connected, refreshPending };
|
|
83
|
+
if (enabled && connected && refreshPending) {
|
|
84
|
+
connection.current.refreshPending = false;
|
|
85
|
+
void refetch().catch(() => {
|
|
86
|
+
// Query state owns the load error; do not create an unhandled reconnect rejection.
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}, [connected, enabled, refetch]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Overlay transient generation progress and archive tombstones onto one atomic campaign editor
|
|
94
|
+
* session. Core fields such as editVersion must remain from the same query
|
|
95
|
+
* response as the editor definition or a stale tree could be saved under a
|
|
96
|
+
* newer revision.
|
|
97
|
+
*/
|
|
98
|
+
export function getCampaignEditSessionWithProgress(
|
|
99
|
+
querySession: CampaignEditSessionGQL | null | undefined,
|
|
100
|
+
reactiveCampaign:
|
|
101
|
+
| Pick<
|
|
102
|
+
CampaignGQL,
|
|
103
|
+
| 'id'
|
|
104
|
+
| 'generationProgress'
|
|
105
|
+
| 'generationProgressStage'
|
|
106
|
+
| '__deleted'
|
|
107
|
+
| 'archivedAt'
|
|
108
|
+
>
|
|
109
|
+
| null
|
|
110
|
+
| undefined,
|
|
111
|
+
) {
|
|
112
|
+
// Archive packets carry no revision or definition; safely lock this existing session without a refetch.
|
|
113
|
+
if (
|
|
114
|
+
querySession?.campaign &&
|
|
115
|
+
reactiveCampaign?.__deleted &&
|
|
116
|
+
querySession.campaign.id === reactiveCampaign.id
|
|
117
|
+
) {
|
|
118
|
+
querySession = {
|
|
119
|
+
...querySession,
|
|
120
|
+
campaign: applyCampaignArchive(querySession.campaign, reactiveCampaign)!,
|
|
121
|
+
editable: false,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const hasProgress =
|
|
125
|
+
!!reactiveCampaign && Object.hasOwn(reactiveCampaign, 'generationProgress');
|
|
126
|
+
const hasProgressStage =
|
|
127
|
+
!!reactiveCampaign &&
|
|
128
|
+
Object.hasOwn(reactiveCampaign, 'generationProgressStage');
|
|
129
|
+
const progressIsValid =
|
|
130
|
+
hasProgress &&
|
|
131
|
+
(reactiveCampaign.generationProgress === null ||
|
|
132
|
+
typeof reactiveCampaign.generationProgress === 'string');
|
|
133
|
+
const progressStageIsValid =
|
|
134
|
+
hasProgressStage &&
|
|
135
|
+
(reactiveCampaign.generationProgressStage === null ||
|
|
136
|
+
FILE_CONSTANTS.generationProgressStages.has(
|
|
137
|
+
reactiveCampaign.generationProgressStage,
|
|
138
|
+
));
|
|
139
|
+
if (
|
|
140
|
+
!querySession?.campaign ||
|
|
141
|
+
!reactiveCampaign ||
|
|
142
|
+
String(querySession.campaign.id) !== String(reactiveCampaign.id) ||
|
|
143
|
+
(!progressIsValid && !progressStageIsValid) ||
|
|
144
|
+
(querySession.campaign.generationProgress ===
|
|
145
|
+
reactiveCampaign.generationProgress &&
|
|
146
|
+
querySession.campaign.generationProgressStage ===
|
|
147
|
+
reactiveCampaign.generationProgressStage)
|
|
148
|
+
) {
|
|
149
|
+
return querySession;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
...querySession,
|
|
154
|
+
campaign: {
|
|
155
|
+
...querySession.campaign,
|
|
156
|
+
...(progressIsValid
|
|
157
|
+
? { generationProgress: reactiveCampaign.generationProgress }
|
|
158
|
+
: {}),
|
|
159
|
+
...(progressStageIsValid
|
|
160
|
+
? { generationProgressStage: reactiveCampaign.generationProgressStage }
|
|
161
|
+
: {}),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Fetch one organization's campaign templates.
|
|
168
|
+
*
|
|
169
|
+
* Archived templates are excluded server-side unless explicitly requested, so
|
|
170
|
+
* the default list is the active reusable-template working set.
|
|
171
|
+
*/
|
|
172
|
+
export function useCampaignTemplates(
|
|
173
|
+
variables: PaginationArgs & {
|
|
174
|
+
organizationId?: string | null;
|
|
175
|
+
filter?: CampaignTemplatesFilterArgs;
|
|
176
|
+
},
|
|
177
|
+
params: UseQueryParams = {},
|
|
178
|
+
) {
|
|
179
|
+
const { data, ...rest } = useQuery(campaignTemplatesQry, {
|
|
180
|
+
...params,
|
|
181
|
+
variables: {
|
|
182
|
+
...variables,
|
|
183
|
+
filter: variables.filter || {},
|
|
184
|
+
cursor: variables.cursor ?? null,
|
|
185
|
+
after: true,
|
|
186
|
+
limit: variables.limit ?? FILE_CONSTANTS.campaignListsLimit,
|
|
187
|
+
},
|
|
188
|
+
skip: !variables.organizationId || params.skip,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
campaignTemplates: data?.campaignTemplates,
|
|
193
|
+
...rest,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Fetch every current system template for one kind. The list is small and
|
|
199
|
+
* unpaginated, so one query returns the complete set.
|
|
200
|
+
*/
|
|
201
|
+
export function useSystemCampaignTemplates(
|
|
202
|
+
variables: {
|
|
203
|
+
filter?: SystemCampaignTemplatesFilterArgs;
|
|
204
|
+
},
|
|
205
|
+
params: UseQueryParams = {},
|
|
206
|
+
) {
|
|
207
|
+
const { data, ...rest } = useQuery(systemCampaignTemplatesQry, {
|
|
208
|
+
...params,
|
|
209
|
+
variables: {
|
|
210
|
+
filter: variables.filter || {},
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
systemCampaignTemplates: data?.systemCampaignTemplates,
|
|
216
|
+
...rest,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Fetch one campaign template core and its canonical editor projection.
|
|
222
|
+
*/
|
|
223
|
+
export function useCampaignTemplateEditSession(
|
|
224
|
+
variables: {
|
|
225
|
+
templateId?: string | null;
|
|
226
|
+
},
|
|
227
|
+
params: UseQueryParams = {},
|
|
228
|
+
) {
|
|
229
|
+
const { data, ...rest } = useQuery(campaignTemplateEditSessionQry, {
|
|
230
|
+
retryTransientErrors: true,
|
|
231
|
+
...params,
|
|
232
|
+
variables,
|
|
233
|
+
skip: !variables.templateId || params.skip,
|
|
234
|
+
});
|
|
235
|
+
useCampaignSessionReconnect(
|
|
236
|
+
rest.connectedToServer,
|
|
237
|
+
rest.refetch,
|
|
238
|
+
!params.skip && !!variables.templateId,
|
|
239
|
+
);
|
|
240
|
+
const querySession = data?.campaignTemplateEditSession;
|
|
241
|
+
const reactiveTemplate = useReactiveCampaignTemplateSummaryFragment(
|
|
242
|
+
variables.templateId || '',
|
|
243
|
+
querySession?.template,
|
|
244
|
+
rest.updatedCount,
|
|
245
|
+
);
|
|
246
|
+
// An archive fragment locks the current template without reloading the session or its campaign list.
|
|
247
|
+
const campaignTemplateEditSession =
|
|
248
|
+
querySession?.template && reactiveTemplate?.__deleted
|
|
249
|
+
? {
|
|
250
|
+
...querySession,
|
|
251
|
+
template: applyCampaignArchive(
|
|
252
|
+
querySession.template,
|
|
253
|
+
reactiveTemplate,
|
|
254
|
+
),
|
|
255
|
+
editable: false,
|
|
256
|
+
}
|
|
257
|
+
: querySession;
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
campaignTemplateEditSession,
|
|
261
|
+
editable: Boolean(campaignTemplateEditSession?.editable),
|
|
262
|
+
...rest,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Fetch one organization's campaigns.
|
|
268
|
+
*
|
|
269
|
+
* The limit is fixed to FILE_CONSTANTS.campaignsLimit and must never change or
|
|
270
|
+
* be overridden by callers: the limit is part of the query cache key, so every
|
|
271
|
+
* page (workspace, web forms, email campaigns, pickers) must request the same
|
|
272
|
+
* limit to share one cache entry. Callers that need fewer rows should slice the
|
|
273
|
+
* result client-side; callers that need more should paginate with fetchMore.
|
|
274
|
+
*/
|
|
275
|
+
export function useCampaigns(
|
|
276
|
+
variables: {
|
|
277
|
+
organizationId?: string | null;
|
|
278
|
+
filter: CampaignsFilterArgs;
|
|
279
|
+
sort?: CampaignsSortEnum | null;
|
|
280
|
+
},
|
|
281
|
+
params: UseQueryParams = {},
|
|
282
|
+
) {
|
|
283
|
+
const { organizationId, filter, sort } = variables;
|
|
284
|
+
const { data, ...rest } = useQuery(campaignsQry, {
|
|
285
|
+
...params,
|
|
286
|
+
variables: {
|
|
287
|
+
organizationId,
|
|
288
|
+
filter,
|
|
289
|
+
sort,
|
|
290
|
+
cursor: null,
|
|
291
|
+
after: true,
|
|
292
|
+
limit: FILE_CONSTANTS.campaignsLimit,
|
|
293
|
+
},
|
|
294
|
+
skip: !variables.organizationId || params.skip,
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
campaigns: variables.organizationId ? data?.campaigns : [],
|
|
299
|
+
...rest,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
* Merge one campaign cursor page by id while retaining the server's list order.
|
|
305
|
+
*/
|
|
306
|
+
function mergePublicFormCampaignPickerPages(
|
|
307
|
+
currentCampaigns: CampaignSummaryGQL[],
|
|
308
|
+
nextCampaigns: CampaignSummaryGQL[],
|
|
309
|
+
) {
|
|
310
|
+
const campaignIndexById = new Map(
|
|
311
|
+
currentCampaigns.map((campaign, index) => [campaign.id, index]),
|
|
312
|
+
);
|
|
313
|
+
const campaigns = currentCampaigns.slice();
|
|
314
|
+
|
|
315
|
+
for (const campaign of nextCampaigns) {
|
|
316
|
+
const existingIndex = campaignIndexById.get(campaign.id);
|
|
317
|
+
if (existingIndex === undefined) {
|
|
318
|
+
campaignIndexById.set(campaign.id, campaigns.length);
|
|
319
|
+
campaigns.push(campaign);
|
|
320
|
+
} else {
|
|
321
|
+
campaigns[existingIndex] = campaign;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return campaigns;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* Retain only public-form campaigns in a Sheet source picker page.
|
|
330
|
+
*/
|
|
331
|
+
function filterPublicFormCampaignPickerPage(campaigns: CampaignSummaryGQL[]) {
|
|
332
|
+
return campaigns.filter((campaign) => campaign.kind === 'PUBLIC_FORM');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/*
|
|
336
|
+
* Load every public-form campaign page for a Sheet source picker.
|
|
337
|
+
*/
|
|
338
|
+
export function usePublicFormCampaignsForPicker(
|
|
339
|
+
organizationId?: string | null,
|
|
340
|
+
params: UseQueryParams = {},
|
|
341
|
+
) {
|
|
342
|
+
const filter = FILE_CONSTANTS.publicFormPickerFilter;
|
|
343
|
+
const [pageState, setPageState] = useState<PublicFormCampaignPickerPageState>(
|
|
344
|
+
() => ({
|
|
345
|
+
campaigns: FILE_CONSTANTS.emptyPublicFormCampaigns,
|
|
346
|
+
queryKey: '',
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
const [loadingAllPages, setLoadingAllPages] = useState(false);
|
|
350
|
+
const [paginationError, setPaginationError] = useState<any>(null);
|
|
351
|
+
const [reloadCount, setReloadCount] = useState(0);
|
|
352
|
+
const {
|
|
353
|
+
campaigns: firstPage,
|
|
354
|
+
error,
|
|
355
|
+
fetchMore,
|
|
356
|
+
loading,
|
|
357
|
+
queryKey,
|
|
358
|
+
refetch,
|
|
359
|
+
refreshTime,
|
|
360
|
+
updatedCount,
|
|
361
|
+
variablesKey,
|
|
362
|
+
...rest
|
|
363
|
+
} = useCampaigns(
|
|
364
|
+
{
|
|
365
|
+
filter,
|
|
366
|
+
organizationId,
|
|
367
|
+
},
|
|
368
|
+
params,
|
|
369
|
+
);
|
|
370
|
+
const firstPageRef = useRef<CampaignSummaryGQL[] | null>(null);
|
|
371
|
+
const paginationInProgressRef = useRef(false);
|
|
372
|
+
const firstPageReady = Array.isArray(firstPage);
|
|
373
|
+
firstPageRef.current = firstPageReady ? firstPage : null;
|
|
374
|
+
const pageLoadKey =
|
|
375
|
+
organizationId &&
|
|
376
|
+
firstPageReady &&
|
|
377
|
+
(loading !== true || paginationInProgressRef.current) &&
|
|
378
|
+
queryKey === `#campaigns:${variablesKey}`
|
|
379
|
+
? `${organizationId}:${refreshTime || ''}:${reloadCount}`
|
|
380
|
+
: '';
|
|
381
|
+
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
if (!pageLoadKey || error) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let cancelled = false;
|
|
388
|
+
const requestQueryKey = String(organizationId || '');
|
|
389
|
+
|
|
390
|
+
/*
|
|
391
|
+
* Follow the campaign cursor until the picker has the organization's full list.
|
|
392
|
+
*/
|
|
393
|
+
const loadAllPages = async () => {
|
|
394
|
+
let cursorPage =
|
|
395
|
+
firstPageRef.current || FILE_CONSTANTS.emptyPublicFormCampaigns;
|
|
396
|
+
let mergedCampaigns = filterPublicFormCampaignPickerPage(cursorPage);
|
|
397
|
+
const seenCursors = new Set<string>();
|
|
398
|
+
|
|
399
|
+
paginationInProgressRef.current = true;
|
|
400
|
+
setLoadingAllPages(true);
|
|
401
|
+
setPaginationError(null);
|
|
402
|
+
|
|
403
|
+
try {
|
|
404
|
+
while (cursorPage.length === FILE_CONSTANTS.campaignsLimit) {
|
|
405
|
+
const cursor = String(cursorPage.at(-1)?.cursor || '');
|
|
406
|
+
if (!cursor || seenCursors.has(cursor)) {
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
seenCursors.add(cursor);
|
|
411
|
+
const result = await fetchMore({
|
|
412
|
+
variables: {
|
|
413
|
+
after: true,
|
|
414
|
+
cursor,
|
|
415
|
+
filter,
|
|
416
|
+
limit: FILE_CONSTANTS.campaignsLimit,
|
|
417
|
+
organizationId,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
if (cancelled) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (result?.error) {
|
|
424
|
+
throw result.error;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
cursorPage = (result?.campaigns || []) as CampaignSummaryGQL[];
|
|
428
|
+
mergedCampaigns = mergePublicFormCampaignPickerPages(
|
|
429
|
+
mergedCampaigns,
|
|
430
|
+
filterPublicFormCampaignPickerPage(cursorPage),
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (!cancelled) {
|
|
435
|
+
mergedCampaigns = mergePublicFormCampaignPickerPages(
|
|
436
|
+
filterPublicFormCampaignPickerPage(
|
|
437
|
+
firstPageRef.current || FILE_CONSTANTS.emptyPublicFormCampaigns,
|
|
438
|
+
),
|
|
439
|
+
mergedCampaigns,
|
|
440
|
+
);
|
|
441
|
+
setPageState({
|
|
442
|
+
campaigns: mergedCampaigns,
|
|
443
|
+
queryKey: requestQueryKey,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
} catch (nextError) {
|
|
447
|
+
if (!cancelled) {
|
|
448
|
+
setPaginationError(nextError);
|
|
449
|
+
}
|
|
450
|
+
} finally {
|
|
451
|
+
if (!cancelled) {
|
|
452
|
+
paginationInProgressRef.current = false;
|
|
453
|
+
setLoadingAllPages(false);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
void loadAllPages();
|
|
459
|
+
|
|
460
|
+
return () => {
|
|
461
|
+
cancelled = true;
|
|
462
|
+
paginationInProgressRef.current = false;
|
|
463
|
+
};
|
|
464
|
+
}, [error, fetchMore, filter, organizationId, pageLoadKey]);
|
|
465
|
+
|
|
466
|
+
/*
|
|
467
|
+
* Rebase accumulated pages when a reactive campaign-list reset refreshes page one.
|
|
468
|
+
*/
|
|
469
|
+
useEffect(() => {
|
|
470
|
+
if (!organizationId || !Array.isArray(firstPage)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
setPageState((currentPage) =>
|
|
475
|
+
currentPage.queryKey === String(organizationId)
|
|
476
|
+
? {
|
|
477
|
+
...currentPage,
|
|
478
|
+
campaigns: mergePublicFormCampaignPickerPages(
|
|
479
|
+
filterPublicFormCampaignPickerPage(firstPage),
|
|
480
|
+
currentPage.campaigns,
|
|
481
|
+
),
|
|
482
|
+
}
|
|
483
|
+
: currentPage,
|
|
484
|
+
);
|
|
485
|
+
}, [firstPage, organizationId]);
|
|
486
|
+
|
|
487
|
+
const visibleCampaigns =
|
|
488
|
+
pageState.queryKey === String(organizationId || '')
|
|
489
|
+
? pageState.campaigns
|
|
490
|
+
: null;
|
|
491
|
+
const reactiveCampaigns = useReactiveCampaignFragmentMap(
|
|
492
|
+
visibleCampaigns,
|
|
493
|
+
updatedCount,
|
|
494
|
+
) as CampaignSummaryGQL[] | null;
|
|
495
|
+
const pickerCampaigns = useMemo(
|
|
496
|
+
() =>
|
|
497
|
+
visibleCampaigns
|
|
498
|
+
? filterPublicFormCampaignPickerPage(
|
|
499
|
+
reactiveCampaigns || FILE_CONSTANTS.emptyPublicFormCampaigns,
|
|
500
|
+
)
|
|
501
|
+
: null,
|
|
502
|
+
[reactiveCampaigns, visibleCampaigns],
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
/*
|
|
506
|
+
* Retry the base query and then start a fresh all-pages traversal.
|
|
507
|
+
*/
|
|
508
|
+
const refetchAllPages = useCallback(async () => {
|
|
509
|
+
setPaginationError(null);
|
|
510
|
+
const result = await refetch();
|
|
511
|
+
setReloadCount((count) => count + 1);
|
|
512
|
+
return result;
|
|
513
|
+
}, [refetch]);
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
campaigns: pickerCampaigns,
|
|
517
|
+
error: error || paginationError,
|
|
518
|
+
fetchMore,
|
|
519
|
+
loading: loading === true || loadingAllPages,
|
|
520
|
+
queryKey,
|
|
521
|
+
refetch: refetchAllPages,
|
|
522
|
+
refreshTime,
|
|
523
|
+
updatedCount,
|
|
524
|
+
variablesKey,
|
|
525
|
+
...rest,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Fetch one campaign's core and editor projections in one edit session.
|
|
531
|
+
*/
|
|
532
|
+
export function useCampaignEditSession(
|
|
533
|
+
variables: {
|
|
534
|
+
campaignId?: string | null;
|
|
535
|
+
},
|
|
536
|
+
params: UseQueryParams = {},
|
|
537
|
+
) {
|
|
538
|
+
const { data, refetch, ...rest } = useQuery(campaignEditSessionQry, {
|
|
539
|
+
retryTransientErrors: true,
|
|
540
|
+
...params,
|
|
541
|
+
variables,
|
|
542
|
+
skip: !variables.campaignId || params.skip,
|
|
543
|
+
});
|
|
544
|
+
useCampaignSessionReconnect(
|
|
545
|
+
rest.connectedToServer,
|
|
546
|
+
refetch,
|
|
547
|
+
!params.skip && !!variables.campaignId,
|
|
548
|
+
);
|
|
549
|
+
const querySession = data?.campaignEditSession;
|
|
550
|
+
const reactiveCampaign = useReactiveFragment(
|
|
551
|
+
querySession?.campaign || null,
|
|
552
|
+
variables.campaignId
|
|
553
|
+
? [makeFragmentKey(FRAGMENT_NAMES.campaign, variables.campaignId)]
|
|
554
|
+
: [],
|
|
555
|
+
rest.updatedCount,
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
useCampaignGenerationRecovery({
|
|
559
|
+
campaignId: variables.campaignId,
|
|
560
|
+
enabled:
|
|
561
|
+
!params.skip &&
|
|
562
|
+
!reactiveCampaign?.__deleted &&
|
|
563
|
+
(!rest.error || isTransientServerError(rest.error)),
|
|
564
|
+
generationStatus: querySession?.campaign?.generationStatus,
|
|
565
|
+
reactiveGenerationStatus: reactiveCampaign?.generationStatus,
|
|
566
|
+
refetch,
|
|
567
|
+
});
|
|
568
|
+
const campaignEditSession = useMemo(
|
|
569
|
+
/*
|
|
570
|
+
* Merge progress and archive state while preserving the atomic editor revision.
|
|
571
|
+
*/
|
|
572
|
+
() => getCampaignEditSessionWithProgress(querySession, reactiveCampaign),
|
|
573
|
+
[querySession, reactiveCampaign],
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
return {
|
|
577
|
+
campaignEditSession,
|
|
578
|
+
editable: Boolean(campaignEditSession?.editable),
|
|
579
|
+
manageable: Boolean(campaignEditSession?.manageable),
|
|
580
|
+
refetch,
|
|
581
|
+
...rest,
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/*
|
|
586
|
+
* Fetch one public-form campaign's current grant overrides and organization
|
|
587
|
+
* picker targets without attaching them to every campaign fragment.
|
|
588
|
+
*/
|
|
589
|
+
export function useCampaignFormAccessSession(
|
|
590
|
+
variables: {
|
|
591
|
+
campaignId?: string | null;
|
|
592
|
+
organizationId?: string | null;
|
|
593
|
+
},
|
|
594
|
+
params: UseQueryParams = {},
|
|
595
|
+
) {
|
|
596
|
+
const { data, ...rest } = useQuery(campaignFormAccessSessionQry, {
|
|
597
|
+
...params,
|
|
598
|
+
variables,
|
|
599
|
+
skip: !variables.organizationId || !variables.campaignId || params.skip,
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
useCampaignSessionReconnect(
|
|
603
|
+
rest.connectedToServer,
|
|
604
|
+
rest.refetch,
|
|
605
|
+
!params.skip && !!variables.organizationId && !!variables.campaignId,
|
|
606
|
+
);
|
|
607
|
+
|
|
608
|
+
return {
|
|
609
|
+
campaignFormAccessSession: data?.campaignFormAccessSession || null,
|
|
610
|
+
...rest,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Fetch one campaign's responses for the organization side.
|
|
616
|
+
*/
|
|
617
|
+
export function useCampaignResponses(
|
|
618
|
+
variables: {
|
|
619
|
+
organizationId?: string | null;
|
|
620
|
+
filter: CampaignResponsesFilterArgs;
|
|
621
|
+
} & PaginationArgs,
|
|
622
|
+
params: UseQueryParams = {},
|
|
623
|
+
) {
|
|
624
|
+
const { data, ...rest } = useQuery(campaignResponsesQry, {
|
|
625
|
+
...params,
|
|
626
|
+
variables: {
|
|
627
|
+
...variables,
|
|
628
|
+
cursor: null,
|
|
629
|
+
after: true,
|
|
630
|
+
limit: variables.limit ?? FILE_CONSTANTS.campaignPeopleListLimit,
|
|
631
|
+
},
|
|
632
|
+
skip:
|
|
633
|
+
!variables.organizationId || !variables.filter.campaignId || params.skip,
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
return {
|
|
637
|
+
campaignResponses: data?.campaignResponses,
|
|
638
|
+
...rest,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Fetch one complete campaign response for the detail modal.
|
|
644
|
+
*/
|
|
645
|
+
export function useCampaignResponse(
|
|
646
|
+
variables: {
|
|
647
|
+
organizationId?: string | null;
|
|
648
|
+
responseId?: string | null;
|
|
649
|
+
},
|
|
650
|
+
params: UseQueryParams = {},
|
|
651
|
+
) {
|
|
652
|
+
const { data, ...rest } = useQuery(campaignResponseQry, {
|
|
653
|
+
...params,
|
|
654
|
+
variables,
|
|
655
|
+
skip: !variables.organizationId || !variables.responseId || params.skip,
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
return {
|
|
659
|
+
campaignResponse: data?.campaignResponse || null,
|
|
660
|
+
...rest,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/*
|
|
665
|
+
* Fetch one public-form campaign's aggregate response overview.
|
|
666
|
+
*/
|
|
667
|
+
export function useCampaignResponsesOverview(
|
|
668
|
+
variables: {
|
|
669
|
+
organizationId?: string | null;
|
|
670
|
+
campaignId?: string | null;
|
|
671
|
+
},
|
|
672
|
+
params: UseQueryParams = {},
|
|
673
|
+
) {
|
|
674
|
+
const { data, ...rest } = useQuery(campaignResponseOverviewQry, {
|
|
675
|
+
...params,
|
|
676
|
+
variables,
|
|
677
|
+
skip: !variables.organizationId || !variables.campaignId || params.skip,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
return {
|
|
681
|
+
campaignResponsesOverview: data?.campaignResponseOverview || null,
|
|
682
|
+
...rest,
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Fetch one email campaign's recipient snapshots.
|
|
688
|
+
*/
|
|
689
|
+
export function useCampaignRecipients(
|
|
690
|
+
variables: {
|
|
691
|
+
organizationId?: string | null;
|
|
692
|
+
filter: CampaignRecipientsFilterArgs;
|
|
693
|
+
} & PaginationArgs,
|
|
694
|
+
params: UseQueryParams = {},
|
|
695
|
+
) {
|
|
696
|
+
const skipped =
|
|
697
|
+
!variables.organizationId || !variables.filter.campaignId || !!params.skip;
|
|
698
|
+
const { data, ...rest } = useQuery(campaignRecipientsQry, {
|
|
699
|
+
...params,
|
|
700
|
+
variables: {
|
|
701
|
+
...variables,
|
|
702
|
+
cursor: variables.cursor ?? null,
|
|
703
|
+
after: variables.after ?? true,
|
|
704
|
+
limit: variables.limit ?? FILE_CONSTANTS.campaignPeopleListLimit,
|
|
705
|
+
},
|
|
706
|
+
skip: skipped,
|
|
707
|
+
});
|
|
708
|
+
const currentData = getCampaignQueryData({ data, ...rest }, skipped);
|
|
709
|
+
|
|
710
|
+
return {
|
|
711
|
+
campaignRecipients: (currentData?.campaignRecipients ?? null) as
|
|
712
|
+
| CampaignRecipientGQL[]
|
|
713
|
+
| null,
|
|
714
|
+
...rest,
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/*
|
|
719
|
+
* Fetch one email campaign's aggregate delivery and engagement overview.
|
|
720
|
+
*/
|
|
721
|
+
export function useCampaignRecipientOverview(
|
|
722
|
+
variables: {
|
|
723
|
+
organizationId?: string | null;
|
|
724
|
+
campaignId?: string | null;
|
|
725
|
+
},
|
|
726
|
+
params: UseQueryParams = {},
|
|
727
|
+
) {
|
|
728
|
+
const skipped =
|
|
729
|
+
!variables.organizationId || !variables.campaignId || !!params.skip;
|
|
730
|
+
const { data, ...rest } = useQuery(campaignRecipientOverviewQry, {
|
|
731
|
+
...params,
|
|
732
|
+
variables,
|
|
733
|
+
skip: skipped,
|
|
734
|
+
});
|
|
735
|
+
const currentData = getCampaignQueryData({ data, ...rest }, skipped);
|
|
736
|
+
|
|
737
|
+
return {
|
|
738
|
+
campaignRecipientOverview: (currentData?.campaignRecipientOverview ??
|
|
739
|
+
null) as CampaignRecipientOverviewGQL | null,
|
|
740
|
+
...rest,
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Read one template list row through the reactive fragment cache.
|
|
746
|
+
*/
|
|
747
|
+
export function useReactiveCampaignTemplateSummaryFragment(
|
|
748
|
+
templateId: string,
|
|
749
|
+
currentData?: any,
|
|
750
|
+
queryCount?: number,
|
|
751
|
+
) {
|
|
752
|
+
return useReactiveFragment(
|
|
753
|
+
currentData,
|
|
754
|
+
[makeFragmentKey(FRAGMENT_NAMES.campaignTemplate, templateId)],
|
|
755
|
+
queryCount,
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Read a whole template list through the reactive fragment cache.
|
|
761
|
+
*
|
|
762
|
+
* The per-row form of this belongs to table routes, which subscribe each row
|
|
763
|
+
* individually. A plain list (the template picker) has no such mechanism, so it
|
|
764
|
+
* observes every row's fragment key at once and rebuilds the array in place for
|
|
765
|
+
* ordinary template lifecycle and preview updates.
|
|
766
|
+
*/
|
|
767
|
+
export function useReactiveCampaignTemplateFragmentMap(
|
|
768
|
+
templates?: any[] | null,
|
|
769
|
+
queryCount?: number,
|
|
770
|
+
) {
|
|
771
|
+
return useReactiveFragmentMap(
|
|
772
|
+
templates || null,
|
|
773
|
+
getFragmentBaseName(FRAGMENT_NAMES.campaignTemplate),
|
|
774
|
+
queryCount,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Read one campaign through the reactive fragment cache.
|
|
780
|
+
*/
|
|
781
|
+
export function useReactiveCampaignFragment(
|
|
782
|
+
campaignId: string,
|
|
783
|
+
currentData?: any,
|
|
784
|
+
queryCount?: number,
|
|
785
|
+
) {
|
|
786
|
+
return useReactiveFragment(
|
|
787
|
+
currentData,
|
|
788
|
+
[makeFragmentKey(FRAGMENT_NAMES.campaign, campaignId)],
|
|
789
|
+
queryCount,
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Read a whole campaign list through the reactive fragment cache.
|
|
795
|
+
*/
|
|
796
|
+
export function useReactiveCampaignFragmentMap(
|
|
797
|
+
campaigns?: any[] | null,
|
|
798
|
+
queryCount?: number,
|
|
799
|
+
) {
|
|
800
|
+
return useReactiveFragmentMap(
|
|
801
|
+
campaigns || null,
|
|
802
|
+
getFragmentBaseName(FRAGMENT_NAMES.campaign),
|
|
803
|
+
queryCount,
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Read an email campaign recipient list through the reactive fragment cache.
|
|
809
|
+
*/
|
|
810
|
+
export function useReactiveCampaignRecipientFragmentMap(
|
|
811
|
+
recipients?: CampaignRecipientGQL[] | null,
|
|
812
|
+
queryCount?: number,
|
|
813
|
+
): CampaignRecipientGQL[] | null {
|
|
814
|
+
return useReactiveFragmentMap(
|
|
815
|
+
recipients || null,
|
|
816
|
+
getFragmentBaseName(FRAGMENT_NAMES.campaignRecipient),
|
|
817
|
+
queryCount,
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/*
|
|
822
|
+
* Observe one mounted recipient using the exact campaign recipient fragment key.
|
|
823
|
+
*/
|
|
824
|
+
export function useReactiveCampaignRecipientFragment(
|
|
825
|
+
recipientId: string,
|
|
826
|
+
currentData?: CampaignRecipientGQL | null,
|
|
827
|
+
queryCount?: number,
|
|
828
|
+
): CampaignRecipientGQL | null | undefined {
|
|
829
|
+
return useReactiveFragment(
|
|
830
|
+
currentData,
|
|
831
|
+
[makeFragmentKey(FRAGMENT_NAMES.campaignRecipient, recipientId)],
|
|
832
|
+
queryCount,
|
|
833
|
+
);
|
|
834
|
+
}
|