@kelpie/ui 0.17.0 → 0.19.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 (189) hide show
  1. package/dist/api/resources/ai.d.ts +5 -0
  2. package/dist/api/resources/ai.d.ts.map +1 -1
  3. package/dist/api/resources/ai.js +9 -1
  4. package/dist/api/resources/ai.js.map +1 -1
  5. package/dist/api/resources/forms.d.ts +8 -0
  6. package/dist/api/resources/forms.d.ts.map +1 -1
  7. package/dist/api/resources/forms.js +39 -0
  8. package/dist/api/resources/forms.js.map +1 -1
  9. package/dist/api/resources/personIntake.d.ts +12 -0
  10. package/dist/api/resources/personIntake.d.ts.map +1 -0
  11. package/dist/api/resources/personIntake.js +54 -0
  12. package/dist/api/resources/personIntake.js.map +1 -0
  13. package/dist/app/KelpieApp.js +2 -2
  14. package/dist/app/KelpieApp.js.map +1 -1
  15. package/dist/components/AgentTasks.js +2 -2
  16. package/dist/components/AgentTasks.js.map +1 -1
  17. package/dist/components/AiDrawer.d.ts +13 -0
  18. package/dist/components/AiDrawer.d.ts.map +1 -0
  19. package/dist/components/AiDrawer.js +165 -0
  20. package/dist/components/AiDrawer.js.map +1 -0
  21. package/dist/components/ApiKeysPanel.js +1 -1
  22. package/dist/components/DataTable.js +1 -1
  23. package/dist/components/KanbanBoard.d.ts +5 -1
  24. package/dist/components/KanbanBoard.d.ts.map +1 -1
  25. package/dist/components/KanbanBoard.js +37 -2
  26. package/dist/components/KanbanBoard.js.map +1 -1
  27. package/dist/components/NotesPanel.js +2 -2
  28. package/dist/components/NotesPanel.js.map +1 -1
  29. package/dist/components/PageHeader.js +1 -1
  30. package/dist/components/PageHeader.js.map +1 -1
  31. package/dist/components/PersonIntakeDialog.d.ts +19 -0
  32. package/dist/components/PersonIntakeDialog.d.ts.map +1 -0
  33. package/dist/components/PersonIntakeDialog.js +87 -0
  34. package/dist/components/PersonIntakeDialog.js.map +1 -0
  35. package/dist/components/PersonIntakePanel.d.ts +21 -0
  36. package/dist/components/PersonIntakePanel.d.ts.map +1 -0
  37. package/dist/components/PersonIntakePanel.js +76 -0
  38. package/dist/components/PersonIntakePanel.js.map +1 -0
  39. package/dist/components/SegmentedControl.js +2 -2
  40. package/dist/components/SegmentedControl.js.map +1 -1
  41. package/dist/components/Shell.d.ts.map +1 -1
  42. package/dist/components/Shell.js +40 -4
  43. package/dist/components/Shell.js.map +1 -1
  44. package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
  45. package/dist/components/WorkspaceSwitcher.js +10 -2
  46. package/dist/components/WorkspaceSwitcher.js.map +1 -1
  47. package/dist/components/aiDrawerState.d.ts +45 -0
  48. package/dist/components/aiDrawerState.d.ts.map +1 -0
  49. package/dist/components/aiDrawerState.js +14 -0
  50. package/dist/components/aiDrawerState.js.map +1 -0
  51. package/dist/components/personIntakeTask.d.ts +5 -0
  52. package/dist/components/personIntakeTask.d.ts.map +1 -0
  53. package/dist/components/personIntakeTask.js +13 -0
  54. package/dist/components/personIntakeTask.js.map +1 -0
  55. package/dist/index.d.ts +5 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +5 -2
  58. package/dist/index.js.map +1 -1
  59. package/dist/lib/mediaQuery.d.ts +9 -0
  60. package/dist/lib/mediaQuery.d.ts.map +1 -0
  61. package/dist/lib/mediaQuery.js +24 -0
  62. package/dist/lib/mediaQuery.js.map +1 -0
  63. package/dist/modules/PersonIntakeWizard.d.ts +3 -0
  64. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -0
  65. package/dist/modules/PersonIntakeWizard.js +227 -0
  66. package/dist/modules/PersonIntakeWizard.js.map +1 -0
  67. package/dist/modules/ai.d.ts +4 -3
  68. package/dist/modules/ai.d.ts.map +1 -1
  69. package/dist/modules/ai.js +10 -6
  70. package/dist/modules/ai.js.map +1 -1
  71. package/dist/modules/aiRunner.d.ts.map +1 -1
  72. package/dist/modules/aiRunner.js +7 -5
  73. package/dist/modules/aiRunner.js.map +1 -1
  74. package/dist/modules/personIntakeSelection.d.ts +7 -0
  75. package/dist/modules/personIntakeSelection.d.ts.map +1 -0
  76. package/dist/modules/personIntakeSelection.js +21 -0
  77. package/dist/modules/personIntakeSelection.js.map +1 -0
  78. package/dist/pages/FormDetail.d.ts.map +1 -1
  79. package/dist/pages/FormDetail.js +7 -7
  80. package/dist/pages/FormDetail.js.map +1 -1
  81. package/dist/pages/FormsPage.js +4 -4
  82. package/dist/pages/FormsPage.js.map +1 -1
  83. package/dist/pages/ListDetail.d.ts.map +1 -1
  84. package/dist/pages/ListDetail.js +2 -2
  85. package/dist/pages/ListDetail.js.map +1 -1
  86. package/dist/pages/PeoplePage.d.ts.map +1 -1
  87. package/dist/pages/PeoplePage.js +9 -1
  88. package/dist/pages/PeoplePage.js.map +1 -1
  89. package/dist/pages/RoleDetail.d.ts.map +1 -1
  90. package/dist/pages/RoleDetail.js +3 -3
  91. package/dist/pages/RoleDetail.js.map +1 -1
  92. package/dist/pages/account/ConnectedAppsPage.js +1 -1
  93. package/dist/pages/admin/AiAdminPage.d.ts +2 -0
  94. package/dist/pages/admin/AiAdminPage.d.ts.map +1 -0
  95. package/dist/pages/admin/AiAdminPage.js +19 -0
  96. package/dist/pages/admin/AiAdminPage.js.map +1 -0
  97. package/dist/pages/admin/AiPage.d.ts +4 -1
  98. package/dist/pages/admin/AiPage.d.ts.map +1 -1
  99. package/dist/pages/admin/AiPage.js +77 -15
  100. package/dist/pages/admin/AiPage.js.map +1 -1
  101. package/dist/pages/admin/DataPage.js +2 -2
  102. package/dist/pages/admin/McpPanel.d.ts +3 -0
  103. package/dist/pages/admin/McpPanel.d.ts.map +1 -0
  104. package/dist/pages/admin/McpPanel.js +123 -0
  105. package/dist/pages/admin/McpPanel.js.map +1 -0
  106. package/dist/pages/admin/PrivacyPage.js +19 -3
  107. package/dist/pages/admin/PrivacyPage.js.map +1 -1
  108. package/dist/pages/forms/AddFieldMenu.js +2 -2
  109. package/dist/pages/forms/AddFieldMenu.js.map +1 -1
  110. package/dist/pages/forms/EmbedPanel.js +5 -2
  111. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  112. package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
  113. package/dist/pages/forms/FieldsEditor.js +90 -8
  114. package/dist/pages/forms/FieldsEditor.js.map +1 -1
  115. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  116. package/dist/pages/forms/FormSettings.js +73 -6
  117. package/dist/pages/forms/FormSettings.js.map +1 -1
  118. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  119. package/dist/pages/forms/SubmissionDetail.js +2 -1
  120. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  121. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  122. package/dist/pages/forms/SubmissionsTable.js +2 -1
  123. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  124. package/dist/pages/forms/fieldList.d.ts +2 -2
  125. package/dist/pages/forms/fieldList.d.ts.map +1 -1
  126. package/dist/pages/forms/fieldList.js +38 -10
  127. package/dist/pages/forms/fieldList.js.map +1 -1
  128. package/dist/pages/forms/template.d.ts.map +1 -1
  129. package/dist/pages/forms/template.js +13 -0
  130. package/dist/pages/forms/template.js.map +1 -1
  131. package/dist/pages/handbook/HandbookPage.js +4 -4
  132. package/dist/pages/handbook/HandbookPage.js.map +1 -1
  133. package/dist/registry/context.d.ts +5 -1
  134. package/dist/registry/context.d.ts.map +1 -1
  135. package/dist/registry/context.js +8 -0
  136. package/dist/registry/context.js.map +1 -1
  137. package/dist/registry/contributions.d.ts +37 -1
  138. package/dist/registry/contributions.d.ts.map +1 -1
  139. package/dist/registry/registry.d.ts +8 -1
  140. package/dist/registry/registry.d.ts.map +1 -1
  141. package/dist/registry/registry.js +13 -0
  142. package/dist/registry/registry.js.map +1 -1
  143. package/package.json +2 -2
  144. package/src/api/resources/ai.ts +11 -1
  145. package/src/api/resources/forms.ts +56 -0
  146. package/src/api/resources/personIntake.ts +95 -0
  147. package/src/app/KelpieApp.tsx +4 -2
  148. package/src/components/AgentTasks.tsx +2 -2
  149. package/src/components/AiDrawer.tsx +272 -0
  150. package/src/components/ApiKeysPanel.tsx +1 -1
  151. package/src/components/DataTable.tsx +1 -1
  152. package/src/components/KanbanBoard.tsx +119 -2
  153. package/src/components/NotesPanel.tsx +7 -4
  154. package/src/components/PageHeader.tsx +1 -1
  155. package/src/components/PersonIntakePanel.tsx +193 -0
  156. package/src/components/SegmentedControl.tsx +2 -2
  157. package/src/components/Shell.tsx +99 -13
  158. package/src/components/WorkspaceSwitcher.tsx +13 -2
  159. package/src/components/aiDrawerState.ts +61 -0
  160. package/src/components/personIntakeTask.tsx +14 -0
  161. package/src/index.ts +12 -1
  162. package/src/lib/mediaQuery.ts +32 -0
  163. package/src/modules/PersonIntakeWizard.tsx +638 -0
  164. package/src/modules/ai.tsx +10 -6
  165. package/src/modules/aiRunner.ts +8 -5
  166. package/src/modules/personIntakeSelection.ts +24 -0
  167. package/src/pages/FormDetail.tsx +18 -14
  168. package/src/pages/FormsPage.tsx +4 -4
  169. package/src/pages/ListDetail.tsx +5 -3
  170. package/src/pages/PeoplePage.tsx +18 -5
  171. package/src/pages/RoleDetail.tsx +10 -5
  172. package/src/pages/account/ConnectedAppsPage.tsx +1 -1
  173. package/src/pages/admin/AiAdminPage.tsx +52 -0
  174. package/src/pages/admin/AiPage.tsx +136 -32
  175. package/src/pages/admin/DataPage.tsx +2 -2
  176. package/src/pages/admin/{McpPage.tsx → McpPanel.tsx} +4 -6
  177. package/src/pages/admin/PrivacyPage.tsx +42 -0
  178. package/src/pages/forms/AddFieldMenu.tsx +2 -2
  179. package/src/pages/forms/EmbedPanel.tsx +5 -1
  180. package/src/pages/forms/FieldsEditor.tsx +204 -15
  181. package/src/pages/forms/FormSettings.tsx +156 -9
  182. package/src/pages/forms/SubmissionDetail.tsx +2 -1
  183. package/src/pages/forms/SubmissionsTable.tsx +2 -1
  184. package/src/pages/forms/fieldList.ts +39 -10
  185. package/src/pages/forms/template.ts +13 -0
  186. package/src/pages/handbook/HandbookPage.tsx +5 -5
  187. package/src/registry/context.ts +13 -0
  188. package/src/registry/contributions.ts +39 -1
  189. package/src/registry/registry.ts +30 -0
