@kelpie/ui 0.21.0 → 0.23.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/resource.d.ts +12 -0
- package/dist/api/resource.d.ts.map +1 -1
- package/dist/api/resource.js +11 -0
- package/dist/api/resource.js.map +1 -1
- package/dist/api/resources/decisions.d.ts +31 -0
- package/dist/api/resources/decisions.d.ts.map +1 -1
- package/dist/api/resources/decisions.js +51 -1
- package/dist/api/resources/decisions.js.map +1 -1
- package/dist/api/resources/forms.d.ts +21 -7
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +39 -1
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/api/resources/oauth.d.ts +2 -0
- package/dist/api/resources/oauth.d.ts.map +1 -1
- package/dist/api/resources/oauth.js +13 -1
- package/dist/api/resources/oauth.js.map +1 -1
- package/dist/api/resources/personIntake.d.ts +15 -3
- package/dist/api/resources/personIntake.d.ts.map +1 -1
- package/dist/api/resources/personIntake.js +38 -9
- package/dist/api/resources/personIntake.js.map +1 -1
- package/dist/api/resources/session.d.ts.map +1 -1
- package/dist/api/resources/session.js +4 -0
- package/dist/api/resources/session.js.map +1 -1
- package/dist/api/resources/tags.d.ts +20 -0
- package/dist/api/resources/tags.d.ts.map +1 -0
- package/dist/api/resources/tags.js +52 -0
- package/dist/api/resources/tags.js.map +1 -0
- package/dist/app/KelpieApp.d.ts.map +1 -1
- package/dist/app/KelpieApp.js +2 -1
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/AddRecordPanel.d.ts +35 -0
- package/dist/components/AddRecordPanel.d.ts.map +1 -0
- package/dist/components/AddRecordPanel.js +35 -0
- package/dist/components/AddRecordPanel.js.map +1 -0
- package/dist/components/AiDrawer.d.ts.map +1 -1
- package/dist/components/AiDrawer.js +29 -6
- package/dist/components/AiDrawer.js.map +1 -1
- package/dist/components/ApiKeysPanel.d.ts.map +1 -1
- package/dist/components/ApiKeysPanel.js +101 -44
- package/dist/components/ApiKeysPanel.js.map +1 -1
- package/dist/components/Chip.d.ts +5 -1
- package/dist/components/Chip.d.ts.map +1 -1
- package/dist/components/Chip.js +8 -2
- package/dist/components/Chip.js.map +1 -1
- package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
- package/dist/components/CustomFieldsPanel.js +5 -2
- package/dist/components/CustomFieldsPanel.js.map +1 -1
- package/dist/components/DecisionProvenance.d.ts +27 -0
- package/dist/components/DecisionProvenance.d.ts.map +1 -0
- package/dist/components/DecisionProvenance.js +53 -0
- package/dist/components/DecisionProvenance.js.map +1 -0
- package/dist/components/DecisionsPanel.d.ts +3 -0
- package/dist/components/DecisionsPanel.d.ts.map +1 -1
- package/dist/components/DecisionsPanel.js +9 -5
- package/dist/components/DecisionsPanel.js.map +1 -1
- package/dist/components/MarkdownView.d.ts.map +1 -1
- package/dist/components/MarkdownView.js +18 -2
- package/dist/components/MarkdownView.js.map +1 -1
- package/dist/components/NotesPanel.d.ts.map +1 -1
- package/dist/components/NotesPanel.js +7 -3
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/OriginLabel.d.ts +5 -0
- package/dist/components/OriginLabel.d.ts.map +1 -0
- package/dist/components/OriginLabel.js +22 -0
- package/dist/components/OriginLabel.js.map +1 -0
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +17 -5
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/TagInput.d.ts +29 -0
- package/dist/components/TagInput.d.ts.map +1 -0
- package/dist/components/TagInput.js +139 -0
- package/dist/components/TagInput.js.map +1 -0
- package/dist/components/aiDrawerState.d.ts +12 -0
- package/dist/components/aiDrawerState.d.ts.map +1 -1
- package/dist/components/aiDrawerState.js.map +1 -1
- package/dist/components/personIntakeTask.d.ts +15 -0
- package/dist/components/personIntakeTask.d.ts.map +1 -1
- package/dist/components/personIntakeTask.js +42 -0
- package/dist/components/personIntakeTask.js.map +1 -1
- package/dist/lib/personIntakeRunStorage.d.ts +15 -0
- package/dist/lib/personIntakeRunStorage.d.ts.map +1 -0
- package/dist/lib/personIntakeRunStorage.js +88 -0
- package/dist/lib/personIntakeRunStorage.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 +243 -29
- package/dist/modules/PersonIntakeWizard.js.map +1 -1
- package/dist/modules/ai.d.ts +1 -1
- package/dist/modules/ai.js +1 -1
- package/dist/pages/CompaniesPage.d.ts.map +1 -1
- package/dist/pages/CompaniesPage.js +13 -6
- 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/DealDetail.d.ts.map +1 -1
- package/dist/pages/DealDetail.js +4 -3
- package/dist/pages/DealDetail.js.map +1 -1
- package/dist/pages/DealsPage.d.ts.map +1 -1
- package/dist/pages/DealsPage.js +16 -8
- package/dist/pages/DealsPage.js.map +1 -1
- package/dist/pages/DecisionsPage.d.ts.map +1 -1
- package/dist/pages/DecisionsPage.js +7 -3
- package/dist/pages/DecisionsPage.js.map +1 -1
- package/dist/pages/EnquiriesPage.d.ts.map +1 -1
- package/dist/pages/EnquiriesPage.js +14 -6
- package/dist/pages/EnquiriesPage.js.map +1 -1
- package/dist/pages/EnquiryDetail.js +4 -4
- package/dist/pages/EnquiryDetail.js.map +1 -1
- package/dist/pages/EventDetail.js +4 -4
- package/dist/pages/EventDetail.js.map +1 -1
- package/dist/pages/FundraisingPage.d.ts.map +1 -1
- package/dist/pages/FundraisingPage.js +16 -11
- package/dist/pages/FundraisingPage.js.map +1 -1
- package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
- package/dist/pages/OpportunitiesPage.js +14 -6
- package/dist/pages/OpportunitiesPage.js.map +1 -1
- package/dist/pages/OpportunityDetail.js +4 -4
- package/dist/pages/OpportunityDetail.js.map +1 -1
- package/dist/pages/PartnershipDetail.js +4 -4
- package/dist/pages/PartnershipDetail.js.map +1 -1
- package/dist/pages/PartnershipsPage.d.ts.map +1 -1
- package/dist/pages/PartnershipsPage.js +16 -11
- package/dist/pages/PartnershipsPage.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +13 -8
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/PersonDetail.js +7 -7
- package/dist/pages/PersonDetail.js.map +1 -1
- package/dist/pages/RaiseDetail.js +4 -4
- package/dist/pages/RaiseDetail.js.map +1 -1
- package/dist/pages/SearchPage.d.ts.map +1 -1
- package/dist/pages/SearchPage.js +2 -1
- package/dist/pages/SearchPage.js.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.d.ts +0 -5
- package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.js +38 -6
- package/dist/pages/account/ConnectedAppsPage.js.map +1 -1
- package/dist/pages/admin/AgentsPanel.d.ts +10 -0
- package/dist/pages/admin/AgentsPanel.d.ts.map +1 -0
- package/dist/pages/admin/AgentsPanel.js +81 -0
- package/dist/pages/admin/AgentsPanel.js.map +1 -0
- package/dist/pages/admin/AiAdminPage.d.ts.map +1 -1
- package/dist/pages/admin/AiAdminPage.js +9 -6
- package/dist/pages/admin/AiAdminPage.js.map +1 -1
- package/dist/pages/admin/AiPage.js +1 -1
- package/dist/pages/admin/TeamPage.d.ts.map +1 -1
- package/dist/pages/admin/TeamPage.js +16 -3
- package/dist/pages/admin/TeamPage.js.map +1 -1
- package/dist/pages/ai/AiAccessPage.d.ts +11 -0
- package/dist/pages/ai/AiAccessPage.d.ts.map +1 -0
- package/dist/pages/ai/AiAccessPage.js +16 -0
- package/dist/pages/ai/AiAccessPage.js.map +1 -0
- package/dist/pages/ai/McpPanel.d.ts +7 -0
- package/dist/pages/ai/McpPanel.d.ts.map +1 -0
- package/dist/pages/ai/McpPanel.js +86 -0
- package/dist/pages/ai/McpPanel.js.map +1 -0
- package/dist/pages/auth/nextPath.d.ts +6 -0
- package/dist/pages/auth/nextPath.d.ts.map +1 -1
- package/dist/pages/auth/nextPath.js +16 -1
- package/dist/pages/auth/nextPath.js.map +1 -1
- package/dist/pages/dashboard/sections.d.ts.map +1 -1
- package/dist/pages/dashboard/sections.js +4 -2
- package/dist/pages/dashboard/sections.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +1 -1
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
- package/dist/pages/forms/FieldsEditor.js +6 -7
- package/dist/pages/forms/FieldsEditor.js.map +1 -1
- package/dist/pages/forms/FormActions.d.ts.map +1 -1
- package/dist/pages/forms/FormActions.js +4 -11
- package/dist/pages/forms/FormActions.js.map +1 -1
- package/dist/pages/forms/FormEmails.d.ts.map +1 -1
- package/dist/pages/forms/FormEmails.js +6 -1
- package/dist/pages/forms/FormEmails.js.map +1 -1
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +6 -2
- 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 +26 -6
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +81 -6
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/fieldList.d.ts +13 -5
- package/dist/pages/forms/fieldList.d.ts.map +1 -1
- package/dist/pages/forms/fieldList.js +12 -4
- package/dist/pages/forms/fieldList.js.map +1 -1
- package/dist/pages/oauth/ConsentPage.d.ts.map +1 -1
- package/dist/pages/oauth/ConsentPage.js +132 -15
- package/dist/pages/oauth/ConsentPage.js.map +1 -1
- package/dist/registry/contributions.d.ts +1 -1
- package/package.json +3 -3
- package/src/api/resource.ts +16 -0
- package/src/api/resources/decisions.ts +81 -1
- package/src/api/resources/forms.ts +68 -7
- package/src/api/resources/oauth.ts +15 -1
- package/src/api/resources/personIntake.ts +54 -13
- package/src/api/resources/session.ts +4 -0
- package/src/api/resources/tags.ts +71 -0
- package/src/app/KelpieApp.tsx +4 -2
- package/src/components/AddRecordPanel.tsx +143 -0
- package/src/components/AiDrawer.tsx +34 -7
- package/src/components/ApiKeysPanel.tsx +193 -75
- package/src/components/Chip.tsx +32 -1
- package/src/components/CustomFieldsPanel.tsx +15 -5
- package/src/components/DecisionProvenance.tsx +95 -0
- package/src/components/DecisionsPanel.tsx +30 -2
- package/src/components/MarkdownView.tsx +45 -11
- package/src/components/NotesPanel.tsx +15 -6
- package/src/components/OriginLabel.tsx +26 -0
- package/src/components/Shell.tsx +30 -6
- package/src/components/TagInput.tsx +285 -0
- package/src/components/aiDrawerState.ts +12 -0
- package/src/components/personIntakeTask.tsx +48 -0
- package/src/lib/personIntakeRunStorage.ts +97 -0
- package/src/modules/PersonIntakeWizard.tsx +391 -30
- package/src/modules/ai.tsx +1 -1
- package/src/pages/CompaniesPage.tsx +22 -5
- package/src/pages/CompanyDetail.tsx +6 -17
- package/src/pages/DealDetail.tsx +6 -17
- package/src/pages/DealsPage.tsx +25 -8
- package/src/pages/DecisionsPage.tsx +28 -1
- package/src/pages/EnquiriesPage.tsx +23 -5
- package/src/pages/EnquiryDetail.tsx +6 -18
- package/src/pages/EventDetail.tsx +6 -18
- package/src/pages/FundraisingPage.tsx +25 -11
- package/src/pages/OpportunitiesPage.tsx +23 -5
- package/src/pages/OpportunityDetail.tsx +6 -18
- package/src/pages/PartnershipDetail.tsx +6 -18
- package/src/pages/PartnershipsPage.tsx +25 -11
- package/src/pages/PeoplePage.tsx +22 -7
- package/src/pages/PersonDetail.tsx +11 -21
- package/src/pages/RaiseDetail.tsx +6 -18
- package/src/pages/SearchPage.tsx +3 -0
- package/src/pages/account/ConnectedAppsPage.tsx +97 -14
- package/src/pages/admin/{McpPanel.tsx → AgentsPanel.tsx} +11 -168
- package/src/pages/admin/AiAdminPage.tsx +16 -11
- package/src/pages/admin/AiPage.tsx +1 -1
- package/src/pages/admin/TeamPage.tsx +33 -0
- package/src/pages/ai/AiAccessPage.tsx +23 -0
- package/src/pages/ai/McpPanel.tsx +261 -0
- package/src/pages/auth/nextPath.ts +18 -1
- package/src/pages/dashboard/sections.tsx +4 -0
- package/src/pages/forms/EmbedPanel.tsx +3 -2
- package/src/pages/forms/FieldsEditor.tsx +6 -7
- package/src/pages/forms/FormActions.tsx +18 -20
- package/src/pages/forms/FormEmails.tsx +11 -2
- package/src/pages/forms/FormSettings.tsx +5 -0
- package/src/pages/forms/SubmissionDetail.tsx +47 -9
- package/src/pages/forms/SubmissionsTable.tsx +180 -5
- package/src/pages/forms/fieldList.ts +21 -7
- package/src/pages/oauth/ConsentPage.tsx +271 -33
- package/src/registry/contributions.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kelpie/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "React UI for Kelpie: components, pages, API client, and the extension registry an assembly composes modules through.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kelpie",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@dnd-kit/core": "^6.3.1",
|
|
49
49
|
"@dnd-kit/sortable": "^10.0.0",
|
|
50
50
|
"@dnd-kit/utilities": "^3.2.2",
|
|
51
|
-
"@kelpie/schemas": "^0.
|
|
51
|
+
"@kelpie/schemas": "^0.23.0",
|
|
52
52
|
"@tanstack/react-query": "^5.101.4",
|
|
53
53
|
"react-markdown": "^10.1.0",
|
|
54
54
|
"react-router": "^8.3.0",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"react-dom": "^19.2.8",
|
|
70
70
|
"tailwindcss": "^4.3.3",
|
|
71
71
|
"vite": "^8.2.0",
|
|
72
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^5.0.3"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/api/resource.ts
CHANGED
|
@@ -195,6 +195,22 @@ function writeRecordEverywhere<TRecord extends { readonly id: string }>(
|
|
|
195
195
|
)
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Puts a record the server just answered with into every cache of its
|
|
200
|
+
* resource, by the resource's name.
|
|
201
|
+
*
|
|
202
|
+
* For a write that is not one of the five verbs: an action route that answers
|
|
203
|
+
* with the whole record. Without it the row shows its old state until the
|
|
204
|
+
* refetch lands.
|
|
205
|
+
*/
|
|
206
|
+
export function cacheRecord<TRecord extends { readonly id: string }>(
|
|
207
|
+
queryClient: QueryClient,
|
|
208
|
+
name: string,
|
|
209
|
+
record: TRecord,
|
|
210
|
+
): void {
|
|
211
|
+
writeRecordEverywhere(queryClient, keysFor(name), record)
|
|
212
|
+
}
|
|
213
|
+
|
|
198
214
|
function removeRecordEverywhere<TRecord extends { readonly id: string }>(
|
|
199
215
|
queryClient: QueryClient,
|
|
200
216
|
keys: ResourceKeys,
|
|
@@ -6,8 +6,13 @@ import type {
|
|
|
6
6
|
RecordTargetType,
|
|
7
7
|
} from '@kelpie/schemas'
|
|
8
8
|
|
|
9
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
10
|
+
import { useState } from 'react'
|
|
11
|
+
|
|
9
12
|
import type { QueryParameters } from '../client.ts'
|
|
10
|
-
import {
|
|
13
|
+
import { useApiClient } from '../context.ts'
|
|
14
|
+
import { toError } from '../errors.ts'
|
|
15
|
+
import { cacheRecord, createResourceHooks } from '../resource.ts'
|
|
11
16
|
import type { MutationResult, RecordListResult, UpdateArguments } from '../resource.ts'
|
|
12
17
|
|
|
13
18
|
/**
|
|
@@ -61,3 +66,78 @@ export function useUpdateDecision(): MutationResult<UpdateArguments<DecisionInpu
|
|
|
61
66
|
export function useDeleteDecision(): MutationResult<string, void> {
|
|
62
67
|
return decisions.useRemove()
|
|
63
68
|
}
|
|
69
|
+
|
|
70
|
+
/** The proposal to confirm, as the member read it. */
|
|
71
|
+
export interface ConfirmDecisionArguments {
|
|
72
|
+
readonly id: string
|
|
73
|
+
/**
|
|
74
|
+
* The `updatedAt` of the Decision on screen. The server refuses with `409`
|
|
75
|
+
* when the Decision was edited after it, so the member confirms the text
|
|
76
|
+
* they read and not one an agent put there before the click.
|
|
77
|
+
*/
|
|
78
|
+
readonly updatedAt: Date
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ConfirmDecisionResult extends MutationResult<ConfirmDecisionArguments, Decision> {
|
|
82
|
+
/**
|
|
83
|
+
* Every Decision a confirm is in flight for, so each row shows its own
|
|
84
|
+
* state. A set and not one id: a member can click a second row before the
|
|
85
|
+
* first answer is back, and both are then still in flight.
|
|
86
|
+
*/
|
|
87
|
+
readonly pendingIds: ReadonlySet<string>
|
|
88
|
+
/** How many confirms have succeeded on this page, for a status line a screen reader hears. */
|
|
89
|
+
readonly confirmedCount: number
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Confirms a proposal.
|
|
94
|
+
*
|
|
95
|
+
* Not optimistic: until the server answers, the Decision is still a proposal,
|
|
96
|
+
* and a page that showed it as a commitment for a moment would say the one
|
|
97
|
+
* thing this field exists to keep true. The answer is written into the caches
|
|
98
|
+
* at once, so the row does not stay "not confirmed" while the lists refetch.
|
|
99
|
+
* The dashboard lists recent decisions with the same label, so it goes stale
|
|
100
|
+
* too. A refusal refetches the lists: the usual cause is that the text changed.
|
|
101
|
+
*/
|
|
102
|
+
export function useConfirmDecision(): ConfirmDecisionResult {
|
|
103
|
+
const client = useApiClient()
|
|
104
|
+
const queryClient = useQueryClient()
|
|
105
|
+
const [pendingIds, setPendingIds] = useState<ReadonlySet<string>>(new Set())
|
|
106
|
+
const [confirmedCount, setConfirmedCount] = useState(0)
|
|
107
|
+
const mutation = useMutation({
|
|
108
|
+
mutationFn: ({ id, updatedAt }: ConfirmDecisionArguments) =>
|
|
109
|
+
client.post(
|
|
110
|
+
`/decisions/${id}/confirm`,
|
|
111
|
+
{ updated_at: updatedAt.toISOString() },
|
|
112
|
+
decisionSchema.parse,
|
|
113
|
+
),
|
|
114
|
+
// The mutation's own state follows only the newest call. These two run
|
|
115
|
+
// for every call, so the set holds each id until its own answer is back.
|
|
116
|
+
onMutate: ({ id }) => {
|
|
117
|
+
setPendingIds((current) => new Set(current).add(id))
|
|
118
|
+
},
|
|
119
|
+
onSettled: (_decision, _error, { id }) => {
|
|
120
|
+
setPendingIds((current) => new Set([...current].filter((pending) => pending !== id)))
|
|
121
|
+
},
|
|
122
|
+
onSuccess: (decision) => {
|
|
123
|
+
setConfirmedCount((count) => count + 1)
|
|
124
|
+
cacheRecord(queryClient, 'decisions', decision)
|
|
125
|
+
void queryClient.invalidateQueries({ queryKey: ['decisions'] })
|
|
126
|
+
void queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
|
127
|
+
},
|
|
128
|
+
onError: () => {
|
|
129
|
+
void queryClient.invalidateQueries({ queryKey: ['decisions'] })
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
run: (input) => {
|
|
135
|
+
mutation.mutate(input)
|
|
136
|
+
},
|
|
137
|
+
runAsync: (input) => mutation.mutateAsync(input),
|
|
138
|
+
isPending: pendingIds.size > 0,
|
|
139
|
+
pendingIds,
|
|
140
|
+
confirmedCount,
|
|
141
|
+
error: toError(mutation.error),
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createFormBody,
|
|
3
|
+
formBody,
|
|
4
|
+
formSchema,
|
|
5
|
+
formSubmissionSchema,
|
|
6
|
+
formSubmissionsDeletedSchema,
|
|
7
|
+
} from '@kelpie/schemas'
|
|
2
8
|
import type {
|
|
3
9
|
CreateFormInput,
|
|
4
10
|
Form,
|
|
@@ -6,6 +12,7 @@ import type {
|
|
|
6
12
|
FormInput,
|
|
7
13
|
FormSubmission,
|
|
8
14
|
FormSubmissionLinkTarget,
|
|
15
|
+
FormSubmissionsDeleted,
|
|
9
16
|
FormSubmissionStatus,
|
|
10
17
|
} from '@kelpie/schemas'
|
|
11
18
|
import {
|
|
@@ -32,8 +39,8 @@ import type {
|
|
|
32
39
|
*
|
|
33
40
|
* A form carries its fields, so there is no separate field resource and no
|
|
34
41
|
* per-field write. The whole list goes back on every save, which is what a drag
|
|
35
|
-
* reorder sends as well
|
|
36
|
-
*
|
|
42
|
+
* reorder sends as well. Each saved field goes with its id and keeps it; the
|
|
43
|
+
* server treats a list identical to the stored one as no write at all.
|
|
37
44
|
*
|
|
38
45
|
* A submit writes People, Companies, Positions and Deals, so those lists go
|
|
39
46
|
* stale whenever a form changes — not because editing a form touches them, but
|
|
@@ -44,10 +51,10 @@ import type {
|
|
|
44
51
|
* Everything about a form except its fields.
|
|
45
52
|
*
|
|
46
53
|
* The field list is excluded because the shared update hook merges the request
|
|
47
|
-
* into the cached record optimistically, and a request carries *drafts*: no
|
|
48
|
-
* no
|
|
49
|
-
*
|
|
50
|
-
* addresses fields by id. `useUpdateFormFields` handles that half.
|
|
54
|
+
* into the cached record optimistically, and a request carries *drafts*: no
|
|
55
|
+
* positions, and no id for a field just added, both assigned server-side.
|
|
56
|
+
* Merging those in would put a field with no id on screen for as long as the
|
|
57
|
+
* PATCH takes, and the builder addresses fields by id. `useUpdateFormFields` handles that half.
|
|
51
58
|
*/
|
|
52
59
|
export type FormSettingsInput = Omit<FormInput, 'fields'>
|
|
53
60
|
|
|
@@ -267,6 +274,60 @@ export function useReleaseFormSubmission(): MutationResult<
|
|
|
267
274
|
}
|
|
268
275
|
}
|
|
269
276
|
|
|
277
|
+
export interface DeleteSubmissionsArguments {
|
|
278
|
+
readonly formId: string
|
|
279
|
+
readonly submissionIds: readonly string[]
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Deletes one or more of a form's submissions, with
|
|
284
|
+
* `POST /v1/forms/:id/submissions/delete`. One route for one row and for many,
|
|
285
|
+
* so the table and the detail page share a hook.
|
|
286
|
+
*
|
|
287
|
+
* Not optimistic: a submission list is paged, and a page with rows taken out
|
|
288
|
+
* would show a short page until the refetch. The records a submission linked
|
|
289
|
+
* stay, so only the submission lists go stale, the per-record ones included.
|
|
290
|
+
*/
|
|
291
|
+
export function useDeleteFormSubmissions(): MutationResult<
|
|
292
|
+
DeleteSubmissionsArguments,
|
|
293
|
+
FormSubmissionsDeleted
|
|
294
|
+
> {
|
|
295
|
+
const client = useApiClient()
|
|
296
|
+
const queryClient = useQueryClient()
|
|
297
|
+
const mutation = useMutation({
|
|
298
|
+
mutationFn: ({ formId, submissionIds }: DeleteSubmissionsArguments) =>
|
|
299
|
+
client.post(
|
|
300
|
+
`/forms/${formId}/submissions/delete`,
|
|
301
|
+
{ ids: submissionIds },
|
|
302
|
+
formSubmissionsDeletedSchema.parse,
|
|
303
|
+
),
|
|
304
|
+
onSuccess: ({ deletedIds }, { formId }) => {
|
|
305
|
+
// A deleted submission's own read is dropped, not refetched: a refetch
|
|
306
|
+
// answers 404, and the detail page would show "not found" before it
|
|
307
|
+
// navigates away.
|
|
308
|
+
const gone = new Set(deletedIds)
|
|
309
|
+
|
|
310
|
+
for (const id of deletedIds) {
|
|
311
|
+
queryClient.removeQueries({ queryKey: ['forms', 'submissions', formId, id], exact: true })
|
|
312
|
+
}
|
|
313
|
+
void queryClient.invalidateQueries({
|
|
314
|
+
queryKey: ['forms', 'submissions', formId],
|
|
315
|
+
predicate: (query) => !gone.has(String(query.queryKey[3])),
|
|
316
|
+
})
|
|
317
|
+
void queryClient.invalidateQueries({ queryKey: ['form-submissions'] })
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
run: (input) => {
|
|
323
|
+
mutation.mutate(input)
|
|
324
|
+
},
|
|
325
|
+
runAsync: (input) => mutation.mutateAsync(input),
|
|
326
|
+
isPending: mutation.isPending,
|
|
327
|
+
error: toError(mutation.error),
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
270
331
|
/**
|
|
271
332
|
* Submissions that touched one record, newest first.
|
|
272
333
|
*
|
|
@@ -16,7 +16,7 @@ import { asMutationResult } from './mutation.ts'
|
|
|
16
16
|
* `/v1/oauth`: the consent page an MCP client sends a person to, and the
|
|
17
17
|
* "Connected apps" list. Session only; the server refuses a bearer credential.
|
|
18
18
|
*
|
|
19
|
-
* Not workspace-scoped. A request asks which
|
|
19
|
+
* Not workspace-scoped. A request asks which workspaces to connect, and the
|
|
20
20
|
* list covers every workspace the person belongs to.
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -110,3 +110,17 @@ export function useRevokeOAuthGrant(): MutationResult<string, void> {
|
|
|
110
110
|
|
|
111
111
|
return asMutationResult(mutation)
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
/** Ends a whole connection: every workspace that was approved together. */
|
|
115
|
+
export function useRevokeOAuthConnection(): MutationResult<string, void> {
|
|
116
|
+
const client = useApiClient()
|
|
117
|
+
const queryClient = useQueryClient()
|
|
118
|
+
const mutation = useMutation({
|
|
119
|
+
mutationFn: (id: string) => client.delete(`/oauth/connections/${id}`),
|
|
120
|
+
onSuccess: async () => {
|
|
121
|
+
await queryClient.invalidateQueries({ queryKey: GRANTS_KEY })
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return asMutationResult(mutation)
|
|
126
|
+
}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
personIntakeApplyResultSchema,
|
|
3
3
|
personIntakeCandidateBody,
|
|
4
|
-
personIntakeIdentifyResultSchema,
|
|
5
4
|
personIntakeItemBody,
|
|
6
|
-
|
|
5
|
+
personIntakeRunSchema,
|
|
6
|
+
personIntakeRunStartedSchema,
|
|
7
7
|
} from '@kelpie/schemas'
|
|
8
8
|
import type {
|
|
9
9
|
PersonIntakeApplyResult,
|
|
10
10
|
PersonIntakeCandidate,
|
|
11
|
-
PersonIntakeIdentifyResult,
|
|
12
11
|
PersonIntakeItem,
|
|
13
|
-
|
|
12
|
+
PersonIntakeRun,
|
|
13
|
+
PersonIntakeRunStarted,
|
|
14
14
|
} from '@kelpie/schemas'
|
|
15
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
15
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
16
16
|
|
|
17
|
+
import { ApiError } from '../client.ts'
|
|
17
18
|
import { useApiClient } from '../context.ts'
|
|
19
|
+
import { toError } from '../errors.ts'
|
|
18
20
|
import type { MutationResult } from '../resource.ts'
|
|
19
21
|
import { asMutationResult } from './mutation.ts'
|
|
20
22
|
|
|
@@ -22,21 +24,25 @@ import { asMutationResult } from './mutation.ts'
|
|
|
22
24
|
* `/v1/ai/person-intake/*`, from the optional `ai` module. Only the module's
|
|
23
25
|
* wizard calls these, and only an assembly that lists the module serves them.
|
|
24
26
|
*
|
|
25
|
-
* `identify` and `research`
|
|
26
|
-
*
|
|
27
|
-
*
|
|
27
|
+
* `identify` and `research` start an AI run on the server's job queue and
|
|
28
|
+
* answer its id at once. The wizard then reads the run every 2 seconds until
|
|
29
|
+
* it settles (`usePersonIntakeRun`). Each run shows in the run log, so
|
|
30
|
+
* starting one refreshes it. `apply` can touch every record type the wizard
|
|
31
|
+
* offers, so it refreshes all of them.
|
|
28
32
|
*/
|
|
29
33
|
|
|
30
34
|
const RUN_LOG_KEY = ['ai_runs'] as const
|
|
31
35
|
|
|
32
36
|
const WRITTEN_RESOURCES = ['people', 'companies', 'positions', 'notes', 'partnerships', 'deals', 'enquiries'] as const
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
/** How often the wizard reads a run that has not settled. */
|
|
39
|
+
export const PERSON_INTAKE_POLL_INTERVAL_MS = 2000
|
|
40
|
+
|
|
41
|
+
export function useStartIdentify(): MutationResult<string, PersonIntakeRunStarted> {
|
|
35
42
|
const client = useApiClient()
|
|
36
43
|
const cache = useQueryClient()
|
|
37
44
|
const mutation = useMutation({
|
|
38
|
-
mutationFn: (text: string) =>
|
|
39
|
-
client.post('/ai/person-intake/identify', { text }, personIntakeIdentifyResultSchema.parse),
|
|
45
|
+
mutationFn: (text: string) => client.post('/ai/person-intake/identify', { text }, personIntakeRunStartedSchema.parse),
|
|
40
46
|
onSettled: () => {
|
|
41
47
|
void cache.invalidateQueries({ queryKey: RUN_LOG_KEY })
|
|
42
48
|
},
|
|
@@ -52,7 +58,7 @@ export interface ResearchPersonInput {
|
|
|
52
58
|
readonly existingPersonId: string | null
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
export function
|
|
61
|
+
export function useStartResearch(): MutationResult<ResearchPersonInput, PersonIntakeRunStarted> {
|
|
56
62
|
const client = useApiClient()
|
|
57
63
|
const cache = useQueryClient()
|
|
58
64
|
const mutation = useMutation({
|
|
@@ -64,7 +70,7 @@ export function useResearchPerson(): MutationResult<ResearchPersonInput, PersonI
|
|
|
64
70
|
candidate: personIntakeCandidateBody(input.candidate),
|
|
65
71
|
existing_person_id: input.existingPersonId,
|
|
66
72
|
},
|
|
67
|
-
|
|
73
|
+
personIntakeRunStartedSchema.parse,
|
|
68
74
|
),
|
|
69
75
|
onSettled: () => {
|
|
70
76
|
void cache.invalidateQueries({ queryKey: RUN_LOG_KEY })
|
|
@@ -74,6 +80,41 @@ export function useResearchPerson(): MutationResult<ResearchPersonInput, PersonI
|
|
|
74
80
|
return asMutationResult(mutation)
|
|
75
81
|
}
|
|
76
82
|
|
|
83
|
+
export interface PersonIntakeRunResult {
|
|
84
|
+
readonly run: PersonIntakeRun | undefined
|
|
85
|
+
readonly error: Error | null
|
|
86
|
+
/** The server has no such run for this caller, or never had one. */
|
|
87
|
+
readonly isNotFound: boolean
|
|
88
|
+
/** Reads the run again now, for a read that failed. */
|
|
89
|
+
readonly refetch: () => void
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One intake run, read every 2 seconds until it settles. Nothing is read while `runId` is undefined. */
|
|
93
|
+
export function usePersonIntakeRun(runId: string | undefined): PersonIntakeRunResult {
|
|
94
|
+
const client = useApiClient()
|
|
95
|
+
const result = useQuery({
|
|
96
|
+
queryKey: ['person_intake_runs', runId ?? ''],
|
|
97
|
+
queryFn: () => client.get(`/ai/person-intake/runs/${encodeURIComponent(runId ?? '')}`, personIntakeRunSchema.parse),
|
|
98
|
+
enabled: runId !== undefined,
|
|
99
|
+
// A settled run never changes again, except that its result goes after an hour.
|
|
100
|
+
staleTime: Infinity,
|
|
101
|
+
refetchInterval: (query) => {
|
|
102
|
+
const status = query.state.data?.status
|
|
103
|
+
|
|
104
|
+
return status === 'queued' || status === 'running' ? PERSON_INTAKE_POLL_INTERVAL_MS : false
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
run: result.data,
|
|
110
|
+
error: toError(result.error),
|
|
111
|
+
isNotFound: result.error instanceof ApiError && result.error.status === 404,
|
|
112
|
+
refetch: () => {
|
|
113
|
+
void result.refetch()
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
77
118
|
export function useApplyPersonIntake(): MutationResult<readonly PersonIntakeItem[], PersonIntakeApplyResult> {
|
|
78
119
|
const client = useApiClient()
|
|
79
120
|
const cache = useQueryClient()
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
} from '@kelpie/schemas'
|
|
27
27
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
28
28
|
|
|
29
|
+
import { clearAllSavedIntakeRuns } from '../../lib/personIntakeRunStorage.ts'
|
|
29
30
|
import { ApiError } from '../client.ts'
|
|
30
31
|
import type { ApiClient } from '../client.ts'
|
|
31
32
|
import { useApiClient } from '../context.ts'
|
|
@@ -136,6 +137,9 @@ export function useLogOut(): MutationResult<void, void> {
|
|
|
136
137
|
// and the next protected route asks for the session itself.
|
|
137
138
|
onSettled: () => {
|
|
138
139
|
queryClient.clear()
|
|
140
|
+
// The person-intake wizard saves its notes in this tab. The next person
|
|
141
|
+
// to sign in here must not find them.
|
|
142
|
+
clearAllSavedIntakeRuns()
|
|
139
143
|
},
|
|
140
144
|
})
|
|
141
145
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { tagSuggestionsSchema } from '@kelpie/schemas'
|
|
2
|
+
import type { TagSuggestion, TagTargetType } from '@kelpie/schemas'
|
|
3
|
+
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { useCallback } from 'react'
|
|
5
|
+
|
|
6
|
+
import { useApiClient } from '../context.ts'
|
|
7
|
+
import { toError } from '../errors.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `/v1/tags`, read-only: the tags already in use on one record type.
|
|
11
|
+
*
|
|
12
|
+
* Not a `createResourceHooks` resource. A tag is not a record: it has no id and
|
|
13
|
+
* no write of its own, and it changes when the record carrying it is saved.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** How many suggestions a tag picker shows. */
|
|
17
|
+
const SUGGESTION_LIMIT = 20
|
|
18
|
+
|
|
19
|
+
export interface TagSuggestionsState {
|
|
20
|
+
readonly suggestions: readonly TagSuggestion[]
|
|
21
|
+
readonly isLoading: boolean
|
|
22
|
+
readonly error: Error | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param term What was typed. Empty asks for the most used tags, which is what a
|
|
27
|
+
* picker shows on focus before anyone types.
|
|
28
|
+
* @param enabled False until the picker opens, so a page of tag fields does not
|
|
29
|
+
* send a request for each one on load.
|
|
30
|
+
*/
|
|
31
|
+
export function useTagSuggestions(
|
|
32
|
+
targetType: TagTargetType,
|
|
33
|
+
term: string,
|
|
34
|
+
enabled: boolean,
|
|
35
|
+
): TagSuggestionsState {
|
|
36
|
+
const client = useApiClient()
|
|
37
|
+
const trimmed = term.trim()
|
|
38
|
+
|
|
39
|
+
const result = useQuery({
|
|
40
|
+
queryKey: ['tags', targetType, trimmed],
|
|
41
|
+
queryFn: () =>
|
|
42
|
+
client.get('/tags', tagSuggestionsSchema.parse, {
|
|
43
|
+
target_type: targetType,
|
|
44
|
+
q: trimmed.length === 0 ? undefined : trimmed,
|
|
45
|
+
limit: SUGGESTION_LIMIT,
|
|
46
|
+
}),
|
|
47
|
+
enabled,
|
|
48
|
+
// Keeps the last answer on screen while the next keystroke's request runs,
|
|
49
|
+
// so the list does not blink empty between letters.
|
|
50
|
+
placeholderData: keepPreviousData,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
suggestions: result.data?.tags ?? [],
|
|
55
|
+
isLoading: result.isPending && enabled,
|
|
56
|
+
error: toError(result.error),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Marks every tag suggestion stale. A picker calls this after it saves, so a tag
|
|
62
|
+
* created on one record is offered on the next one at once rather than after
|
|
63
|
+
* the 30-second stale time.
|
|
64
|
+
*/
|
|
65
|
+
export function useInvalidateTagSuggestions(): () => void {
|
|
66
|
+
const queryClient = useQueryClient()
|
|
67
|
+
|
|
68
|
+
return useCallback(() => {
|
|
69
|
+
void queryClient.invalidateQueries({ queryKey: ['tags'] })
|
|
70
|
+
}, [queryClient])
|
|
71
|
+
}
|
package/src/app/KelpieApp.tsx
CHANGED
|
@@ -42,6 +42,7 @@ import { PreferencesPage } from '../pages/account/PreferencesPage.tsx'
|
|
|
42
42
|
import { ProfilePage } from '../pages/account/ProfilePage.tsx'
|
|
43
43
|
import { SecurityPage } from '../pages/account/SecurityPage.tsx'
|
|
44
44
|
import { AiAdminPage } from '../pages/admin/AiAdminPage.tsx'
|
|
45
|
+
import { AiAccessPage } from '../pages/ai/AiAccessPage.tsx'
|
|
45
46
|
import { ApiKeysPage } from '../pages/admin/ApiKeysPage.tsx'
|
|
46
47
|
import { DataPage } from '../pages/admin/DataPage.tsx'
|
|
47
48
|
import { FieldsPage } from '../pages/admin/FieldsPage.tsx'
|
|
@@ -193,6 +194,7 @@ function AppRoutes(): React.JSX.Element {
|
|
|
193
194
|
{/* The optional segment is the mockup's: /handbook opens the first page. */}
|
|
194
195
|
<Route path="handbook" element={<HandbookLayout />} />
|
|
195
196
|
<Route path="handbook/:pageId" element={<HandbookLayout />} />
|
|
197
|
+
<Route path="ai" element={<AiAccessPage />} />
|
|
196
198
|
<Route path="admin" element={<Navigate to="/admin/workspace" replace />} />
|
|
197
199
|
<Route path="admin/workspace" element={<WorkspaceSettingsPage />} />
|
|
198
200
|
<Route path="admin/team" element={<TeamPage />} />
|
|
@@ -201,8 +203,8 @@ function AppRoutes(): React.JSX.Element {
|
|
|
201
203
|
<Route path="admin/data" element={<DataPage />} />
|
|
202
204
|
<Route path="admin/api-keys" element={<ApiKeysPage />} />
|
|
203
205
|
<Route path="admin/ai" element={<AiAdminPage />} />
|
|
204
|
-
{/* MCP moved
|
|
205
|
-
<Route path="admin/mcp" element={<Navigate to="/
|
|
206
|
+
{/* MCP moved out of Admin: every member can open the AI page. */}
|
|
207
|
+
<Route path="admin/mcp" element={<Navigate to="/ai" replace />} />
|
|
206
208
|
<Route path="admin/webhooks" element={<WebhooksPage />} />
|
|
207
209
|
<Route path="admin/modules" element={<ModulesPage />} />
|
|
208
210
|
{/* The mockup's own shape: /account opens the first tab. */}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useCompanies } from '../api/resources/companies.ts'
|
|
4
|
+
import { EntitySearch } from './EntitySearch.tsx'
|
|
5
|
+
import type { SearchOption } from './EntitySearch.tsx'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Asks for a record's name before the record exists.
|
|
9
|
+
*
|
|
10
|
+
* A list page's Add button opens this instead of creating a record with a
|
|
11
|
+
* placeholder name. The created event then carries the real name, which is what
|
|
12
|
+
* a webhook, an agent task or a notification reads. Nothing is saved when the
|
|
13
|
+
* reader cancels.
|
|
14
|
+
*
|
|
15
|
+
* `company` adds a required company picker, for the records that belong to one
|
|
16
|
+
* (deals, raises, partnerships).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export interface AddRecordValues {
|
|
20
|
+
readonly name: string
|
|
21
|
+
/** Set only when the panel was given `company`. */
|
|
22
|
+
readonly companyId?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AddRecordCompanyPicker {
|
|
26
|
+
readonly options: readonly SearchOption[]
|
|
27
|
+
/** Set to search on the server as the reader types. */
|
|
28
|
+
readonly onQueryChange?: (query: string) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AddRecordPanelProps {
|
|
32
|
+
/** The heading and the submit label, e.g. "Add person". */
|
|
33
|
+
readonly title: string
|
|
34
|
+
readonly namePlaceholder?: string
|
|
35
|
+
readonly company?: AddRecordCompanyPicker
|
|
36
|
+
readonly isPending: boolean
|
|
37
|
+
readonly onCancel: () => void
|
|
38
|
+
readonly onCreate: (values: AddRecordValues) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function AddRecordPanel({
|
|
42
|
+
title,
|
|
43
|
+
namePlaceholder,
|
|
44
|
+
company,
|
|
45
|
+
isPending,
|
|
46
|
+
onCancel,
|
|
47
|
+
onCreate,
|
|
48
|
+
}: AddRecordPanelProps): React.JSX.Element {
|
|
49
|
+
const [name, setName] = useState('')
|
|
50
|
+
const [companyId, setCompanyId] = useState('')
|
|
51
|
+
const trimmed = name.trim()
|
|
52
|
+
const ready = trimmed.length > 0 && (company === undefined || companyId.length > 0)
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<form
|
|
56
|
+
aria-label={title}
|
|
57
|
+
className="mb-3 max-w-md rounded-md border border-border bg-surface-raised p-4"
|
|
58
|
+
onSubmit={(event) => {
|
|
59
|
+
event.preventDefault()
|
|
60
|
+
|
|
61
|
+
if (!ready || isPending) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onCreate(company === undefined ? { name: trimmed } : { name: trimmed, companyId })
|
|
66
|
+
}}
|
|
67
|
+
onKeyDown={(event) => {
|
|
68
|
+
if (event.key === 'Escape' && !isPending) {
|
|
69
|
+
onCancel()
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<p className="text-[13px] font-semibold text-ink">{title}</p>
|
|
74
|
+
|
|
75
|
+
<div className="mt-3 space-y-3">
|
|
76
|
+
<label className="block text-[12px] font-medium text-ink-muted">
|
|
77
|
+
Name
|
|
78
|
+
<input
|
|
79
|
+
// The reader pressed Add to type a name, so the caret starts here.
|
|
80
|
+
autoFocus
|
|
81
|
+
value={name}
|
|
82
|
+
onChange={(event) => {
|
|
83
|
+
setName(event.target.value)
|
|
84
|
+
}}
|
|
85
|
+
placeholder={namePlaceholder}
|
|
86
|
+
className="mt-1 block w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-[13px] text-ink"
|
|
87
|
+
/>
|
|
88
|
+
</label>
|
|
89
|
+
|
|
90
|
+
{company !== undefined && (
|
|
91
|
+
<div className="text-[12px] font-medium text-ink-muted">
|
|
92
|
+
Company
|
|
93
|
+
<div className="mt-1">
|
|
94
|
+
<EntitySearch
|
|
95
|
+
options={company.options}
|
|
96
|
+
value={companyId}
|
|
97
|
+
onChange={setCompanyId}
|
|
98
|
+
onQueryChange={company.onQueryChange}
|
|
99
|
+
placeholder="Search companies…"
|
|
100
|
+
emptyMessage="No company matches"
|
|
101
|
+
size="sm"
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
)}
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div className="mt-4 flex justify-end gap-2">
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
onClick={onCancel}
|
|
112
|
+
disabled={isPending}
|
|
113
|
+
className="rounded-md px-2.5 py-1 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50"
|
|
114
|
+
>
|
|
115
|
+
Cancel
|
|
116
|
+
</button>
|
|
117
|
+
<button
|
|
118
|
+
type="submit"
|
|
119
|
+
disabled={isPending || !ready}
|
|
120
|
+
className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
121
|
+
>
|
|
122
|
+
{isPending ? 'Adding…' : title}
|
|
123
|
+
</button>
|
|
124
|
+
</div>
|
|
125
|
+
</form>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** `AddRecordPanel` with the company picker searching the workspace's companies. */
|
|
130
|
+
export function AddCompanyRecordPanel(props: Omit<AddRecordPanelProps, 'company'>): React.JSX.Element {
|
|
131
|
+
const [search, setSearch] = useState('')
|
|
132
|
+
const companies = useCompanies({ term: search.trim().length > 0 ? search.trim() : undefined })
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<AddRecordPanel
|
|
136
|
+
{...props}
|
|
137
|
+
company={{
|
|
138
|
+
options: companies.records.map((company) => ({ id: company.id, label: company.name })),
|
|
139
|
+
onQueryChange: setSearch,
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
)
|
|
143
|
+
}
|