@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.
- package/dist/api/resources/account.d.ts +7 -1
- package/dist/api/resources/account.d.ts.map +1 -1
- package/dist/api/resources/account.js +17 -1
- package/dist/api/resources/account.js.map +1 -1
- package/dist/api/resources/bulkActions.d.ts +50 -0
- package/dist/api/resources/bulkActions.d.ts.map +1 -0
- package/dist/api/resources/bulkActions.js +192 -0
- package/dist/api/resources/bulkActions.js.map +1 -0
- package/dist/api/resources/forms.d.ts +26 -1
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +98 -1
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/app/KelpieApp.d.ts.map +1 -1
- package/dist/app/KelpieApp.js +3 -1
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/ActivitiesPanel.d.ts.map +1 -1
- package/dist/components/ActivitiesPanel.js +3 -12
- package/dist/components/ActivitiesPanel.js.map +1 -1
- package/dist/components/BulkActions.d.ts +61 -0
- package/dist/components/BulkActions.d.ts.map +1 -0
- package/dist/components/BulkActions.js +351 -0
- package/dist/components/BulkActions.js.map +1 -0
- package/dist/components/BulkParamFields.d.ts +13 -0
- package/dist/components/BulkParamFields.d.ts.map +1 -0
- package/dist/components/BulkParamFields.js +177 -0
- package/dist/components/BulkParamFields.js.map +1 -0
- package/dist/components/CellLinks.d.ts +38 -0
- package/dist/components/CellLinks.d.ts.map +1 -0
- package/dist/components/CellLinks.js +58 -0
- package/dist/components/CellLinks.js.map +1 -0
- package/dist/components/CustomFieldsPanel.d.ts +12 -1
- package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
- package/dist/components/CustomFieldsPanel.js +5 -1
- package/dist/components/CustomFieldsPanel.js.map +1 -1
- package/dist/components/DataTable.d.ts +42 -1
- package/dist/components/DataTable.d.ts.map +1 -1
- package/dist/components/DataTable.js +51 -16
- package/dist/components/DataTable.js.map +1 -1
- package/dist/components/NotesPanel.d.ts.map +1 -1
- package/dist/components/NotesPanel.js +2 -15
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/PhonesField.d.ts.map +1 -1
- package/dist/components/PhonesField.js +1 -3
- package/dist/components/PhonesField.js.map +1 -1
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +16 -6
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/TagInput.d.ts.map +1 -1
- package/dist/components/TagInput.js +5 -0
- package/dist/components/TagInput.js.map +1 -1
- package/dist/components/bulkActionParams.d.ts +71 -0
- package/dist/components/bulkActionParams.d.ts.map +1 -0
- package/dist/components/bulkActionParams.js +241 -0
- package/dist/components/bulkActionParams.js.map +1 -0
- package/dist/components/bulkActionSummary.d.ts +22 -0
- package/dist/components/bulkActionSummary.d.ts.map +1 -0
- package/dist/components/bulkActionSummary.js +68 -0
- package/dist/components/bulkActionSummary.js.map +1 -0
- package/dist/components/bulkJobStatus.d.ts +4 -0
- package/dist/components/bulkJobStatus.d.ts.map +1 -0
- package/dist/components/bulkJobStatus.js +10 -0
- package/dist/components/bulkJobStatus.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/attribution.d.ts +31 -0
- package/dist/lib/attribution.d.ts.map +1 -0
- package/dist/lib/attribution.js +48 -0
- package/dist/lib/attribution.js.map +1 -0
- package/dist/lib/bulkSelection.d.ts +43 -0
- package/dist/lib/bulkSelection.d.ts.map +1 -0
- package/dist/lib/bulkSelection.js +70 -0
- package/dist/lib/bulkSelection.js.map +1 -0
- package/dist/lib/contactLinks.d.ts +15 -0
- package/dist/lib/contactLinks.d.ts.map +1 -0
- package/dist/lib/contactLinks.js +22 -0
- package/dist/lib/contactLinks.js.map +1 -0
- package/dist/pages/BulkJobsPage.d.ts +3 -0
- package/dist/pages/BulkJobsPage.d.ts.map +1 -0
- package/dist/pages/BulkJobsPage.js +92 -0
- package/dist/pages/BulkJobsPage.js.map +1 -0
- package/dist/pages/CompaniesPage.d.ts.map +1 -1
- package/dist/pages/CompaniesPage.js +9 -5
- package/dist/pages/CompaniesPage.js.map +1 -1
- package/dist/pages/CompanyDetail.d.ts.map +1 -1
- package/dist/pages/CompanyDetail.js +4 -3
- package/dist/pages/CompanyDetail.js.map +1 -1
- package/dist/pages/DealsPage.d.ts.map +1 -1
- package/dist/pages/DealsPage.js +15 -4
- package/dist/pages/DealsPage.js.map +1 -1
- package/dist/pages/DecisionsPage.d.ts.map +1 -1
- package/dist/pages/DecisionsPage.js +11 -1
- package/dist/pages/DecisionsPage.js.map +1 -1
- package/dist/pages/EnquiriesPage.d.ts.map +1 -1
- package/dist/pages/EnquiriesPage.js +15 -6
- package/dist/pages/EnquiriesPage.js.map +1 -1
- package/dist/pages/EventDetail.d.ts.map +1 -1
- package/dist/pages/EventDetail.js +14 -6
- package/dist/pages/EventDetail.js.map +1 -1
- package/dist/pages/EventsPage.d.ts.map +1 -1
- package/dist/pages/EventsPage.js +22 -5
- package/dist/pages/EventsPage.js.map +1 -1
- package/dist/pages/FormsPage.d.ts.map +1 -1
- package/dist/pages/FormsPage.js +2 -2
- package/dist/pages/FormsPage.js.map +1 -1
- package/dist/pages/FundraisingPage.d.ts.map +1 -1
- package/dist/pages/FundraisingPage.js +15 -4
- package/dist/pages/FundraisingPage.js.map +1 -1
- package/dist/pages/HiringPage.d.ts.map +1 -1
- package/dist/pages/HiringPage.js +2 -1
- package/dist/pages/HiringPage.js.map +1 -1
- package/dist/pages/ListDetail.d.ts.map +1 -1
- package/dist/pages/ListDetail.js +39 -7
- package/dist/pages/ListDetail.js.map +1 -1
- package/dist/pages/ListsPage.d.ts.map +1 -1
- package/dist/pages/ListsPage.js +2 -1
- package/dist/pages/ListsPage.js.map +1 -1
- package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
- package/dist/pages/OpportunitiesPage.js +15 -6
- package/dist/pages/OpportunitiesPage.js.map +1 -1
- package/dist/pages/PartnershipsPage.d.ts.map +1 -1
- package/dist/pages/PartnershipsPage.js +15 -4
- package/dist/pages/PartnershipsPage.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +10 -9
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/PlanningPage.d.ts.map +1 -1
- package/dist/pages/PlanningPage.js +15 -4
- package/dist/pages/PlanningPage.js.map +1 -1
- package/dist/pages/RoleDetail.d.ts.map +1 -1
- package/dist/pages/RoleDetail.js +12 -4
- package/dist/pages/RoleDetail.js.map +1 -1
- package/dist/pages/dashboard/sections.d.ts.map +1 -1
- package/dist/pages/dashboard/sections.js +8 -10
- package/dist/pages/dashboard/sections.js.map +1 -1
- package/dist/pages/forms/BlockedSendersPage.d.ts +10 -0
- package/dist/pages/forms/BlockedSendersPage.d.ts.map +1 -0
- package/dist/pages/forms/BlockedSendersPage.js +65 -0
- package/dist/pages/forms/BlockedSendersPage.js.map +1 -0
- package/dist/pages/forms/MarkSpamPanel.d.ts +19 -0
- package/dist/pages/forms/MarkSpamPanel.d.ts.map +1 -0
- package/dist/pages/forms/MarkSpamPanel.js +62 -0
- package/dist/pages/forms/MarkSpamPanel.js.map +1 -0
- package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +41 -11
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +6 -4
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/markSpamChoices.d.ts +51 -0
- package/dist/pages/forms/markSpamChoices.d.ts.map +1 -0
- package/dist/pages/forms/markSpamChoices.js +96 -0
- package/dist/pages/forms/markSpamChoices.js.map +1 -0
- package/dist/pages/positionDirectory.d.ts +5 -0
- package/dist/pages/positionDirectory.d.ts.map +1 -1
- package/dist/pages/positionDirectory.js +11 -3
- package/dist/pages/positionDirectory.js.map +1 -1
- package/dist/registry/context.d.ts +3 -1
- package/dist/registry/context.d.ts.map +1 -1
- package/dist/registry/context.js +4 -0
- package/dist/registry/context.js.map +1 -1
- package/dist/registry/contributions.d.ts +23 -0
- package/dist/registry/contributions.d.ts.map +1 -1
- package/dist/registry/contributions.js.map +1 -1
- package/dist/registry/registry.d.ts +4 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +6 -0
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/visibleNav.d.ts.map +1 -1
- package/dist/registry/visibleNav.js +1 -0
- package/dist/registry/visibleNav.js.map +1 -1
- package/package.json +3 -3
- package/src/api/resources/account.ts +20 -0
- package/src/api/resources/bulkActions.ts +267 -0
- package/src/api/resources/forms.ts +135 -0
- package/src/app/KelpieApp.tsx +5 -0
- package/src/components/ActivitiesPanel.tsx +3 -14
- package/src/components/BulkActions.tsx +961 -0
- package/src/components/BulkParamFields.tsx +524 -0
- package/src/components/CellLinks.tsx +138 -0
- package/src/components/CustomFieldsPanel.tsx +6 -2
- package/src/components/DataTable.tsx +142 -2
- package/src/components/NotesPanel.tsx +2 -17
- package/src/components/PhonesField.tsx +2 -4
- package/src/components/Shell.tsx +23 -6
- package/src/components/TagInput.tsx +5 -0
- package/src/components/bulkActionParams.ts +405 -0
- package/src/components/bulkActionSummary.ts +104 -0
- package/src/components/bulkJobStatus.ts +11 -0
- package/src/index.ts +3 -0
- package/src/lib/attribution.ts +59 -0
- package/src/lib/bulkSelection.ts +128 -0
- package/src/lib/contactLinks.ts +25 -0
- package/src/pages/BulkJobsPage.tsx +206 -0
- package/src/pages/CompaniesPage.tsx +21 -6
- package/src/pages/CompanyDetail.tsx +4 -3
- package/src/pages/DealsPage.tsx +30 -2
- package/src/pages/DecisionsPage.tsx +21 -1
- package/src/pages/EnquiriesPage.tsx +33 -5
- package/src/pages/EventDetail.tsx +43 -16
- package/src/pages/EventsPage.tsx +35 -4
- package/src/pages/FormsPage.tsx +7 -1
- package/src/pages/FundraisingPage.tsx +30 -2
- package/src/pages/HiringPage.tsx +6 -1
- package/src/pages/ListDetail.tsx +69 -5
- package/src/pages/ListsPage.tsx +6 -1
- package/src/pages/OpportunitiesPage.tsx +33 -5
- package/src/pages/PartnershipsPage.tsx +30 -2
- package/src/pages/PeoplePage.tsx +26 -21
- package/src/pages/PlanningPage.tsx +65 -24
- package/src/pages/RoleDetail.tsx +35 -7
- package/src/pages/dashboard/sections.tsx +13 -14
- package/src/pages/forms/BlockedSendersPage.tsx +155 -0
- package/src/pages/forms/MarkSpamPanel.tsx +193 -0
- package/src/pages/forms/SubmissionDetail.tsx +73 -18
- package/src/pages/forms/SubmissionsTable.tsx +7 -5
- package/src/pages/forms/markSpamChoices.ts +141 -0
- package/src/pages/positionDirectory.ts +16 -4
- package/src/registry/context.ts +6 -0
- package/src/registry/contributions.ts +25 -0
- package/src/registry/registry.ts +12 -0
- package/src/registry/visibleNav.ts +1 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomFieldDefinition,
|
|
3
|
+
CustomFieldObjectType,
|
|
4
|
+
CustomFieldType,
|
|
5
|
+
CustomFieldValue,
|
|
6
|
+
PipelineKind,
|
|
7
|
+
RecordTargetType,
|
|
8
|
+
} from '@kelpie/schemas'
|
|
9
|
+
import { useId, useState } from 'react'
|
|
10
|
+
|
|
11
|
+
import { useTimezone } from '../api/resources/account.ts'
|
|
12
|
+
import { useCompanies } from '../api/resources/companies.ts'
|
|
13
|
+
import { useCustomFields } from '../api/resources/customFields.ts'
|
|
14
|
+
import { useEvents } from '../api/resources/events.ts'
|
|
15
|
+
import { useLists } from '../api/resources/lists.ts'
|
|
16
|
+
import { useMembers } from '../api/resources/members.ts'
|
|
17
|
+
import { usePipelineStages } from '../api/resources/pipelineStages.ts'
|
|
18
|
+
import { useRoles } from '../api/resources/roles.ts'
|
|
19
|
+
import { formatDate } from '../lib/dates.ts'
|
|
20
|
+
import type { ParamField, ParamValue, ParamValues, PickedRecordType } from './bulkActionParams.ts'
|
|
21
|
+
import { ControlFor } from './CustomFieldsPanel.tsx'
|
|
22
|
+
import { EntitySearch } from './EntitySearch.tsx'
|
|
23
|
+
import type { SearchOption } from './EntitySearch.tsx'
|
|
24
|
+
import { TagInput } from './TagInput.tsx'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The inputs for a bulk action's params, one per field, with the pickers the
|
|
28
|
+
* rest of the app uses for the same values. Which field gets which input is
|
|
29
|
+
* decided in `bulkActionParams.ts`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const inputClass =
|
|
33
|
+
'mt-1 block w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent'
|
|
34
|
+
|
|
35
|
+
const labelClass = 'block text-[12px] font-medium text-ink-muted'
|
|
36
|
+
|
|
37
|
+
/** The `<option>` value for "no owner": a select cannot hold `null`. */
|
|
38
|
+
const NO_OWNER = '__none__'
|
|
39
|
+
|
|
40
|
+
/** Lists are few, and a picker that pages would hide some. The API's page maximum. */
|
|
41
|
+
const LIST_PAGE = 200
|
|
42
|
+
|
|
43
|
+
/** Custom fields per record type are few too. Read in the order the settings page sets. */
|
|
44
|
+
const FIELD_PAGE = 200
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `choice` is the text of the option picked in a select, such as a stage's
|
|
48
|
+
* label for a stage id, so the confirm step can name it without a lookup.
|
|
49
|
+
*/
|
|
50
|
+
export type ParamChange = (name: string, value: ParamValue, choice?: string) => void
|
|
51
|
+
|
|
52
|
+
export interface BulkParamFieldsProps {
|
|
53
|
+
readonly fields: readonly ParamField[]
|
|
54
|
+
readonly values: ParamValues
|
|
55
|
+
readonly onChange: ParamChange
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type FieldChange = (value: ParamValue, choice?: string) => void
|
|
59
|
+
|
|
60
|
+
/** The visible text of the option a select now shows. */
|
|
61
|
+
function chosenText(select: HTMLSelectElement): string | undefined {
|
|
62
|
+
return select.selectedOptions[0]?.textContent ?? undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function BulkParamFields({ fields, values, onChange }: BulkParamFieldsProps): React.JSX.Element {
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
{fields.map((field) => (
|
|
69
|
+
<ParamInput
|
|
70
|
+
key={field.name}
|
|
71
|
+
field={field}
|
|
72
|
+
value={values[field.name] ?? ''}
|
|
73
|
+
values={values}
|
|
74
|
+
onChange={(value, choice) => {
|
|
75
|
+
onChange(field.name, value, choice)
|
|
76
|
+
}}
|
|
77
|
+
onFieldPicked={(initial) => {
|
|
78
|
+
// A value chosen for one custom field may not fit the next.
|
|
79
|
+
for (const other of fields) {
|
|
80
|
+
if (other.kind === 'customValue' && other.fieldParam === field.name) {
|
|
81
|
+
onChange(other.name, initial)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
))}
|
|
87
|
+
</>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function asString(value: ParamValue): string {
|
|
92
|
+
return typeof value === 'string' ? value : ''
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function ParamInput({
|
|
96
|
+
field,
|
|
97
|
+
value,
|
|
98
|
+
values,
|
|
99
|
+
onChange,
|
|
100
|
+
onFieldPicked,
|
|
101
|
+
}: {
|
|
102
|
+
readonly field: ParamField
|
|
103
|
+
readonly value: ParamValue
|
|
104
|
+
readonly values: ParamValues
|
|
105
|
+
readonly onChange: FieldChange
|
|
106
|
+
/** A custom field was picked. Its value starts again from `initial`. */
|
|
107
|
+
readonly onFieldPicked: (initial: ParamValue) => void
|
|
108
|
+
}): React.JSX.Element {
|
|
109
|
+
switch (field.kind) {
|
|
110
|
+
case 'record':
|
|
111
|
+
return <RecordInput label={field.label} recordType={field.recordType} value={asString(value)} onChange={onChange} />
|
|
112
|
+
case 'customField':
|
|
113
|
+
return (
|
|
114
|
+
<CustomFieldInput
|
|
115
|
+
label={field.label}
|
|
116
|
+
objectType={field.objectType}
|
|
117
|
+
value={asString(value)}
|
|
118
|
+
onChange={(fieldId, choice, initial) => {
|
|
119
|
+
onChange(fieldId, choice)
|
|
120
|
+
onFieldPicked(initial)
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
)
|
|
124
|
+
case 'customValue':
|
|
125
|
+
return (
|
|
126
|
+
<CustomValueInput
|
|
127
|
+
label={field.label}
|
|
128
|
+
objectType={field.objectType}
|
|
129
|
+
fieldId={asString(values[field.fieldParam] ?? '')}
|
|
130
|
+
value={value}
|
|
131
|
+
onChange={onChange}
|
|
132
|
+
/>
|
|
133
|
+
)
|
|
134
|
+
case 'tags':
|
|
135
|
+
return (
|
|
136
|
+
<TagInput
|
|
137
|
+
value={Array.isArray(value) ? value : []}
|
|
138
|
+
onChange={onChange}
|
|
139
|
+
targetType={field.tagType}
|
|
140
|
+
size="md"
|
|
141
|
+
label={field.label}
|
|
142
|
+
/>
|
|
143
|
+
)
|
|
144
|
+
case 'member':
|
|
145
|
+
return <MemberInput label={field.label} nullable={field.nullable} value={value} onChange={onChange} />
|
|
146
|
+
case 'stage':
|
|
147
|
+
return <StageInput label={field.label} pipeline={field.pipeline} value={asString(value)} onChange={onChange} />
|
|
148
|
+
case 'list':
|
|
149
|
+
return <ListInput label={field.label} listType={field.listType} value={asString(value)} onChange={onChange} />
|
|
150
|
+
case 'enum':
|
|
151
|
+
return (
|
|
152
|
+
<label className={labelClass}>
|
|
153
|
+
{field.label}
|
|
154
|
+
<select
|
|
155
|
+
value={asString(value)}
|
|
156
|
+
onChange={(event) => {
|
|
157
|
+
onChange(event.target.value, chosenText(event.target))
|
|
158
|
+
}}
|
|
159
|
+
className={inputClass}
|
|
160
|
+
>
|
|
161
|
+
<option value="">Choose…</option>
|
|
162
|
+
{field.options.map((option) => (
|
|
163
|
+
<option key={option.value} value={option.value}>
|
|
164
|
+
{option.label}
|
|
165
|
+
</option>
|
|
166
|
+
))}
|
|
167
|
+
</select>
|
|
168
|
+
</label>
|
|
169
|
+
)
|
|
170
|
+
case 'boolean':
|
|
171
|
+
return (
|
|
172
|
+
<label className="inline-flex items-center gap-2 text-[13px] text-ink">
|
|
173
|
+
<input
|
|
174
|
+
type="checkbox"
|
|
175
|
+
checked={value === true}
|
|
176
|
+
onChange={(event) => {
|
|
177
|
+
onChange(event.target.checked)
|
|
178
|
+
}}
|
|
179
|
+
className="h-3.5 w-3.5 rounded border-border text-accent focus:ring-accent"
|
|
180
|
+
/>
|
|
181
|
+
{field.label}
|
|
182
|
+
</label>
|
|
183
|
+
)
|
|
184
|
+
case 'date':
|
|
185
|
+
case 'text':
|
|
186
|
+
case 'number':
|
|
187
|
+
return (
|
|
188
|
+
<ClearableInput
|
|
189
|
+
label={field.label}
|
|
190
|
+
type={field.kind}
|
|
191
|
+
nullable={field.nullable}
|
|
192
|
+
value={value}
|
|
193
|
+
onChange={onChange}
|
|
194
|
+
/>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* A text or date box. Where the field may be cleared, a checkbox says so
|
|
201
|
+
* outright, so an empty box is never read as "clear it on every record".
|
|
202
|
+
*/
|
|
203
|
+
function ClearableInput({
|
|
204
|
+
label,
|
|
205
|
+
type,
|
|
206
|
+
nullable,
|
|
207
|
+
value,
|
|
208
|
+
onChange,
|
|
209
|
+
}: {
|
|
210
|
+
readonly label: string
|
|
211
|
+
readonly type: 'date' | 'text' | 'number'
|
|
212
|
+
readonly nullable: boolean
|
|
213
|
+
readonly value: ParamValue
|
|
214
|
+
readonly onChange: FieldChange
|
|
215
|
+
}): React.JSX.Element {
|
|
216
|
+
const id = useId()
|
|
217
|
+
const cleared = value === null
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<div>
|
|
221
|
+
<label htmlFor={id} className={labelClass}>
|
|
222
|
+
{label}
|
|
223
|
+
</label>
|
|
224
|
+
<input
|
|
225
|
+
id={id}
|
|
226
|
+
type={type}
|
|
227
|
+
value={asString(value)}
|
|
228
|
+
disabled={cleared}
|
|
229
|
+
onChange={(event) => {
|
|
230
|
+
onChange(event.target.value)
|
|
231
|
+
}}
|
|
232
|
+
className={`${inputClass} disabled:opacity-50`}
|
|
233
|
+
/>
|
|
234
|
+
{nullable && (
|
|
235
|
+
<label className="mt-1.5 inline-flex items-center gap-2 text-[12px] text-ink-muted">
|
|
236
|
+
<input
|
|
237
|
+
type="checkbox"
|
|
238
|
+
checked={cleared}
|
|
239
|
+
onChange={(event) => {
|
|
240
|
+
onChange(event.target.checked ? null : '')
|
|
241
|
+
}}
|
|
242
|
+
className="h-3.5 w-3.5 rounded border-border text-accent focus:ring-accent"
|
|
243
|
+
/>
|
|
244
|
+
Clear {label.toLowerCase()} instead
|
|
245
|
+
</label>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function MemberInput({
|
|
252
|
+
label,
|
|
253
|
+
nullable,
|
|
254
|
+
value,
|
|
255
|
+
onChange,
|
|
256
|
+
}: {
|
|
257
|
+
readonly label: string
|
|
258
|
+
readonly nullable: boolean
|
|
259
|
+
readonly value: ParamValue
|
|
260
|
+
readonly onChange: FieldChange
|
|
261
|
+
}): React.JSX.Element {
|
|
262
|
+
const members = useMembers()
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<label className={labelClass}>
|
|
266
|
+
{label}
|
|
267
|
+
<select
|
|
268
|
+
value={value === null ? NO_OWNER : asString(value)}
|
|
269
|
+
onChange={(event) => {
|
|
270
|
+
onChange(event.target.value === NO_OWNER ? null : event.target.value, chosenText(event.target))
|
|
271
|
+
}}
|
|
272
|
+
className={inputClass}
|
|
273
|
+
>
|
|
274
|
+
<option value="">{members.isLoading ? 'Loading…' : 'Choose…'}</option>
|
|
275
|
+
{nullable && <option value={NO_OWNER}>No owner</option>}
|
|
276
|
+
{members.members.map((member) => (
|
|
277
|
+
<option key={member.id} value={member.id}>
|
|
278
|
+
{member.name}
|
|
279
|
+
</option>
|
|
280
|
+
))}
|
|
281
|
+
</select>
|
|
282
|
+
</label>
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function StageInput({
|
|
287
|
+
label,
|
|
288
|
+
pipeline,
|
|
289
|
+
value,
|
|
290
|
+
onChange,
|
|
291
|
+
}: {
|
|
292
|
+
readonly label: string
|
|
293
|
+
readonly pipeline: PipelineKind
|
|
294
|
+
readonly value: string
|
|
295
|
+
readonly onChange: FieldChange
|
|
296
|
+
}): React.JSX.Element {
|
|
297
|
+
const stages = usePipelineStages(pipeline)
|
|
298
|
+
const ordered = [...stages.records].sort((left, right) => left.sortOrder - right.sortOrder)
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<label className={labelClass}>
|
|
302
|
+
{label}
|
|
303
|
+
<select
|
|
304
|
+
value={value}
|
|
305
|
+
onChange={(event) => {
|
|
306
|
+
onChange(event.target.value, chosenText(event.target))
|
|
307
|
+
}}
|
|
308
|
+
className={inputClass}
|
|
309
|
+
>
|
|
310
|
+
<option value="">{stages.isLoading ? 'Loading…' : 'Choose…'}</option>
|
|
311
|
+
{ordered.map((stage) => (
|
|
312
|
+
<option key={stage.id} value={stage.id}>
|
|
313
|
+
{stage.label}
|
|
314
|
+
</option>
|
|
315
|
+
))}
|
|
316
|
+
</select>
|
|
317
|
+
</label>
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function ListInput({
|
|
322
|
+
label,
|
|
323
|
+
listType,
|
|
324
|
+
value,
|
|
325
|
+
onChange,
|
|
326
|
+
}: {
|
|
327
|
+
readonly label: string
|
|
328
|
+
readonly listType: RecordTargetType
|
|
329
|
+
readonly value: string
|
|
330
|
+
readonly onChange: FieldChange
|
|
331
|
+
}): React.JSX.Element {
|
|
332
|
+
const lists = useLists({ targetType: listType, limit: LIST_PAGE })
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<label className={labelClass}>
|
|
336
|
+
{label}
|
|
337
|
+
<select
|
|
338
|
+
value={value}
|
|
339
|
+
onChange={(event) => {
|
|
340
|
+
onChange(event.target.value, chosenText(event.target))
|
|
341
|
+
}}
|
|
342
|
+
className={inputClass}
|
|
343
|
+
>
|
|
344
|
+
<option value="">{lists.isLoading ? 'Loading…' : 'Choose…'}</option>
|
|
345
|
+
{lists.records.map((list) => (
|
|
346
|
+
<option key={list.id} value={list.id}>
|
|
347
|
+
{list.name}
|
|
348
|
+
</option>
|
|
349
|
+
))}
|
|
350
|
+
</select>
|
|
351
|
+
{!lists.isLoading && lists.records.length === 0 && (
|
|
352
|
+
<span className="mt-1 block text-[11px] text-ink-faint">No lists hold this type of record yet.</span>
|
|
353
|
+
)}
|
|
354
|
+
</label>
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The search each picked record type runs, as options for the picker. */
|
|
359
|
+
function useRecordOptions(recordType: PickedRecordType, term: string | undefined): readonly SearchOption[] {
|
|
360
|
+
// Each hook runs on every render, as hooks must; only the one in use is enabled.
|
|
361
|
+
const events = useEvents({ term }, { enabled: recordType === 'event' })
|
|
362
|
+
const roles = useRoles({ term }, { enabled: recordType === 'role' })
|
|
363
|
+
const companies = useCompanies({ term }, { enabled: recordType === 'company' })
|
|
364
|
+
const timezone = useTimezone()
|
|
365
|
+
|
|
366
|
+
switch (recordType) {
|
|
367
|
+
case 'event':
|
|
368
|
+
return events.records.map((event) => ({ id: event.id, label: event.name, meta: formatDate(event.startsAt, timezone) }))
|
|
369
|
+
case 'role':
|
|
370
|
+
return roles.records.map((role) => ({ id: role.id, label: role.title }))
|
|
371
|
+
case 'company':
|
|
372
|
+
return companies.records.map((company) => ({
|
|
373
|
+
id: company.id,
|
|
374
|
+
label: company.name,
|
|
375
|
+
meta: company.domain ?? undefined,
|
|
376
|
+
}))
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const RECORD_PLACEHOLDER: Readonly<Record<PickedRecordType, string>> = {
|
|
381
|
+
event: 'Search events…',
|
|
382
|
+
role: 'Search roles…',
|
|
383
|
+
company: 'Search companies…',
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** One event, role or company, found by a server-side search. */
|
|
387
|
+
function RecordInput({
|
|
388
|
+
label,
|
|
389
|
+
recordType,
|
|
390
|
+
value,
|
|
391
|
+
onChange,
|
|
392
|
+
}: {
|
|
393
|
+
readonly label: string
|
|
394
|
+
readonly recordType: PickedRecordType
|
|
395
|
+
readonly value: string
|
|
396
|
+
readonly onChange: FieldChange
|
|
397
|
+
}): React.JSX.Element {
|
|
398
|
+
const [search, setSearch] = useState('')
|
|
399
|
+
const term = search.trim().length > 0 ? search.trim() : undefined
|
|
400
|
+
const options = useRecordOptions(recordType, term)
|
|
401
|
+
|
|
402
|
+
return (
|
|
403
|
+
<div>
|
|
404
|
+
<span className={labelClass}>{label}</span>
|
|
405
|
+
<EntitySearch
|
|
406
|
+
options={options}
|
|
407
|
+
value={value}
|
|
408
|
+
onChange={(id) => {
|
|
409
|
+
onChange(id, options.find((option) => option.id === id)?.label)
|
|
410
|
+
}}
|
|
411
|
+
onQueryChange={setSearch}
|
|
412
|
+
placeholder={RECORD_PLACEHOLDER[recordType]}
|
|
413
|
+
size="md"
|
|
414
|
+
className="mt-1"
|
|
415
|
+
/>
|
|
416
|
+
</div>
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** The value a newly picked field starts from. A checkbox has no "not chosen". */
|
|
421
|
+
function initialCustomValue(type: CustomFieldType | undefined): ParamValue {
|
|
422
|
+
return type === 'checkbox' ? false : ''
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** The custom fields of one record type, in their settings order. */
|
|
426
|
+
function useFieldDefinitions(objectType: CustomFieldObjectType): {
|
|
427
|
+
readonly definitions: readonly CustomFieldDefinition[]
|
|
428
|
+
readonly isLoading: boolean
|
|
429
|
+
} {
|
|
430
|
+
const fields = useCustomFields({ objectType, sort: 'sort_order', limit: FIELD_PAGE })
|
|
431
|
+
|
|
432
|
+
return { definitions: fields.records, isLoading: fields.isLoading }
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function CustomFieldInput({
|
|
436
|
+
label,
|
|
437
|
+
objectType,
|
|
438
|
+
value,
|
|
439
|
+
onChange,
|
|
440
|
+
}: {
|
|
441
|
+
readonly label: string
|
|
442
|
+
readonly objectType: CustomFieldObjectType
|
|
443
|
+
readonly value: string
|
|
444
|
+
readonly onChange: (fieldId: string, choice: string | undefined, initial: ParamValue) => void
|
|
445
|
+
}): React.JSX.Element {
|
|
446
|
+
const { definitions, isLoading } = useFieldDefinitions(objectType)
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<label className={labelClass}>
|
|
450
|
+
{label}
|
|
451
|
+
<select
|
|
452
|
+
value={value}
|
|
453
|
+
onChange={(event) => {
|
|
454
|
+
const definition = definitions.find((candidate) => candidate.id === event.target.value)
|
|
455
|
+
|
|
456
|
+
onChange(event.target.value, chosenText(event.target), initialCustomValue(definition?.type as CustomFieldType))
|
|
457
|
+
}}
|
|
458
|
+
className={inputClass}
|
|
459
|
+
>
|
|
460
|
+
<option value="">{isLoading ? 'Loading…' : 'Choose…'}</option>
|
|
461
|
+
{definitions.map((definition) => (
|
|
462
|
+
<option key={definition.id} value={definition.id}>
|
|
463
|
+
{definition.label}
|
|
464
|
+
</option>
|
|
465
|
+
))}
|
|
466
|
+
</select>
|
|
467
|
+
{!isLoading && definitions.length === 0 && (
|
|
468
|
+
<span className="mt-1 block text-[11px] text-ink-faint">This type of record has no custom fields yet.</span>
|
|
469
|
+
)}
|
|
470
|
+
</label>
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** How the confirm step names a value the select text cannot give. */
|
|
475
|
+
function customValueChoice(value: CustomFieldValue): string | undefined {
|
|
476
|
+
if (typeof value === 'object' && !Array.isArray(value) && 'amountCents' in value) {
|
|
477
|
+
return `${(value.amountCents / 100).toFixed(2)} ${value.currency}`
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return undefined
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** The chosen field's own input, as a record page shows it. */
|
|
484
|
+
function CustomValueInput({
|
|
485
|
+
label,
|
|
486
|
+
objectType,
|
|
487
|
+
fieldId,
|
|
488
|
+
value,
|
|
489
|
+
onChange,
|
|
490
|
+
}: {
|
|
491
|
+
readonly label: string
|
|
492
|
+
readonly objectType: CustomFieldObjectType
|
|
493
|
+
readonly fieldId: string
|
|
494
|
+
readonly value: ParamValue
|
|
495
|
+
readonly onChange: FieldChange
|
|
496
|
+
}): React.JSX.Element {
|
|
497
|
+
const { definitions } = useFieldDefinitions(objectType)
|
|
498
|
+
const definition = definitions.find((candidate) => candidate.id === fieldId)
|
|
499
|
+
|
|
500
|
+
return (
|
|
501
|
+
<div>
|
|
502
|
+
<span className={labelClass}>{label}</span>
|
|
503
|
+
{definition === undefined ? (
|
|
504
|
+
<p className="mt-1 text-[12px] text-ink-faint">Choose a field first.</p>
|
|
505
|
+
) : (
|
|
506
|
+
<div className="mt-1 text-[13px] text-ink">
|
|
507
|
+
<ControlFor
|
|
508
|
+
definition={definition}
|
|
509
|
+
type={definition.type as CustomFieldType}
|
|
510
|
+
value={value === null || value === '' ? undefined : value}
|
|
511
|
+
onChange={(next) => {
|
|
512
|
+
onChange(next, next === null ? undefined : customValueChoice(next))
|
|
513
|
+
}}
|
|
514
|
+
/>
|
|
515
|
+
{value === null && (
|
|
516
|
+
<p className="mt-1 text-[11px] text-ink-muted">
|
|
517
|
+
{definition.label} will be cleared on every record.
|
|
518
|
+
</p>
|
|
519
|
+
)}
|
|
520
|
+
</div>
|
|
521
|
+
)}
|
|
522
|
+
</div>
|
|
523
|
+
)
|
|
524
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { MouseEvent, ReactNode } from 'react'
|
|
2
|
+
import { Link } from 'react-router'
|
|
3
|
+
|
|
4
|
+
import { mailtoHref, telHref, websiteHref } from '../lib/contactLinks.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Links for list cells.
|
|
8
|
+
*
|
|
9
|
+
* A `DataTable` row opens its record when clicked anywhere. A link inside a
|
|
10
|
+
* cell goes somewhere else (a company, a mail client, a dialer), so each of
|
|
11
|
+
* these stops the click before the row sees it. Without that, clicking an
|
|
12
|
+
* email would open the mail client and also navigate away from the list.
|
|
13
|
+
*/
|
|
14
|
+
function stopRowClick(event: MouseEvent<HTMLAnchorElement>): void {
|
|
15
|
+
event.stopPropagation()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LINK_CLASS = 'hover:text-accent hover:underline'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The row's main label, as a real link to the row's own record. The row click
|
|
22
|
+
* already goes there, but a real link also gives middle-click, "open in new
|
|
23
|
+
* tab" and keyboard focus.
|
|
24
|
+
*/
|
|
25
|
+
export function RecordLink({
|
|
26
|
+
to,
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
}: {
|
|
30
|
+
readonly to: string
|
|
31
|
+
readonly children: ReactNode
|
|
32
|
+
readonly className?: string | undefined
|
|
33
|
+
}): React.JSX.Element {
|
|
34
|
+
return (
|
|
35
|
+
<Link to={to} onClick={stopRowClick} className={`${className ?? ''} ${LINK_CLASS}`}>
|
|
36
|
+
{children}
|
|
37
|
+
</Link>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Companies, comma separated, each linking to its own page. */
|
|
42
|
+
export function CompanyLinks({
|
|
43
|
+
companies,
|
|
44
|
+
}: {
|
|
45
|
+
readonly companies: readonly { readonly id: string; readonly name: string }[]
|
|
46
|
+
}): React.JSX.Element | string {
|
|
47
|
+
if (companies.length === 0) {
|
|
48
|
+
return '—'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<span>
|
|
53
|
+
{companies.map((company, index) => (
|
|
54
|
+
<span key={company.id}>
|
|
55
|
+
{index > 0 && ', '}
|
|
56
|
+
<RecordLink to={`/companies/${company.id}`}>{company.name}</RecordLink>
|
|
57
|
+
</span>
|
|
58
|
+
))}
|
|
59
|
+
</span>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One optional company. A name that has not loaded, or a company outside the
|
|
65
|
+
* loaded page, shows a dash rather than a link with no label.
|
|
66
|
+
*/
|
|
67
|
+
export function CompanyLink({
|
|
68
|
+
id,
|
|
69
|
+
name,
|
|
70
|
+
}: {
|
|
71
|
+
readonly id: string | null
|
|
72
|
+
readonly name: string | undefined
|
|
73
|
+
}): React.JSX.Element | string {
|
|
74
|
+
return id === null || name === undefined ? '—' : <CompanyLinks companies={[{ id, name }]} />
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function EmailLink({ email }: { readonly email: string | null }): React.JSX.Element | string {
|
|
78
|
+
if (email === null) {
|
|
79
|
+
return '—'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<a
|
|
84
|
+
href={mailtoHref(email)}
|
|
85
|
+
onClick={stopRowClick}
|
|
86
|
+
className={`font-mono text-[12px] text-ink-muted ${LINK_CLASS}`}
|
|
87
|
+
>
|
|
88
|
+
{email}
|
|
89
|
+
</a>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** One `tel:` link per number, so each dials on its own. */
|
|
94
|
+
export function PhoneLinks({
|
|
95
|
+
phones,
|
|
96
|
+
}: {
|
|
97
|
+
readonly phones: readonly string[]
|
|
98
|
+
}): React.JSX.Element | string {
|
|
99
|
+
if (phones.length === 0) {
|
|
100
|
+
return '—'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<span className="font-mono text-[12px] text-ink-muted">
|
|
105
|
+
{phones.map((phone, index) => (
|
|
106
|
+
<span key={`${phone}-${String(index)}`}>
|
|
107
|
+
{index > 0 && ', '}
|
|
108
|
+
<a href={telHref(phone)} onClick={stopRowClick} className={LINK_CLASS}>
|
|
109
|
+
{phone}
|
|
110
|
+
</a>
|
|
111
|
+
</span>
|
|
112
|
+
))}
|
|
113
|
+
</span>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A company's website, in a new tab so the list stays where it was. */
|
|
118
|
+
export function WebsiteLink({
|
|
119
|
+
domain,
|
|
120
|
+
}: {
|
|
121
|
+
readonly domain: string | null
|
|
122
|
+
}): React.JSX.Element {
|
|
123
|
+
if (domain === null) {
|
|
124
|
+
return <span className="font-mono text-[12px] text-ink-muted">—</span>
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<a
|
|
129
|
+
href={websiteHref(domain)}
|
|
130
|
+
target="_blank"
|
|
131
|
+
rel="noopener noreferrer"
|
|
132
|
+
onClick={stopRowClick}
|
|
133
|
+
className={`font-mono text-[12px] text-ink-muted ${LINK_CLASS}`}
|
|
134
|
+
>
|
|
135
|
+
{domain}
|
|
136
|
+
</a>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
@@ -113,14 +113,18 @@ function CustomFieldControl({
|
|
|
113
113
|
)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
interface ControlForProps {
|
|
116
|
+
export interface ControlForProps {
|
|
117
117
|
readonly definition: CustomFieldDefinition
|
|
118
118
|
readonly type: CustomFieldType
|
|
119
119
|
readonly value: CustomFieldValue | undefined
|
|
120
120
|
readonly onChange: (value: CustomFieldValue | null) => void
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The input for one custom field's value, by the field's type. The record
|
|
125
|
+
* pages use it, and so does the bulk Set field form. `null` clears the field.
|
|
126
|
+
*/
|
|
127
|
+
export function ControlFor({
|
|
124
128
|
definition,
|
|
125
129
|
type,
|
|
126
130
|
value,
|