@aglyn/plugins-crm 1.0.0-beta.217 → 1.0.0-beta.219

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 (249) hide show
  1. package/package.json +14 -13
  2. package/src/index.d.ts +1 -0
  3. package/src/index.js.map +1 -1
  4. package/src/lib/components/companies-bulk-bar.js +12 -4
  5. package/src/lib/components/companies-bulk-bar.js.map +1 -1
  6. package/src/lib/components/company-detail-page.js +11 -0
  7. package/src/lib/components/company-detail-page.js.map +1 -1
  8. package/src/lib/components/company-edit-drawer.js +12 -2
  9. package/src/lib/components/company-edit-drawer.js.map +1 -1
  10. package/src/lib/components/company-import-drawer.d.ts +1 -1
  11. package/src/lib/components/company-picker.js +10 -3
  12. package/src/lib/components/company-picker.js.map +1 -1
  13. package/src/lib/components/contact-detail-page.d.ts +4 -4
  14. package/src/lib/components/contact-detail-page.js +50 -53
  15. package/src/lib/components/contact-detail-page.js.map +1 -1
  16. package/src/lib/components/contact-list-columns.d.ts +3 -0
  17. package/src/lib/components/contact-list-columns.js +21 -5
  18. package/src/lib/components/contact-list-columns.js.map +1 -1
  19. package/src/lib/components/contact-merge-dialog.js +2 -1
  20. package/src/lib/components/contact-merge-dialog.js.map +1 -1
  21. package/src/lib/components/contact-timeline-card.js +4 -3
  22. package/src/lib/components/contact-timeline-card.js.map +1 -1
  23. package/src/lib/components/contacts-bulk-bar.d.ts +3 -3
  24. package/src/lib/components/contacts-bulk-bar.js +24 -51
  25. package/src/lib/components/contacts-bulk-bar.js.map +1 -1
  26. package/src/lib/components/contacts-section.js +9 -3
  27. package/src/lib/components/contacts-section.js.map +1 -1
  28. package/src/lib/components/crm-export-all-button.d.ts +1 -1
  29. package/src/lib/components/crm-export-all-button.js.map +1 -1
  30. package/src/lib/components/crm-send-email-dialog.js +9 -6
  31. package/src/lib/components/crm-send-email-dialog.js.map +1 -1
  32. package/src/lib/components/csv-import-drawer.js +2 -2
  33. package/src/lib/components/csv-import-drawer.js.map +1 -1
  34. package/src/lib/components/deal-detail-page.js +18 -2
  35. package/src/lib/components/deal-detail-page.js.map +1 -1
  36. package/src/lib/components/deal-edit-drawer.js +10 -0
  37. package/src/lib/components/deal-edit-drawer.js.map +1 -1
  38. package/src/lib/components/deals-bulk-bar.js +13 -5
  39. package/src/lib/components/deals-bulk-bar.js.map +1 -1
  40. package/src/lib/components/lead-campaigns-card.js +6 -0
  41. package/src/lib/components/lead-campaigns-card.js.map +1 -1
  42. package/src/lib/components/lead-detail-page.js +25 -5
  43. package/src/lib/components/lead-detail-page.js.map +1 -1
  44. package/src/lib/components/lead-properties-card.js +6 -0
  45. package/src/lib/components/lead-properties-card.js.map +1 -1
  46. package/src/lib/components/lead-surfaces-note.js +4 -5
  47. package/src/lib/components/lead-surfaces-note.js.map +1 -1
  48. package/src/lib/components/lead-unqualify-dialog.js +6 -0
  49. package/src/lib/components/lead-unqualify-dialog.js.map +1 -1
  50. package/src/lib/components/leads-bulk-bar.js +28 -3
  51. package/src/lib/components/leads-bulk-bar.js.map +1 -1
  52. package/src/lib/components/leads-section.js +36 -7
  53. package/src/lib/components/leads-section.js.map +1 -1
  54. package/src/lib/components/org-lead-surfaces-note.js +6 -2
  55. package/src/lib/components/org-lead-surfaces-note.js.map +1 -1
  56. package/src/lib/components/recipes-card.js +9 -4
  57. package/src/lib/components/recipes-card.js.map +1 -1
  58. package/src/lib/components/record-sharing-card.d.ts +57 -0
  59. package/src/lib/components/record-sharing-card.js +244 -0
  60. package/src/lib/components/record-sharing-card.js.map +1 -0
  61. package/src/lib/components/settings-section.js +7 -0
  62. package/src/lib/components/settings-section.js.map +1 -1
  63. package/src/lib/components/share-records-dialog.d.ts +28 -0
  64. package/src/lib/components/share-records-dialog.js +184 -0
  65. package/src/lib/components/share-records-dialog.js.map +1 -0
  66. package/src/lib/components/sharing-rule-drawer.d.ts +37 -0
  67. package/src/lib/components/sharing-rule-drawer.js +374 -0
  68. package/src/lib/components/sharing-rule-drawer.js.map +1 -0
  69. package/src/lib/components/sharing-rules-card.d.ts +24 -0
  70. package/src/lib/components/sharing-rules-card.js +287 -0
  71. package/src/lib/components/sharing-rules-card.js.map +1 -0
  72. package/src/lib/components/use-crm-api.d.ts +1 -1
  73. package/src/lib/components/use-crm-api.js.map +1 -1
  74. package/src/lib/components/use-site-route-context.d.ts +25 -0
  75. package/src/lib/components/use-site-route-context.js +58 -0
  76. package/src/lib/components/use-site-route-context.js.map +1 -0
  77. package/src/lib/constants/api-routes.d.ts +31 -0
  78. package/src/lib/constants/api-routes.js +27 -1
  79. package/src/lib/constants/api-routes.js.map +1 -1
  80. package/src/lib/declarations.console-server.d.ts +37 -0
  81. package/src/lib/declarations.console-server.js +103 -0
  82. package/src/lib/declarations.console-server.js.map +1 -0
  83. package/src/lib/declarations.server.d.ts +6 -0
  84. package/src/lib/declarations.server.js +33 -0
  85. package/src/lib/declarations.server.js.map +1 -1
  86. package/src/lib/hooks/use-contact-remove.d.ts +35 -0
  87. package/src/lib/hooks/use-contact-remove.js +77 -0
  88. package/src/lib/hooks/use-contact-remove.js.map +1 -0
  89. package/src/lib/hooks/use-crm-sharing.d.ts +30 -0
  90. package/src/lib/hooks/use-crm-sharing.js +109 -0
  91. package/src/lib/hooks/use-crm-sharing.js.map +1 -0
  92. package/src/lib/model/companies-csv.d.ts +1 -1
  93. package/src/lib/model/companies-csv.js +2 -2
  94. package/src/lib/model/companies-csv.js.map +1 -1
  95. package/src/lib/model/contact-holder.d.ts +68 -0
  96. package/src/lib/model/contact-holder.js +129 -0
  97. package/src/lib/model/contact-holder.js.map +1 -0
  98. package/src/lib/model/contact-interaction-links.d.ts +46 -0
  99. package/src/lib/model/contact-interaction-links.js +65 -0
  100. package/src/lib/model/contact-interaction-links.js.map +1 -0
  101. package/src/lib/model/contact-merge.d.ts +136 -0
  102. package/src/lib/model/contact-merge.js +412 -0
  103. package/src/lib/model/contact-merge.js.map +1 -0
  104. package/src/lib/model/contact-record.d.ts +7 -1
  105. package/src/lib/model/contact-record.js +6 -5
  106. package/src/lib/model/contact-record.js.map +1 -1
  107. package/src/lib/model/contact-remove.d.ts +48 -0
  108. package/src/lib/model/contact-remove.js +22 -0
  109. package/src/lib/model/contact-remove.js.map +1 -0
  110. package/src/lib/model/contacts-bulk-writes.d.ts +2 -71
  111. package/src/lib/model/contacts-bulk-writes.js +2 -82
  112. package/src/lib/model/contacts-bulk-writes.js.map +1 -1
  113. package/src/lib/model/contacts-csv.d.ts +2 -2
  114. package/src/lib/model/contacts-csv.js +2 -2
  115. package/src/lib/model/contacts-csv.js.map +1 -1
  116. package/src/lib/model/crm-csv.d.ts +239 -0
  117. package/src/lib/model/crm-csv.js +467 -0
  118. package/src/lib/model/crm-csv.js.map +1 -0
  119. package/src/lib/model/crm-digest.d.ts +185 -0
  120. package/src/lib/model/crm-digest.js +272 -0
  121. package/src/lib/model/crm-digest.js.map +1 -0
  122. package/src/lib/model/crm-import.d.ts +7 -1
  123. package/src/lib/model/crm-import.js +2 -1
  124. package/src/lib/model/crm-import.js.map +1 -1
  125. package/src/lib/model/crm-record-routes.d.ts +5 -0
  126. package/src/lib/model/crm-record-routes.js +7 -0
  127. package/src/lib/model/crm-record-routes.js.map +1 -1
  128. package/src/lib/model/crm-routes.d.ts +6 -5
  129. package/src/lib/model/crm-routes.js +7 -7
  130. package/src/lib/model/crm-routes.js.map +1 -1
  131. package/src/lib/model/crm-search-sources.d.ts +15 -0
  132. package/src/lib/model/crm-search-sources.js +162 -0
  133. package/src/lib/model/crm-search-sources.js.map +1 -0
  134. package/src/lib/model/crm-sharing-api.d.ts +32 -0
  135. package/src/lib/model/crm-sharing-api.js +59 -0
  136. package/src/lib/model/crm-sharing-api.js.map +1 -0
  137. package/src/lib/model/crm-sharing.d.ts +333 -0
  138. package/src/lib/model/crm-sharing.js +603 -0
  139. package/src/lib/model/crm-sharing.js.map +1 -0
  140. package/src/lib/model/deals-csv.d.ts +1 -1
  141. package/src/lib/model/deals-csv.js +4 -5
  142. package/src/lib/model/deals-csv.js.map +1 -1
  143. package/src/lib/model/lead-filters.d.ts +1 -1
  144. package/src/lib/model/leads-csv.d.ts +1 -1
  145. package/src/lib/model/leads-csv.js +1 -1
  146. package/src/lib/model/leads-csv.js.map +1 -1
  147. package/src/lib/model/tasks-csv.d.ts +1 -1
  148. package/src/lib/model/tasks-csv.js +1 -1
  149. package/src/lib/model/tasks-csv.js.map +1 -1
  150. package/src/lib/plan-entitlements.d.ts +75 -0
  151. package/src/lib/plan-entitlements.js +56 -0
  152. package/src/lib/plan-entitlements.js.map +1 -0
  153. package/src/lib/plugin.js +3 -0
  154. package/src/lib/plugin.js.map +1 -1
  155. package/src/lib/server/api-v1/contacts-merge.d.ts +20 -0
  156. package/src/lib/server/api-v1/contacts-merge.js +120 -0
  157. package/src/lib/server/api-v1/contacts-merge.js.map +1 -0
  158. package/src/lib/server/api-v1/contacts.d.ts +18 -0
  159. package/src/lib/server/api-v1/contacts.js +1076 -0
  160. package/src/lib/server/api-v1/contacts.js.map +1 -0
  161. package/src/lib/server/api-v1/crm-activities.d.ts +18 -0
  162. package/src/lib/server/api-v1/crm-activities.js +269 -0
  163. package/src/lib/server/api-v1/crm-activities.js.map +1 -0
  164. package/src/lib/server/api-v1/crm-companies.d.ts +18 -0
  165. package/src/lib/server/api-v1/crm-companies.js +391 -0
  166. package/src/lib/server/api-v1/crm-companies.js.map +1 -0
  167. package/src/lib/server/api-v1/crm-deals.d.ts +18 -0
  168. package/src/lib/server/api-v1/crm-deals.js +631 -0
  169. package/src/lib/server/api-v1/crm-deals.js.map +1 -0
  170. package/src/lib/server/api-v1/crm-email-templates.d.ts +18 -0
  171. package/src/lib/server/api-v1/crm-email-templates.js +336 -0
  172. package/src/lib/server/api-v1/crm-email-templates.js.map +1 -0
  173. package/src/lib/server/api-v1/crm-leads.d.ts +18 -0
  174. package/src/lib/server/api-v1/crm-leads.js +832 -0
  175. package/src/lib/server/api-v1/crm-leads.js.map +1 -0
  176. package/src/lib/server/api-v1/crm-pipelines.d.ts +76 -0
  177. package/src/lib/server/api-v1/crm-pipelines.js +146 -0
  178. package/src/lib/server/api-v1/crm-pipelines.js.map +1 -0
  179. package/src/lib/server/api-v1/crm-shared.d.ts +271 -0
  180. package/src/lib/server/api-v1/crm-shared.js +436 -0
  181. package/src/lib/server/api-v1/crm-shared.js.map +1 -0
  182. package/src/lib/server/api-v1/crm-tasks.d.ts +18 -0
  183. package/src/lib/server/api-v1/crm-tasks.js +398 -0
  184. package/src/lib/server/api-v1/crm-tasks.js.map +1 -0
  185. package/src/lib/server/api-v1/openapi.d.ts +29 -0
  186. package/src/lib/server/api-v1/openapi.js +985 -0
  187. package/src/lib/server/api-v1/openapi.js.map +1 -0
  188. package/src/lib/server/api-v1/usage.d.ts +26 -0
  189. package/src/lib/server/api-v1/usage.js +73 -0
  190. package/src/lib/server/api-v1/usage.js.map +1 -0
  191. package/src/lib/server/consent-group-participant.js +1 -1
  192. package/src/lib/server/consent-group-participant.js.map +1 -1
  193. package/src/lib/server/contact-lifecycle-floor.d.ts +89 -0
  194. package/src/lib/server/contact-lifecycle-floor.js +91 -0
  195. package/src/lib/server/contact-lifecycle-floor.js.map +1 -0
  196. package/src/lib/server/contact-remove.d.ts +75 -0
  197. package/src/lib/server/contact-remove.js +244 -0
  198. package/src/lib/server/contact-remove.js.map +1 -0
  199. package/src/lib/server/contact-update.js +2 -1
  200. package/src/lib/server/contact-update.js.map +1 -1
  201. package/src/lib/server/contacts-import.d.ts +47 -11
  202. package/src/lib/server/contacts-import.js +171 -71
  203. package/src/lib/server/contacts-import.js.map +1 -1
  204. package/src/lib/server/contacts-merge.d.ts +1 -1
  205. package/src/lib/server/contacts-merge.js +3 -2
  206. package/src/lib/server/contacts-merge.js.map +1 -1
  207. package/src/lib/server/convert-host-lead.d.ts +189 -0
  208. package/src/lib/server/convert-host-lead.js +518 -0
  209. package/src/lib/server/convert-host-lead.js.map +1 -0
  210. package/src/lib/server/crm-sharing.d.ts +108 -0
  211. package/src/lib/server/crm-sharing.js +790 -0
  212. package/src/lib/server/crm-sharing.js.map +1 -0
  213. package/src/lib/server/daily-digest-route.d.ts +107 -0
  214. package/src/lib/server/daily-digest-route.js +588 -0
  215. package/src/lib/server/daily-digest-route.js.map +1 -0
  216. package/src/lib/server/export-route.d.ts +60 -0
  217. package/src/lib/server/export-route.js +447 -0
  218. package/src/lib/server/export-route.js.map +1 -0
  219. package/src/lib/server/inbound-route.d.ts +74 -0
  220. package/src/lib/server/inbound-route.js +257 -0
  221. package/src/lib/server/inbound-route.js.map +1 -0
  222. package/src/lib/server/lead-convert.d.ts +1 -1
  223. package/src/lib/server/lead-convert.js +2 -2
  224. package/src/lib/server/lead-convert.js.map +1 -1
  225. package/src/lib/server/merge-contacts.d.ts +55 -0
  226. package/src/lib/server/merge-contacts.js +274 -0
  227. package/src/lib/server/merge-contacts.js.map +1 -0
  228. package/src/lib/server/pipeline-record-index.d.ts +36 -0
  229. package/src/lib/server/pipeline-record-index.js +87 -0
  230. package/src/lib/server/pipeline-record-index.js.map +1 -0
  231. package/src/lib/server/record-facts.js +2 -1
  232. package/src/lib/server/record-facts.js.map +1 -1
  233. package/src/lib/server/task-reminders-route.d.ts +82 -0
  234. package/src/lib/server/task-reminders-route.js +497 -0
  235. package/src/lib/server/task-reminders-route.js.map +1 -0
  236. package/src/lib/server-deal-stage.js +2 -1
  237. package/src/lib/server-deal-stage.js.map +1 -1
  238. package/src/lib/server.d.ts +5 -2
  239. package/src/lib/server.js +47 -2
  240. package/src/lib/server.js.map +1 -1
  241. package/src/lib/testing/stand-in-site-record-routes.d.ts +26 -0
  242. package/src/lib/testing/stand-in-site-record-routes.js +55 -0
  243. package/src/lib/testing/stand-in-site-record-routes.js.map +1 -0
  244. package/src/lib/usage-axes.d.ts +35 -0
  245. package/src/lib/usage-axes.js +68 -0
  246. package/src/lib/usage-axes.js.map +1 -0
  247. package/src/lib/components/use-emails-hub-path.d.ts +0 -24
  248. package/src/lib/components/use-emails-hub-path.js +0 -59
  249. package/src/lib/components/use-emails-hub-path.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import { type CrmSharingObject, type CrmSharingSite } from '../model/crm-sharing';