@@ -58,12 +58,15 @@ function PurposesAdmin(): React.JSX.Element {
58
58
  slug: 'contact',
59
59
  label: 'Contact',
60
60
  description: 'Being contacted by the workspace about our work together.',
61
+ statement:
62
+ 'I consent to {{workspace}} contacting me and retaining my information for the purpose of handling my enquiry.',
61
63
  defaultStatus: 'unknown',
62
64
  })
63
65
  await create.runAsync({
64
66
  slug: 'marketing',
65
67
  label: 'Marketing',
66
68
  description: 'Marketing communications — newsletters, product updates, and campaigns.',
69
+ statement: 'I consent to {{workspace}} retaining my information for marketing purposes.',
67
70
  defaultStatus: 'unknown',
68
71
  })
69
72
  } catch {
@@ -165,6 +168,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
165
168
  const [slug, setSlug] = useState('')
166
169
  const [slugEdited, setSlugEdited] = useState(false)
167
170
  const [description, setDescription] = useState('')
171
+ const [statement, setStatement] = useState('')
168
172
  const [defaultStatus, setDefaultStatus] = useState<ConsentPurposeStatus>('unknown')
169
173
 
170
174
  const derivedSlug = useMemo(
@@ -183,6 +187,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
183
187
  slug: derivedSlug,
184
188
  label: trimmedLabel,
185
189
  description: description.trim(),
190
+ statement: statement.trim(),
186
191
  defaultStatus,
187
192
  })
