@fayz-ai/plugin-crm 0.8.0 → 0.8.1
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/components/CrmGeneralSettings.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/index.cjs +168 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -34
- package/dist/index.js.map +1 -1
- package/dist/lib/form-answers.d.ts +10 -0
- package/dist/lib/form-answers.d.ts.map +1 -0
- package/dist/locales/en.d.ts.map +1 -1
- package/dist/locales/pt-BR.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/public/context.d.ts +23 -0
- package/dist/public/context.d.ts.map +1 -0
- package/dist/public/createPublicFormsPlugin.d.ts +38 -0
- package/dist/public/createPublicFormsPlugin.d.ts.map +1 -0
- package/dist/public/data.supabase.d.ts +7 -0
- package/dist/public/data.supabase.d.ts.map +1 -0
- package/dist/public/inbox.d.ts +22 -0
- package/dist/public/inbox.d.ts.map +1 -0
- package/dist/public/index.cjs +306 -0
- package/dist/public/index.cjs.map +1 -0
- package/dist/public/index.d.ts +10 -0
- package/dist/public/index.d.ts.map +1 -0
- package/dist/public/index.js +298 -0
- package/dist/public/index.js.map +1 -0
- package/dist/public/types.d.ts +92 -0
- package/dist/public/types.d.ts.map +1 -0
- package/dist/views/DealSidebar.d.ts.map +1 -1
- package/dist/views/LeadDetailView.d.ts.map +1 -1
- package/dist/views/LeadFormView.d.ts.map +1 -1
- package/dist/views/LeadListView.d.ts.map +1 -1
- package/dist/views/PipelineView.d.ts.map +1 -1
- package/dist/views/QuoteFormView.d.ts.map +1 -1
- package/package.json +11 -5
- package/src/components/CrmGeneralSettings.tsx +35 -15
- package/src/data/supabase.ts +47 -4
- package/src/index.ts +9 -0
- package/src/lib/form-answers.tsx +39 -0
- package/src/locales/en.ts +1 -0
- package/src/locales/pt-BR.ts +1 -0
- package/src/migrations/005_public_lead.sql +189 -0
- package/src/migrations/006_lead_enters_pipeline.sql +265 -0
- package/src/migrations/index.ts +461 -1
- package/src/public/context.tsx +69 -0
- package/src/public/createPublicFormsPlugin.ts +188 -0
- package/src/public/data.supabase.ts +86 -0
- package/src/public/inbox.ts +136 -0
- package/src/public/index.ts +30 -0
- package/src/public/types.ts +113 -0
- package/src/views/DealSidebar.tsx +31 -0
- package/src/views/LeadDetailView.tsx +53 -0
- package/src/views/LeadFormView.tsx +10 -0
- package/src/views/LeadListView.tsx +19 -0
- package/src/views/PipelineView.tsx +34 -1
- package/src/views/QuoteFormView.tsx +5 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAIzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAanD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,OAAO,CAAA;QAChB,UAAU,CAAC,EAAE,OAAO,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createPluginContext, PluginSettingsPanel, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, SettingsGroup, ToggleRow, formatCurrency, PersonLink } from '@fayz-ai/saas';
|
|
2
|
+
import { createPluginContext, PluginSettingsPanel, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, useTenantPluginSettings, SettingsGroup, ToggleRow, useLimitGuard, formatCurrency, PersonLink, invalidateLimit } from '@fayz-ai/saas';
|
|
3
3
|
import { registerTranslations, createSafeDataProvider, useTranslation, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
|
|
4
4
|
import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, Button, SubpageHeader, ListView, useSaveBar, SearchSelect, DatePicker, DataTable, Breadcrumb, DashboardCanvas, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter, CurrencyInput, Dropdown, DropdownTrigger, DropdownContent, DropdownLabel, DropdownSeparator, DropdownItem, ConfirmDialog, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -13,44 +13,47 @@ var CrmContextProvider = ctx.ContextProvider;
|
|
|
13
13
|
var useCrmConfig = ctx.useConfig;
|
|
14
14
|
var useCrmProvider = ctx.useProvider;
|
|
15
15
|
var useCrmStore = ctx.useStore;
|
|
16
|
+
var CRM_DEFAULTS = {
|
|
17
|
+
autoAssign: false,
|
|
18
|
+
requireSource: true,
|
|
19
|
+
leadScoring: false,
|
|
20
|
+
duplicateDetection: true,
|
|
21
|
+
autoCreateDeal: true,
|
|
22
|
+
requireCloseDate: false,
|
|
23
|
+
rottingDeals: true,
|
|
24
|
+
weightedPipeline: true,
|
|
25
|
+
autoNumberQuotes: true,
|
|
26
|
+
defaultValidity: true,
|
|
27
|
+
requireApproval: false,
|
|
28
|
+
overdueAlerts: true,
|
|
29
|
+
stageChangeAlerts: false,
|
|
30
|
+
newLeadNotif: true
|
|
31
|
+
};
|
|
16
32
|
function CrmGeneralSettings() {
|
|
17
33
|
const t2 = useTranslation();
|
|
34
|
+
const s = useTenantPluginSettings("crm", CRM_DEFAULTS);
|
|
18
35
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
19
36
|
/* @__PURE__ */ jsxs(SettingsGroup, { title: t2("crm.settings.leadManagement"), description: t2("crm.settings.leadManagementDesc"), children: [
|
|
20
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoAssign"), description: t2("crm.settings.autoAssignDesc"), checked:
|
|
21
|
-
|
|
22
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.
|
|
23
|
-
|
|
24
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.leadScoring"), description: t2("crm.settings.leadScoringDesc"), checked: false, onChange: () => {
|
|
25
|
-
} }),
|
|
26
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.duplicateDetection"), description: t2("crm.settings.duplicateDetectionDesc"), checked: true, onChange: () => {
|
|
27
|
-
} })
|
|
37
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoAssign"), description: t2("crm.settings.autoAssignDesc"), checked: s.get("autoAssign"), onChange: (v) => s.set("autoAssign", v) }),
|
|
38
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.requireSource"), description: t2("crm.settings.requireSourceDesc"), checked: s.get("requireSource"), onChange: (v) => s.set("requireSource", v) }),
|
|
39
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.leadScoring"), description: t2("crm.settings.leadScoringDesc"), checked: s.get("leadScoring"), onChange: (v) => s.set("leadScoring", v) }),
|
|
40
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.duplicateDetection"), description: t2("crm.settings.duplicateDetectionDesc"), checked: s.get("duplicateDetection"), onChange: (v) => s.set("duplicateDetection", v) })
|
|
28
41
|
] }),
|
|
29
42
|
/* @__PURE__ */ jsxs(SettingsGroup, { title: t2("crm.settings.deals"), description: t2("crm.settings.dealsDesc"), children: [
|
|
30
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoCreateDeal"), description: t2("crm.settings.autoCreateDealDesc"), checked:
|
|
31
|
-
|
|
32
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.
|
|
33
|
-
|
|
34
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.rottingDeals"), description: t2("crm.settings.rottingDealsDesc"), checked: true, onChange: () => {
|
|
35
|
-
} }),
|
|
36
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.weightedPipeline"), description: t2("crm.settings.weightedPipelineDesc"), checked: true, onChange: () => {
|
|
37
|
-
} })
|
|
43
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoCreateDeal"), description: t2("crm.settings.autoCreateDealDesc"), checked: s.get("autoCreateDeal"), onChange: (v) => s.set("autoCreateDeal", v) }),
|
|
44
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.requireCloseDate"), description: t2("crm.settings.requireCloseDateDesc"), checked: s.get("requireCloseDate"), onChange: (v) => s.set("requireCloseDate", v) }),
|
|
45
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.rottingDeals"), description: t2("crm.settings.rottingDealsDesc"), checked: s.get("rottingDeals"), onChange: (v) => s.set("rottingDeals", v) }),
|
|
46
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.weightedPipeline"), description: t2("crm.settings.weightedPipelineDesc"), checked: s.get("weightedPipeline"), onChange: (v) => s.set("weightedPipeline", v) })
|
|
38
47
|
] }),
|
|
39
48
|
/* @__PURE__ */ jsxs(SettingsGroup, { title: t2("crm.settings.quotes"), description: t2("crm.settings.quotesDesc"), children: [
|
|
40
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoNumberQuotes"), description: t2("crm.settings.autoNumberQuotesDesc"), checked:
|
|
41
|
-
|
|
42
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.
|
|
43
|
-
} }),
|
|
44
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.requireApproval"), description: t2("crm.settings.requireApprovalDesc"), checked: false, onChange: () => {
|
|
45
|
-
} })
|
|
49
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.autoNumberQuotes"), description: t2("crm.settings.autoNumberQuotesDesc"), checked: s.get("autoNumberQuotes"), onChange: (v) => s.set("autoNumberQuotes", v) }),
|
|
50
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.defaultValidity"), description: t2("crm.settings.defaultValidityDesc"), checked: s.get("defaultValidity"), onChange: (v) => s.set("defaultValidity", v) }),
|
|
51
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.requireApproval"), description: t2("crm.settings.requireApprovalDesc"), checked: s.get("requireApproval"), onChange: (v) => s.set("requireApproval", v) })
|
|
46
52
|
] }),
|
|
47
53
|
/* @__PURE__ */ jsxs(SettingsGroup, { title: t2("crm.settings.notifications"), description: t2("crm.settings.notificationsDesc"), children: [
|
|
48
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.overdueAlerts"), description: t2("crm.settings.overdueAlertsDesc"), checked:
|
|
49
|
-
|
|
50
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.
|
|
51
|
-
} }),
|
|
52
|
-
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.newLeadNotif"), description: t2("crm.settings.newLeadNotifDesc"), checked: true, onChange: () => {
|
|
53
|
-
} })
|
|
54
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.overdueAlerts"), description: t2("crm.settings.overdueAlertsDesc"), checked: s.get("overdueAlerts"), onChange: (v) => s.set("overdueAlerts", v) }),
|
|
55
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.stageChangeAlerts"), description: t2("crm.settings.stageChangeAlertsDesc"), checked: s.get("stageChangeAlerts"), onChange: (v) => s.set("stageChangeAlerts", v) }),
|
|
56
|
+
/* @__PURE__ */ jsx(ToggleRow, { label: t2("crm.settings.newLeadNotif"), description: t2("crm.settings.newLeadNotifDesc"), checked: s.get("newLeadNotif"), onChange: (v) => s.set("newLeadNotif", v) })
|
|
54
57
|
] })
|
|
55
58
|
] });
|
|
56
59
|
}
|
|
@@ -260,6 +263,23 @@ function QuoteStatusDropdown({ quote, onStatusChange, size = "default" }) {
|
|
|
260
263
|
showReject && /* @__PURE__ */ jsx(RejectModal, { onConfirm: handleReject, onCancel: () => setShowReject(false) })
|
|
261
264
|
] });
|
|
262
265
|
}
|
|
266
|
+
|
|
267
|
+
// src/lib/form-answers.tsx
|
|
268
|
+
function humanizeKey(key) {
|
|
269
|
+
const spaced = key.replace(/[_-]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2");
|
|
270
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
271
|
+
}
|
|
272
|
+
function renderFieldValue(value) {
|
|
273
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
274
|
+
if (Array.isArray(value)) return value.length ? value.join(", ") : null;
|
|
275
|
+
if (typeof value === "boolean") return value ? "Sim" : "N\xE3o";
|
|
276
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
277
|
+
return String(value);
|
|
278
|
+
}
|
|
279
|
+
function answerEntries(fields) {
|
|
280
|
+
if (!fields || typeof fields !== "object" || Array.isArray(fields)) return [];
|
|
281
|
+
return Object.entries(fields).filter(([, v]) => v !== null && v !== void 0 && v !== "");
|
|
282
|
+
}
|
|
263
283
|
var TYPE_ICONS = {
|
|
264
284
|
call: Phone,
|
|
265
285
|
email: Mail,
|
|
@@ -288,6 +308,19 @@ function TabBar({ active, counts, onChange }) {
|
|
|
288
308
|
tab.id
|
|
289
309
|
)) });
|
|
290
310
|
}
|
|
311
|
+
function FormAnswers({ lead }) {
|
|
312
|
+
const t2 = useTranslation();
|
|
313
|
+
const entries = answerEntries(lead?.metadata?.fields);
|
|
314
|
+
if (entries.length === 0) return null;
|
|
315
|
+
const formId = lead?.metadata?.formId;
|
|
316
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
317
|
+
/* @__PURE__ */ jsx("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: formId ? `${t2("crm.leadDetail.formAnswers")} \xB7 ${formId}` : t2("crm.leadDetail.formAnswers") }),
|
|
318
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-xl border divide-y", children: entries.map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3 px-4 py-2.5", children: [
|
|
319
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground shrink-0 min-w-24", children: humanizeKey(key) }),
|
|
320
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-right flex-1 break-words", children: renderFieldValue(value) ?? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/50", children: "\u2014" }) })
|
|
321
|
+
] }, key)) })
|
|
322
|
+
] });
|
|
323
|
+
}
|
|
291
324
|
function OverviewTab({ deal, lead, currency }) {
|
|
292
325
|
const t2 = useTranslation();
|
|
293
326
|
const initial = (lead?.name ?? deal.contactName ?? deal.title).charAt(0).toUpperCase();
|
|
@@ -353,6 +386,7 @@ function OverviewTab({ deal, lead, currency }) {
|
|
|
353
386
|
] })
|
|
354
387
|
] })
|
|
355
388
|
] }),
|
|
389
|
+
/* @__PURE__ */ jsx(FormAnswers, { lead }),
|
|
356
390
|
deal.tags && deal.tags.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
357
391
|
/* @__PURE__ */ jsx("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: t2("crm.dealSidebar.tags") }),
|
|
358
392
|
/* @__PURE__ */ jsx("div", { className: "flex gap-1.5 flex-wrap", children: deal.tags.map((tag) => /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-medium text-muted-foreground", children: tag }, tag)) })
|
|
@@ -662,6 +696,22 @@ function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead }) {
|
|
|
662
696
|
useEffect(() => {
|
|
663
697
|
if (pipelines.length > 0) fetchDealsByStage(pipelines[0].id);
|
|
664
698
|
}, [pipelines]);
|
|
699
|
+
const pipelineId = pipelines[0]?.id;
|
|
700
|
+
useEffect(() => {
|
|
701
|
+
if (!pipelineId) return;
|
|
702
|
+
const supabase = getSupabaseClientOptional();
|
|
703
|
+
if (!supabase) return;
|
|
704
|
+
const channel = supabase.channel(`crm:board:${pipelineId}`).on(
|
|
705
|
+
"postgres_changes",
|
|
706
|
+
{ event: "*", schema: "public", table: "plg_crm_deal_extensions" },
|
|
707
|
+
() => {
|
|
708
|
+
void fetchDealsByStage(pipelineId);
|
|
709
|
+
}
|
|
710
|
+
).subscribe();
|
|
711
|
+
return () => {
|
|
712
|
+
supabase.removeChannel(channel);
|
|
713
|
+
};
|
|
714
|
+
}, [pipelineId]);
|
|
665
715
|
useEffect(() => {
|
|
666
716
|
if (savingDealIds.size === 0) setOptimisticBoard(null);
|
|
667
717
|
}, [dealsByStage, savingDealIds]);
|
|
@@ -786,6 +836,24 @@ var columns = [
|
|
|
786
836
|
const opt = STATUS_OPTIONS.find((o) => o.value === status);
|
|
787
837
|
return /* @__PURE__ */ jsx("span", { className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${opt?.color ?? "bg-muted text-muted-foreground"}`, children: opt?.label ?? status });
|
|
788
838
|
}
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
// When the lead came in. The list is already sorted by it (provider orders
|
|
842
|
+
// created_at desc) but never showed it, so "is this enquiry from today or
|
|
843
|
+
// from March?" was unanswerable without opening the record.
|
|
844
|
+
accessorKey: "createdAt",
|
|
845
|
+
header: "Entrada",
|
|
846
|
+
cell: ({ getValue }) => {
|
|
847
|
+
const raw = getValue();
|
|
848
|
+
if (!raw) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: "\u2014" });
|
|
849
|
+
const at = new Date(raw);
|
|
850
|
+
if (Number.isNaN(at.getTime())) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: "\u2014" });
|
|
851
|
+
return /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs whitespace-nowrap", title: at.toLocaleString(), children: [
|
|
852
|
+
at.toLocaleDateString(void 0, { day: "2-digit", month: "2-digit", year: "2-digit" }),
|
|
853
|
+
" \xB7 ",
|
|
854
|
+
at.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" })
|
|
855
|
+
] });
|
|
856
|
+
}
|
|
789
857
|
}
|
|
790
858
|
];
|
|
791
859
|
function LeadListView({ onNew, onEdit }) {
|
|
@@ -828,6 +896,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
828
896
|
function LeadFormView({ onSaved }) {
|
|
829
897
|
const t2 = useTranslation();
|
|
830
898
|
const createLead = useCrmStore((s) => s.createLead);
|
|
899
|
+
const guardLeads = useLimitGuard("leads");
|
|
831
900
|
const fetchPipelines = useCrmStore((s) => s.fetchPipelines);
|
|
832
901
|
const pipelines = useCrmStore((s) => s.pipelines);
|
|
833
902
|
useEffect(() => {
|
|
@@ -844,9 +913,12 @@ function LeadFormView({ onSaved }) {
|
|
|
844
913
|
toast.error(t2("common.formIncomplete"));
|
|
845
914
|
return;
|
|
846
915
|
}
|
|
916
|
+
if (await guardLeads() === "blocked") return;
|
|
847
917
|
setSaving(true);
|
|
848
918
|
try {
|
|
849
919
|
const lead = await createLead({ name, email: email || void 0, phone: phone || void 0, company: company || void 0, notes: notes || void 0 });
|
|
920
|
+
invalidateLimit("leads");
|
|
921
|
+
invalidateLimit("deals");
|
|
850
922
|
onSaved?.(lead.id);
|
|
851
923
|
} finally {
|
|
852
924
|
setSaving(false);
|
|
@@ -1096,6 +1168,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1096
1168
|
const { currency, itemTypes } = config;
|
|
1097
1169
|
const createQuote = useCrmStore((s) => s.createQuote);
|
|
1098
1170
|
const updateQuote = useCrmStore((s) => s.updateQuote);
|
|
1171
|
+
const guardQuotes = useLimitGuard("quotes");
|
|
1099
1172
|
const isEdit = !!quoteId;
|
|
1100
1173
|
const [loadingExisting, setLoadingExisting] = useState(isEdit || !!leadId);
|
|
1101
1174
|
const [linkedLeadId, setLinkedLeadId] = useState(leadId ?? "");
|
|
@@ -1174,6 +1247,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1174
1247
|
toast.error(t2("crm.quoteForm.errNoItems"));
|
|
1175
1248
|
return;
|
|
1176
1249
|
}
|
|
1250
|
+
if (!isEdit && await guardQuotes() === "blocked") return;
|
|
1177
1251
|
setSaving(true);
|
|
1178
1252
|
try {
|
|
1179
1253
|
const input = {
|
|
@@ -1199,6 +1273,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1199
1273
|
onSaved?.(quoteId);
|
|
1200
1274
|
} else {
|
|
1201
1275
|
const created = await createQuote(input);
|
|
1276
|
+
invalidateLimit("quotes");
|
|
1202
1277
|
onSaved?.(created?.id);
|
|
1203
1278
|
}
|
|
1204
1279
|
} finally {
|
|
@@ -1717,6 +1792,17 @@ var STATUS_COLORS2 = {
|
|
|
1717
1792
|
converted: "bg-warning-soft text-warning-soft-foreground",
|
|
1718
1793
|
lost: "bg-destructive-soft text-destructive-soft-foreground"
|
|
1719
1794
|
};
|
|
1795
|
+
function humanizeKey2(key) {
|
|
1796
|
+
const spaced = key.replace(/[_-]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2");
|
|
1797
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
1798
|
+
}
|
|
1799
|
+
function renderFieldValue2(value) {
|
|
1800
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
1801
|
+
if (Array.isArray(value)) return value.length ? value.join(", ") : null;
|
|
1802
|
+
if (typeof value === "boolean") return value ? "Sim" : "N\xE3o";
|
|
1803
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
1804
|
+
return String(value);
|
|
1805
|
+
}
|
|
1720
1806
|
function FieldRow({ label, value }) {
|
|
1721
1807
|
return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-3 gap-4 py-3", children: [
|
|
1722
1808
|
/* @__PURE__ */ jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: label }),
|
|
@@ -1813,6 +1899,24 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
|
|
|
1813
1899
|
/* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.source"), value: lead.sourceName }) })
|
|
1814
1900
|
] }) })
|
|
1815
1901
|
] }),
|
|
1902
|
+
(() => {
|
|
1903
|
+
const meta = lead.metadata ?? {};
|
|
1904
|
+
const fields = Object.entries(meta.fields ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
|
|
1905
|
+
const utm = Object.entries(meta.utm ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
|
|
1906
|
+
if (!fields.length && !utm.length) return null;
|
|
1907
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1908
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.formAnswers") }),
|
|
1909
|
+
/* @__PURE__ */ jsxs("div", { className: "rounded-xl border bg-card shadow-sm", children: [
|
|
1910
|
+
/* @__PURE__ */ jsx("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: fields.map(([key, value]) => /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: humanizeKey2(key), value: renderFieldValue2(value) }) }, key)) }),
|
|
1911
|
+
utm.length > 0 && /* @__PURE__ */ jsx("div", { className: "border-t px-5 py-3 flex flex-wrap gap-x-4 gap-y-1", children: utm.map(([key, value]) => /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
1912
|
+
humanizeKey2(key.replace(/^utm_/, "")),
|
|
1913
|
+
":",
|
|
1914
|
+
" ",
|
|
1915
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground", children: renderFieldValue2(value) })
|
|
1916
|
+
] }, key)) })
|
|
1917
|
+
] })
|
|
1918
|
+
] });
|
|
1919
|
+
})(),
|
|
1816
1920
|
deal && /* @__PURE__ */ jsxs("div", { children: [
|
|
1817
1921
|
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.pipeline") }),
|
|
1818
1922
|
/* @__PURE__ */ jsx("div", { className: "rounded-xl border bg-card shadow-sm", children: /* @__PURE__ */ jsxs("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: [
|
|
@@ -2802,6 +2906,12 @@ function getClients() {
|
|
|
2802
2906
|
if (!supabase) throw new Error("Supabase not initialized");
|
|
2803
2907
|
return { core: supabase, pub: supabase };
|
|
2804
2908
|
}
|
|
2909
|
+
async function mergePersonMetadata(personId, patch) {
|
|
2910
|
+
const { core } = getClients();
|
|
2911
|
+
const { data: row } = await core.from("people").select("metadata").eq("id", personId).maybeSingle();
|
|
2912
|
+
const current = row?.metadata ?? {};
|
|
2913
|
+
await core.from("people").update({ metadata: { ...current, ...patch } }).eq("id", personId);
|
|
2914
|
+
}
|
|
2805
2915
|
function createSupabaseCrmProvider(options) {
|
|
2806
2916
|
const provider = {
|
|
2807
2917
|
// --- Pipelines (public.plg_crm_pipelines + plg_crm_pipeline_stages) ---
|
|
@@ -2860,8 +2970,16 @@ function createSupabaseCrmProvider(options) {
|
|
|
2860
2970
|
phone: r.phone,
|
|
2861
2971
|
company: r.company,
|
|
2862
2972
|
status: r.lead_status ?? "new",
|
|
2973
|
+
sourceName: r.source_name,
|
|
2863
2974
|
tags: r.tags ?? [],
|
|
2864
2975
|
notes: r.notes,
|
|
2976
|
+
// Answers from a public form. Kept as an opaque bag so a new landing
|
|
2977
|
+
// page needs no schema change; the detail view renders whatever is here.
|
|
2978
|
+
metadata: {
|
|
2979
|
+
formId: r.form_id ?? void 0,
|
|
2980
|
+
fields: r.custom_fields ?? {},
|
|
2981
|
+
utm: r.utm ?? {}
|
|
2982
|
+
},
|
|
2865
2983
|
tenantId: r.tenant_id,
|
|
2866
2984
|
createdAt: r.created_at,
|
|
2867
2985
|
updatedAt: r.updated_at
|
|
@@ -2892,14 +3010,14 @@ function createSupabaseCrmProvider(options) {
|
|
|
2892
3010
|
if (partial.email !== void 0) row.email = partial.email;
|
|
2893
3011
|
if (partial.phone !== void 0) row.phone = partial.phone;
|
|
2894
3012
|
if (partial.notes !== void 0) row.notes = partial.notes;
|
|
2895
|
-
|
|
2896
|
-
const { data, error } = await core.from("people").update(row).eq("id", id).select().single();
|
|
3013
|
+
const { error } = await core.from("people").update(row).eq("id", id).select().single();
|
|
2897
3014
|
if (error) throw new Error(error.message);
|
|
3015
|
+
if (partial.status) await mergePersonMetadata(id, { status: partial.status });
|
|
2898
3016
|
return await provider.getLeadById(id);
|
|
2899
3017
|
},
|
|
2900
3018
|
async convertLeadToDeal(leadId, dealInput) {
|
|
2901
|
-
|
|
2902
|
-
await
|
|
3019
|
+
getClients();
|
|
3020
|
+
await mergePersonMetadata(leadId, { status: "converted" });
|
|
2903
3021
|
return provider.createDeal({ ...dealInput, leadId });
|
|
2904
3022
|
},
|
|
2905
3023
|
// --- Deals (via view — single query with all joins) ---
|
|
@@ -2957,6 +3075,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
2957
3075
|
status: r.status ?? "open",
|
|
2958
3076
|
contactName: r.contact_name,
|
|
2959
3077
|
tags: r.tags ?? [],
|
|
3078
|
+
// v_deals exposes de.lead_id and Deal declares leadId, but the mapping
|
|
3079
|
+
// dropped it — so DealSidebar's `if (d?.leadId)` never fired and the
|
|
3080
|
+
// card opened blank: no contact, no form answers. For a card that came
|
|
3081
|
+
// from a form, the lead IS the content.
|
|
3082
|
+
leadId: r.lead_id ?? void 0,
|
|
2960
3083
|
tenantId: r.tenant_id,
|
|
2961
3084
|
createdAt: r.created_at,
|
|
2962
3085
|
updatedAt: r.updated_at
|
|
@@ -2978,6 +3101,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
2978
3101
|
status: r.status ?? "open",
|
|
2979
3102
|
contactName: r.contact_name,
|
|
2980
3103
|
tags: r.tags ?? [],
|
|
3104
|
+
leadId: r.lead_id ?? void 0,
|
|
2981
3105
|
tenantId: r.tenant_id,
|
|
2982
3106
|
createdAt: r.created_at,
|
|
2983
3107
|
updatedAt: r.updated_at
|
|
@@ -3073,7 +3197,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3073
3197
|
const { data: ext } = await pub.from(T.dealExtensions).select("lead_id").eq("order_id", dealId).single();
|
|
3074
3198
|
if (ext?.lead_id) {
|
|
3075
3199
|
const newLeadStatus = deriveLeadStatus(typedStage);
|
|
3076
|
-
await
|
|
3200
|
+
await mergePersonMetadata(ext.lead_id, { status: newLeadStatus });
|
|
3077
3201
|
}
|
|
3078
3202
|
const { data: quotes } = await core.from("orders").select("id, status").eq("kind", "quote");
|
|
3079
3203
|
for (const q of quotes ?? []) {
|
|
@@ -3924,6 +4048,7 @@ var en = {
|
|
|
3924
4048
|
"crm.dealSidebar.viewLeadProfile": "View Full Lead Profile",
|
|
3925
4049
|
"crm.leadDetail.assignedTo": "Assigned to",
|
|
3926
4050
|
"crm.leadDetail.backToList": "Back to list",
|
|
4051
|
+
"crm.leadDetail.formAnswers": "Form answers",
|
|
3927
4052
|
"crm.leadDetail.company": "Company",
|
|
3928
4053
|
"crm.leadDetail.contactInfo": "Contact Information",
|
|
3929
4054
|
"crm.leadDetail.createQuote": "Create Quote",
|
|
@@ -4217,6 +4342,7 @@ var ptBR = {
|
|
|
4217
4342
|
"crm.dealSidebar.viewLeadProfile": "Ver Perfil Completo do Lead",
|
|
4218
4343
|
"crm.leadDetail.assignedTo": "Atribu\xEDdo a",
|
|
4219
4344
|
"crm.leadDetail.backToList": "Voltar \xE0 lista",
|
|
4345
|
+
"crm.leadDetail.formAnswers": "Dados do formul\xE1rio",
|
|
4220
4346
|
"crm.leadDetail.company": "Empresa",
|
|
4221
4347
|
"crm.leadDetail.contactInfo": "Informa\xE7\xF5es de Contato",
|
|
4222
4348
|
"crm.leadDetail.createQuote": "Criar Or\xE7amento",
|
|
@@ -4520,6 +4646,15 @@ function createCrmPlugin(options) {
|
|
|
4520
4646
|
{ id: "crm.quotes", label: config.labels.quotes, group: config.labels.pageTitle },
|
|
4521
4647
|
{ id: "crm.pipeline", label: config.labels.pipeline, group: config.labels.pageTitle }
|
|
4522
4648
|
],
|
|
4649
|
+
// Stock quantity caps. leads/deals/quotes share core tables partitioned by
|
|
4650
|
+
// `kind` (people/orders), so each declaration carries a kindFilter. A lead
|
|
4651
|
+
// create auto-spawns a deal, so the lead guard also gates deal creation;
|
|
4652
|
+
// `deals` has no standalone create UI (declared for usage banners/counts).
|
|
4653
|
+
declaredLimits: [
|
|
4654
|
+
{ key: "leads", label: "Leads", table: "people", kindFilter: "lead" },
|
|
4655
|
+
{ key: "deals", label: "Deals", table: "orders", kindFilter: "deal" },
|
|
4656
|
+
{ key: "quotes", label: "Quotes", table: "orders", kindFilter: "quote" }
|
|
4657
|
+
],
|
|
4523
4658
|
navigation: [
|
|
4524
4659
|
{
|
|
4525
4660
|
section: options?.navSection ?? "main",
|