@kelpie/ui 0.27.0 → 0.28.0

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 (198) hide show
  1. package/dist/api/resources/bulkActions.d.ts +50 -0
  2. package/dist/api/resources/bulkActions.d.ts.map +1 -0
  3. package/dist/api/resources/bulkActions.js +192 -0
  4. package/dist/api/resources/bulkActions.js.map +1 -0
  5. package/dist/api/resources/forms.d.ts +26 -1
  6. package/dist/api/resources/forms.d.ts.map +1 -1
  7. package/dist/api/resources/forms.js +98 -1
  8. package/dist/api/resources/forms.js.map +1 -1
  9. package/dist/app/KelpieApp.d.ts.map +1 -1
  10. package/dist/app/KelpieApp.js +3 -1
  11. package/dist/app/KelpieApp.js.map +1 -1
  12. package/dist/components/BulkActions.d.ts +61 -0
  13. package/dist/components/BulkActions.d.ts.map +1 -0
  14. package/dist/components/BulkActions.js +351 -0
  15. package/dist/components/BulkActions.js.map +1 -0
  16. package/dist/components/BulkParamFields.d.ts +13 -0
  17. package/dist/components/BulkParamFields.d.ts.map +1 -0
  18. package/dist/components/BulkParamFields.js +177 -0
  19. package/dist/components/BulkParamFields.js.map +1 -0
  20. package/dist/components/CellLinks.d.ts +38 -0
  21. package/dist/components/CellLinks.d.ts.map +1 -0
  22. package/dist/components/CellLinks.js +58 -0
  23. package/dist/components/CellLinks.js.map +1 -0
  24. package/dist/components/CustomFieldsPanel.d.ts +12 -1
  25. package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
  26. package/dist/components/CustomFieldsPanel.js +5 -1
  27. package/dist/components/CustomFieldsPanel.js.map +1 -1
  28. package/dist/components/DataTable.d.ts +42 -1
  29. package/dist/components/DataTable.d.ts.map +1 -1
  30. package/dist/components/DataTable.js +51 -16
  31. package/dist/components/DataTable.js.map +1 -1
  32. package/dist/components/PhonesField.d.ts.map +1 -1
  33. package/dist/components/PhonesField.js +1 -3
  34. package/dist/components/PhonesField.js.map +1 -1
  35. package/dist/components/Shell.d.ts.map +1 -1
  36. package/dist/components/Shell.js +16 -6
  37. package/dist/components/Shell.js.map +1 -1
  38. package/dist/components/TagInput.d.ts.map +1 -1
  39. package/dist/components/TagInput.js +5 -0
  40. package/dist/components/TagInput.js.map +1 -1
  41. package/dist/components/bulkActionParams.d.ts +71 -0
  42. package/dist/components/bulkActionParams.d.ts.map +1 -0
  43. package/dist/components/bulkActionParams.js +241 -0
  44. package/dist/components/bulkActionParams.js.map +1 -0
  45. package/dist/components/bulkActionSummary.d.ts +22 -0
  46. package/dist/components/bulkActionSummary.d.ts.map +1 -0
  47. package/dist/components/bulkActionSummary.js +68 -0
  48. package/dist/components/bulkActionSummary.js.map +1 -0
  49. package/dist/components/bulkJobStatus.d.ts +4 -0
  50. package/dist/components/bulkJobStatus.d.ts.map +1 -0
  51. package/dist/components/bulkJobStatus.js +10 -0
  52. package/dist/components/bulkJobStatus.js.map +1 -0
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +1 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/lib/bulkSelection.d.ts +43 -0
  58. package/dist/lib/bulkSelection.d.ts.map +1 -0
  59. package/dist/lib/bulkSelection.js +70 -0
  60. package/dist/lib/bulkSelection.js.map +1 -0
  61. package/dist/lib/contactLinks.d.ts +15 -0
  62. package/dist/lib/contactLinks.d.ts.map +1 -0
  63. package/dist/lib/contactLinks.js +22 -0
  64. package/dist/lib/contactLinks.js.map +1 -0
  65. package/dist/pages/BulkJobsPage.d.ts +3 -0
  66. package/dist/pages/BulkJobsPage.d.ts.map +1 -0
  67. package/dist/pages/BulkJobsPage.js +92 -0
  68. package/dist/pages/BulkJobsPage.js.map +1 -0
  69. package/dist/pages/CompaniesPage.d.ts.map +1 -1
  70. package/dist/pages/CompaniesPage.js +8 -4
  71. package/dist/pages/CompaniesPage.js.map +1 -1
  72. package/dist/pages/DealsPage.d.ts.map +1 -1
  73. package/dist/pages/DealsPage.js +15 -4
  74. package/dist/pages/DealsPage.js.map +1 -1
  75. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  76. package/dist/pages/DecisionsPage.js +11 -1
  77. package/dist/pages/DecisionsPage.js.map +1 -1
  78. package/dist/pages/EnquiriesPage.d.ts.map +1 -1
  79. package/dist/pages/EnquiriesPage.js +15 -6
  80. package/dist/pages/EnquiriesPage.js.map +1 -1
  81. package/dist/pages/EventDetail.d.ts.map +1 -1
  82. package/dist/pages/EventDetail.js +14 -6
  83. package/dist/pages/EventDetail.js.map +1 -1
  84. package/dist/pages/EventsPage.d.ts.map +1 -1
  85. package/dist/pages/EventsPage.js +13 -3
  86. package/dist/pages/EventsPage.js.map +1 -1
  87. package/dist/pages/FormsPage.d.ts.map +1 -1
  88. package/dist/pages/FormsPage.js +2 -2
  89. package/dist/pages/FormsPage.js.map +1 -1
  90. package/dist/pages/FundraisingPage.d.ts.map +1 -1
  91. package/dist/pages/FundraisingPage.js +15 -4
  92. package/dist/pages/FundraisingPage.js.map +1 -1
  93. package/dist/pages/HiringPage.d.ts.map +1 -1
  94. package/dist/pages/HiringPage.js +2 -1
  95. package/dist/pages/HiringPage.js.map +1 -1
  96. package/dist/pages/ListDetail.d.ts.map +1 -1
  97. package/dist/pages/ListDetail.js +39 -7
  98. package/dist/pages/ListDetail.js.map +1 -1
  99. package/dist/pages/ListsPage.d.ts.map +1 -1
  100. package/dist/pages/ListsPage.js +2 -1
  101. package/dist/pages/ListsPage.js.map +1 -1
  102. package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
  103. package/dist/pages/OpportunitiesPage.js +15 -6
  104. package/dist/pages/OpportunitiesPage.js.map +1 -1
  105. package/dist/pages/PartnershipsPage.d.ts.map +1 -1
  106. package/dist/pages/PartnershipsPage.js +15 -4
  107. package/dist/pages/PartnershipsPage.js.map +1 -1
  108. package/dist/pages/PeoplePage.d.ts.map +1 -1
  109. package/dist/pages/PeoplePage.js +10 -9
  110. package/dist/pages/PeoplePage.js.map +1 -1
  111. package/dist/pages/PlanningPage.d.ts.map +1 -1
  112. package/dist/pages/PlanningPage.js +15 -4
  113. package/dist/pages/PlanningPage.js.map +1 -1
  114. package/dist/pages/RoleDetail.d.ts.map +1 -1
  115. package/dist/pages/RoleDetail.js +12 -4
  116. package/dist/pages/RoleDetail.js.map +1 -1
  117. package/dist/pages/forms/BlockedSendersPage.d.ts +10 -0
  118. package/dist/pages/forms/BlockedSendersPage.d.ts.map +1 -0
  119. package/dist/pages/forms/BlockedSendersPage.js +65 -0
  120. package/dist/pages/forms/BlockedSendersPage.js.map +1 -0
  121. package/dist/pages/forms/MarkSpamPanel.d.ts +19 -0
  122. package/dist/pages/forms/MarkSpamPanel.d.ts.map +1 -0
  123. package/dist/pages/forms/MarkSpamPanel.js +62 -0
  124. package/dist/pages/forms/MarkSpamPanel.js.map +1 -0
  125. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  126. package/dist/pages/forms/SubmissionDetail.js +41 -11
  127. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  128. package/dist/pages/forms/SubmissionsTable.d.ts +1 -1
  129. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  130. package/dist/pages/forms/SubmissionsTable.js +6 -4
  131. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  132. package/dist/pages/forms/markSpamChoices.d.ts +51 -0
  133. package/dist/pages/forms/markSpamChoices.d.ts.map +1 -0
  134. package/dist/pages/forms/markSpamChoices.js +96 -0
  135. package/dist/pages/forms/markSpamChoices.js.map +1 -0
  136. package/dist/pages/positionDirectory.d.ts +5 -0
  137. package/dist/pages/positionDirectory.d.ts.map +1 -1
  138. package/dist/pages/positionDirectory.js +11 -3
  139. package/dist/pages/positionDirectory.js.map +1 -1
  140. package/dist/registry/context.d.ts +3 -1
  141. package/dist/registry/context.d.ts.map +1 -1
  142. package/dist/registry/context.js +4 -0
  143. package/dist/registry/context.js.map +1 -1
  144. package/dist/registry/contributions.d.ts +23 -0
  145. package/dist/registry/contributions.d.ts.map +1 -1
  146. package/dist/registry/contributions.js.map +1 -1
  147. package/dist/registry/registry.d.ts +4 -1
  148. package/dist/registry/registry.d.ts.map +1 -1
  149. package/dist/registry/registry.js +6 -0
  150. package/dist/registry/registry.js.map +1 -1
  151. package/dist/registry/visibleNav.d.ts.map +1 -1
  152. package/dist/registry/visibleNav.js +1 -0
  153. package/dist/registry/visibleNav.js.map +1 -1
  154. package/package.json +3 -3
  155. package/src/api/resources/bulkActions.ts +267 -0
  156. package/src/api/resources/forms.ts +135 -0
  157. package/src/app/KelpieApp.tsx +5 -0
  158. package/src/components/BulkActions.tsx +961 -0
  159. package/src/components/BulkParamFields.tsx +524 -0
  160. package/src/components/CellLinks.tsx +138 -0
  161. package/src/components/CustomFieldsPanel.tsx +6 -2
  162. package/src/components/DataTable.tsx +142 -2
  163. package/src/components/PhonesField.tsx +2 -4
  164. package/src/components/Shell.tsx +23 -6
  165. package/src/components/TagInput.tsx +5 -0
  166. package/src/components/bulkActionParams.ts +405 -0
  167. package/src/components/bulkActionSummary.ts +104 -0
  168. package/src/components/bulkJobStatus.ts +11 -0
  169. package/src/index.ts +3 -0
  170. package/src/lib/bulkSelection.ts +128 -0
  171. package/src/lib/contactLinks.ts +25 -0
  172. package/src/pages/BulkJobsPage.tsx +206 -0
  173. package/src/pages/CompaniesPage.tsx +20 -5
  174. package/src/pages/DealsPage.tsx +30 -2
  175. package/src/pages/DecisionsPage.tsx +21 -1
  176. package/src/pages/EnquiriesPage.tsx +33 -5
  177. package/src/pages/EventDetail.tsx +43 -16
  178. package/src/pages/EventsPage.tsx +26 -2
  179. package/src/pages/FormsPage.tsx +7 -1
  180. package/src/pages/FundraisingPage.tsx +30 -2
  181. package/src/pages/HiringPage.tsx +6 -1
  182. package/src/pages/ListDetail.tsx +69 -5
  183. package/src/pages/ListsPage.tsx +6 -1
  184. package/src/pages/OpportunitiesPage.tsx +33 -5
  185. package/src/pages/PartnershipsPage.tsx +30 -2
  186. package/src/pages/PeoplePage.tsx +26 -21
  187. package/src/pages/PlanningPage.tsx +65 -24
  188. package/src/pages/RoleDetail.tsx +35 -7
  189. package/src/pages/forms/BlockedSendersPage.tsx +155 -0
  190. package/src/pages/forms/MarkSpamPanel.tsx +193 -0
  191. package/src/pages/forms/SubmissionDetail.tsx +73 -18
  192. package/src/pages/forms/SubmissionsTable.tsx +7 -5
  193. package/src/pages/forms/markSpamChoices.ts +141 -0
  194. package/src/pages/positionDirectory.ts +16 -4
  195. package/src/registry/context.ts +6 -0
  196. package/src/registry/contributions.ts +25 -0
  197. package/src/registry/registry.ts +12 -0
  198. package/src/registry/visibleNav.ts +1 -0