188
193
  .then(() => {
@@ -190,6 +195,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
190
195
  setSlug('')
191
196
  setSlugEdited(false)
192
197
  setDescription('')
198
+ setStatement('')
193
199
  setDefaultStatus('unknown')
194
200
  onDone()
195
201
  })
@@ -252,6 +258,7 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
252
258
  }}
253
259
  />
254
260
  </Field>
261
+ <StatementField value={statement} onChange={setStatement} />
255
262
 
256
263
  {create.error !== null && <ErrorPanel error={create.error} />}
257
264
 
@@ -277,6 +284,32 @@ function AddPurposeForm({ onDone }: AddPurposeFormProps): React.JSX.Element {
277
284
  )
278
285
  }
279
286
 
287
+ /**
288
+ * The consent statement a form shows beside this purpose's checkbox. The
289
+ * Person record keeps showing the label.
290
+ */
291
+ function StatementField({
292
+ value,
293
+ onChange,
294
+ }: {
295
+ readonly value: string
296
+ readonly onChange: (value: string) => void
297
+ }): React.JSX.Element {
298
+ return (
299
+ <Field label="Consent statement (shown on forms instead of the label; {{workspace}} becomes the workspace name)">
300
+ <textarea
301
+ className="min-h-[60px] w-full rounded-md border border-border bg-transparent px-2 py-1 text-[13px] outline-none focus:border-accent"
302
+ value={value}
303
+ maxLength={1000}
304
+ placeholder="I consent to {{workspace}} …"
305
+ onChange={(event) => {
306
+ onChange(event.target.value)
307
+ }}
308
+ />
309
+ </Field>
310
+ )
311
+ }
312
+
280
313
  interface PurposeRowProps {
281
314
  readonly purpose: ConsentPurpose
282
315
  }
@@ -287,6 +320,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
287
320
  const [editing, setEditing] = useState(false)
288
321
  const [label, setLabel] = useState(purpose.label)
289
322
  const [description, setDescription] = useState(purpose.description)
323
+ const [statement, setStatement] = useState(purpose.statement)
290
324
  const [defaultStatus, setDefaultStatus] = useState<ConsentPurposeStatus>(purpose.defaultStatus)
291
325
  const [confirmingDelete, setConfirmingDelete] = useState(false)
