@burdenoff/microfe-headshotmarketing 2026.1123.1 → 2026.1124.2
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/generated/wspace-operations.d.ts +742 -0
- package/dist/generated/wspace-operations.js +752 -351
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.js +41 -33
- package/dist/generated/wspace-types.js.map +1 -1
- package/dist/headshotmarketing/pages/ads/AdBudgetAiPanel.d.ts +7 -0
- package/dist/headshotmarketing/pages/ads/AdBudgetAiPanel.js +133 -0
- package/dist/headshotmarketing/pages/ads/AdBudgetAiPanel.js.map +1 -0
- package/dist/headshotmarketing/pages/ads/AdCampaignDetailsPage.js +54 -49
- package/dist/headshotmarketing/pages/ads/AdCampaignDetailsPage.js.map +1 -1
- package/dist/headshotmarketing/pages/ai/AiDecisionCard.d.ts +31 -0
- package/dist/headshotmarketing/pages/ai/AiDecisionCard.js +150 -0
- package/dist/headshotmarketing/pages/ai/AiDecisionCard.js.map +1 -0
- package/dist/headshotmarketing/pages/ai/AiOperationsPage.d.ts +2 -18
- package/dist/headshotmarketing/pages/ai/AiOperationsPage.js +607 -8
- package/dist/headshotmarketing/pages/ai/AiOperationsPage.js.map +1 -1
- package/dist/headshotmarketing/pages/ai/aiDecisionHelpers.d.ts +53 -0
- package/dist/headshotmarketing/pages/ai/aiDecisionHelpers.js +50 -0
- package/dist/headshotmarketing/pages/ai/aiDecisionHelpers.js.map +1 -0
- package/dist/headshotmarketing/pages/campaigns/CampaignAiPanel.d.ts +7 -0
- package/dist/headshotmarketing/pages/campaigns/CampaignAiPanel.js +267 -0
- package/dist/headshotmarketing/pages/campaigns/CampaignAiPanel.js.map +1 -0
- package/dist/headshotmarketing/pages/campaigns/CampaignDetailsPage.js +258 -251
- package/dist/headshotmarketing/pages/campaigns/CampaignDetailsPage.js.map +1 -1
- package/dist/headshotmarketing/pages/crm/DealNextActionPanel.d.ts +14 -0
- package/dist/headshotmarketing/pages/crm/DealNextActionPanel.js +116 -0
- package/dist/headshotmarketing/pages/crm/DealNextActionPanel.js.map +1 -0
- package/dist/headshotmarketing/pages/crm/LeadAiDecisionPanel.d.ts +20 -0
- package/dist/headshotmarketing/pages/crm/LeadAiDecisionPanel.js +319 -0
- package/dist/headshotmarketing/pages/crm/LeadAiDecisionPanel.js.map +1 -0
- package/dist/headshotmarketing/pages/crm/LeadsPage.js +78 -41
- package/dist/headshotmarketing/pages/crm/LeadsPage.js.map +1 -1
- package/dist/headshotmarketing/pages/crm/PipelinePage.js +126 -102
- package/dist/headshotmarketing/pages/crm/PipelinePage.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import "../../components/index.js";
|
|
2
|
+
import { useHeadshotmarketingScoreLeadMutation as e, useHeadshotmarketingScoreLeadsBatchMutation as t } from "../../../generated/wspace-operations.js";
|
|
3
|
+
import { Modal as n } from "../../components/Modal.js";
|
|
4
|
+
import { HeadshotmarketingLeadScoreTier as r } from "../../../generated/wspace-types.js";
|
|
5
|
+
import { AiDecisionCard as i } from "../ai/AiDecisionCard.js";
|
|
6
|
+
import { AI_DISCLAIMER_TEXT as a, buildBatchChunks as o } from "../ai/aiDecisionHelpers.js";
|
|
7
|
+
import { useRef as s, useState as c } from "react";
|
|
8
|
+
import { AlertTriangle as l, Check as u, Play as d, Sparkles as f, Square as p } from "lucide-react";
|
|
9
|
+
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
10
|
+
// src/headshotmarketing/pages/crm/LeadAiDecisionPanel.tsx
|
|
11
|
+
function _(e) {
|
|
12
|
+
return e === r.Hot ? "success" : e === r.Warm ? "warning" : "info";
|
|
13
|
+
}
|
|
14
|
+
var v = ({ lead: t, onClose: r, onApplied: a }) => {
|
|
15
|
+
let [o, { loading: s }] = e(), [l, u] = c(null), [d, p] = c(!1), [m, v] = c(null), y = () => {
|
|
16
|
+
u(null), p(!1), v(null), r();
|
|
17
|
+
}, b = async () => {
|
|
18
|
+
if (t) {
|
|
19
|
+
v(null), p(!1);
|
|
20
|
+
try {
|
|
21
|
+
let e = (await o({ variables: { input: {
|
|
22
|
+
leadId: t.id,
|
|
23
|
+
dryRun: !0
|
|
24
|
+
} } })).data?.headshotmarketingScoreLead ?? null;
|
|
25
|
+
if (!e) {
|
|
26
|
+
v("AI lead scoring did not return a result.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
u(e);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
v(e instanceof Error ? e.message : "AI lead scoring is currently unavailable.");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}, x = async () => {
|
|
35
|
+
if (t) {
|
|
36
|
+
v(null);
|
|
37
|
+
try {
|
|
38
|
+
let e = await o({ variables: { input: {
|
|
39
|
+
leadId: t.id,
|
|
40
|
+
dryRun: !1
|
|
41
|
+
} } });
|
|
42
|
+
e.data?.headshotmarketingScoreLead && u(e.data.headshotmarketingScoreLead), p(!0), await a();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
v(e instanceof Error ? e.message : "Failed to apply lead score.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ h(n, {
|
|
49
|
+
open: t !== null,
|
|
50
|
+
onClose: y,
|
|
51
|
+
title: t ? `AI Lead Score · ${t.name}` : "AI Lead Score",
|
|
52
|
+
description: "Preview the AI score and rationale before updating the lead.",
|
|
53
|
+
size: "lg",
|
|
54
|
+
children: t && /* @__PURE__ */ h("div", {
|
|
55
|
+
className: "space-y-4",
|
|
56
|
+
children: l ? /* @__PURE__ */ h(i, {
|
|
57
|
+
testId: "lead-score-decision-card",
|
|
58
|
+
title: `Proposed score: ${l.score} / 100`,
|
|
59
|
+
subtitle: `Current: ${t.currentScore} · Baseline heuristic: ${l.baselineScore}`,
|
|
60
|
+
badge: l.tier,
|
|
61
|
+
badgeTone: _(l.tier),
|
|
62
|
+
rationale: l.summary,
|
|
63
|
+
factors: l.factors,
|
|
64
|
+
provider: l.provider,
|
|
65
|
+
model: l.model,
|
|
66
|
+
source: l.source,
|
|
67
|
+
latencyMs: l.latencyMs,
|
|
68
|
+
creditsCharged: l.creditsCharged,
|
|
69
|
+
applyLabel: "Apply score to lead",
|
|
70
|
+
dismissLabel: "Dismiss",
|
|
71
|
+
busy: s,
|
|
72
|
+
applied: d,
|
|
73
|
+
appliedNotice: `Score ${l.score} applied to ${t.name}`,
|
|
74
|
+
error: m,
|
|
75
|
+
onApply: d ? void 0 : () => void x(),
|
|
76
|
+
onDismiss: y
|
|
77
|
+
}) : /* @__PURE__ */ g("div", {
|
|
78
|
+
className: "rounded-lg border border-border-subtle bg-bg-sunken/40 p-4 space-y-3",
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ g("p", {
|
|
81
|
+
className: "text-sm text-text-primary",
|
|
82
|
+
children: [
|
|
83
|
+
"Current lead score:",
|
|
84
|
+
" ",
|
|
85
|
+
/* @__PURE__ */ h("span", {
|
|
86
|
+
className: "font-semibold tabular-nums",
|
|
87
|
+
children: t.currentScore
|
|
88
|
+
}),
|
|
89
|
+
". Running a preview computes a fresh 0–100 score and rationale without changing the lead until you confirm."
|
|
90
|
+
]
|
|
91
|
+
}),
|
|
92
|
+
m && /* @__PURE__ */ h("div", {
|
|
93
|
+
role: "alert",
|
|
94
|
+
className: "rounded-md border border-status-error-border/40 bg-status-error-bg/15 px-3 py-2 text-xs text-status-error-text",
|
|
95
|
+
children: m
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ g("div", {
|
|
98
|
+
className: "flex items-center justify-end gap-2",
|
|
99
|
+
children: [/* @__PURE__ */ h("button", {
|
|
100
|
+
type: "button",
|
|
101
|
+
onClick: y,
|
|
102
|
+
className: "rounded-md border border-border-seam bg-gloss-card px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken",
|
|
103
|
+
children: "Cancel"
|
|
104
|
+
}), /* @__PURE__ */ g("button", {
|
|
105
|
+
type: "button",
|
|
106
|
+
onClick: () => void b(),
|
|
107
|
+
disabled: s,
|
|
108
|
+
className: "inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-1.5 text-xs font-medium text-action-primary-text hover:bg-action-primary-bg/90 disabled:opacity-60",
|
|
109
|
+
children: [/* @__PURE__ */ h(f, {
|
|
110
|
+
className: "h-3.5 w-3.5",
|
|
111
|
+
"aria-hidden": "true"
|
|
112
|
+
}), s ? "Scoring preview..." : "Generate score preview"]
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}, y = ({ open: e, totalAvailable: r, onClose: i, onCompleted: f }) => {
|
|
120
|
+
let [_] = t(), [v, y] = c(10), [b, x] = c(!0), [S, C] = c(!0), [w, T] = c(!1), [E, D] = c(!1), [O, k] = c(0), [A, j] = c(0), [M, N] = c(0), [P, F] = c([]), [I, L] = c(null), R = s(!1), z = Math.max(1, Math.min(50, Math.min(r || 10, v))), B = z > 0 ? Math.min(100, Math.round(O / z * 100)) : 0, V = () => {
|
|
121
|
+
w && (R.current = !0), i();
|
|
122
|
+
}, H = () => {
|
|
123
|
+
R.current = !0, D(!0);
|
|
124
|
+
}, U = async () => {
|
|
125
|
+
R.current = !1, T(!0), D(!1), L(null), k(0), j(0), N(0), F([]);
|
|
126
|
+
let e = o(z, 5), t = 0, n = 0, r = 0, i = [];
|
|
127
|
+
try {
|
|
128
|
+
for (let a of e) {
|
|
129
|
+
if (R.current) {
|
|
130
|
+
D(!0);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
let e = (await _({ variables: { input: {
|
|
134
|
+
limit: a,
|
|
135
|
+
onlyUnscored: b,
|
|
136
|
+
dryRun: S
|
|
137
|
+
} } })).data?.headshotmarketingScoreLeadsBatch;
|
|
138
|
+
if (!e) {
|
|
139
|
+
L("Batch scoring returned no data.");
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
t += e.scored, n += e.failed, r += e.requested;
|
|
143
|
+
for (let t of e.results) i.push({
|
|
144
|
+
leadId: t.leadId,
|
|
145
|
+
score: t.score,
|
|
146
|
+
tier: t.tier,
|
|
147
|
+
source: t.source
|
|
148
|
+
});
|
|
149
|
+
if (k(r), j(t), N(n), F([...i]), e.requested < a) break;
|
|
150
|
+
}
|
|
151
|
+
!S && t > 0 && await f();
|
|
152
|
+
} catch (e) {
|
|
153
|
+
L(e instanceof Error ? e.message : "Batch lead scoring stopped due to an AI service error.");
|
|
154
|
+
} finally {
|
|
155
|
+
T(!1);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return /* @__PURE__ */ h(n, {
|
|
159
|
+
open: e,
|
|
160
|
+
onClose: V,
|
|
161
|
+
title: "Batch AI Lead Scoring",
|
|
162
|
+
description: "Score leads in bounded steps with live progress and mid-run cancellation.",
|
|
163
|
+
size: "lg",
|
|
164
|
+
children: /* @__PURE__ */ g("div", {
|
|
165
|
+
className: "space-y-4",
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ g("div", {
|
|
168
|
+
className: "grid grid-cols-1 gap-3 sm:grid-cols-3",
|
|
169
|
+
children: [
|
|
170
|
+
/* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h("label", {
|
|
171
|
+
htmlFor: "hsm-batch-target",
|
|
172
|
+
className: "block text-xs font-medium text-text-secondary",
|
|
173
|
+
children: "Leads to score (1–50)"
|
|
174
|
+
}), /* @__PURE__ */ h("input", {
|
|
175
|
+
id: "hsm-batch-target",
|
|
176
|
+
type: "number",
|
|
177
|
+
min: 1,
|
|
178
|
+
max: 50,
|
|
179
|
+
disabled: w,
|
|
180
|
+
value: v,
|
|
181
|
+
onChange: (e) => y(Number(e.target.value) || 1),
|
|
182
|
+
className: "mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
183
|
+
})] }),
|
|
184
|
+
/* @__PURE__ */ g("label", {
|
|
185
|
+
className: "flex items-center gap-2 self-end pb-1.5 text-xs text-text-primary",
|
|
186
|
+
children: [/* @__PURE__ */ h("input", {
|
|
187
|
+
type: "checkbox",
|
|
188
|
+
disabled: w,
|
|
189
|
+
checked: b,
|
|
190
|
+
onChange: (e) => x(e.target.checked),
|
|
191
|
+
className: "rounded border-border-subtle"
|
|
192
|
+
}), "Only unscored leads"]
|
|
193
|
+
}),
|
|
194
|
+
/* @__PURE__ */ g("label", {
|
|
195
|
+
className: "flex items-center gap-2 self-end pb-1.5 text-xs text-text-primary",
|
|
196
|
+
children: [/* @__PURE__ */ h("input", {
|
|
197
|
+
type: "checkbox",
|
|
198
|
+
disabled: w,
|
|
199
|
+
checked: S,
|
|
200
|
+
onChange: (e) => C(e.target.checked),
|
|
201
|
+
className: "rounded border-border-subtle"
|
|
202
|
+
}), "Preview only (dry run)"]
|
|
203
|
+
})
|
|
204
|
+
]
|
|
205
|
+
}),
|
|
206
|
+
(w || O > 0) && /* @__PURE__ */ g("div", {
|
|
207
|
+
"data-testid": "batch-score-progress",
|
|
208
|
+
className: "rounded-md border border-border-subtle bg-bg-sunken/40 p-3 space-y-2",
|
|
209
|
+
children: [
|
|
210
|
+
/* @__PURE__ */ g("div", {
|
|
211
|
+
className: "flex items-center justify-between text-xs",
|
|
212
|
+
children: [/* @__PURE__ */ h("span", {
|
|
213
|
+
className: "font-medium text-text-primary",
|
|
214
|
+
children: w ? "Scoring leads..." : E ? "Cancelled — completed steps kept safely" : "Batch complete"
|
|
215
|
+
}), /* @__PURE__ */ g("span", {
|
|
216
|
+
className: "tabular-nums text-text-secondary",
|
|
217
|
+
children: [
|
|
218
|
+
O,
|
|
219
|
+
" / ",
|
|
220
|
+
z,
|
|
221
|
+
" (",
|
|
222
|
+
B,
|
|
223
|
+
"%)"
|
|
224
|
+
]
|
|
225
|
+
})]
|
|
226
|
+
}),
|
|
227
|
+
/* @__PURE__ */ h("div", {
|
|
228
|
+
className: "h-2 w-full overflow-hidden rounded-full bg-bg-sunken",
|
|
229
|
+
children: /* @__PURE__ */ h("div", {
|
|
230
|
+
className: "h-full rounded-full bg-action-primary-bg transition-all",
|
|
231
|
+
style: { width: `${B}%` }
|
|
232
|
+
})
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ g("div", {
|
|
235
|
+
className: "flex items-center gap-4 text-xs text-text-secondary",
|
|
236
|
+
children: [
|
|
237
|
+
/* @__PURE__ */ g("span", {
|
|
238
|
+
className: "inline-flex items-center gap-1 text-status-success-text",
|
|
239
|
+
children: [
|
|
240
|
+
/* @__PURE__ */ h(u, {
|
|
241
|
+
className: "h-3.5 w-3.5",
|
|
242
|
+
"aria-hidden": "true"
|
|
243
|
+
}),
|
|
244
|
+
A,
|
|
245
|
+
" scored"
|
|
246
|
+
]
|
|
247
|
+
}),
|
|
248
|
+
M > 0 && /* @__PURE__ */ g("span", {
|
|
249
|
+
className: "text-status-error-text",
|
|
250
|
+
children: [M, " failed"]
|
|
251
|
+
}),
|
|
252
|
+
S && /* @__PURE__ */ h("span", { children: "Mode: preview only (no leads mutated)" })
|
|
253
|
+
]
|
|
254
|
+
})
|
|
255
|
+
]
|
|
256
|
+
}),
|
|
257
|
+
P.length > 0 && /* @__PURE__ */ h("div", {
|
|
258
|
+
className: "max-h-48 overflow-y-auto rounded-md border border-border-subtle divide-y divide-border-subtle text-xs",
|
|
259
|
+
children: P.map((e, t) => /* @__PURE__ */ g("div", {
|
|
260
|
+
className: "flex items-center justify-between px-3 py-2",
|
|
261
|
+
children: [/* @__PURE__ */ h("span", {
|
|
262
|
+
className: "truncate font-mono text-text-secondary",
|
|
263
|
+
children: e.leadId
|
|
264
|
+
}), /* @__PURE__ */ g("span", {
|
|
265
|
+
className: "font-semibold tabular-nums text-text-primary",
|
|
266
|
+
children: [
|
|
267
|
+
e.score,
|
|
268
|
+
" · ",
|
|
269
|
+
e.tier
|
|
270
|
+
]
|
|
271
|
+
})]
|
|
272
|
+
}, `${e.leadId}-${t}`))
|
|
273
|
+
}),
|
|
274
|
+
I && /* @__PURE__ */ h("div", {
|
|
275
|
+
role: "alert",
|
|
276
|
+
className: "rounded-md border border-status-error-border/40 bg-status-error-bg/15 px-3 py-2 text-xs text-status-error-text",
|
|
277
|
+
children: I
|
|
278
|
+
}),
|
|
279
|
+
/* @__PURE__ */ g("p", {
|
|
280
|
+
className: "flex items-center gap-1.5 text-[11px] text-text-secondary",
|
|
281
|
+
children: [/* @__PURE__ */ h(l, {
|
|
282
|
+
className: "h-3 w-3 shrink-0",
|
|
283
|
+
"aria-hidden": "true"
|
|
284
|
+
}), /* @__PURE__ */ h("span", { children: a })]
|
|
285
|
+
}),
|
|
286
|
+
/* @__PURE__ */ h("div", {
|
|
287
|
+
className: "flex items-center justify-end gap-2",
|
|
288
|
+
children: w ? /* @__PURE__ */ g("button", {
|
|
289
|
+
type: "button",
|
|
290
|
+
onClick: H,
|
|
291
|
+
"data-testid": "batch-score-cancel",
|
|
292
|
+
className: "inline-flex items-center gap-1.5 rounded-md border border-status-error-border/50 bg-gloss-card px-3 py-1.5 text-xs font-medium text-status-error-text hover:bg-bg-sunken",
|
|
293
|
+
children: [/* @__PURE__ */ h(p, {
|
|
294
|
+
className: "h-3.5 w-3.5",
|
|
295
|
+
"aria-hidden": "true"
|
|
296
|
+
}), "Cancel batch"]
|
|
297
|
+
}) : /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("button", {
|
|
298
|
+
type: "button",
|
|
299
|
+
onClick: V,
|
|
300
|
+
className: "rounded-md border border-border-seam bg-gloss-card px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken",
|
|
301
|
+
children: "Close"
|
|
302
|
+
}), /* @__PURE__ */ g("button", {
|
|
303
|
+
type: "button",
|
|
304
|
+
onClick: () => void U(),
|
|
305
|
+
"data-testid": "batch-score-start",
|
|
306
|
+
className: "inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-1.5 text-xs font-medium text-action-primary-text hover:bg-action-primary-bg/90",
|
|
307
|
+
children: [/* @__PURE__ */ h(d, {
|
|
308
|
+
className: "h-3.5 w-3.5",
|
|
309
|
+
"aria-hidden": "true"
|
|
310
|
+
}), S ? "Run dry-run preview" : "Score & update leads"]
|
|
311
|
+
})] })
|
|
312
|
+
})
|
|
313
|
+
]
|
|
314
|
+
})
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
export { y as LeadBatchScoringModal, v as LeadScoreDecisionModal };
|
|
318
|
+
|
|
319
|
+
//# sourceMappingURL=LeadAiDecisionPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeadAiDecisionPanel.js","names":["_Fragment","tierBadgeTone","tier","HeadshotmarketingLeadScoreTier","LeadScoreDecisionModal","scoreLead","scoring","useHeadshotmarketingScoreLeadMutation","preview","setPreview","useState","applied","setApplied","error","setError","handleClose","onClose","handlePreview","lead","result","err","handleApply","res","onApplied","Modal","AiDecisionCard","Sparkles","LeadBatchScoringModal","scoreBatch","useHeadshotmarketingScoreLeadsBatchMutation","targetCount","setTargetCount","onlyUnscored","setOnlyUnscored","dryRun","setDryRun","running","setRunning","cancelled","setCancelled","processed","setProcessed","scoredCount","setScoredCount","failedCount","setFailedCount","results","setResults","cancelFlagRef","useRef","clampedTarget","totalAvailable","progressPct","handleCancel","handleStart","chunks","buildBatchChunks","totalScored","totalFailed","totalProcessed","collected","limit","batch","item","onCompleted","Check","idx","AlertTriangle","AI_DISCLAIMER_TEXT","Square","Fragment","Play"],"sources":["../../../../src/headshotmarketing/pages/crm/LeadAiDecisionPanel.tsx"],"sourcesContent":["/**\n * Lead AI Decision Panels (BOFF-3736 / BOFF-3782)\n *\n * 1. LeadScoreDecisionModal — previews an AI lead score (`dryRun: true`) and\n * renders a confirmation-gated `AiDecisionCard` with ranked factors, model,\n * cost and disclaimer. Only clicking \"Apply score\" writes the score to the\n * lead (`dryRun: false`).\n * 2. LeadBatchScoringModal — runs `headshotmarketingScoreLeadsBatch` in\n * bounded chunks with live progress and a working Cancel button that stops\n * cleanly between chunks without corrupting already-scored leads\n * (readiness criterion 4.2).\n *\n * @module headshotmarketing/pages/crm\n */\n\nimport { useRef, useState, type FC } from \"react\";\nimport { Sparkles, Play, Square, AlertTriangle, Check } from \"lucide-react\";\nimport { Modal } from \"../../components\";\nimport {\n useHeadshotmarketingScoreLeadMutation,\n useHeadshotmarketingScoreLeadsBatchMutation,\n type HeadshotmarketingScoreLeadMutation,\n} from \"../../../generated/wspace-operations\";\nimport { HeadshotmarketingLeadScoreTier } from \"../../../generated/wspace-types\";\nimport { AiDecisionCard } from \"../ai/AiDecisionCard\";\nimport { AI_DISCLAIMER_TEXT, buildBatchChunks } from \"../ai/aiDecisionHelpers\";\n\ntype ScoreResult =\n HeadshotmarketingScoreLeadMutation[\"headshotmarketingScoreLead\"];\n\nexport interface LeadScoreTarget {\n id: string;\n name: string;\n currentScore: number;\n}\n\ninterface LeadScoreDecisionModalProps {\n lead: LeadScoreTarget | null;\n onClose: () => void;\n onApplied: () => Promise<void> | void;\n}\n\nfunction tierBadgeTone(\n tier: HeadshotmarketingLeadScoreTier,\n): \"success\" | \"warning\" | \"info\" {\n if (tier === HeadshotmarketingLeadScoreTier.Hot) return \"success\";\n if (tier === HeadshotmarketingLeadScoreTier.Warm) return \"warning\";\n return \"info\";\n}\n\nexport const LeadScoreDecisionModal: FC<LeadScoreDecisionModalProps> = ({\n lead,\n onClose,\n onApplied,\n}) => {\n const [scoreLead, { loading: scoring }] =\n useHeadshotmarketingScoreLeadMutation();\n const [preview, setPreview] = useState<ScoreResult | null>(null);\n const [applied, setApplied] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const handleClose = (): void => {\n setPreview(null);\n setApplied(false);\n setError(null);\n onClose();\n };\n\n const handlePreview = async (): Promise<void> => {\n if (!lead) return;\n setError(null);\n setApplied(false);\n try {\n const res = await scoreLead({\n variables: { input: { leadId: lead.id, dryRun: true } },\n });\n const result = res.data?.headshotmarketingScoreLead ?? null;\n if (!result) {\n setError(\"AI lead scoring did not return a result.\");\n return;\n }\n setPreview(result);\n } catch (err) {\n setError(\n err instanceof Error\n ? err.message\n : \"AI lead scoring is currently unavailable.\",\n );\n }\n };\n\n const handleApply = async (): Promise<void> => {\n if (!lead) return;\n setError(null);\n try {\n const res = await scoreLead({\n variables: { input: { leadId: lead.id, dryRun: false } },\n });\n if (res.data?.headshotmarketingScoreLead) {\n setPreview(res.data.headshotmarketingScoreLead);\n }\n setApplied(true);\n await onApplied();\n } catch (err) {\n setError(\n err instanceof Error ? err.message : \"Failed to apply lead score.\",\n );\n }\n };\n\n return (\n <Modal\n open={lead !== null}\n onClose={handleClose}\n title={lead ? `AI Lead Score · ${lead.name}` : \"AI Lead Score\"}\n description=\"Preview the AI score and rationale before updating the lead.\"\n size=\"lg\"\n >\n {lead && (\n <div className=\"space-y-4\">\n {!preview ? (\n <div className=\"rounded-lg border border-border-subtle bg-bg-sunken/40 p-4 space-y-3\">\n <p className=\"text-sm text-text-primary\">\n Current lead score:{\" \"}\n <span className=\"font-semibold tabular-nums\">\n {lead.currentScore}\n </span>\n . Running a preview computes a fresh 0–100 score and rationale\n without changing the lead until you confirm.\n </p>\n {error && (\n <div\n role=\"alert\"\n className=\"rounded-md border border-status-error-border/40 bg-status-error-bg/15 px-3 py-2 text-xs text-status-error-text\"\n >\n {error}\n </div>\n )}\n <div className=\"flex items-center justify-end gap-2\">\n <button\n type=\"button\"\n onClick={handleClose}\n className=\"rounded-md border border-border-seam bg-gloss-card px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n Cancel\n </button>\n <button\n type=\"button\"\n onClick={() => void handlePreview()}\n disabled={scoring}\n className=\"inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-1.5 text-xs font-medium text-action-primary-text hover:bg-action-primary-bg/90 disabled:opacity-60\"\n >\n <Sparkles className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n {scoring ? \"Scoring preview...\" : \"Generate score preview\"}\n </button>\n </div>\n </div>\n ) : (\n <AiDecisionCard\n testId=\"lead-score-decision-card\"\n title={`Proposed score: ${preview.score} / 100`}\n subtitle={`Current: ${lead.currentScore} · Baseline heuristic: ${preview.baselineScore}`}\n badge={preview.tier}\n badgeTone={tierBadgeTone(preview.tier)}\n rationale={preview.summary}\n factors={preview.factors}\n provider={preview.provider}\n model={preview.model}\n source={preview.source}\n latencyMs={preview.latencyMs}\n creditsCharged={preview.creditsCharged}\n applyLabel=\"Apply score to lead\"\n dismissLabel=\"Dismiss\"\n busy={scoring}\n applied={applied}\n appliedNotice={`Score ${preview.score} applied to ${lead.name}`}\n error={error}\n onApply={applied ? undefined : () => void handleApply()}\n onDismiss={handleClose}\n />\n )}\n </div>\n )}\n </Modal>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Batch Lead Scoring with Progress & Cancel (readiness criterion 4.2)\n// ---------------------------------------------------------------------------\n\ninterface LeadBatchScoringModalProps {\n open: boolean;\n totalAvailable: number;\n onClose: () => void;\n onCompleted: () => Promise<void> | void;\n}\n\ninterface BatchRunSummary {\n leadId: string;\n score: number;\n tier: string;\n source: string;\n}\n\nexport const LeadBatchScoringModal: FC<LeadBatchScoringModalProps> = ({\n open,\n totalAvailable,\n onClose,\n onCompleted,\n}) => {\n const [scoreBatch] = useHeadshotmarketingScoreLeadsBatchMutation();\n const [targetCount, setTargetCount] = useState<number>(10);\n const [onlyUnscored, setOnlyUnscored] = useState<boolean>(true);\n const [dryRun, setDryRun] = useState<boolean>(true);\n const [running, setRunning] = useState<boolean>(false);\n const [cancelled, setCancelled] = useState<boolean>(false);\n const [processed, setProcessed] = useState<number>(0);\n const [scoredCount, setScoredCount] = useState<number>(0);\n const [failedCount, setFailedCount] = useState<number>(0);\n const [results, setResults] = useState<BatchRunSummary[]>([]);\n const [error, setError] = useState<string | null>(null);\n const cancelFlagRef = useRef<boolean>(false);\n\n const clampedTarget = Math.max(\n 1,\n Math.min(50, Math.min(totalAvailable || 10, targetCount)),\n );\n const progressPct =\n clampedTarget > 0\n ? Math.min(100, Math.round((processed / clampedTarget) * 100))\n : 0;\n\n const handleClose = (): void => {\n if (running) {\n cancelFlagRef.current = true;\n }\n onClose();\n };\n\n const handleCancel = (): void => {\n cancelFlagRef.current = true;\n setCancelled(true);\n };\n\n const handleStart = async (): Promise<void> => {\n cancelFlagRef.current = false;\n setRunning(true);\n setCancelled(false);\n setError(null);\n setProcessed(0);\n setScoredCount(0);\n setFailedCount(0);\n setResults([]);\n\n const chunks = buildBatchChunks(clampedTarget, 5);\n let totalScored = 0;\n let totalFailed = 0;\n let totalProcessed = 0;\n const collected: BatchRunSummary[] = [];\n\n try {\n for (const limit of chunks) {\n if (cancelFlagRef.current) {\n setCancelled(true);\n break;\n }\n const res = await scoreBatch({\n variables: {\n input: {\n limit,\n onlyUnscored,\n dryRun,\n },\n },\n });\n const batch = res.data?.headshotmarketingScoreLeadsBatch;\n if (!batch) {\n setError(\"Batch scoring returned no data.\");\n break;\n }\n totalScored += batch.scored;\n totalFailed += batch.failed;\n totalProcessed += batch.requested;\n for (const item of batch.results) {\n collected.push({\n leadId: item.leadId,\n score: item.score,\n tier: item.tier,\n source: item.source,\n });\n }\n setProcessed(totalProcessed);\n setScoredCount(totalScored);\n setFailedCount(totalFailed);\n setResults([...collected]);\n\n // Backend ran out of matching leads before filling the chunk.\n if (batch.requested < limit) {\n break;\n }\n }\n if (!dryRun && totalScored > 0) {\n await onCompleted();\n }\n } catch (err) {\n setError(\n err instanceof Error\n ? err.message\n : \"Batch lead scoring stopped due to an AI service error.\",\n );\n } finally {\n setRunning(false);\n }\n };\n\n return (\n <Modal\n open={open}\n onClose={handleClose}\n title=\"Batch AI Lead Scoring\"\n description=\"Score leads in bounded steps with live progress and mid-run cancellation.\"\n size=\"lg\"\n >\n <div className=\"space-y-4\">\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <div>\n <label\n htmlFor=\"hsm-batch-target\"\n className=\"block text-xs font-medium text-text-secondary\"\n >\n Leads to score (1–50)\n </label>\n <input\n id=\"hsm-batch-target\"\n type=\"number\"\n min={1}\n max={50}\n disabled={running}\n value={targetCount}\n onChange={(e) => setTargetCount(Number(e.target.value) || 1)}\n className=\"mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <label className=\"flex items-center gap-2 self-end pb-1.5 text-xs text-text-primary\">\n <input\n type=\"checkbox\"\n disabled={running}\n checked={onlyUnscored}\n onChange={(e) => setOnlyUnscored(e.target.checked)}\n className=\"rounded border-border-subtle\"\n />\n Only unscored leads\n </label>\n <label className=\"flex items-center gap-2 self-end pb-1.5 text-xs text-text-primary\">\n <input\n type=\"checkbox\"\n disabled={running}\n checked={dryRun}\n onChange={(e) => setDryRun(e.target.checked)}\n className=\"rounded border-border-subtle\"\n />\n Preview only (dry run)\n </label>\n </div>\n\n {/* Progress indicator */}\n {(running || processed > 0) && (\n <div\n data-testid=\"batch-score-progress\"\n className=\"rounded-md border border-border-subtle bg-bg-sunken/40 p-3 space-y-2\"\n >\n <div className=\"flex items-center justify-between text-xs\">\n <span className=\"font-medium text-text-primary\">\n {running\n ? \"Scoring leads...\"\n : cancelled\n ? \"Cancelled — completed steps kept safely\"\n : \"Batch complete\"}\n </span>\n <span className=\"tabular-nums text-text-secondary\">\n {processed} / {clampedTarget} ({progressPct}%)\n </span>\n </div>\n <div className=\"h-2 w-full overflow-hidden rounded-full bg-bg-sunken\">\n <div\n className=\"h-full rounded-full bg-action-primary-bg transition-all\"\n style={{ width: `${progressPct}%` }}\n />\n </div>\n <div className=\"flex items-center gap-4 text-xs text-text-secondary\">\n <span className=\"inline-flex items-center gap-1 text-status-success-text\">\n <Check className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n {scoredCount} scored\n </span>\n {failedCount > 0 && (\n <span className=\"text-status-error-text\">\n {failedCount} failed\n </span>\n )}\n {dryRun && <span>Mode: preview only (no leads mutated)</span>}\n </div>\n </div>\n )}\n\n {results.length > 0 && (\n <div className=\"max-h-48 overflow-y-auto rounded-md border border-border-subtle divide-y divide-border-subtle text-xs\">\n {results.map((item, idx) => (\n <div\n key={`${item.leadId}-${idx}`}\n className=\"flex items-center justify-between px-3 py-2\"\n >\n <span className=\"truncate font-mono text-text-secondary\">\n {item.leadId}\n </span>\n <span className=\"font-semibold tabular-nums text-text-primary\">\n {item.score} · {item.tier}\n </span>\n </div>\n ))}\n </div>\n )}\n\n {error && (\n <div\n role=\"alert\"\n className=\"rounded-md border border-status-error-border/40 bg-status-error-bg/15 px-3 py-2 text-xs text-status-error-text\"\n >\n {error}\n </div>\n )}\n\n <p className=\"flex items-center gap-1.5 text-[11px] text-text-secondary\">\n <AlertTriangle className=\"h-3 w-3 shrink-0\" aria-hidden=\"true\" />\n <span>{AI_DISCLAIMER_TEXT}</span>\n </p>\n\n <div className=\"flex items-center justify-end gap-2\">\n {running ? (\n <button\n type=\"button\"\n onClick={handleCancel}\n data-testid=\"batch-score-cancel\"\n className=\"inline-flex items-center gap-1.5 rounded-md border border-status-error-border/50 bg-gloss-card px-3 py-1.5 text-xs font-medium text-status-error-text hover:bg-bg-sunken\"\n >\n <Square className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n Cancel batch\n </button>\n ) : (\n <>\n <button\n type=\"button\"\n onClick={handleClose}\n className=\"rounded-md border border-border-seam bg-gloss-card px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n Close\n </button>\n <button\n type=\"button\"\n onClick={() => void handleStart()}\n data-testid=\"batch-score-start\"\n className=\"inline-flex items-center gap-1.5 rounded-md bg-action-primary-bg px-3 py-1.5 text-xs font-medium text-action-primary-text hover:bg-action-primary-bg/90\"\n >\n <Play className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n {dryRun ? \"Run dry-run preview\" : \"Score & update leads\"}\n </button>\n </>\n )}\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AAK;OACjB;MACH,CAAA,CAAA;KATE,GAAA,GAAGA,EAAK,OAAO,GAAGG,GASpB,CACN;IACE,CAAA;IAGNrD,KACC,kBAAC,OAAD;KACE,MAAK;KACL,WAAU;KAET,UAAAA;IACE,CAAA;IAGP,kBAAC,KAAD;KAAG,WAAU;KAAb,UAAA,CACE,kBAACsD,GAAD;MAAe,WAAU;MAAmB,eAAY;KAAQ,CAAA,GAChE,kBAAC,QAAD,EAAA,UAAOC,EAAyB,CAAA,CAC/B;;IAEH,kBAAC,OAAD;KAAK,WAAU;KACZ,UAAAhC,IACC,kBAAC,UAAD;MACE,MAAK;MACL,SAASiB;MACT,eAAY;MACZ,WAAU;MAJZ,UAAA,CAME,kBAACgB,GAAD;OAAQ,WAAU;OAAc,eAAY;MAAQ,CAAA,GAAC,cAE/C;KAER,CAAA,IAAA,kBAAArE,GAAA,EAAA,UAAA,CACE,kBAAC,UAAD;MACE,MAAK;MACL,SAASe;MACT,WAAU;MACX,UAAA;KAEO,CAAA,GACR,kBAAC,UAAD;MACE,MAAK;MACL,eAAe,KAAKuC,EAAY;MAChC,eAAY;MACZ,WAAU;MAJZ,UAAA,CAME,kBAACiB,GAAD;OAAM,WAAU;OAAc,eAAY;MAAQ,CAAA,GACjDrC,IAAS,wBAAwB,sBAC5B;KACR,CAAA,CAAA,EAAA,CAAA;IAED,CAAA;GACF;;CACA,CAAA;AAEX"}
|
|
@@ -19,9 +19,10 @@ import { useRecordSelection as v } from "../../hooks/useRecordSelection.js";
|
|
|
19
19
|
import { useRefreshCrmSelection as te } from "../../hooks/useRefreshCrmSelection.js";
|
|
20
20
|
import { CrmRecordSelection as ne } from "../../components/CrmRecordSelection.js";
|
|
21
21
|
import { ConvertLeadButton as re } from "./ConvertLeadButton.js";
|
|
22
|
-
import { LeadAvatar as y, LeadScoreHistogram as ie, LeadSourceCell as ae, bucketScores as
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
22
|
+
import { LeadAvatar as y, LeadScoreHistogram as ie, LeadSourceCell as ae, bucketScores as oe } from "./LeadsWidgets.js";
|
|
23
|
+
import { LeadBatchScoringModal as se, LeadScoreDecisionModal as ce } from "./LeadAiDecisionPanel.js";
|
|
24
|
+
import { useMemo as b, useState as x } from "react";
|
|
25
|
+
import { Flame as S, Gauge as C, Plus as w, Sparkles as T, TrendingUp as E, Users as D } from "lucide-react";
|
|
25
26
|
import { jsx as O, jsxs as k } from "react/jsx-runtime";
|
|
26
27
|
import { EmphasisPanel as A, PagePurpose as j } from "@burdenoff/fe-libs/ui";
|
|
27
28
|
// src/headshotmarketing/pages/crm/LeadsPage.tsx
|
|
@@ -63,7 +64,7 @@ var M = [
|
|
|
63
64
|
label: "Other"
|
|
64
65
|
}
|
|
65
66
|
], N = "min-h-[44px] rounded-md border border-border-seam bg-gloss-card shadow-pop px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]", P = () => {
|
|
66
|
-
let { selectRecord: P } = v(), { data: F, loading: I, error: L } = p(), R = te("lead"), { currentUser: z, navigate:
|
|
67
|
+
let { selectRecord: P } = v(), { data: F, loading: I, error: L } = p(), R = te("lead"), { currentUser: z, navigate: le, basePath: B } = m(), [V, H] = x(""), [U, W] = x("all"), [G, ue] = x("all"), [de, K] = x(!1), [fe, q] = x(null), [pe, J] = x(!1), me = b(() => {
|
|
67
68
|
let e = F?.headshotmarketingPipelines.items ?? [];
|
|
68
69
|
if (e.length === 0) return null;
|
|
69
70
|
let t = e.find((e) => e.isDefault) ?? e[0], n = [...t.stages].sort((e, t) => e.order - t.order)[0];
|
|
@@ -73,10 +74,10 @@ var M = [
|
|
|
73
74
|
stageId: n.id,
|
|
74
75
|
stageName: n.name
|
|
75
76
|
} : null;
|
|
76
|
-
}, [F?.headshotmarketingPipelines.items]), Y =
|
|
77
|
+
}, [F?.headshotmarketingPipelines.items]), Y = b(() => {
|
|
77
78
|
let e = (F?.headshotmarketingContacts.items ?? []).map((e) => r(e));
|
|
78
79
|
return Object.fromEntries(e.map((e) => [e.id, e]));
|
|
79
|
-
}, [F?.headshotmarketingContacts.items]), X =
|
|
80
|
+
}, [F?.headshotmarketingContacts.items]), X = b(() => F?.headshotmarketingLeads.items ?? [], [F?.headshotmarketingLeads.items]), Z = b(() => {
|
|
80
81
|
let e = new Map(X.map((e) => [e.id, e]));
|
|
81
82
|
return X.map((e) => ee(e, Y)).map((t) => {
|
|
82
83
|
let n = e.get(t.id), r = n?.contactId ? Y[n.contactId] : void 0;
|
|
@@ -86,18 +87,18 @@ var M = [
|
|
|
86
87
|
contactAvatar: r?.avatar ?? ""
|
|
87
88
|
};
|
|
88
89
|
});
|
|
89
|
-
}, [X, Y]), Q = X.length,
|
|
90
|
+
}, [X, Y]), Q = X.length, he = b(() => {
|
|
90
91
|
if (Q === 0) return 0;
|
|
91
92
|
let e = X.reduce((e, t) => e + (t.score ?? 0), 0);
|
|
92
93
|
return Math.round(e / Q);
|
|
93
|
-
}, [X, Q]),
|
|
94
|
+
}, [X, Q]), ge = b(() => X.filter((e) => (e.score ?? 0) >= 80).length, [X]), _e = b(() => {
|
|
94
95
|
if (Q === 0) return 0;
|
|
95
96
|
let e = X.filter((e) => e.status === f.Converted || e.status === f.Qualified).length;
|
|
96
97
|
return Math.round(e / Q * 100);
|
|
97
|
-
}, [X, Q]),
|
|
98
|
+
}, [X, Q]), ve = b(() => oe(X.map((e) => e.score ?? 0)), [X]), $ = Z.filter((e) => {
|
|
98
99
|
let t = !V || `${e.firstName} ${e.lastName} ${e.email} ${e.company} ${e.title}`.toLowerCase().includes(V.toLowerCase()), n = U === "all" || e.status === U, r = G === "all" || e.source === G;
|
|
99
100
|
return t && n && r;
|
|
100
|
-
}),
|
|
101
|
+
}), ye = (e) => {
|
|
101
102
|
if (!e || e === "Unassigned") return /* @__PURE__ */ O("span", {
|
|
102
103
|
className: "text-sm text-text-secondary",
|
|
103
104
|
children: "Unassigned"
|
|
@@ -127,24 +128,43 @@ var M = [
|
|
|
127
128
|
return /* @__PURE__ */ k(i, {
|
|
128
129
|
title: "Leads",
|
|
129
130
|
description: "Track and manage your leads pipeline",
|
|
130
|
-
actions: /* @__PURE__ */ k("
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
actions: /* @__PURE__ */ k("div", {
|
|
132
|
+
className: "flex flex-wrap items-center gap-2",
|
|
133
|
+
children: [/* @__PURE__ */ k("button", {
|
|
134
|
+
type: "button",
|
|
135
|
+
onClick: () => J(!0),
|
|
136
|
+
className: "inline-flex items-center gap-2 rounded-md border border-border-seam bg-gloss-card px-3 py-2 text-sm font-medium text-text-primary shadow-pop hover:bg-bg-sunken",
|
|
137
|
+
children: [/* @__PURE__ */ O(T, { className: "h-4 w-4 text-action-primary-bg" }), "Batch AI Score"]
|
|
138
|
+
}), /* @__PURE__ */ k("button", {
|
|
139
|
+
type: "button",
|
|
140
|
+
onClick: () => K(!0),
|
|
141
|
+
className: "inline-flex items-center gap-2 rounded-md bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text shadow-pop hover:bg-action-primary-bg/90",
|
|
142
|
+
children: [/* @__PURE__ */ O(w, { className: "h-4 w-4" }), "New Lead"]
|
|
143
|
+
})]
|
|
135
144
|
}),
|
|
136
145
|
children: [
|
|
137
146
|
/* @__PURE__ */ O(_, {
|
|
138
|
-
open:
|
|
139
|
-
onClose: () =>
|
|
147
|
+
open: de,
|
|
148
|
+
onClose: () => K(!1),
|
|
140
149
|
contacts: Object.values(Y),
|
|
141
150
|
onCreated: R
|
|
142
151
|
}),
|
|
152
|
+
/* @__PURE__ */ O(ce, {
|
|
153
|
+
lead: fe,
|
|
154
|
+
onClose: () => q(null),
|
|
155
|
+
onApplied: R
|
|
156
|
+
}),
|
|
157
|
+
/* @__PURE__ */ O(se, {
|
|
158
|
+
open: pe,
|
|
159
|
+
totalAvailable: Q,
|
|
160
|
+
onClose: () => J(!1),
|
|
161
|
+
onCompleted: R
|
|
162
|
+
}),
|
|
143
163
|
/* @__PURE__ */ O(j, { children: "Track every prospect from first touch to qualified. See where each lead sits — new, contacted, qualified or disqualified — sort by lead score, and focus your follow-ups on the people most likely to convert." }),
|
|
144
164
|
/* @__PURE__ */ O(h, {
|
|
145
165
|
active: "leads",
|
|
146
166
|
basePath: B,
|
|
147
|
-
navigate:
|
|
167
|
+
navigate: le
|
|
148
168
|
}),
|
|
149
169
|
/* @__PURE__ */ O(ne, { kind: "lead" }),
|
|
150
170
|
/* @__PURE__ */ k(d, {
|
|
@@ -168,18 +188,18 @@ var M = [
|
|
|
168
188
|
}),
|
|
169
189
|
/* @__PURE__ */ O(a, {
|
|
170
190
|
title: "Avg Lead Score",
|
|
171
|
-
value:
|
|
172
|
-
icon: /* @__PURE__ */ O(
|
|
191
|
+
value: he,
|
|
192
|
+
icon: /* @__PURE__ */ O(C, { className: "h-5 w-5" })
|
|
173
193
|
}),
|
|
174
194
|
/* @__PURE__ */ O(a, {
|
|
175
195
|
title: "Conversion Rate",
|
|
176
|
-
value: `${
|
|
196
|
+
value: `${_e}%`,
|
|
177
197
|
icon: /* @__PURE__ */ O(E, { className: "h-5 w-5" })
|
|
178
198
|
}),
|
|
179
199
|
/* @__PURE__ */ O(a, {
|
|
180
200
|
title: "Hot Leads",
|
|
181
|
-
value:
|
|
182
|
-
icon: /* @__PURE__ */ O(
|
|
201
|
+
value: ge,
|
|
202
|
+
icon: /* @__PURE__ */ O(S, { className: "h-5 w-5" })
|
|
183
203
|
})
|
|
184
204
|
]
|
|
185
205
|
}) })
|
|
@@ -187,7 +207,7 @@ var M = [
|
|
|
187
207
|
title: "Score distribution",
|
|
188
208
|
subtitle: "Leads by score tier",
|
|
189
209
|
className: "xl:col-span-1",
|
|
190
|
-
children: /* @__PURE__ */ O(ie, { data:
|
|
210
|
+
children: /* @__PURE__ */ O(ie, { data: ve })
|
|
191
211
|
})]
|
|
192
212
|
}),
|
|
193
213
|
/* @__PURE__ */ O(u, {
|
|
@@ -225,7 +245,7 @@ var M = [
|
|
|
225
245
|
]
|
|
226
246
|
}), /* @__PURE__ */ O("select", {
|
|
227
247
|
value: G,
|
|
228
|
-
onChange: (e) =>
|
|
248
|
+
onChange: (e) => ue(e.target.value),
|
|
229
249
|
className: N,
|
|
230
250
|
"aria-label": "Filter by source",
|
|
231
251
|
children: M.map((e) => /* @__PURE__ */ O("option", {
|
|
@@ -319,7 +339,7 @@ var M = [
|
|
|
319
339
|
{
|
|
320
340
|
key: "assignedTo",
|
|
321
341
|
header: "Owner",
|
|
322
|
-
render: (e) =>
|
|
342
|
+
render: (e) => ye(e.assignedTo)
|
|
323
343
|
},
|
|
324
344
|
{
|
|
325
345
|
key: "createdAt",
|
|
@@ -333,21 +353,38 @@ var M = [
|
|
|
333
353
|
{
|
|
334
354
|
key: "actions",
|
|
335
355
|
header: "",
|
|
336
|
-
className: "w-
|
|
337
|
-
render: (e) =>
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
356
|
+
className: "w-36 text-right",
|
|
357
|
+
render: (e) => {
|
|
358
|
+
let t = `${e.firstName} ${e.lastName}`.trim() || e.title;
|
|
359
|
+
return /* @__PURE__ */ k("div", {
|
|
360
|
+
className: "flex items-center justify-end gap-1",
|
|
361
|
+
children: [
|
|
362
|
+
/* @__PURE__ */ k("button", {
|
|
363
|
+
type: "button",
|
|
364
|
+
onClick: () => q({
|
|
365
|
+
id: e.id,
|
|
366
|
+
name: t,
|
|
367
|
+
currentScore: e.score
|
|
368
|
+
}),
|
|
369
|
+
title: "Preview AI lead score",
|
|
370
|
+
className: "inline-flex items-center gap-1 rounded-md border border-border-subtle px-2 py-1 text-xs font-medium text-text-primary hover:bg-bg-sunken",
|
|
371
|
+
children: [/* @__PURE__ */ O(T, { className: "h-3.5 w-3.5 text-action-primary-bg" }), "AI Score"]
|
|
372
|
+
}),
|
|
373
|
+
/* @__PURE__ */ O(re, {
|
|
374
|
+
lead: {
|
|
375
|
+
id: e.id,
|
|
376
|
+
title: e.title
|
|
377
|
+
},
|
|
378
|
+
target: me,
|
|
379
|
+
onConverted: R
|
|
380
|
+
}),
|
|
381
|
+
/* @__PURE__ */ O(g, {
|
|
382
|
+
lead: e,
|
|
383
|
+
onChanged: R
|
|
384
|
+
})
|
|
385
|
+
]
|
|
386
|
+
});
|
|
387
|
+
}
|
|
351
388
|
}
|
|
352
389
|
],
|
|
353
390
|
pageSize: 10
|