@jsb188/graphql 1.1.7 → 1.1.10
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 +14 -4
- package/cache/index.test.ts +319 -0
- package/cache/index.ts +522 -85
- package/client/index.ts +2 -2
- package/client/request.ts +48 -9
- package/deno.test.json +6 -0
- package/gql/fragments/accountFragments.ts +1 -0
- package/gql/fragments/aiChatFragments.ts +1 -0
- package/gql/fragments/dataTableFragments.ts +212 -0
- package/gql/fragments/emailFragments.ts +26 -0
- package/gql/fragments/inboundContactFragments.ts +15 -0
- package/gql/fragments/integrationFragments.ts +22 -0
- package/gql/fragments/logFragments.ts +40 -12
- package/gql/fragments/organizationFragments.ts +59 -24
- package/gql/fragments/productFragments.ts +0 -24
- package/gql/fragments/reportFragments.ts +52 -10
- package/gql/fragments/sheetFragments.ts +145 -0
- package/gql/fragments/storageFragments.ts +3 -1
- package/gql/fragments/workflowFragments.ts +43 -0
- package/gql/mutations/accountMutations.ts +24 -2
- package/gql/mutations/aiChatMutations.ts +28 -1
- package/gql/mutations/authMutations.ts +3 -3
- package/gql/mutations/billingMutations.ts +1 -1
- package/gql/mutations/dataTableMutations.ts +84 -0
- package/gql/mutations/inboundContactMutations.ts +24 -0
- package/gql/mutations/index.ts +12 -8
- package/gql/mutations/integrationMutations.ts +25 -0
- package/gql/mutations/logMutations.ts +15 -1
- package/gql/mutations/organizationMutations.ts +151 -2
- package/gql/mutations/sheetMutations.ts +168 -0
- package/gql/mutations/storageMutations.ts +1 -2
- package/gql/queries/aiChatQueries.ts +1 -1
- package/gql/queries/billingQueries.ts +1 -1
- package/gql/queries/dataTableQueries.ts +45 -0
- package/gql/queries/emailQueries.ts +44 -0
- package/gql/queries/inboundContactQueries.ts +40 -0
- package/gql/queries/index.ts +11 -6
- package/gql/queries/logQueries.ts +47 -20
- package/gql/queries/organizationQueries.ts +62 -8
- package/gql/queries/productQueries.ts +1 -40
- package/gql/queries/reportQueries.ts +81 -13
- package/gql/queries/sheetQueries.ts +72 -0
- package/gql/queries/workflowQueries.ts +30 -0
- package/hooks/index.ts +208 -58
- package/hooks/use-account-mtn.ts +52 -4
- package/hooks/use-aiChat-mtn.ts +62 -6
- package/hooks/use-aiChat-qry.ts +76 -24
- package/hooks/use-app-qry.ts +2 -2
- package/hooks/use-auth-mtn.ts +5 -5
- package/hooks/use-dataTable-mtn.ts +87 -0
- package/hooks/use-dataTable-qry.ts +172 -0
- package/hooks/use-email-qry.ts +112 -0
- package/hooks/use-inboundContact-mtn.ts +31 -0
- package/hooks/use-inboundContact-qry.ts +88 -0
- package/hooks/use-integration-mtn.ts +59 -0
- package/hooks/use-integration-qry.ts +15 -0
- package/hooks/use-log-mtn.ts +6 -6
- package/hooks/use-log-qry.ts +38 -35
- package/hooks/use-organization-mtn.ts +288 -16
- package/hooks/use-organization-qry.ts +71 -22
- package/hooks/use-product-qry.ts +4 -46
- package/hooks/use-report-qry.ts +94 -10
- package/hooks/use-sheet-mtn.ts +181 -0
- package/hooks/use-sheet-qry.ts +157 -0
- package/hooks/use-storage-mtn.ts +6 -5
- package/hooks/use-storage-qry.ts +1 -1
- package/hooks/use-workflow-qry.ts +72 -0
- package/package.json +23 -4
- package/sse.ts +2 -2
- package/tsconfig.json +12 -0
- package/types.d.ts +2 -1
- package/utils.ts +2 -4
- package/gql/fragments/actionFragments.ts +0 -16
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
+
import { updateFragment } from '../cache/index.ts';
|
|
4
|
+
import {
|
|
5
|
+
createIntegrationAuthorizationUrlMtn,
|
|
6
|
+
disconnectIntegrationMtn,
|
|
7
|
+
} from '../gql/mutations/integrationMutations.ts';
|
|
8
|
+
import { useMutation } from './index.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create integration OAuth authorization URL.
|
|
12
|
+
*/
|
|
13
|
+
export function useCreateIntegrationAuthorizationUrl(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
14
|
+
const [createIntegrationAuthorizationUrl, mtnValues, mtnHandlers] = useMutation(createIntegrationAuthorizationUrlMtn, {
|
|
15
|
+
openModalPopUp,
|
|
16
|
+
...params,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
createIntegrationAuthorizationUrl,
|
|
21
|
+
...mtnValues,
|
|
22
|
+
...mtnHandlers,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Disconnect an integration.
|
|
28
|
+
*/
|
|
29
|
+
export function useDisconnectIntegration(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
30
|
+
const { onCompleted, ...otherParams } = params;
|
|
31
|
+
const [disconnectIntegration, mtnValues, mtnHandlers, updateObservers] = useMutation(disconnectIntegrationMtn, {
|
|
32
|
+
openModalPopUp,
|
|
33
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
34
|
+
const disconnectedIntegrationId = data?.disconnectIntegration;
|
|
35
|
+
|
|
36
|
+
if (disconnectedIntegrationId) {
|
|
37
|
+
const organizationFragmentKey = `$organizationFragment:${variables.organizationId}`;
|
|
38
|
+
|
|
39
|
+
updateFragment(
|
|
40
|
+
`$integrationConnectionFragment:${disconnectedIntegrationId}`,
|
|
41
|
+
{ status: 'DISCONNECTED' },
|
|
42
|
+
null,
|
|
43
|
+
false,
|
|
44
|
+
updateObservers,
|
|
45
|
+
[organizationFragmentKey],
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onCompleted?.(disconnectedIntegrationId, error, variables);
|
|
50
|
+
},
|
|
51
|
+
...otherParams,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
disconnectIntegration,
|
|
56
|
+
...mtnValues,
|
|
57
|
+
...mtnHandlers,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useReactiveFragment } from '../client/index.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get reactive integration connection fragment.
|
|
5
|
+
*/
|
|
6
|
+
export function useReactiveIntegrationConnection(integrationConnectionId?: string | null, currentData?: any, queryCount?: number) {
|
|
7
|
+
return useReactiveFragment(
|
|
8
|
+
currentData,
|
|
9
|
+
integrationConnectionId ? [`$integrationConnectionFragment:${integrationConnectionId}`] : [],
|
|
10
|
+
queryCount,
|
|
11
|
+
undefined,
|
|
12
|
+
undefined,
|
|
13
|
+
true,
|
|
14
|
+
);
|
|
15
|
+
}
|
package/hooks/use-log-mtn.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { checkACLPermission } from '@jsb188/mday/utils/organization';
|
|
1
|
+
import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
|
|
2
2
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
3
3
|
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
4
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 { useOrgRelFromMyOrganizations } from './use-organization-qry';
|
|
5
|
+
import { updateFragment } from '../cache/index.ts';
|
|
6
|
+
import { deleteLogEntryMtn, editLogEntryMtn } from '../gql/mutations/logMutations.ts';
|
|
7
|
+
import { useMutation } from './index.ts';
|
|
8
|
+
import { useReactiveLogFragment } from './use-log-qry.ts';
|
|
9
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Fetch a single log entry,
|
package/hooks/use-log-qry.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d';
|
|
2
|
-
import { useQuery, useReactiveFragment } from '../client';
|
|
3
|
-
import { logEntriesQry,
|
|
4
|
-
import type { PaginationArgs, UseQueryParams } from '../types';
|
|
1
|
+
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d.ts';
|
|
2
|
+
import { useQuery, useReactiveFragment } from '../client/index.ts';
|
|
3
|
+
import { logEntriesForReportQry, logEntriesQry, logEntryQry } from '../gql/queries/logQueries.ts';
|
|
4
|
+
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Constants
|
|
@@ -13,16 +13,27 @@ import type { PaginationArgs, UseQueryParams } from '../types';
|
|
|
13
13
|
const LOG_ENTRIES_LIMIT = 250;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Fetch one log entry.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
export function
|
|
19
|
+
export function useLogEntry(
|
|
20
|
+
variables: {
|
|
21
|
+
organizationId?: string | null;
|
|
22
|
+
logEntryId?: string | null;
|
|
23
|
+
},
|
|
24
|
+
params: UseQueryParams = {}
|
|
25
|
+
) {
|
|
26
|
+
const { logEntryId, organizationId } = variables;
|
|
27
|
+
const reactiveLogEntry = useReactiveLogFragment(logEntryId || '');
|
|
28
|
+
const { data, ...rest } = useQuery(logEntryQry, {
|
|
29
|
+
...params,
|
|
30
|
+
variables,
|
|
31
|
+
skip: !!reactiveLogEntry || !organizationId || !logEntryId || params.skip,
|
|
32
|
+
});
|
|
33
|
+
|
|
20
34
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
startDate: null,
|
|
24
|
-
endDate: null,
|
|
25
|
-
query: ''
|
|
35
|
+
logEntry: reactiveLogEntry || data?.logEntry,
|
|
36
|
+
...rest,
|
|
26
37
|
};
|
|
27
38
|
}
|
|
28
39
|
|
|
@@ -34,7 +45,6 @@ export function useLogEntries(
|
|
|
34
45
|
variables: PaginationArgs & {
|
|
35
46
|
organizationId?: string | null;
|
|
36
47
|
accountId?: string;
|
|
37
|
-
timeZone: string | null;
|
|
38
48
|
filter: FilterLogEntriesArgs;
|
|
39
49
|
},
|
|
40
50
|
params: UseQueryParams = {}
|
|
@@ -48,7 +58,7 @@ export function useLogEntries(
|
|
|
48
58
|
limit: LOG_ENTRIES_LIMIT
|
|
49
59
|
},
|
|
50
60
|
// If this query is used for virtualized list pagination, set {params.skip=true}
|
|
51
|
-
skip: !variables.organizationId ||
|
|
61
|
+
skip: !variables.organizationId || params.skip,
|
|
52
62
|
});
|
|
53
63
|
|
|
54
64
|
return {
|
|
@@ -58,32 +68,27 @@ export function useLogEntries(
|
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
61
|
-
* Fetch
|
|
71
|
+
* Fetch all log entries for one report source.
|
|
62
72
|
*/
|
|
63
73
|
|
|
64
|
-
export function
|
|
74
|
+
export function useLogEntriesForReport(
|
|
65
75
|
variables: {
|
|
66
|
-
organizationId
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
after?: boolean,
|
|
70
|
-
limit?: number,
|
|
76
|
+
organizationId?: string | null;
|
|
77
|
+
reportSourceId?: string | null;
|
|
78
|
+
reportSubmissionId: string | null;
|
|
71
79
|
},
|
|
72
80
|
params: UseQueryParams = {}
|
|
73
81
|
) {
|
|
74
|
-
const {
|
|
82
|
+
const { organizationId, reportSourceId, reportSubmissionId } = variables;
|
|
83
|
+
const { data, ...rest } = useQuery(logEntriesForReportQry, {
|
|
75
84
|
...params,
|
|
76
|
-
variables
|
|
77
|
-
|
|
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,
|
|
85
|
+
variables,
|
|
86
|
+
skip: !organizationId || !reportSourceId || !reportSubmissionId || params.skip,
|
|
82
87
|
});
|
|
83
88
|
|
|
84
89
|
return {
|
|
85
|
-
|
|
86
|
-
...rest
|
|
90
|
+
logEntriesForReport: data?.logEntriesForReport,
|
|
91
|
+
...rest,
|
|
87
92
|
};
|
|
88
93
|
}
|
|
89
94
|
|
|
@@ -96,12 +101,10 @@ export function useReactiveLogFragment(logEntryId: string, currentData?: any, qu
|
|
|
96
101
|
currentData,
|
|
97
102
|
[
|
|
98
103
|
`$logEntryFragment:${logEntryId}`,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// This is not needed because $logEntryFragment has spread data
|
|
104
|
-
// [`$accountFragment:${logEntryId}`, 'account']
|
|
104
|
+
[`$logArableFragment:${logEntryId}`, 'details'],
|
|
105
|
+
[`$logFarmersMarketFragment:${logEntryId}`, 'details'],
|
|
106
|
+
[`$logGrowerNetworkFragment:${logEntryId}`, 'details'],
|
|
107
|
+
[`$logLivestockFragment:${logEntryId}`, 'details'],
|
|
105
108
|
],
|
|
106
109
|
queryCount,
|
|
107
110
|
);
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import { checkACL, type OperationName } from '@jsb188/mday/utils/organization.ts';
|
|
2
3
|
import { OpenModalPopUpFn, useCurrentAccount } from '@jsb188/react/states';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { useCallback, useMemo } from 'react';
|
|
5
|
+
import { updateFragment } from '../cache/index.ts';
|
|
6
|
+
import { graphqlRequest } from '../client/request.ts';
|
|
7
|
+
import {
|
|
8
|
+
deleteChildOrganizationMtn,
|
|
9
|
+
deleteComplianceDocumentMtn,
|
|
10
|
+
editChildOrganizationMtn,
|
|
11
|
+
editComplianceDocumentMtn,
|
|
12
|
+
editMembershipMtn,
|
|
13
|
+
editOrganizationMtn,
|
|
14
|
+
editOrganizationInboundEmailMtn,
|
|
15
|
+
editOrganizationSettingsMtn,
|
|
16
|
+
editSiteLocationMtn,
|
|
17
|
+
removeMembershipMtn,
|
|
18
|
+
switchOrganizationMtn
|
|
19
|
+
} from '../gql/mutations/organizationMutations.ts';
|
|
20
|
+
import { useMutation } from './index.ts';
|
|
21
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
|
|
9
22
|
|
|
10
23
|
/**
|
|
11
24
|
* Fetch a single log entry,
|
|
@@ -20,7 +33,7 @@ export function useSwitchOrganization(params: UseMutationParams = {}, openModalP
|
|
|
20
33
|
const [switchOrganization, mtnValues, mtnHandlers] = useMutation(switchOrganizationMtn, {
|
|
21
34
|
// checkMountedBeforeCallback: true,
|
|
22
35
|
openModalPopUp,
|
|
23
|
-
onCompleted: (data, error, variables) => {
|
|
36
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
24
37
|
const result = data?.switchOrganization;
|
|
25
38
|
if (result) {
|
|
26
39
|
// navigate('/app', { replace: true });
|
|
@@ -75,30 +88,289 @@ export function useDeleteComplianceDocument(params: UseMutationParams = {}, open
|
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
/**
|
|
78
|
-
* Edit
|
|
91
|
+
* Edit a compliance document
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
export function useEditComplianceDocument(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
95
|
+
const [editComplianceDocument, mtnValues, mtnHandlers] = useMutation(editComplianceDocumentMtn,
|
|
96
|
+
{
|
|
97
|
+
openModalPopUp,
|
|
98
|
+
...params,
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
editComplianceDocument,
|
|
104
|
+
...mtnValues,
|
|
105
|
+
...mtnHandlers,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Edit an organization
|
|
79
111
|
*/
|
|
80
112
|
|
|
81
113
|
export function useEditOrganization(
|
|
82
114
|
params?: UseMutationParams | null,
|
|
83
115
|
openModalPopUp?: OpenModalPopUpFn
|
|
84
116
|
) {
|
|
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
117
|
const [editOrganization, mtnValues, mtnHandlers] = useMutation(editOrganizationMtn, {
|
|
93
118
|
// checkMountedBeforeCallback: true,
|
|
94
119
|
openModalPopUp,
|
|
95
120
|
...params,
|
|
96
121
|
});
|
|
97
122
|
|
|
123
|
+
return {
|
|
124
|
+
editOrganization,
|
|
125
|
+
...mtnValues,
|
|
126
|
+
...mtnHandlers,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* Edit an organization's inbound email handle.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
export function useEditOrganizationInboundEmail(
|
|
135
|
+
params: UseMutationParams = {},
|
|
136
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
137
|
+
) {
|
|
138
|
+
const { onCompleted, ...rest } = params;
|
|
139
|
+
|
|
140
|
+
const [editOrganizationInboundEmail, mtnValues, mtnHandlers, updateObservers] = useMutation(editOrganizationInboundEmailMtn, {
|
|
141
|
+
openModalPopUp,
|
|
142
|
+
onCompleted: (data, error, variables) => {
|
|
143
|
+
const updatedOrganization = data?.editOrganizationInboundEmail;
|
|
144
|
+
|
|
145
|
+
if (updatedOrganization?.id) {
|
|
146
|
+
updateFragment(
|
|
147
|
+
`$organizationFragment:${updatedOrganization.id}`,
|
|
148
|
+
updatedOrganization,
|
|
149
|
+
null,
|
|
150
|
+
false,
|
|
151
|
+
updateObservers
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
onCompleted?.(updatedOrganization, error, variables);
|
|
156
|
+
},
|
|
157
|
+
...rest,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
editOrganizationInboundEmail,
|
|
162
|
+
...mtnValues,
|
|
163
|
+
...mtnHandlers,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
* Edit an organization's settings.
|
|
169
|
+
*/
|
|
170
|
+
export function useEditOrganizationSettings(
|
|
171
|
+
params?: UseMutationParams | null,
|
|
172
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
173
|
+
) {
|
|
174
|
+
const [editOrganizationSettings, mtnValues, mtnHandlers] = useMutation(editOrganizationSettingsMtn, {
|
|
175
|
+
openModalPopUp,
|
|
176
|
+
...params,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
editOrganizationSettings,
|
|
181
|
+
...mtnValues,
|
|
182
|
+
...mtnHandlers,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
* Return a non-reactive mutation function for background organization settings saves.
|
|
188
|
+
*/
|
|
189
|
+
export function useEditOrganizationSettingsRequest(openModalPopUp?: OpenModalPopUpFn) {
|
|
190
|
+
return useCallback((variables: {
|
|
191
|
+
organizationId: string;
|
|
192
|
+
sidebar?: any[] | null;
|
|
193
|
+
routeId?: string | null;
|
|
194
|
+
columnWidths?: string[] | null;
|
|
195
|
+
}) => {
|
|
196
|
+
return graphqlRequest(
|
|
197
|
+
editOrganizationSettingsMtn,
|
|
198
|
+
variables,
|
|
199
|
+
{
|
|
200
|
+
openModalPopUp,
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
}, [openModalPopUp]);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Edit a child organization from parent organization context
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
export function useEditChildOrganization(
|
|
211
|
+
params?: UseMutationParams | null,
|
|
212
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
213
|
+
) {
|
|
214
|
+
const [editChildOrganization, mtnValues, mtnHandlers] = useMutation(editChildOrganizationMtn, {
|
|
215
|
+
openModalPopUp,
|
|
216
|
+
...params,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
editChildOrganization,
|
|
221
|
+
...mtnValues,
|
|
222
|
+
...mtnHandlers,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Delete a child organization from an organization directory.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
export function useDeleteChildOrganization(
|
|
231
|
+
params: UseMutationParams = {},
|
|
232
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
233
|
+
) {
|
|
234
|
+
const { onCompleted, ...rest } = params;
|
|
235
|
+
|
|
236
|
+
const [deleteChildOrganization, mtnValues, mtnHandlers] = useMutation(deleteChildOrganizationMtn, {
|
|
237
|
+
openModalPopUp,
|
|
238
|
+
onCompleted: (data, error, variables) => {
|
|
239
|
+
const deleted = data?.deleteChildOrganization;
|
|
240
|
+
onCompleted?.(deleted, error, variables);
|
|
241
|
+
},
|
|
242
|
+
...rest,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
deleteChildOrganization,
|
|
247
|
+
...mtnValues,
|
|
248
|
+
...mtnHandlers,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Edit an organization site location.
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
export function useEditSiteLocation(
|
|
257
|
+
params: UseMutationParams = {},
|
|
258
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
259
|
+
) {
|
|
260
|
+
const { onCompleted, ...rest } = params;
|
|
261
|
+
|
|
262
|
+
const [editSiteLocation, mtnValues, mtnHandlers, updateObservers] = useMutation(editSiteLocationMtn, {
|
|
263
|
+
openModalPopUp,
|
|
264
|
+
onCompleted: (data, error, variables) => {
|
|
265
|
+
const updatedSiteLocation = data?.editSiteLocation;
|
|
266
|
+
|
|
267
|
+
if (updatedSiteLocation?.id) {
|
|
268
|
+
updateFragment(
|
|
269
|
+
`$organizationSiteFragment:${updatedSiteLocation.id}`,
|
|
270
|
+
updatedSiteLocation,
|
|
271
|
+
null,
|
|
272
|
+
false,
|
|
273
|
+
updateObservers
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
onCompleted?.(updatedSiteLocation, error, variables);
|
|
278
|
+
},
|
|
279
|
+
...rest,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
editSiteLocation,
|
|
284
|
+
...mtnValues,
|
|
285
|
+
...mtnHandlers,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Edit logged in user's organization with ACL permission check
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
export function useEditOrganizationWithACL(
|
|
294
|
+
params?: UseMutationParams | null,
|
|
295
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
296
|
+
aclOpName: OperationName = 'org_management'
|
|
297
|
+
) {
|
|
298
|
+
const { primaryOrganizationId } = useCurrentAccount();
|
|
299
|
+
const { organizationRelationship } = useOrgRelFromMyOrganizations(primaryOrganizationId);
|
|
300
|
+
const mtnHook = useEditOrganization(params, openModalPopUp);
|
|
301
|
+
|
|
302
|
+
const allowEdit = useMemo(() => {
|
|
303
|
+
return checkACL(organizationRelationship, aclOpName);
|
|
304
|
+
}, [organizationRelationship?.acl, organizationRelationship?.role]);
|
|
305
|
+
|
|
98
306
|
return {
|
|
99
307
|
allowEdit,
|
|
100
308
|
organizationRelationship,
|
|
101
|
-
|
|
309
|
+
...mtnHook
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Edit a membership on an organization
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
export function useEditMembership(
|
|
318
|
+
params: UseMutationParams = {},
|
|
319
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
320
|
+
) {
|
|
321
|
+
const { onCompleted, ...rest } = params;
|
|
322
|
+
|
|
323
|
+
const [editMembership, mtnValues, mtnHandlers, updateObservers] = useMutation(editMembershipMtn, {
|
|
324
|
+
openModalPopUp,
|
|
325
|
+
onCompleted: (data, error, variables) => {
|
|
326
|
+
const updatedMembership = data?.editMembership;
|
|
327
|
+
|
|
328
|
+
if (updatedMembership?.id) {
|
|
329
|
+
updateFragment(
|
|
330
|
+
`$organizationRelationshipFragment:${updatedMembership.id}`,
|
|
331
|
+
updatedMembership,
|
|
332
|
+
null,
|
|
333
|
+
false,
|
|
334
|
+
updateObservers
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
onCompleted?.(updatedMembership, error, variables);
|
|
339
|
+
},
|
|
340
|
+
...rest,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
editMembership,
|
|
345
|
+
...mtnValues,
|
|
346
|
+
...mtnHandlers,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Remove a membership on an organization
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
export function useRemoveMembership(
|
|
355
|
+
params: UseMutationParams = {},
|
|
356
|
+
openModalPopUp?: OpenModalPopUpFn
|
|
357
|
+
) {
|
|
358
|
+
const { onCompleted, ...rest } = params;
|
|
359
|
+
|
|
360
|
+
const [removeMembership, mtnValues, mtnHandlers, updateObservers] = useMutation(removeMembershipMtn, {
|
|
361
|
+
openModalPopUp,
|
|
362
|
+
onCompleted: (data, error, variables) => {
|
|
363
|
+
const removed = data?.removeMembership;
|
|
364
|
+
if (removed) {
|
|
365
|
+
updateFragment(`$organizationRelationshipFragment:${variables.membershipId}`, { __deleted: true }, null, false, updateObservers);
|
|
366
|
+
}
|
|
367
|
+
onCompleted?.(removed, error, variables);
|
|
368
|
+
},
|
|
369
|
+
...rest,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
removeMembership,
|
|
102
374
|
...mtnValues,
|
|
103
375
|
...mtnHandlers,
|
|
104
376
|
};
|