@@ -1,21 +1,26 @@
1
1
  import { FORM_SPAM_REASON_LABELS, formFieldDisplayLabel } from '@kelpie/schemas'
2
2
  import type { Form, FormField, FormSubmission, FormSubmissionActionEntry } from '@kelpie/schemas'
3
- import { useMemo } from 'react'
3
+ import { useMemo, useState } from 'react'
4
4
  import { Link, useNavigate, useParams } from 'react-router'
5
5
 
6
6
  import { useTimezone } from '../../api/resources/account.ts'
7
7
  import { useCompanies } from '../../api/resources/companies.ts'
8
+ import { useDeal } from '../../api/resources/deals.ts'
9
+ import { useEnquiry } from '../../api/resources/enquiries.ts'
8
10
  import {
9
11
  useDeleteFormSubmissions,
10
12
  useForm,
11
13
  useFormSubmission,
12
14
  useReleaseFormSubmission,
13
15
  } from '../../api/resources/forms.ts'
16
+ import { useOpportunity } from '../../api/resources/opportunities.ts'
17
+ import { usePartnership } from '../../api/resources/partnerships.ts'
14
18
  import { usePeople } from '../../api/resources/people.ts'
15
19
  import { DeleteRecord } from '../../components/DeleteRecord.tsx'