292
326
 
@@ -298,6 +332,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
298
332
  changes: {
299
333
  label: label.trim(),
300
334
  description: description.trim(),
335
+ statement: statement.trim(),
301
336
  defaultStatus,
302
337
  },
303
338
  })
@@ -325,6 +360,12 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
325
360
  {purpose.description.length > 0 && (
326
361
  <p className="mt-1 text-[12px] text-ink-muted">{purpose.description}</p>
327
362
  )}
363
+ {purpose.statement.length > 0 && (
364
+ <p className="mt-1 text-[12px] text-ink">
365
+ <span className="text-ink-faint">On forms: </span>
366
+ {purpose.statement}
367
+ </p>
368
+ )}
328
369
  </div>
329
370
  <div className="flex shrink-0 gap-2">
330
371
  <button
@@ -384,6 +425,7 @@ function PurposeRow({ purpose }: PurposeRowProps): React.JSX.Element {
384
425
  }}
385
426
  />
386
427
  </Field>
428
+ <StatementField value={statement} onChange={setStatement} />
387
429
  {update.error !== null && <ErrorPanel error={update.error} />}
388
430
  <div className="flex justify-end">
389
431
  <button
@@ -57,7 +57,7 @@ export function AddFieldMenu({ fields, onAdd }: AddFieldMenuProps): React.JSX.El
57
57
  }
58
58
 