2
+ import type { CrmTaskRouteScope } from '../model/task-routes';
3
+ export interface ShareRecordsDialogProps {
4
+ open: boolean;
5
+ onClose: () => void;
6
+ object: CrmSharingObject;
7
+ ids: readonly string[];
8
+ /** The route scope the share is sent with. */
9
+ scope: CrmTaskRouteScope | null;
10
+ sites: readonly CrmSharingSite[];
11
+ sitesReady: boolean;
12
+ /** Sites that already hold the record — not offered, since they see it anyway. */
13
+ heldHostIds?: readonly string[];
14
+ onShared?: (changed: number) => void;
15
+ }
16
+ /**
17
+ * "Share with sites…" (AGL-3336): the sites a manager picks, or All sites —
18
+ * which covers a site created later — and whether they may edit.
19
+ *
20
+ * Read-only is the default. The sentence under the choice is the guardrail
21
+ * a manager has to read before sharing: the other site sees the person and
22
+ * may work the record, and gains no permission to market to them.
23
+ */
24
+ export declare function ShareRecordsDialog(props: ShareRecordsDialogProps): import("react").JSX.Element;
25
+ export declare namespace ShareRecordsDialog {
26
+ var displayName: string;
27
+ }
28
+ export default ShareRecordsDialog;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import { MAX_SCOPE_HOSTS } from "@aglyn/aglyn";
19
+ import { useSnackbar } from "@aglyn/shared-ui-snackstack";
20
+ import { useUser } from "@aglyn/tenant-feature-instance";
21
+ import { Button, Checkbox, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, FormControlLabel, FormGroup, FormHelperText, FormLabel, Radio, RadioGroup, Stack, Typography } from "@mui/material";
22
+ import { useEffect, useState } from "react";
23
+ import { CRM_SHARING_OBJECT_LABELS } from "../model/crm-sharing.js";
24
+ import { callCrmSharing } from "../model/crm-sharing-api.js";
25
+ /**
26
+ * "Share with sites…" (AGL-3336): the sites a manager picks, or All sites —
27
+ * which covers a site created later — and whether they may edit.
28
+ *
29
+ * Read-only is the default. The sentence under the choice is the guardrail
30
+ * a manager has to read before sharing: the other site sees the person and
31
+ * may work the record, and gains no permission to market to them.
32
+ */ export function ShareRecordsDialog(props) {
33
+ const { open, onClose, object, ids, scope, sites, sitesReady, heldHostIds = [], onShared } = props;
34
+ const { data: user } = useUser();
35
+ const { enqueueSnackbar } = useSnackbar();
36
+ const [allSites, setAllSites] = useState(false);
37
+ const [picked, setPicked] = useState([]);
38
+ const [access, setAccess] = useState('read');
39
+ const [busy, setBusy] = useState(false);
40
+ useEffect(()=>{
41
+ if (!open) return;
42
+ setAllSites(false);
43
+ setPicked([]);
44
+ setAccess('read');
45
+ }, [
46
+ open
47
+ ]);
48
+ const offered = sites.filter((site)=>!heldHostIds.includes(site.id));
49
+ const label = CRM_SHARING_OBJECT_LABELS[object];
50
+ const what = ids.length === 1 ? `this ${label.one}` : `${ids.length} ${label.many.toLowerCase()}`;
51
+ const tooMany = !allSites && picked.length > MAX_SCOPE_HOSTS;
52
+ const ready = Boolean(scope) && ids.length > 0 && (allSites || picked.length > 0) && !tooMany;
53
+ const submit = async ()=>{
54
+ if (!scope || !ready) return;
55
+ setBusy(true);
56
+ try {
57
+ var _answer_changed;
58
+ const answer = await callCrmSharing(user, scope, 'share', {
59
+ object,
60
+ ids,
61
+ targets: allSites ? 'all' : picked,
62
+ access
63
+ });
64
+ enqueueSnackbar(answer.changed ? `Shared ${answer.changed === 1 ? `one ${label.one}` : `${answer.changed} ${label.many.toLowerCase()}`}` : `Already shared that way`, {
65
+ variant: 'success',
66
+ persist: false
67
+ });
68
+ onShared == null ? void 0 : onShared((_answer_changed = answer.changed) != null ? _answer_changed : 0);
69
+ onClose();
70
+ } catch (error) {
71
+ enqueueSnackbar(error.message, {
72
+ variant: 'error',
73
+ allowDuplicate: true
74
+ });
75
+ } finally{
76
+ setBusy(false);
77
+ }
78
+ };
79
+ return /*#__PURE__*/ _jsxs(Dialog, {
80
+ open: open,
81
+ onClose: busy ? undefined : onClose,
82
+ fullWidth: true,
83
+ maxWidth: "xs",
84
+ children: [
85
+ /*#__PURE__*/ _jsx(DialogTitle, {
86
+ children: 'Share with sites'
87
+ }),
88
+ /*#__PURE__*/ _jsx(DialogContent, {
89
+ children: /*#__PURE__*/ _jsxs(Stack, {
90
+ spacing: 2,
91
+ children: [
92
+ /*#__PURE__*/ _jsx(Typography, {
93
+ variant: "body2",
94
+ color: "text.secondary",
95
+ children: `The sites you pick see ${what} on their CRM lists and can log activity and tasks on it.`
96
+ }),
97
+ /*#__PURE__*/ _jsxs(FormGroup, {
98
+ children: [
99
+ /*#__PURE__*/ _jsx(FormControlLabel, {
100
+ control: /*#__PURE__*/ _jsx(Checkbox, {
101
+ checked: allSites,
102
+ onChange: (event)=>setAllSites(event.target.checked)
103
+ }),
104
+ label: "All sites, including sites added later"
105
+ }),
106
+ offered.map((site)=>/*#__PURE__*/ _jsx(FormControlLabel, {
107
+ control: /*#__PURE__*/ _jsx(Checkbox, {
108
+ checked: allSites || picked.includes(site.id),
109
+ disabled: allSites,
110
+ onChange: (event)=>setPicked((current)=>event.target.checked ? [
111
+ ...current,
112
+ site.id
113
+ ] : current.filter((id)=>id !== site.id))
114
+ }),
115
+ label: site.name
116
+ }, site.id)),
117
+ !sitesReady ? /*#__PURE__*/ _jsx(FormHelperText, {
118
+ children: 'Loading your sites…'
119
+ }) : !offered.length ? /*#__PURE__*/ _jsx(FormHelperText, {
120
+ children: 'No other site to share with. All sites still covers sites added later.'
121
+ }) : null,
122
+ tooMany ? /*#__PURE__*/ _jsx(FormHelperText, {
123
+ error: true,
124
+ children: `Choose ${MAX_SCOPE_HOSTS} sites or fewer, or share with All sites.`
125
+ }) : null
126
+ ]
127
+ }),
128
+ /*#__PURE__*/ _jsxs(FormControl, {
129
+ children: [
130
+ /*#__PURE__*/ _jsx(FormLabel, {
131
+ children: 'Access'
132
+ }),
133
+ /*#__PURE__*/ _jsxs(RadioGroup, {
134
+ value: access,
135
+ onChange: (event)=>setAccess(event.target.value === 'edit' ? 'edit' : 'read'),
136
+ children: [
137
+ /*#__PURE__*/ _jsx(FormControlLabel, {
138
+ value: "read",
139
+ control: /*#__PURE__*/ _jsx(Radio, {
140
+ size: "small"
141
+ }),
142
+ label: "Read-only"
143
+ }),
144
+ /*#__PURE__*/ _jsx(FormControlLabel, {
145
+ value: "edit",
146
+ control: /*#__PURE__*/ _jsx(Radio, {
147
+ size: "small"
148
+ }),
149
+ label: "Read and edit"
150
+ })
151
+ ]
152
+ })
153
+ ]
154
+ }),
155
+ /*#__PURE__*/ _jsx(Typography, {
156
+ variant: "caption",
157
+ color: "text.secondary",
158
+ children: 'Sharing is not consent. A site this is shared with cannot include the person ' + 'in a campaign, a list or a sequence unless the person gave that site consent.'
159
+ })
160
+ ]
161
+ })
162
+ }),
163
+ /*#__PURE__*/ _jsxs(DialogActions, {
164
+ children: [
165
+ /*#__PURE__*/ _jsx(Button, {
166
+ onClick: onClose,
167
+ disabled: busy,
168
+ children: 'Cancel'
169
+ }),
170
+ /*#__PURE__*/ _jsx(Button, {
171
+ variant: "contained",
172
+ onClick: ()=>void submit(),
173
+ disabled: !ready || busy,
174
+ children: 'Share'
175
+ })
176
+ ]
177
+ })
178
+ ]
179
+ });
180
+ }
181
+ ShareRecordsDialog.displayName = 'ShareRecordsDialog';
182
+ export default ShareRecordsDialog;
183
+
184
+ //# sourceMappingURL=share-records-dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/share-records-dialog.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { MAX_SCOPE_HOSTS } from '@aglyn/aglyn'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Button,\n Checkbox,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControl,\n FormControlLabel,\n FormGroup,\n FormHelperText,\n FormLabel,\n Radio,\n RadioGroup,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useEffect, useState } from 'react'\nimport {\n CRM_SHARING_OBJECT_LABELS,\n type CrmShareAccess,\n type CrmSharingObject,\n type CrmSharingSite,\n} from '../model/crm-sharing'\nimport { callCrmSharing } from '../model/crm-sharing-api'\nimport type { CrmTaskRouteScope } from '../model/task-routes'\n\nexport interface ShareRecordsDialogProps {\n open: boolean\n onClose: () => void\n object: CrmSharingObject\n ids: readonly string[]\n /** The route scope the share is sent with. */\n scope: CrmTaskRouteScope | null\n sites: readonly CrmSharingSite[]\n sitesReady: boolean\n /** Sites that already hold the record — not offered, since they see it anyway. */\n heldHostIds?: readonly string[]\n onShared?: (changed: number) => void\n}\n\n/**\n * \"Share with sites…\" (AGL-3336): the sites a manager picks, or All sites —\n * which covers a site created later — and whether they may edit.\n *\n * Read-only is the default. The sentence under the choice is the guardrail\n * a manager has to read before sharing: the other site sees the person and\n * may work the record, and gains no permission to market to them.\n */\nexport function ShareRecordsDialog(props: ShareRecordsDialogProps) {\n const { open, onClose, object, ids, scope, sites, sitesReady, heldHostIds = [], onShared } = props\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const [allSites, setAllSites] = useState(false)\n const [picked, setPicked] = useState<string[]>([])\n const [access, setAccess] = useState<CrmShareAccess>('read')\n const [busy, setBusy] = useState(false)\n useEffect(() => {\n if (!open) return\n setAllSites(false)\n setPicked([])\n setAccess('read')\n }, [open])\n\n const offered = sites.filter((site) => !heldHostIds.includes(site.id))\n const label = CRM_SHARING_OBJECT_LABELS[object]\n const what = ids.length === 1 ? `this ${label.one}` : `${ids.length} ${label.many.toLowerCase()}`\n const tooMany = !allSites && picked.length > MAX_SCOPE_HOSTS\n const ready = Boolean(scope) && ids.length > 0 && (allSites || picked.length > 0) && !tooMany\n\n const submit = async () => {\n if (!scope || !ready) return\n setBusy(true)\n try {\n const answer = await callCrmSharing(user, scope, 'share', {\n object,\n ids,\n targets: allSites ? 'all' : picked,\n access,\n })\n enqueueSnackbar(\n answer.changed\n ? `Shared ${answer.changed === 1 ? `one ${label.one}` : `${answer.changed} ${label.many.toLowerCase()}`}`\n : `Already shared that way`,\n { variant: 'success', persist: false },\n )\n onShared?.(answer.changed ?? 0)\n onClose()\n } catch (error) {\n enqueueSnackbar((error as Error).message, { variant: 'error', allowDuplicate: true })\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <Dialog open={open} onClose={busy ? undefined : onClose} fullWidth maxWidth=\"xs\">\n <DialogTitle>{'Share with sites'}</DialogTitle>\n <DialogContent>\n <Stack spacing={2}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`The sites you pick see ${what} on their CRM lists and can log activity and tasks on it.`}\n </Typography>\n <FormGroup>\n <FormControlLabel\n control={\n <Checkbox\n checked={allSites}\n onChange={(event) => setAllSites(event.target.checked)}\n />\n }\n label=\"All sites, including sites added later\"\n />\n {offered.map((site) => (\n <FormControlLabel\n key={site.id}\n control={\n <Checkbox\n checked={allSites || picked.includes(site.id)}\n disabled={allSites}\n onChange={(event) =>\n setPicked((current) =>\n event.target.checked\n ? [...current, site.id]\n : current.filter((id) => id !== site.id),\n )\n }\n />\n }\n label={site.name}\n />\n ))}\n {!sitesReady ? (\n <FormHelperText>{'Loading your sites…'}</FormHelperText>\n ) : !offered.length ? (\n <FormHelperText>{'No other site to share with. All sites still covers sites added later.'}</FormHelperText>\n ) : null}\n {tooMany ? (\n <FormHelperText error>\n {`Choose ${MAX_SCOPE_HOSTS} sites or fewer, or share with All sites.`}\n </FormHelperText>\n ) : null}\n </FormGroup>\n <FormControl>\n <FormLabel>{'Access'}</FormLabel>\n <RadioGroup\n value={access}\n onChange={(event) => setAccess(event.target.value === 'edit' ? 'edit' : 'read')}\n >\n <FormControlLabel value=\"read\" control={<Radio size=\"small\" />} label=\"Read-only\" />\n <FormControlLabel value=\"edit\" control={<Radio size=\"small\" />} label=\"Read and edit\" />\n </RadioGroup>\n </FormControl>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Sharing is not consent. A site this is shared with cannot include the person ' +\n 'in a campaign, a list or a sequence unless the person gave that site consent.'}\n </Typography>\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" onClick={() => void submit()} disabled={!ready || busy}>\n {'Share'}\n </Button>\n </DialogActions>\n </Dialog>\n )\n}\nShareRecordsDialog.displayName = 'ShareRecordsDialog'\n\nexport default ShareRecordsDialog\n"],"names":["MAX_SCOPE_HOSTS","useSnackbar","useUser","Button","Checkbox","Dialog","DialogActions","DialogContent","DialogTitle","FormControl","FormControlLabel","FormGroup","FormHelperText","FormLabel","Radio","RadioGroup","Stack","Typography","useEffect","useState","CRM_SHARING_OBJECT_LABELS","callCrmSharing","ShareRecordsDialog","props","open","onClose","object","ids","scope","sites","sitesReady","heldHostIds","onShared","data","user","enqueueSnackbar","allSites","setAllSites","picked","setPicked","access","setAccess","busy","setBusy","offered","filter","site","includes","id","label","what","length","one","many","toLowerCase","tooMany","ready","Boolean","submit","answer","targets","changed","variant","persist","error","message","allowDuplicate","undefined","fullWidth","maxWidth","spacing","color","control","checked","onChange","event","target","map","disabled","current","name","value","size","onClick","displayName"],"mappings":"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"}
@@ -0,0 +1,37 @@
1
+ import type { OrgMemberOption } from '../hooks/use-org-member-directory';
2
+ import { type CrmShareAccess, type CrmSharingCriteria, type CrmSharingObject, type CrmSharingRule, type CrmSharingSite } from '../model/crm-sharing';
3
+ /** What the drawer hands back: the rule as `crm/sharing` `rule-save` reads it. */
4
+ export interface SharingRuleDraft {
5
+ id?: string;
6
+ name: string;
7
+ object: CrmSharingObject;
8
+ enabled: boolean;
9
+ sourceHostIds: string[];
10
+ criteria: CrmSharingCriteria;
11
+ targets: 'all' | string[];
12
+ access: CrmShareAccess;
13
+ }
14
+ export interface SharingRuleDrawerProps {
15
+ open: boolean;
16
+ onClose: () => void;
17
+ /** The rule being edited, or `null` for a new one. */
18
+ rule: CrmSharingRule | null;
19
+ sites: readonly CrmSharingSite[];
20
+ members: readonly OrgMemberOption[];
21
+ campaigns: readonly {
22
+ value: string;
23
+ label: string;
24
+ }[];
25
+ busy: boolean;
26
+ onSubmit: (draft: SharingRuleDraft) => void;
27
+ }
28
+ /**
29
+ * A sharing rule, three parts (AGL-3336): WHICH RECORDS (an object, the
30
+ * sites that captured them, optional criteria), SHARED WITH (sites, or all
31
+ * sites), and ACCESS (read-only unless edit is chosen).
32
+ */
33
+ export declare function SharingRuleDrawer(props: SharingRuleDrawerProps): import("react").JSX.Element;
34
+ export declare namespace SharingRuleDrawer {
35
+ var displayName: string;
36
+ }
37
+ export default SharingRuleDrawer;
@@ -0,0 +1,374 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
+ import { CONTACT_LIFECYCLE_STAGE_LABELS, CONTACT_LIFECYCLE_STAGES, CRM_LEAD_STATUS_LABELS, CRM_LEAD_STATUSES, crmMemberPickerLabel } from "@aglyn/aglyn";
20
+ import { hostIdsFromScope, ORG_SCOPE_TOKEN } from "@aglyn/aglyn/app-utils/scope-tokens";
21
+ import { Button, Checkbox, Drawer, FormControl, FormControlLabel, FormGroup, FormHelperText, FormLabel, MenuItem, Radio, RadioGroup, Stack, Switch, TextField, Typography } from "@mui/material";
22
+ import { useEffect, useState } from "react";
23
+ import { CRM_SHARING_CRITERIA_FOR, CRM_SHARING_OBJECT_LABELS, CRM_SHARING_OBJECTS } from "../model/crm-sharing.js";
24
+ const splitList = (text)=>[
25
+ ...new Set(text.split(',').map((entry)=>entry.trim()).filter(Boolean))
26
+ ].slice(0, 20);
27
+ /**
28
+ * A sharing rule, three parts (AGL-3336): WHICH RECORDS (an object, the
29
+ * sites that captured them, optional criteria), SHARED WITH (sites, or all
30
+ * sites), and ACCESS (read-only unless edit is chosen).
31
+ */ export function SharingRuleDrawer(props) {
32
+ const { open, onClose, rule, sites, members, campaigns, busy, onSubmit } = props;
33
+ const [name, setName] = useState('');
34
+ const [object, setObject] = useState('leads');
35
+ const [enabled, setEnabled] = useState(true);
36
+ const [sourceHostIds, setSourceHostIds] = useState([]);
37
+ const [leadSources, setLeadSources] = useState('');
38
+ const [tags, setTags] = useState('');
39
+ const [stages, setStages] = useState([]);
40
+ const [ownerUids, setOwnerUids] = useState([]);
41
+ const [campaignIds, setCampaignIds] = useState([]);
42
+ const [allSites, setAllSites] = useState(true);
43
+ const [targets, setTargets] = useState([]);
44
+ const [access, setAccess] = useState('read');
45
+ useEffect(()=>{
46
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
47
+ if (!open) return;
48
+ setName((_ref = rule == null ? void 0 : rule.name) != null ? _ref : '');
49
+ setObject((_ref1 = rule == null ? void 0 : rule.object) != null ? _ref1 : 'leads');
50
+ setEnabled((_ref2 = rule == null ? void 0 : rule.enabled) != null ? _ref2 : true);
51
+ setSourceHostIds((_ref3 = rule == null ? void 0 : rule.sourceHostIds) != null ? _ref3 : []);
52
+ setLeadSources(((_ref4 = rule == null ? void 0 : rule.criteria.leadSources) != null ? _ref4 : []).join(', '));
53
+ setTags(((_ref5 = rule == null ? void 0 : rule.criteria.tags) != null ? _ref5 : []).join(', '));
54
+ setStages((_ref6 = rule == null ? void 0 : rule.criteria.stages) != null ? _ref6 : []);
55
+ setOwnerUids((_ref7 = rule == null ? void 0 : rule.criteria.ownerUids) != null ? _ref7 : []);
56
+ setCampaignIds((_ref8 = rule == null ? void 0 : rule.criteria.campaignIds) != null ? _ref8 : []);
57
+ setAllSites(rule ? rule.targets.includes(ORG_SCOPE_TOKEN) : true);
58
+ setTargets(rule ? hostIdsFromScope(rule.targets) : []);
59
+ setAccess((_ref9 = rule == null ? void 0 : rule.access) != null ? _ref9 : 'read');
60
+ }, [
61
+ open,
62
+ rule
63
+ ]);
64
+ const offers = CRM_SHARING_CRITERIA_FOR[object];
65
+ const stageOptions = object === 'leads' ? CRM_LEAD_STATUSES.map((value)=>({
66
+ value,
67
+ label: CRM_LEAD_STATUS_LABELS[value]
68
+ })) : object === 'contacts' ? CONTACT_LIFECYCLE_STAGES.map((value)=>({
69
+ value,
70
+ label: CONTACT_LIFECYCLE_STAGE_LABELS[value]
71
+ })) : [];
72
+ const canSubmit = !busy && name.trim().length > 0 && (allSites || targets.length > 0);
73
+ const submit = ()=>{
74
+ if (!canSubmit) return;
75
+ const criteria = {};
76
+ if (offers.includes('leadSources') && splitList(leadSources).length) {
77
+ criteria.leadSources = splitList(leadSources);
78
+ }
79
+ if (offers.includes('tags') && splitList(tags).length) {
80
+ criteria.tags = splitList(tags).map((tag)=>tag.toLowerCase());
81
+ }
82
+ if (stageOptions.length && stages.length) criteria.stages = stages;
83
+ if (offers.includes('ownerUids') && ownerUids.length) criteria.ownerUids = ownerUids;
84
+ if (offers.includes('campaignIds') && campaignIds.length) criteria.campaignIds = campaignIds;
85
+ onSubmit(_extends({}, rule ? {
86
+ id: rule.id
87
+ } : {}, {
88
+ name: name.trim(),
89
+ object,
90
+ enabled,
91
+ sourceHostIds,
92
+ criteria,
93
+ targets: allSites ? 'all' : targets,
94
+ access
95
+ }));
96
+ };
97
+ const siteName = (id)=>{
98
+ var _ref;
99
+ var _sites_find;
100
+ return (_ref = (_sites_find = sites.find((site)=>site.id === id)) == null ? void 0 : _sites_find.name) != null ? _ref : id;
101
+ };
102
+ return /*#__PURE__*/ _jsx(Drawer, {
103
+ anchor: "right",
104
+ open: open,
105
+ onClose: busy ? undefined : onClose,
106
+ children: /*#__PURE__*/ _jsxs(Stack, {
107
+ spacing: 2,
108
+ sx: {
109
+ width: 400,
110
+ maxWidth: '100vw',
111
+ p: 3
112
+ },
113
+ children: [
114
+ /*#__PURE__*/ _jsx(Typography, {
115
+ variant: "h6",
116
+ children: rule ? 'Edit sharing rule' : 'New sharing rule'
117
+ }),
118
+ /*#__PURE__*/ _jsx(Typography, {
119
+ variant: "body2",
120
+ color: "text.secondary",
121
+ children: 'Shares every record the rule matches — the ones you already have, and every one ' + 'captured or changed from now on. Sharing lets a site see and work a record; it ' + 'never shares the person’s consent.'
122
+ }),
123
+ /*#__PURE__*/ _jsx(TextField, {
124
+ size: "small",
125
+ label: "Name",
126
+ value: name,
127
+ onChange: (event)=>setName(event.target.value),
128
+ slotProps: {
129
+ htmlInput: {
130
+ maxLength: 120
131
+ }
132
+ },
133
+ required: true,
134
+ fullWidth: true
135
+ }),
136
+ /*#__PURE__*/ _jsx(FormLabel, {
137
+ children: 'Which records'
138
+ }),
139
+ /*#__PURE__*/ _jsx(TextField, {
140
+ select: true,
141
+ size: "small",
142
+ label: "Records",
143
+ value: object,
144
+ onChange: (event)=>{
145
+ setObject(event.target.value);
146
+ setStages([]);
147
+ },
148
+ disabled: Boolean(rule),
149
+ helperText: rule ? 'A rule keeps the kind of record it was made for.' : undefined,
150
+ fullWidth: true,
151
+ children: CRM_SHARING_OBJECTS.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
152
+ value: option,
153
+ children: CRM_SHARING_OBJECT_LABELS[option].many
154
+ }, option))
155
+ }),
156
+ /*#__PURE__*/ _jsx(TextField, {
157
+ select: true,
158
+ size: "small",
159
+ label: "Captured on",
160
+ value: sourceHostIds,
161
+ onChange: (event)=>{
162
+ const value = event.target.value;
163
+ setSourceHostIds(Array.isArray(value) ? value : String(value).split(','));
164
+ },
165
+ slotProps: {
166
+ select: {
167
+ multiple: true,
168
+ displayEmpty: true,
169
+ renderValue: (value)=>value.length ? value.map(siteName).join(', ') : 'Any site'
170
+ },
171
+ inputLabel: {
172
+ shrink: true
173
+ }
174
+ },
175
+ helperText: "The sites the record was captured or created on.",
176
+ fullWidth: true,
177
+ children: sites.map((site)=>/*#__PURE__*/ _jsx(MenuItem, {
178
+ value: site.id,
179
+ children: site.name
180
+ }, site.id))
181
+ }),
182
+ offers.includes('leadSources') ? /*#__PURE__*/ _jsx(TextField, {
183
+ size: "small",
184
+ label: "Lead source",
185
+ value: leadSources,
186
+ onChange: (event)=>setLeadSources(event.target.value),
187
+ helperText: "Any of these, separated by commas. Blank for any source.",
188
+ fullWidth: true
189
+ }) : null,
190
+ offers.includes('tags') ? /*#__PURE__*/ _jsx(TextField, {
191
+ size: "small",
192
+ label: "Tags",
193
+ value: tags,
194
+ onChange: (event)=>setTags(event.target.value),
195
+ helperText: "Any of these, separated by commas. Blank for any tags.",
196
+ fullWidth: true
197
+ }) : null,
198
+ stageOptions.length ? /*#__PURE__*/ _jsx(TextField, {
199
+ select: true,
200
+ size: "small",
201
+ label: object === 'leads' ? 'Status' : 'Lifecycle stage',
202
+ value: stages,
203
+ onChange: (event)=>{
204
+ const value = event.target.value;
205
+ setStages(Array.isArray(value) ? value : String(value).split(','));
206
+ },
207
+ slotProps: {
208
+ select: {
209
+ multiple: true,
210
+ displayEmpty: true,
211
+ renderValue: (value)=>value.length ? value.map((id)=>{
212
+ var _ref;
213
+ var _stageOptions_find;
214
+ return (_ref = (_stageOptions_find = stageOptions.find((option)=>option.value === id)) == null ? void 0 : _stageOptions_find.label) != null ? _ref : id;
215
+ }).join(', ') : 'Any'
216
+ },
217
+ inputLabel: {
218
+ shrink: true
219
+ }
220
+ },
221
+ fullWidth: true,
222
+ children: stageOptions.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
223
+ value: option.value,
224
+ children: option.label
225
+ }, option.value))
226
+ }) : null,
227
+ offers.includes('campaignIds') && campaigns.length ? /*#__PURE__*/ _jsx(TextField, {
228
+ select: true,
229
+ size: "small",
230
+ label: "Campaign",
231
+ value: campaignIds,
232
+ onChange: (event)=>{
233
+ const value = event.target.value;
234
+ setCampaignIds(Array.isArray(value) ? value : String(value).split(','));
235
+ },
236
+ slotProps: {
237
+ select: {
238
+ multiple: true,
239
+ displayEmpty: true,
240
+ renderValue: (value)=>value.length ? value.map((id)=>{
241
+ var _ref;
242
+ var _campaigns_find;
243
+ return (_ref = (_campaigns_find = campaigns.find((option)=>option.value === id)) == null ? void 0 : _campaigns_find.label) != null ? _ref : id;
244
+ }).join(', ') : 'Any'
245
+ },
246
+ inputLabel: {
247
+ shrink: true
248
+ }
249
+ },
250
+ fullWidth: true,
251
+ children: campaigns.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
252
+ value: option.value,
253
+ children: option.label
254
+ }, option.value))
255
+ }) : null,
256
+ /*#__PURE__*/ _jsx(TextField, {
257
+ select: true,
258
+ size: "small",
259
+ label: "Owner",
260
+ value: ownerUids,
261
+ onChange: (event)=>{
262
+ const value = event.target.value;
263
+ setOwnerUids(Array.isArray(value) ? value : String(value).split(','));
264
+ },
265
+ slotProps: {
266
+ select: {
267
+ multiple: true,
268
+ displayEmpty: true,
269
+ renderValue: (value)=>value.length ? value.map((uid)=>{
270
+ const member = members.find((entry)=>entry.uid === uid);
271
+ return member ? crmMemberPickerLabel(member) : uid;
272
+ }).join(', ') : 'Anyone'
273
+ },
274
+ inputLabel: {
275
+ shrink: true
276
+ }
277
+ },
278
+ fullWidth: true,
279
+ children: members.map((member)=>/*#__PURE__*/ _jsx(MenuItem, {
280
+ value: member.uid,
281
+ children: crmMemberPickerLabel(member)
282
+ }, member.uid))
283
+ }),
284
+ /*#__PURE__*/ _jsxs(FormControl, {
285
+ children: [
286
+ /*#__PURE__*/ _jsx(FormLabel, {
287
+ children: 'Shared with'
288
+ }),
289
+ /*#__PURE__*/ _jsxs(FormGroup, {
290
+ children: [
291
+ /*#__PURE__*/ _jsx(FormControlLabel, {
292
+ control: /*#__PURE__*/ _jsx(Checkbox, {
293
+ checked: allSites,
294
+ onChange: (event)=>setAllSites(event.target.checked)
295
+ }),
296
+ label: "All sites, including sites added later"
297
+ }),
298
+ sites.map((site)=>/*#__PURE__*/ _jsx(FormControlLabel, {
299
+ control: /*#__PURE__*/ _jsx(Checkbox, {
300
+ checked: allSites || targets.includes(site.id),
301
+ disabled: allSites,
302
+ onChange: (event)=>setTargets((current)=>event.target.checked ? [
303
+ ...current,
304
+ site.id
305
+ ] : current.filter((id)=>id !== site.id))
306
+ }),
307
+ label: site.name
308
+ }, site.id))
309
+ ]
310
+ })
311
+ ]
312
+ }),
313
+ /*#__PURE__*/ _jsxs(FormControl, {
314
+ children: [
315
+ /*#__PURE__*/ _jsx(FormLabel, {
316
+ children: 'Access'
317
+ }),
318
+ /*#__PURE__*/ _jsxs(RadioGroup, {
319
+ value: access,
320
+ onChange: (event)=>setAccess(event.target.value === 'edit' ? 'edit' : 'read'),
321
+ children: [
322
+ /*#__PURE__*/ _jsx(FormControlLabel, {
323
+ value: "read",
324
+ control: /*#__PURE__*/ _jsx(Radio, {
325
+ size: "small"
326
+ }),
327
+ label: "Read-only"
328
+ }),
329
+ /*#__PURE__*/ _jsx(FormControlLabel, {
330
+ value: "edit",
331
+ control: /*#__PURE__*/ _jsx(Radio, {
332
+ size: "small"
333
+ }),
334
+ label: "Read and edit"
335
+ })
336
+ ]
337
+ })
338
+ ]
339
+ }),
340
+ /*#__PURE__*/ _jsx(FormControlLabel, {
341
+ control: /*#__PURE__*/ _jsx(Switch, {
342
+ checked: enabled,
343
+ onChange: (event)=>setEnabled(event.target.checked)
344
+ }),
345
+ label: "On"
346
+ }),
347
+ !enabled ? /*#__PURE__*/ _jsx(FormHelperText, {
348
+ children: 'Off keeps the rule and takes away what it shared.'
349
+ }) : null,
350
+ /*#__PURE__*/ _jsxs(Stack, {
351
+ direction: "row",
352
+ spacing: 1,
353
+ children: [
354
+ /*#__PURE__*/ _jsx(Button, {
355
+ variant: "contained",
356
+ disabled: !canSubmit,
357
+ onClick: submit,
358
+ children: rule ? 'Save rule' : 'Add rule'
359
+ }),
360
+ /*#__PURE__*/ _jsx(Button, {
361
+ onClick: onClose,
362
+ disabled: busy,
363
+ children: 'Cancel'
364
+ })
365
+ ]
366
+ })
367
+ ]
368
+ })
369
+ });
370
+ }
371
+ SharingRuleDrawer.displayName = 'SharingRuleDrawer';
372
+ export default SharingRuleDrawer;
373
+
374
+ //# sourceMappingURL=sharing-rule-drawer.js.map