@jsb188/graphql 1.1.8 → 1.1.11

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.
Files changed (122) hide show
  1. package/cache/config.ts +66 -42
  2. package/cache/index.test.ts +881 -0
  3. package/cache/index.ts +1815 -979
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +4 -2
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +973 -143
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +10 -0
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +1 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +17 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +102 -0
  31. package/gql/fragments/emailFragments.ts +36 -0
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/inboundContactFragments.ts +15 -0
  34. package/gql/fragments/integrationFragments.ts +22 -0
  35. package/gql/fragments/logFragments.ts +33 -64
  36. package/gql/fragments/organizationFragments.ts +94 -21
  37. package/gql/fragments/scheduleFragments.ts +155 -0
  38. package/gql/fragments/sheetFragments.ts +675 -0
  39. package/gql/fragments/storageFragments.ts +21 -1
  40. package/gql/fragments/workflowFragments.ts +67 -0
  41. package/gql/mutations/accountMutations.ts +24 -4
  42. package/gql/mutations/agentDocMutations.ts +177 -0
  43. package/gql/mutations/agentMemoryMutations.ts +36 -0
  44. package/gql/mutations/aiChatMutations.ts +43 -3
  45. package/gql/mutations/authMutations.ts +160 -19
  46. package/gql/mutations/campaignMutations.ts +215 -0
  47. package/gql/mutations/dataTableMutations.ts +106 -0
  48. package/gql/mutations/fieldDocMutations.ts +24 -0
  49. package/gql/mutations/inboundContactMutations.ts +24 -0
  50. package/gql/mutations/index.ts +17 -8
  51. package/gql/mutations/integrationMutations.ts +25 -0
  52. package/gql/mutations/logMutations.ts +10 -19
  53. package/gql/mutations/organizationMutations.ts +160 -2
  54. package/gql/mutations/scheduleMutations.ts +423 -0
  55. package/gql/mutations/sheetMutations.ts +385 -0
  56. package/gql/mutations/storageMutations.ts +21 -2
  57. package/gql/mutations/workflowMutations.ts +42 -0
  58. package/gql/queries/agentDocQueries.ts +120 -0
  59. package/gql/queries/agentMemoryQueries.ts +22 -0
  60. package/gql/queries/aiChatQueries.ts +18 -2
  61. package/gql/queries/authQueries.ts +41 -0
  62. package/gql/queries/billingQueries.ts +24 -1
  63. package/gql/queries/campaignQueries.ts +127 -0
  64. package/gql/queries/dataTableQueries.ts +134 -0
  65. package/gql/queries/emailQueries.ts +96 -0
  66. package/gql/queries/fieldDocQueries.ts +158 -0
  67. package/gql/queries/inboundContactQueries.ts +40 -0
  68. package/gql/queries/index.ts +17 -6
  69. package/gql/queries/logQueries.ts +42 -32
  70. package/gql/queries/organizationQueries.ts +113 -8
  71. package/gql/queries/scheduleQueries.ts +315 -0
  72. package/gql/queries/sheetQueries.ts +383 -0
  73. package/gql/queries/storageQueries.ts +38 -0
  74. package/gql/queries/workflowQueries.ts +99 -0
  75. package/hooks/index.ts +2104 -860
  76. package/hooks/use-account-mtn.ts +91 -48
  77. package/hooks/use-agentDoc-mtn.ts +285 -0
  78. package/hooks/use-agentDoc-qry.ts +208 -0
  79. package/hooks/use-agentMemory-mtn.ts +73 -0
  80. package/hooks/use-agentMemory-qry.ts +44 -0
  81. package/hooks/use-aiChat-mtn.ts +248 -97
  82. package/hooks/use-aiChat-qry.ts +501 -191
  83. package/hooks/use-app-qry.ts +14 -11
  84. package/hooks/use-auth-mtn.ts +410 -256
  85. package/hooks/use-auth-qry.ts +51 -0
  86. package/hooks/use-campaign-mtn.ts +377 -0
  87. package/hooks/use-campaign-qry.ts +257 -0
  88. package/hooks/use-dataTable-mtn.ts +170 -0
  89. package/hooks/use-dataTable-qry.ts +996 -0
  90. package/hooks/use-email-qry.ts +227 -0
  91. package/hooks/use-fieldDoc-mtn.ts +50 -0
  92. package/hooks/use-fieldDoc-qry.ts +180 -0
  93. package/hooks/use-inboundContact-mtn.ts +34 -0
  94. package/hooks/use-inboundContact-qry.ts +96 -0
  95. package/hooks/use-integration-mtn.ts +77 -0
  96. package/hooks/use-integration-qry.ts +30 -0
  97. package/hooks/use-log-mtn.ts +77 -61
  98. package/hooks/use-log-qry.ts +99 -72
  99. package/hooks/use-organization-mtn.ts +409 -80
  100. package/hooks/use-organization-qry.ts +211 -92
  101. package/hooks/use-schedule-mtn.ts +416 -0
  102. package/hooks/use-schedule-qry.ts +157 -0
  103. package/hooks/use-sheet-mtn.ts +367 -0
  104. package/hooks/use-sheet-qry.ts +440 -0
  105. package/hooks/use-storage-mtn.ts +83 -42
  106. package/hooks/use-storage-qry.ts +104 -13
  107. package/hooks/use-workflow-mtn.ts +55 -0
  108. package/hooks/use-workflow-qry.ts +230 -0
  109. package/loaders/campaign.ts +137 -0
  110. package/package.json +94 -52
  111. package/sse.ts +158 -105
  112. package/tsconfig.json +13 -0
  113. package/types.d.ts +60 -29
  114. package/utils.ts +77 -50
  115. package/gql/fragments/actionFragments.ts +0 -16
  116. package/gql/fragments/productFragments.ts +0 -63
  117. package/gql/fragments/reportFragments.ts +0 -48
  118. package/gql/mutations/billingMutations.ts +0 -34
  119. package/gql/queries/productQueries.ts +0 -70
  120. package/gql/queries/reportQueries.ts +0 -66
  121. package/hooks/use-product-qry.ts +0 -109
  122. package/hooks/use-report-qry.ts +0 -69