16
20
  import { ErrorPanel, LoadingPanel, NotFoundPanel } from '../../components/QueryState.tsx'
17
21
  import { SectionHeader } from '../../components/SectionHeader.tsx'
18
22
  import { formatDateTime } from '../../lib/dates.ts'
23
+ import { MarkSpamPanel } from './MarkSpamPanel.tsx'
19
24
 
20
25
  /**
21
26
  * One submission: every answer, the records it linked, and the action log.
@@ -35,10 +40,25 @@ export function SubmissionDetail(): React.JSX.Element {
35
40
  const people = usePeople({ limit: MAX_PAGE })
36
41
  const companies = useCompanies({ limit: MAX_PAGE })
37
42
  const timezone = useTimezone()
43
+ // The pipeline records the submission links, by their own reads, so the
44
+ // mark-as-spam confirmation can name them. A link that is null asks nothing.
45
+ const deal = useDeal(submission.record?.dealId ?? undefined)
46
+ const opportunity = useOpportunity(submission.record?.opportunityId ?? undefined)
47
+ const partnership = usePartnership(submission.record?.partnershipId ?? undefined)
48
+ const enquiry = useEnquiry(submission.record?.enquiryId ?? undefined)
38
49
 
39
50
  const nameById = useMemo(
40
- () => new Map([...people.records, ...companies.records].map((record) => [record.id, record.name])),
41
- [people.records, companies.records],
51
+ () =>
52
+ new Map(
53
+ [
54
+ ...people.records,
55
+ ...companies.records,
56
+ ...[deal.record, opportunity.record, partnership.record, enquiry.record].filter(
57
+ (record) => record !== undefined,
58
+ ),
59
+ ].map((record) => [record.id, record.name]),
60
+ ),
61
+ [people.records, companies.records, deal.record, opportunity.record, partnership.record, enquiry.record],
42
62
  )
43
63
 
44
64
  if (form.isNotFound || submission.isNotFound) {
@@ -94,6 +114,16 @@ function SubmissionDetailView({
94
114
  }))
95
115
  const remove = useDeleteFormSubmissions()
96
116
  const navigate = useNavigate()
117
+ const [markingSpam, setMarkingSpam] = useState(false)
118
+ const [statusSeen, setStatusSeen] = useState(submission.status)
119
+
120
+ // A mark or a release changes the status. The open panel's choices were
121
+ // worked out from the old links, so it closes rather than reopening stale
122
+ // after a later release on the same page.
123
+ if (statusSeen !== submission.status) {
124
+ setStatusSeen(submission.status)
125
+ setMarkingSpam(false)
126
+ }
97
127
 
98
128
  return (
99
129
  <div className="animate-fade-in mx-auto max-w-2xl">
@@ -110,19 +140,43 @@ function SubmissionDetailView({
110
140
  title="Submission"
111
141
  description={`Received ${formatDateTime(submission.submittedAt, timezone)}.`}
112
142
  />
113
- <DeleteRecord
114
- recordLabel="Submission"
115
- recordName="this submission"
116
- isPending={remove.isPending}
117
- error={remove.error}
118
- onConfirm={() => {
119
- remove
120
- .runAsync({ formId: form.id, submissionIds: [submission.id] })
121
- .then(() => navigate(`/forms/${form.id}`))
122
- .catch(() => undefined)
143
+ <div className="flex items-start gap-2">
144
+ {submission.status === 'accepted' && !markingSpam && (
145
+ <button
146
+ type="button"
147
+ onClick={() => {
148
+ setMarkingSpam(true)
149
+ }}
150
+ className="rounded-md border border-border px-2.5 py-1 text-[12px] font-medium text-ink-muted transition hover:border-warning hover:text-ink"
151
+ >
152
+ Mark as spam
153
+ </button>
154
+ )}
155
+ <DeleteRecord
156
+ recordLabel="Submission"
157
+ recordName="this submission"
158
+ isPending={remove.isPending}
159
+ error={remove.error}
160
+ onConfirm={() => {
161
+ remove
162
+ .runAsync({ formId: form.id, submissionIds: [submission.id] })
163
+ .then(() => navigate(`/forms/${form.id}`))
164
+ .catch(() => undefined)
165
+ }}
166
+ />
167
+ </div>
168
+ </div>
169
+
170
+ {submission.status === 'accepted' && markingSpam && (
171
+ <MarkSpamPanel
172
+ fields={form.fields}
173
+ submission={submission}
174
+ nameById={nameById}
175
+ onClose={() => {
176
+ setMarkingSpam(false)
123
177
  }}
124
178
  />
125
- </div>
179
+ )}
126
180
 
127
181
  <SpamNotice form={form} submission={submission} />
128
182
 
@@ -232,7 +286,7 @@ function SubmissionDetailView({
232
286
  }
233
287
 
234
288
  /**
235
- * What the spam check said about this submission, and the way out.
289
+ * Why this submission is or was held, and the way out.
236
290
  *
237
291
  * A held submission shows the reason and a Release button. One a person
238
292
  * released keeps its reason, so the page says where it came from.
@@ -255,7 +309,7 @@ function SpamNotice({
255
309
  if (submission.status !== 'spam') {
256
310
  return (
257
311
  <p className="mt-4 rounded-md border border-border bg-surface px-3 py-2 text-[12px] text-ink-muted">
258
- The spam check held this submission, and a person released it. Reason it was held:{' '}
312
+ This submission was held as spam, and a person released it. Reason it was held:{' '}
259
313
  {reason}.
260
314
  </p>
261
315
  )
@@ -265,8 +319,9 @@ function SpamNotice({
265
319
  <div className="mt-4 rounded-md border border-warning/40 bg-warning-soft px-3 py-2.5">
266
320
  <p className="text-[13px] font-medium text-ink">Held as spam</p>
267
321
  <p className="mt-0.5 text-[12px] text-ink-muted">
268
- {reason}. Nothing was written to your CRM and no email was sent. If a person sent
269
- this, release it: Kelpie then processes it as a normal submission.
322
+ {submission.spamReason === 'marked_by_member'
323
+ ? `${reason}. Its records are no longer linked, and any emails it sent were not unsent. Releasing it is not an undo: Kelpie runs the form again, so it creates new records and sends the emails again. Records kept when it was marked stay unlinked.`
324
+ : `${reason}. Nothing was written to your CRM and no email was sent. If a person sent this, release it: Kelpie then processes it as a normal submission.`}
270
325
  </p>
271
326
  {release.error !== null && (
272
327
  <div className="mt-2">
@@ -36,9 +36,11 @@ import { formatDateTime } from '../../lib/dates.ts'
36
36
  * links still navigate, and stop the row click so opening a person does not
37
37
  * also open the submission.
38
38
  *
39
- * What the spam check held is a second list, behind the Spam button. Those rows
40
- * link no records, so they show the reason and a Release button in place of the
41
- * person and company.
39
+ * What is held as spam is a second list, behind the Spam button: what the spam
40
+ * check caught, what a blocked sender sent, and what a member marked. Those
41
+ * rows link no records, so they show the reason and a Release button in place
42
+ * of the person and company. Marking one accepted submission as spam is on
43
+ * its own page, because it asks which linked records to delete.
42
44
  *
43
45
  * Each row has a checkbox, and the ticked rows can be deleted together. A
44
46
  * selection is of the rows on screen only: it is cleared when the list, the
@@ -52,7 +54,7 @@ const MAX_PAGE = 200
52
54
  export interface SubmissionsTableProps {
53
55
  readonly form: Form
54
56
  readonly submissions: RecordListResult<FormSubmission>
55
- /** The submissions the spam check held. */
57
+ /** The submissions held as spam. */
56
58
  readonly spam: RecordListResult<FormSubmission>
