@elevasis/ui 2.67.0 → 2.68.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/index.d.ts +1 -1
- package/dist/api/index.js +3 -3
- package/dist/app/index.d.ts +1 -6
- package/dist/app/index.js +15 -12
- package/dist/auth/index.js +10 -12
- package/dist/charts/index.js +10 -12
- package/dist/chunk-2MTP3H3A.js +425 -0
- package/dist/chunk-3KMDHCAR.js +52 -0
- package/dist/chunk-3MEXPLWT.js +265 -0
- package/dist/{chunk-XNW3O6QW.js → chunk-5NRJ2BLQ.js} +1 -1
- package/dist/chunk-75NOC536.js +2162 -0
- package/dist/chunk-76IVMVI3.js +1764 -0
- package/dist/chunk-AH52XQB7.js +1 -0
- package/dist/chunk-BZZCNLT6.js +12 -0
- package/dist/chunk-DLR4SDZW.js +51 -0
- package/dist/chunk-FK3K2VK2.js +2103 -0
- package/dist/chunk-GBXTRSAU.js +37 -0
- package/dist/chunk-HJVPVS57.js +1934 -0
- package/dist/{chunk-M535KHLW.js → chunk-JC5W55J3.js} +1 -1
- package/dist/{chunk-I7BZVVVU.js → chunk-L3HFJFYF.js} +89 -382
- package/dist/chunk-LGKLC5MG.js +44 -0
- package/dist/{chunk-4DV4ECMG.js → chunk-N7U24M2J.js} +4 -0
- package/dist/chunk-NDHMZT2G.js +383 -0
- package/dist/chunk-OOACTYRA.js +10 -0
- package/dist/chunk-PDHTXPSF.js +12 -0
- package/dist/chunk-QYI5BZKM.js +85 -0
- package/dist/{chunk-4OEVLV66.js → chunk-R6NMRXNO.js} +112 -147
- package/dist/chunk-SIVUCZXQ.js +1194 -0
- package/dist/{chunk-JFBZ6XDW.js → chunk-SNZDFCOQ.js} +3 -49
- package/dist/chunk-TGPJNKDU.js +1595 -0
- package/dist/chunk-TUMSNGTX.js +35 -0
- package/dist/chunk-TYKAKJGW.js +67 -0
- package/dist/chunk-UD657ICS.js +589 -0
- package/dist/chunk-WPIASV3H.js +194 -0
- package/dist/chunk-ZFISGKYW.js +39 -0
- package/dist/chunk-ZGCWTWBD.js +16127 -0
- package/dist/chunk-ZNKZMK2E.js +4528 -0
- package/dist/chunk-ZWS3TCQR.js +11032 -0
- package/dist/components/chat/index.js +2 -1
- package/dist/components/index.d.ts +23 -11
- package/dist/components/index.js +2773 -14
- package/dist/components/navigation/index.js +11 -12
- package/dist/features/auth/index.d.ts +0 -4
- package/dist/features/auth/index.js +12 -13
- package/dist/features/clients/index.js +14 -12
- package/dist/features/crm/index.d.ts +1371 -15
- package/dist/features/crm/index.js +15 -12
- package/dist/features/dashboard/index.d.ts +1 -2
- package/dist/features/dashboard/index.js +15 -12
- package/dist/features/delivery/index.d.ts +0 -4
- package/dist/features/delivery/index.js +15 -12
- package/dist/features/knowledge/index.js +10 -12
- package/dist/features/lead-gen/index.d.ts +35 -15
- package/dist/features/lead-gen/index.js +16 -12
- package/dist/features/monitoring/index.js +15 -12
- package/dist/features/monitoring/requests/index.js +13 -13
- package/dist/features/operations/index.d.ts +1 -2
- package/dist/features/operations/index.js +21 -12
- package/dist/features/public-agent-chat/index.js +2 -1
- package/dist/features/seo/index.js +2 -1
- package/dist/features/settings/index.d.ts +0 -4
- package/dist/features/settings/index.js +14 -12
- package/dist/hooks/access/index.js +10 -12
- package/dist/hooks/delivery/index.d.ts +0 -4
- package/dist/hooks/delivery/index.js +2 -23
- package/dist/hooks/index.d.ts +13 -7
- package/dist/hooks/index.js +10 -12
- package/dist/hooks/operations/command-view/utils/transformCommandViewData.d.ts +1 -2
- package/dist/hooks/published.d.ts +13 -7
- package/dist/hooks/published.js +10 -12
- package/dist/initialization/index.d.ts +1 -5
- package/dist/knowledge/index.d.ts +1 -2
- package/dist/knowledge/index.js +15 -13
- package/dist/layout/index.js +14 -12
- package/dist/organization/index.d.ts +3 -3
- package/dist/organization/index.js +1 -21
- package/dist/profile/index.d.ts +0 -4
- package/dist/provider/index.d.ts +2 -7
- package/dist/provider/index.js +10 -12
- package/dist/provider/published.d.ts +2 -7
- package/dist/provider/published.js +10 -12
- package/dist/supabase/index.d.ts +0 -8
- package/dist/test-utils/index.d.ts +5 -0
- package/dist/test-utils/index.js +5 -5
- package/dist/test-utils/setup-integration.js +1 -1
- package/dist/test-utils/setup.js +1 -1
- package/dist/theme/index.js +2 -1
- package/dist/typeform/index.js +2049 -1
- package/dist/types/index.d.ts +13 -7
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-5TERYXOO.js +0 -51390
- package/dist/chunk-AUDNF2Q7.js +0 -2050
- package/dist/index.css +0 -659
- package/dist/index.d.ts +0 -17888
- package/dist/index.js +0 -30
- package/dist/{chunk-GMXGDO3I.js → chunk-MISHPEJX.js} +1 -1
|
@@ -0,0 +1,1934 @@
|
|
|
1
|
+
import { CRM_API_INTERFACE } from './chunk-WPIASV3H.js';
|
|
2
|
+
import { PageContainer } from './chunk-BZZCNLT6.js';
|
|
3
|
+
import { TableSelectionToolbar, SortableHeader } from './chunk-TUMSNGTX.js';
|
|
4
|
+
import { FilterBar } from './chunk-PDHTXPSF.js';
|
|
5
|
+
import { CrmSidebarMiddle, useDealsSummary, useOptionalElevasisSystems, getCrmPipelineCatalog, CenteredErrorState, StatCard, PageTitleCaption, useDeleteDeal, usePaginationState, useDeals, useTableSort, sortData, useTableSelection, SubshellContentContainer, EmptyState, CustomModal, useDealDetail, useCrmActions, ActivityTimeline, useCompany, ContextViewer, JsonViewer, dealKeys, useContact, deriveActions, useExecuteAction } from './chunk-ZGCWTWBD.js';
|
|
6
|
+
import { showApiErrorNotification, showSuccessNotification } from './chunk-NDHMZT2G.js';
|
|
7
|
+
import { CardHeader } from './chunk-62GVNH5U.js';
|
|
8
|
+
import { SubshellSidebarSection } from './chunk-MISHPEJX.js';
|
|
9
|
+
import { computeInterfaceReadiness, getSystem, PAGE_SIZE_DEFAULT, formatTimeAgo } from './chunk-L3HFJFYF.js';
|
|
10
|
+
import { useElevasisServices } from './chunk-BI5VDO2K.js';
|
|
11
|
+
import { Stack, Paper, Center, Loader, Group, Box, Text, Alert, Table, SimpleGrid, Button, Select, TextInput, Tabs, Checkbox, Badge, Tooltip, Pagination, Title, Code, Card, SegmentedControl, Switch, NumberInput, ColorSwatch, Popover, ActionIcon, Anchor, CopyButton, Divider, Textarea } from '@mantine/core';
|
|
12
|
+
import { IconAddressBook, IconColumns, IconHistory, IconAlertCircle, IconCurrencyDollar, IconChartBar, IconBriefcase, IconTrophy, IconSearch, IconTargetArrow, IconAlertTriangle, IconMessages, IconArrowLeft, IconFileText, IconInbox, IconUser, IconBolt, IconBuilding, IconSettings, IconRestore, IconInfoCircle, IconMailForward, IconPlus, IconArrowRight, IconNote, IconCheck, IconCopy } from '@tabler/icons-react';
|
|
13
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
14
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
15
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
16
|
+
import { useNavigate } from '@tanstack/react-router';
|
|
17
|
+
import { useForm } from '@mantine/form';
|
|
18
|
+
|
|
19
|
+
var CrmSidebarTop = () => {
|
|
20
|
+
return /* @__PURE__ */ jsx(SubshellSidebarSection, { icon: IconAddressBook, label: "CRM" });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/lib/crm/pipeline.ts
|
|
24
|
+
function getCrmStageOptions(pipeline) {
|
|
25
|
+
return (pipeline?.stages ?? []).map((stage) => ({
|
|
26
|
+
value: stage.stageKey,
|
|
27
|
+
label: stage.label
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
function getCrmStageColors(pipeline) {
|
|
31
|
+
return (pipeline?.stages ?? []).reduce((colors, stage) => {
|
|
32
|
+
if (stage.color) colors[stage.stageKey] = stage.color;
|
|
33
|
+
return colors;
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
function getCrmStageLabel(pipeline, stageKey) {
|
|
37
|
+
const normalized = normalizeCatalogKey(stageKey);
|
|
38
|
+
if (!normalized) return "Unknown";
|
|
39
|
+
return pipeline?.stages.find((stage) => stage.stageKey.toLowerCase() === normalized.toLowerCase())?.label ?? formatReadableKey(normalized);
|
|
40
|
+
}
|
|
41
|
+
function getCrmStateLabel(pipeline, stateKey) {
|
|
42
|
+
const normalized = normalizeCatalogKey(stateKey);
|
|
43
|
+
if (!normalized) return "Unknown";
|
|
44
|
+
for (const stage of pipeline?.stages ?? []) {
|
|
45
|
+
const state = stage.states.find((candidate) => candidate.stateKey.toLowerCase() === normalized.toLowerCase());
|
|
46
|
+
if (state) return state.label;
|
|
47
|
+
}
|
|
48
|
+
return formatReadableKey(normalized);
|
|
49
|
+
}
|
|
50
|
+
function normalizeCatalogKey(value) {
|
|
51
|
+
const normalized = value?.trim();
|
|
52
|
+
return normalized ? normalized : null;
|
|
53
|
+
}
|
|
54
|
+
function formatReadableKey(value) {
|
|
55
|
+
const words = value.split("_").map((word) => word.trim().toLowerCase()).filter(Boolean);
|
|
56
|
+
if (!words.length) return "Unknown";
|
|
57
|
+
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/features/crm/pages/shared.ts
|
|
61
|
+
var DEAL_REFERRER_STORAGE_KEY = "crm:dealReferrer";
|
|
62
|
+
function setDealReferrer(referrer) {
|
|
63
|
+
if (typeof window === "undefined") return;
|
|
64
|
+
try {
|
|
65
|
+
window.sessionStorage.setItem(DEAL_REFERRER_STORAGE_KEY, referrer);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function getDealReferrer() {
|
|
70
|
+
if (typeof window === "undefined") return "deals";
|
|
71
|
+
try {
|
|
72
|
+
const value = window.sessionStorage.getItem(DEAL_REFERRER_STORAGE_KEY);
|
|
73
|
+
return value === "pipeline" ? "pipeline" : "deals";
|
|
74
|
+
} catch {
|
|
75
|
+
return "deals";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getDealStageColors(pipeline) {
|
|
79
|
+
return getCrmStageColors(pipeline);
|
|
80
|
+
}
|
|
81
|
+
function getDealStageOptions(pipeline) {
|
|
82
|
+
return getCrmStageOptions(pipeline).map((option) => ({
|
|
83
|
+
value: option.value,
|
|
84
|
+
label: option.label
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
var DEAL_PRIORITY_OPTIONS = [
|
|
88
|
+
{ value: "needs_response", label: "Needs response" },
|
|
89
|
+
{ value: "follow_up_due", label: "Follow-up due" },
|
|
90
|
+
{ value: "waiting", label: "Waiting" },
|
|
91
|
+
{ value: "stale", label: "Stale" },
|
|
92
|
+
{ value: "closed_low", label: "Closed low" }
|
|
93
|
+
];
|
|
94
|
+
function compareDealsByPriority(a, b, direction = "asc") {
|
|
95
|
+
const rankComparison = comparePriorityRank(a.priority, b.priority, direction);
|
|
96
|
+
if (rankComparison !== 0) return rankComparison;
|
|
97
|
+
const aActivity = getPriorityActivityTimestamp(a);
|
|
98
|
+
const bActivity = getPriorityActivityTimestamp(b);
|
|
99
|
+
return bActivity - aActivity;
|
|
100
|
+
}
|
|
101
|
+
function compareDealsByPriorityThenUpdated(a, b, direction = "asc") {
|
|
102
|
+
const rankComparison = comparePriorityRank(a.priority, b.priority, direction);
|
|
103
|
+
if (rankComparison !== 0) return rankComparison;
|
|
104
|
+
return getUpdatedTimestamp(b) - getUpdatedTimestamp(a);
|
|
105
|
+
}
|
|
106
|
+
function formatDealStageLabel(pipeline, stage) {
|
|
107
|
+
return getCrmStageLabel(pipeline, stage);
|
|
108
|
+
}
|
|
109
|
+
function formatDealStateLabel(pipeline, state) {
|
|
110
|
+
return getCrmStateLabel(pipeline, state);
|
|
111
|
+
}
|
|
112
|
+
function comparePriorityRank(a, b, direction) {
|
|
113
|
+
const comparison = a.rank - b.rank;
|
|
114
|
+
return direction === "asc" ? comparison : -comparison;
|
|
115
|
+
}
|
|
116
|
+
function getPriorityActivityTimestamp(deal) {
|
|
117
|
+
const value = deal.priority.latestActivityAt ?? deal.updated_at;
|
|
118
|
+
const timestamp = new Date(value).getTime();
|
|
119
|
+
return Number.isNaN(timestamp) ? 0 : timestamp;
|
|
120
|
+
}
|
|
121
|
+
function getUpdatedTimestamp(deal) {
|
|
122
|
+
const timestamp = new Date(deal.updated_at).getTime();
|
|
123
|
+
return Number.isNaN(timestamp) ? 0 : timestamp;
|
|
124
|
+
}
|
|
125
|
+
function buildBookingUrl(baseUrl, opts = {}) {
|
|
126
|
+
if (!baseUrl) return void 0;
|
|
127
|
+
const params = new URLSearchParams();
|
|
128
|
+
if (opts.dealId) params.set("dealId", opts.dealId);
|
|
129
|
+
if (opts.contactId) params.set("contactId", opts.contactId);
|
|
130
|
+
return params.size > 0 ? `${baseUrl}?${params.toString()}` : baseUrl;
|
|
131
|
+
}
|
|
132
|
+
var CrmSidebar = ({ children } = {}) => {
|
|
133
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: 0, style: { height: "100%", display: "flex", flexDirection: "column" }, children: [
|
|
134
|
+
/* @__PURE__ */ jsx(CrmSidebarTop, {}),
|
|
135
|
+
children ?? /* @__PURE__ */ jsx(CrmSidebarMiddle, {})
|
|
136
|
+
] });
|
|
137
|
+
};
|
|
138
|
+
var PIPELINE_FUNNEL_ORDER = [
|
|
139
|
+
"interested",
|
|
140
|
+
"proposal",
|
|
141
|
+
"closing",
|
|
142
|
+
"closed_won",
|
|
143
|
+
"closed_lost",
|
|
144
|
+
"nurturing"
|
|
145
|
+
];
|
|
146
|
+
function useCrmPipelineSummary(opts) {
|
|
147
|
+
const { data: summary, isLoading, error } = useDealsSummary();
|
|
148
|
+
const data = useMemo(() => {
|
|
149
|
+
const stageMap = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const stage of PIPELINE_FUNNEL_ORDER) {
|
|
151
|
+
stageMap.set(stage, { count: 0, totalValue: 0 });
|
|
152
|
+
}
|
|
153
|
+
for (const stageSummary of summary?.stageSummary ?? []) {
|
|
154
|
+
const stage = stageSummary.stage;
|
|
155
|
+
if (!stageMap.has(stage)) continue;
|
|
156
|
+
const entry = stageMap.get(stage);
|
|
157
|
+
entry.count = stageSummary.count;
|
|
158
|
+
entry.totalValue = typeof stageSummary.totalValue === "number" ? stageSummary.totalValue : 0;
|
|
159
|
+
}
|
|
160
|
+
return PIPELINE_FUNNEL_ORDER.map((stage) => {
|
|
161
|
+
const entry = stageMap.get(stage);
|
|
162
|
+
return { stage, count: entry.count, totalValue: entry.totalValue };
|
|
163
|
+
});
|
|
164
|
+
}, [summary, opts]);
|
|
165
|
+
return { data, isLoading, error };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/features/crm/overview/hooks/useCrmQuickMetrics.ts
|
|
169
|
+
var ZERO_METRICS = {
|
|
170
|
+
totalDeals: 0,
|
|
171
|
+
openDeals: 0,
|
|
172
|
+
wonDeals: 0,
|
|
173
|
+
winRate: 0,
|
|
174
|
+
avgDealSize: 0,
|
|
175
|
+
totalPipelineValue: 0
|
|
176
|
+
};
|
|
177
|
+
function useCrmQuickMetrics() {
|
|
178
|
+
const { data: summary, isLoading, error } = useDealsSummary();
|
|
179
|
+
const data = summary ? {
|
|
180
|
+
totalDeals: summary.totalDeals,
|
|
181
|
+
openDeals: summary.openDeals,
|
|
182
|
+
wonDeals: summary.wonDeals,
|
|
183
|
+
winRate: summary.winRate,
|
|
184
|
+
avgDealSize: summary.avgDealSize,
|
|
185
|
+
totalPipelineValue: summary.totalPipelineValue
|
|
186
|
+
} : ZERO_METRICS;
|
|
187
|
+
return { data, isLoading, error };
|
|
188
|
+
}
|
|
189
|
+
function useRecentCrmActivity(opts) {
|
|
190
|
+
const { apiRequest, isReady, workOSOrganizationId } = useElevasisServices();
|
|
191
|
+
const limit = opts?.limit ?? 20;
|
|
192
|
+
const query = useQuery({
|
|
193
|
+
queryKey: ["recent-crm-activity", workOSOrganizationId, limit],
|
|
194
|
+
queryFn: () => apiRequest(`/crm/recent-activity?limit=${limit}`),
|
|
195
|
+
enabled: isReady
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
data: query.data?.entries ?? [],
|
|
199
|
+
isLoading: query.isLoading,
|
|
200
|
+
error: query.error
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function summarizeReadinessIssues(issues) {
|
|
204
|
+
return issues[0]?.message;
|
|
205
|
+
}
|
|
206
|
+
function getCrmApiInterfaceReadiness(model) {
|
|
207
|
+
if (!model) {
|
|
208
|
+
return {
|
|
209
|
+
systemPath: CRM_API_INTERFACE.systemPath,
|
|
210
|
+
interfaceKey: CRM_API_INTERFACE.interfaceKey,
|
|
211
|
+
readinessProfile: CRM_API_INTERFACE.readinessProfile,
|
|
212
|
+
declared: false,
|
|
213
|
+
ready: false,
|
|
214
|
+
reason: "No Organization Model is available for CRM System Interface readiness.",
|
|
215
|
+
issues: [
|
|
216
|
+
{
|
|
217
|
+
family: "SYSTEM_INTERFACE_MISSING",
|
|
218
|
+
code: "missing-organization-model",
|
|
219
|
+
message: "No Organization Model is available for CRM System Interface readiness."
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const readiness = computeInterfaceReadiness(model, CRM_API_INTERFACE);
|
|
225
|
+
return {
|
|
226
|
+
systemPath: CRM_API_INTERFACE.systemPath,
|
|
227
|
+
interfaceKey: CRM_API_INTERFACE.interfaceKey,
|
|
228
|
+
readinessProfile: readiness.readinessProfile,
|
|
229
|
+
declared: getSystem(model, CRM_API_INTERFACE.systemPath)?.apiInterface !== void 0,
|
|
230
|
+
ready: readiness.ready,
|
|
231
|
+
reason: summarizeReadinessIssues(readiness.issues),
|
|
232
|
+
issues: readiness.issues
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function useCrmPipelineConfig() {
|
|
236
|
+
const systems = useOptionalElevasisSystems();
|
|
237
|
+
const organizationModel = systems?.organizationModel;
|
|
238
|
+
return useMemo(() => {
|
|
239
|
+
const crmApiInterface = getCrmApiInterfaceReadiness(organizationModel);
|
|
240
|
+
const interfaceState = {
|
|
241
|
+
crmApiInterface,
|
|
242
|
+
canUseCrmApiActions: crmApiInterface.ready
|
|
243
|
+
};
|
|
244
|
+
if (!organizationModel) return { pipeline: void 0, ...interfaceState };
|
|
245
|
+
return {
|
|
246
|
+
pipeline: getCrmPipelineCatalog(organizationModel),
|
|
247
|
+
...interfaceState
|
|
248
|
+
};
|
|
249
|
+
}, [organizationModel]);
|
|
250
|
+
}
|
|
251
|
+
var STAGE_LABELS = {
|
|
252
|
+
interested: "Interested",
|
|
253
|
+
proposal: "Proposal",
|
|
254
|
+
closing: "Closing",
|
|
255
|
+
closed_won: "Closed Won",
|
|
256
|
+
closed_lost: "Closed Lost",
|
|
257
|
+
nurturing: "Nurturing"
|
|
258
|
+
};
|
|
259
|
+
function PipelineFunnelWidget({ onStageClick, getDealValue }) {
|
|
260
|
+
const { data, isLoading, error } = useCrmPipelineSummary({ getDealValue });
|
|
261
|
+
const { pipeline } = useCrmPipelineConfig();
|
|
262
|
+
const stageColors = getDealStageColors(pipeline);
|
|
263
|
+
if (isLoading) {
|
|
264
|
+
return /* @__PURE__ */ jsx(Paper, { withBorder: true, p: "md", children: /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) });
|
|
265
|
+
}
|
|
266
|
+
if (error) {
|
|
267
|
+
return /* @__PURE__ */ jsx(Paper, { withBorder: true, p: "md", children: /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load pipeline data" }) });
|
|
268
|
+
}
|
|
269
|
+
const totalDeals = data.reduce((sum, s) => sum + s.count, 0);
|
|
270
|
+
return /* @__PURE__ */ jsxs(Paper, { withBorder: true, p: "md", children: [
|
|
271
|
+
/* @__PURE__ */ jsx(
|
|
272
|
+
CardHeader,
|
|
273
|
+
{
|
|
274
|
+
icon: /* @__PURE__ */ jsx(IconColumns, { size: 16 }),
|
|
275
|
+
title: "Pipeline",
|
|
276
|
+
subtitle: totalDeals === 0 ? "No deals in the pipeline yet" : `${totalDeals} deal${totalDeals !== 1 ? "s" : ""} total`
|
|
277
|
+
}
|
|
278
|
+
),
|
|
279
|
+
/* @__PURE__ */ jsx(Group, { gap: "lg", wrap: "nowrap", mt: "md", children: PIPELINE_FUNNEL_ORDER.map((stage) => {
|
|
280
|
+
const summary = data.find((s) => s.stage === stage);
|
|
281
|
+
const isEmpty = summary.count === 0;
|
|
282
|
+
const stageColor = stageColors[stage] ?? "gray";
|
|
283
|
+
const accent = `var(--mantine-color-${stageColor}-6)`;
|
|
284
|
+
return /* @__PURE__ */ jsxs(
|
|
285
|
+
Box,
|
|
286
|
+
{
|
|
287
|
+
onClick: () => onStageClick(stage),
|
|
288
|
+
style: {
|
|
289
|
+
flex: 1,
|
|
290
|
+
minWidth: 0,
|
|
291
|
+
cursor: "pointer",
|
|
292
|
+
padding: "4px 0"
|
|
293
|
+
},
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsxs(Group, { gap: 8, wrap: "nowrap", align: "center", mb: 6, children: [
|
|
296
|
+
/* @__PURE__ */ jsx(
|
|
297
|
+
Box,
|
|
298
|
+
{
|
|
299
|
+
style: {
|
|
300
|
+
width: 8,
|
|
301
|
+
height: 8,
|
|
302
|
+
borderRadius: "50%",
|
|
303
|
+
background: accent,
|
|
304
|
+
flexShrink: 0
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
),
|
|
308
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", truncate: true, children: STAGE_LABELS[stage] })
|
|
309
|
+
] }),
|
|
310
|
+
/* @__PURE__ */ jsx(Text, { size: "xl", fw: 600, c: isEmpty ? "dimmed" : void 0, lh: 1, children: summary.count })
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
stage
|
|
314
|
+
);
|
|
315
|
+
}) })
|
|
316
|
+
] });
|
|
317
|
+
}
|
|
318
|
+
function ActivityKindIcon({ kind }) {
|
|
319
|
+
const size = 16;
|
|
320
|
+
switch (kind) {
|
|
321
|
+
case "note":
|
|
322
|
+
return /* @__PURE__ */ jsx(IconNote, { size });
|
|
323
|
+
case "stage_change":
|
|
324
|
+
return /* @__PURE__ */ jsx(IconArrowRight, { size });
|
|
325
|
+
case "deal_created":
|
|
326
|
+
return /* @__PURE__ */ jsx(IconPlus, { size });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function formatRelativeTime(occurredAt) {
|
|
330
|
+
const date = new Date(occurredAt);
|
|
331
|
+
const now = /* @__PURE__ */ new Date();
|
|
332
|
+
const diffMs = now.getTime() - date.getTime();
|
|
333
|
+
const diffMin = Math.floor(diffMs / 6e4);
|
|
334
|
+
const diffHr = Math.floor(diffMin / 60);
|
|
335
|
+
const diffDay = Math.floor(diffHr / 24);
|
|
336
|
+
if (diffMin < 1) return "just now";
|
|
337
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
338
|
+
if (diffHr < 24) return `${diffHr}h ago`;
|
|
339
|
+
if (diffDay < 7) return `${diffDay}d ago`;
|
|
340
|
+
return date.toLocaleDateString();
|
|
341
|
+
}
|
|
342
|
+
function ActivityFeedWidget({ onDealClick, limit }) {
|
|
343
|
+
const { data, isLoading, error } = useRecentCrmActivity({ limit: limit ?? 15 });
|
|
344
|
+
if (isLoading) {
|
|
345
|
+
return /* @__PURE__ */ jsx(Paper, { withBorder: true, p: "md", children: /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) });
|
|
346
|
+
}
|
|
347
|
+
if (error) {
|
|
348
|
+
return /* @__PURE__ */ jsx(Paper, { withBorder: true, p: "md", children: /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load activity" }) });
|
|
349
|
+
}
|
|
350
|
+
if (!data.length) {
|
|
351
|
+
return /* @__PURE__ */ jsxs(Paper, { withBorder: true, p: "md", children: [
|
|
352
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconHistory, { size: 16 }), title: "Recent Activity" }),
|
|
353
|
+
/* @__PURE__ */ jsx(Center, { h: 120, children: /* @__PURE__ */ jsx(Alert, { icon: /* @__PURE__ */ jsx(IconAlertCircle, {}), color: "gray", variant: "light", children: "No recent activity" }) })
|
|
354
|
+
] });
|
|
355
|
+
}
|
|
356
|
+
return /* @__PURE__ */ jsx(Paper, { withBorder: true, p: "md", children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
357
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconHistory, { size: 16 }), title: "Recent Activity" }),
|
|
358
|
+
/* @__PURE__ */ jsxs(Table, { highlightOnHover: true, style: { tableLayout: "fixed", width: "100%" }, children: [
|
|
359
|
+
/* @__PURE__ */ jsx(Table.Thead, { children: /* @__PURE__ */ jsxs(Table.Tr, { children: [
|
|
360
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 40 }),
|
|
361
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 220, children: "Name" }),
|
|
362
|
+
/* @__PURE__ */ jsx(Table.Th, { children: "Activity" }),
|
|
363
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 120, children: "When" })
|
|
364
|
+
] }) }),
|
|
365
|
+
/* @__PURE__ */ jsx(Table.Tbody, { children: data.map((entry) => {
|
|
366
|
+
const name = entry.contactName ?? entry.companyName ?? "Unknown";
|
|
367
|
+
return /* @__PURE__ */ jsxs(Table.Tr, { style: { cursor: "pointer" }, onClick: () => onDealClick(entry.dealId), children: [
|
|
368
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { c: "dimmed", component: "span", children: /* @__PURE__ */ jsx(ActivityKindIcon, { kind: entry.kind }) }) }),
|
|
369
|
+
/* @__PURE__ */ jsx(Table.Td, { style: { maxWidth: 220 }, children: /* @__PURE__ */ jsx(Text, { size: "sm", fw: 500, truncate: true, title: name, style: { minWidth: 0 }, children: name }) }),
|
|
370
|
+
/* @__PURE__ */ jsx(Table.Td, { style: { minWidth: 0 }, children: /* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", truncate: true, title: entry.description, style: { minWidth: 0 }, children: entry.description }) }),
|
|
371
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", style: { whiteSpace: "nowrap" }, children: formatRelativeTime(entry.occurredAt) }) })
|
|
372
|
+
] }, entry.id);
|
|
373
|
+
}) })
|
|
374
|
+
] })
|
|
375
|
+
] }) });
|
|
376
|
+
}
|
|
377
|
+
var currencyFormatter = new Intl.NumberFormat("en-US", {
|
|
378
|
+
style: "currency",
|
|
379
|
+
currency: "USD",
|
|
380
|
+
maximumFractionDigits: 0
|
|
381
|
+
});
|
|
382
|
+
function formatPercent(value) {
|
|
383
|
+
return `${Math.round(value * 100)}%`;
|
|
384
|
+
}
|
|
385
|
+
function MetricsStrip() {
|
|
386
|
+
const { data, isLoading } = useCrmQuickMetrics();
|
|
387
|
+
return /* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 2, sm: 4 }, children: [
|
|
388
|
+
/* @__PURE__ */ jsx(
|
|
389
|
+
StatCard,
|
|
390
|
+
{
|
|
391
|
+
variant: "hero",
|
|
392
|
+
icon: IconCurrencyDollar,
|
|
393
|
+
value: currencyFormatter.format(data.totalPipelineValue),
|
|
394
|
+
label: "Total Pipeline Value",
|
|
395
|
+
isLoading
|
|
396
|
+
}
|
|
397
|
+
),
|
|
398
|
+
/* @__PURE__ */ jsx(
|
|
399
|
+
StatCard,
|
|
400
|
+
{
|
|
401
|
+
variant: "hero",
|
|
402
|
+
icon: IconChartBar,
|
|
403
|
+
value: formatPercent(data.winRate),
|
|
404
|
+
label: "Win Rate",
|
|
405
|
+
isLoading
|
|
406
|
+
}
|
|
407
|
+
),
|
|
408
|
+
/* @__PURE__ */ jsx(
|
|
409
|
+
StatCard,
|
|
410
|
+
{
|
|
411
|
+
variant: "hero",
|
|
412
|
+
icon: IconBriefcase,
|
|
413
|
+
value: String(data.openDeals),
|
|
414
|
+
label: "Open Deals",
|
|
415
|
+
isLoading
|
|
416
|
+
}
|
|
417
|
+
),
|
|
418
|
+
/* @__PURE__ */ jsx(
|
|
419
|
+
StatCard,
|
|
420
|
+
{
|
|
421
|
+
variant: "hero",
|
|
422
|
+
icon: IconTrophy,
|
|
423
|
+
value: String(data.wonDeals),
|
|
424
|
+
label: "Won This Period",
|
|
425
|
+
isLoading
|
|
426
|
+
}
|
|
427
|
+
)
|
|
428
|
+
] });
|
|
429
|
+
}
|
|
430
|
+
function CrmOverview({
|
|
431
|
+
onStageClick,
|
|
432
|
+
onDealClick,
|
|
433
|
+
onGoToPipeline,
|
|
434
|
+
getDealValue,
|
|
435
|
+
renderActions
|
|
436
|
+
}) {
|
|
437
|
+
const rightSection = renderActions ? renderActions() : /* @__PURE__ */ jsx(Button, { leftSection: /* @__PURE__ */ jsx(IconColumns, { size: 16 }), variant: "light", size: "xs", onClick: onGoToPipeline, children: "Go to Pipeline" });
|
|
438
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
439
|
+
/* @__PURE__ */ jsx(
|
|
440
|
+
PageTitleCaption,
|
|
441
|
+
{
|
|
442
|
+
title: "CRM Overview",
|
|
443
|
+
caption: "Pipeline health, tasks, and recent activity at a glance.",
|
|
444
|
+
rightSection
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
/* @__PURE__ */ jsx(MetricsStrip, {}),
|
|
448
|
+
/* @__PURE__ */ jsx(PipelineFunnelWidget, { onStageClick, getDealValue }),
|
|
449
|
+
/* @__PURE__ */ jsx(ActivityFeedWidget, { onDealClick })
|
|
450
|
+
] });
|
|
451
|
+
}
|
|
452
|
+
var sortAccessors = {
|
|
453
|
+
company: (deal) => deal.contact?.company?.name || deal.discovery_data?.company || deal.contact_email?.split("@")[1] || "",
|
|
454
|
+
contact: (deal) => [deal.contact?.first_name, deal.contact?.last_name].filter(Boolean).join(" ") || "",
|
|
455
|
+
email: (deal) => deal.contact_email || "",
|
|
456
|
+
stage: (deal) => deal.stage_key || "",
|
|
457
|
+
state: (deal) => deal.state_key || "",
|
|
458
|
+
ownership: (deal) => deal.ownership || "",
|
|
459
|
+
updated: (deal) => deal.updated_at || ""
|
|
460
|
+
};
|
|
461
|
+
var DEAL_OWNERSHIP_BADGE_COPY = {
|
|
462
|
+
us: {
|
|
463
|
+
color: "red",
|
|
464
|
+
label: "Our move",
|
|
465
|
+
tooltip: "We owe the next move"
|
|
466
|
+
},
|
|
467
|
+
them: {
|
|
468
|
+
color: "gray",
|
|
469
|
+
label: "Their move",
|
|
470
|
+
tooltip: "Lead owes the next move"
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
function DealsListPage() {
|
|
474
|
+
const navigate = useNavigate();
|
|
475
|
+
const deleteDeal = useDeleteDeal();
|
|
476
|
+
const { pipeline } = useCrmPipelineConfig();
|
|
477
|
+
const stageOptions = useMemo(() => getDealStageOptions(pipeline), [pipeline]);
|
|
478
|
+
const stageColors = useMemo(() => getDealStageColors(pipeline), [pipeline]);
|
|
479
|
+
const [stageFilter, setStageFilter] = useState(null);
|
|
480
|
+
const [priorityFilter, setPriorityFilter] = useState("all");
|
|
481
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
482
|
+
const [showBatchDelete, setShowBatchDelete] = useState(false);
|
|
483
|
+
const pagination = usePaginationState(PAGE_SIZE_DEFAULT, [stageFilter, priorityFilter, searchQuery]);
|
|
484
|
+
const {
|
|
485
|
+
data: deals,
|
|
486
|
+
total,
|
|
487
|
+
isLoading,
|
|
488
|
+
error
|
|
489
|
+
} = useDeals({
|
|
490
|
+
stage: stageFilter || void 0,
|
|
491
|
+
search: searchQuery || void 0,
|
|
492
|
+
limit: PAGE_SIZE_DEFAULT,
|
|
493
|
+
offset: pagination.offset
|
|
494
|
+
});
|
|
495
|
+
const { sort, toggleSort } = useTableSort("priority", "asc");
|
|
496
|
+
const sortedDeals = useMemo(() => {
|
|
497
|
+
const filteredDeals = priorityFilter === "all" ? deals ?? [] : (deals ?? []).filter((deal) => deal.priority.bucketKey === priorityFilter);
|
|
498
|
+
if (sort.column === "priority") {
|
|
499
|
+
return [...filteredDeals].sort((a, b) => compareDealsByPriorityThenUpdated(a, b, sort.direction));
|
|
500
|
+
}
|
|
501
|
+
return sortData(filteredDeals, sort, sortAccessors);
|
|
502
|
+
}, [deals, priorityFilter, sort]);
|
|
503
|
+
const selection = useTableSelection(sortedDeals, sortedDeals);
|
|
504
|
+
const handleDeleteSelected = async () => {
|
|
505
|
+
await Promise.all([...selection.selectedIds].map((dealId) => deleteDeal.mutateAsync(dealId)));
|
|
506
|
+
setShowBatchDelete(false);
|
|
507
|
+
selection.clear();
|
|
508
|
+
};
|
|
509
|
+
return /* @__PURE__ */ jsxs(SubshellContentContainer, { children: [
|
|
510
|
+
/* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
511
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title: "Deals", caption: "Deal pipeline and stage tracking" }) }),
|
|
512
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
513
|
+
/* @__PURE__ */ jsxs(
|
|
514
|
+
FilterBar,
|
|
515
|
+
{
|
|
516
|
+
actions: /* @__PURE__ */ jsx(
|
|
517
|
+
TableSelectionToolbar,
|
|
518
|
+
{
|
|
519
|
+
selectedCount: selection.selectedCount,
|
|
520
|
+
onDelete: () => setShowBatchDelete(true),
|
|
521
|
+
isDeleting: deleteDeal.isPending
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
children: [
|
|
525
|
+
/* @__PURE__ */ jsx(
|
|
526
|
+
Select,
|
|
527
|
+
{
|
|
528
|
+
placeholder: "All Stages",
|
|
529
|
+
data: stageOptions,
|
|
530
|
+
style: { minWidth: 180 },
|
|
531
|
+
size: "sm",
|
|
532
|
+
clearable: true,
|
|
533
|
+
value: stageFilter,
|
|
534
|
+
onChange: (value) => setStageFilter(value ?? null)
|
|
535
|
+
}
|
|
536
|
+
),
|
|
537
|
+
/* @__PURE__ */ jsx(
|
|
538
|
+
TextInput,
|
|
539
|
+
{
|
|
540
|
+
placeholder: "Search by email...",
|
|
541
|
+
leftSection: /* @__PURE__ */ jsx(IconSearch, { size: 16 }),
|
|
542
|
+
style: { minWidth: 250 },
|
|
543
|
+
size: "sm",
|
|
544
|
+
value: searchQuery,
|
|
545
|
+
onChange: (e) => setSearchQuery(e.currentTarget.value)
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
),
|
|
551
|
+
/* @__PURE__ */ jsx(
|
|
552
|
+
Tabs,
|
|
553
|
+
{
|
|
554
|
+
value: priorityFilter,
|
|
555
|
+
onChange: (value) => setPriorityFilter(value ?? "all"),
|
|
556
|
+
children: /* @__PURE__ */ jsxs(Tabs.List, { children: [
|
|
557
|
+
/* @__PURE__ */ jsx(Tabs.Tab, { value: "all", children: "All priorities" }),
|
|
558
|
+
DEAL_PRIORITY_OPTIONS.map((option) => /* @__PURE__ */ jsx(Tabs.Tab, { value: option.value, children: option.label }, option.value))
|
|
559
|
+
] })
|
|
560
|
+
}
|
|
561
|
+
),
|
|
562
|
+
isLoading ? /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) : error ? /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load deals" }) : !sortedDeals.length ? /* @__PURE__ */ jsx(EmptyState, { icon: IconTargetArrow, title: "No deals found" }) : /* @__PURE__ */ jsxs(Table, { style: { tableLayout: "fixed" }, children: [
|
|
563
|
+
/* @__PURE__ */ jsx(Table.Thead, { children: /* @__PURE__ */ jsxs(Table.Tr, { children: [
|
|
564
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 40, children: /* @__PURE__ */ jsx(
|
|
565
|
+
Checkbox,
|
|
566
|
+
{
|
|
567
|
+
checked: selection.isPageAllSelected,
|
|
568
|
+
indeterminate: selection.isPagePartiallySelected,
|
|
569
|
+
onChange: selection.togglePage
|
|
570
|
+
}
|
|
571
|
+
) }),
|
|
572
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "company", sort, onToggle: toggleSort, children: "Company" }),
|
|
573
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "contact", sort, onToggle: toggleSort, children: "Contact" }),
|
|
574
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "email", sort, onToggle: toggleSort, children: "Email" }),
|
|
575
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "stage", sort, onToggle: toggleSort, w: 120, children: "Stage" }),
|
|
576
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "state", sort, onToggle: toggleSort, w: 160, children: "State" }),
|
|
577
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "ownership", sort, onToggle: toggleSort, w: 100, children: "Move" }),
|
|
578
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "priority", sort, onToggle: toggleSort, w: 140, children: "Priority" }),
|
|
579
|
+
/* @__PURE__ */ jsx(SortableHeader, { column: "updated", sort, onToggle: toggleSort, w: 100, children: "Updated" })
|
|
580
|
+
] }) }),
|
|
581
|
+
/* @__PURE__ */ jsx(Table.Tbody, { children: sortedDeals.map((deal) => {
|
|
582
|
+
const discoveryData = deal.discovery_data;
|
|
583
|
+
const companyName = deal.contact?.company?.name || discoveryData?.company || deal.contact_email?.split("@")[1] || "-";
|
|
584
|
+
const contactName = [deal.contact?.first_name, deal.contact?.last_name].filter(Boolean).join(" ");
|
|
585
|
+
const ownershipBadge = deal.ownership ? DEAL_OWNERSHIP_BADGE_COPY[deal.ownership] : null;
|
|
586
|
+
return /* @__PURE__ */ jsxs(
|
|
587
|
+
Table.Tr,
|
|
588
|
+
{
|
|
589
|
+
style: { cursor: "pointer" },
|
|
590
|
+
onClick: () => {
|
|
591
|
+
setDealReferrer("deals");
|
|
592
|
+
navigate({
|
|
593
|
+
to: "/crm/deals/$dealId",
|
|
594
|
+
params: { dealId: deal.id }
|
|
595
|
+
});
|
|
596
|
+
},
|
|
597
|
+
children: [
|
|
598
|
+
/* @__PURE__ */ jsx(Table.Td, { onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx(
|
|
599
|
+
Checkbox,
|
|
600
|
+
{
|
|
601
|
+
checked: selection.isSelected(deal.id),
|
|
602
|
+
onChange: () => selection.toggle(deal.id)
|
|
603
|
+
}
|
|
604
|
+
) }),
|
|
605
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { fw: 500, lineClamp: 1, children: companyName }) }),
|
|
606
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { size: "sm", lineClamp: 1, children: contactName || "-" }) }),
|
|
607
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", lineClamp: 1, children: deal.contact_email || "-" }) }),
|
|
608
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Badge, { variant: "light", color: stageColors[deal.stage_key || ""] || "gray", size: "sm", children: formatDealStageLabel(pipeline, deal.stage_key) }) }),
|
|
609
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(
|
|
610
|
+
Badge,
|
|
611
|
+
{
|
|
612
|
+
variant: "light",
|
|
613
|
+
color: deal.state_key ? "gray" : "dark",
|
|
614
|
+
size: "sm",
|
|
615
|
+
style: { maxWidth: "100%", textTransform: "none" },
|
|
616
|
+
children: /* @__PURE__ */ jsx(Text, { span: true, size: "xs", truncate: "end", style: { maxWidth: "100%" }, children: formatDealStateLabel(pipeline, deal.state_key) })
|
|
617
|
+
}
|
|
618
|
+
) }),
|
|
619
|
+
/* @__PURE__ */ jsx(Table.Td, { children: ownershipBadge ? /* @__PURE__ */ jsx(Tooltip, { label: ownershipBadge.tooltip, withArrow: true, children: /* @__PURE__ */ jsx(
|
|
620
|
+
Badge,
|
|
621
|
+
{
|
|
622
|
+
variant: "light",
|
|
623
|
+
color: ownershipBadge.color,
|
|
624
|
+
size: "sm",
|
|
625
|
+
style: { maxWidth: "100%", textTransform: "none" },
|
|
626
|
+
children: /* @__PURE__ */ jsx(Text, { span: true, size: "xs", truncate: "end", style: { maxWidth: "100%" }, children: ownershipBadge.label })
|
|
627
|
+
}
|
|
628
|
+
) }) : /* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", children: "-" }) }),
|
|
629
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Tooltip, { label: deal.priority.reason, withArrow: true, children: /* @__PURE__ */ jsx(
|
|
630
|
+
Badge,
|
|
631
|
+
{
|
|
632
|
+
variant: "light",
|
|
633
|
+
color: deal.priority.color,
|
|
634
|
+
size: "sm",
|
|
635
|
+
style: { maxWidth: "100%", textTransform: "none" },
|
|
636
|
+
children: /* @__PURE__ */ jsx(Text, { span: true, size: "xs", truncate: "end", style: { maxWidth: "100%" }, children: deal.priority.label })
|
|
637
|
+
}
|
|
638
|
+
) }) }),
|
|
639
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", lineClamp: 1, children: formatTimeAgo(deal.updated_at) }) })
|
|
640
|
+
]
|
|
641
|
+
},
|
|
642
|
+
deal.id
|
|
643
|
+
);
|
|
644
|
+
}) })
|
|
645
|
+
] }),
|
|
646
|
+
total > PAGE_SIZE_DEFAULT && /* @__PURE__ */ jsx(Group, { justify: "flex-start", children: /* @__PURE__ */ jsx(
|
|
647
|
+
Pagination,
|
|
648
|
+
{
|
|
649
|
+
value: pagination.page,
|
|
650
|
+
onChange: pagination.setPage,
|
|
651
|
+
total: pagination.totalPages(total),
|
|
652
|
+
size: "sm"
|
|
653
|
+
}
|
|
654
|
+
) })
|
|
655
|
+
] }) })
|
|
656
|
+
] }),
|
|
657
|
+
/* @__PURE__ */ jsx(
|
|
658
|
+
CustomModal,
|
|
659
|
+
{
|
|
660
|
+
opened: showBatchDelete,
|
|
661
|
+
onClose: () => !deleteDeal.isPending && setShowBatchDelete(false),
|
|
662
|
+
size: "sm",
|
|
663
|
+
loading: deleteDeal.isPending,
|
|
664
|
+
children: /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
665
|
+
/* @__PURE__ */ jsxs(Group, { gap: "sm", children: [
|
|
666
|
+
/* @__PURE__ */ jsx(IconAlertTriangle, { size: 24, color: "var(--color-error)" }),
|
|
667
|
+
/* @__PURE__ */ jsxs(Title, { order: 4, children: [
|
|
668
|
+
"Delete ",
|
|
669
|
+
selection.selectedCount,
|
|
670
|
+
" Deals"
|
|
671
|
+
] })
|
|
672
|
+
] }),
|
|
673
|
+
/* @__PURE__ */ jsxs(Text, { size: "sm", children: [
|
|
674
|
+
"Are you sure you want to delete",
|
|
675
|
+
" ",
|
|
676
|
+
/* @__PURE__ */ jsx(Text, { span: true, fw: 600, children: selection.selectedCount }),
|
|
677
|
+
" ",
|
|
678
|
+
"selected deals?"
|
|
679
|
+
] }),
|
|
680
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", children: "This action cannot be undone." }),
|
|
681
|
+
/* @__PURE__ */ jsxs(Group, { justify: "flex-end", mt: "md", children: [
|
|
682
|
+
/* @__PURE__ */ jsx(Button, { variant: "light", onClick: () => setShowBatchDelete(false), disabled: deleteDeal.isPending, children: "Cancel" }),
|
|
683
|
+
/* @__PURE__ */ jsx(Button, { color: "red", loading: deleteDeal.isPending, onClick: () => void handleDeleteSelected(), children: "Delete" })
|
|
684
|
+
] })
|
|
685
|
+
] })
|
|
686
|
+
}
|
|
687
|
+
)
|
|
688
|
+
] });
|
|
689
|
+
}
|
|
690
|
+
function ActionButton({ action, dealId }) {
|
|
691
|
+
const executeAction = useExecuteAction({ dealId });
|
|
692
|
+
return /* @__PURE__ */ jsx(
|
|
693
|
+
Button,
|
|
694
|
+
{
|
|
695
|
+
variant: "light",
|
|
696
|
+
size: "sm",
|
|
697
|
+
loading: executeAction.isPending,
|
|
698
|
+
onClick: () => executeAction.mutate({ key: action.key }),
|
|
699
|
+
children: action.label
|
|
700
|
+
}
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
function getType(schema) {
|
|
704
|
+
const zodSchema = schema;
|
|
705
|
+
return zodSchema._def?.type ?? zodSchema._def?.typeName ?? "";
|
|
706
|
+
}
|
|
707
|
+
function unwrapField(schema) {
|
|
708
|
+
const type = getType(schema);
|
|
709
|
+
if (type === "optional" || type === "ZodOptional") {
|
|
710
|
+
const inner = schema._def?.innerType;
|
|
711
|
+
if (!inner) return { schema, required: false, nullable: false, defaultValue: void 0 };
|
|
712
|
+
return { ...unwrapField(inner), required: false };
|
|
713
|
+
}
|
|
714
|
+
if (type === "nullable" || type === "ZodNullable") {
|
|
715
|
+
const inner = schema._def?.innerType;
|
|
716
|
+
if (!inner) return { schema, required: true, nullable: true, defaultValue: null };
|
|
717
|
+
return { ...unwrapField(inner), nullable: true };
|
|
718
|
+
}
|
|
719
|
+
if (type === "default" || type === "ZodDefault") {
|
|
720
|
+
const def = schema._def;
|
|
721
|
+
const inner = def?.innerType;
|
|
722
|
+
const defaultValue = typeof def?.defaultValue === "function" ? def.defaultValue() : def?.defaultValue;
|
|
723
|
+
if (!inner) return { schema, required: false, nullable: false, defaultValue };
|
|
724
|
+
return { ...unwrapField(inner), required: false, defaultValue };
|
|
725
|
+
}
|
|
726
|
+
return { schema, required: true, nullable: false, defaultValue: void 0 };
|
|
727
|
+
}
|
|
728
|
+
function getObjectShape(schema) {
|
|
729
|
+
const zodSchema = schema;
|
|
730
|
+
const type = getType(schema);
|
|
731
|
+
if (type !== "object" && type !== "ZodObject") {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
const shape = zodSchema.shape;
|
|
735
|
+
if (!shape || typeof shape !== "object" || Array.isArray(shape)) {
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
return shape;
|
|
739
|
+
}
|
|
740
|
+
function getEnumValues(schema) {
|
|
741
|
+
const zodSchema = schema;
|
|
742
|
+
const values = zodSchema.options ?? zodSchema._def?.values ?? Object.values(zodSchema._def?.entries ?? {});
|
|
743
|
+
if (!Array.isArray(values) || values.some((value) => typeof value !== "string")) {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
return values;
|
|
747
|
+
}
|
|
748
|
+
function labelForField(name) {
|
|
749
|
+
return name.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/^./, (s) => s.toUpperCase());
|
|
750
|
+
}
|
|
751
|
+
function isLongTextField(name) {
|
|
752
|
+
return ["body", "message", "reply", "replyBody", "emailBody"].includes(name);
|
|
753
|
+
}
|
|
754
|
+
function initialValueFor(field, defaultValue) {
|
|
755
|
+
if (defaultValue !== void 0) {
|
|
756
|
+
if (field.kind === "date" && defaultValue instanceof Date) {
|
|
757
|
+
return defaultValue.toISOString().slice(0, 10);
|
|
758
|
+
}
|
|
759
|
+
return defaultValue;
|
|
760
|
+
}
|
|
761
|
+
switch (field.kind) {
|
|
762
|
+
case "boolean":
|
|
763
|
+
return false;
|
|
764
|
+
case "number":
|
|
765
|
+
return field.required ? 0 : "";
|
|
766
|
+
case "enum":
|
|
767
|
+
return field.required ? field.enumValues?.[0] ?? "" : "";
|
|
768
|
+
case "date":
|
|
769
|
+
case "dateString":
|
|
770
|
+
case "string":
|
|
771
|
+
return "";
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
function describeSchema(schema) {
|
|
775
|
+
if (!schema) {
|
|
776
|
+
return { supported: false, reason: "This action does not define a payload schema." };
|
|
777
|
+
}
|
|
778
|
+
const shape = getObjectShape(schema);
|
|
779
|
+
if (!shape) {
|
|
780
|
+
return { supported: false, reason: "This action requires a payload schema that is not a flat object." };
|
|
781
|
+
}
|
|
782
|
+
const fields = [];
|
|
783
|
+
const initialValues = {};
|
|
784
|
+
for (const [name, rawFieldSchema] of Object.entries(shape)) {
|
|
785
|
+
const { schema: fieldSchema, required, nullable, defaultValue } = unwrapField(rawFieldSchema);
|
|
786
|
+
const type = getType(fieldSchema);
|
|
787
|
+
const zodField = fieldSchema;
|
|
788
|
+
const stringFormat = zodField._def?.format;
|
|
789
|
+
let descriptor = null;
|
|
790
|
+
if (type === "string" || type === "ZodString") {
|
|
791
|
+
descriptor = {
|
|
792
|
+
name,
|
|
793
|
+
label: labelForField(name),
|
|
794
|
+
kind: stringFormat === "date" ? "dateString" : "string",
|
|
795
|
+
schema: rawFieldSchema,
|
|
796
|
+
required,
|
|
797
|
+
nullable
|
|
798
|
+
};
|
|
799
|
+
} else if (type === "number" || type === "ZodNumber") {
|
|
800
|
+
descriptor = { name, label: labelForField(name), kind: "number", schema: rawFieldSchema, required, nullable };
|
|
801
|
+
} else if (type === "boolean" || type === "ZodBoolean") {
|
|
802
|
+
descriptor = { name, label: labelForField(name), kind: "boolean", schema: rawFieldSchema, required, nullable };
|
|
803
|
+
} else if (type === "enum" || type === "ZodEnum") {
|
|
804
|
+
const enumValues = getEnumValues(fieldSchema);
|
|
805
|
+
if (!enumValues) {
|
|
806
|
+
return { supported: false, reason: `Field "${name}" uses an enum shape that is not supported by this form.` };
|
|
807
|
+
}
|
|
808
|
+
descriptor = {
|
|
809
|
+
name,
|
|
810
|
+
label: labelForField(name),
|
|
811
|
+
kind: "enum",
|
|
812
|
+
schema: rawFieldSchema,
|
|
813
|
+
required,
|
|
814
|
+
nullable,
|
|
815
|
+
enumValues
|
|
816
|
+
};
|
|
817
|
+
} else if (type === "date" || type === "ZodDate") {
|
|
818
|
+
descriptor = { name, label: labelForField(name), kind: "date", schema: rawFieldSchema, required, nullable };
|
|
819
|
+
}
|
|
820
|
+
if (!descriptor) {
|
|
821
|
+
return {
|
|
822
|
+
supported: false,
|
|
823
|
+
reason: `Field "${name}" is not supported. CRM action forms currently support only flat string, number, boolean, enum, and date fields.`
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
const field = { ...descriptor, defaultValue: initialValueFor(descriptor, defaultValue) };
|
|
827
|
+
fields.push(field);
|
|
828
|
+
initialValues[name] = field.defaultValue;
|
|
829
|
+
}
|
|
830
|
+
return { supported: true, fields, initialValues };
|
|
831
|
+
}
|
|
832
|
+
function normalizeValue(field, value) {
|
|
833
|
+
const isEmpty = value === "" || value === void 0 || value === null;
|
|
834
|
+
if (isEmpty) {
|
|
835
|
+
if (!field.required) return void 0;
|
|
836
|
+
if (field.nullable) return null;
|
|
837
|
+
return value;
|
|
838
|
+
}
|
|
839
|
+
if (field.kind === "date") {
|
|
840
|
+
const acceptsString = (field.schema._def?.coerce ?? false) === true;
|
|
841
|
+
return acceptsString ? value : new Date(String(value));
|
|
842
|
+
}
|
|
843
|
+
return value;
|
|
844
|
+
}
|
|
845
|
+
function buildPayload(fields, values) {
|
|
846
|
+
return fields.reduce((payload, field) => {
|
|
847
|
+
const value = normalizeValue(field, values[field.name]);
|
|
848
|
+
if (value !== void 0 || field.required) {
|
|
849
|
+
payload[field.name] = value;
|
|
850
|
+
}
|
|
851
|
+
return payload;
|
|
852
|
+
}, {});
|
|
853
|
+
}
|
|
854
|
+
function ActionFormButton({ action, isActive, onToggle }) {
|
|
855
|
+
return /* @__PURE__ */ jsx(Button, { variant: isActive ? "filled" : "light", size: "sm", onClick: onToggle, children: action.label });
|
|
856
|
+
}
|
|
857
|
+
function ActionForm({ action, dealId, onClose }) {
|
|
858
|
+
const executeAction = useExecuteAction({ dealId });
|
|
859
|
+
const schemaDescription = describeSchema(action.payloadSchema);
|
|
860
|
+
const form = useForm({
|
|
861
|
+
initialValues: schemaDescription.supported ? schemaDescription.initialValues : {}
|
|
862
|
+
});
|
|
863
|
+
const handleSubmit = form.onSubmit(async (values) => {
|
|
864
|
+
if (!schemaDescription.supported || !action.payloadSchema) return;
|
|
865
|
+
form.clearErrors();
|
|
866
|
+
const payload = buildPayload(schemaDescription.fields, values);
|
|
867
|
+
const parsed = action.payloadSchema.safeParse(payload);
|
|
868
|
+
if (!parsed.success) {
|
|
869
|
+
const formErrors = {};
|
|
870
|
+
for (const issue of parsed.error.issues) {
|
|
871
|
+
const fieldName = issue.path[0];
|
|
872
|
+
if (typeof fieldName === "string" && schemaDescription.fields.some((field) => field.name === fieldName)) {
|
|
873
|
+
formErrors[fieldName] = issue.message;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
form.setErrors(formErrors);
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
await executeAction.mutateAsync({ key: action.key, payload: parsed.data });
|
|
880
|
+
onClose();
|
|
881
|
+
});
|
|
882
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
883
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
884
|
+
/* @__PURE__ */ jsx(Title, { order: 3, children: action.label }),
|
|
885
|
+
schemaDescription.supported ? /* @__PURE__ */ jsx("form", { onSubmit: handleSubmit, children: /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
886
|
+
schemaDescription.fields.map((field) => {
|
|
887
|
+
if (field.kind === "number") {
|
|
888
|
+
return /* @__PURE__ */ jsx(
|
|
889
|
+
NumberInput,
|
|
890
|
+
{
|
|
891
|
+
label: field.label,
|
|
892
|
+
required: field.required,
|
|
893
|
+
disabled: executeAction.isPending,
|
|
894
|
+
error: form.errors[field.name],
|
|
895
|
+
...form.getInputProps(field.name)
|
|
896
|
+
},
|
|
897
|
+
field.name
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
if (field.kind === "boolean") {
|
|
901
|
+
return /* @__PURE__ */ jsx(
|
|
902
|
+
Switch,
|
|
903
|
+
{
|
|
904
|
+
label: field.label,
|
|
905
|
+
disabled: executeAction.isPending,
|
|
906
|
+
error: form.errors[field.name],
|
|
907
|
+
...form.getInputProps(field.name, { type: "checkbox" })
|
|
908
|
+
},
|
|
909
|
+
field.name
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
if (field.kind === "enum") {
|
|
913
|
+
return /* @__PURE__ */ jsx(
|
|
914
|
+
Select,
|
|
915
|
+
{
|
|
916
|
+
label: field.label,
|
|
917
|
+
required: field.required,
|
|
918
|
+
disabled: executeAction.isPending,
|
|
919
|
+
data: field.enumValues ?? [],
|
|
920
|
+
error: form.errors[field.name],
|
|
921
|
+
...form.getInputProps(field.name)
|
|
922
|
+
},
|
|
923
|
+
field.name
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
if (field.kind === "string" && isLongTextField(field.name)) {
|
|
927
|
+
return /* @__PURE__ */ jsx(
|
|
928
|
+
Textarea,
|
|
929
|
+
{
|
|
930
|
+
label: field.label,
|
|
931
|
+
required: field.required,
|
|
932
|
+
disabled: executeAction.isPending,
|
|
933
|
+
error: form.errors[field.name],
|
|
934
|
+
autosize: true,
|
|
935
|
+
minRows: 6,
|
|
936
|
+
...form.getInputProps(field.name)
|
|
937
|
+
},
|
|
938
|
+
field.name
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
return /* @__PURE__ */ jsx(
|
|
942
|
+
TextInput,
|
|
943
|
+
{
|
|
944
|
+
label: field.label,
|
|
945
|
+
type: field.kind === "date" || field.kind === "dateString" ? "date" : "text",
|
|
946
|
+
required: field.required,
|
|
947
|
+
disabled: executeAction.isPending,
|
|
948
|
+
error: form.errors[field.name],
|
|
949
|
+
...form.getInputProps(field.name)
|
|
950
|
+
},
|
|
951
|
+
field.name
|
|
952
|
+
);
|
|
953
|
+
}),
|
|
954
|
+
/* @__PURE__ */ jsxs(Group, { justify: "flex-end", gap: "sm", children: [
|
|
955
|
+
/* @__PURE__ */ jsx(Button, { variant: "default", onClick: onClose, disabled: executeAction.isPending, children: "Cancel" }),
|
|
956
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", loading: executeAction.isPending, children: action.label })
|
|
957
|
+
] })
|
|
958
|
+
] }) }) : /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
959
|
+
/* @__PURE__ */ jsx(Alert, { color: "yellow", variant: "light", icon: /* @__PURE__ */ jsx(IconAlertCircle, { size: 16 }), title: "Unsupported action form", children: /* @__PURE__ */ jsx(Text, { size: "sm", children: schemaDescription.reason }) }),
|
|
960
|
+
/* @__PURE__ */ jsx(Group, { justify: "flex-end", children: /* @__PURE__ */ jsx(Button, { variant: "default", onClick: onClose, disabled: executeAction.isPending, children: "Close" }) })
|
|
961
|
+
] })
|
|
962
|
+
] });
|
|
963
|
+
}
|
|
964
|
+
var THREAD_INDENT_STEP = 6;
|
|
965
|
+
var THREAD_MAX_INDENT = 36;
|
|
966
|
+
function formatSentAt(sentAt) {
|
|
967
|
+
if (!sentAt) return "Unknown time";
|
|
968
|
+
const date = new Date(sentAt);
|
|
969
|
+
if (Number.isNaN(date.getTime())) return sentAt;
|
|
970
|
+
return date.toLocaleString();
|
|
971
|
+
}
|
|
972
|
+
function getQuoteDepth(line) {
|
|
973
|
+
const match = line.match(/^\s*((?:>\s*)+)(.*)$/);
|
|
974
|
+
if (!match) return { depth: 0, text: line };
|
|
975
|
+
return {
|
|
976
|
+
depth: (match[1].match(/>/g) ?? []).length,
|
|
977
|
+
text: match[2]
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
function MessageBody({ body }) {
|
|
981
|
+
const resolvedBody = body || "Full message body unavailable from Instantly.";
|
|
982
|
+
return /* @__PURE__ */ jsx(Stack, { gap: 0, children: resolvedBody.split(/\r?\n/).map((line, index) => {
|
|
983
|
+
const { depth, text } = getQuoteDepth(line);
|
|
984
|
+
return /* @__PURE__ */ jsxs(
|
|
985
|
+
Box,
|
|
986
|
+
{
|
|
987
|
+
style: {
|
|
988
|
+
display: "grid",
|
|
989
|
+
gridTemplateColumns: `${depth * 12}px minmax(0, 1fr)`,
|
|
990
|
+
minHeight: "1.55em"
|
|
991
|
+
},
|
|
992
|
+
children: [
|
|
993
|
+
/* @__PURE__ */ jsx(
|
|
994
|
+
Box,
|
|
995
|
+
{
|
|
996
|
+
"aria-hidden": "true",
|
|
997
|
+
style: {
|
|
998
|
+
display: "grid",
|
|
999
|
+
gridTemplateColumns: `repeat(${depth}, 12px)`
|
|
1000
|
+
},
|
|
1001
|
+
children: Array.from({ length: depth }).map((_, depthIndex) => /* @__PURE__ */ jsx(
|
|
1002
|
+
Box,
|
|
1003
|
+
{
|
|
1004
|
+
style: {
|
|
1005
|
+
borderLeft: "1px solid var(--color-border)",
|
|
1006
|
+
marginLeft: 4
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
depthIndex
|
|
1010
|
+
))
|
|
1011
|
+
}
|
|
1012
|
+
),
|
|
1013
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", lh: 1.55, style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere" }, children: text || " " })
|
|
1014
|
+
]
|
|
1015
|
+
},
|
|
1016
|
+
`${index}-${line}`
|
|
1017
|
+
);
|
|
1018
|
+
}) });
|
|
1019
|
+
}
|
|
1020
|
+
function ConversationThread({ messages }) {
|
|
1021
|
+
if (messages.length === 0) {
|
|
1022
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: "xs", children: [
|
|
1023
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconMessages, { size: 18 }), title: "Conversation", mb: "xs" }),
|
|
1024
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", children: "No synced email thread is available. Check Activity for local CRM events." })
|
|
1025
|
+
] });
|
|
1026
|
+
}
|
|
1027
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1028
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconMessages, { size: 18 }), title: "Conversation", mb: 0 }),
|
|
1029
|
+
[...messages].reverse().map((message, index) => {
|
|
1030
|
+
const isOutbound = message.direction === "outbound";
|
|
1031
|
+
const participant = isOutbound ? message.toEmail : message.fromEmail;
|
|
1032
|
+
const olderMessageIndent = Math.min(index * THREAD_INDENT_STEP, THREAD_MAX_INDENT);
|
|
1033
|
+
const olderMessageLevels = olderMessageIndent / THREAD_INDENT_STEP;
|
|
1034
|
+
const directionLabel = isOutbound ? "Sent to" : "Received from";
|
|
1035
|
+
const messageIcon = isOutbound ? /* @__PURE__ */ jsx(IconMailForward, { size: 16 }) : /* @__PURE__ */ jsx(IconInbox, { size: 16 });
|
|
1036
|
+
return /* @__PURE__ */ jsxs(
|
|
1037
|
+
Box,
|
|
1038
|
+
{
|
|
1039
|
+
style: {
|
|
1040
|
+
display: "grid",
|
|
1041
|
+
gridTemplateColumns: `${olderMessageIndent}px minmax(0, 1fr)`
|
|
1042
|
+
},
|
|
1043
|
+
children: [
|
|
1044
|
+
/* @__PURE__ */ jsx(
|
|
1045
|
+
Box,
|
|
1046
|
+
{
|
|
1047
|
+
"aria-hidden": "true",
|
|
1048
|
+
style: {
|
|
1049
|
+
display: "grid",
|
|
1050
|
+
gridTemplateColumns: `repeat(${olderMessageLevels}, ${THREAD_INDENT_STEP}px)`
|
|
1051
|
+
},
|
|
1052
|
+
children: Array.from({ length: olderMessageLevels }).map((_, levelIndex) => /* @__PURE__ */ jsx(
|
|
1053
|
+
Box,
|
|
1054
|
+
{
|
|
1055
|
+
style: {
|
|
1056
|
+
borderLeft: "1px solid var(--color-border)"
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
levelIndex
|
|
1060
|
+
))
|
|
1061
|
+
}
|
|
1062
|
+
),
|
|
1063
|
+
/* @__PURE__ */ jsx(
|
|
1064
|
+
Box,
|
|
1065
|
+
{
|
|
1066
|
+
pl: "md",
|
|
1067
|
+
py: "xs",
|
|
1068
|
+
style: {
|
|
1069
|
+
borderLeft: `2px solid ${isOutbound ? "var(--mantine-color-blue-5)" : "var(--mantine-color-teal-5)"}`
|
|
1070
|
+
},
|
|
1071
|
+
children: /* @__PURE__ */ jsxs(Stack, { gap: 6, children: [
|
|
1072
|
+
/* @__PURE__ */ jsx(
|
|
1073
|
+
CardHeader,
|
|
1074
|
+
{
|
|
1075
|
+
icon: messageIcon,
|
|
1076
|
+
iconColor: isOutbound ? "blue" : "teal",
|
|
1077
|
+
title: `${directionLabel} ${participant || "unknown recipient"}`,
|
|
1078
|
+
subtitle: message.subject ?? void 0,
|
|
1079
|
+
titleOrder: 5,
|
|
1080
|
+
mb: 0,
|
|
1081
|
+
rightSection: /* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", style: { flexShrink: 0, textAlign: "right" }, children: formatSentAt(message.sentAt) })
|
|
1082
|
+
}
|
|
1083
|
+
),
|
|
1084
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(MessageBody, { body: message.body }) })
|
|
1085
|
+
] })
|
|
1086
|
+
}
|
|
1087
|
+
)
|
|
1088
|
+
]
|
|
1089
|
+
},
|
|
1090
|
+
message.id
|
|
1091
|
+
);
|
|
1092
|
+
})
|
|
1093
|
+
] });
|
|
1094
|
+
}
|
|
1095
|
+
var CANONICAL_ACTION_KEYS = /* @__PURE__ */ new Set(["send_reply"]);
|
|
1096
|
+
var DEAL_OWNERSHIP_BADGE_COPY2 = {
|
|
1097
|
+
us: {
|
|
1098
|
+
color: "red",
|
|
1099
|
+
label: "Our move"
|
|
1100
|
+
},
|
|
1101
|
+
them: {
|
|
1102
|
+
color: "gray",
|
|
1103
|
+
label: "Their move"
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
function getContactName(deal) {
|
|
1107
|
+
return [deal.contact?.first_name, deal.contact?.last_name].filter(Boolean).join(" ");
|
|
1108
|
+
}
|
|
1109
|
+
function getCompanyName(deal) {
|
|
1110
|
+
return deal.contact?.company?.name || deal.discovery_data?.company || deal.contact_email?.split("@")[1] || "Unknown";
|
|
1111
|
+
}
|
|
1112
|
+
function toAction(actionDef) {
|
|
1113
|
+
const { key, label, payloadSchema } = actionDef;
|
|
1114
|
+
return { key, label, payloadSchema };
|
|
1115
|
+
}
|
|
1116
|
+
function getVisibleCanonicalDealActions(deal, crmActions) {
|
|
1117
|
+
if (deal.nextAction && CANONICAL_ACTION_KEYS.has(deal.nextAction)) {
|
|
1118
|
+
if (deal.nextAction === "send_reply" && deal.ownership === "them") return [];
|
|
1119
|
+
const nextAction = crmActions.find((action) => action.key === deal.nextAction);
|
|
1120
|
+
return nextAction ? [toAction(nextAction)] : [];
|
|
1121
|
+
}
|
|
1122
|
+
return deriveActions(deal, crmActions).filter((action) => {
|
|
1123
|
+
if (!CANONICAL_ACTION_KEYS.has(action.key)) return false;
|
|
1124
|
+
if (action.key === "send_reply" && deal.ownership === "them") return false;
|
|
1125
|
+
return true;
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
function CopyBookingLinkButton({
|
|
1129
|
+
bookingUrl,
|
|
1130
|
+
dealId,
|
|
1131
|
+
contactId
|
|
1132
|
+
}) {
|
|
1133
|
+
const url = buildBookingUrl(bookingUrl, { dealId, contactId });
|
|
1134
|
+
if (!url) return null;
|
|
1135
|
+
return /* @__PURE__ */ jsx(CopyButton, { value: url, timeout: 1500, children: ({ copied, copy }) => /* @__PURE__ */ jsx(
|
|
1136
|
+
Button,
|
|
1137
|
+
{
|
|
1138
|
+
variant: "light",
|
|
1139
|
+
size: "xs",
|
|
1140
|
+
color: copied ? "teal" : void 0,
|
|
1141
|
+
leftSection: copied ? /* @__PURE__ */ jsx(IconCheck, { size: 14 }) : /* @__PURE__ */ jsx(IconCopy, { size: 14 }),
|
|
1142
|
+
onClick: copy,
|
|
1143
|
+
children: copied ? "Copied" : "Copy Booking Link"
|
|
1144
|
+
}
|
|
1145
|
+
) });
|
|
1146
|
+
}
|
|
1147
|
+
function DetailRow({ label, value }) {
|
|
1148
|
+
return /* @__PURE__ */ jsxs(Group, { gap: "xs", align: "flex-start", wrap: "nowrap", children: [
|
|
1149
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", fw: 500, style: { width: 120, flexShrink: 0 }, children: label }),
|
|
1150
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", style: { minWidth: 0, wordBreak: "break-word", color: "var(--color-text-subtle)" }, children: value || "N/A" })
|
|
1151
|
+
] });
|
|
1152
|
+
}
|
|
1153
|
+
function DealDetailPage({ dealId, renderActions, onDealLoaded, bookingUrl }) {
|
|
1154
|
+
const navigate = useNavigate();
|
|
1155
|
+
const [referrer] = useState(() => getDealReferrer());
|
|
1156
|
+
const backTarget = referrer === "pipeline" ? { to: "/crm/pipeline", label: "Pipeline" } : { to: "/crm/deals", label: "Deals" };
|
|
1157
|
+
const { data: deal, isLoading, error } = useDealDetail(dealId);
|
|
1158
|
+
const crmActions = useCrmActions();
|
|
1159
|
+
const { pipeline } = useCrmPipelineConfig();
|
|
1160
|
+
const stageColors = useMemo(() => getDealStageColors(pipeline), [pipeline]);
|
|
1161
|
+
const actions = useMemo(() => deal ? getVisibleCanonicalDealActions(deal, crmActions) : [], [deal, crmActions]);
|
|
1162
|
+
const [activeActionKey, setActiveActionKey] = useState(null);
|
|
1163
|
+
const activeAction = activeActionKey ? actions.find((action) => action.key === activeActionKey) : null;
|
|
1164
|
+
useEffect(() => {
|
|
1165
|
+
if (activeActionKey && !actions.some((action) => action.key === activeActionKey)) {
|
|
1166
|
+
setActiveActionKey(null);
|
|
1167
|
+
}
|
|
1168
|
+
}, [actions, activeActionKey]);
|
|
1169
|
+
useEffect(() => {
|
|
1170
|
+
if (deal) onDealLoaded?.(deal);
|
|
1171
|
+
}, [deal, onDealLoaded]);
|
|
1172
|
+
const titleName = deal ? getContactName(deal) || getCompanyName(deal) : null;
|
|
1173
|
+
const title = titleName ? `${titleName} Deal` : "Deal Detail";
|
|
1174
|
+
const companyName = deal ? getCompanyName(deal) : "Unknown";
|
|
1175
|
+
const ownershipBadge = deal?.ownership ? DEAL_OWNERSHIP_BADGE_COPY2[deal.ownership] : null;
|
|
1176
|
+
const activityLog = (deal?.activity_log || []).filter(Boolean);
|
|
1177
|
+
const hasDiscoveryData = deal?.discovery_data != null && (typeof deal.discovery_data !== "object" || Array.isArray(deal.discovery_data) || Object.keys(deal.discovery_data).length > 0);
|
|
1178
|
+
const headerActions = /* @__PURE__ */ jsxs(Group, { gap: "xs", children: [
|
|
1179
|
+
/* @__PURE__ */ jsx(
|
|
1180
|
+
Button,
|
|
1181
|
+
{
|
|
1182
|
+
variant: "light",
|
|
1183
|
+
size: "sm",
|
|
1184
|
+
leftSection: /* @__PURE__ */ jsx(IconArrowLeft, { size: 16 }),
|
|
1185
|
+
onClick: () => navigate({ to: backTarget.to }),
|
|
1186
|
+
children: backTarget.label
|
|
1187
|
+
}
|
|
1188
|
+
),
|
|
1189
|
+
deal?.proposal_pdf_url && /* @__PURE__ */ jsx(
|
|
1190
|
+
Button,
|
|
1191
|
+
{
|
|
1192
|
+
variant: "light",
|
|
1193
|
+
size: "sm",
|
|
1194
|
+
leftSection: /* @__PURE__ */ jsx(IconFileText, { size: 16 }),
|
|
1195
|
+
onClick: () => window.open(deal.proposal_pdf_url, "_blank"),
|
|
1196
|
+
children: "View Proposal"
|
|
1197
|
+
}
|
|
1198
|
+
),
|
|
1199
|
+
deal && renderActions?.(deal)
|
|
1200
|
+
] });
|
|
1201
|
+
if (isLoading) {
|
|
1202
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsx(PageContainer, { children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
1203
|
+
/* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Loading deal details...", rightSection: headerActions }),
|
|
1204
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) })
|
|
1205
|
+
] }) }) });
|
|
1206
|
+
}
|
|
1207
|
+
if (error) {
|
|
1208
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsx(PageContainer, { children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
1209
|
+
/* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Unable to load deal details", rightSection: headerActions }),
|
|
1210
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load deal" }) })
|
|
1211
|
+
] }) }) });
|
|
1212
|
+
}
|
|
1213
|
+
if (!deal) {
|
|
1214
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsx(PageContainer, { children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
1215
|
+
/* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Deal not found", rightSection: headerActions }),
|
|
1216
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(EmptyState, { icon: IconInbox, title: "Deal not found", description: "The selected deal no longer exists." }) })
|
|
1217
|
+
] }) }) });
|
|
1218
|
+
}
|
|
1219
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsx(PageContainer, { children: /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1220
|
+
/* @__PURE__ */ jsx(
|
|
1221
|
+
PageTitleCaption,
|
|
1222
|
+
{
|
|
1223
|
+
title,
|
|
1224
|
+
caption: `${companyName} - ${formatDealStageLabel(pipeline, deal.stage_key)}`,
|
|
1225
|
+
rightSection: headerActions
|
|
1226
|
+
}
|
|
1227
|
+
),
|
|
1228
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "lg", children: [
|
|
1229
|
+
/* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1230
|
+
/* @__PURE__ */ jsx(
|
|
1231
|
+
CardHeader,
|
|
1232
|
+
{
|
|
1233
|
+
icon: /* @__PURE__ */ jsx(IconBriefcase, { size: 18 }),
|
|
1234
|
+
title: "Deal",
|
|
1235
|
+
mb: 0,
|
|
1236
|
+
rightSection: /* @__PURE__ */ jsx(CopyBookingLinkButton, { bookingUrl, dealId: deal.id, contactId: deal.contact?.id })
|
|
1237
|
+
}
|
|
1238
|
+
),
|
|
1239
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1240
|
+
/* @__PURE__ */ jsx(
|
|
1241
|
+
DetailRow,
|
|
1242
|
+
{
|
|
1243
|
+
label: "Stage",
|
|
1244
|
+
value: /* @__PURE__ */ jsx(Badge, { color: stageColors[deal.stage_key || ""] || "gray", children: formatDealStageLabel(pipeline, deal.stage_key) })
|
|
1245
|
+
}
|
|
1246
|
+
),
|
|
1247
|
+
/* @__PURE__ */ jsx(
|
|
1248
|
+
DetailRow,
|
|
1249
|
+
{
|
|
1250
|
+
label: "Priority",
|
|
1251
|
+
value: /* @__PURE__ */ jsx(Tooltip, { label: deal.priority.reason, withArrow: true, children: /* @__PURE__ */ jsx(
|
|
1252
|
+
Badge,
|
|
1253
|
+
{
|
|
1254
|
+
variant: "light",
|
|
1255
|
+
color: deal.priority.color,
|
|
1256
|
+
size: "sm",
|
|
1257
|
+
style: { maxWidth: "100%", textTransform: "none" },
|
|
1258
|
+
children: /* @__PURE__ */ jsx(Text, { span: true, size: "xs", truncate: "end", style: { maxWidth: "100%" }, children: deal.priority.label })
|
|
1259
|
+
}
|
|
1260
|
+
) })
|
|
1261
|
+
}
|
|
1262
|
+
),
|
|
1263
|
+
/* @__PURE__ */ jsx(
|
|
1264
|
+
DetailRow,
|
|
1265
|
+
{
|
|
1266
|
+
label: "Move",
|
|
1267
|
+
value: ownershipBadge ? /* @__PURE__ */ jsx(
|
|
1268
|
+
Badge,
|
|
1269
|
+
{
|
|
1270
|
+
variant: "light",
|
|
1271
|
+
color: ownershipBadge.color,
|
|
1272
|
+
size: "sm",
|
|
1273
|
+
style: { maxWidth: "100%", textTransform: "none" },
|
|
1274
|
+
children: /* @__PURE__ */ jsx(Text, { span: true, size: "xs", truncate: "end", style: { maxWidth: "100%" }, children: ownershipBadge.label })
|
|
1275
|
+
}
|
|
1276
|
+
) : "N/A"
|
|
1277
|
+
}
|
|
1278
|
+
),
|
|
1279
|
+
/* @__PURE__ */ jsx(
|
|
1280
|
+
DetailRow,
|
|
1281
|
+
{
|
|
1282
|
+
label: "Sent",
|
|
1283
|
+
value: deal.proposal_sent_at ? new Date(deal.proposal_sent_at).toLocaleString() : "N/A"
|
|
1284
|
+
}
|
|
1285
|
+
),
|
|
1286
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Envelope ID", value: deal.signature_envelope_id || "N/A" }),
|
|
1287
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Contact Email", value: deal.contact?.email || deal.contact_email || "N/A" })
|
|
1288
|
+
] })
|
|
1289
|
+
] }),
|
|
1290
|
+
/* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1291
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconUser, { size: 18 }), title: "Contact", mb: 0 }),
|
|
1292
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1293
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Name", value: getContactName(deal) || "N/A" }),
|
|
1294
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Title", value: deal.contact?.title || "N/A" }),
|
|
1295
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Company", value: deal.contact?.company?.name || "N/A" }),
|
|
1296
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Domain", value: deal.contact?.company?.domain || "N/A" }),
|
|
1297
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Segment", value: deal.contact?.company?.segment || "N/A" }),
|
|
1298
|
+
/* @__PURE__ */ jsx(DetailRow, { label: "Category", value: deal.contact?.company?.category || "N/A" })
|
|
1299
|
+
] })
|
|
1300
|
+
] }),
|
|
1301
|
+
/* @__PURE__ */ jsxs(Tabs, { defaultValue: "conversation", keepMounted: false, children: [
|
|
1302
|
+
/* @__PURE__ */ jsxs(Tabs.List, { children: [
|
|
1303
|
+
/* @__PURE__ */ jsx(Tabs.Tab, { value: "conversation", leftSection: /* @__PURE__ */ jsx(IconMessages, { size: 16 }), children: "Conversation" }),
|
|
1304
|
+
/* @__PURE__ */ jsx(Tabs.Tab, { value: "activity", leftSection: /* @__PURE__ */ jsx(IconHistory, { size: 16 }), children: "Activity" }),
|
|
1305
|
+
/* @__PURE__ */ jsx(Tabs.Tab, { value: "discovery", leftSection: /* @__PURE__ */ jsx(IconSearch, { size: 16 }), children: "Discovery" })
|
|
1306
|
+
] }),
|
|
1307
|
+
/* @__PURE__ */ jsx(Tabs.Panel, { value: "conversation", pt: "md", children: /* @__PURE__ */ jsx(ConversationThread, { messages: deal.conversation.messages }) }),
|
|
1308
|
+
/* @__PURE__ */ jsx(Tabs.Panel, { value: "activity", pt: "md", children: /* @__PURE__ */ jsx(ActivityTimeline, { activities: activityLog }) }),
|
|
1309
|
+
/* @__PURE__ */ jsx(Tabs.Panel, { value: "discovery", pt: "md", children: /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1310
|
+
/* @__PURE__ */ jsx(
|
|
1311
|
+
CardHeader,
|
|
1312
|
+
{
|
|
1313
|
+
icon: /* @__PURE__ */ jsx(IconSearch, { size: 18 }),
|
|
1314
|
+
title: "Discovery",
|
|
1315
|
+
subtitle: "Structured intake answers and qualification context captured before proposal work.",
|
|
1316
|
+
mb: 0
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
hasDiscoveryData ? /* @__PURE__ */ jsx(Code, { block: true, children: JSON.stringify(deal.discovery_data, null, 2) }) : /* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", children: "No discovery responses have been captured for this deal." })
|
|
1320
|
+
] }) })
|
|
1321
|
+
] })
|
|
1322
|
+
] }) }),
|
|
1323
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "md", children: [
|
|
1324
|
+
/* @__PURE__ */ jsx(CardHeader, { icon: /* @__PURE__ */ jsx(IconBolt, { size: 18 }), title: "Actions", titleOrder: 2, mb: 0 }),
|
|
1325
|
+
actions.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1326
|
+
/* @__PURE__ */ jsx(Group, { gap: "sm", children: actions.map(
|
|
1327
|
+
(action) => action.payloadSchema ? /* @__PURE__ */ jsx(
|
|
1328
|
+
ActionFormButton,
|
|
1329
|
+
{
|
|
1330
|
+
action,
|
|
1331
|
+
isActive: activeActionKey === action.key,
|
|
1332
|
+
onToggle: () => setActiveActionKey((current) => current === action.key ? null : action.key)
|
|
1333
|
+
},
|
|
1334
|
+
action.key
|
|
1335
|
+
) : /* @__PURE__ */ jsx(ActionButton, { action, dealId: deal.id }, action.key)
|
|
1336
|
+
) }),
|
|
1337
|
+
activeAction?.payloadSchema && /* @__PURE__ */ jsx(
|
|
1338
|
+
ActionForm,
|
|
1339
|
+
{
|
|
1340
|
+
action: activeAction,
|
|
1341
|
+
dealId: deal.id,
|
|
1342
|
+
onClose: () => setActiveActionKey(null)
|
|
1343
|
+
},
|
|
1344
|
+
activeAction.key
|
|
1345
|
+
)
|
|
1346
|
+
] }) : /* @__PURE__ */ jsx(Alert, { color: "gray", variant: "light", children: "No reply actions are currently available for this deal." })
|
|
1347
|
+
] }) })
|
|
1348
|
+
] }) }) });
|
|
1349
|
+
}
|
|
1350
|
+
function CompanyDetailPage({ companyId }) {
|
|
1351
|
+
const navigate = useNavigate();
|
|
1352
|
+
const { data: company, isLoading, error } = useCompany(companyId);
|
|
1353
|
+
const [enrichmentView, setEnrichmentView] = useState("formatted");
|
|
1354
|
+
const title = company ? company.name : "Company Detail";
|
|
1355
|
+
const headerActions = /* @__PURE__ */ jsx(
|
|
1356
|
+
Button,
|
|
1357
|
+
{
|
|
1358
|
+
variant: "light",
|
|
1359
|
+
size: "sm",
|
|
1360
|
+
leftSection: /* @__PURE__ */ jsx(IconArrowLeft, { size: 16 }),
|
|
1361
|
+
onClick: () => navigate({ to: "/crm" }),
|
|
1362
|
+
children: "CRM"
|
|
1363
|
+
}
|
|
1364
|
+
);
|
|
1365
|
+
if (isLoading) {
|
|
1366
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1367
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Loading company details...", rightSection: headerActions }) }),
|
|
1368
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) })
|
|
1369
|
+
] }) });
|
|
1370
|
+
}
|
|
1371
|
+
if (error) {
|
|
1372
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1373
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Unable to load company details", rightSection: headerActions }) }),
|
|
1374
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load company" }) })
|
|
1375
|
+
] }) });
|
|
1376
|
+
}
|
|
1377
|
+
if (!company) {
|
|
1378
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1379
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Company not found", rightSection: headerActions }) }),
|
|
1380
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(
|
|
1381
|
+
EmptyState,
|
|
1382
|
+
{
|
|
1383
|
+
icon: IconBuilding,
|
|
1384
|
+
title: "Company not found",
|
|
1385
|
+
description: "The selected company no longer exists."
|
|
1386
|
+
}
|
|
1387
|
+
) })
|
|
1388
|
+
] }) });
|
|
1389
|
+
}
|
|
1390
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1391
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(
|
|
1392
|
+
PageTitleCaption,
|
|
1393
|
+
{
|
|
1394
|
+
title: company.name,
|
|
1395
|
+
caption: [company.domain, company.locationCity, company.locationState].filter(Boolean).join(" \xB7 ") || "Company",
|
|
1396
|
+
rightSection: headerActions
|
|
1397
|
+
}
|
|
1398
|
+
) }),
|
|
1399
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "md", p: "md", children: [
|
|
1400
|
+
/* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1401
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Overview" }),
|
|
1402
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1403
|
+
/* @__PURE__ */ jsxs(Group, { children: [
|
|
1404
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Name:" }),
|
|
1405
|
+
/* @__PURE__ */ jsx(Text, { children: company.name })
|
|
1406
|
+
] }),
|
|
1407
|
+
/* @__PURE__ */ jsxs(Group, { children: [
|
|
1408
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Status:" }),
|
|
1409
|
+
/* @__PURE__ */ jsx(Badge, { variant: "light", color: "blue", children: company.status })
|
|
1410
|
+
] }),
|
|
1411
|
+
company.domain && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1412
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Domain:" }),
|
|
1413
|
+
/* @__PURE__ */ jsx(Text, { children: company.domain })
|
|
1414
|
+
] }),
|
|
1415
|
+
company.website && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1416
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Website:" }),
|
|
1417
|
+
/* @__PURE__ */ jsx(Text, { component: "a", href: company.website, target: "_blank", c: "blue", children: company.website })
|
|
1418
|
+
] }),
|
|
1419
|
+
company.numEmployees != null && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1420
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Employees:" }),
|
|
1421
|
+
/* @__PURE__ */ jsx(Text, { children: company.numEmployees.toLocaleString() })
|
|
1422
|
+
] }),
|
|
1423
|
+
company.foundedYear != null && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1424
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Founded:" }),
|
|
1425
|
+
/* @__PURE__ */ jsx(Text, { children: company.foundedYear })
|
|
1426
|
+
] }),
|
|
1427
|
+
company.contactCount != null && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1428
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Contacts:" }),
|
|
1429
|
+
/* @__PURE__ */ jsx(Text, { children: company.contactCount })
|
|
1430
|
+
] })
|
|
1431
|
+
] })
|
|
1432
|
+
] }) }),
|
|
1433
|
+
(company.locationCity || company.locationState) && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1434
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Location" }),
|
|
1435
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1436
|
+
company.locationCity && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1437
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "City:" }),
|
|
1438
|
+
/* @__PURE__ */ jsx(Text, { children: company.locationCity })
|
|
1439
|
+
] }),
|
|
1440
|
+
company.locationState && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1441
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "State:" }),
|
|
1442
|
+
/* @__PURE__ */ jsx(Text, { children: company.locationState })
|
|
1443
|
+
] })
|
|
1444
|
+
] })
|
|
1445
|
+
] }) }),
|
|
1446
|
+
company.linkedinUrl && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1447
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Social" }),
|
|
1448
|
+
/* @__PURE__ */ jsxs(Group, { children: [
|
|
1449
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "LinkedIn:" }),
|
|
1450
|
+
/* @__PURE__ */ jsx(Text, { component: "a", href: company.linkedinUrl, target: "_blank", c: "blue", children: "View Profile" })
|
|
1451
|
+
] })
|
|
1452
|
+
] }) }),
|
|
1453
|
+
(company.segment || company.category) && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1454
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Classification" }),
|
|
1455
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1456
|
+
company.segment && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1457
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Segment:" }),
|
|
1458
|
+
/* @__PURE__ */ jsx(Text, { children: company.segment })
|
|
1459
|
+
] }),
|
|
1460
|
+
company.category && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1461
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Category:" }),
|
|
1462
|
+
/* @__PURE__ */ jsx(Text, { children: company.category })
|
|
1463
|
+
] })
|
|
1464
|
+
] })
|
|
1465
|
+
] }) }),
|
|
1466
|
+
company.verticalResearch && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1467
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Vertical Research" }),
|
|
1468
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", style: { whiteSpace: "pre-wrap" }, children: company.verticalResearch })
|
|
1469
|
+
] }) }),
|
|
1470
|
+
company.enrichmentData && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1471
|
+
/* @__PURE__ */ jsxs(Group, { justify: "space-between", align: "center", children: [
|
|
1472
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Enrichment Data" }),
|
|
1473
|
+
/* @__PURE__ */ jsx(
|
|
1474
|
+
SegmentedControl,
|
|
1475
|
+
{
|
|
1476
|
+
value: enrichmentView,
|
|
1477
|
+
onChange: (v) => setEnrichmentView(v),
|
|
1478
|
+
size: "xs",
|
|
1479
|
+
data: [
|
|
1480
|
+
{ label: "Formatted", value: "formatted" },
|
|
1481
|
+
{ label: "JSON", value: "json" }
|
|
1482
|
+
]
|
|
1483
|
+
}
|
|
1484
|
+
)
|
|
1485
|
+
] }),
|
|
1486
|
+
enrichmentView === "formatted" ? /* @__PURE__ */ jsx(ContextViewer, { data: company.enrichmentData }) : /* @__PURE__ */ jsx(JsonViewer, { data: company.enrichmentData })
|
|
1487
|
+
] }) })
|
|
1488
|
+
] }) })
|
|
1489
|
+
] }) });
|
|
1490
|
+
}
|
|
1491
|
+
var crmPrioritySettingsKeys = {
|
|
1492
|
+
all: ["crm-priority-settings"],
|
|
1493
|
+
detail: (organizationId) => [...crmPrioritySettingsKeys.all, organizationId]
|
|
1494
|
+
};
|
|
1495
|
+
function useCrmPrioritySettings() {
|
|
1496
|
+
const { apiRequest, isReady, workOSOrganizationId } = useElevasisServices();
|
|
1497
|
+
return useQuery({
|
|
1498
|
+
queryKey: crmPrioritySettingsKeys.detail(workOSOrganizationId),
|
|
1499
|
+
queryFn: () => apiRequest("/crm/settings/priority"),
|
|
1500
|
+
enabled: isReady
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
function useUpdateCrmPrioritySettings() {
|
|
1504
|
+
const { apiRequest, workOSOrganizationId } = useElevasisServices();
|
|
1505
|
+
const queryClient = useQueryClient();
|
|
1506
|
+
return useMutation({
|
|
1507
|
+
mutationFn: (override) => apiRequest("/crm/settings/priority", {
|
|
1508
|
+
method: "PATCH",
|
|
1509
|
+
body: JSON.stringify(override)
|
|
1510
|
+
}),
|
|
1511
|
+
onSuccess: () => {
|
|
1512
|
+
queryClient.invalidateQueries({ queryKey: crmPrioritySettingsKeys.detail(workOSOrganizationId) });
|
|
1513
|
+
queryClient.invalidateQueries({ queryKey: dealKeys.lists() });
|
|
1514
|
+
queryClient.invalidateQueries({ queryKey: dealKeys.details() });
|
|
1515
|
+
showSuccessNotification("CRM priority settings saved.");
|
|
1516
|
+
},
|
|
1517
|
+
onError: (error) => {
|
|
1518
|
+
showApiErrorNotification(error);
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
function useResetCrmPrioritySettings() {
|
|
1523
|
+
const { apiRequest, workOSOrganizationId } = useElevasisServices();
|
|
1524
|
+
const queryClient = useQueryClient();
|
|
1525
|
+
return useMutation({
|
|
1526
|
+
mutationFn: () => apiRequest("/crm/settings/priority", {
|
|
1527
|
+
method: "DELETE"
|
|
1528
|
+
}),
|
|
1529
|
+
onSuccess: () => {
|
|
1530
|
+
queryClient.invalidateQueries({ queryKey: crmPrioritySettingsKeys.detail(workOSOrganizationId) });
|
|
1531
|
+
queryClient.invalidateQueries({ queryKey: dealKeys.lists() });
|
|
1532
|
+
queryClient.invalidateQueries({ queryKey: dealKeys.details() });
|
|
1533
|
+
showSuccessNotification("CRM priority settings reset to Org-OS defaults.");
|
|
1534
|
+
},
|
|
1535
|
+
onError: (error) => {
|
|
1536
|
+
showApiErrorNotification(error);
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
var BUCKET_KEYS = ["needs_response", "follow_up_due", "waiting", "stale", "closed_low"];
|
|
1541
|
+
var COLOR_OPTIONS = ["red", "orange", "yellow", "blue", "gray", "dark", "green", "teal", "violet", "grape"].map(
|
|
1542
|
+
(color) => ({ value: color, label: color })
|
|
1543
|
+
);
|
|
1544
|
+
var ORDER_OPTIONS = [
|
|
1545
|
+
{ value: "10", label: "First - most urgent" },
|
|
1546
|
+
{ value: "20", label: "Second - follow-up queue" },
|
|
1547
|
+
{ value: "30", label: "Middle - waiting" },
|
|
1548
|
+
{ value: "40", label: "Later - stale review" },
|
|
1549
|
+
{ value: "50", label: "Last - closed or low priority" }
|
|
1550
|
+
];
|
|
1551
|
+
var BUCKET_RULE_COPY = {
|
|
1552
|
+
needs_response: {
|
|
1553
|
+
applies: "Current state or latest activity indicates the lead replied or cancelled and needs a human response.",
|
|
1554
|
+
example: "A lead replies to the discovery email; the deal moves to Needs Response immediately."
|
|
1555
|
+
},
|
|
1556
|
+
follow_up_due: {
|
|
1557
|
+
applies: "The configured follow-up window for the current state has elapsed.",
|
|
1558
|
+
example: "A discovery link was sent 5 days ago and the follow-up window is 3 days."
|
|
1559
|
+
},
|
|
1560
|
+
waiting: {
|
|
1561
|
+
applies: "No response is needed yet, or the next action time is still in the future.",
|
|
1562
|
+
example: "A discovery link was sent yesterday and the follow-up window has not elapsed."
|
|
1563
|
+
},
|
|
1564
|
+
stale: {
|
|
1565
|
+
applies: "No meaningful activity has happened for the stale threshold and no stronger bucket applies.",
|
|
1566
|
+
example: "A deal has had no activity for 14 days and is not waiting on a scheduled follow-up."
|
|
1567
|
+
},
|
|
1568
|
+
closed_low: {
|
|
1569
|
+
applies: "The deal is in a closed stage, so it should stay out of the active follow-up queue.",
|
|
1570
|
+
example: "A deal is marked Closed Won or Closed Lost."
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
function getOrderLabel(rank) {
|
|
1574
|
+
if (rank <= 10) return "Shown first";
|
|
1575
|
+
if (rank <= 20) return "After urgent replies";
|
|
1576
|
+
if (rank <= 30) return "Middle";
|
|
1577
|
+
if (rank <= 40) return "Later review";
|
|
1578
|
+
return "Shown last";
|
|
1579
|
+
}
|
|
1580
|
+
var EMPTY_RESOLVED_CRM_PRIORITY_RULE_CONFIG = {
|
|
1581
|
+
enabled: true,
|
|
1582
|
+
buckets: [],
|
|
1583
|
+
closedStageKeys: [],
|
|
1584
|
+
followUpAfterDaysByStateKey: {},
|
|
1585
|
+
staleAfterDays: 14
|
|
1586
|
+
};
|
|
1587
|
+
function toResolvedConfig(config = EMPTY_RESOLVED_CRM_PRIORITY_RULE_CONFIG) {
|
|
1588
|
+
return {
|
|
1589
|
+
...config,
|
|
1590
|
+
enabled: "enabled" in config ? config.enabled : true,
|
|
1591
|
+
buckets: [...config.buckets].sort((a, b) => a.rank - b.rank),
|
|
1592
|
+
closedStageKeys: [...config.closedStageKeys],
|
|
1593
|
+
followUpAfterDaysByStateKey: { ...config.followUpAfterDaysByStateKey }
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
function draftFromConfig(config, defaultBucketsList) {
|
|
1597
|
+
const defaultBuckets = new Map(defaultBucketsList.map((bucket) => [bucket.bucketKey, bucket]));
|
|
1598
|
+
const resolvedBuckets = new Map(config.buckets.map((bucket) => [bucket.bucketKey, bucket]));
|
|
1599
|
+
return {
|
|
1600
|
+
enabled: config.enabled,
|
|
1601
|
+
staleAfterDays: config.staleAfterDays,
|
|
1602
|
+
buckets: Object.fromEntries(
|
|
1603
|
+
BUCKET_KEYS.map((bucketKey) => {
|
|
1604
|
+
const bucket = resolvedBuckets.get(bucketKey) ?? defaultBuckets.get(bucketKey) ?? {
|
|
1605
|
+
label: bucketKey.replaceAll("_", " "),
|
|
1606
|
+
color: "gray",
|
|
1607
|
+
rank: 0
|
|
1608
|
+
};
|
|
1609
|
+
return [bucketKey, { label: bucket.label, color: bucket.color, rank: bucket.rank }];
|
|
1610
|
+
})
|
|
1611
|
+
)
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function toOverride(draft) {
|
|
1615
|
+
return {
|
|
1616
|
+
enabled: draft.enabled,
|
|
1617
|
+
staleAfterDays: draft.staleAfterDays,
|
|
1618
|
+
buckets: Object.fromEntries(
|
|
1619
|
+
BUCKET_KEYS.map((bucketKey) => [
|
|
1620
|
+
bucketKey,
|
|
1621
|
+
{
|
|
1622
|
+
label: draft.buckets[bucketKey].label.trim(),
|
|
1623
|
+
color: draft.buckets[bucketKey].color.trim(),
|
|
1624
|
+
rank: draft.buckets[bucketKey].rank
|
|
1625
|
+
}
|
|
1626
|
+
])
|
|
1627
|
+
)
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
function CrmSettingsPage() {
|
|
1631
|
+
const settingsQuery = useCrmPrioritySettings();
|
|
1632
|
+
const updateSettings = useUpdateCrmPrioritySettings();
|
|
1633
|
+
const resetSettings = useResetCrmPrioritySettings();
|
|
1634
|
+
const resolvedConfig = useMemo(() => toResolvedConfig(settingsQuery.data?.resolved), [settingsQuery.data?.resolved]);
|
|
1635
|
+
const defaultConfig = useMemo(() => toResolvedConfig(settingsQuery.data?.defaults), [settingsQuery.data?.defaults]);
|
|
1636
|
+
const [draft, setDraft] = useState(() => draftFromConfig(resolvedConfig, defaultConfig.buckets));
|
|
1637
|
+
useEffect(() => {
|
|
1638
|
+
if (settingsQuery.data) {
|
|
1639
|
+
setDraft(draftFromConfig(toResolvedConfig(settingsQuery.data.resolved), defaultConfig.buckets));
|
|
1640
|
+
}
|
|
1641
|
+
}, [settingsQuery.data, defaultConfig.buckets]);
|
|
1642
|
+
const hasOverride = Boolean(settingsQuery.data?.override);
|
|
1643
|
+
const isSaving = updateSettings.isPending || resetSettings.isPending;
|
|
1644
|
+
const updateBucket = (bucketKey, field, value) => {
|
|
1645
|
+
setDraft((current) => ({
|
|
1646
|
+
...current,
|
|
1647
|
+
buckets: {
|
|
1648
|
+
...current.buckets,
|
|
1649
|
+
[bucketKey]: {
|
|
1650
|
+
...current.buckets[bucketKey],
|
|
1651
|
+
[field]: value
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}));
|
|
1655
|
+
};
|
|
1656
|
+
const handleReset = async () => {
|
|
1657
|
+
const response = await resetSettings.mutateAsync();
|
|
1658
|
+
setDraft(draftFromConfig(toResolvedConfig(response.resolved), defaultConfig.buckets));
|
|
1659
|
+
};
|
|
1660
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsx(PageContainer, { children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
1661
|
+
/* @__PURE__ */ jsx(
|
|
1662
|
+
PageTitleCaption,
|
|
1663
|
+
{
|
|
1664
|
+
title: "CRM Settings",
|
|
1665
|
+
caption: "Scoped CRM controls for priority presentation and thresholds",
|
|
1666
|
+
rightSection: !settingsQuery.isLoading && !settingsQuery.error ? /* @__PURE__ */ jsx(
|
|
1667
|
+
Switch,
|
|
1668
|
+
{
|
|
1669
|
+
label: "Priority Enabled",
|
|
1670
|
+
checked: draft.enabled,
|
|
1671
|
+
onChange: (event) => setDraft((current) => ({ ...current, enabled: event.currentTarget.checked }))
|
|
1672
|
+
}
|
|
1673
|
+
) : null
|
|
1674
|
+
}
|
|
1675
|
+
),
|
|
1676
|
+
settingsQuery.isLoading ? /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) : settingsQuery.error ? /* @__PURE__ */ jsx(CenteredErrorState, { error: settingsQuery.error, title: "Failed to load CRM settings" }) : /* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { children: [
|
|
1677
|
+
/* @__PURE__ */ jsxs(Group, { justify: "space-between", align: "flex-start", children: [
|
|
1678
|
+
/* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
|
|
1679
|
+
/* @__PURE__ */ jsxs(Group, { gap: "xs", children: [
|
|
1680
|
+
/* @__PURE__ */ jsx(IconSettings, { size: 18 }),
|
|
1681
|
+
/* @__PURE__ */ jsx(Title, { order: 3, children: "Priority Rules" }),
|
|
1682
|
+
/* @__PURE__ */ jsx(Badge, { variant: "light", color: hasOverride ? "blue" : "gray", children: hasOverride ? "Custom" : "Org-OS defaults" })
|
|
1683
|
+
] }),
|
|
1684
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", c: "dimmed", children: "These settings are saved for CRM priority evaluation. Deals continue to receive priority from the backend response." })
|
|
1685
|
+
] }),
|
|
1686
|
+
/* @__PURE__ */ jsxs(Group, { gap: "xs", children: [
|
|
1687
|
+
/* @__PURE__ */ jsx(
|
|
1688
|
+
Button,
|
|
1689
|
+
{
|
|
1690
|
+
variant: "light",
|
|
1691
|
+
leftSection: /* @__PURE__ */ jsx(IconRestore, { size: 16 }),
|
|
1692
|
+
loading: resetSettings.isPending,
|
|
1693
|
+
disabled: isSaving,
|
|
1694
|
+
onClick: () => void handleReset(),
|
|
1695
|
+
children: "Reset defaults"
|
|
1696
|
+
}
|
|
1697
|
+
),
|
|
1698
|
+
/* @__PURE__ */ jsx(
|
|
1699
|
+
Button,
|
|
1700
|
+
{
|
|
1701
|
+
loading: updateSettings.isPending,
|
|
1702
|
+
disabled: isSaving,
|
|
1703
|
+
onClick: () => void updateSettings.mutateAsync(toOverride(draft)),
|
|
1704
|
+
children: "Save changes"
|
|
1705
|
+
}
|
|
1706
|
+
)
|
|
1707
|
+
] })
|
|
1708
|
+
] }),
|
|
1709
|
+
/* @__PURE__ */ jsx(
|
|
1710
|
+
NumberInput,
|
|
1711
|
+
{
|
|
1712
|
+
label: "Stale threshold",
|
|
1713
|
+
description: "Deals with no meaningful activity after this many days can move to Stale.",
|
|
1714
|
+
min: 1,
|
|
1715
|
+
max: 365,
|
|
1716
|
+
value: draft.staleAfterDays,
|
|
1717
|
+
onChange: (value) => setDraft((current) => ({ ...current, staleAfterDays: Number(value) || current.staleAfterDays })),
|
|
1718
|
+
suffix: " days",
|
|
1719
|
+
maw: 320
|
|
1720
|
+
}
|
|
1721
|
+
),
|
|
1722
|
+
/* @__PURE__ */ jsxs(Table, { style: { tableLayout: "fixed" }, children: [
|
|
1723
|
+
/* @__PURE__ */ jsx(Table.Thead, { children: /* @__PURE__ */ jsxs(Table.Tr, { children: [
|
|
1724
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 150, children: "Bucket" }),
|
|
1725
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 180, children: "Label" }),
|
|
1726
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 170, children: "Color" }),
|
|
1727
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 210, children: "Display order" }),
|
|
1728
|
+
/* @__PURE__ */ jsx(Table.Th, { w: 80, children: "Logic" })
|
|
1729
|
+
] }) }),
|
|
1730
|
+
/* @__PURE__ */ jsx(Table.Tbody, { children: BUCKET_KEYS.map((bucketKey) => {
|
|
1731
|
+
const bucket = draft.buckets[bucketKey];
|
|
1732
|
+
const defaultBucket = defaultConfig.buckets.find((candidate) => candidate.bucketKey === bucketKey);
|
|
1733
|
+
return /* @__PURE__ */ jsxs(Table.Tr, { children: [
|
|
1734
|
+
/* @__PURE__ */ jsxs(Table.Td, { children: [
|
|
1735
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", fw: 600, children: bucketKey.replaceAll("_", " ") }),
|
|
1736
|
+
/* @__PURE__ */ jsxs(
|
|
1737
|
+
Badge,
|
|
1738
|
+
{
|
|
1739
|
+
mt: 6,
|
|
1740
|
+
variant: "light",
|
|
1741
|
+
color: defaultBucket?.color ?? "gray",
|
|
1742
|
+
style: { textTransform: "none" },
|
|
1743
|
+
children: [
|
|
1744
|
+
"Default: ",
|
|
1745
|
+
defaultBucket ? getOrderLabel(defaultBucket.rank) : "Not set"
|
|
1746
|
+
]
|
|
1747
|
+
}
|
|
1748
|
+
)
|
|
1749
|
+
] }),
|
|
1750
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(
|
|
1751
|
+
TextInput,
|
|
1752
|
+
{
|
|
1753
|
+
size: "sm",
|
|
1754
|
+
value: bucket.label,
|
|
1755
|
+
onChange: (event) => updateBucket(bucketKey, "label", event.currentTarget.value)
|
|
1756
|
+
}
|
|
1757
|
+
) }),
|
|
1758
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsxs(Group, { gap: "xs", wrap: "nowrap", children: [
|
|
1759
|
+
/* @__PURE__ */ jsx(ColorSwatch, { color: `var(--mantine-color-${bucket.color}-6)`, size: 18 }),
|
|
1760
|
+
/* @__PURE__ */ jsx(
|
|
1761
|
+
Select,
|
|
1762
|
+
{
|
|
1763
|
+
size: "sm",
|
|
1764
|
+
data: COLOR_OPTIONS,
|
|
1765
|
+
value: bucket.color,
|
|
1766
|
+
searchable: true,
|
|
1767
|
+
allowDeselect: false,
|
|
1768
|
+
onChange: (value) => updateBucket(bucketKey, "color", value ?? bucket.color)
|
|
1769
|
+
}
|
|
1770
|
+
)
|
|
1771
|
+
] }) }),
|
|
1772
|
+
/* @__PURE__ */ jsxs(Table.Td, { children: [
|
|
1773
|
+
/* @__PURE__ */ jsx(
|
|
1774
|
+
Select,
|
|
1775
|
+
{
|
|
1776
|
+
size: "sm",
|
|
1777
|
+
data: ORDER_OPTIONS,
|
|
1778
|
+
value: String(bucket.rank),
|
|
1779
|
+
allowDeselect: false,
|
|
1780
|
+
onChange: (value) => updateBucket(bucketKey, "rank", Number(value) || bucket.rank)
|
|
1781
|
+
}
|
|
1782
|
+
),
|
|
1783
|
+
/* @__PURE__ */ jsx(Text, { mt: 4, size: "xs", c: "dimmed", children: "Lower order appears earlier in Pipeline and Deals." })
|
|
1784
|
+
] }),
|
|
1785
|
+
/* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsxs(Popover, { width: 360, position: "left", withArrow: true, shadow: "md", children: [
|
|
1786
|
+
/* @__PURE__ */ jsx(Popover.Target, { children: /* @__PURE__ */ jsx(ActionIcon, { variant: "subtle", color: "gray", "aria-label": `Show ${bucket.label} logic`, children: /* @__PURE__ */ jsx(IconInfoCircle, { size: 18 }) }) }),
|
|
1787
|
+
/* @__PURE__ */ jsx(Popover.Dropdown, { children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1788
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1789
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", fw: 700, tt: "uppercase", c: "dimmed", children: "When it applies" }),
|
|
1790
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: BUCKET_RULE_COPY[bucketKey].applies })
|
|
1791
|
+
] }),
|
|
1792
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1793
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", fw: 700, tt: "uppercase", c: "dimmed", children: "Example" }),
|
|
1794
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: BUCKET_RULE_COPY[bucketKey].example })
|
|
1795
|
+
] })
|
|
1796
|
+
] }) })
|
|
1797
|
+
] }) })
|
|
1798
|
+
] }, bucketKey);
|
|
1799
|
+
}) })
|
|
1800
|
+
] })
|
|
1801
|
+
] }) })
|
|
1802
|
+
] }) }) });
|
|
1803
|
+
}
|
|
1804
|
+
function ContactDetailPage({ contactId }) {
|
|
1805
|
+
const navigate = useNavigate();
|
|
1806
|
+
const { data: contact, isLoading, error } = useContact(contactId);
|
|
1807
|
+
const fullName = contact ? [contact.firstName, contact.lastName].filter(Boolean).join(" ") || contact.email : "Contact Detail";
|
|
1808
|
+
const title = contact ? fullName : "Contact Detail";
|
|
1809
|
+
const headerActions = /* @__PURE__ */ jsx(
|
|
1810
|
+
Button,
|
|
1811
|
+
{
|
|
1812
|
+
variant: "light",
|
|
1813
|
+
size: "sm",
|
|
1814
|
+
leftSection: /* @__PURE__ */ jsx(IconArrowLeft, { size: 16 }),
|
|
1815
|
+
onClick: () => navigate({ to: "/crm" }),
|
|
1816
|
+
children: "CRM"
|
|
1817
|
+
}
|
|
1818
|
+
);
|
|
1819
|
+
if (isLoading) {
|
|
1820
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1821
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Loading contact details...", rightSection: headerActions }) }),
|
|
1822
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(Center, { p: "xl", children: /* @__PURE__ */ jsx(Loader, {}) }) })
|
|
1823
|
+
] }) });
|
|
1824
|
+
}
|
|
1825
|
+
if (error) {
|
|
1826
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1827
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Unable to load contact details", rightSection: headerActions }) }),
|
|
1828
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(CenteredErrorState, { error, title: "Failed to load contact" }) })
|
|
1829
|
+
] }) });
|
|
1830
|
+
}
|
|
1831
|
+
if (!contact) {
|
|
1832
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1833
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title, caption: "Contact not found", rightSection: headerActions }) }),
|
|
1834
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsx(
|
|
1835
|
+
EmptyState,
|
|
1836
|
+
{
|
|
1837
|
+
icon: IconUser,
|
|
1838
|
+
title: "Contact not found",
|
|
1839
|
+
description: "The selected contact no longer exists."
|
|
1840
|
+
}
|
|
1841
|
+
) })
|
|
1842
|
+
] }) });
|
|
1843
|
+
}
|
|
1844
|
+
const liData = contact.enrichmentData;
|
|
1845
|
+
const caption = [contact.title, contact.email].filter(Boolean).join(" \xB7 ") || [contact.company?.name].filter(Boolean).join("") || "Contact";
|
|
1846
|
+
return /* @__PURE__ */ jsx(SubshellContentContainer, { children: /* @__PURE__ */ jsxs(PageContainer, { children: [
|
|
1847
|
+
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(PageTitleCaption, { title: fullName, caption, rightSection: headerActions }) }),
|
|
1848
|
+
/* @__PURE__ */ jsx(Paper, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "md", p: "md", children: [
|
|
1849
|
+
/* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1850
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Overview" }),
|
|
1851
|
+
/* @__PURE__ */ jsxs(Group, { gap: "xs", children: [
|
|
1852
|
+
/* @__PURE__ */ jsx(Badge, { variant: "light", color: "blue", children: contact.status }),
|
|
1853
|
+
contact.openingLine && /* @__PURE__ */ jsx(Badge, { variant: "light", color: "green", children: "Personalized" })
|
|
1854
|
+
] }),
|
|
1855
|
+
/* @__PURE__ */ jsxs(SimpleGrid, { cols: { base: 1, sm: 2 }, spacing: "sm", children: [
|
|
1856
|
+
/* @__PURE__ */ jsxs(Group, { children: [
|
|
1857
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Email:" }),
|
|
1858
|
+
/* @__PURE__ */ jsx(Text, { children: contact.email })
|
|
1859
|
+
] }),
|
|
1860
|
+
contact.title && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1861
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Title:" }),
|
|
1862
|
+
/* @__PURE__ */ jsx(Text, { children: contact.title })
|
|
1863
|
+
] }),
|
|
1864
|
+
contact.headline && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1865
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "Headline:" }),
|
|
1866
|
+
/* @__PURE__ */ jsx(Text, { children: contact.headline })
|
|
1867
|
+
] }),
|
|
1868
|
+
contact.linkedinUrl && /* @__PURE__ */ jsxs(Group, { children: [
|
|
1869
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: "LinkedIn:" }),
|
|
1870
|
+
/* @__PURE__ */ jsx(Anchor, { href: contact.linkedinUrl, target: "_blank", size: "sm", children: "View Profile" })
|
|
1871
|
+
] })
|
|
1872
|
+
] }),
|
|
1873
|
+
/* @__PURE__ */ jsxs(Text, { size: "xs", c: "dimmed", children: [
|
|
1874
|
+
"Created: ",
|
|
1875
|
+
new Date(contact.createdAt).toLocaleDateString(),
|
|
1876
|
+
contact.updatedAt && ` | Updated: ${new Date(contact.updatedAt).toLocaleDateString()}`
|
|
1877
|
+
] })
|
|
1878
|
+
] }) }),
|
|
1879
|
+
contact.company && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1880
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Company" }),
|
|
1881
|
+
/* @__PURE__ */ jsxs(
|
|
1882
|
+
Card,
|
|
1883
|
+
{
|
|
1884
|
+
withBorder: true,
|
|
1885
|
+
style: { cursor: "pointer" },
|
|
1886
|
+
onClick: () => navigate({
|
|
1887
|
+
to: "/crm/companies/$companyId",
|
|
1888
|
+
params: { companyId: contact.company.id }
|
|
1889
|
+
}),
|
|
1890
|
+
children: [
|
|
1891
|
+
/* @__PURE__ */ jsx(Text, { fw: 500, children: contact.company.name }),
|
|
1892
|
+
contact.company.domain && /* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: contact.company.domain })
|
|
1893
|
+
]
|
|
1894
|
+
}
|
|
1895
|
+
)
|
|
1896
|
+
] }) }),
|
|
1897
|
+
(liData?.linkedin?.summary || liData?.linkedin?.pastExperience || liData?.linkedin?.education) && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1898
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "LinkedIn Data" }),
|
|
1899
|
+
liData.linkedin?.summary && /* @__PURE__ */ jsxs(Stack, { gap: "xs", children: [
|
|
1900
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: "Summary" }),
|
|
1901
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: liData.linkedin.summary })
|
|
1902
|
+
] }),
|
|
1903
|
+
liData.linkedin?.pastExperience && /* @__PURE__ */ jsxs(Stack, { gap: "xs", children: [
|
|
1904
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: "Past Experience" }),
|
|
1905
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: liData.linkedin.pastExperience })
|
|
1906
|
+
] }),
|
|
1907
|
+
liData.linkedin?.education && /* @__PURE__ */ jsxs(Stack, { gap: "xs", children: [
|
|
1908
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: "Education" }),
|
|
1909
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: liData.linkedin.education })
|
|
1910
|
+
] })
|
|
1911
|
+
] }) }),
|
|
1912
|
+
liData?.linkedin?.activity && liData.linkedin.activity.length > 0 && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1913
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Recent Activity" }),
|
|
1914
|
+
/* @__PURE__ */ jsx(Stack, { gap: "xs", children: liData.linkedin.activity.slice(0, 3).map((activity, i) => /* @__PURE__ */ jsxs(Card, { withBorder: true, children: [
|
|
1915
|
+
activity.date && /* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: activity.date }),
|
|
1916
|
+
activity.content && /* @__PURE__ */ jsx(Text, { size: "sm", children: activity.content })
|
|
1917
|
+
] }, i)) })
|
|
1918
|
+
] }) }),
|
|
1919
|
+
contact.openingLine && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1920
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Personalization" }),
|
|
1921
|
+
/* @__PURE__ */ jsxs(Stack, { gap: "xs", children: [
|
|
1922
|
+
/* @__PURE__ */ jsx(Text, { size: "xs", c: "dimmed", children: "Opening Line" }),
|
|
1923
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", children: contact.openingLine })
|
|
1924
|
+
] })
|
|
1925
|
+
] }) }),
|
|
1926
|
+
contact.filterReason && /* @__PURE__ */ jsx(Card, { withBorder: true, children: /* @__PURE__ */ jsxs(Stack, { gap: "sm", children: [
|
|
1927
|
+
/* @__PURE__ */ jsx(Title, { order: 4, children: "Qualification" }),
|
|
1928
|
+
/* @__PURE__ */ jsx(Text, { size: "sm", c: "red", children: contact.filterReason })
|
|
1929
|
+
] }) })
|
|
1930
|
+
] }) })
|
|
1931
|
+
] }) });
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
export { ActivityFeedWidget, CompanyDetailPage, ContactDetailPage, ConversationThread, CrmOverview, CrmSettingsPage, CrmSidebar, CrmSidebarTop, DealDetailPage, DealsListPage, MetricsStrip, PIPELINE_FUNNEL_ORDER, PipelineFunnelWidget, compareDealsByPriority, crmPrioritySettingsKeys, getCrmApiInterfaceReadiness, setDealReferrer, useCrmPipelineConfig, useCrmPipelineSummary, useCrmPrioritySettings, useCrmQuickMetrics, useRecentCrmActivity, useResetCrmPrioritySettings, useUpdateCrmPrioritySettings };
|