@odla-ai/crm 0.1.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.
@@ -0,0 +1,775 @@
1
+ // src/ui/hooks.ts
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ function useCrmQuery(client, type, initial) {
4
+ const first = useRef(initial);
5
+ const [params, setParams] = useState({ type, offset: 0, ...first.current });
6
+ const [page, setPage] = useState(null);
7
+ const [loading, setLoading] = useState(true);
8
+ const [error, setError] = useState(null);
9
+ const [tick, setTick] = useState(0);
10
+ const seq = useRef(0);
11
+ useEffect(() => {
12
+ setParams({ type, offset: 0, ...first.current });
13
+ }, [type]);
14
+ useEffect(() => {
15
+ const mine = ++seq.current;
16
+ setLoading(true);
17
+ client.listRecords(params).then(
18
+ (result) => {
19
+ if (seq.current !== mine) return;
20
+ setPage(result);
21
+ setError(null);
22
+ setLoading(false);
23
+ },
24
+ (failure) => {
25
+ if (seq.current !== mine) return;
26
+ setError(failure instanceof Error ? failure.message : String(failure));
27
+ setLoading(false);
28
+ }
29
+ );
30
+ }, [client, params, tick]);
31
+ const update = useCallback((patch) => {
32
+ setParams((prev) => ({ ...prev, ...patch, offset: 0 }));
33
+ }, []);
34
+ const setOffset = useCallback((offset) => {
35
+ setParams((prev) => ({ ...prev, offset }));
36
+ }, []);
37
+ const setSort = useCallback((sort) => update({ sort }), [update]);
38
+ const setSearch = useCallback((search) => update({ search }), [update]);
39
+ const refresh = useCallback(() => setTick((t) => t + 1), []);
40
+ return useMemo(
41
+ () => ({ params, page, loading, error, update, setOffset, setSort, setSearch, refresh }),
42
+ [params, page, loading, error, update, setOffset, setSort, setSearch, refresh]
43
+ );
44
+ }
45
+ function useCrmRecord(client, id) {
46
+ const [detail, setDetail] = useState(null);
47
+ const [loading, setLoading] = useState(Boolean(id));
48
+ const [error, setError] = useState(null);
49
+ const [tick, setTick] = useState(0);
50
+ const seq = useRef(0);
51
+ useEffect(() => {
52
+ const mine = ++seq.current;
53
+ if (!id) {
54
+ setDetail(null);
55
+ setLoading(false);
56
+ setError(null);
57
+ return;
58
+ }
59
+ setLoading(true);
60
+ client.getRecord(id).then(
61
+ (result) => {
62
+ if (seq.current !== mine) return;
63
+ setDetail(result);
64
+ setError(null);
65
+ setLoading(false);
66
+ },
67
+ (failure) => {
68
+ if (seq.current !== mine) return;
69
+ setError(failure instanceof Error ? failure.message : String(failure));
70
+ setLoading(false);
71
+ }
72
+ );
73
+ }, [client, id, tick]);
74
+ const refresh = useCallback(() => setTick((t) => t + 1), []);
75
+ return useMemo(() => ({ detail, loading, error, refresh }), [detail, loading, error, refresh]);
76
+ }
77
+
78
+ // src/constants.ts
79
+ var CRM_SLOTS = ["s1", "s2", "s3", "s4", "n1", "n2", "n3", "d1", "d2"];
80
+ var SORTABLE_COLUMNS = [
81
+ "name",
82
+ "primaryEmail",
83
+ "stageIndex",
84
+ "stageChangedAt",
85
+ "rank",
86
+ "score",
87
+ "emailStatus",
88
+ "billingStatus",
89
+ "renewalAt",
90
+ "createdAt",
91
+ "updatedAt"
92
+ ];
93
+ var RESERVED_FIELDS = /* @__PURE__ */ new Set([
94
+ "id",
95
+ "type",
96
+ "primaryEmail",
97
+ "stage",
98
+ "stageIndex",
99
+ "stageChangedAt",
100
+ "rank",
101
+ "score",
102
+ "ownerId",
103
+ "emailStatus",
104
+ "clerkUserId",
105
+ "stripeCustomerId",
106
+ "subscriptionId",
107
+ "billingStatus",
108
+ "renewalAt",
109
+ "mrr",
110
+ "fields",
111
+ "searchText",
112
+ "archived",
113
+ "createdAt",
114
+ "updatedAt",
115
+ "archivedAt",
116
+ ...CRM_SLOTS
117
+ ]);
118
+
119
+ // src/ui/columns.tsx
120
+ var dateText = (value) => typeof value === "number" ? new Date(value).toISOString().slice(0, 10) : "\u2014";
121
+ var PROMOTED = {
122
+ name: { header: "Name", cell: (r) => r.name },
123
+ primaryEmail: { header: "Email", cell: (r) => r.primaryEmail ?? "\u2014" },
124
+ stage: { header: "Stage", cell: (r) => r.stage ?? "\u2014" },
125
+ emailStatus: { header: "Contactable", cell: (r) => r.emailStatus ?? "\u2014" },
126
+ billingStatus: { header: "Billing", cell: (r) => r.billingStatus ?? "\u2014" },
127
+ renewalAt: { header: "Renews", cell: (r) => dateText(r.renewalAt) },
128
+ score: { header: "Score", cell: (r) => r.score != null ? String(r.score) : "\u2014" },
129
+ rank: { header: "Rank", cell: (r) => r.rank != null ? String(r.rank) : "\u2014" },
130
+ createdAt: { header: "Created", cell: (r) => dateText(r.createdAt) },
131
+ updatedAt: { header: "Updated", cell: (r) => dateText(r.updatedAt) }
132
+ };
133
+ var SORT_ALIAS = { stage: "stageIndex" };
134
+ function fieldCell(field, name) {
135
+ return (record) => {
136
+ const value = record.fields[name];
137
+ if (value == null || value === "") return "\u2014";
138
+ if (field.type === "date") return dateText(value);
139
+ if (field.type === "boolean") return value ? "yes" : "no";
140
+ if (field.type === "json") return JSON.stringify(value);
141
+ return String(value);
142
+ };
143
+ }
144
+ var fieldSortAs = (field) => {
145
+ if (!field.slot) return void 0;
146
+ if (field.type === "number") return "number";
147
+ if (field.type === "date") return "date";
148
+ return "string";
149
+ };
150
+ function sortFieldFor(crm, type, key) {
151
+ if (SORT_ALIAS[key]) return SORT_ALIAS[key];
152
+ if (SORTABLE_COLUMNS.includes(key)) return key;
153
+ return crm.type(type).fields[key]?.slot ? key : null;
154
+ }
155
+ function columnsFor(crm, type, keys) {
156
+ const def = crm.type(type);
157
+ const columns = [];
158
+ for (const key of keys) {
159
+ const promoted = PROMOTED[key];
160
+ if (promoted) {
161
+ const sortable = sortFieldFor(crm, type, key) != null;
162
+ columns.push({
163
+ key,
164
+ header: promoted.header,
165
+ cell: promoted.cell,
166
+ ...sortable ? { sortAs: key === "name" || key === "primaryEmail" ? "string" : "number" } : {}
167
+ });
168
+ continue;
169
+ }
170
+ const field = def.fields[key];
171
+ if (!field) continue;
172
+ const sortAs = fieldSortAs(field);
173
+ columns.push({
174
+ key,
175
+ header: field.label ?? key,
176
+ cell: fieldCell(field, key),
177
+ ...sortAs ? { sortAs } : {}
178
+ });
179
+ }
180
+ return columns;
181
+ }
182
+ function defaultColumns(crm, type) {
183
+ const def = crm.type(type);
184
+ const keys = ["name"];
185
+ if (def.pipeline) keys.push("stage");
186
+ if (def.emailField) keys.push("primaryEmail", "emailStatus");
187
+ for (const [name, field] of Object.entries(def.fields)) {
188
+ if (field.slot && name !== def.emailField && name !== (def.nameField ?? "name"))
189
+ keys.push(name);
190
+ }
191
+ keys.push("updatedAt");
192
+ return keys;
193
+ }
194
+
195
+ // src/ui/crm-list.tsx
196
+ import { DataTable, FilterChips, Pagination } from "@odla-ai/ui/components";
197
+ import { jsx, jsxs } from "react/jsx-runtime";
198
+ function CrmList({
199
+ crm,
200
+ type,
201
+ query,
202
+ columns,
203
+ onOpenRecord,
204
+ selectable = false,
205
+ selected,
206
+ onSelectionChange,
207
+ toolbar
208
+ }) {
209
+ const def = crm.type(type);
210
+ const keys = columns ?? defaultColumns(crm, type);
211
+ const tableColumns = columnsFor(crm, type, keys).map(
212
+ (column) => onOpenRecord && column.key === "name" ? {
213
+ ...column,
214
+ cell: (record) => /* @__PURE__ */ jsx("button", { type: "button", className: "crm-record-open", onClick: () => onOpenRecord(record), children: record.name })
215
+ } : column
216
+ );
217
+ const limit = query.page?.limit ?? query.params.limit ?? 50;
218
+ const sort = query.params.sort ? { key: query.params.sort.field, dir: query.params.sort.dir } : null;
219
+ return /* @__PURE__ */ jsxs("div", { className: "crm-list", children: [
220
+ (def.pipeline || toolbar) && /* @__PURE__ */ jsxs("div", { className: "crm-list-toolbar", children: [
221
+ def.pipeline && /* @__PURE__ */ jsx(
222
+ FilterChips,
223
+ {
224
+ ariaLabel: "Stage",
225
+ allLabel: "All stages",
226
+ chips: def.pipeline.stages.map((stage) => ({
227
+ value: stage.id,
228
+ label: stage.label ?? stage.id
229
+ })),
230
+ value: query.params.stage ?? [],
231
+ onValueChange: (stage) => query.update({ stage })
232
+ }
233
+ ),
234
+ toolbar
235
+ ] }),
236
+ /* @__PURE__ */ jsx(
237
+ DataTable,
238
+ {
239
+ manual: true,
240
+ filterable: true,
241
+ rows: query.page?.records ?? [],
242
+ rowKey: (record) => record.id,
243
+ columns: tableColumns,
244
+ loading: query.loading && !query.page,
245
+ sort,
246
+ onSortChange: (next) => {
247
+ const field = sortFieldFor(crm, type, next.key);
248
+ if (field) query.setSort({ field, dir: next.dir });
249
+ },
250
+ filter: query.params.search ?? "",
251
+ onFilterChange: (search) => query.setSearch(search),
252
+ filterPlaceholder: "Search records\u2026",
253
+ selectable,
254
+ selected,
255
+ onSelectionChange,
256
+ emptyState: query.error ?? "No records yet",
257
+ ariaLabel: `${def.labelPlural ?? def.label} list`
258
+ }
259
+ ),
260
+ /* @__PURE__ */ jsx(
261
+ Pagination,
262
+ {
263
+ offset: query.params.offset ?? 0,
264
+ limit,
265
+ total: query.page?.total,
266
+ count: query.page?.records.length,
267
+ onOffsetChange: (offset) => query.setOffset(offset),
268
+ disabled: query.loading
269
+ }
270
+ )
271
+ ] });
272
+ }
273
+
274
+ // src/ui/crm-shell.tsx
275
+ import { AppShell, Sidebar, SidebarItem, SidebarSection } from "@odla-ai/ui/components";
276
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
277
+ function CrmShell({ crm, active, views = [], onNavigate, onOpenSettings, header, children }) {
278
+ return /* @__PURE__ */ jsx2(
279
+ AppShell,
280
+ {
281
+ header,
282
+ sidebar: /* @__PURE__ */ jsxs2(Sidebar, { "aria-label": "CRM navigation", children: [
283
+ /* @__PURE__ */ jsx2(SidebarSection, { label: "Records", children: Object.entries(crm.config.types).map(([type, def]) => /* @__PURE__ */ jsx2(
284
+ SidebarItem,
285
+ {
286
+ active: active.type === type && !active.viewId,
287
+ onClick: () => onNavigate({ type }),
288
+ children: def.labelPlural ?? def.label
289
+ },
290
+ type
291
+ )) }),
292
+ views.length > 0 && /* @__PURE__ */ jsx2(SidebarSection, { label: "Views", children: views.map((view) => /* @__PURE__ */ jsxs2(
293
+ SidebarItem,
294
+ {
295
+ active: active.viewId === view.id,
296
+ onClick: () => onNavigate({ type: view.type, viewId: view.id }),
297
+ children: [
298
+ view.name,
299
+ view.shared ? " \xB7shared" : ""
300
+ ]
301
+ },
302
+ view.id
303
+ )) }),
304
+ onOpenSettings && /* @__PURE__ */ jsx2(SidebarSection, { label: "Manage", children: /* @__PURE__ */ jsx2(SidebarItem, { onClick: onOpenSettings, children: "Settings" }) })
305
+ ] }),
306
+ children
307
+ }
308
+ );
309
+ }
310
+
311
+ // src/ui/record-panel.tsx
312
+ import { Tabs } from "@odla-ai/ui/components";
313
+
314
+ // src/ui/cards.tsx
315
+ import { Button } from "@odla-ai/ui/components";
316
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
317
+ var dateText2 = (value) => value != null ? new Date(value).toISOString().slice(0, 10) : "\u2014";
318
+ function IdentityCard({ record, onLink, linking = false }) {
319
+ return /* @__PURE__ */ jsxs3("section", { className: "crm-card", "aria-label": "Identity", children: [
320
+ /* @__PURE__ */ jsx3("h3", { className: "crm-card-title", children: "Identity" }),
321
+ record.clerkUserId ? /* @__PURE__ */ jsxs3("p", { children: [
322
+ "Linked account: ",
323
+ /* @__PURE__ */ jsx3("code", { children: record.clerkUserId })
324
+ ] }) : /* @__PURE__ */ jsxs3("p", { className: "crm-card-empty", children: [
325
+ "No linked account.",
326
+ onLink && /* @__PURE__ */ jsx3(Button, { mini: true, onClick: onLink, disabled: linking, children: "Find by email" })
327
+ ] })
328
+ ] });
329
+ }
330
+ function BillingCard({ record }) {
331
+ return /* @__PURE__ */ jsxs3("section", { className: "crm-card", "aria-label": "Billing", children: [
332
+ /* @__PURE__ */ jsx3("h3", { className: "crm-card-title", children: "Billing" }),
333
+ record.stripeCustomerId ? /* @__PURE__ */ jsxs3("dl", { className: "crm-card-facts", children: [
334
+ /* @__PURE__ */ jsx3("dt", { children: "Status" }),
335
+ /* @__PURE__ */ jsx3("dd", { children: record.billingStatus ?? "\u2014" }),
336
+ /* @__PURE__ */ jsx3("dt", { children: "Renews" }),
337
+ /* @__PURE__ */ jsx3("dd", { children: dateText2(record.renewalAt) }),
338
+ /* @__PURE__ */ jsx3("dt", { children: "Customer" }),
339
+ /* @__PURE__ */ jsx3("dd", { children: /* @__PURE__ */ jsx3("code", { children: record.stripeCustomerId }) })
340
+ ] }) : /* @__PURE__ */ jsx3("p", { className: "crm-card-empty", children: "No billing on file." })
341
+ ] });
342
+ }
343
+ function ChannelsCard({ channels }) {
344
+ return /* @__PURE__ */ jsxs3("section", { className: "crm-card", "aria-label": "Contact channels", children: [
345
+ /* @__PURE__ */ jsx3("h3", { className: "crm-card-title", children: "Contact" }),
346
+ channels.length === 0 ? /* @__PURE__ */ jsx3("p", { className: "crm-card-empty", children: "No channels." }) : /* @__PURE__ */ jsx3("ul", { className: "crm-channel-list", children: channels.map((channel) => /* @__PURE__ */ jsxs3("li", { children: [
347
+ /* @__PURE__ */ jsx3("span", { children: channel.value }),
348
+ channel.isPrimary && /* @__PURE__ */ jsx3("span", { className: "crm-badge", children: "primary" }),
349
+ /* @__PURE__ */ jsx3("span", { className: `crm-badge consent-${channel.consent}`, children: channel.consent })
350
+ ] }, channel.id)) })
351
+ ] });
352
+ }
353
+
354
+ // src/ui/fields-form.tsx
355
+ import { useState as useState2 } from "react";
356
+ import { Button as Button2, Checkbox, Field, Input, Select, Textarea } from "@odla-ai/ui/components";
357
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
358
+ var dateInput = (value) => typeof value === "number" ? new Date(value).toISOString().slice(0, 10) : "";
359
+ function initialDraft(def, record) {
360
+ const draft = {};
361
+ for (const [name, field] of Object.entries(def)) {
362
+ const value = record?.fields[name];
363
+ if (field.type === "boolean") draft[name] = value === true;
364
+ else if (field.type === "date") draft[name] = dateInput(value);
365
+ else if (field.type === "json") draft[name] = value == null ? "" : JSON.stringify(value);
366
+ else draft[name] = value == null ? "" : String(value);
367
+ }
368
+ return draft;
369
+ }
370
+ function parseDraft(field, raw) {
371
+ if (field.type === "boolean") return raw === true;
372
+ const text = String(raw).trim();
373
+ if (text === "") return null;
374
+ if (field.type === "number") return Number(text);
375
+ if (field.type === "date") return Date.parse(text);
376
+ if (field.type === "json") {
377
+ try {
378
+ return JSON.parse(text);
379
+ } catch {
380
+ return text;
381
+ }
382
+ }
383
+ return text;
384
+ }
385
+ function FieldsForm({
386
+ crm,
387
+ type,
388
+ record,
389
+ onSubmit,
390
+ submitting = false,
391
+ errors = {},
392
+ submitLabel
393
+ }) {
394
+ const fields = crm.type(type).fields;
395
+ const [draft, setDraft] = useState2(() => initialDraft(fields, record));
396
+ const set = (name, value) => setDraft((prev) => ({ ...prev, [name]: value }));
397
+ const submit = () => {
398
+ const input = {};
399
+ for (const [name, field] of Object.entries(fields)) input[name] = parseDraft(field, draft[name]);
400
+ onSubmit(input);
401
+ };
402
+ return /* @__PURE__ */ jsxs4(
403
+ "form",
404
+ {
405
+ className: "crm-fields-form",
406
+ onSubmit: (event) => {
407
+ event.preventDefault();
408
+ submit();
409
+ },
410
+ children: [
411
+ Object.entries(fields).map(([name, field]) => {
412
+ const label = field.label ?? name;
413
+ const error = errors[name];
414
+ const common = { invalid: Boolean(error) };
415
+ return /* @__PURE__ */ jsx4(Field, { label: field.type === "boolean" ? void 0 : label, error, children: field.type === "enum" ? /* @__PURE__ */ jsx4(
416
+ Select,
417
+ {
418
+ ...common,
419
+ value: String(draft[name] ?? ""),
420
+ onChange: (event) => set(name, event.currentTarget.value),
421
+ options: [
422
+ { value: "", label: "\u2014" },
423
+ ...(field.options ?? []).map((option) => ({ value: option, label: option }))
424
+ ]
425
+ }
426
+ ) : field.type === "boolean" ? /* @__PURE__ */ jsx4(
427
+ Checkbox,
428
+ {
429
+ checked: draft[name] === true,
430
+ onChange: (event) => set(name, event.currentTarget.checked),
431
+ label
432
+ }
433
+ ) : field.type === "json" ? /* @__PURE__ */ jsx4(
434
+ Textarea,
435
+ {
436
+ ...common,
437
+ value: String(draft[name] ?? ""),
438
+ rows: 3,
439
+ onChange: (event) => set(name, event.currentTarget.value)
440
+ }
441
+ ) : /* @__PURE__ */ jsx4(
442
+ Input,
443
+ {
444
+ ...common,
445
+ type: field.type === "number" ? "number" : field.type === "date" ? "date" : field.type === "email" ? "email" : field.type === "url" ? "url" : "text",
446
+ value: String(draft[name] ?? ""),
447
+ onChange: (event) => set(name, event.currentTarget.value)
448
+ }
449
+ ) }, name);
450
+ }),
451
+ /* @__PURE__ */ jsx4(Button2, { type: "submit", disabled: submitting, children: submitLabel ?? (record ? "Save" : "Create") })
452
+ ]
453
+ }
454
+ );
455
+ }
456
+
457
+ // src/ui/stage-control.tsx
458
+ import { useState as useState3 } from "react";
459
+ import { Button as Button3, Field as Field2, Select as Select2 } from "@odla-ai/ui/components";
460
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
461
+ function StageControl({ crm, record, onMove, disabled = false }) {
462
+ const pipeline = crm.type(record.type).pipeline;
463
+ const [target, setTarget] = useState3("");
464
+ const [busy, setBusy] = useState3(false);
465
+ const [error, setError] = useState3(null);
466
+ if (!pipeline) return null;
467
+ const move = async () => {
468
+ if (!target) return;
469
+ setBusy(true);
470
+ setError(null);
471
+ try {
472
+ await onMove(target);
473
+ setTarget("");
474
+ } catch (failure) {
475
+ setError(failure instanceof Error ? failure.message : String(failure));
476
+ } finally {
477
+ setBusy(false);
478
+ }
479
+ };
480
+ return /* @__PURE__ */ jsx5(Field2, { label: "Stage", error, className: "crm-stage-control", children: /* @__PURE__ */ jsxs5("div", { className: "crm-stage-row", children: [
481
+ /* @__PURE__ */ jsx5("span", { className: "crm-stage-current", children: record.stage ?? "\u2014" }),
482
+ /* @__PURE__ */ jsx5(
483
+ Select2,
484
+ {
485
+ "aria-label": "Move to stage",
486
+ value: target,
487
+ onChange: (event) => setTarget(event.currentTarget.value),
488
+ options: [
489
+ { value: "", label: "Move to\u2026" },
490
+ ...pipeline.stages.filter((stage) => stage.id !== record.stage).map((stage) => ({ value: stage.id, label: stage.label ?? stage.id }))
491
+ ]
492
+ }
493
+ ),
494
+ /* @__PURE__ */ jsx5(Button3, { mini: true, onClick: move, disabled: disabled || busy || !target, children: "Move" })
495
+ ] }) });
496
+ }
497
+
498
+ // src/ui/tag-editor.tsx
499
+ import { Combobox } from "@odla-ai/ui/components";
500
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
501
+ function TagEditor({ tags, onAdd, onRemove, suggest, disabled = false }) {
502
+ return /* @__PURE__ */ jsxs6("div", { className: "crm-tag-editor", children: [
503
+ /* @__PURE__ */ jsx6("div", { className: "chips", role: "group", "aria-label": "Tags", children: tags.map((tag) => /* @__PURE__ */ jsxs6("span", { className: "chip crm-tag-chip", children: [
504
+ tag.tag,
505
+ /* @__PURE__ */ jsx6(
506
+ "button",
507
+ {
508
+ type: "button",
509
+ className: "crm-tag-remove",
510
+ "aria-label": `Remove tag ${tag.tag}`,
511
+ disabled,
512
+ onClick: () => onRemove(tag.tag),
513
+ children: "\xD7"
514
+ }
515
+ )
516
+ ] }, tag.id)) }),
517
+ /* @__PURE__ */ jsx6(
518
+ Combobox,
519
+ {
520
+ ariaLabel: "Add tag",
521
+ placeholder: "Add tag\u2026",
522
+ freeText: true,
523
+ disabled,
524
+ search: suggest ?? (() => []),
525
+ onPick: (value) => onAdd(value)
526
+ }
527
+ )
528
+ ] });
529
+ }
530
+
531
+ // src/ui/record-panel.tsx
532
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
533
+ function RecordPanel({
534
+ crm,
535
+ detail,
536
+ onSaveFields,
537
+ onMoveStage,
538
+ onAddTag,
539
+ onRemoveTag,
540
+ onLinkIdentity,
541
+ saving = false,
542
+ fieldErrors,
543
+ activitySlot
544
+ }) {
545
+ const { record, tags, channels, links } = detail;
546
+ const def = crm.type(record.type);
547
+ const facets = def.facets ?? {};
548
+ const profile = /* @__PURE__ */ jsx7("div", { className: "crm-panel-profile", children: /* @__PURE__ */ jsx7(
549
+ FieldsForm,
550
+ {
551
+ crm,
552
+ type: record.type,
553
+ record,
554
+ onSubmit: onSaveFields,
555
+ submitting: saving,
556
+ errors: fieldErrors
557
+ },
558
+ record.id + String(record.updatedAt)
559
+ ) });
560
+ const connections = /* @__PURE__ */ jsxs7("div", { className: "crm-panel-connections", children: [
561
+ /* @__PURE__ */ jsx7(TagEditor, { tags, onAdd: onAddTag, onRemove: onRemoveTag, disabled: saving }),
562
+ /* @__PURE__ */ jsx7("ul", { className: "crm-link-list", "aria-label": "Linked records", children: links.map((link) => /* @__PURE__ */ jsxs7("li", { children: [
563
+ link.relation,
564
+ ": ",
565
+ /* @__PURE__ */ jsx7("code", { children: link.fromId === record.id ? link.toId : link.fromId })
566
+ ] }, link.id)) })
567
+ ] });
568
+ return /* @__PURE__ */ jsxs7("div", { className: "crm-record-panel", "aria-label": record.name, children: [
569
+ /* @__PURE__ */ jsxs7("header", { className: "crm-panel-header", children: [
570
+ /* @__PURE__ */ jsx7("h2", { children: record.name }),
571
+ def.pipeline && /* @__PURE__ */ jsx7(StageControl, { crm, record, onMove: onMoveStage, disabled: saving })
572
+ ] }),
573
+ /* @__PURE__ */ jsxs7("div", { className: "crm-panel-cards", children: [
574
+ facets.identity && /* @__PURE__ */ jsx7(IdentityCard, { record, onLink: onLinkIdentity, linking: saving }),
575
+ facets.billing && /* @__PURE__ */ jsx7(BillingCard, { record }),
576
+ facets.email !== false && channels.length > 0 && /* @__PURE__ */ jsx7(ChannelsCard, { channels })
577
+ ] }),
578
+ /* @__PURE__ */ jsx7(
579
+ Tabs,
580
+ {
581
+ ariaLabel: "Record detail",
582
+ items: [
583
+ { value: "profile", label: "Profile", panel: profile },
584
+ ...activitySlot ? [{ value: "activity", label: "Activity", panel: activitySlot }] : [],
585
+ { value: "connections", label: "Connections", panel: connections }
586
+ ],
587
+ defaultValue: "profile"
588
+ }
589
+ )
590
+ ] });
591
+ }
592
+
593
+ // src/ui/activity-feed.tsx
594
+ import { useState as useState4 } from "react";
595
+ import { Button as Button4, Checkbox as Checkbox2, Input as Input2, Segmented, Textarea as Textarea2 } from "@odla-ai/ui/components";
596
+ import { Fragment, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
597
+ var when = (at) => new Date(at).toISOString().replace("T", " ").slice(0, 16);
598
+ function ActivityFeed({ activities, onAddNote, onAddTask, onToggleTask, busy = false }) {
599
+ const [mode, setMode] = useState4("note");
600
+ const [body, setBody] = useState4("");
601
+ const [dueAt, setDueAt] = useState4("");
602
+ const [waitingOn, setWaitingOn] = useState4("");
603
+ const submit = () => {
604
+ const text = body.trim();
605
+ if (!text) return;
606
+ if (mode === "note") onAddNote(text);
607
+ else
608
+ onAddTask({
609
+ body: text,
610
+ ...dueAt ? { dueAt: Date.parse(dueAt) } : {},
611
+ ...waitingOn.trim() ? { waitingOn: waitingOn.trim() } : {}
612
+ });
613
+ setBody("");
614
+ setDueAt("");
615
+ setWaitingOn("");
616
+ };
617
+ return /* @__PURE__ */ jsxs8("div", { className: "crm-activity-feed", children: [
618
+ /* @__PURE__ */ jsxs8("div", { className: "crm-activity-composer", children: [
619
+ /* @__PURE__ */ jsx8(
620
+ Segmented,
621
+ {
622
+ ariaLabel: "Entry kind",
623
+ value: mode,
624
+ onValueChange: (value) => setMode(value),
625
+ options: [
626
+ { value: "note", label: "Note" },
627
+ { value: "task", label: "Follow-up" }
628
+ ]
629
+ }
630
+ ),
631
+ /* @__PURE__ */ jsx8(
632
+ Textarea2,
633
+ {
634
+ "aria-label": mode === "note" ? "New note" : "New follow-up",
635
+ value: body,
636
+ rows: 2,
637
+ placeholder: mode === "note" ? "What happened?" : "What needs doing?",
638
+ onChange: (event) => setBody(event.currentTarget.value)
639
+ }
640
+ ),
641
+ mode === "task" && /* @__PURE__ */ jsxs8("div", { className: "crm-activity-task-row", children: [
642
+ /* @__PURE__ */ jsx8(
643
+ Input2,
644
+ {
645
+ type: "date",
646
+ "aria-label": "Due date",
647
+ value: dueAt,
648
+ onChange: (event) => setDueAt(event.currentTarget.value)
649
+ }
650
+ ),
651
+ /* @__PURE__ */ jsx8(
652
+ Input2,
653
+ {
654
+ "aria-label": "Waiting on",
655
+ placeholder: "Waiting on\u2026",
656
+ value: waitingOn,
657
+ onChange: (event) => setWaitingOn(event.currentTarget.value)
658
+ }
659
+ )
660
+ ] }),
661
+ /* @__PURE__ */ jsx8(Button4, { mini: true, onClick: submit, disabled: busy || !body.trim(), children: "Add" })
662
+ ] }),
663
+ /* @__PURE__ */ jsx8("ul", { className: "crm-activity-list", children: activities.map((activity) => /* @__PURE__ */ jsxs8("li", { className: `crm-activity kind-${activity.kind}`, children: [
664
+ activity.kind === "task" ? /* @__PURE__ */ jsx8(
665
+ Checkbox2,
666
+ {
667
+ checked: activity.status === "done",
668
+ disabled: busy,
669
+ onChange: (event) => onToggleTask(activity, event.currentTarget.checked),
670
+ label: /* @__PURE__ */ jsxs8(Fragment, { children: [
671
+ activity.body,
672
+ activity.dueAt != null && /* @__PURE__ */ jsxs8("span", { className: "crm-activity-due", children: [
673
+ " \xB7 due ",
674
+ when(activity.dueAt).slice(0, 10)
675
+ ] }),
676
+ activity.waitingOn && /* @__PURE__ */ jsxs8("span", { className: "crm-activity-waiting", children: [
677
+ " \xB7 waiting on ",
678
+ activity.waitingOn
679
+ ] })
680
+ ] })
681
+ }
682
+ ) : /* @__PURE__ */ jsx8("p", { children: activity.body }),
683
+ /* @__PURE__ */ jsxs8("span", { className: "crm-activity-meta", children: [
684
+ activity.kind,
685
+ " \xB7 ",
686
+ when(activity.createdAt)
687
+ ] })
688
+ ] }, activity.id)) })
689
+ ] });
690
+ }
691
+
692
+ // src/ui/bulk-bar.tsx
693
+ import { Button as Button5 } from "@odla-ai/ui/components";
694
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
695
+ function BulkBar({ selected, actions, onClear, busy = false }) {
696
+ if (selected.length === 0) return null;
697
+ return /* @__PURE__ */ jsxs9("div", { className: "crm-bulk-bar", role: "toolbar", "aria-label": "Bulk actions", children: [
698
+ /* @__PURE__ */ jsxs9("span", { className: "crm-bulk-count", children: [
699
+ selected.length,
700
+ " selected"
701
+ ] }),
702
+ actions.map((action) => /* @__PURE__ */ jsx9(Button5, { mini: true, disabled: busy, onClick: () => void action.run(selected), children: action.label }, action.id)),
703
+ /* @__PURE__ */ jsx9(Button5, { mini: true, variant: "ghost", onClick: onClear, disabled: busy, children: "Clear" })
704
+ ] });
705
+ }
706
+
707
+ // src/ui/view-editor.tsx
708
+ import { useState as useState5 } from "react";
709
+ import { Button as Button6, Checkbox as Checkbox3, Input as Input3 } from "@odla-ai/ui/components";
710
+ import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
711
+ function ViewEditor({ current, onSave }) {
712
+ const [open, setOpen] = useState5(false);
713
+ const [name, setName] = useState5("");
714
+ const [shared, setShared] = useState5(false);
715
+ const [busy, setBusy] = useState5(false);
716
+ const [error, setError] = useState5(null);
717
+ if (!open)
718
+ return /* @__PURE__ */ jsx10(Button6, { mini: true, variant: "ghost", onClick: () => setOpen(true), children: "Save view\u2026" });
719
+ const save = async () => {
720
+ setBusy(true);
721
+ setError(null);
722
+ try {
723
+ await onSave({ ...current, name: name.trim(), shared });
724
+ setOpen(false);
725
+ setName("");
726
+ setShared(false);
727
+ } catch (failure) {
728
+ setError(failure instanceof Error ? failure.message : String(failure));
729
+ } finally {
730
+ setBusy(false);
731
+ }
732
+ };
733
+ return /* @__PURE__ */ jsxs10("div", { className: "crm-view-editor", role: "group", "aria-label": "Save view", children: [
734
+ /* @__PURE__ */ jsx10(
735
+ Input3,
736
+ {
737
+ "aria-label": "View name",
738
+ placeholder: "View name",
739
+ value: name,
740
+ onChange: (event) => setName(event.currentTarget.value)
741
+ }
742
+ ),
743
+ /* @__PURE__ */ jsx10(
744
+ Checkbox3,
745
+ {
746
+ checked: shared,
747
+ onChange: (event) => setShared(event.currentTarget.checked),
748
+ label: "Shared"
749
+ }
750
+ ),
751
+ /* @__PURE__ */ jsx10(Button6, { mini: true, onClick: save, disabled: busy || !name.trim(), children: "Save" }),
752
+ /* @__PURE__ */ jsx10(Button6, { mini: true, variant: "ghost", onClick: () => setOpen(false), disabled: busy, children: "Cancel" }),
753
+ error && /* @__PURE__ */ jsx10("span", { className: "crm-view-error", children: error })
754
+ ] });
755
+ }
756
+ export {
757
+ ActivityFeed,
758
+ BillingCard,
759
+ BulkBar,
760
+ ChannelsCard,
761
+ CrmList,
762
+ CrmShell,
763
+ FieldsForm,
764
+ IdentityCard,
765
+ RecordPanel,
766
+ StageControl,
767
+ TagEditor,
768
+ ViewEditor,
769
+ columnsFor,
770
+ defaultColumns,
771
+ sortFieldFor,
772
+ useCrmQuery,
773
+ useCrmRecord
774
+ };
775
+ //# sourceMappingURL=index.js.map