@jsb188/graphql 1.1.5 → 1.1.7
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 +12 -5
- package/cache/index.ts +258 -109
- package/gql/fragments/actionFragments.ts +16 -0
- package/gql/fragments/logFragments.ts +72 -2
- package/gql/fragments/organizationFragments.ts +64 -5
- package/gql/fragments/otherFragments.ts +10 -8
- package/gql/fragments/productFragments.ts +63 -0
- package/gql/fragments/reportFragments.ts +48 -0
- package/gql/fragments/storageFragments.ts +11 -0
- package/gql/mutations/accountMutations.ts +10 -0
- package/gql/mutations/authMutations.ts +11 -16
- package/gql/mutations/index.ts +2 -1
- package/gql/mutations/logMutations.ts +20 -6
- package/gql/mutations/organizationMutations.ts +42 -0
- package/gql/mutations/storageMutations.ts +36 -0
- package/gql/mutations/userAuthMutations.ts +0 -12
- package/gql/queries/aiChatQueries.ts +3 -0
- package/gql/queries/index.ts +6 -0
- package/gql/queries/logQueries.ts +60 -11
- package/gql/queries/organizationQueries.ts +61 -1
- package/gql/queries/productQueries.ts +70 -0
- package/gql/queries/reportQueries.ts +66 -0
- package/hooks/index.ts +146 -45
- package/hooks/use-account-mtn.ts +26 -1
- package/hooks/use-aiChat-mtn.ts +17 -1
- package/hooks/use-aiChat-qry.ts +19 -10
- package/hooks/use-auth-mtn.ts +25 -2
- package/hooks/use-log-mtn.ts +4 -4
- package/hooks/use-log-qry.ts +47 -16
- package/hooks/use-organization-mtn.ts +105 -0
- package/hooks/use-organization-qry.ts +119 -15
- package/hooks/use-product-qry.ts +109 -0
- package/hooks/use-report-qry.ts +69 -0
- package/hooks/use-storage-mtn.ts +56 -0
- package/hooks/use-storage-qry.ts +21 -0
- package/package.json +14 -11
- package/sse.ts +11 -0
- package/gql/mutations/otherMutations.ts +0 -46
- package/gql/queries/otherQueries.ts +0 -12
package/hooks/use-aiChat-qry.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getENVVariable } from '@jsb188/app';
|
|
2
2
|
import { getAuthToken } from '@jsb188/app/utils/api';
|
|
3
|
+
import { makeVariablesKey } from '@jsb188/app/utils/logic';
|
|
3
4
|
import SSE from '@jsb188/sse';
|
|
4
5
|
import { useEffect, useState } from 'react';
|
|
5
|
-
import { loadFragment, loadQuery,
|
|
6
|
+
import { loadFragment, loadQuery, resetQuery, updateQuery } from '../cache/';
|
|
6
7
|
import { useQuery } from '../client';
|
|
7
8
|
import { aiChatMessagesQry, aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries';
|
|
8
9
|
import handleSSEData, { type PublishPayload } from '../sse';
|
|
@@ -12,8 +13,8 @@ import type { UpdateObserversFn, UseQueryParams } from '../types.d';
|
|
|
12
13
|
* Constants
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
|
-
const AI_CHATS_LIMIT =
|
|
16
|
-
const AI_CHAT_MESSAGES_LIMIT =
|
|
16
|
+
const AI_CHATS_LIMIT = 70; // Must match server code exactly
|
|
17
|
+
const AI_CHAT_MESSAGES_LIMIT = 55; // Must match server code exactly
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Helper; get generating (status) key from SSE data
|
|
@@ -49,7 +50,7 @@ function getGeneratingFragmentId(sseData: PublishPayload) {
|
|
|
49
50
|
|
|
50
51
|
export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string | null, params: UseQueryParams = {}) {
|
|
51
52
|
|
|
52
|
-
const { data, ...
|
|
53
|
+
const { data, ...rest } = useQuery(aiChatQry, {
|
|
53
54
|
variables: {
|
|
54
55
|
aiChatId
|
|
55
56
|
},
|
|
@@ -57,7 +58,7 @@ export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string |
|
|
|
57
58
|
...params,
|
|
58
59
|
});
|
|
59
60
|
|
|
60
|
-
const { updateObservers } =
|
|
61
|
+
const { updateObservers } = rest;
|
|
61
62
|
const [sessionKey, setSessionKey] = useState<string | null>(initialSessionKey || null);
|
|
62
63
|
const [generatingFragmentId, setGeneratingFragmentId] = useState<string | null>(null);
|
|
63
64
|
const aiChat = data?.aiChat || loadFragment(`$aiChatFragment:${aiChatId}`);
|
|
@@ -95,7 +96,6 @@ export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string |
|
|
|
95
96
|
};
|
|
96
97
|
|
|
97
98
|
connection.connect(connectParams);
|
|
98
|
-
|
|
99
99
|
// const removeNetworkListeners = reconnectOnBrowserNetwork(connection, connectParams);
|
|
100
100
|
|
|
101
101
|
return () => {
|
|
@@ -134,16 +134,24 @@ export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string |
|
|
|
134
134
|
}, false, updateObservers);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
|
|
138
137
|
}
|
|
139
138
|
}, [dataAIChatId]);
|
|
140
139
|
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
// Force reset if chat message is in progress
|
|
142
|
+
if (aiChat?.inProgress) {
|
|
143
|
+
return () => {
|
|
144
|
+
resetQuery(rest.queryKey, true, updateObservers);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}, [aiChat?.inProgress]);
|
|
148
|
+
|
|
141
149
|
return {
|
|
142
150
|
aiChat,
|
|
143
151
|
generatingFragmentId,
|
|
144
152
|
sessionKey,
|
|
145
153
|
setSessionKey,
|
|
146
|
-
...
|
|
154
|
+
...rest
|
|
147
155
|
};
|
|
148
156
|
}
|
|
149
157
|
|
|
@@ -204,15 +212,16 @@ export function updateAIChats(aiChat: any, updateObservers: UpdateObserversFn) {
|
|
|
204
212
|
* Fetch AI chats list
|
|
205
213
|
*/
|
|
206
214
|
|
|
207
|
-
export function useAIChats(filter?: 'CAL_DATE' | 'CHATS') {
|
|
215
|
+
export function useAIChats(organizationId: string, filter?: 'CAL_DATE' | 'CHATS') {
|
|
208
216
|
const { data, ...other } = useQuery(aiChatsQry, {
|
|
209
217
|
variables: {
|
|
218
|
+
organizationId,
|
|
210
219
|
filter,
|
|
211
220
|
cursor: null,
|
|
212
221
|
after: false,
|
|
213
222
|
limit: AI_CHATS_LIMIT
|
|
214
223
|
},
|
|
215
|
-
skip:
|
|
224
|
+
skip: !organizationId,
|
|
216
225
|
});
|
|
217
226
|
|
|
218
227
|
return {
|
package/hooks/use-auth-mtn.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
|
4
4
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
5
5
|
import { AppContext, onGuestInit, useOpenModalPopUp } from '@jsb188/react/states';
|
|
6
6
|
import React, { useContext, useEffect, useState } from 'react';
|
|
7
|
-
import { changeAccountPasswordMtn, checkUsernameOrEmailMtn, confirmPhoneVerificationCodeMtn, requestTokenizedEmailMtn, sendPhoneVerificationCodeMtn, signUpWithEmailMtn } from '../gql/mutations/authMutations';
|
|
7
|
+
import { changeAccountPasswordMtn, checkUsernameOrEmailMtn, confirmPasswordMtn, confirmPhoneVerificationCodeMtn, requestTokenizedEmailMtn, sendPhoneVerificationCodeMtn, signUpWithEmailMtn } from '../gql/mutations/authMutations';
|
|
8
8
|
import { signOutMtn } from '../gql/mutations/userAuthMutations';
|
|
9
9
|
import { useMutation } from './index';
|
|
10
10
|
|
|
@@ -135,7 +135,7 @@ export function useChangeAccountPasswordForm(params: UseMutationParams = {}) {
|
|
|
135
135
|
|
|
136
136
|
export function useRequestTokenizedEmail(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
137
137
|
const { onCompleted, onError } = params;
|
|
138
|
-
const [requestTokenizedEmail, mtnValues] = useMutation(
|
|
138
|
+
const [requestTokenizedEmail, mtnValues, mtnHandlers] = useMutation(
|
|
139
139
|
requestTokenizedEmailMtn,
|
|
140
140
|
{
|
|
141
141
|
checkMountedBeforeCallback: true,
|
|
@@ -148,6 +148,7 @@ export function useRequestTokenizedEmail(params: UseMutationParams = {}, openMod
|
|
|
148
148
|
return {
|
|
149
149
|
requestTokenizedEmail,
|
|
150
150
|
...mtnValues,
|
|
151
|
+
...mtnHandlers,
|
|
151
152
|
};
|
|
152
153
|
}
|
|
153
154
|
|
|
@@ -254,6 +255,28 @@ export function useSignUpWithEmail(params: AuthHookParams = {}, openModalPopUp?:
|
|
|
254
255
|
};
|
|
255
256
|
}
|
|
256
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Confirm password
|
|
260
|
+
* NOTE: *must* be signed in already
|
|
261
|
+
*/
|
|
262
|
+
|
|
263
|
+
export function useConfirmPassword(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
264
|
+
const [confirmPassword, mtnValues, mtnHandlers] = useMutation(
|
|
265
|
+
confirmPasswordMtn,
|
|
266
|
+
{
|
|
267
|
+
checkMountedBeforeCallback: true,
|
|
268
|
+
openModalPopUp,
|
|
269
|
+
...params,
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
confirmPassword,
|
|
275
|
+
...mtnValues,
|
|
276
|
+
...mtnHandlers,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
257
280
|
// Before are deprecated HOC that needs to be migrated to hooks
|
|
258
281
|
// Before are deprecated HOC that needs to be migrated to hooks
|
|
259
282
|
// Before are deprecated HOC that needs to be migrated to hooks
|
package/hooks/use-log-mtn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkACLPermission } from '@jsb188/
|
|
1
|
+
import { checkACLPermission } from '@jsb188/mday/utils/organization';
|
|
2
2
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
3
3
|
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
4
|
import { useMemo } from 'react';
|
|
@@ -6,7 +6,7 @@ import { updateFragment } from '../cache/index';
|
|
|
6
6
|
import { deleteLogEntryMtn, editLogEntryMtn } from '../gql/mutations/logMutations';
|
|
7
7
|
import { useMutation } from './index';
|
|
8
8
|
import { useReactiveLogFragment } from './use-log-qry';
|
|
9
|
-
import {
|
|
9
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Fetch a single log entry,
|
|
@@ -21,7 +21,7 @@ export function useEditLogEntry(
|
|
|
21
21
|
openModalPopUp?: OpenModalPopUpFn
|
|
22
22
|
) {
|
|
23
23
|
|
|
24
|
-
const { organizationRelationship } =
|
|
24
|
+
const { organizationRelationship } = useOrgRelFromMyOrganizations(organizationId);
|
|
25
25
|
const notReady = !organizationRelationship;
|
|
26
26
|
|
|
27
27
|
const [editLogEntry, mtnValues, mtnHandlers] = useMutation(
|
|
@@ -36,7 +36,7 @@ export function useEditLogEntry(
|
|
|
36
36
|
const logEntry = useReactiveLogFragment(logEntryId, null, mtnValues.mutationCount);
|
|
37
37
|
// const logEntry = useReactiveFragment(
|
|
38
38
|
// null,
|
|
39
|
-
// [`$logEntryFragment:${logEntryId}`, [`$
|
|
39
|
+
// [`$logEntryFragment:${logEntryId}`, [`$logArableFragment:${logEntryId}`, 'details']],
|
|
40
40
|
// mtnValues.mutationCount,
|
|
41
41
|
// );
|
|
42
42
|
|
package/hooks/use-log-qry.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d';
|
|
2
2
|
import { useQuery, useReactiveFragment } from '../client';
|
|
3
|
-
import { logEntriesQry } from '../gql/queries/logQueries';
|
|
3
|
+
import { logEntriesQry, logEvidencesQry } from '../gql/queries/logQueries';
|
|
4
4
|
import type { PaginationArgs, UseQueryParams } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Constants
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// I tried 100, but that was way too small.
|
|
11
|
+
// Having less data is better for performance for iPads and low-end devices, because it might reduce brief rendering mishaps,
|
|
12
|
+
// But a decent amount of visual load size is needed for Virtualized List to work well.
|
|
13
|
+
const LOG_ENTRIES_LIMIT = 250;
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Helper; use this to get/use same filter for logEntries() query everywhere
|
|
@@ -27,16 +30,17 @@ export function getDefaultLogEntriesFilter(operation: FilterLogEntriesArgs['oper
|
|
|
27
30
|
* Fetch log entries
|
|
28
31
|
*/
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
export function useLogEntries(
|
|
34
|
+
variables: PaginationArgs & {
|
|
35
|
+
organizationId?: string | null;
|
|
36
|
+
accountId?: string;
|
|
37
|
+
timeZone: string | null;
|
|
38
|
+
filter: FilterLogEntriesArgs;
|
|
39
|
+
},
|
|
40
|
+
params: UseQueryParams = {}
|
|
41
|
+
) {
|
|
39
42
|
const { data, ...rest } = useQuery(logEntriesQry, {
|
|
43
|
+
...params,
|
|
40
44
|
variables: {
|
|
41
45
|
...variables,
|
|
42
46
|
cursor: null,
|
|
@@ -44,8 +48,7 @@ export function useLogEntries(variables: LogEntriesArgs, params: UseQueryParams
|
|
|
44
48
|
limit: LOG_ENTRIES_LIMIT
|
|
45
49
|
},
|
|
46
50
|
// If this query is used for virtualized list pagination, set {params.skip=true}
|
|
47
|
-
skip: !variables.organizationId || !variables.filter?.operation,
|
|
48
|
-
...params,
|
|
51
|
+
skip: !variables.organizationId || !variables.filter?.operation || params.skip,
|
|
49
52
|
});
|
|
50
53
|
|
|
51
54
|
return {
|
|
@@ -54,6 +57,36 @@ export function useLogEntries(variables: LogEntriesArgs, params: UseQueryParams
|
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Fetch logs as evidences for a specific report
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
export function useLogEvidences(
|
|
65
|
+
variables: {
|
|
66
|
+
organizationId: string,
|
|
67
|
+
reportId: string,
|
|
68
|
+
cursor?: string | null,
|
|
69
|
+
after?: boolean,
|
|
70
|
+
limit?: number,
|
|
71
|
+
},
|
|
72
|
+
params: UseQueryParams = {}
|
|
73
|
+
) {
|
|
74
|
+
const { data, ...rest } = useQuery(logEvidencesQry, {
|
|
75
|
+
...params,
|
|
76
|
+
variables: {
|
|
77
|
+
...variables,
|
|
78
|
+
after: variables.after ?? true,
|
|
79
|
+
limit: variables.limit ?? 1000, // Change this when we have pagination support
|
|
80
|
+
},
|
|
81
|
+
skip: !variables.organizationId || !variables.reportId || params.skip,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
logEvidences: data?.logEvidences,
|
|
86
|
+
...rest
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
/**
|
|
58
91
|
* Get reactive log fragment
|
|
59
92
|
*/
|
|
@@ -65,13 +98,11 @@ export function useReactiveLogFragment(logEntryId: string, currentData?: any, qu
|
|
|
65
98
|
`$logEntryFragment:${logEntryId}`,
|
|
66
99
|
|
|
67
100
|
// By having the second paramter as null, we only observe the reactive changes without setting the data
|
|
68
|
-
[`$
|
|
101
|
+
// [`$logArableFragment:${logEntryId}`, null],
|
|
69
102
|
|
|
70
103
|
// This is not needed because $logEntryFragment has spread data
|
|
71
104
|
// [`$accountFragment:${logEntryId}`, 'account']
|
|
72
105
|
],
|
|
73
106
|
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
107
|
);
|
|
77
108
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import { OpenModalPopUpFn, useCurrentAccount } from '@jsb188/react/states';
|
|
3
|
+
import { updateFragment } from '../cache/index';
|
|
4
|
+
import { deleteComplianceDocumentMtn, editOrganizationMtn, switchOrganizationMtn } from '../gql/mutations/organizationMutations';
|
|
5
|
+
import { useMutation } from './index';
|
|
6
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry';
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
import { checkACLPermission } from '@jsb188/mday/utils/organization';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fetch a single log entry,
|
|
12
|
+
* from cache first; only check server if cache is not found.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function useSwitchOrganization(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
16
|
+
const { onCompleted, ...otherParams } = params;
|
|
17
|
+
// const navigate = useNavigate();
|
|
18
|
+
const { dispatchApp, account, primaryOrganizationId } = useCurrentAccount();
|
|
19
|
+
|
|
20
|
+
const [switchOrganization, mtnValues, mtnHandlers] = useMutation(switchOrganizationMtn, {
|
|
21
|
+
// checkMountedBeforeCallback: true,
|
|
22
|
+
openModalPopUp,
|
|
23
|
+
onCompleted: (data, error, variables) => {
|
|
24
|
+
const result = data?.switchOrganization;
|
|
25
|
+
if (result) {
|
|
26
|
+
// navigate('/app', { replace: true });
|
|
27
|
+
dispatchApp({
|
|
28
|
+
__type: 'APP_SWITCH_PRIMARY_ORGANIZATION',
|
|
29
|
+
data: {
|
|
30
|
+
primaryOrganizationId: variables.organizationId,
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
onCompleted?.(result, error);
|
|
36
|
+
},
|
|
37
|
+
...otherParams,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
switchOrganization,
|
|
42
|
+
...mtnValues,
|
|
43
|
+
...mtnHandlers,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Delete a compliance document
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export function useDeleteComplianceDocument(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
52
|
+
const { onCompleted, ...otherParams } = params;
|
|
53
|
+
|
|
54
|
+
const [deleteComplianceDocument, mtnValues, mtnHandlers, updateObservers] = useMutation(deleteComplianceDocumentMtn,
|
|
55
|
+
{
|
|
56
|
+
// checkMountedBeforeCallback: true,
|
|
57
|
+
openModalPopUp,
|
|
58
|
+
onCompleted: (data, error, variables) => {
|
|
59
|
+
const deleted = data?.deleteComplianceDocument;
|
|
60
|
+
if (deleted) {
|
|
61
|
+
updateFragment(`$organizationComplianceFragment:${variables.complianceId}`, { __deleted: true }, null, false, updateObservers);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
onCompleted?.(deleted, error);
|
|
65
|
+
},
|
|
66
|
+
...otherParams,
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
deleteComplianceDocument,
|
|
72
|
+
...mtnValues,
|
|
73
|
+
...mtnHandlers,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Edit logged in user's organization (if allowed)
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export function useEditOrganization(
|
|
82
|
+
params?: UseMutationParams | null,
|
|
83
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
84
|
+
) {
|
|
85
|
+
const { primaryOrganizationId } = useCurrentAccount();
|
|
86
|
+
const { organizationRelationship } = useOrgRelFromMyOrganizations(primaryOrganizationId);
|
|
87
|
+
const allowEdit = useMemo(() =>
|
|
88
|
+
checkACLPermission(organizationRelationship, 'orgManagement', 'MANAGE'),
|
|
89
|
+
[organizationRelationship?.acl, organizationRelationship?.role]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const [editOrganization, mtnValues, mtnHandlers] = useMutation(editOrganizationMtn, {
|
|
93
|
+
// checkMountedBeforeCallback: true,
|
|
94
|
+
openModalPopUp,
|
|
95
|
+
...params,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
allowEdit,
|
|
100
|
+
organizationRelationship,
|
|
101
|
+
editOrganization,
|
|
102
|
+
...mtnValues,
|
|
103
|
+
...mtnHandlers,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -1,37 +1,141 @@
|
|
|
1
|
-
import { useQuery } from '@jsb188/graphql/client';
|
|
2
|
-
import {
|
|
3
|
-
import type { UseQueryParams } from '../types.d';
|
|
1
|
+
import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
|
|
2
|
+
import { childOrganizationsQry, myOrganizationsQry, organizationWorkflowsQry } from '../gql/queries/organizationQueries';
|
|
3
|
+
import type { PaginationArgs, UseQueryParams } from '../types.d';
|
|
4
|
+
import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d';
|
|
5
|
+
|
|
6
|
+
const ORG_CHILDREN_LIMIT = 250;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Fetch my organizations
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export function useMyOrganizations(params: UseQueryParams = {}) {
|
|
13
|
+
const { data, ...rest } = useQuery(myOrganizationsQry, params);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
myOrganizations: data?.myOrganizations,
|
|
17
|
+
...rest
|
|
18
|
+
};
|
|
19
|
+
}
|
|
4
20
|
|
|
5
21
|
/**
|
|
6
|
-
* Fetch organization
|
|
22
|
+
* Fetch organization workflows
|
|
7
23
|
*/
|
|
8
24
|
|
|
9
|
-
export function
|
|
10
|
-
const { data, ...
|
|
25
|
+
export function useOrganizationWorkflows(organizationId: string | null, operation: OrganizationOperationEnum | null) {
|
|
26
|
+
const { data, ...rest } = useQuery(organizationWorkflowsQry, {
|
|
11
27
|
variables: {
|
|
12
|
-
organizationId
|
|
28
|
+
organizationId,
|
|
29
|
+
operation,
|
|
13
30
|
},
|
|
31
|
+
skip: !organizationId || !operation,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
organizationWorkflows: data?.organizationWorkflows,
|
|
36
|
+
...rest
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get reactive organization fragment
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
export function useReactiveOrganizationWorkflowFragment(workflowId: string, currentData?: any, queryCount?: number) {
|
|
45
|
+
return useReactiveFragment(
|
|
46
|
+
currentData,
|
|
47
|
+
[`$organizationInstructionsFragment:${workflowId}`],
|
|
48
|
+
queryCount,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get reactive organization fragment
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export function useReactiveOrganization(orgId: string, currentData?: any, queryCount?: number) {
|
|
57
|
+
return useReactiveFragment(
|
|
58
|
+
currentData,
|
|
59
|
+
[`$organizationFragment:${orgId}`],
|
|
60
|
+
queryCount,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Fetch my organizations and then get one by ID
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
export function useOrgRelFromMyOrganizations(organizationId: string | null) {
|
|
69
|
+
const { myOrganizations, ...rest } = useMyOrganizations({
|
|
14
70
|
skip: !organizationId,
|
|
15
|
-
...params,
|
|
16
71
|
});
|
|
17
72
|
|
|
73
|
+
const orgRel = myOrganizations?.find((orgRel: any) => orgRel.organization?.id === organizationId) || null;
|
|
74
|
+
const organization = useReactiveOrganization(orgRel?.organization?.id, orgRel?.organization);
|
|
75
|
+
|
|
18
76
|
return {
|
|
19
|
-
organizationRelationship:
|
|
20
|
-
|
|
77
|
+
organizationRelationship: orgRel,
|
|
78
|
+
organization,
|
|
79
|
+
myOrganizations,
|
|
80
|
+
...rest
|
|
21
81
|
};
|
|
22
82
|
}
|
|
23
83
|
|
|
24
84
|
/**
|
|
25
|
-
* Fetch
|
|
85
|
+
* Fetch child organizations
|
|
26
86
|
*/
|
|
27
87
|
|
|
28
|
-
export function
|
|
29
|
-
|
|
88
|
+
export function useChildOrganizations(variables: PaginationArgs & {
|
|
89
|
+
organizationId?: string | null;
|
|
90
|
+
// filters: ? not ready yet
|
|
91
|
+
}, params: UseQueryParams = {}) {
|
|
92
|
+
const { data, ...rest } = useQuery(childOrganizationsQry, {
|
|
93
|
+
variables: {
|
|
94
|
+
...variables,
|
|
95
|
+
cursor: null,
|
|
96
|
+
after: true,
|
|
97
|
+
limit: ORG_CHILDREN_LIMIT
|
|
98
|
+
},
|
|
99
|
+
skip: !variables.organizationId,
|
|
30
100
|
...params,
|
|
31
101
|
});
|
|
32
102
|
|
|
33
103
|
return {
|
|
34
|
-
|
|
35
|
-
...
|
|
104
|
+
childOrganizations: data?.childOrganizations,
|
|
105
|
+
...rest
|
|
36
106
|
};
|
|
37
107
|
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get reactive organization fragment
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
export function useReactiveOrganizationChildFragment(childId: string, currentData?: any, queryCount?: number) {
|
|
114
|
+
return useReactiveFragment(
|
|
115
|
+
currentData,
|
|
116
|
+
[
|
|
117
|
+
`$organizationChildFragment:${childId}`,
|
|
118
|
+
// [`$organizationChildArableFragment:${childId}`, null],
|
|
119
|
+
// By having the second paramter as null, we only observe the reactive changes without setting the data
|
|
120
|
+
// [`$logArableFragment:${logEntryId}`, null],
|
|
121
|
+
],
|
|
122
|
+
queryCount,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get reactive organization compliance document fragment
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
export function useReactiveOrganizationComplianceFragment(complianceId: string, currentData?: any, queryCount?: number) {
|
|
131
|
+
return useReactiveFragment(
|
|
132
|
+
currentData,
|
|
133
|
+
[
|
|
134
|
+
`$organizationComplianceFragment:${complianceId}`,
|
|
135
|
+
// [`$organizationChildArableFragment:${organizationId}`, null],
|
|
136
|
+
// By having the second paramter as null, we only observe the reactive changes without setting the data
|
|
137
|
+
// [`$logArableFragment:${logEntryId}`, null],
|
|
138
|
+
],
|
|
139
|
+
queryCount,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { checkACLPermission } from '@jsb188/mday/utils/organization';
|
|
2
|
+
import type { ProductsFilterArgs } from '@jsb188/mday/types/product.d';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useQuery, useReactiveFragment } from '../client';
|
|
5
|
+
import { productAttendanceListQry, productsListQry } from '../gql/queries/productQueries';
|
|
6
|
+
import type { PaginationArgs, UseQueryParams } from '../types';
|
|
7
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constants
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const PRODUCTS_LIST_LIMIT = 200;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Helper; use this to get/use same filter for productsList() query everywhere
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// export function getDefaultProductsListFilter(operation: FilterProductsListArgs['operation']): FilterProductsListArgs {
|
|
20
|
+
// return {
|
|
21
|
+
// operation,
|
|
22
|
+
// types: null,
|
|
23
|
+
// startDate: null,
|
|
24
|
+
// endDate: null,
|
|
25
|
+
// query: ''
|
|
26
|
+
// };
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fetch log entries
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
export function useProductsList(
|
|
34
|
+
variables: PaginationArgs & {
|
|
35
|
+
organizationId?: string | null;
|
|
36
|
+
filter: ProductsFilterArgs;
|
|
37
|
+
},
|
|
38
|
+
params: UseQueryParams = {}
|
|
39
|
+
) {
|
|
40
|
+
const { data, ...rest } = useQuery(productsListQry, {
|
|
41
|
+
variables: {
|
|
42
|
+
...variables,
|
|
43
|
+
cursor: null,
|
|
44
|
+
after: false,
|
|
45
|
+
limit: PRODUCTS_LIST_LIMIT
|
|
46
|
+
},
|
|
47
|
+
// If this query is used for virtualized list pagination, set {params.skip=true}
|
|
48
|
+
skip: !variables.organizationId,
|
|
49
|
+
...params,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
productsList: data?.productsList,
|
|
54
|
+
...rest
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get reactive log fragment
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
export function useReactiveProductFragment(productId: string, currentData?: any, queryCount?: number) {
|
|
63
|
+
return useReactiveFragment(
|
|
64
|
+
currentData,
|
|
65
|
+
[
|
|
66
|
+
`$productFragment:${productId}`,
|
|
67
|
+
],
|
|
68
|
+
queryCount,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Fetch Org Event attendance, ACL, and Org Event fragment from cache
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
export function useProductAttendance(
|
|
77
|
+
variables: {
|
|
78
|
+
organizationId: string;
|
|
79
|
+
productId: string;
|
|
80
|
+
calDate: string;
|
|
81
|
+
},
|
|
82
|
+
params: UseQueryParams = {},
|
|
83
|
+
) {
|
|
84
|
+
|
|
85
|
+
const { organizationId, productId, calDate } = variables;
|
|
86
|
+
const { organizationRelationship } = useOrgRelFromMyOrganizations(organizationId);
|
|
87
|
+
|
|
88
|
+
const { data, ...rest } = useQuery(productAttendanceListQry, {
|
|
89
|
+
variables,
|
|
90
|
+
skip: !productId || !calDate || !organizationId,
|
|
91
|
+
...params,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const productAttendanceList = data?.productAttendanceList;
|
|
95
|
+
const notReady = !organizationRelationship || !productAttendanceList;
|
|
96
|
+
|
|
97
|
+
const allowEdit = useMemo(() => {
|
|
98
|
+
return checkACLPermission(organizationRelationship, 'products', 'MANAGE');
|
|
99
|
+
}, [organizationRelationship?.acl, organizationRelationship?.role]);
|
|
100
|
+
|
|
101
|
+
// console.log('viewerAccountId', viewerAccountId, organizationEvent?.accountId, isMyDocument, allowEdit);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
productAttendanceList,
|
|
105
|
+
notReady,
|
|
106
|
+
allowEdit,
|
|
107
|
+
...rest
|
|
108
|
+
};
|
|
109
|
+
}
|