59
59
  return (
60
- <div className="relative" ref={containerRef}>
60
+ <div className="relative shrink-0" ref={containerRef}>
61
61
  <button
62
62
  type="button"
63
63
  onClick={() => {
@@ -65,7 +65,7 @@ export function AddFieldMenu({ fields, onAdd }: AddFieldMenuProps): React.JSX.El
65
65
  }}
66
66
  aria-expanded={open}
67
67
  aria-haspopup="menu"
68
- className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover"
68
+ className="whitespace-nowrap rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover"
69
69
  >
70
70
  + Add field
71
71
  </button>
@@ -160,10 +160,14 @@ function EmbedPreviewModal({
160
160
  return
161
161
  }
162
162
 
163
+ // The same check the pasted snippet makes: only the embed page may resize it.
164
+ const embedOrigin = new URL(url, window.location.href).origin
165
+
163
166
  function onMessage(event: MessageEvent): void {
164
167
  const data = event.data as { kelpie?: string; formId?: string; height?: number } | null
165
168
 
166
169
  if (
170
+ event.origin !== embedOrigin ||
167
171
  data === null ||
168
172
  typeof data !== 'object' ||
169
173
  data.kelpie !== 'height' ||
@@ -182,7 +186,7 @@ function EmbedPreviewModal({
182
186
  return () => {
183
187
  window.removeEventListener('message', onMessage)
184
188
  }
185
- }, [formId, mode])
189
+ }, [formId, mode, url])
186
190
 
187
191
  useEffect(() => {
188
192
  function onKeyDown(event: KeyboardEvent): void {
@@ -9,7 +9,7 @@ import {
9
9
  import type { DragEndEvent } from '@dnd-kit/core'
10
10
  import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable'
11
11
  import { CSS } from '@dnd-kit/utilities'
12
- import { FORM_OPTION_VALUE_TYPES } from '@kelpie/schemas'
12
+ import { FORM_OPTION_VALUE_TYPES, consentCheckboxText, formFieldDisplayLabel } from '@kelpie/schemas'
13
13
  import type {
14
14
  Form,
15
15
  FormFieldInput,
@@ -20,8 +20,10 @@ import { useEffect, useMemo, useRef, useState } from 'react'
20
20
 
21
21
  import { useConsentPurposes } from '../../api/resources/consentPurposes.ts'
22
22
  import { useCustomFields } from '../../api/resources/customFields.ts'
23
- import type { ConsentPurpose } from '@kelpie/schemas'
23
+ import type { ConsentPurpose, List } from '@kelpie/schemas'
24
24
  import { useUpdateFormFields } from '../../api/resources/forms.ts'
25
+ import { useLists } from '../../api/resources/lists.ts'
26
+ import { useWorkspace } from '../../api/resources/workspace.ts'
25
27
  import { ErrorPanel } from '../../components/QueryState.tsx'
26
28
  import { AddFieldMenu } from './AddFieldMenu.tsx'
27
29
  import { MapTargetSearch } from './MapTargetSearch.tsx'
@@ -281,8 +283,8 @@ function PreviewField({ field, selected, problem, onSelect }: PreviewFieldProps)
281
283
  >
282
284
  <button
283
285
  type="button"
284
- className="mt-8 shrink-0 cursor-grab touch-none rounded-md px-1 py-1 text-[10px] leading-none text-ink-faint opacity-0 transition hover:text-ink focus-visible:opacity-100 active:cursor-grabbing group-hover:opacity-100"
285
- aria-label={`Drag ${field.label} to reorder`}
286
+ className="shrink-0 self-center cursor-grab touch-none rounded-md px-1 py-1 text-[10px] leading-none text-ink-faint opacity-0 transition hover:text-ink focus-visible:opacity-100 active:cursor-grabbing group-hover:opacity-100"
287
+ aria-label={`Drag ${formFieldDisplayLabel(field)} to reorder`}
286
288
  {...attributes}
287
289
  {...listeners}
288
290
  >
@@ -302,16 +304,19 @@ function PreviewField({ field, selected, problem, onSelect }: PreviewFieldProps)
302
304
  <button
303
305
  type="button"
304
306
  onClick={onSelect}
305
- aria-label={`Edit ${field.label}`}
307
+ aria-label={`Edit ${formFieldDisplayLabel(field)}`}
306
308
  aria-pressed={selected}
307
309
  className="absolute inset-0 z-10 cursor-pointer rounded-md"
308
310
  />
309
311
 
310
312
  <div className="pointer-events-none">
311
- <span className="mb-1 block text-[13px] font-medium text-ink">
312
- {field.label}
313
- {(field.required ?? false) && <span className="ml-0.5 text-danger">*</span>}
314
- </span>
313
+ {/* No label, no heading: the same as the embed. */}
314
+ {field.label.trim().length > 0 && (
315
+ <span className="mb-1 block text-[13px] font-medium text-ink">
316
+ {field.label}
317
+ {(field.required ?? false) && <span className="ml-0.5 text-danger">*</span>}
318
+ </span>
319
+ )}
315
320
  <PreviewControl field={field} />
316
321
  {problem !== undefined && <p className="mt-1.5 text-[12px] text-danger">{problem}</p>}
317
322
  </div>
@@ -368,6 +373,10 @@ function PreviewControl({ field }: { readonly field: EditableField }): React.JSX
368
373
  return <NoticePreview field={field} />
369
374
  }
370
375
 
376
+ if (field.type === 'list') {
377
+ return <ListPreview field={field} />
378
+ }
379
+
371
380
  return (
372
381
  <input
373
382
  readOnly
@@ -405,10 +414,15 @@ function NoticePreview({ field }: { readonly field: EditableField }): React.JSX.
405
414
  )
406
415
  }
407
416
 
417
+ /** Until the workspace loads, the preview shows the token rather than a guess. */
418
+ const WORKSPACE_TOKEN = '{{workspace}}'
419
+
408
420
  function ConsentPreview({ field }: { readonly field: EditableField }): React.JSX.Element {
409
421
  const purposes = useConsentPurposes({ sort: 'sort_order', limit: 200 })
410
- const labelById = new Map<string, string>(
411
- purposes.records.map((purpose: ConsentPurpose) => [purpose.id, purpose.label]),
422
+ const { workspace } = useWorkspace()
423
+ const workspaceName = workspace?.name ?? WORKSPACE_TOKEN
424
+ const purposeById = new Map<string, ConsentPurpose>(
425
+ purposes.records.map((purpose: ConsentPurpose) => [purpose.id, purpose]),
412
426
  )
413
427
  const statement = field.statement ?? field.label
414
428
  const ids = field.consentPurposeIds ?? []
@@ -426,7 +440,11 @@ function ConsentPreview({ field }: { readonly field: EditableField }): React.JSX
426
440
  <div key={id} className="flex items-start gap-2">
427
441
  <input readOnly tabIndex={-1} type="checkbox" className="mt-0.5" />
428
442
  <span className="text-[13px] text-ink">
429
- {overrides[id] ?? labelById.get(id) ?? id}
443
+ {consentCheckboxText(
444
+ overrides[id],
445
+ purposeById.get(id) ?? { label: id, statement: '' },
446
+ workspaceName,
447
+ )}
430
448
  </span>
431
449
  </div>
432
450
  ))
@@ -435,6 +453,51 @@ function ConsentPreview({ field }: { readonly field: EditableField }): React.JSX
435
453
  )
436
454
  }
437
455
 
456
+ /**
457
+ * The lists a form can feed: person lists get the submitter, company lists the
458
+ * resolved company. The same two the form's Actions tab offers.
459
+ */
460
+ function useFormLists(): { readonly isLoading: boolean; readonly records: readonly List[] } {
461
+ const personLists = useLists({ targetType: 'person' })
462
+ const companyLists = useLists({ targetType: 'company' })
463
+ const records = useMemo(
464
+ () => [...personLists.records, ...companyLists.records],
465
+ [personLists.records, companyLists.records],
466
+ )
467
+
468
+ return { isLoading: personLists.isLoading || companyLists.isLoading, records }
469
+ }
470
+
471
+ /**
472
+ * The Add to list preview — what the visitor sees: the statement, then one
473
+ * checkbox per list, each with the field's own text or else the list's name.
474
+ */
475
+ function ListPreview({ field }: { readonly field: EditableField }): React.JSX.Element {
476
+ const lists = useFormLists()
477
+ const nameById = new Map(lists.records.map((list) => [list.id, list.name]))
478
+ const statement = (field.statement ?? '').trim()
479
+ const ids = field.listIds ?? []
480
+ const overrides = field.listLabels ?? {}
481
+
482
+ return (
483
+ <div className="space-y-1.5">
484
+ {statement.length > 0 && <p className="text-[12px] text-ink-muted">{statement}</p>}
485
+ {ids.length === 0 ? (
486
+ <p className="text-[11px] italic text-ink-faint">
487
+ Pick at least one list in the settings panel.
488
+ </p>
489
+ ) : (
490
+ ids.map((id) => (
491
+ <div key={id} className="flex items-start gap-2">
492
+ <input readOnly tabIndex={-1} type="checkbox" className="mt-0.5" />
493
+ <span className="text-[13px] text-ink">{overrides[id] ?? nameById.get(id) ?? id}</span>
494
+ </div>
495
+ ))
496
+ )}
497
+ </div>
498
+ )
499
+ }
500
+
438
501
  interface FieldSettingsProps {
439
502
  readonly field: EditableField
440
503
  readonly fields: readonly EditableField[]
@@ -590,6 +653,33 @@ function FieldSettings({
590
653
  </>
591
654
  )}
592
655
 
656
+ {field.type === 'list' && (
657
+ <>
658
+ <label className="block">
659
+ <span className="mb-1 block text-[11px] font-medium text-ink-faint">
660
+ Description (text above the checkboxes)
661
+ </span>
662
+ <textarea
663
+ className={inputClass}
664
+ rows={3}
665
+ value={field.statement ?? ''}
666
+ onChange={(event) => {
667
+ const value = event.target.value
668
+ onChange({ statement: value.length === 0 ? null : value })
669
+ }}
670
+ placeholder="We send one email a month."
671
+ />
672
+ </label>
673
+ <FormListPicker
674
+ value={field.listIds ?? []}
675
+ labels={field.listLabels ?? {}}
676
+ onChange={(listIds, listLabels) => {
677
+ onChange({ listIds, listLabels })
678
+ }}
679
+ />
680
+ </>
681
+ )}
682
+
593
683
  {problem !== undefined && <p className="text-[12px] text-danger">{problem}</p>}
594
684
 
595
685
  <button
@@ -701,7 +791,7 @@ function OptionsEditor({
701
791
  * beside each selected purpose so the admin can override the checkbox text.
702
792
  * The override is bound to the same purpose the checkbox grants — the wording
703
793
  * changes, the mapping never does. An empty override falls back to the
704
- * workspace purpose's own label at render time.
794
+ * workspace purpose's consent statement, then its label, at render time.
705
795
  */
706
796
  function ConsentPurposePicker({
707
797
  mode,
@@ -790,7 +880,7 @@ function ConsentPurposePicker({
790
880
  {isChosen && mode === 'checkbox' && (
791
881
  <label className="mt-1.5 block">
792
882
  <span className="mb-1 block text-[11px] font-medium text-ink-faint">
793
- Checkbox text (defaults to the purpose label)
883
+ Checkbox text (defaults to the purpose's consent statement)
794
884
  </span>
795
885
  <input
796
886
  className={inputClass}
@@ -798,7 +888,106 @@ function ConsentPurposePicker({
798
888
  onChange={(event) => {
799
889
  setLabel(purpose.id, event.target.value)
800
890
  }}
801
- placeholder={purpose.label}
891
+ placeholder={
892
+ purpose.statement.trim().length > 0 ? purpose.statement : purpose.label
893
+ }
894
+ />
895
+ </label>
896
+ )}
897
+ </div>
898
+ )
899
+ })}
900
+ </div>
901
+ </fieldset>
902
+ )
903
+ }
904
+
905
+ /**
906
+ * Picks the lists an Add to list field offers, with a text input beside each
907
+ * chosen list to override its checkbox text. An empty override falls back to
908
+ * the list's name. The workspace's list order is the order the visitor sees.
909
+ */
910
+ function FormListPicker({
911
+ value,
912
+ labels,
913
+ onChange,
914
+ }: {
915
+ readonly value: readonly string[]
916
+ readonly labels: Readonly<Record<string, string>>
917
+ readonly onChange: (ids: readonly string[], labels: Readonly<Record<string, string>>) => void
918
+ }): React.JSX.Element {
919
+ const lists = useFormLists()
920
+
921
+ if (lists.isLoading) {
922
+ return <p className="text-[12px] text-ink-muted">Loading lists…</p>
923
+ }
924
+
925
+ if (lists.records.length === 0) {
926
+ return (
927
+ <p className="text-[12px] text-ink-muted">
928
+ No person or company lists yet. Add one on the Lists page, then pick it here.
929
+ </p>
930
+ )
931
+ }
932
+
933
+ const chosen = new Set(value)
934
+
935
+ function toggle(id: string, checked: boolean): void {
936
+ const nextIds = lists.records
937
+ .map((list) => list.id)
938
+ .filter((listId) => (listId === id ? checked : chosen.has(listId)))
939
+ // A list taken off the field drops its text too, so it does not come
940
+ // back if the list is picked again later.
941
+ const nextLabels: Record<string, string> = {}
942
+ for (const [key, text] of Object.entries(labels)) {
943
+ if (nextIds.includes(key)) nextLabels[key] = text
944
+ }
945
+ onChange(nextIds, nextLabels)
946
+ }
947
+
948
+ function setLabel(id: string, text: string): void {
949
+ const nextLabels: Record<string, string> = { ...labels }
950
+ if (text.length === 0) {
951
+ delete nextLabels[id]
952
+ } else {
953
+ nextLabels[id] = text
954
+ }
955
+ onChange(value, nextLabels)
956
+ }
957
+
958
+ return (
959
+ <fieldset className="block">
960
+ <legend className="mb-1 block text-[11px] font-medium text-ink-faint">
961
+ Lists (each selected one becomes a checkbox)
962
+ </legend>
963
+ <div className="flex flex-col gap-2">
964
+ {lists.records.map((list) => {
965
+ const isChosen = chosen.has(list.id)
966
+ return (
967
+ <div key={list.id} className="rounded-md border border-border p-2">
968
+ <label className="flex items-center gap-2 text-[13px] text-ink">
969
+ <input
970
+ type="checkbox"
971
+ checked={isChosen}
972
+ onChange={(event) => {
973
+ toggle(list.id, event.target.checked)
974
+ }}
975
+ />
976
+ {list.name}
977
+ <span className="text-[11px] text-ink-faint">{list.targetType}</span>
978
+ </label>
979
+ {isChosen && (
980
+ <label className="mt-1.5 block">
981
+ <span className="mb-1 block text-[11px] font-medium text-ink-faint">
982
+ Checkbox text (defaults to the list's name)
983
+ </span>
984
+ <input
985
+ className={inputClass}
986
+ value={labels[list.id] ?? ''}
987
+ onChange={(event) => {
988
+ setLabel(list.id, event.target.value)
989
+ }}
990
+ placeholder={list.name}
802
991
  />
803
992
  </label>
804
993
  )}
@@ -1,17 +1,23 @@
1
- import { FORM_STATUSES } from '@kelpie/schemas'
1
+ import { useState } from 'react'
2
+ import { FORM_SLUG_PATTERN, FORM_STATUSES } from '@kelpie/schemas'
2
3
  import type { Form, FormStatus } from '@kelpie/schemas'
3
4
 
4
- import { useUpdateForm } from '../../api/resources/forms.ts'
5
+ import { ApiError } from '../../api/client.ts'
6
+ import {
7
+ useRegenerateFormSlug,
8
+ useUpdateForm,
9
+ useUpdateFormSlug,
10
+ } from '../../api/resources/forms.ts'
5
11
  import { ErrorPanel } from '../../components/QueryState.tsx'
6
12
  import { SectionHeader } from '../../components/SectionHeader.tsx'
7
13
 
8
14
  /**
9
- * The form's identity: status, public heading, thank-you copy, and the public key.
15
+ * The form's identity: status, public heading, thank-you copy, and the slug.
10
16
  *
11
17
  * Every control commits on change, because each one is a single field and the
12
18
  * optimistic update in `createResourceHooks` puts the old value back if the
13
19
  * PATCH is refused. The field list is the exception and has its own Save; see
14
- * `FieldsEditor`. What the form *does* on submit — create records, tag them,
20
+ * `FieldsEditor`, and so is the slug, which asks first; see `SlugSetting`. What the form *does* on submit — create records, tag them,
15
21
  * add to lists, attach the submitter — lives on the Actions tab.
16
22
  */
17
23
 
@@ -32,7 +38,7 @@ export function FormSettings({ form }: FormSettingsProps): React.JSX.Element {
32
38
  <div className="max-w-xl space-y-4">
33
39
  <SectionHeader
34
40
  title="Settings"
35
- description="Status, the public form title, thank-you copy, and the public key."
41
+ description="Status, the public form title, thank-you copy, and the slug in its submit URL."
36
42
  />
37
43
 
38
44
  {updateForm.error !== null && <ErrorPanel error={updateForm.error} />}
@@ -90,14 +96,155 @@ export function FormSettings({ form }: FormSettingsProps): React.JSX.Element {
90
96
  <strong className="font-medium text-ink">Actions</strong> tab.
91
97
  </p>
92
98
 
93
- <Labelled label="Public key">
94
- <input className={`${inputClass} font-mono text-[12px]`} value={form.publicKey} readOnly />
95
- <Hint>The only credential the public submit takes. It never changes.</Hint>
96
- </Labelled>
99
+ {/* Keyed on the slug so the draft starts over whenever the stored slug moves. */}
100
+ <SlugSetting key={form.slug} form={form} />
97
101
  </div>
98
102
  )
99
103
  }
100
104
 
105
+ type SlugAction = 'change' | 'regenerate'
106
+
107
+ /**
108
+ * The form's slug, with an edit and a Regenerate button.
109
+ *
110
+ * The slug is only in the submit URL. Embed snippets use the form id, and the
111
+ * embed page carries the current submit URL, so embeds follow a change on their
112
+ * own. Anything that saved the old submit URL does not, which is the point of
113
+ * Regenerate. So, unlike the other settings, a change here does not commit on
114
+ * blur: both actions say what moves and wait for a confirm.
115
+ */
116
+ function SlugSetting({ form }: { readonly form: Form }): React.JSX.Element {
117
+ const updateSlug = useUpdateFormSlug()
118
+ const regenerateSlug = useRegenerateFormSlug()
119
+ const [draft, setDraft] = useState(form.slug)
120
+ const [confirming, setConfirming] = useState<SlugAction | null>(null)
121
+ const [lastError, setLastError] = useState<Error | null>(null)
122
+
123
+ const trimmed = draft.trim()
124
+ const edited = trimmed !== form.slug
125
+ const valid = FORM_SLUG_PATTERN.test(trimmed)
126
+ const isPending = updateSlug.isPending || regenerateSlug.isPending
127
+ const pendingAction: SlugAction | null = edited ? 'change' : confirming
128
+
129
+ const reset = (): void => {
130
+ setDraft(form.slug)
131
+ setConfirming(null)
132
+ setLastError(null)
133
+ }
134
+
135
+ const commit = async (): Promise<void> => {
136
+ setLastError(null)
137
+ try {
138
+ // Success moves `form.slug`, and the key on this component then resets it.
139
+ await (pendingAction === 'regenerate'
140
+ ? regenerateSlug.runAsync(form.id)
141
+ : updateSlug.runAsync({ id: form.id, slug: trimmed }))
142
+ } catch (error) {
143
+ setLastError(error instanceof Error ? error : new Error(String(error)))
144
+ }
145
+ }
146
+
147
+ return (
148
+ <div>
149
+ <label htmlFor="form-slug" className="mb-1.5 block text-[12px] font-medium text-ink">
150
+ Slug
151
+ </label>
152
+ <div className="flex gap-2">
153
+ <input
154
+ id="form-slug"
155
+ className={`${inputClass} font-mono text-[12px]`}
156
+ value={draft}
157
+ spellCheck={false}
158
+ autoComplete="off"
159
+ disabled={isPending}
160
+ aria-invalid={edited && !valid}
161
+ onChange={(event) => {
162
+ setDraft(event.target.value)
163
+ setConfirming(null)
164
+ setLastError(null)
165
+ }}
166
+ onKeyDown={(event) => {
167
+ if (event.key === 'Escape') {
168
+ reset()
169
+ }
170
+ }}
171
+ />
172
+ <button
173
+ type="button"
174
+ disabled={isPending || edited}
175
+ onClick={() => {
176
+ setConfirming('regenerate')
177
+ setLastError(null)
178
+ }}
179
+ className="shrink-0 rounded-md border border-border bg-surface-raised px-3 py-2 text-[12px] font-medium text-ink transition hover:bg-surface disabled:opacity-50"
180
+ >
181
+ Regenerate
182
+ </button>
183
+ </div>
184
+
185
+ {edited && !valid ? (
186
+ <p className="mt-1 text-[11px] text-danger">
187
+ Use 3 to 64 characters: letters, digits, hyphens (-) or underscores (_).
188
+ </p>
189
+ ) : (
190
+ <Hint>
191
+ The name of this form in its submit URL. It is not a secret: every page that embeds
192
+ the form shows it. If a bot sends spam to the form, regenerate the slug. Your
193
+ embeds keep working and use the new slug.
194
+ </Hint>
195
+ )}
196
+
197
+ {pendingAction !== null && (edited ? valid : true) && (
198
+ <div className="mt-2 rounded-md border border-border bg-surface px-3 py-2">
199
+ <p className="text-[12px] text-ink">
200
+ {pendingAction === 'regenerate'
201
+ ? 'Replace the slug with a new random one?'
202
+ : `Change the slug to "${trimmed}"?`}{' '}
203
+ Embeds on your sites change to the new slug in less than a minute. You do not
204
+ need to paste new code. Anything that sends to the old submit URL directly gets
205
+ an error.
206
+ </p>
207
+ <div className="mt-2 flex justify-end gap-2">
208
+ <button
209
+ type="button"
210
+ disabled={isPending}
211
+ onClick={reset}
212
+ className="rounded-md px-2 py-1 text-[12px] font-medium text-ink-muted hover:text-ink"
213
+ >
214
+ Cancel
215
+ </button>
216
+ <button
217
+ type="button"
218
+ disabled={isPending}
219
+ onClick={() => {
220
+ void commit()
221
+ }}
222
+ className="rounded-md bg-accent px-2.5 py-1 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover disabled:opacity-50"
223
+ >
224
+ {isPending
225
+ ? 'Saving…'
226
+ : pendingAction === 'regenerate'
227
+ ? 'Regenerate slug'
228
+ : 'Change slug'}
229
+ </button>
230
+ </div>
231
+ </div>
232
+ )}
233
+
234
+ {lastError !== null && <p className="mt-1 text-[11px] text-danger">{slugErrorText(lastError)}</p>}
235
+ </div>
236
+ )
237
+ }
238
+
239
+ /** The field-level message for a refused slug write, when the API gives one. */
240
+ function slugErrorText(error: Error): string {
241
+ if (error instanceof ApiError && error.status === 409) {
242
+ return 'Another form in this workspace uses this slug. Choose a different one.'
243
+ }
244
+
245
+ return error.message
246
+ }
247
+
101
248
  function Labelled({
102
249
  label,
103
250
  children,
@@ -1,3 +1,4 @@
1
+ import { formFieldDisplayLabel } from '@kelpie/schemas'
1
2
  import type { Form, FormField, FormSubmission, FormSubmissionActionEntry } from '@kelpie/schemas'
2
3
  import { useMemo } from 'react'
3
4
  import { Link, useParams } from 'react-router'
@@ -112,7 +113,7 @@ function SubmissionDetailView({
112
113
  className="grid gap-0.5 px-3 py-2.5 sm:grid-cols-[10rem_1fr] sm:gap-3"
113
114
  >
114
115
  <dt className="text-[12px] font-medium text-ink-muted">
115
- {field.label}
116
+ {formFieldDisplayLabel(field)}
116
117
  {field.required && <span className="ml-0.5 text-danger">*</span>}
117
118
  </dt>
118
119
  <dd className="whitespace-pre-wrap text-[13px] text-ink">