@@ -0,0 +1,227 @@
1
+ import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
2
+ import type {
3
+ InboundEmailGQL,
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';
14
+ import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
15
+
16
+ /**
17
+ * Constants
18
+ */
19
+
20
+ const EMAILS_LIST_LIMIT = 250;
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
+ }
68
+
69
+ /*
70
+ * Fetch one inbound email.
71
+ */
72
+
73
+ export function useInboundEmail(
74
+ variables: {
75
+ organizationId?: string | null;
76
+ inboundEmailId?: string | null;
77
+ },
78
+ params: UseQueryParams = {},
79
+ ) {
80
+ const cachedInboundEmail = useReactiveInboundEmailFragment(
81
+ variables.inboundEmailId || '',
82
+ null,
83
+ );
84
+ const shouldFetchInboundEmail = shouldFetchEmailRecord(
85
+ variables,
86
+ variables.inboundEmailId,
87
+ cachedInboundEmail,
88
+ params,
89
+ );
90
+ const { data, ...rest } = useQuery(inboundEmailQry, {
91
+ ...params,
92
+ variables,
93
+ skip: !shouldFetchInboundEmail,
94
+ });
95
+
96
+ return {
97
+ inboundEmail: cachedInboundEmail || data?.inboundEmail,
98
+ initialLoading: shouldFetchInboundEmail && !data,
99
+ ...rest,
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Fetch inbound emails.
105
+ */
106
+
107
+ export function useInboundEmails(
108
+ variables: PaginationArgs & {
109
+ organizationId?: string | null;
110
+ filter?: EmailListFilter;
111
+ sort?: InboundEmailsSortEnum | null;
112
+ },
113
+ params: UseQueryParams = {},
114
+ ) {
115
+ const { data, ...rest } = useQuery(inboundEmailsQry, {
116
+ ...params,
117
+ variables: {
118
+ ...variables,
119
+ filter: normalizeEmailsFilter(variables.filter),
120
+ cursor: null,
121
+ after: true,
122
+ limit: EMAILS_LIST_LIMIT,
123
+ },
124
+ skip: !variables.organizationId || params.skip,
125
+ });
126
+
127
+ return {
128
+ inboundEmails: data?.inboundEmails,
129
+ ...rest,
130
+ };
131
+ }
132
+
133
+ /*
134
+ * Fetch one outbound email.
135
+ */
136
+
137
+ export function useOutboundEmail(
138
+ variables: {
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
+ };
165
+ }
166
+
167
+ /**
168
+ * Fetch outbound emails.
169
+ */
170
+
171
+ export function useOutboundEmails(
172
+ variables: PaginationArgs & {
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
+
191
+ return {
192
+ outboundEmails: data?.outboundEmails,
193
+ ...rest,
194
+ };
195
+ }
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,50 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
7
+ import { updateFragment } from '../cache/index.ts';
8
+ import { editFieldDocAgentHintMtn } from '../gql/mutations/fieldDocMutations.ts';
9
+ import { useMutation } from './index.ts';
10
+
11
+ /*
12
+ * Edit one fieldDoc's agent-only matching hint.
13
+ */
14
+
15
+ export function useEditFieldDocAgentHint(
16
+ params: UseMutationParams = {},
17
+ openModalPopUp?: OpenModalPopUpFn,
18
+ ) {
19
+ const { onCompleted, ...rest } = params;
20
+
21
+ const [editFieldDocAgentHint, mtnValues, mtnHandlers, updateObservers] =
22
+ useMutation(editFieldDocAgentHintMtn, {
23
+ openModalPopUp,
24
+ onCompleted: (data, error, variables) => {
25
+ const updatedFieldDoc = data?.editFieldDocAgentHint;
26
+
27
+ if (updatedFieldDoc?.id) {
28
+ // The reset-only realtime emit reaches every socket, but the issuer
29
+ // refreshes its own cached fragment here for an instant update
30
+ updateFragment(
31
+ makeFragmentKey(FRAGMENT_NAMES.fieldDoc, updatedFieldDoc.id),
32
+ updatedFieldDoc,
33
+ null,
34
+ false,
35
+ updateObservers,
36
+ );
37
+ }
38
+
39
+ onCompleted?.(updatedFieldDoc, error, variables);
40
+ },
41
+ ...rest,
42
+ });
43
+
44
+ return {
45
+ editFieldDocAgentHint,
46
+ updateObservers,
47
+ ...mtnValues,
48
+ ...mtnHandlers,
49
+ };
50
+ }
@@ -0,0 +1,180 @@
1
+ import type {
2
+ FieldDocsFilterArgs,
3
+ FieldDocsSortEnum,
4
+ } from '@jsb188/mday/types/fieldDoc.d.ts';
5
+ import {
6
+ FRAGMENT_NAMES,
7
+ getFragmentBaseName,
8
+ makeFragmentKey,
9
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
10
+ import {
11
+ useQuery,
12
+ useReactiveFragment,
13
+ useReactiveFragmentMap,
14
+ } from '../client/index.ts';
15
+ import {
16
+ fieldDocGroupsQry,
17
+ fieldDocQry,
18
+ fieldDocsQry,
19
+ fieldDocSubmissionsQry,
20
+ } from '../gql/queries/fieldDocQueries.ts';
21
+ import type { UseQueryParams } from '../types.d.ts';
22
+
23
+ /**
24
+ * Get reactive fieldDoc fragment
25
+ */
26
+
27
+ export function useReactiveFieldDocFragment(
28
+ fieldDocId: string,
29
+ currentData?: any,
30
+ queryCount?: number,
31
+ ) {
32
+ return useReactiveFragment(
33
+ currentData,
34
+ [makeFragmentKey(FRAGMENT_NAMES.fieldDoc, fieldDocId)],
35
+ queryCount,
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Get reactive fieldDoc submission fragment
41
+ */
42
+
43
+ export function useReactiveFieldDocSubmissionFragment(
44
+ fieldDocSubmissionId: string,
45
+ currentData?: any,
46
+ queryCount?: number,
47
+ ) {
48
+ return useReactiveFragment(
49
+ currentData,
50
+ [makeFragmentKey(FRAGMENT_NAMES.fieldDocSubmission, fieldDocSubmissionId)],
51
+ queryCount,
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Get reactive fieldDoc element fragments for a list of fieldDoc elements.
57
+ */
58
+
59
+ export function useReactiveFieldDocElementFragmentMap(
60
+ currentData?: any[] | null,
61
+ ) {
62
+ return useReactiveFragmentMap(
63
+ currentData || null,
64
+ getFragmentBaseName(FRAGMENT_NAMES.fieldDocElementData),
65
+ );
66
+ }
67
+
68
+ /**
69
+ * Fetch list of fieldDocs by type and period
70
+ */
71
+
72
+ export function useFieldDocs(
73
+ variables: {
74
+ organizationId: string;
75
+ filter: FieldDocsFilterArgs;
76
+ sort?: FieldDocsSortEnum;
77
+ },
78
+ params: UseQueryParams = {},
79
+ ) {
80
+ const { organizationId, filter } = variables;
81
+ const { skip, ...restParams } = params;
82
+ const { data, ...rest } = useQuery(fieldDocsQry, {
83
+ variables,
84
+ skip:
85
+ skip ||
86
+ !organizationId ||
87
+ !filter?.fieldDocGroupId ||
88
+ !(filter?.startPeriod || filter?.endPeriod),
89
+ ...restParams,
90
+ });
91
+
92
+ return {
93
+ fieldDocs: data?.fieldDocs,
94
+ ...rest,
95
+ };
96
+ }
97
+
98
+ /**
99
+ * Fetch one fieldDoc by fieldDoc source id
100
+ */
101
+
102
+ export function useFieldDoc(
103
+ organizationId: string | null,
104
+ fieldDocSourceId: string | null,
105
+ params: UseQueryParams = {},
106
+ ) {
107
+ const { skip, ...restParams } = params;
108
+ const { data, ...rest } = useQuery(fieldDocQry, {
109
+ variables: {
110
+ organizationId,
111
+ fieldDocSourceId,
112
+ },
113
+ skip: skip || !organizationId || !fieldDocSourceId,
114
+ ...restParams,
115
+ });
116
+
117
+ return {
118
+ fieldDoc: data?.fieldDoc,
119
+ ...rest,
120
+ };
121
+ }
122
+
123
+ /**
124
+ * Fetch list of fieldDoc groups for organization
125
+ */
126
+
127
+ export function useFieldDocGroups(
128
+ organizationId: string | null,
129
+ params: UseQueryParams = {},
130
+ ) {
131
+ const { skip, ...restParams } = params;
132
+ const { data, ...rest } = useQuery(fieldDocGroupsQry, {
133
+ variables: {
134
+ organizationId,
135
+ },
136
+ skip: skip || !organizationId,
137
+ ...restParams,
138
+ });
139
+
140
+ return {
141
+ fieldDocGroups: data?.fieldDocGroups,
142
+ ...rest,
143
+ };
144
+ }
145
+
146
+ /**
147
+ * Fetch list of fieldDoc submissions for organization
148
+ */
149
+
150
+ export function useFieldDocSubmissions(
151
+ variables: {
152
+ organizationId: string | null;
153
+ filter: FieldDocsFilterArgs;
154
+ sort?: FieldDocsSortEnum;
155
+ limit?: number;
156
+ },
157
+ params: UseQueryParams = {},
158
+ ) {
159
+ const {
160
+ organizationId,
161
+ filter,
162
+ sort = 'PERIOD_DESC',
163
+ limit = 100,
164
+ } = variables;
165
+ const { skip, ...restParams } = params;
166
+ const { data, ...rest } = useQuery(fieldDocSubmissionsQry, {
167
+ variables: {
168
+ ...variables,
169
+ sort,
170
+ limit,
171
+ },
172
+ skip: skip || !organizationId || !filter,
173
+ ...restParams,
174
+ });
175
+
176
+ return {
177
+ fieldDocSubmissions: data?.fieldDocSubmissions,
178
+ ...rest,
179
+ };
180
+ }
@@ -0,0 +1,34 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import { editInboundContactMtn } from '../gql/mutations/inboundContactMutations.ts';
4
+ import { useMutation } from './index.ts';
5
+
6
+ /**
7
+ * Edit one inbound contact memory record.
8
+ */
9
+
10
+ export function useEditInboundContact(
11
+ params: UseMutationParams = {},
12
+ openModalPopUp?: OpenModalPopUpFn,
13
+ ) {
14
+ const { onCompleted, ...rest } = params;
15
+
16
+ const [editInboundContact, mtnValues, mtnHandlers] = useMutation(
17
+ editInboundContactMtn,
18
+ {
19
+ openModalPopUp,
20
+ onCompleted: (data, error, variables) => {
21
+ const updatedInboundContact = data?.editInboundContact;
22
+
23
+ onCompleted?.(updatedInboundContact, error, variables);
24
+ },
25
+ ...rest,
26
+ },
27
+ );
28
+
29
+ return {
30
+ editInboundContact,
31
+ ...mtnValues,
32
+ ...mtnHandlers,
33
+ };
34
+ }
@@ -0,0 +1,96 @@
1
+ import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
2
+ import type { InboundContactsSortEnum } from '@jsb188/mday/types/inboundContact.d.ts';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
7
+ import {
8
+ inboundContactQry,
9
+ inboundContactsQry,
10
+ } from '../gql/queries/inboundContactQueries.ts';
11
+ import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
12
+
13
+ /**
14
+ * Constants
15
+ */
16
+
17
+ const INBOUND_CONTACTS_LIMIT = 250;
18
+
19
+ /*
20
+ * Fetch one inbound contact.
21
+ */
22
+
23
+ export function useInboundContact(
24
+ variables: {
25
+ organizationId?: string | null;
26
+ inboundContactId?: string | null;
27
+ },
28
+ params: UseQueryParams = {},
29
+ ) {
30
+ const cachedInboundContact = useReactiveInboundContactFragment(
31
+ variables.inboundContactId || '',
32
+ null,
33
+ );
34
+ const shouldFetchInboundContact =
35
+ !!variables.organizationId &&
36
+ !!variables.inboundContactId &&
37
+ !cachedInboundContact &&
38
+ !params.skip;
39
+ const { data, ...rest } = useQuery(inboundContactQry, {
40
+ ...params,
41
+ variables,
42
+ skip: !shouldFetchInboundContact,
43
+ });
44
+
45
+ return {
46
+ inboundContact: cachedInboundContact || data?.inboundContact,
47
+ initialLoading: shouldFetchInboundContact && !data,
48
+ ...rest,
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Fetch inbound contacts.
54
+ */
55
+
56
+ export function useInboundContacts(
57
+ variables: PaginationArgs & {
58
+ organizationId?: string | null;
59
+ filter?: unknown;
60
+ sort?: InboundContactsSortEnum | null;
61
+ },
62
+ params: UseQueryParams = {},
63
+ ) {
64
+ const { filter: _filter, ...queryVariables } = variables;
65
+ const { data, ...rest } = useQuery(inboundContactsQry, {
66
+ ...params,
67
+ variables: {
68
+ ...queryVariables,
69
+ cursor: null,
70
+ after: true,
71
+ limit: INBOUND_CONTACTS_LIMIT,
72
+ },
73
+ skip: !variables.organizationId || params.skip,
74
+ });
75
+
76
+ return {
77
+ inboundContacts: data?.inboundContacts,
78
+ ...rest,
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Get reactive inbound contact fragment.
84
+ */
85
+
86
+ export function useReactiveInboundContactFragment(
87
+ inboundContactId: string,
88
+ currentData?: any,
89
+ queryCount?: number,
90
+ ) {
91
+ return useReactiveFragment(
92
+ currentData,
93
+ [makeFragmentKey(FRAGMENT_NAMES.inboundContact, inboundContactId)],
94
+ queryCount,
95
+ );
96
+ }
@@ -0,0 +1,77 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ FRAGMENT_NAMES,
5
+ makeFragmentKey,
6
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
7
+ import { updateFragment } from '../cache/index.ts';
8
+ import {
9
+ createIntegrationAuthorizationUrlMtn,
10
+ disconnectIntegrationMtn,
11
+ } from '../gql/mutations/integrationMutations.ts';
12
+ import { useMutation } from './index.ts';
13
+
14
+ /**
15
+ * Create integration OAuth authorization URL.
16
+ */
17
+ export function useCreateIntegrationAuthorizationUrl(
18
+ params: UseMutationParams = {},
19
+ openModalPopUp?: OpenModalPopUpFn,
20
+ ) {
21
+ const [createIntegrationAuthorizationUrl, mtnValues, mtnHandlers] =
22
+ useMutation(createIntegrationAuthorizationUrlMtn, {
23
+ openModalPopUp,
24
+ ...params,
25
+ });
26
+
27
+ return {
28
+ createIntegrationAuthorizationUrl,
29
+ ...mtnValues,
30
+ ...mtnHandlers,
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Disconnect an integration.
36
+ */
37
+ export function useDisconnectIntegration(
38
+ params: UseMutationParams = {},
39
+ openModalPopUp?: OpenModalPopUpFn,
40
+ ) {
41
+ const { onCompleted, ...otherParams } = params;
42
+ const [disconnectIntegration, mtnValues, mtnHandlers, updateObservers] =
43
+ useMutation(disconnectIntegrationMtn, {
44
+ openModalPopUp,
45
+ onCompleted: (data: any, error: any, variables: any) => {
46
+ const disconnectedIntegrationId = data?.disconnectIntegration;
47
+
48
+ if (disconnectedIntegrationId) {
49
+ const organizationFragmentKey = makeFragmentKey(
50
+ FRAGMENT_NAMES.organization,
51
+ variables.organizationId,
52
+ );
53
+
54
+ updateFragment(
55
+ makeFragmentKey(
56
+ FRAGMENT_NAMES.integrationConnection,
57
+ disconnectedIntegrationId,
58
+ ),
59
+ { status: 'DISCONNECTED' },
60
+ null,
61
+ false,
62
+ updateObservers,
63
+ [organizationFragmentKey],
64
+ );
65
+ }
66
+
67
+ onCompleted?.(disconnectedIntegrationId, error, variables);
68
+ },
69
+ ...otherParams,
70
+ });
71
+
72
+ return {
73
+ disconnectIntegration,
74
+ ...mtnValues,
75
+ ...mtnHandlers,
76
+ };
77
+ }
@@ -0,0 +1,30 @@
1
+ import {
2
+ FRAGMENT_NAMES,
3
+ makeFragmentKey,
4
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
5
+ import { useReactiveFragment } from '../client/index.ts';
6
+
7
+ /**
8
+ * Get reactive integration connection fragment.
9
+ */
10
+ export function useReactiveIntegrationConnection(
11
+ integrationConnectionId?: string | null,
12
+ currentData?: any,
13
+ queryCount?: number,
14
+ ) {
15
+ return useReactiveFragment(
16
+ currentData,
17
+ integrationConnectionId
18
+ ? [
19
+ makeFragmentKey(
20
+ FRAGMENT_NAMES.integrationConnection,
21
+ integrationConnectionId,
22
+ ),
23
+ ]
24
+ : [],
25
+ queryCount,
26
+ undefined,
27
+ undefined,
28
+ true,
29
+ );
30
+ }