@kelpie/ui 0.26.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 (224) hide show
  1. package/dist/api/resources/account.d.ts +7 -1
  2. package/dist/api/resources/account.d.ts.map +1 -1
  3. package/dist/api/resources/account.js +17 -1
  4. package/dist/api/resources/account.js.map +1 -1
  5. package/dist/api/resources/bulkActions.d.ts +50 -0
  6. package/dist/api/resources/bulkActions.d.ts.map +1 -0
  7. package/dist/api/resources/bulkActions.js +192 -0
  8. package/dist/api/resources/bulkActions.js.map +1 -0
  9. package/dist/api/resources/forms.d.ts +26 -1
  10. package/dist/api/resources/forms.d.ts.map +1 -1
  11. package/dist/api/resources/forms.js +98 -1
  12. package/dist/api/resources/forms.js.map +1 -1
  13. package/dist/app/KelpieApp.d.ts.map +1 -1
  14. package/dist/app/KelpieApp.js +3 -1
  15. package/dist/app/KelpieApp.js.map +1 -1
  16. package/dist/components/ActivitiesPanel.d.ts.map +1 -1
  17. package/dist/components/ActivitiesPanel.js +3 -12
  18. package/dist/components/ActivitiesPanel.js.map +1 -1
  19. package/dist/components/BulkActions.d.ts +61 -0
  20. package/dist/components/BulkActions.d.ts.map +1 -0
  21. package/dist/components/BulkActions.js +351 -0
  22. package/dist/components/BulkActions.js.map +1 -0
  23. package/dist/components/BulkParamFields.d.ts +13 -0
  24. package/dist/components/BulkParamFields.d.ts.map +1 -0
  25. package/dist/components/BulkParamFields.js +177 -0
  26. package/dist/components/BulkParamFields.js.map +1 -0
  27. package/dist/components/CellLinks.d.ts +38 -0
  28. package/dist/components/CellLinks.d.ts.map +1 -0
  29. package/dist/components/CellLinks.js +58 -0
  30. package/dist/components/CellLinks.js.map +1 -0
  31. package/dist/components/CustomFieldsPanel.d.ts +12 -1
  32. package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
  33. package/dist/components/CustomFieldsPanel.js +5 -1
  34. package/dist/components/CustomFieldsPanel.js.map +1 -1
  35. package/dist/components/DataTable.d.ts +42 -1
  36. package/dist/components/DataTable.d.ts.map +1 -1
  37. package/dist/components/DataTable.js +51 -16
  38. package/dist/components/DataTable.js.map +1 -1
  39. package/dist/components/NotesPanel.d.ts.map +1 -1
  40. package/dist/components/NotesPanel.js +2 -15
  41. package/dist/components/NotesPanel.js.map +1 -1
  42. package/dist/components/PhonesField.d.ts.map +1 -1
  43. package/dist/components/PhonesField.js +1 -3
  44. package/dist/components/PhonesField.js.map +1 -1
  45. package/dist/components/Shell.d.ts.map +1 -1
  46. package/dist/components/Shell.js +16 -6
  47. package/dist/components/Shell.js.map +1 -1
  48. package/dist/components/TagInput.d.ts.map +1 -1
  49. package/dist/components/TagInput.js +5 -0
  50. package/dist/components/TagInput.js.map +1 -1
  51. package/dist/components/bulkActionParams.d.ts +71 -0
  52. package/dist/components/bulkActionParams.d.ts.map +1 -0
  53. package/dist/components/bulkActionParams.js +241 -0
  54. package/dist/components/bulkActionParams.js.map +1 -0
  55. package/dist/components/bulkActionSummary.d.ts +22 -0
  56. package/dist/components/bulkActionSummary.d.ts.map +1 -0
  57. package/dist/components/bulkActionSummary.js +68 -0
  58. package/dist/components/bulkActionSummary.js.map +1 -0
  59. package/dist/components/bulkJobStatus.d.ts +4 -0
  60. package/dist/components/bulkJobStatus.d.ts.map +1 -0
  61. package/dist/components/bulkJobStatus.js +10 -0
  62. package/dist/components/bulkJobStatus.js.map +1 -0
  63. package/dist/index.d.ts +2 -2
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +1 -1
  66. package/dist/index.js.map +1 -1
  67. package/dist/lib/attribution.d.ts +31 -0
  68. package/dist/lib/attribution.d.ts.map +1 -0
  69. package/dist/lib/attribution.js +48 -0
  70. package/dist/lib/attribution.js.map +1 -0
  71. package/dist/lib/bulkSelection.d.ts +43 -0
  72. package/dist/lib/bulkSelection.d.ts.map +1 -0
  73. package/dist/lib/bulkSelection.js +70 -0
  74. package/dist/lib/bulkSelection.js.map +1 -0
  75. package/dist/lib/contactLinks.d.ts +15 -0
  76. package/dist/lib/contactLinks.d.ts.map +1 -0
  77. package/dist/lib/contactLinks.js +22 -0
  78. package/dist/lib/contactLinks.js.map +1 -0
  79. package/dist/pages/BulkJobsPage.d.ts +3 -0
  80. package/dist/pages/BulkJobsPage.d.ts.map +1 -0
  81. package/dist/pages/BulkJobsPage.js +92 -0
  82. package/dist/pages/BulkJobsPage.js.map +1 -0
  83. package/dist/pages/CompaniesPage.d.ts.map +1 -1
  84. package/dist/pages/CompaniesPage.js +9 -5
  85. package/dist/pages/CompaniesPage.js.map +1 -1
  86. package/dist/pages/CompanyDetail.d.ts.map +1 -1
  87. package/dist/pages/CompanyDetail.js +4 -3
  88. package/dist/pages/CompanyDetail.js.map +1 -1
  89. package/dist/pages/DealsPage.d.ts.map +1 -1
  90. package/dist/pages/DealsPage.js +15 -4
  91. package/dist/pages/DealsPage.js.map +1 -1
  92. package/dist/pages/DecisionsPage.d.ts.map +1 -1
  93. package/dist/pages/DecisionsPage.js +11 -1
  94. package/dist/pages/DecisionsPage.js.map +1 -1
  95. package/dist/pages/EnquiriesPage.d.ts.map +1 -1
  96. package/dist/pages/EnquiriesPage.js +15 -6
  97. package/dist/pages/EnquiriesPage.js.map +1 -1
  98. package/dist/pages/EventDetail.d.ts.map +1 -1
  99. package/dist/pages/EventDetail.js +14 -6
  100. package/dist/pages/EventDetail.js.map +1 -1
  101. package/dist/pages/EventsPage.d.ts.map +1 -1
  102. package/dist/pages/EventsPage.js +22 -5
  103. package/dist/pages/EventsPage.js.map +1 -1
  104. package/dist/pages/FormsPage.d.ts.map +1 -1
  105. package/dist/pages/FormsPage.js +2 -2
  106. package/dist/pages/FormsPage.js.map +1 -1
  107. package/dist/pages/FundraisingPage.d.ts.map +1 -1
  108. package/dist/pages/FundraisingPage.js +15 -4
  109. package/dist/pages/FundraisingPage.js.map +1 -1
  110. package/dist/pages/HiringPage.d.ts.map +1 -1
  111. package/dist/pages/HiringPage.js +2 -1
  112. package/dist/pages/HiringPage.js.map +1 -1
  113. package/dist/pages/ListDetail.d.ts.map +1 -1
  114. package/dist/pages/ListDetail.js +39 -7
  115. package/dist/pages/ListDetail.js.map +1 -1
  116. package/dist/pages/ListsPage.d.ts.map +1 -1
  117. package/dist/pages/ListsPage.js +2 -1
  118. package/dist/pages/ListsPage.js.map +1 -1
  119. package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
  120. package/dist/pages/OpportunitiesPage.js +15 -6
  121. package/dist/pages/OpportunitiesPage.js.map +1 -1
  122. package/dist/pages/PartnershipsPage.d.ts.map +1 -1
  123. package/dist/pages/PartnershipsPage.js +15 -4
  124. package/dist/pages/PartnershipsPage.js.map +1 -1
  125. package/dist/pages/PeoplePage.d.ts.map +1 -1
  126. package/dist/pages/PeoplePage.js +10 -9
  127. package/dist/pages/PeoplePage.js.map +1 -1
  128. package/dist/pages/PlanningPage.d.ts.map +1 -1
  129. package/dist/pages/PlanningPage.js +15 -4
  130. package/dist/pages/PlanningPage.js.map +1 -1
  131. package/dist/pages/RoleDetail.d.ts.map +1 -1
  132. package/dist/pages/RoleDetail.js +12 -4
  133. package/dist/pages/RoleDetail.js.map +1 -1
  134. package/dist/pages/dashboard/sections.d.ts.map +1 -1
  135. package/dist/pages/dashboard/sections.js +8 -10
  136. package/dist/pages/dashboard/sections.js.map +1 -1
  137. package/dist/pages/forms/BlockedSendersPage.d.ts +10 -0
  138. package/dist/pages/forms/BlockedSendersPage.d.ts.map +1 -0
  139. package/dist/pages/forms/BlockedSendersPage.js +65 -0
  140. package/dist/pages/forms/BlockedSendersPage.js.map +1 -0
  141. package/dist/pages/forms/MarkSpamPanel.d.ts +19 -0
  142. package/dist/pages/forms/MarkSpamPanel.d.ts.map +1 -0
  143. package/dist/pages/forms/MarkSpamPanel.js +62 -0
  144. package/dist/pages/forms/MarkSpamPanel.js.map +1 -0
  145. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  146. package/dist/pages/forms/SubmissionDetail.js +41 -11
  147. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  148. package/dist/pages/forms/SubmissionsTable.d.ts +1 -1
  149. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  150. package/dist/pages/forms/SubmissionsTable.js +6 -4
  151. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  152. package/dist/pages/forms/markSpamChoices.d.ts +51 -0
  153. package/dist/pages/forms/markSpamChoices.d.ts.map +1 -0
  154. package/dist/pages/forms/markSpamChoices.js +96 -0
  155. package/dist/pages/forms/markSpamChoices.js.map +1 -0
  156. package/dist/pages/positionDirectory.d.ts +5 -0
  157. package/dist/pages/positionDirectory.d.ts.map +1 -1
  158. package/dist/pages/positionDirectory.js +11 -3
  159. package/dist/pages/positionDirectory.js.map +1 -1
  160. package/dist/registry/context.d.ts +3 -1
  161. package/dist/registry/context.d.ts.map +1 -1
  162. package/dist/registry/context.js +4 -0
  163. package/dist/registry/context.js.map +1 -1
  164. package/dist/registry/contributions.d.ts +23 -0
  165. package/dist/registry/contributions.d.ts.map +1 -1
  166. package/dist/registry/contributions.js.map +1 -1
  167. package/dist/registry/registry.d.ts +4 -1
  168. package/dist/registry/registry.d.ts.map +1 -1
  169. package/dist/registry/registry.js +6 -0
  170. package/dist/registry/registry.js.map +1 -1
  171. package/dist/registry/visibleNav.d.ts.map +1 -1
  172. package/dist/registry/visibleNav.js +1 -0
  173. package/dist/registry/visibleNav.js.map +1 -1
  174. package/package.json +3 -3
  175. package/src/api/resources/account.ts +20 -0
  176. package/src/api/resources/bulkActions.ts +267 -0
  177. package/src/api/resources/forms.ts +135 -0
  178. package/src/app/KelpieApp.tsx +5 -0
  179. package/src/components/ActivitiesPanel.tsx +3 -14
  180. package/src/components/BulkActions.tsx +961 -0
  181. package/src/components/BulkParamFields.tsx +524 -0
  182. package/src/components/CellLinks.tsx +138 -0
  183. package/src/components/CustomFieldsPanel.tsx +6 -2
  184. package/src/components/DataTable.tsx +142 -2
  185. package/src/components/NotesPanel.tsx +2 -17
  186. package/src/components/PhonesField.tsx +2 -4
  187. package/src/components/Shell.tsx +23 -6
  188. package/src/components/TagInput.tsx +5 -0
  189. package/src/components/bulkActionParams.ts +405 -0
  190. package/src/components/bulkActionSummary.ts +104 -0
  191. package/src/components/bulkJobStatus.ts +11 -0
  192. package/src/index.ts +3 -0
  193. package/src/lib/attribution.ts +59 -0
  194. package/src/lib/bulkSelection.ts +128 -0
  195. package/src/lib/contactLinks.ts +25 -0
  196. package/src/pages/BulkJobsPage.tsx +206 -0
  197. package/src/pages/CompaniesPage.tsx +21 -6
  198. package/src/pages/CompanyDetail.tsx +4 -3
  199. package/src/pages/DealsPage.tsx +30 -2
  200. package/src/pages/DecisionsPage.tsx +21 -1
  201. package/src/pages/EnquiriesPage.tsx +33 -5
  202. package/src/pages/EventDetail.tsx +43 -16
  203. package/src/pages/EventsPage.tsx +35 -4
  204. package/src/pages/FormsPage.tsx +7 -1
  205. package/src/pages/FundraisingPage.tsx +30 -2
  206. package/src/pages/HiringPage.tsx +6 -1
  207. package/src/pages/ListDetail.tsx +69 -5
  208. package/src/pages/ListsPage.tsx +6 -1
  209. package/src/pages/OpportunitiesPage.tsx +33 -5
  210. package/src/pages/PartnershipsPage.tsx +30 -2
  211. package/src/pages/PeoplePage.tsx +26 -21
  212. package/src/pages/PlanningPage.tsx +65 -24
  213. package/src/pages/RoleDetail.tsx +35 -7
  214. package/src/pages/dashboard/sections.tsx +13 -14
  215. package/src/pages/forms/BlockedSendersPage.tsx +155 -0
  216. package/src/pages/forms/MarkSpamPanel.tsx +193 -0
  217. package/src/pages/forms/SubmissionDetail.tsx +73 -18
  218. package/src/pages/forms/SubmissionsTable.tsx +7 -5
  219. package/src/pages/forms/markSpamChoices.ts +141 -0
  220. package/src/pages/positionDirectory.ts +16 -4
  221. package/src/registry/context.ts +6 -0
  222. package/src/registry/contributions.ts +25 -0
  223. package/src/registry/registry.ts +12 -0
  224. package/src/registry/visibleNav.ts +1 -0