57
59
  }
58
60
 
@@ -241,7 +243,7 @@ export function SubmissionsTable({
241
243
  title="Submissions"
242
244
  description={
243
245
  view === 'spam'
244
- ? 'Submissions the spam check held. Nothing was written to your CRM. Release one to process it as a normal submission. A held submission is deleted after 30 days.'
246
+ ? 'Submissions held as spam: caught by the spam check, sent from a blocked address, or marked by a member. Release one to process it as a normal submission. A held submission is deleted after 30 days.'
245
247
  : 'Inbound answers, and the records each one created or matched. Click a row to open it.'
246
248
  }
247
249
  />
@@ -0,0 +1,141 @@
1
+ import { PERSON_EMAIL_TARGET } from '@kelpie/schemas'
2
+ import type { FormField, FormSubmission, FormSubmissionLinkTarget } from '@kelpie/schemas'
3
+
4
+ /**
5
+ * What the "Mark as spam" confirmation offers, worked out from the submission.
6
+ *
7
+ * Pure, so the rules for what starts ticked are tested without rendering.
8
+ */
9
+
10
+ /** Whether the submission made a record, found one that was there, or nobody recorded which. */
11
+ export type RecordOrigin = 'created' | 'matched' | 'unknown'
12
+
13
+ /** One linked record the confirmation lists, with a checkbox. */
14
+ export interface MarkSpamRecordChoice {
15
+ readonly target: FormSubmissionLinkTarget
16
+ readonly id: string
17
+ readonly label: string
18
+ readonly origin: RecordOrigin
19
+ /**
20
+ * Deleting it takes other people's records with it. A company is the case:
21
+ * every position at it goes, whoever holds it.
22
+ */
23
+ readonly widens: boolean
24
+ /** Ticked at first: a record this submission created, unless deleting it widens. */
25
+ readonly ticked: boolean
26
+ }
27
+
28
+ const TARGET_LABELS: Readonly<Record<FormSubmissionLinkTarget, string>> = {
29
+ person: 'Person',
30
+ company: 'Company',
31
+ position: 'Position',
32
+ deal: 'Deal',
33
+ opportunity: 'Opportunity',
34
+ partnership: 'Partnership',
35
+ enquiry: 'Enquiry',
36
+ }
37
+
38
+ /** The order the confirmation lists them in, which is the order the submission page shows. */
39
+ const LISTED: readonly FormSubmissionLinkTarget[] = [
40
+ 'person',
41
+ 'company',
42
+ 'position',
43
+ 'deal',
44
+ 'opportunity',
45
+ 'partnership',
46
+ 'enquiry',
47
+ ]
48
+
49
+ function linkedId(submission: FormSubmission, target: FormSubmissionLinkTarget): string | null {
50
+ switch (target) {
51
+ case 'person':
52
+ return submission.personId
53
+ case 'company':
54
+ return submission.companyId
55
+ case 'position':
56
+ return submission.positionId
57
+ case 'deal':
58
+ return submission.dealId
59
+ case 'opportunity':
60
+ return submission.opportunityId
61
+ case 'partnership':
62
+ return submission.partnershipId
63
+ case 'enquiry':
64
+ return submission.enquiryId
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Every record the submission links, ticked when the submission created it.
70
+ *
71
+ * A record it matched was in the CRM before it arrived, so it starts unticked.
72
+ * So does every record of a submission stored before Kelpie recorded which
73
+ * records it created: nobody knows, and a delete cannot be undone. A company
74
+ * starts unticked even when the submission created it, because others may
75
+ * have joined it since and their positions go with it.
76
+ *
77
+ * @param names A record's display name by id, where one is known.
78
+ */
79
+ export function markSpamRecordChoices(
80
+ submission: FormSubmission,
81
+ names: ReadonlyMap<string, string>,
82
+ ): MarkSpamRecordChoice[] {
83
+ const created = submission.createdRecordIds === null ? null : new Set(submission.createdRecordIds)
84
+
85
+ return LISTED.flatMap((target): MarkSpamRecordChoice[] => {
86
+ const id = linkedId(submission, target)
87
+
88
+ if (id === null) {
89
+ return []
90
+ }
91
+
92
+ const origin: RecordOrigin = created === null ? 'unknown' : created.has(id) ? 'created' : 'matched'
93
+ const name = names.get(id)
94
+ const widens = target === 'company'
95
+
96
+ return [
97
+ {
98
+ target,
99
+ id,
100
+ label: name === undefined ? TARGET_LABELS[target] : `${TARGET_LABELS[target]}: ${name}`,
101
+ origin,
102
+ widens,
103
+ ticked: origin === 'created' && !widens,
104
+ },
105
+ ]
106
+ })
107
+ }
108
+
109
+ /**
110
+ * The address the form's email field holds in this submission, trimmed and
111
+ * lowercased as the server stores a blocked address.
112
+ *
113
+ * @returns null when the form's current fields have no email answer in this
114
+ * submission. The server then refuses to block a sender, so the
115
+ * confirmation does not offer it.
116
+ */
117
+ export function submittedEmail(
118
+ fields: readonly Pick<FormField, 'id' | 'mapTo'>[],
119
+ submission: Pick<FormSubmission, 'answers'>,
120
+ ): string | null {
121
+ const field = fields.find((candidate) => candidate.mapTo === PERSON_EMAIL_TARGET)
122
+ const answer = field === undefined ? undefined : submission.answers[field.id]?.trim().toLowerCase()
123
+
124
+ return answer === undefined || answer.length === 0 ? null : answer
125
+ }
126
+
127
+ /**
128
+ * Whether "Block this sender" starts ticked: only when the submission created
129
+ * the person. When it matched one, the address belongs to somebody already in
130
+ * the CRM, and a stranger may have typed a real contact's address. When nobody
131
+ * recorded which, the same doubt applies.
132
+ */
133
+ export function blockSenderStartsTicked(
134
+ submission: Pick<FormSubmission, 'personId' | 'createdRecordIds'>,
135
+ ): boolean {
136
+ return (
137
+ submission.personId !== null &&
138
+ submission.createdRecordIds !== null &&
139
+ submission.createdRecordIds.includes(submission.personId)
140
+ )
141
+ }
@@ -25,6 +25,8 @@ export interface PeopleDirectory {
25
25
  /** The first title a person holds, matching the mockup's primary position. */
26
26
  titleFor(personId: string): string | undefined
27
27
  companyNamesFor(personId: string): readonly string[]
28
+ /** The same companies as `companyNamesFor`, with ids, for cells that link to them. */
29
+ companiesFor(personId: string): readonly { readonly id: string; readonly name: string }[]
28
30
  readonly isLoading: boolean
29
31
  /**
30
32
  * False when these people hold more positions than one page could return.
@@ -57,12 +59,22 @@ export function usePeopleDirectory(personIds: readonly string[]): PeopleDirector
57
59
  return grouped
58
60
  }, [positions.records])
59
61
 
62
+ // Two positions at one company (a promotion kept as history, say) name the
63
+ // company once.
64
+ function companiesFor(personId: string): { readonly id: string; readonly name: string }[] {
65
+ const companyIds = new Set((byPerson.get(personId) ?? []).map((held) => held.companyId))
66
+
67
+ return [...companyIds].flatMap((companyId) => {
68
+ const name = companyNameById.get(companyId)
69
+
70
+ return name === undefined ? [] : [{ id: companyId, name }]
71
+ })
72
+ }
73
+
60
74
  return {
61
75
  titleFor: (personId) => byPerson.get(personId)?.[0]?.title,
62
- companyNamesFor: (personId) =>
63
- (byPerson.get(personId) ?? [])
64
- .map((held) => companyNameById.get(held.companyId))
65
- .filter((name): name is string => name !== undefined),
76
+ companyNamesFor: (personId) => companiesFor(personId).map((company) => company.name),
77
+ companiesFor,
66
78
  isLoading: positions.isLoading || companies.isLoading,
67
79
  isComplete: !positions.hasNext && !companies.hasNext,
68
80
  }
@@ -14,6 +14,7 @@ import type {
14
14
  RecordSidebarCard,
15
15
  RecordTab,
16
16
  RouteContribution,
17
+ UserMenuItem,
17
18
  } from './contributions.ts'
18
19
  import type { Overridable } from './overridable.ts'
19
20
  import { NO_UI_MODULES } from './registry.ts'
@@ -68,6 +69,11 @@ export function useAuthMethods(): readonly AuthMethod[] {
68
69
  return useUiExtensions().authMethods()
69
70
  }
70
71
 
72
+ /** Module rows for the user menu, in order. The shell renders them above Sign out. */
73
+ export function useUserMenuItems(): readonly UserMenuItem[] {
74
+ return useUiExtensions().userMenuItems()
75
+ }
76
+
71
77
  /** The agent the Agent menu's Run button dispatches to, when a module provides one. */
72
78
  export function useAgentRunner(): AgentRunner | undefined {
73
79
  return useUiExtensions().agentRunner()
@@ -51,6 +51,31 @@ export interface AuthMethod {
51
51
  readonly render: (context: AuthMethodContext) => ReactNode
52
52
  }
53
53
 
54
+ /**
55
+ * What a user-menu item is rendering against.
56
+ *
57
+ * `close` shuts the menu; call it when the item acts. `itemClassName` is the
58
+ * class core's own menu items use, so a contributed row looks like a core one.
59
+ */
60
+ export interface UserMenuItemContext {
61
+ readonly close: () => void
62
+ readonly itemClassName: string
63
+ }
64
+
65
+ /**
66
+ * A row in the user menu, the avatar menu at the top right of the shell.
67
+ *
68
+ * A render function rather than a fixed link: some items depend on something
69
+ * only the contributor can check (a cloud operator link appears only for an
70
+ * operator), and an item with nothing to offer renders `null` and leaves no
71
+ * gap. The rendered element should carry `role="menuitem"`.
72
+ */
73
+ export interface UserMenuItem {
74
+ readonly id: string
75
+ readonly order?: number
76
+ readonly render: (context: UserMenuItemContext) => ReactNode
77
+ }
78
+
54
79
  /** A whole page, mounted under the shell's chrome. */
55
80
  export interface RouteContribution {
56
81
  readonly path: string
@@ -13,6 +13,7 @@ import type {
13
13
  RecordSidebarCard,
14
14
  RecordTab,
15
15
  RouteContribution,
16
+ UserMenuItem,
16
17
  } from './contributions.ts'
17
18
  import { createOverrideStore } from './overridable.ts'
18
19
  import type { Overridable, OverrideStore } from './overridable.ts'
@@ -40,6 +41,8 @@ export interface UiModuleContext {
40
41
  dashboardCard(card: DashboardCard): void
41
42
  /** Another way to sign in, rendered beside the password form on `/login` and `/signup`. */
42
43
  authMethod(method: AuthMethod): void
44
+ /** A row in the user menu, above Sign out. */
45
+ userMenuItem(item: UserMenuItem): void
43
46
  /** The agent the Agent menu's Run button dispatches to. One per assembly. */
44
47
  agentRunner(runner: AgentRunner): void
45
48
  /** The wizard behind People's Add from notes. One per assembly. */
@@ -62,6 +65,7 @@ export interface UiExtensions {
62
65
  adminTabs(page: ExtensibleAdminPage): readonly AdminTab[]
63
66
  dashboardCards(): readonly DashboardCard[]
64
67
  authMethods(): readonly AuthMethod[]
68
+ userMenuItems(): readonly UserMenuItem[]
65
69
  /** The registered runner, or `undefined` when no module provides one. */
66
70
  agentRunner(): AgentRunner | undefined
67
71
  /** The registered intake wizard, or `undefined` when no module provides one. */
@@ -93,6 +97,7 @@ interface Accumulator {
93
97
  readonly adminTabs: Map<ExtensibleAdminPage, AdminTab[]>
94
98
  readonly dashboardCards: DashboardCard[]
95
99
  readonly authMethods: AuthMethod[]
100
+ readonly userMenuItems: UserMenuItem[]
96
101
  readonly overrides: OverrideStore
97
102
  }
98
103
 
@@ -167,6 +172,11 @@ function createModuleContext(
167
172
  accumulator.authMethods.push(method)
168
173
  },
169
174
 
175
+ userMenuItem(item) {
176
+ claim(taken, module.id, 'user.menu', item.id)
177
+ accumulator.userMenuItems.push(item)
178
+ },
179
+
170
180
  agentRunner(runner) {
171
181
  // One button, one agent: a second runner would silently win or lose.
172
182
  if (accumulator.agentRunner !== undefined) {
@@ -214,6 +224,7 @@ export function registerUiModules(modules: readonly UiModule[]): UiExtensions {
214
224
  adminTabs: new Map(),
215
225
  dashboardCards: [],
216
226
  authMethods: [],
227
+ userMenuItems: [],
217
228
  overrides: createOverrideStore(),
218
229
  }
219
230
  const taken = new Set<string>()
@@ -237,6 +248,7 @@ export function registerUiModules(modules: readonly UiModule[]): UiExtensions {
237
248
  adminTabs: (page) => inSlotOrder(accumulator.adminTabs.get(page) ?? []),
238
249
  dashboardCards: () => inSlotOrder(accumulator.dashboardCards),
239
250
  authMethods: () => inSlotOrder(accumulator.authMethods),
251
+ userMenuItems: () => inSlotOrder(accumulator.userMenuItems),
240
252
  agentRunner: () => accumulator.agentRunner,
241
253
  personIntake: () => accumulator.personIntake,
242
254
  componentFor: (token) => accumulator.overrides.get(token),
@@ -21,6 +21,7 @@ import { inSlotOrder } from './registry.ts'
21
21
  const NAV_ID_TO_MODULE_ID: Readonly<Record<string, string>> = {
22
22
  fundraising: 'raises',
23
23
  data: 'import-export',
24
+ 'bulk-jobs': 'bulk-actions',
24
25
  }
25
26
 
26
27
  export function useVisibleNavItems(