@kelpie/ui 0.18.0 → 0.20.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.
- package/dist/api/resources/forms.d.ts +21 -2
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +51 -4
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/components/AiDrawer.d.ts +13 -0
- package/dist/components/AiDrawer.d.ts.map +1 -0
- package/dist/components/AiDrawer.js +165 -0
- package/dist/components/AiDrawer.js.map +1 -0
- package/dist/components/ApiKeysPanel.js +1 -1
- package/dist/components/DataTable.js +1 -1
- package/dist/components/KanbanBoard.d.ts +5 -1
- package/dist/components/KanbanBoard.d.ts.map +1 -1
- package/dist/components/KanbanBoard.js +37 -2
- package/dist/components/KanbanBoard.js.map +1 -1
- package/dist/components/NotesPanel.js +2 -2
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/PageHeader.js +1 -1
- package/dist/components/PageHeader.js.map +1 -1
- package/dist/components/PersonIntakePanel.d.ts +21 -0
- package/dist/components/PersonIntakePanel.d.ts.map +1 -0
- package/dist/components/PersonIntakePanel.js +76 -0
- package/dist/components/PersonIntakePanel.js.map +1 -0
- package/dist/components/SegmentedControl.js +2 -2
- package/dist/components/SegmentedControl.js.map +1 -1
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +39 -3
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
- package/dist/components/WorkspaceSwitcher.js +10 -2
- package/dist/components/WorkspaceSwitcher.js.map +1 -1
- package/dist/components/aiDrawerState.d.ts +45 -0
- package/dist/components/aiDrawerState.d.ts.map +1 -0
- package/dist/components/aiDrawerState.js +14 -0
- package/dist/components/aiDrawerState.js.map +1 -0
- package/dist/components/personIntakeTask.d.ts +5 -0
- package/dist/components/personIntakeTask.d.ts.map +1 -0
- package/dist/components/personIntakeTask.js +13 -0
- package/dist/components/personIntakeTask.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/mediaQuery.d.ts +9 -0
- package/dist/lib/mediaQuery.d.ts.map +1 -0
- package/dist/lib/mediaQuery.js +24 -0
- package/dist/lib/mediaQuery.js.map +1 -0
- package/dist/modules/PersonIntakeWizard.d.ts +1 -1
- package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
- package/dist/modules/PersonIntakeWizard.js +9 -5
- package/dist/modules/PersonIntakeWizard.js.map +1 -1
- package/dist/pages/FormDetail.d.ts.map +1 -1
- package/dist/pages/FormDetail.js +9 -8
- package/dist/pages/FormDetail.js.map +1 -1
- package/dist/pages/FormsPage.d.ts.map +1 -1
- package/dist/pages/FormsPage.js +5 -1
- package/dist/pages/FormsPage.js.map +1 -1
- package/dist/pages/ListDetail.d.ts.map +1 -1
- package/dist/pages/ListDetail.js +2 -2
- package/dist/pages/ListDetail.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +8 -6
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/RoleDetail.d.ts.map +1 -1
- package/dist/pages/RoleDetail.js +3 -3
- package/dist/pages/RoleDetail.js.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.js +1 -1
- package/dist/pages/admin/DataPage.js +2 -2
- package/dist/pages/forms/AddFieldMenu.js +2 -2
- package/dist/pages/forms/AddFieldMenu.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.d.ts +5 -0
- package/dist/pages/forms/EmbedPanel.d.ts.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +79 -14
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FormActions.d.ts.map +1 -1
- package/dist/pages/forms/FormActions.js +2 -1
- package/dist/pages/forms/FormActions.js.map +1 -1
- package/dist/pages/forms/FormEmails.d.ts +6 -0
- package/dist/pages/forms/FormEmails.d.ts.map +1 -0
- package/dist/pages/forms/FormEmails.js +173 -0
- package/dist/pages/forms/FormEmails.js.map +1 -0
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +5 -3
- package/dist/pages/forms/FormSettings.js.map +1 -1
- package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +22 -3
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts +3 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +48 -11
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/embedPrompts.d.ts +45 -0
- package/dist/pages/forms/embedPrompts.d.ts.map +1 -0
- package/dist/pages/forms/embedPrompts.js +174 -0
- package/dist/pages/forms/embedPrompts.js.map +1 -0
- package/dist/pages/handbook/HandbookPage.js +4 -4
- package/dist/pages/handbook/HandbookPage.js.map +1 -1
- package/dist/registry/contributions.d.ts +8 -3
- package/dist/registry/contributions.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/api/resources/forms.ts +75 -4
- package/src/components/AiDrawer.tsx +272 -0
- package/src/components/ApiKeysPanel.tsx +1 -1
- package/src/components/DataTable.tsx +1 -1
- package/src/components/KanbanBoard.tsx +119 -2
- package/src/components/NotesPanel.tsx +7 -4
- package/src/components/PageHeader.tsx +1 -1
- package/src/components/{PersonIntakeDialog.tsx → PersonIntakePanel.tsx} +17 -50
- package/src/components/SegmentedControl.tsx +2 -2
- package/src/components/Shell.tsx +98 -12
- package/src/components/WorkspaceSwitcher.tsx +13 -2
- package/src/components/aiDrawerState.ts +61 -0
- package/src/components/personIntakeTask.tsx +14 -0
- package/src/index.ts +5 -0
- package/src/lib/mediaQuery.ts +32 -0
- package/src/modules/PersonIntakeWizard.tsx +10 -5
- package/src/pages/FormDetail.tsx +22 -15
- package/src/pages/FormsPage.tsx +5 -1
- package/src/pages/ListDetail.tsx +5 -3
- package/src/pages/PeoplePage.tsx +7 -10
- package/src/pages/RoleDetail.tsx +10 -5
- package/src/pages/account/ConnectedAppsPage.tsx +1 -1
- package/src/pages/admin/DataPage.tsx +2 -2
- package/src/pages/forms/AddFieldMenu.tsx +2 -2
- package/src/pages/forms/EmbedPanel.tsx +238 -34
- package/src/pages/forms/FormActions.tsx +4 -1
- package/src/pages/forms/FormEmails.tsx +449 -0
- package/src/pages/forms/FormSettings.tsx +23 -4
- package/src/pages/forms/SubmissionDetail.tsx +64 -2
- package/src/pages/forms/SubmissionsTable.tsx +123 -16
- package/src/pages/forms/embedPrompts.ts +257 -0
- package/src/pages/handbook/HandbookPage.tsx +5 -5
- package/src/registry/contributions.ts +8 -3
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FORM_EMAIL_MAX_RECIPIENTS,
|
|
3
|
+
FORM_EMAIL_PLACEHOLDERS,
|
|
4
|
+
formEmailPlaceholderText,
|
|
5
|
+
} from '@kelpie/schemas'
|
|
6
|
+
import type { Form, FormEmailKind, FormEmailRecipient, Member } from '@kelpie/schemas'
|
|
7
|
+
import { useEffect, useRef, useState } from 'react'
|
|
8
|
+
|
|
9
|
+
import { useUpdateForm } from '../../api/resources/forms.ts'
|
|
10
|
+
import type { FormSettingsInput } from '../../api/resources/forms.ts'
|
|
11
|
+
import { useMembers } from '../../api/resources/members.ts'
|
|
12
|
+
import { ErrorPanel } from '../../components/QueryState.tsx'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The two emails a form sends after a submit: a notification to people the
|
|
16
|
+
* workspace names, and an auto-reply to the submitter.
|
|
17
|
+
*
|
|
18
|
+
* On the Actions tab because an email is something the form does with a
|
|
19
|
+
* submission. Toggles, recipients and the Reply-To commit on change, like
|
|
20
|
+
* every other action; a template commits on blur, so a half-typed placeholder
|
|
21
|
+
* is not sent to the server for checking on every key.
|
|
22
|
+
*
|
|
23
|
+
* The placeholder chips come from `FORM_EMAIL_PLACEHOLDERS`, the same list the
|
|
24
|
+
* server checks templates against, so a chip never inserts a placeholder the
|
|
25
|
+
* server refuses. The auto-reply offers only the ones that carry no visitor
|
|
26
|
+
* text.
|
|
27
|
+
*
|
|
28
|
+
* Its own mutation, so a refusal shows here, beside the controls that caused
|
|
29
|
+
* it, rather than at the top of a long tab.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const inputClass =
|
|
33
|
+
'w-full rounded-md border border-border bg-surface-raised px-3 py-2 text-[13px] outline-none focus:border-accent focus:ring-2 focus:ring-accent/20'
|
|
34
|
+
|
|
35
|
+
export interface FormEmailsProps {
|
|
36
|
+
readonly form: Form
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function FormEmails({ form }: FormEmailsProps): React.JSX.Element {
|
|
40
|
+
const { members } = useMembers()
|
|
41
|
+
const updateForm = useUpdateForm()
|
|
42
|
+
const onChange = (changes: FormSettingsInput): void => {
|
|
43
|
+
updateForm.run({ id: form.id, changes })
|
|
44
|
+
}
|
|
45
|
+
/** For a template: rejects when refused, so the field keeps what was typed. */
|
|
46
|
+
const commit = async (changes: FormSettingsInput): Promise<void> => {
|
|
47
|
+
await updateForm.runAsync({ id: form.id, changes })
|
|
48
|
+
}
|
|
49
|
+
const hasRecipients = form.notifyRecipients.length > 0
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className="space-y-3">
|
|
53
|
+
{updateForm.error !== null && <ErrorPanel error={updateForm.error} />}
|
|
54
|
+
|
|
55
|
+
<div className="space-y-3 rounded-md border border-border p-4">
|
|
56
|
+
<label className="flex items-center gap-2 text-[13px] font-medium text-ink">
|
|
57
|
+
<input
|
|
58
|
+
type="checkbox"
|
|
59
|
+
checked={form.notifyEmail}
|
|
60
|
+
disabled={!hasRecipients && !form.notifyEmail}
|
|
61
|
+
onChange={(event) => onChange({ notifyEmail: event.target.checked })}
|
|
62
|
+
/>
|
|
63
|
+
Email my team
|
|
64
|
+
</label>
|
|
65
|
+
<p className="text-[11px] text-ink-faint">
|
|
66
|
+
{hasRecipients || form.notifyEmail
|
|
67
|
+
? 'Sent after each submit, with a link to the submission. A reply goes to the person who filled in the form.'
|
|
68
|
+
: 'Add a recipient first.'}
|
|
69
|
+
</p>
|
|
70
|
+
|
|
71
|
+
<RecipientList
|
|
72
|
+
recipients={form.notifyRecipients}
|
|
73
|
+
members={members}
|
|
74
|
+
onChange={(next) =>
|
|
75
|
+
onChange(
|
|
76
|
+
next.length === 0 && form.notifyEmail
|
|
77
|
+
? { notifyRecipients: next, notifyEmail: false }
|
|
78
|
+
: { notifyRecipients: next },
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
<TemplateInput
|
|
84
|
+
label="Subject"
|
|
85
|
+
kind="notification"
|
|
86
|
+
value={form.notifySubject}
|
|
87
|
+
multiline={false}
|
|
88
|
+
onCommit={(next) => commit({ notifySubject: next })}
|
|
89
|
+
/>
|
|
90
|
+
<TemplateInput
|
|
91
|
+
label="Message"
|
|
92
|
+
kind="notification"
|
|
93
|
+
value={form.notifyBody}
|
|
94
|
+
multiline
|
|
95
|
+
onCommit={(next) => commit({ notifyBody: next })}
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<div className="space-y-3 rounded-md border border-border p-4">
|
|
100
|
+
<label className="flex items-center gap-2 text-[13px] font-medium text-ink">
|
|
101
|
+
<input
|
|
102
|
+
type="checkbox"
|
|
103
|
+
checked={form.autoReply}
|
|
104
|
+
onChange={(event) => onChange({ autoReply: event.target.checked })}
|
|
105
|
+
/>
|
|
106
|
+
Send an auto-reply
|
|
107
|
+
</label>
|
|
108
|
+
<p className="text-[11px] text-ink-faint">
|
|
109
|
+
Sent to the email address the visitor typed. Use it to confirm the request only, not
|
|
110
|
+
for marketing. It cannot include the visitor's answers: anybody can type any
|
|
111
|
+
address into a public form, so it contains only text you wrote. One auto-reply per
|
|
112
|
+
address per day for each form.
|
|
113
|
+
</p>
|
|
114
|
+
|
|
115
|
+
<ReplyToPicker
|
|
116
|
+
value={form.autoReplyReplyTo}
|
|
117
|
+
members={members}
|
|
118
|
+
onChange={(next) => onChange({ autoReplyReplyTo: next })}
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
<TemplateInput
|
|
122
|
+
label="Subject"
|
|
123
|
+
kind="auto_reply"
|
|
124
|
+
value={form.autoReplySubject}
|
|
125
|
+
multiline={false}
|
|
126
|
+
onCommit={(next) => commit({ autoReplySubject: next })}
|
|
127
|
+
/>
|
|
128
|
+
<TemplateInput
|
|
129
|
+
label="Message"
|
|
130
|
+
kind="auto_reply"
|
|
131
|
+
value={form.autoReplyBody}
|
|
132
|
+
multiline
|
|
133
|
+
onCommit={(next) => commit({ autoReplyBody: next })}
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// -------- Recipients --------
|
|
141
|
+
|
|
142
|
+
function recipientKey(recipient: FormEmailRecipient): string {
|
|
143
|
+
return recipient.kind === 'member' ? `member:${recipient.memberId}` : `address:${recipient.address}`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function recipientText(recipient: FormEmailRecipient, members: readonly Member[]): string {
|
|
147
|
+
if (recipient.kind === 'address') {
|
|
148
|
+
return recipient.address
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const member = members.find((candidate) => candidate.id === recipient.memberId)
|
|
152
|
+
|
|
153
|
+
return member === undefined ? 'A former member' : `${member.name} (${member.email})`
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Loose on purpose: the server has the real check, and says why it refuses. */
|
|
157
|
+
function looksLikeAddress(text: string): boolean {
|
|
158
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/u.test(text)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function RecipientList({
|
|
162
|
+
recipients,
|
|
163
|
+
members,
|
|
164
|
+
onChange,
|
|
165
|
+
}: {
|
|
166
|
+
readonly recipients: readonly FormEmailRecipient[]
|
|
167
|
+
readonly members: readonly Member[]
|
|
168
|
+
readonly onChange: (next: readonly FormEmailRecipient[]) => void
|
|
169
|
+
}): React.JSX.Element {
|
|
170
|
+
const [memberPick, setMemberPick] = useState('')
|
|
171
|
+
const [address, setAddress] = useState('')
|
|
172
|
+
const chosen = new Set(recipients.map(recipientKey))
|
|
173
|
+
const remainingMembers = members.filter((member) => !chosen.has(`member:${member.id}`))
|
|
174
|
+
const full = recipients.length >= FORM_EMAIL_MAX_RECIPIENTS
|
|
175
|
+
const typed = address.trim().toLowerCase()
|
|
176
|
+
const canAddAddress = !full && looksLikeAddress(typed) && !chosen.has(`address:${typed}`)
|
|
177
|
+
|
|
178
|
+
function add(recipient: FormEmailRecipient): void {
|
|
179
|
+
if (!full && !chosen.has(recipientKey(recipient))) {
|
|
180
|
+
onChange([...recipients, recipient])
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div className="space-y-2">
|
|
186
|
+
<div className="text-[12px] font-medium text-ink">Recipients</div>
|
|
187
|
+
<ul className="divide-y divide-border">
|
|
188
|
+
{recipients.length === 0 && <li className="py-2 text-[12px] text-ink-faint">No recipients yet.</li>}
|
|
189
|
+
{recipients.map((recipient) => (
|
|
190
|
+
<li key={recipientKey(recipient)} className="flex items-center justify-between gap-2 py-2">
|
|
191
|
+
<span className="min-w-0 break-words text-[13px] text-ink">{recipientText(recipient, members)}</span>
|
|
192
|
+
<button
|
|
193
|
+
type="button"
|
|
194
|
+
onClick={() => onChange(recipients.filter((entry) => recipientKey(entry) !== recipientKey(recipient)))}
|
|
195
|
+
className="shrink-0 text-[11px] font-medium text-danger hover:underline"
|
|
196
|
+
>
|
|
197
|
+
Remove
|
|
198
|
+
</button>
|
|
199
|
+
</li>
|
|
200
|
+
))}
|
|
201
|
+
</ul>
|
|
202
|
+
|
|
203
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
204
|
+
<select
|
|
205
|
+
aria-label="Add a member"
|
|
206
|
+
className={`${inputClass} min-w-[12rem] flex-1`}
|
|
207
|
+
value={memberPick}
|
|
208
|
+
disabled={full}
|
|
209
|
+
onChange={(event) => setMemberPick(event.target.value)}
|
|
210
|
+
>
|
|
211
|
+
<option value="">Pick a member…</option>
|
|
212
|
+
{remainingMembers.map((member) => (
|
|
213
|
+
<option key={member.id} value={member.id}>
|
|
214
|
+
{member.name} ({member.email})
|
|
215
|
+
</option>
|
|
216
|
+
))}
|
|
217
|
+
</select>
|
|
218
|
+
<button
|
|
219
|
+
type="button"
|
|
220
|
+
disabled={memberPick.length === 0 || full}
|
|
221
|
+
onClick={() => {
|
|
222
|
+
add({ kind: 'member', memberId: memberPick })
|
|
223
|
+
setMemberPick('')
|
|
224
|
+
}}
|
|
225
|
+
className="shrink-0 rounded-md bg-accent px-3 py-2 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
226
|
+
>
|
|
227
|
+
Add
|
|
228
|
+
</button>
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
232
|
+
<input
|
|
233
|
+
type="email"
|
|
234
|
+
aria-label="Add an email address"
|
|
235
|
+
placeholder="sales@yourcompany.com"
|
|
236
|
+
className={`${inputClass} min-w-[12rem] flex-1`}
|
|
237
|
+
value={address}
|
|
238
|
+
disabled={full}
|
|
239
|
+
onChange={(event) => setAddress(event.target.value)}
|
|
240
|
+
onKeyDown={(event) => {
|
|
241
|
+
if (event.key === 'Enter' && canAddAddress) {
|
|
242
|
+
event.preventDefault()
|
|
243
|
+
add({ kind: 'address', address: typed })
|
|
244
|
+
setAddress('')
|
|
245
|
+
}
|
|
246
|
+
}}
|
|
247
|
+
/>
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
disabled={!canAddAddress}
|
|
251
|
+
onClick={() => {
|
|
252
|
+
add({ kind: 'address', address: typed })
|
|
253
|
+
setAddress('')
|
|
254
|
+
}}
|
|
255
|
+
className="shrink-0 rounded-md bg-accent px-3 py-2 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
256
|
+
>
|
|
257
|
+
Add
|
|
258
|
+
</button>
|
|
259
|
+
</div>
|
|
260
|
+
<p className="text-[11px] text-ink-faint">
|
|
261
|
+
Up to {FORM_EMAIL_MAX_RECIPIENTS}. A member gets it at their current account email.
|
|
262
|
+
</p>
|
|
263
|
+
</div>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// -------- Reply-To --------
|
|
268
|
+
|
|
269
|
+
const NO_REPLY_TO = ''
|
|
270
|
+
const ADDRESS_REPLY_TO = '__address__'
|
|
271
|
+
|
|
272
|
+
function ReplyToPicker({
|
|
273
|
+
value,
|
|
274
|
+
members,
|
|
275
|
+
onChange,
|
|
276
|
+
}: {
|
|
277
|
+
readonly value: FormEmailRecipient | null
|
|
278
|
+
readonly members: readonly Member[]
|
|
279
|
+
readonly onChange: (next: FormEmailRecipient | null) => void
|
|
280
|
+
}): React.JSX.Element {
|
|
281
|
+
const [choosingAddress, setChoosingAddress] = useState(value?.kind === 'address')
|
|
282
|
+
const selected =
|
|
283
|
+
value?.kind === 'member' ? value.memberId : choosingAddress || value?.kind === 'address' ? ADDRESS_REPLY_TO : NO_REPLY_TO
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<div className="space-y-2">
|
|
287
|
+
<label className="block">
|
|
288
|
+
<span className="mb-1.5 block text-[12px] font-medium text-ink">Replies go to</span>
|
|
289
|
+
<select
|
|
290
|
+
className={inputClass}
|
|
291
|
+
value={selected}
|
|
292
|
+
onChange={(event) => {
|
|
293
|
+
const next = event.target.value
|
|
294
|
+
|
|
295
|
+
if (next === ADDRESS_REPLY_TO) {
|
|
296
|
+
setChoosingAddress(true)
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setChoosingAddress(false)
|
|
301
|
+
onChange(next === NO_REPLY_TO ? null : { kind: 'member', memberId: next })
|
|
302
|
+
}}
|
|
303
|
+
>
|
|
304
|
+
<option value={NO_REPLY_TO}>The sending address (no Reply-To)</option>
|
|
305
|
+
{members.map((member) => (
|
|
306
|
+
<option key={member.id} value={member.id}>
|
|
307
|
+
{member.name} ({member.email})
|
|
308
|
+
</option>
|
|
309
|
+
))}
|
|
310
|
+
<option value={ADDRESS_REPLY_TO}>Another address…</option>
|
|
311
|
+
</select>
|
|
312
|
+
</label>
|
|
313
|
+
|
|
314
|
+
{selected === ADDRESS_REPLY_TO && (
|
|
315
|
+
<input
|
|
316
|
+
key={value?.kind === 'address' ? value.address : 'new'}
|
|
317
|
+
type="email"
|
|
318
|
+
aria-label="Reply-To address"
|
|
319
|
+
placeholder="hello@yourcompany.com"
|
|
320
|
+
className={inputClass}
|
|
321
|
+
defaultValue={value?.kind === 'address' ? value.address : ''}
|
|
322
|
+
onBlur={(event) => {
|
|
323
|
+
const next = event.target.value.trim().toLowerCase()
|
|
324
|
+
const current = value?.kind === 'address' ? value.address : ''
|
|
325
|
+
|
|
326
|
+
if (next !== current && looksLikeAddress(next)) {
|
|
327
|
+
onChange({ kind: 'address', address: next })
|
|
328
|
+
}
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
</div>
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// -------- Templates --------
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* A subject or message template with placeholder chips.
|
|
340
|
+
*
|
|
341
|
+
* The draft follows the stored template only when it moves to a value this
|
|
342
|
+
* field has not seen. A commit moves the stored value twice on a refusal: the
|
|
343
|
+
* optimistic update to the draft, then the rollback to the old text, and
|
|
344
|
+
* React may render either after the PATCH has settled. So the check is on
|
|
345
|
+
* values, not on timing: the text being saved and the last text known to be
|
|
346
|
+
* stored are both ignored. A refused draft stays in the field, marked
|
|
347
|
+
* unsaved, so it can be corrected rather than typed again.
|
|
348
|
+
*
|
|
349
|
+
* A chip keeps the field's focus (`onMouseDown` prevents the blur) and inserts
|
|
350
|
+
* at the cursor; the template commits on blur like the other text settings.
|
|
351
|
+
*/
|
|
352
|
+
function TemplateInput({
|
|
353
|
+
label,
|
|
354
|
+
kind,
|
|
355
|
+
value,
|
|
356
|
+
multiline,
|
|
357
|
+
onCommit,
|
|
358
|
+
}: {
|
|
359
|
+
readonly label: string
|
|
360
|
+
readonly kind: FormEmailKind
|
|
361
|
+
readonly value: string
|
|
362
|
+
readonly multiline: boolean
|
|
363
|
+
readonly onCommit: (next: string) => Promise<void>
|
|
364
|
+
}): React.JSX.Element {
|
|
365
|
+
const [draft, setDraft] = useState(value)
|
|
366
|
+
const [refused, setRefused] = useState(false)
|
|
367
|
+
/** The last text known to be stored. */
|
|
368
|
+
const stored = useRef(value)
|
|
369
|
+
/** The text the latest commit sent. */
|
|
370
|
+
const sent = useRef<string | null>(null)
|
|
371
|
+
const ref = useRef<HTMLInputElement & HTMLTextAreaElement>(null)
|
|
372
|
+
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
if (value === stored.current || value === sent.current) {
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
stored.current = value
|
|
379
|
+
setDraft(value)
|
|
380
|
+
setRefused(false)
|
|
381
|
+
}, [value])
|
|
382
|
+
const placeholders = FORM_EMAIL_PLACEHOLDERS.filter(
|
|
383
|
+
(placeholder) => placeholder.scope === 'both' || kind === 'notification',
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
function insert(text: string): void {
|
|
387
|
+
const element = ref.current
|
|
388
|
+
const start = element?.selectionStart ?? draft.length
|
|
389
|
+
const end = element?.selectionEnd ?? draft.length
|
|
390
|
+
const next = `${draft.slice(0, start)}${text}${draft.slice(end)}`
|
|
391
|
+
|
|
392
|
+
setDraft(next)
|
|
393
|
+
requestAnimationFrame(() => {
|
|
394
|
+
element?.setSelectionRange(start + text.length, start + text.length)
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const shared = {
|
|
399
|
+
ref,
|
|
400
|
+
className: multiline ? `${inputClass} min-h-[96px] font-mono text-[12px]` : inputClass,
|
|
401
|
+
value: draft,
|
|
402
|
+
'aria-invalid': refused,
|
|
403
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => setDraft(event.target.value),
|
|
404
|
+
onBlur: () => {
|
|
405
|
+
if (draft === value) {
|
|
406
|
+
return
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const text = draft
|
|
410
|
+
|
|
411
|
+
sent.current = text
|
|
412
|
+
onCommit(text)
|
|
413
|
+
.then(() => {
|
|
414
|
+
stored.current = text
|
|
415
|
+
setRefused(false)
|
|
416
|
+
})
|
|
417
|
+
.catch(() => {
|
|
418
|
+
// The section's error panel says why.
|
|
419
|
+
setRefused(true)
|
|
420
|
+
})
|
|
421
|
+
},
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return (
|
|
425
|
+
<div>
|
|
426
|
+
<label className="block">
|
|
427
|
+
<span className="mb-1.5 block text-[12px] font-medium text-ink">{label}</span>
|
|
428
|
+
{multiline ? <textarea {...shared} /> : <input {...shared} />}
|
|
429
|
+
</label>
|
|
430
|
+
{refused && (
|
|
431
|
+
<p className="mt-1 text-[11px] text-danger">Not saved. Correct it and leave the field to save again.</p>
|
|
432
|
+
)}
|
|
433
|
+
<div className="mt-1.5 flex flex-wrap gap-1">
|
|
434
|
+
{placeholders.map((placeholder) => (
|
|
435
|
+
<button
|
|
436
|
+
key={placeholder.name}
|
|
437
|
+
type="button"
|
|
438
|
+
title={`Insert ${formEmailPlaceholderText(placeholder.name)}`}
|
|
439
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
440
|
+
onClick={() => insert(formEmailPlaceholderText(placeholder.name))}
|
|
441
|
+
className="inline-flex items-center rounded border border-border px-1.5 py-0.5 text-[10px] font-medium leading-none text-ink-muted hover:bg-surface"
|
|
442
|
+
>
|
|
443
|
+
{placeholder.label}
|
|
444
|
+
</button>
|
|
445
|
+
))}
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
)
|
|
449
|
+
}
|
|
@@ -38,7 +38,7 @@ export function FormSettings({ form }: FormSettingsProps): React.JSX.Element {
|
|
|
38
38
|
<div className="max-w-xl space-y-4">
|
|
39
39
|
<SectionHeader
|
|
40
40
|
title="Settings"
|
|
41
|
-
description="Status, the public form title, thank-you copy, and the slug in its submit URL."
|
|
41
|
+
description="Status, the public form title, thank-you copy, the spam check, and the slug in its submit URL."
|
|
42
42
|
/>
|
|
43
43
|
|
|
44
44
|
{updateForm.error !== null && <ErrorPanel error={updateForm.error} />}
|
|
@@ -91,8 +91,27 @@ export function FormSettings({ form }: FormSettingsProps): React.JSX.Element {
|
|
|
91
91
|
<Hint>Shown in place of the form once a submission lands.</Hint>
|
|
92
92
|
</Labelled>
|
|
93
93
|
|
|
94
|
+
<div>
|
|
95
|
+
<label className="flex items-center gap-2 text-[13px] font-medium text-ink">
|
|
96
|
+
<input
|
|
97
|
+
type="checkbox"
|
|
98
|
+
checked={form.requireSpamCheck}
|
|
99
|
+
onChange={(event) => {
|
|
100
|
+
patch({ requireSpamCheck: event.target.checked })
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
Require the spam check
|
|
104
|
+
</label>
|
|
105
|
+
<Hint>
|
|
106
|
+
A submit that fails the check is held as spam and writes nothing to your CRM. You
|
|
107
|
+
can release it from the Submissions tab. Your embeds pass the check by themselves.
|
|
108
|
+
If a site posts JSON to this form from its own markup, it must get a token first:
|
|
109
|
+
see the Embed tab.
|
|
110
|
+
</Hint>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
94
113
|
<p className="rounded-md border border-border bg-surface px-3 py-2 text-[12px] text-ink-muted">
|
|
95
|
-
Deal, opportunity, partnership, tags, lists,
|
|
114
|
+
Deal, opportunity, partnership, tags, lists, attached records, and emails live on the{' '}
|
|
96
115
|
<strong className="font-medium text-ink">Actions</strong> tab.
|
|
97
116
|
</p>
|
|
98
117
|
|
|
@@ -189,8 +208,8 @@ function SlugSetting({ form }: { readonly form: Form }): React.JSX.Element {
|
|
|
189
208
|
) : (
|
|
190
209
|
<Hint>
|
|
191
210
|
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
|
|
193
|
-
embeds keep working and use the new slug.
|
|
211
|
+
the form shows it. If a bot sends spam to the submit URL directly, regenerate the
|
|
212
|
+
slug. Your embeds keep working and use the new slug.
|
|
194
213
|
</Hint>
|
|
195
214
|
)}
|
|
196
215
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { formFieldDisplayLabel } from '@kelpie/schemas'
|
|
1
|
+
import { FORM_SPAM_REASON_LABELS, formFieldDisplayLabel } from '@kelpie/schemas'
|
|
2
2
|
import type { Form, FormField, FormSubmission, FormSubmissionActionEntry } from '@kelpie/schemas'
|
|
3
3
|
import { useMemo } from 'react'
|
|
4
4
|
import { Link, 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 {
|
|
8
|
+
import {
|
|
9
|
+
useForm,
|
|
10
|
+
useFormSubmission,
|
|
11
|
+
useReleaseFormSubmission,
|
|
12
|
+
} from '../../api/resources/forms.ts'
|
|
9
13
|
import { usePeople } from '../../api/resources/people.ts'
|
|
10
14
|
import { ErrorPanel, LoadingPanel, NotFoundPanel } from '../../components/QueryState.tsx'
|
|
11
15
|
import { SectionHeader } from '../../components/SectionHeader.tsx'
|
|
@@ -101,6 +105,8 @@ function SubmissionDetailView({
|
|
|
101
105
|
description={`Received ${formatDateTime(submission.submittedAt, timezone)}.`}
|
|
102
106
|
/>
|
|
103
107
|
|
|
108
|
+
<SpamNotice form={form} submission={submission} />
|
|
109
|
+
|
|
104
110
|
<div className="mt-6 space-y-6">
|
|
105
111
|
<section>
|
|
106
112
|
<h3 className="mb-2 text-[11px] font-semibold uppercase tracking-wide text-ink-faint">
|
|
@@ -203,6 +209,62 @@ function SubmissionDetailView({
|
|
|
203
209
|
)
|
|
204
210
|
}
|
|
205
211
|
|
|
212
|
+
/**
|
|
213
|
+
* What the spam check said about this submission, and the way out.
|
|
214
|
+
*
|
|
215
|
+
* A held submission shows the reason and a Release button. One a person
|
|
216
|
+
* released keeps its reason, so the page says where it came from.
|
|
217
|
+
*/
|
|
218
|
+
function SpamNotice({
|
|
219
|
+
form,
|
|
220
|
+
submission,
|
|
221
|
+
}: {
|
|
222
|
+
readonly form: Form
|
|
223
|
+
readonly submission: FormSubmission
|
|
224
|
+
}): React.JSX.Element | null {
|
|
225
|
+
const release = useReleaseFormSubmission()
|
|
226
|
+
|
|
227
|
+
if (submission.spamReason === null) {
|
|
228
|
+
return null
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const reason = FORM_SPAM_REASON_LABELS[submission.spamReason]
|
|
232
|
+
|
|
233
|
+
if (submission.status !== 'spam') {
|
|
234
|
+
return (
|
|
235
|
+
<p className="mt-4 rounded-md border border-border bg-surface px-3 py-2 text-[12px] text-ink-muted">
|
|
236
|
+
The spam check held this submission, and a person released it. Reason it was held:{' '}
|
|
237
|
+
{reason}.
|
|
238
|
+
</p>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<div className="mt-4 rounded-md border border-warning/40 bg-warning-soft px-3 py-2.5">
|
|
244
|
+
<p className="text-[13px] font-medium text-ink">Held as spam</p>
|
|
245
|
+
<p className="mt-0.5 text-[12px] text-ink-muted">
|
|
246
|
+
{reason}. Nothing was written to your CRM and no email was sent. If a person sent
|
|
247
|
+
this, release it: Kelpie then processes it as a normal submission.
|
|
248
|
+
</p>
|
|
249
|
+
{release.error !== null && (
|
|
250
|
+
<div className="mt-2">
|
|
251
|
+
<ErrorPanel error={release.error} />
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
<button
|
|
255
|
+
type="button"
|
|
256
|
+
disabled={release.isPending}
|
|
257
|
+
onClick={() => {
|
|
258
|
+
release.run({ formId: form.id, submissionId: submission.id })
|
|
259
|
+
}}
|
|
260
|
+
className="mt-2 rounded-md bg-accent px-2.5 py-1 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover disabled:opacity-50"
|
|
261
|
+
>
|
|
262
|
+
{release.isPending ? 'Releasing…' : 'Release'}
|
|
263
|
+
</button>
|
|
264
|
+
</div>
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
206
268
|
function RecordRow({
|
|
207
269
|
label,
|
|
208
270
|
to,
|