@@ -0,0 +1,155 @@
1
+ import type { FormBlockedSender } from '@kelpie/schemas'
2
+ import { useState } from 'react'
3
+ import { Link } from 'react-router'
4
+
5
+ import { useTimezone } from '../../api/resources/account.ts'
6
+ import {
7
+ useCreateFormBlockedSender,
8
+ useDeleteFormBlockedSender,
9
+ useFormBlockedSenders,
10
+ } from '../../api/resources/forms.ts'
11
+ import { DataTable } from '../../components/DataTable.tsx'
12
+ import type { Column } from '../../components/DataTable.tsx'
13
+ import { PageHeader } from '../../components/PageHeader.tsx'
14
+ import { Paginator } from '../../components/Paginator.tsx'
15
+ import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
16
+ import { formatDateTime } from '../../lib/dates.ts'
17
+
18
+ /**
19
+ * The workspace's blocked senders: addresses whose submits are held as spam
20
+ * on every form.
21
+ *
22
+ * An address arrives here from "Mark as spam" on a submission, or typed in
23
+ * by hand. Removing one lets that address submit again; what it already sent
24
+ * stays where it is.
25
+ */
26
+ export function BlockedSendersPage(): React.JSX.Element {
27
+ const blocked = useFormBlockedSenders()
28
+ const create = useCreateFormBlockedSender()
29
+ const remove = useDeleteFormBlockedSender()
30
+ const timezone = useTimezone()
31
+ const [email, setEmail] = useState('')
32
+
33
+ function add(): void {
34
+ const address = email.trim()
35
+
36
+ if (address.length === 0) {
37
+ return
38
+ }
39
+
40
+ create
41
+ .runAsync({ email: address })
42
+ .then(() => {
43
+ setEmail('')
44
+ })
45
+ .catch(() => undefined)
46
+ }
47
+
48
+ const columns: readonly Column<FormBlockedSender>[] = [
49
+ {
50
+ key: 'email',
51
+ header: 'Email address',
52
+ render: (row) => <span className="text-ink">{row.email}</span>,
53
+ },
54
+ {
55
+ key: 'createdAt',
56
+ header: 'Blocked',
57
+ className: 'w-48',
58
+ render: (row) => (
59
+ <span className="font-mono text-[12px] text-ink-muted">
60
+ {formatDateTime(row.createdAt, timezone)}
61
+ </span>
62
+ ),
63
+ },
64
+ {
65
+ key: 'remove',
66
+ header: '',
67
+ className: 'w-24 text-right',
68
+ render: (row) => (
69
+ <button
70
+ type="button"
71
+ disabled={remove.isPending}
72
+ onClick={() => {
73
+ remove.run(row.id)
74
+ }}
75
+ aria-label={`Unblock ${row.email}`}
76
+ className="rounded-md border border-border px-2.5 py-1 text-[12px] font-medium text-ink-muted transition hover:border-danger hover:text-danger disabled:opacity-50"
77
+ >
78
+ Unblock
79
+ </button>
80
+ ),
81
+ },
82
+ ]
83
+
84
+ return (
85
+ <div className="animate-fade-in mx-auto max-w-3xl">
86
+ <Link
87
+ to="/forms"
88
+ className="mb-4 inline-flex text-[12px] font-medium text-ink-muted transition hover:text-accent"
89
+ >
90
+ ← Forms
91
+ </Link>
92
+ <PageHeader
93
+ title="Blocked senders"
94
+ description="Kelpie holds every submission from these addresses as spam, on all your forms. The sender still sees the thank-you message."
95
+ />
96
+
97
+ <form
98
+ className="mb-4 flex flex-wrap items-center gap-2"
99
+ onSubmit={(event) => {
100
+ event.preventDefault()
101
+ add()
102
+ }}
103
+ >
104
+ <label className="sr-only" htmlFor="blocked-sender-email">
105
+ Email address to block
106
+ </label>
107
+ <input
108
+ id="blocked-sender-email"
109
+ type="email"
110
+ value={email}
111
+ onChange={(event) => {
112
+ setEmail(event.target.value)
113
+ }}
114
+ placeholder="name@example.com"
115
+ className="w-full max-w-xs rounded-md border border-border bg-transparent px-2.5 py-1.5 text-[13px] outline-none placeholder:text-ink-faint focus:border-accent"
116
+ />
117
+ <button
118
+ type="submit"
119
+ disabled={create.isPending || email.trim().length === 0}
120
+ className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover disabled:opacity-50"
121
+ >
122
+ {create.isPending ? 'Blocking…' : 'Block'}
123
+ </button>
124
+ </form>
125
+
126
+ {create.error !== null && (
127
+ <div className="mb-3">
128
+ <ErrorPanel error={create.error} />
129
+ </div>
130
+ )}
131
+ {remove.error !== null && (
132
+ <div className="mb-3">
133
+ <ErrorPanel error={remove.error} />
134
+ </div>
135
+ )}
136
+
137
+ {blocked.error !== null ? (
138
+ <ErrorPanel error={blocked.error} />
139
+ ) : blocked.isLoading ? (
140
+ <LoadingPanel label="Loading blocked senders…" />
141
+ ) : (
142
+ <>
143
+ <DataTable
144
+ columns={columns}
145
+ rows={blocked.records}
146
+ getRowId={(row) => row.id}
147
+ emptyMessage="No blocked senders"
148
+ emptyDescription="Block an address here, or tick “Block” when you mark a submission as spam."
149
+ />
150
+ <Paginator list={blocked} />
151
+ </>
152
+ )}
153
+ </div>
154
+ )
155
+ }
@@ -0,0 +1,193 @@
1
+ import type { FormField, FormSubmission } from '@kelpie/schemas'
2
+ import { useState } from 'react'
3
+
4
+ import { useMarkFormSubmissionSpam } from '../../api/resources/forms.ts'
5
+ import { ErrorPanel } from '../../components/QueryState.tsx'
6
+ import { blockSenderStartsTicked, markSpamRecordChoices, submittedEmail } from './markSpamChoices.ts'
7
+ import type { MarkSpamRecordChoice } from './markSpamChoices.ts'
8
+
9
+ /**
10
+ * The confirmation for marking an accepted submission as spam.
11
+ *
12
+ * Each linked record has a box. A record the submission created starts
13
+ * ticked; one it matched, or one nobody recorded, starts clear, because a
14
+ * delete cannot be undone. A company starts clear even when created, because
15
+ * its delete takes every position at it. Blocking the sender is offered only
16
+ * when the submission has an email answer, and starts ticked only when the
17
+ * submission created the person (`markSpamChoices.ts`).
18
+ */
19
+ export function MarkSpamPanel({
20
+ fields,
21
+ submission,
22
+ nameById,
23
+ onClose,
24
+ }: {
25
+ /** The form's current fields, to find the email answer. */
26
+ readonly fields: readonly Pick<FormField, 'id' | 'mapTo'>[]
27
+ readonly submission: FormSubmission
28
+ readonly nameById: ReadonlyMap<string, string>
29
+ readonly onClose: () => void
30
+ }): React.JSX.Element {
31
+ const markSpam = useMarkFormSubmissionSpam()
32
+ const choices = markSpamRecordChoices(submission, nameById)
33
+ const email = submittedEmail(fields, submission)
34
+ const [ticked, setTicked] = useState<ReadonlySet<string>>(
35
+ () => new Set(choices.filter((choice) => choice.ticked).map((choice) => choice.id)),
36
+ )
37
+ const blockIsSafe = blockSenderStartsTicked(submission)
38
+ const [blockSender, setBlockSender] = useState(email !== null && blockIsSafe)
39
+
40
+ function toggle(id: string): void {
41
+ setTicked((current) => {
42
+ const next = new Set(current)
43
+
44
+ if (next.has(id)) {
45
+ next.delete(id)
46
+ } else {
47
+ next.add(id)
48
+ }
49
+
50
+ return next
51
+ })
52
+ }
53
+
54
+ return (
55
+ <div className="mt-4 rounded-md border border-border bg-surface-raised p-4">
56
+ <p className="text-[13px] font-medium text-ink">Mark this submission as spam</p>
57
+ <p className="mt-0.5 text-[12px] text-ink-muted">
58
+ Kelpie holds it with your other spam and unlinks its records. Releasing it later is not
59
+ an undo: Kelpie runs the form again, so it creates new records and sends the emails again.
60
+ Records you keep now stay unlinked.
61
+ </p>
62
+
63
+ {choices.length > 0 && (
64
+ <fieldset className="mt-3">
65
+ <legend className="text-[12px] font-medium text-ink-muted">
66
+ Delete the records it linked
67
+ </legend>
68
+ <ul className="mt-1.5 space-y-1.5">
69
+ {choices.map((choice) => (
70
+ <RecordChoice
71
+ key={choice.id}
72
+ choice={choice}
73
+ checked={ticked.has(choice.id)}
74
+ onToggle={() => {
75
+ toggle(choice.id)
76
+ }}
77
+ />
78
+ ))}
79
+ </ul>
80
+ <p className="mt-1.5 text-[12px] text-ink-faint">
81
+ A record you leave unticked stays in your CRM. A deleted record cannot be restored.
82
+ </p>
83
+ </fieldset>
84
+ )}
85
+
86
+ {email !== null && (
87
+ <label className="mt-3 flex items-start gap-2 text-[13px] text-ink">
88
+ <input
89
+ type="checkbox"
90
+ checked={blockSender}
91
+ onChange={(event) => {
92
+ setBlockSender(event.target.checked)
93
+ }}
94
+ className="mt-0.5 h-3.5 w-3.5 rounded border-border text-accent focus:ring-accent"
95
+ />
96
+ <span>
97
+ Block <span className="font-medium">{email}</span> from future submissions
98
+ {!blockIsSafe && (
99
+ <span className="block text-[12px] text-warning">
100
+ This address may belong to a real contact. Someone can type another person's
101
+ address into a form.
102
+ </span>
103
+ )}
104
+ </span>
105
+ </label>
106
+ )}
107
+
108
+ <p className="mt-3 text-[12px] text-ink-muted">
109
+ Emails this submission already sent cannot be unsent.
110
+ </p>
111
+
112
+ {markSpam.error !== null && (
113
+ <div className="mt-3">
114
+ <ErrorPanel error={markSpam.error} />
115
+ </div>
116
+ )}
117
+
118
+ <div className="mt-4 flex justify-end gap-2">
119
+ <button
120
+ type="button"
121
+ onClick={onClose}
122
+ disabled={markSpam.isPending}
123
+ className="rounded-md px-2.5 py-1 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50"
124
+ >
125
+ Cancel
126
+ </button>
127
+ <button
128
+ type="button"
129
+ disabled={markSpam.isPending}
130
+ onClick={() => {
131
+ markSpam
132
+ .runAsync({
133
+ formId: submission.formId,
134
+ submissionId: submission.id,
135
+ deleteRecordIds: choices
136
+ .filter((choice) => ticked.has(choice.id))
137
+ .map((choice) => choice.id),
138
+ blockSender: email !== null && blockSender,
139
+ })
140
+ .then(onClose)
141
+ .catch(() => undefined)
142
+ }}
143
+ className="rounded-md bg-danger px-3 py-1.5 text-[12px] font-semibold text-danger-fg transition hover:opacity-90 disabled:opacity-50"
144
+ >
145
+ {markSpam.isPending ? 'Marking…' : 'Mark as spam'}
146
+ </button>
147
+ </div>
148
+ </div>
149
+ )
150
+ }
151
+
152
+ /** What the confirmation says beside a record, by whether this submission made it. */
153
+ const ORIGIN_NOTES: Readonly<Record<MarkSpamRecordChoice['origin'], string>> = {
154
+ created: 'This submission created it.',
155
+ matched: 'It was in your CRM before this submission.',
156
+ unknown: 'Kelpie did not record whether this submission created it. Check before you delete.',
157
+ }
158
+
159
+ function RecordChoice({
160
+ choice,
161
+ checked,
162
+ onToggle,
163
+ }: {
164
+ readonly choice: MarkSpamRecordChoice
165
+ readonly checked: boolean
166
+ readonly onToggle: () => void
167
+ }): React.JSX.Element {
168
+ return (
169
+ <li>
170
+ <label className="flex items-start gap-2 text-[13px] text-ink">
171
+ <input
172
+ type="checkbox"
173
+ checked={checked}
174
+ onChange={onToggle}
175
+ className="mt-0.5 h-3.5 w-3.5 rounded border-border text-accent focus:ring-accent"
176
+ />
177
+ <span>
178
+ {choice.label}
179
+ <span
180
+ className={`block text-[12px] ${choice.origin === 'unknown' ? 'text-warning' : 'text-ink-faint'}`}
181
+ >
182
+ {ORIGIN_NOTES[choice.origin]}
183
+ </span>
184
+ {choice.widens && (
185
+ <span className="block text-[12px] text-warning">
186
+ Deleting a company removes every position at it, including other people's.
187
+ </span>
188
+ )}
189
+ </span>
190
+ </label>
191
+ </li>
192
+ )
193
+ }
@@ -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
+ }