@jsb188/graphql 1.1.3 → 1.1.5
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/cache/config.ts +3 -3
- package/cache/index.ts +173 -85
- package/gql/fragments/accountAuthFragments.ts +3 -9
- package/gql/fragments/accountFragments.ts +11 -0
- package/gql/fragments/logFragments.ts +25 -0
- package/gql/fragments/organizationFragments.ts +10 -2
- package/gql/mutations/accountMutations.ts +21 -0
- package/gql/mutations/aiChatMutations.ts +1 -0
- package/gql/mutations/authMutations.ts +171 -0
- package/gql/mutations/index.ts +7 -0
- package/gql/mutations/logMutations.ts +43 -0
- package/gql/mutations/userAuthMutations.ts +0 -163
- package/gql/queries/aiChatQueries.ts +1 -0
- package/gql/queries/appQueries.ts +2 -1
- package/gql/queries/logQueries.ts +37 -0
- package/gql/queries/organizationQueries.ts +1 -0
- package/hooks/index.ts +134 -75
- package/hooks/use-account-mtn.ts +43 -0
- package/hooks/use-aiChat-mtn.ts +96 -0
- package/hooks/use-aiChat-qry.ts +65 -3
- package/hooks/use-auth-mtn.ts +99 -112
- package/hooks/use-log-mtn.ts +85 -0
- package/hooks/use-log-qry.ts +77 -0
- package/package.json +10 -20
- package/types.d.ts +1 -0
- package/gql/fragments/cardFragments.ts +0 -15
- package/gql/fragments/chatFragments.ts +0 -98
- package/gql/fragments/journalFragments.ts +0 -14
- package/gql/fragments/userAuthFragments.ts +0 -8
- package/gql/fragments/userFragments.ts +0 -69
- package/gql/mutations/accountAuthMutations.ts +0 -81
- package/gql/mutations/chatMutations.ts +0 -116
- package/gql/mutations/journalMutations.ts +0 -2
- package/gql/mutations/userMutations.ts +0 -89
- package/gql/queries/cardQueries.ts +0 -24
- package/gql/queries/chatQueries.ts +0 -86
- package/gql/queries/journalQueries.ts +0 -28
- package/gql/queries/userQueries.ts +0 -104
- package/hooks/use-journal-qry.ts +0 -50
package/hooks/use-auth-mtn.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import { useMutation } from './index';
|
|
3
|
-
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
4
2
|
import { deleteAuthToken } from '@jsb188/app/platform';
|
|
5
|
-
import {
|
|
3
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
6
4
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
7
|
-
import { AppContext,
|
|
8
|
-
import React, {
|
|
5
|
+
import { AppContext, onGuestInit, useOpenModalPopUp } from '@jsb188/react/states';
|
|
6
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
7
|
+
import { changeAccountPasswordMtn, checkUsernameOrEmailMtn, confirmPhoneVerificationCodeMtn, requestTokenizedEmailMtn, sendPhoneVerificationCodeMtn, signUpWithEmailMtn } from '../gql/mutations/authMutations';
|
|
8
|
+
import { signOutMtn } from '../gql/mutations/userAuthMutations';
|
|
9
|
+
import { useMutation } from './index';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Types
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
interface
|
|
15
|
+
interface AuthHookParams extends UseMutationParams {
|
|
15
16
|
initialError?: any;
|
|
16
17
|
initialFormData?: Record<string, any>;
|
|
17
18
|
}
|
|
@@ -20,20 +21,31 @@ interface SignInParams extends UseMutationParams {
|
|
|
20
21
|
* Change password (while logged in)
|
|
21
22
|
*/
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
interface UseChangeAccountPasswordParams extends UseMutationParams {
|
|
25
|
+
doNotFinishForm?: boolean;
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
const openModalPopUp = useOpenModalPopUp();
|
|
27
|
-
const { onCompleted, onError } = params;
|
|
28
|
+
export function useChangeAccountPassword(params: UseChangeAccountPasswordParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const { dispatchApp, appState: { hasPassword, account } } = useContext(AppContext);
|
|
31
|
+
const { onCompleted, onError, doNotFinishForm } = params;
|
|
32
|
+
|
|
33
|
+
const onFinishChangeAccountPassword = () => {
|
|
34
|
+
if (!hasPassword) {
|
|
35
|
+
dispatchApp({
|
|
36
|
+
__type: 'APP_EDIT_AUTH',
|
|
37
|
+
data: {
|
|
38
|
+
id: account?.id,
|
|
39
|
+
hasPassword: true,
|
|
40
|
+
}
|
|
41
|
+
});
|
|
32
42
|
}
|
|
43
|
+
};
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
const onCompleted_ = (data: any, err: any, variables: any) => {
|
|
46
|
+
const success = !!data?.changeAccountPassword;
|
|
35
47
|
if (success) {
|
|
36
|
-
openModalPopUp({
|
|
48
|
+
openModalPopUp?.({
|
|
37
49
|
name: 'password_changed',
|
|
38
50
|
props: {
|
|
39
51
|
title: i18n.t('form.success'),
|
|
@@ -42,20 +54,18 @@ export function useChangePassword(params: UseMutationParams = {}) {
|
|
|
42
54
|
}
|
|
43
55
|
});
|
|
44
56
|
|
|
45
|
-
if (!
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
});
|
|
57
|
+
if (!doNotFinishForm) {
|
|
58
|
+
onFinishChangeAccountPassword();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (onCompleted) {
|
|
62
|
+
onCompleted(success, err, variables);
|
|
53
63
|
}
|
|
54
64
|
}
|
|
55
65
|
};
|
|
56
66
|
|
|
57
|
-
const [
|
|
58
|
-
|
|
67
|
+
const [changeAccountPassword, mtnValues, mtnHandlers] = useMutation(
|
|
68
|
+
changeAccountPasswordMtn,
|
|
59
69
|
{
|
|
60
70
|
openModalPopUp,
|
|
61
71
|
onCompleted: onCompleted_,
|
|
@@ -65,8 +75,11 @@ export function useChangePassword(params: UseMutationParams = {}) {
|
|
|
65
75
|
|
|
66
76
|
return {
|
|
67
77
|
openModalPopUp,
|
|
68
|
-
|
|
78
|
+
changeAccountPassword,
|
|
79
|
+
onFinishChangeAccountPassword,
|
|
80
|
+
account,
|
|
69
81
|
...mtnValues,
|
|
82
|
+
...mtnHandlers,
|
|
70
83
|
};
|
|
71
84
|
}
|
|
72
85
|
|
|
@@ -74,7 +87,7 @@ export function useChangePassword(params: UseMutationParams = {}) {
|
|
|
74
87
|
* Reset password (from 30m email link)
|
|
75
88
|
*/
|
|
76
89
|
|
|
77
|
-
export function
|
|
90
|
+
export function useChangeAccountPasswordForm(params: UseMutationParams = {}) {
|
|
78
91
|
|
|
79
92
|
const { dispatchApp, appState: { hasPassword, account } } = useContext(AppContext);
|
|
80
93
|
const { onCompleted, onError } = params;
|
|
@@ -84,7 +97,7 @@ export function useChangePasswordForm(params: UseMutationParams = {}) {
|
|
|
84
97
|
onCompleted(data, err, variables);
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
const success = !!data?.
|
|
100
|
+
const success = !!data?.changeAccountPassword;
|
|
88
101
|
if (success) {
|
|
89
102
|
// It's possible for user to use this hook without being logged in
|
|
90
103
|
// So we have to check for ID first
|
|
@@ -100,8 +113,8 @@ export function useChangePasswordForm(params: UseMutationParams = {}) {
|
|
|
100
113
|
}
|
|
101
114
|
};
|
|
102
115
|
|
|
103
|
-
const [
|
|
104
|
-
|
|
116
|
+
const [changeAccountPassword, mtnValues, mtnHandlers] = useMutation(
|
|
117
|
+
changeAccountPasswordMtn,
|
|
105
118
|
{
|
|
106
119
|
checkMountedBeforeCallback: true,
|
|
107
120
|
onCompleted: onCompleted_,
|
|
@@ -110,53 +123,66 @@ export function useChangePasswordForm(params: UseMutationParams = {}) {
|
|
|
110
123
|
);
|
|
111
124
|
|
|
112
125
|
return {
|
|
113
|
-
|
|
126
|
+
changeAccountPassword,
|
|
114
127
|
...mtnValues,
|
|
128
|
+
...mtnHandlers,
|
|
115
129
|
};
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
/**
|
|
119
|
-
*
|
|
133
|
+
* Request password reset (email with link)
|
|
120
134
|
*/
|
|
121
135
|
|
|
122
|
-
export function
|
|
123
|
-
|
|
136
|
+
export function useRequestTokenizedEmail(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
124
137
|
const { onCompleted, onError } = params;
|
|
125
|
-
const [
|
|
126
|
-
|
|
138
|
+
const [requestTokenizedEmail, mtnValues] = useMutation(
|
|
139
|
+
requestTokenizedEmailMtn,
|
|
127
140
|
{
|
|
141
|
+
checkMountedBeforeCallback: true,
|
|
128
142
|
openModalPopUp,
|
|
129
|
-
onError,
|
|
130
143
|
onCompleted,
|
|
144
|
+
onError
|
|
131
145
|
},
|
|
132
146
|
);
|
|
133
147
|
|
|
134
|
-
|
|
135
|
-
|
|
148
|
+
return {
|
|
149
|
+
requestTokenizedEmail,
|
|
150
|
+
...mtnValues,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Send verification code to phone number
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
export function useSendPhoneVerificationCode(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
159
|
+
const { onCompleted, onError } = params;
|
|
160
|
+
const [sendPhoneVerificationCode, mtnValues, mtnHandlers] = useMutation(
|
|
161
|
+
sendPhoneVerificationCodeMtn,
|
|
136
162
|
{
|
|
163
|
+
checkMountedBeforeCallback: true,
|
|
137
164
|
openModalPopUp,
|
|
138
|
-
onError,
|
|
139
165
|
onCompleted,
|
|
166
|
+
onError
|
|
140
167
|
},
|
|
141
168
|
);
|
|
142
169
|
|
|
143
170
|
return {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
sending: mtnValues2.saving,
|
|
171
|
+
sendPhoneVerificationCode,
|
|
172
|
+
...mtnValues,
|
|
173
|
+
...mtnHandlers,
|
|
148
174
|
};
|
|
149
175
|
}
|
|
150
176
|
|
|
151
177
|
/**
|
|
152
|
-
*
|
|
178
|
+
* Confirm verification code
|
|
153
179
|
*/
|
|
154
180
|
|
|
155
|
-
export function
|
|
156
|
-
|
|
181
|
+
export function useConfirmPhoneVerificationCode(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
157
182
|
const { onCompleted, onError } = params;
|
|
158
|
-
|
|
159
|
-
|
|
183
|
+
|
|
184
|
+
const [confirmPhoneVerificationCode, mtnValues, mtnHandlers] = useMutation(
|
|
185
|
+
confirmPhoneVerificationCodeMtn,
|
|
160
186
|
{
|
|
161
187
|
checkMountedBeforeCallback: true,
|
|
162
188
|
openModalPopUp,
|
|
@@ -166,8 +192,9 @@ export function useRequestTokenizedEmail(params: UseMutationParams = {}, openMod
|
|
|
166
192
|
);
|
|
167
193
|
|
|
168
194
|
return {
|
|
169
|
-
|
|
195
|
+
confirmPhoneVerificationCode,
|
|
170
196
|
...mtnValues,
|
|
197
|
+
...mtnHandlers,
|
|
171
198
|
};
|
|
172
199
|
}
|
|
173
200
|
|
|
@@ -175,9 +202,8 @@ export function useRequestTokenizedEmail(params: UseMutationParams = {}, openMod
|
|
|
175
202
|
* Sign in
|
|
176
203
|
*/
|
|
177
204
|
|
|
178
|
-
export function
|
|
205
|
+
export function useCheckUsernameOrEmail(params: AuthHookParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
179
206
|
const { onError, onCompleted, initialError, initialFormData } = params;
|
|
180
|
-
const { dispatchApp } = useContext<any>(AppContext);
|
|
181
207
|
|
|
182
208
|
const [dataForSchema, setDataForSchema] = useState({
|
|
183
209
|
hasInput: !!initialFormData?.usernameOrEmail,
|
|
@@ -185,7 +211,7 @@ export function useSignIn(params: SignInParams = {}, openModalPopUp?: OpenModalP
|
|
|
185
211
|
hidePassword: !initialFormData?.usernameOrEmail,
|
|
186
212
|
});
|
|
187
213
|
|
|
188
|
-
const [checkUsernameOrEmail,
|
|
214
|
+
const [checkUsernameOrEmail, mtnValues, mtnHandlers] = useMutation(
|
|
189
215
|
checkUsernameOrEmailMtn,
|
|
190
216
|
{
|
|
191
217
|
openModalPopUp,
|
|
@@ -195,42 +221,36 @@ export function useSignIn(params: SignInParams = {}, openModalPopUp?: OpenModalP
|
|
|
195
221
|
},
|
|
196
222
|
);
|
|
197
223
|
|
|
198
|
-
|
|
199
|
-
|
|
224
|
+
return {
|
|
225
|
+
...mtnValues,
|
|
226
|
+
...mtnHandlers,
|
|
227
|
+
checkUsernameOrEmail,
|
|
228
|
+
dataForSchema,
|
|
229
|
+
setDataForSchema,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Sign up with email
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
export function useSignUpWithEmail(params: AuthHookParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
238
|
+
const { onError, onCompleted, initialError } = params;
|
|
239
|
+
|
|
240
|
+
const [signUpWithEmail, mtnValues, mtnHandlers] = useMutation(
|
|
241
|
+
signUpWithEmailMtn,
|
|
200
242
|
{
|
|
201
243
|
openModalPopUp,
|
|
202
244
|
initialError,
|
|
203
245
|
onError,
|
|
204
|
-
onCompleted
|
|
205
|
-
const result = data?.signIn;
|
|
206
|
-
if (result?.token && result.user?.id) {
|
|
207
|
-
onAccountLogin(result, dispatchApp);
|
|
208
|
-
|
|
209
|
-
if (onCompleted) {
|
|
210
|
-
onCompleted(data, error);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
246
|
+
onCompleted,
|
|
214
247
|
},
|
|
215
248
|
);
|
|
216
249
|
|
|
217
|
-
let mtnValues;
|
|
218
|
-
let mtnHandlers;
|
|
219
|
-
if (dataForSchema.hidePassword) {
|
|
220
|
-
mtnValues = step1MtnValues;
|
|
221
|
-
mtnHandlers = step1MtnHandlers;
|
|
222
|
-
} else {
|
|
223
|
-
mtnValues = step2MtnValues;
|
|
224
|
-
mtnHandlers = step2MtnHandlers;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
250
|
return {
|
|
228
251
|
...mtnValues,
|
|
229
252
|
...mtnHandlers,
|
|
230
|
-
|
|
231
|
-
signIn,
|
|
232
|
-
dataForSchema,
|
|
233
|
-
setDataForSchema,
|
|
253
|
+
signUpWithEmail,
|
|
234
254
|
};
|
|
235
255
|
}
|
|
236
256
|
|
|
@@ -240,39 +260,6 @@ export function useSignIn(params: SignInParams = {}, openModalPopUp?: OpenModalP
|
|
|
240
260
|
// Before are deprecated HOC that needs to be migrated to hooks
|
|
241
261
|
// Before are deprecated HOC that needs to be migrated to hooks
|
|
242
262
|
|
|
243
|
-
/**
|
|
244
|
-
* Sign up
|
|
245
|
-
*/
|
|
246
|
-
|
|
247
|
-
export function composeSignUp(Cmp: React.FC<any>) {
|
|
248
|
-
const SignUpCnt = (p) => {
|
|
249
|
-
const { doNotAlertErrors, onError, onCompleted } = p;
|
|
250
|
-
const openModalPopUp = useOpenModalPopUp();
|
|
251
|
-
|
|
252
|
-
const [signUp, mtnValues, mtnHandlers] = useMutation(
|
|
253
|
-
signUpMtn,
|
|
254
|
-
{
|
|
255
|
-
openModalPopUp: doNotAlertErrors ? null : openModalPopUp,
|
|
256
|
-
onError,
|
|
257
|
-
onCompleted,
|
|
258
|
-
},
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
// return (
|
|
262
|
-
// <Cmp
|
|
263
|
-
// {...p}
|
|
264
|
-
// {...mtnValues}
|
|
265
|
-
// {...mtnHandlers}
|
|
266
|
-
// signUp={signUp}
|
|
267
|
-
// />
|
|
268
|
-
// );
|
|
269
|
-
|
|
270
|
-
return 'This page is not done yet.'
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
return SignUpCnt;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
263
|
/**
|
|
277
264
|
* Sign out
|
|
278
265
|
*/
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { checkACLPermission } from '@jsb188/app/utils/organization';
|
|
2
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
3
|
+
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { updateFragment } from '../cache/index';
|
|
6
|
+
import { deleteLogEntryMtn, editLogEntryMtn } from '../gql/mutations/logMutations';
|
|
7
|
+
import { useMutation } from './index';
|
|
8
|
+
import { useReactiveLogFragment } from './use-log-qry';
|
|
9
|
+
import { useOrganizationRelationship } from './use-organization-qry';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fetch a single log entry,
|
|
13
|
+
* from cache first; only check server if cache is not found.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function useEditLogEntry(
|
|
17
|
+
viewerAccountId: string,
|
|
18
|
+
logEntryId: string,
|
|
19
|
+
organizationId: string,
|
|
20
|
+
params: UseMutationParams = {},
|
|
21
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
22
|
+
) {
|
|
23
|
+
|
|
24
|
+
const { organizationRelationship } = useOrganizationRelationship(organizationId);
|
|
25
|
+
const notReady = !organizationRelationship;
|
|
26
|
+
|
|
27
|
+
const [editLogEntry, mtnValues, mtnHandlers] = useMutation(
|
|
28
|
+
editLogEntryMtn,
|
|
29
|
+
{
|
|
30
|
+
// checkMountedBeforeCallback: true,
|
|
31
|
+
openModalPopUp,
|
|
32
|
+
...params,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const logEntry = useReactiveLogFragment(logEntryId, null, mtnValues.mutationCount);
|
|
37
|
+
// const logEntry = useReactiveFragment(
|
|
38
|
+
// null,
|
|
39
|
+
// [`$logEntryFragment:${logEntryId}`, [`$logEntryArableFragment:${logEntryId}`, 'details']],
|
|
40
|
+
// mtnValues.mutationCount,
|
|
41
|
+
// );
|
|
42
|
+
|
|
43
|
+
const isMyDocument = !!viewerAccountId && logEntry?.accountId === viewerAccountId;
|
|
44
|
+
const allowEdit = useMemo(() => {
|
|
45
|
+
return checkACLPermission(organizationRelationship, 'logs', isMyDocument ? 'WRITE' : 'MANAGE');
|
|
46
|
+
}, [organizationRelationship?.acl, organizationRelationship?.role]);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
logEntry,
|
|
50
|
+
editLogEntry,
|
|
51
|
+
notReady,
|
|
52
|
+
allowEdit,
|
|
53
|
+
...mtnValues,
|
|
54
|
+
...mtnHandlers,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Delete a single log entry
|
|
60
|
+
* NOTE: Don't check ACL and allow server to handle it.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export function useDeleteLogEntry(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
64
|
+
|
|
65
|
+
const { onCompleted, ...rest } = params;
|
|
66
|
+
const [deleteLogEntry, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
67
|
+
deleteLogEntryMtn,
|
|
68
|
+
{
|
|
69
|
+
openModalPopUp,
|
|
70
|
+
onCompleted: (data, dataMtnValues, variables) => {
|
|
71
|
+
if (data?.deleteLogEntry) {
|
|
72
|
+
updateFragment(`$logEntryFragment:${variables.logEntryId}`, { __deleted: true }, null, false, updateObservers);
|
|
73
|
+
}
|
|
74
|
+
onCompleted?.(data, dataMtnValues, variables);
|
|
75
|
+
},
|
|
76
|
+
...rest,
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
deleteLogEntry,
|
|
82
|
+
...mtnValues,
|
|
83
|
+
...mtnHandlers,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d';
|
|
2
|
+
import { useQuery, useReactiveFragment } from '../client';
|
|
3
|
+
import { logEntriesQry } from '../gql/queries/logQueries';
|
|
4
|
+
import type { PaginationArgs, UseQueryParams } from '../types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Constants
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const LOG_ENTRIES_LIMIT = 200;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Helper; use this to get/use same filter for logEntries() query everywhere
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function getDefaultLogEntriesFilter(operation: FilterLogEntriesArgs['operation']): FilterLogEntriesArgs {
|
|
17
|
+
return {
|
|
18
|
+
operation,
|
|
19
|
+
types: null,
|
|
20
|
+
startDate: null,
|
|
21
|
+
endDate: null,
|
|
22
|
+
query: ''
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fetch log entries
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
interface LogEntriesArgs extends PaginationArgs {
|
|
31
|
+
organizationId: string;
|
|
32
|
+
accountId?: string;
|
|
33
|
+
timeZone: string | null;
|
|
34
|
+
filter: FilterLogEntriesArgs;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useLogEntries(variables: LogEntriesArgs, params: UseQueryParams = {}) {
|
|
38
|
+
|
|
39
|
+
const { data, ...rest } = useQuery(logEntriesQry, {
|
|
40
|
+
variables: {
|
|
41
|
+
...variables,
|
|
42
|
+
cursor: null,
|
|
43
|
+
after: true,
|
|
44
|
+
limit: LOG_ENTRIES_LIMIT
|
|
45
|
+
},
|
|
46
|
+
// If this query is used for virtualized list pagination, set {params.skip=true}
|
|
47
|
+
skip: !variables.organizationId || !variables.filter?.operation,
|
|
48
|
+
...params,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
logEntries: data?.logEntries,
|
|
53
|
+
...rest
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get reactive log fragment
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export function useReactiveLogFragment(logEntryId: string, currentData?: any, queryCount?: number) {
|
|
62
|
+
return useReactiveFragment(
|
|
63
|
+
currentData,
|
|
64
|
+
[
|
|
65
|
+
`$logEntryFragment:${logEntryId}`,
|
|
66
|
+
|
|
67
|
+
// By having the second paramter as null, we only observe the reactive changes without setting the data
|
|
68
|
+
[`$logEntryArableFragment:${logEntryId}`, null],
|
|
69
|
+
|
|
70
|
+
// This is not needed because $logEntryFragment has spread data
|
|
71
|
+
// [`$accountFragment:${logEntryId}`, 'account']
|
|
72
|
+
],
|
|
73
|
+
queryCount,
|
|
74
|
+
// Using the otherCheck() function is the only way I could keep sticker updates reactive
|
|
75
|
+
// (_, updatedKeys) => updatedKeys.find((k) => typeof k === 'string' && k.startsWith('$chatStickerFragment:')),
|
|
76
|
+
);
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/graphql",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "GraphQL client for react, using recoil",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -11,33 +11,23 @@
|
|
|
11
11
|
"./fragments/accountAuth": "./gql/fragments/accountAuthFragments.ts",
|
|
12
12
|
"./fragments/aiChat": "./gql/fragments/aiChatFragments.ts",
|
|
13
13
|
"./fragments/billing": "./gql/fragments/billingFragments.ts",
|
|
14
|
-
"./fragments/
|
|
15
|
-
"./fragments/chat": "./gql/fragments/chatFragments.ts",
|
|
16
|
-
"./fragments/journal": "./gql/fragments/journalFragments.ts",
|
|
14
|
+
"./fragments/log": "./gql/fragments/logFragments.ts",
|
|
17
15
|
"./fragments/organization": "./gql/fragments/organizationFragments.ts",
|
|
18
16
|
"./fragments/other": "./gql/fragments/otherFragments.ts",
|
|
19
|
-
"./fragments/user": "./gql/fragments/userFragments.ts",
|
|
20
|
-
"./fragments/userAuth": "./gql/fragments/userAuthFragments.ts",
|
|
21
17
|
"./hooks": "./hooks/",
|
|
22
18
|
"./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
|
|
23
19
|
"./hooks/use-app-qry": "./hooks/use-app-qry.ts",
|
|
24
|
-
"./hooks/use-
|
|
20
|
+
"./hooks/use-log-qry": "./hooks/use-log-qry.ts",
|
|
25
21
|
"./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
|
|
22
|
+
"./hooks/use-account-mtn": "./hooks/use-account-mtn.ts",
|
|
23
|
+
"./hooks/use-aiChat-mtn": "./hooks/use-aiChat-mtn.ts",
|
|
26
24
|
"./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
|
|
27
|
-
"./
|
|
28
|
-
"./mutations
|
|
29
|
-
"./mutations/billing": "./gql/mutations/billingMutations.ts",
|
|
30
|
-
"./mutations/chat": "./gql/mutations/chatMutations.ts",
|
|
31
|
-
"./mutations/journal": "./gql/mutations/journalMutations.ts",
|
|
32
|
-
"./mutations/other": "./gql/mutations/otherMutations.ts",
|
|
33
|
-
"./mutations/user": "./gql/mutations/userMutations.ts",
|
|
34
|
-
"./mutations/userAuth": "./gql/mutations/userAuthMutations.ts",
|
|
25
|
+
"./hooks/use-log-mtn": "./hooks/use-log-mtn.ts",
|
|
26
|
+
"./mutations": "./gql/mutations/index.ts",
|
|
35
27
|
"./queries/aiChat": "./gql/queries/aiChatQueries.ts",
|
|
36
28
|
"./queries/app": "./gql/queries/appQueries.ts",
|
|
37
29
|
"./queries/billing": "./gql/queries/billingQueries.ts",
|
|
38
|
-
"./queries/
|
|
39
|
-
"./queries/chat": "./gql/queries/chatQueries.ts",
|
|
40
|
-
"./queries/journal": "./gql/queries/journalQueries.ts",
|
|
30
|
+
"./queries/log": "./gql/queries/logQueries.ts",
|
|
41
31
|
"./queries/organization": "./gql/queries/organizationQueries.ts",
|
|
42
32
|
"./queries/other": "./gql/queries/otherQueries.ts",
|
|
43
33
|
"./queries/user": "./gql/queries/userQueries.ts",
|
|
@@ -55,7 +45,7 @@
|
|
|
55
45
|
"graphql-tag": "^2.12.6"
|
|
56
46
|
},
|
|
57
47
|
"peerDependencies": {
|
|
58
|
-
"@jsb188/app": "1.1.
|
|
59
|
-
"@jsb188/react": "1.1.
|
|
48
|
+
"@jsb188/app": "1.1.5",
|
|
49
|
+
"@jsb188/react": "1.1.5"
|
|
60
50
|
}
|
|
61
51
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// NOTE: Can't use "hasAccess" here; because live chats need participants[] data in back-end
|
|
2
|
-
// NOTE: "chatFragment" is used in lists, "chatPartial" is used in chat main
|
|
3
|
-
export const chatFragment = `fragment chatFragment on Chat {
|
|
4
|
-
id
|
|
5
|
-
ownerId
|
|
6
|
-
name
|
|
7
|
-
note
|
|
8
|
-
deleted
|
|
9
|
-
photoUri
|
|
10
|
-
unread
|
|
11
|
-
pinned
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
status
|
|
15
|
-
liveCategory
|
|
16
|
-
|
|
17
|
-
theme {
|
|
18
|
-
id
|
|
19
|
-
name
|
|
20
|
-
backgroundPhotoUri
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
lastMessage
|
|
24
|
-
lastMessageAt
|
|
25
|
-
lastMessageUserId
|
|
26
|
-
lastMessageDisplayName
|
|
27
|
-
lastMessagePhotoUri
|
|
28
|
-
lastMessageIsSelf
|
|
29
|
-
}`;
|
|
30
|
-
|
|
31
|
-
export const chatStickerFragment = `fragment chatStickerFragment on ChatSticker {
|
|
32
|
-
id
|
|
33
|
-
code
|
|
34
|
-
photoId
|
|
35
|
-
photoUri
|
|
36
|
-
}`;
|
|
37
|
-
|
|
38
|
-
// NOTE: "chatFragment" is used in lists, "chatPartial" is used in chat main
|
|
39
|
-
export const chatPartial = `fragment chatPartial on Chat {
|
|
40
|
-
id
|
|
41
|
-
ownerId
|
|
42
|
-
name
|
|
43
|
-
note
|
|
44
|
-
deleted
|
|
45
|
-
photoUri
|
|
46
|
-
unread
|
|
47
|
-
hasAccess
|
|
48
|
-
|
|
49
|
-
type
|
|
50
|
-
status
|
|
51
|
-
liveCategory
|
|
52
|
-
|
|
53
|
-
theme {
|
|
54
|
-
id
|
|
55
|
-
name
|
|
56
|
-
backgroundPhotoUri
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
stickers {
|
|
60
|
-
id
|
|
61
|
-
code
|
|
62
|
-
photoId
|
|
63
|
-
photoUri
|
|
64
|
-
}
|
|
65
|
-
}`;
|
|
66
|
-
|
|
67
|
-
export const chatStatusPartial = `fragment chatStatusPartial on Chat {
|
|
68
|
-
id
|
|
69
|
-
unread
|
|
70
|
-
pinned
|
|
71
|
-
status
|
|
72
|
-
}`;
|
|
73
|
-
|
|
74
|
-
export const chatMessageFragment = `fragment chatMessageFragment on ChatMessage {
|
|
75
|
-
id
|
|
76
|
-
userId
|
|
77
|
-
aiId
|
|
78
|
-
|
|
79
|
-
displayName
|
|
80
|
-
photoUri
|
|
81
|
-
plusStatus
|
|
82
|
-
badge
|
|
83
|
-
message
|
|
84
|
-
attachmentUri
|
|
85
|
-
interactionType
|
|
86
|
-
|
|
87
|
-
metaData {
|
|
88
|
-
stickers
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
createdAt
|
|
92
|
-
updatedAt
|
|
93
|
-
}`;
|
|
94
|
-
|
|
95
|
-
export const chatUserStatusFragment = `fragment chatUserStatusFragment on ChatUserStatus {
|
|
96
|
-
id
|
|
97
|
-
onlineStatus
|
|
98
|
-
}`;
|