@fayz-ai/plugin-crm 0.3.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/README.md +2 -0
- package/dist/components/CrmGeneralSettings.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/tables.d.ts +10 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/index.cjs +209 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +210 -61
- 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 +12 -0
- package/dist/migrations/index.d.ts.map +1 -0
- 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/registries.d.ts.map +1 -1
- package/dist/schema/index.d.ts +65 -65
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema.cjs +23 -23
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.js +24 -24
- package/dist/schema.js.map +1 -1
- 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 +17 -5
- package/src/components/CrmGeneralSettings.tsx +35 -15
- package/src/data/supabase.ts +74 -28
- package/src/data/tables.ts +11 -0
- package/src/index.ts +15 -3
- 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/000_plg_rename.sql +28 -0
- package/src/migrations/001_crm_base.sql +32 -32
- package/src/migrations/002_activities.sql +14 -14
- package/src/migrations/003_crm_views_rls.sql +8 -8
- package/src/migrations/004_seed_default_pipeline.sql +5 -5
- package/src/migrations/005_public_lead.sql +189 -0
- package/src/migrations/006_lead_enters_pipeline.sql +265 -0
- package/src/migrations/index.ts +707 -0
- 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/registries.ts +6 -5
- package/src/schema/index.ts +25 -25
- 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/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@fayz-ai/plugin-crm)
|
|
6
6
|
[](https://github.com/FayaLabs/fayz-sdk/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
+
**Status:** beta — pre-1.0. Core surface is stable; some backend facets (see `PLUGIN_PATTERNS.md`) are still landing. APIs may change before 1.0.
|
|
9
|
+
|
|
8
10
|
Every business that sells anything needs a way to track who's interested, what's in motion, and what's about to close. Most verticals end up rebuilding the same CRM badly. `plugin-crm` is the one sales engine — leads, a drag-style pipeline, deals, quotes, and activities — that snaps into a `defineSaas` app and adapts to the vertical underneath it.
|
|
9
11
|
|
|
10
12
|
A salon tracks "customers", a clinic tracks "patients", an agency tracks "clients" — same engine, different labels and stages. The plugin ships a full UI today, a vertical-aware label/stage/source config, AI tools your assistant can call, and a data-provider seam that runs on a mock or a Supabase backend. When a lead is approved it can convert a person into a real client record in your domain schema. This is what "compose a real SaaS from plugins" means in practice.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrmGeneralSettings.d.ts","sourceRoot":"","sources":["../../src/components/CrmGeneralSettings.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"CrmGeneralSettings.d.ts","sourceRoot":"","sources":["../../src/components/CrmGeneralSettings.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAuBzB,wBAAgB,kBAAkB,sBAgCjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAwD9C,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,gBAAgB,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CACvF,GAAG,eAAe,CA6mBlB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const T: {
|
|
2
|
+
readonly activities: "plg_crm_activities";
|
|
3
|
+
readonly tags: "plg_crm_tags";
|
|
4
|
+
readonly activityTypes: "plg_crm_activity_types";
|
|
5
|
+
readonly pipelines: "plg_crm_pipelines";
|
|
6
|
+
readonly pipelineStages: "plg_crm_pipeline_stages";
|
|
7
|
+
readonly dealExtensions: "plg_crm_deal_extensions";
|
|
8
|
+
readonly leadSources: "plg_crm_lead_sources";
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC;;;;;;;;CAQJ,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -19,44 +19,47 @@ var CrmContextProvider = ctx.ContextProvider;
|
|
|
19
19
|
var useCrmConfig = ctx.useConfig;
|
|
20
20
|
var useCrmProvider = ctx.useProvider;
|
|
21
21
|
var useCrmStore = ctx.useStore;
|
|
22
|
+
var CRM_DEFAULTS = {
|
|
23
|
+
autoAssign: false,
|
|
24
|
+
requireSource: true,
|
|
25
|
+
leadScoring: false,
|
|
26
|
+
duplicateDetection: true,
|
|
27
|
+
autoCreateDeal: true,
|
|
28
|
+
requireCloseDate: false,
|
|
29
|
+
rottingDeals: true,
|
|
30
|
+
weightedPipeline: true,
|
|
31
|
+
autoNumberQuotes: true,
|
|
32
|
+
defaultValidity: true,
|
|
33
|
+
requireApproval: false,
|
|
34
|
+
overdueAlerts: true,
|
|
35
|
+
stageChangeAlerts: false,
|
|
36
|
+
newLeadNotif: true
|
|
37
|
+
};
|
|
22
38
|
function CrmGeneralSettings() {
|
|
23
39
|
const t2 = core.useTranslation();
|
|
40
|
+
const s = saas.useTenantPluginSettings("crm", CRM_DEFAULTS);
|
|
24
41
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
25
42
|
/* @__PURE__ */ jsxRuntime.jsxs(saas.SettingsGroup, { title: t2("crm.settings.leadManagement"), description: t2("crm.settings.leadManagementDesc"), children: [
|
|
26
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoAssign"), description: t2("crm.settings.autoAssignDesc"), checked:
|
|
27
|
-
|
|
28
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.
|
|
29
|
-
|
|
30
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.leadScoring"), description: t2("crm.settings.leadScoringDesc"), checked: false, onChange: () => {
|
|
31
|
-
} }),
|
|
32
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.duplicateDetection"), description: t2("crm.settings.duplicateDetectionDesc"), checked: true, onChange: () => {
|
|
33
|
-
} })
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoAssign"), description: t2("crm.settings.autoAssignDesc"), checked: s.get("autoAssign"), onChange: (v) => s.set("autoAssign", v) }),
|
|
44
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.requireSource"), description: t2("crm.settings.requireSourceDesc"), checked: s.get("requireSource"), onChange: (v) => s.set("requireSource", v) }),
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.leadScoring"), description: t2("crm.settings.leadScoringDesc"), checked: s.get("leadScoring"), onChange: (v) => s.set("leadScoring", v) }),
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.duplicateDetection"), description: t2("crm.settings.duplicateDetectionDesc"), checked: s.get("duplicateDetection"), onChange: (v) => s.set("duplicateDetection", v) })
|
|
34
47
|
] }),
|
|
35
48
|
/* @__PURE__ */ jsxRuntime.jsxs(saas.SettingsGroup, { title: t2("crm.settings.deals"), description: t2("crm.settings.dealsDesc"), children: [
|
|
36
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoCreateDeal"), description: t2("crm.settings.autoCreateDealDesc"), checked:
|
|
37
|
-
|
|
38
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.
|
|
39
|
-
|
|
40
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.rottingDeals"), description: t2("crm.settings.rottingDealsDesc"), checked: true, onChange: () => {
|
|
41
|
-
} }),
|
|
42
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.weightedPipeline"), description: t2("crm.settings.weightedPipelineDesc"), checked: true, onChange: () => {
|
|
43
|
-
} })
|
|
49
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoCreateDeal"), description: t2("crm.settings.autoCreateDealDesc"), checked: s.get("autoCreateDeal"), onChange: (v) => s.set("autoCreateDeal", v) }),
|
|
50
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.requireCloseDate"), description: t2("crm.settings.requireCloseDateDesc"), checked: s.get("requireCloseDate"), onChange: (v) => s.set("requireCloseDate", v) }),
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.rottingDeals"), description: t2("crm.settings.rottingDealsDesc"), checked: s.get("rottingDeals"), onChange: (v) => s.set("rottingDeals", v) }),
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.weightedPipeline"), description: t2("crm.settings.weightedPipelineDesc"), checked: s.get("weightedPipeline"), onChange: (v) => s.set("weightedPipeline", v) })
|
|
44
53
|
] }),
|
|
45
54
|
/* @__PURE__ */ jsxRuntime.jsxs(saas.SettingsGroup, { title: t2("crm.settings.quotes"), description: t2("crm.settings.quotesDesc"), children: [
|
|
46
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoNumberQuotes"), description: t2("crm.settings.autoNumberQuotesDesc"), checked:
|
|
47
|
-
|
|
48
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.
|
|
49
|
-
} }),
|
|
50
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.requireApproval"), description: t2("crm.settings.requireApprovalDesc"), checked: false, onChange: () => {
|
|
51
|
-
} })
|
|
55
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.autoNumberQuotes"), description: t2("crm.settings.autoNumberQuotesDesc"), checked: s.get("autoNumberQuotes"), onChange: (v) => s.set("autoNumberQuotes", v) }),
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.defaultValidity"), description: t2("crm.settings.defaultValidityDesc"), checked: s.get("defaultValidity"), onChange: (v) => s.set("defaultValidity", v) }),
|
|
57
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.requireApproval"), description: t2("crm.settings.requireApprovalDesc"), checked: s.get("requireApproval"), onChange: (v) => s.set("requireApproval", v) })
|
|
52
58
|
] }),
|
|
53
59
|
/* @__PURE__ */ jsxRuntime.jsxs(saas.SettingsGroup, { title: t2("crm.settings.notifications"), description: t2("crm.settings.notificationsDesc"), children: [
|
|
54
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.overdueAlerts"), description: t2("crm.settings.overdueAlertsDesc"), checked:
|
|
55
|
-
|
|
56
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.
|
|
57
|
-
} }),
|
|
58
|
-
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.newLeadNotif"), description: t2("crm.settings.newLeadNotifDesc"), checked: true, onChange: () => {
|
|
59
|
-
} })
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.overdueAlerts"), description: t2("crm.settings.overdueAlertsDesc"), checked: s.get("overdueAlerts"), onChange: (v) => s.set("overdueAlerts", v) }),
|
|
61
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.stageChangeAlerts"), description: t2("crm.settings.stageChangeAlertsDesc"), checked: s.get("stageChangeAlerts"), onChange: (v) => s.set("stageChangeAlerts", v) }),
|
|
62
|
+
/* @__PURE__ */ jsxRuntime.jsx(saas.ToggleRow, { label: t2("crm.settings.newLeadNotif"), description: t2("crm.settings.newLeadNotifDesc"), checked: s.get("newLeadNotif"), onChange: (v) => s.set("newLeadNotif", v) })
|
|
60
63
|
] })
|
|
61
64
|
] });
|
|
62
65
|
}
|
|
@@ -266,6 +269,23 @@ function QuoteStatusDropdown({ quote, onStatusChange, size = "default" }) {
|
|
|
266
269
|
showReject && /* @__PURE__ */ jsxRuntime.jsx(RejectModal, { onConfirm: handleReject, onCancel: () => setShowReject(false) })
|
|
267
270
|
] });
|
|
268
271
|
}
|
|
272
|
+
|
|
273
|
+
// src/lib/form-answers.tsx
|
|
274
|
+
function humanizeKey(key) {
|
|
275
|
+
const spaced = key.replace(/[_-]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2");
|
|
276
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
277
|
+
}
|
|
278
|
+
function renderFieldValue(value) {
|
|
279
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
280
|
+
if (Array.isArray(value)) return value.length ? value.join(", ") : null;
|
|
281
|
+
if (typeof value === "boolean") return value ? "Sim" : "N\xE3o";
|
|
282
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
283
|
+
return String(value);
|
|
284
|
+
}
|
|
285
|
+
function answerEntries(fields) {
|
|
286
|
+
if (!fields || typeof fields !== "object" || Array.isArray(fields)) return [];
|
|
287
|
+
return Object.entries(fields).filter(([, v]) => v !== null && v !== void 0 && v !== "");
|
|
288
|
+
}
|
|
269
289
|
var TYPE_ICONS = {
|
|
270
290
|
call: lucideReact.Phone,
|
|
271
291
|
email: lucideReact.Mail,
|
|
@@ -294,6 +314,19 @@ function TabBar({ active, counts, onChange }) {
|
|
|
294
314
|
tab.id
|
|
295
315
|
)) });
|
|
296
316
|
}
|
|
317
|
+
function FormAnswers({ lead }) {
|
|
318
|
+
const t2 = core.useTranslation();
|
|
319
|
+
const entries = answerEntries(lead?.metadata?.fields);
|
|
320
|
+
if (entries.length === 0) return null;
|
|
321
|
+
const formId = lead?.metadata?.formId;
|
|
322
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
323
|
+
/* @__PURE__ */ jsxRuntime.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") }),
|
|
324
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border divide-y", children: entries.map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3 px-4 py-2.5", children: [
|
|
325
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] text-muted-foreground shrink-0 min-w-24", children: humanizeKey(key) }),
|
|
326
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-right flex-1 break-words", children: renderFieldValue(value) ?? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground/50", children: "\u2014" }) })
|
|
327
|
+
] }, key)) })
|
|
328
|
+
] });
|
|
329
|
+
}
|
|
297
330
|
function OverviewTab({ deal, lead, currency }) {
|
|
298
331
|
const t2 = core.useTranslation();
|
|
299
332
|
const initial = (lead?.name ?? deal.contactName ?? deal.title).charAt(0).toUpperCase();
|
|
@@ -359,6 +392,7 @@ function OverviewTab({ deal, lead, currency }) {
|
|
|
359
392
|
] })
|
|
360
393
|
] })
|
|
361
394
|
] }),
|
|
395
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormAnswers, { lead }),
|
|
362
396
|
deal.tags && deal.tags.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
363
397
|
/* @__PURE__ */ jsxRuntime.jsx("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: t2("crm.dealSidebar.tags") }),
|
|
364
398
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1.5 flex-wrap", children: deal.tags.map((tag) => /* @__PURE__ */ jsxRuntime.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)) })
|
|
@@ -668,6 +702,22 @@ function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead }) {
|
|
|
668
702
|
React14.useEffect(() => {
|
|
669
703
|
if (pipelines.length > 0) fetchDealsByStage(pipelines[0].id);
|
|
670
704
|
}, [pipelines]);
|
|
705
|
+
const pipelineId = pipelines[0]?.id;
|
|
706
|
+
React14.useEffect(() => {
|
|
707
|
+
if (!pipelineId) return;
|
|
708
|
+
const supabase = core.getSupabaseClientOptional();
|
|
709
|
+
if (!supabase) return;
|
|
710
|
+
const channel = supabase.channel(`crm:board:${pipelineId}`).on(
|
|
711
|
+
"postgres_changes",
|
|
712
|
+
{ event: "*", schema: "public", table: "plg_crm_deal_extensions" },
|
|
713
|
+
() => {
|
|
714
|
+
void fetchDealsByStage(pipelineId);
|
|
715
|
+
}
|
|
716
|
+
).subscribe();
|
|
717
|
+
return () => {
|
|
718
|
+
supabase.removeChannel(channel);
|
|
719
|
+
};
|
|
720
|
+
}, [pipelineId]);
|
|
671
721
|
React14.useEffect(() => {
|
|
672
722
|
if (savingDealIds.size === 0) setOptimisticBoard(null);
|
|
673
723
|
}, [dealsByStage, savingDealIds]);
|
|
@@ -792,6 +842,24 @@ var columns = [
|
|
|
792
842
|
const opt = STATUS_OPTIONS.find((o) => o.value === status);
|
|
793
843
|
return /* @__PURE__ */ jsxRuntime.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 });
|
|
794
844
|
}
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
// When the lead came in. The list is already sorted by it (provider orders
|
|
848
|
+
// created_at desc) but never showed it, so "is this enquiry from today or
|
|
849
|
+
// from March?" was unanswerable without opening the record.
|
|
850
|
+
accessorKey: "createdAt",
|
|
851
|
+
header: "Entrada",
|
|
852
|
+
cell: ({ getValue }) => {
|
|
853
|
+
const raw = getValue();
|
|
854
|
+
if (!raw) return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-xs", children: "\u2014" });
|
|
855
|
+
const at = new Date(raw);
|
|
856
|
+
if (Number.isNaN(at.getTime())) return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-xs", children: "\u2014" });
|
|
857
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground text-xs whitespace-nowrap", title: at.toLocaleString(), children: [
|
|
858
|
+
at.toLocaleDateString(void 0, { day: "2-digit", month: "2-digit", year: "2-digit" }),
|
|
859
|
+
" \xB7 ",
|
|
860
|
+
at.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" })
|
|
861
|
+
] });
|
|
862
|
+
}
|
|
795
863
|
}
|
|
796
864
|
];
|
|
797
865
|
function LeadListView({ onNew, onEdit }) {
|
|
@@ -834,6 +902,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
834
902
|
function LeadFormView({ onSaved }) {
|
|
835
903
|
const t2 = core.useTranslation();
|
|
836
904
|
const createLead = useCrmStore((s) => s.createLead);
|
|
905
|
+
const guardLeads = saas.useLimitGuard("leads");
|
|
837
906
|
const fetchPipelines = useCrmStore((s) => s.fetchPipelines);
|
|
838
907
|
const pipelines = useCrmStore((s) => s.pipelines);
|
|
839
908
|
React14.useEffect(() => {
|
|
@@ -850,9 +919,12 @@ function LeadFormView({ onSaved }) {
|
|
|
850
919
|
ui.toast.error(t2("common.formIncomplete"));
|
|
851
920
|
return;
|
|
852
921
|
}
|
|
922
|
+
if (await guardLeads() === "blocked") return;
|
|
853
923
|
setSaving(true);
|
|
854
924
|
try {
|
|
855
925
|
const lead = await createLead({ name, email: email || void 0, phone: phone || void 0, company: company || void 0, notes: notes || void 0 });
|
|
926
|
+
saas.invalidateLimit("leads");
|
|
927
|
+
saas.invalidateLimit("deals");
|
|
856
928
|
onSaved?.(lead.id);
|
|
857
929
|
} finally {
|
|
858
930
|
setSaving(false);
|
|
@@ -1102,6 +1174,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1102
1174
|
const { currency, itemTypes } = config;
|
|
1103
1175
|
const createQuote = useCrmStore((s) => s.createQuote);
|
|
1104
1176
|
const updateQuote = useCrmStore((s) => s.updateQuote);
|
|
1177
|
+
const guardQuotes = saas.useLimitGuard("quotes");
|
|
1105
1178
|
const isEdit = !!quoteId;
|
|
1106
1179
|
const [loadingExisting, setLoadingExisting] = React14.useState(isEdit || !!leadId);
|
|
1107
1180
|
const [linkedLeadId, setLinkedLeadId] = React14.useState(leadId ?? "");
|
|
@@ -1180,6 +1253,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1180
1253
|
ui.toast.error(t2("crm.quoteForm.errNoItems"));
|
|
1181
1254
|
return;
|
|
1182
1255
|
}
|
|
1256
|
+
if (!isEdit && await guardQuotes() === "blocked") return;
|
|
1183
1257
|
setSaving(true);
|
|
1184
1258
|
try {
|
|
1185
1259
|
const input = {
|
|
@@ -1205,6 +1279,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1205
1279
|
onSaved?.(quoteId);
|
|
1206
1280
|
} else {
|
|
1207
1281
|
const created = await createQuote(input);
|
|
1282
|
+
saas.invalidateLimit("quotes");
|
|
1208
1283
|
onSaved?.(created?.id);
|
|
1209
1284
|
}
|
|
1210
1285
|
} finally {
|
|
@@ -1723,6 +1798,17 @@ var STATUS_COLORS2 = {
|
|
|
1723
1798
|
converted: "bg-warning-soft text-warning-soft-foreground",
|
|
1724
1799
|
lost: "bg-destructive-soft text-destructive-soft-foreground"
|
|
1725
1800
|
};
|
|
1801
|
+
function humanizeKey2(key) {
|
|
1802
|
+
const spaced = key.replace(/[_-]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2");
|
|
1803
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
1804
|
+
}
|
|
1805
|
+
function renderFieldValue2(value) {
|
|
1806
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
1807
|
+
if (Array.isArray(value)) return value.length ? value.join(", ") : null;
|
|
1808
|
+
if (typeof value === "boolean") return value ? "Sim" : "N\xE3o";
|
|
1809
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
1810
|
+
return String(value);
|
|
1811
|
+
}
|
|
1726
1812
|
function FieldRow({ label, value }) {
|
|
1727
1813
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-3 gap-4 py-3", children: [
|
|
1728
1814
|
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: label }),
|
|
@@ -1819,6 +1905,24 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
|
|
|
1819
1905
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: t2("crm.leadDetail.source"), value: lead.sourceName }) })
|
|
1820
1906
|
] }) })
|
|
1821
1907
|
] }),
|
|
1908
|
+
(() => {
|
|
1909
|
+
const meta = lead.metadata ?? {};
|
|
1910
|
+
const fields = Object.entries(meta.fields ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
|
|
1911
|
+
const utm = Object.entries(meta.utm ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
|
|
1912
|
+
if (!fields.length && !utm.length) return null;
|
|
1913
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1914
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.formAnswers") }),
|
|
1915
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border bg-card shadow-sm", children: [
|
|
1916
|
+
/* @__PURE__ */ jsxRuntime.jsx("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: fields.map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: humanizeKey2(key), value: renderFieldValue2(value) }) }, key)) }),
|
|
1917
|
+
utm.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t px-5 py-3 flex flex-wrap gap-x-4 gap-y-1", children: utm.map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
1918
|
+
humanizeKey2(key.replace(/^utm_/, "")),
|
|
1919
|
+
":",
|
|
1920
|
+
" ",
|
|
1921
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-foreground", children: renderFieldValue2(value) })
|
|
1922
|
+
] }, key)) })
|
|
1923
|
+
] })
|
|
1924
|
+
] });
|
|
1925
|
+
})(),
|
|
1822
1926
|
deal && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1823
1927
|
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.pipeline") }),
|
|
1824
1928
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border bg-card shadow-sm", children: /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: [
|
|
@@ -2781,6 +2885,17 @@ function createMockCrmProvider(options) {
|
|
|
2781
2885
|
return provider;
|
|
2782
2886
|
}
|
|
2783
2887
|
|
|
2888
|
+
// src/data/tables.ts
|
|
2889
|
+
var T = {
|
|
2890
|
+
activities: "plg_crm_activities",
|
|
2891
|
+
tags: "plg_crm_tags",
|
|
2892
|
+
activityTypes: "plg_crm_activity_types",
|
|
2893
|
+
pipelines: "plg_crm_pipelines",
|
|
2894
|
+
pipelineStages: "plg_crm_pipeline_stages",
|
|
2895
|
+
dealExtensions: "plg_crm_deal_extensions",
|
|
2896
|
+
leadSources: "plg_crm_lead_sources"
|
|
2897
|
+
};
|
|
2898
|
+
|
|
2784
2899
|
// src/data/supabase.ts
|
|
2785
2900
|
function getTenantId() {
|
|
2786
2901
|
return core.getActiveTenantId();
|
|
@@ -2795,19 +2910,25 @@ function snakeToCamel(obj) {
|
|
|
2795
2910
|
function getClients() {
|
|
2796
2911
|
const supabase = core.getSupabaseClientOptional();
|
|
2797
2912
|
if (!supabase) throw new Error("Supabase not initialized");
|
|
2798
|
-
return { core: supabase
|
|
2913
|
+
return { core: supabase, pub: supabase };
|
|
2914
|
+
}
|
|
2915
|
+
async function mergePersonMetadata(personId, patch) {
|
|
2916
|
+
const { core } = getClients();
|
|
2917
|
+
const { data: row } = await core.from("people").select("metadata").eq("id", personId).maybeSingle();
|
|
2918
|
+
const current = row?.metadata ?? {};
|
|
2919
|
+
await core.from("people").update({ metadata: { ...current, ...patch } }).eq("id", personId);
|
|
2799
2920
|
}
|
|
2800
2921
|
function createSupabaseCrmProvider(options) {
|
|
2801
2922
|
const provider = {
|
|
2802
|
-
// --- Pipelines (public.
|
|
2923
|
+
// --- Pipelines (public.plg_crm_pipelines + plg_crm_pipeline_stages) ---
|
|
2803
2924
|
async getPipelines() {
|
|
2804
2925
|
const { pub } = getClients();
|
|
2805
|
-
const { data } = await pub.from(
|
|
2926
|
+
const { data } = await pub.from(T.pipelines).select("*").eq("is_active", true).order("name");
|
|
2806
2927
|
return (data ?? []).map((r) => snakeToCamel(r));
|
|
2807
2928
|
},
|
|
2808
2929
|
async getPipelineStages(pipelineId) {
|
|
2809
2930
|
const { pub } = getClients();
|
|
2810
|
-
const { data } = await pub.from(
|
|
2931
|
+
const { data } = await pub.from(T.pipelineStages).select("*").eq("pipeline_id", pipelineId).order("order");
|
|
2811
2932
|
return (data ?? []).map((r) => snakeToCamel(r));
|
|
2812
2933
|
},
|
|
2813
2934
|
// --- Leads (via view — single query) ---
|
|
@@ -2855,8 +2976,16 @@ function createSupabaseCrmProvider(options) {
|
|
|
2855
2976
|
phone: r.phone,
|
|
2856
2977
|
company: r.company,
|
|
2857
2978
|
status: r.lead_status ?? "new",
|
|
2979
|
+
sourceName: r.source_name,
|
|
2858
2980
|
tags: r.tags ?? [],
|
|
2859
2981
|
notes: r.notes,
|
|
2982
|
+
// Answers from a public form. Kept as an opaque bag so a new landing
|
|
2983
|
+
// page needs no schema change; the detail view renders whatever is here.
|
|
2984
|
+
metadata: {
|
|
2985
|
+
formId: r.form_id ?? void 0,
|
|
2986
|
+
fields: r.custom_fields ?? {},
|
|
2987
|
+
utm: r.utm ?? {}
|
|
2988
|
+
},
|
|
2860
2989
|
tenantId: r.tenant_id,
|
|
2861
2990
|
createdAt: r.created_at,
|
|
2862
2991
|
updatedAt: r.updated_at
|
|
@@ -2865,7 +2994,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
2865
2994
|
async createLead(input) {
|
|
2866
2995
|
const { core } = getClients();
|
|
2867
2996
|
const tenantId = getTenantId();
|
|
2868
|
-
const { data, error } = await core.from("
|
|
2997
|
+
const { data, error } = await core.from("people").insert({
|
|
2869
2998
|
tenant_id: tenantId,
|
|
2870
2999
|
kind: "lead",
|
|
2871
3000
|
name: input.name,
|
|
@@ -2887,14 +3016,14 @@ function createSupabaseCrmProvider(options) {
|
|
|
2887
3016
|
if (partial.email !== void 0) row.email = partial.email;
|
|
2888
3017
|
if (partial.phone !== void 0) row.phone = partial.phone;
|
|
2889
3018
|
if (partial.notes !== void 0) row.notes = partial.notes;
|
|
2890
|
-
|
|
2891
|
-
const { data, error } = await core.from("persons").update(row).eq("id", id).select().single();
|
|
3019
|
+
const { error } = await core.from("people").update(row).eq("id", id).select().single();
|
|
2892
3020
|
if (error) throw new Error(error.message);
|
|
3021
|
+
if (partial.status) await mergePersonMetadata(id, { status: partial.status });
|
|
2893
3022
|
return await provider.getLeadById(id);
|
|
2894
3023
|
},
|
|
2895
3024
|
async convertLeadToDeal(leadId, dealInput) {
|
|
2896
|
-
|
|
2897
|
-
await
|
|
3025
|
+
getClients();
|
|
3026
|
+
await mergePersonMetadata(leadId, { status: "converted" });
|
|
2898
3027
|
return provider.createDeal({ ...dealInput, leadId });
|
|
2899
3028
|
},
|
|
2900
3029
|
// --- Deals (via view — single query with all joins) ---
|
|
@@ -2952,6 +3081,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
2952
3081
|
status: r.status ?? "open",
|
|
2953
3082
|
contactName: r.contact_name,
|
|
2954
3083
|
tags: r.tags ?? [],
|
|
3084
|
+
// v_deals exposes de.lead_id and Deal declares leadId, but the mapping
|
|
3085
|
+
// dropped it — so DealSidebar's `if (d?.leadId)` never fired and the
|
|
3086
|
+
// card opened blank: no contact, no form answers. For a card that came
|
|
3087
|
+
// from a form, the lead IS the content.
|
|
3088
|
+
leadId: r.lead_id ?? void 0,
|
|
2955
3089
|
tenantId: r.tenant_id,
|
|
2956
3090
|
createdAt: r.created_at,
|
|
2957
3091
|
updatedAt: r.updated_at
|
|
@@ -2973,6 +3107,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
2973
3107
|
status: r.status ?? "open",
|
|
2974
3108
|
contactName: r.contact_name,
|
|
2975
3109
|
tags: r.tags ?? [],
|
|
3110
|
+
leadId: r.lead_id ?? void 0,
|
|
2976
3111
|
tenantId: r.tenant_id,
|
|
2977
3112
|
createdAt: r.created_at,
|
|
2978
3113
|
updatedAt: r.updated_at
|
|
@@ -3001,7 +3136,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3001
3136
|
metadata: { contactName: input.contactName }
|
|
3002
3137
|
}).select().single();
|
|
3003
3138
|
if (error) throw new Error(error.message);
|
|
3004
|
-
await pub.from(
|
|
3139
|
+
await pub.from(T.dealExtensions).insert({
|
|
3005
3140
|
order_id: order.id,
|
|
3006
3141
|
tenant_id: tenantId,
|
|
3007
3142
|
pipeline_id: input.pipelineId,
|
|
@@ -3039,14 +3174,14 @@ function createSupabaseCrmProvider(options) {
|
|
|
3039
3174
|
if (partial.stageId) row.stage_id = partial.stageId;
|
|
3040
3175
|
if (partial.probability != null) row.probability = partial.probability;
|
|
3041
3176
|
if (partial.expectedCloseDate) row.expected_close_date = partial.expectedCloseDate;
|
|
3042
|
-
await pub.from(
|
|
3177
|
+
await pub.from(T.dealExtensions).update(row).eq("order_id", id);
|
|
3043
3178
|
}
|
|
3044
3179
|
return await provider.getDealById(id);
|
|
3045
3180
|
},
|
|
3046
3181
|
async moveDealToStage(dealId, stageId) {
|
|
3047
3182
|
const { core, pub } = getClients();
|
|
3048
|
-
const { data: stageRow } = await pub.from(
|
|
3049
|
-
await pub.from(
|
|
3183
|
+
const { data: stageRow } = await pub.from(T.pipelineStages).select("*").eq("id", stageId).single();
|
|
3184
|
+
await pub.from(T.dealExtensions).update({
|
|
3050
3185
|
stage_id: stageId,
|
|
3051
3186
|
probability: stageRow?.probability ?? 0
|
|
3052
3187
|
}).eq("order_id", dealId);
|
|
@@ -3065,10 +3200,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
3065
3200
|
tenantId: stageRow.tenant_id,
|
|
3066
3201
|
createdAt: stageRow.created_at
|
|
3067
3202
|
};
|
|
3068
|
-
const { data: ext } = await pub.from(
|
|
3203
|
+
const { data: ext } = await pub.from(T.dealExtensions).select("lead_id").eq("order_id", dealId).single();
|
|
3069
3204
|
if (ext?.lead_id) {
|
|
3070
3205
|
const newLeadStatus = deriveLeadStatus(typedStage);
|
|
3071
|
-
await
|
|
3206
|
+
await mergePersonMetadata(ext.lead_id, { status: newLeadStatus });
|
|
3072
3207
|
}
|
|
3073
3208
|
const { data: quotes } = await core.from("orders").select("id, status").eq("kind", "quote");
|
|
3074
3209
|
for (const q of quotes ?? []) {
|
|
@@ -3083,10 +3218,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
3083
3218
|
}
|
|
3084
3219
|
return await provider.getDealById(dealId);
|
|
3085
3220
|
},
|
|
3086
|
-
// --- Activities (public.
|
|
3221
|
+
// --- Activities (public.plg_crm_activities) ---
|
|
3087
3222
|
async getActivities(query) {
|
|
3088
3223
|
const { pub } = getClients();
|
|
3089
|
-
let qb = pub.from(
|
|
3224
|
+
let qb = pub.from(T.activities).select("*", { count: "exact" });
|
|
3090
3225
|
if (query.dealId) qb = qb.eq("deal_id", query.dealId);
|
|
3091
3226
|
if (query.leadId) qb = qb.eq("lead_id", query.leadId);
|
|
3092
3227
|
if (query.activityType) qb = qb.eq("activity_type", query.activityType);
|
|
@@ -3101,7 +3236,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3101
3236
|
async createActivity(input) {
|
|
3102
3237
|
const { pub } = getClients();
|
|
3103
3238
|
const tenantId = getTenantId();
|
|
3104
|
-
const { data, error } = await pub.from(
|
|
3239
|
+
const { data, error } = await pub.from(T.activities).insert({
|
|
3105
3240
|
tenant_id: tenantId,
|
|
3106
3241
|
deal_id: input.dealId,
|
|
3107
3242
|
lead_id: input.leadId,
|
|
@@ -3117,11 +3252,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
3117
3252
|
},
|
|
3118
3253
|
async completeActivity(id) {
|
|
3119
3254
|
const { pub } = getClients();
|
|
3120
|
-
const { data, error } = await pub.from(
|
|
3255
|
+
const { data, error } = await pub.from(T.activities).update({ completed_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id).select().single();
|
|
3121
3256
|
if (error) throw new Error(error.message);
|
|
3122
3257
|
return snakeToCamel(data);
|
|
3123
3258
|
},
|
|
3124
|
-
// --- Quotes (
|
|
3259
|
+
// --- Quotes (public.orders kind='quote' + order_items) ---
|
|
3125
3260
|
async getQuotes(query) {
|
|
3126
3261
|
const { core } = getClients();
|
|
3127
3262
|
let qb = core.from("orders").select("*", { count: "exact" }).eq("kind", "quote");
|
|
@@ -3320,11 +3455,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
3320
3455
|
const personToConvert = quote.leadId ?? quote.contactId;
|
|
3321
3456
|
if (personToConvert) {
|
|
3322
3457
|
const clientKind = options?.clientConversion?.archetypeKind ?? "client";
|
|
3323
|
-
const { data: person } = await core.from("
|
|
3458
|
+
const { data: person } = await core.from("people").select("kind, name, email, phone, tenant_id, metadata").eq("id", personToConvert).single();
|
|
3324
3459
|
const personKind = person?.kind;
|
|
3325
3460
|
if (person && (personKind === "lead" || personKind === "contact")) {
|
|
3326
3461
|
const personMeta = person?.metadata ?? {};
|
|
3327
|
-
await core.from("
|
|
3462
|
+
await core.from("people").update({
|
|
3328
3463
|
kind: clientKind,
|
|
3329
3464
|
metadata: { ...personMeta, convertedFromLead: true }
|
|
3330
3465
|
}).eq("id", personToConvert);
|
|
@@ -3388,7 +3523,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3388
3523
|
},
|
|
3389
3524
|
async getDealByLeadId(leadId) {
|
|
3390
3525
|
const { pub } = getClients();
|
|
3391
|
-
const { data } = await pub.from(
|
|
3526
|
+
const { data } = await pub.from(T.dealExtensions).select("order_id").eq("lead_id", leadId).limit(1);
|
|
3392
3527
|
if (!data || data.length === 0) return null;
|
|
3393
3528
|
return provider.getDealById(data[0].order_id);
|
|
3394
3529
|
},
|
|
@@ -3397,16 +3532,16 @@ function createSupabaseCrmProvider(options) {
|
|
|
3397
3532
|
const { core, pub } = getClients();
|
|
3398
3533
|
const monthStart = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7) + "-01";
|
|
3399
3534
|
const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
3400
|
-
const { count: totalLeads } = await core.from("
|
|
3401
|
-
const { count: newLeads } = await core.from("
|
|
3535
|
+
const { count: totalLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead");
|
|
3536
|
+
const { count: newLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead").gte("created_at", monthStart);
|
|
3402
3537
|
const { data: deals } = await core.from("orders").select("status, total, updated_at").eq("kind", "deal");
|
|
3403
3538
|
const allDeals = deals ?? [];
|
|
3404
3539
|
const openDeals = allDeals.filter((d) => d.status === "open");
|
|
3405
3540
|
const wonDeals = allDeals.filter((d) => d.status === "won");
|
|
3406
3541
|
const wonThisMonth = wonDeals.filter((d) => d.updated_at >= monthStart);
|
|
3407
3542
|
const convertedLeads = allDeals.length;
|
|
3408
|
-
const { count: pendingActs } = await pub.from(
|
|
3409
|
-
const { count: overdueActs } = await pub.from(
|
|
3543
|
+
const { count: pendingActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null);
|
|
3544
|
+
const { count: overdueActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null).lt("due_date", today2);
|
|
3410
3545
|
return {
|
|
3411
3546
|
totalLeads: totalLeads ?? 0,
|
|
3412
3547
|
newLeadsThisMonth: newLeads ?? 0,
|
|
@@ -3748,7 +3883,7 @@ var leadSourceEntity = {
|
|
|
3748
3883
|
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
3749
3884
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3750
3885
|
],
|
|
3751
|
-
data: { table:
|
|
3886
|
+
data: { table: T.leadSources, tenantScoped: true }
|
|
3752
3887
|
};
|
|
3753
3888
|
var tagEntity = {
|
|
3754
3889
|
name: "Tag",
|
|
@@ -3761,7 +3896,7 @@ var tagEntity = {
|
|
|
3761
3896
|
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
|
|
3762
3897
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3763
3898
|
],
|
|
3764
|
-
data: { table:
|
|
3899
|
+
data: { table: T.tags, tenantScoped: true }
|
|
3765
3900
|
};
|
|
3766
3901
|
var pipelineStageEntity = {
|
|
3767
3902
|
name: "Stage",
|
|
@@ -3775,7 +3910,7 @@ var pipelineStageEntity = {
|
|
|
3775
3910
|
key: "pipelineId",
|
|
3776
3911
|
label: "Pipeline",
|
|
3777
3912
|
type: "relation",
|
|
3778
|
-
relation: { table:
|
|
3913
|
+
relation: { table: T.pipelines, labelField: "name" },
|
|
3779
3914
|
required: true,
|
|
3780
3915
|
showInTable: true
|
|
3781
3916
|
},
|
|
@@ -3785,7 +3920,7 @@ var pipelineStageEntity = {
|
|
|
3785
3920
|
{ key: "isWon", label: "Won Stage", type: "boolean", showInTable: true, defaultValue: false },
|
|
3786
3921
|
{ key: "isLost", label: "Lost Stage", type: "boolean", showInTable: true, defaultValue: false }
|
|
3787
3922
|
],
|
|
3788
|
-
data: { table:
|
|
3923
|
+
data: { table: T.pipelineStages, tenantScoped: true }
|
|
3789
3924
|
};
|
|
3790
3925
|
var activityTypeEntity = {
|
|
3791
3926
|
name: "Activity Type",
|
|
@@ -3797,7 +3932,7 @@ var activityTypeEntity = {
|
|
|
3797
3932
|
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
3798
3933
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3799
3934
|
],
|
|
3800
|
-
data: { table:
|
|
3935
|
+
data: { table: T.activityTypes, tenantScoped: true }
|
|
3801
3936
|
};
|
|
3802
3937
|
var crmRegistries = [
|
|
3803
3938
|
{
|
|
@@ -3919,6 +4054,7 @@ var en = {
|
|
|
3919
4054
|
"crm.dealSidebar.viewLeadProfile": "View Full Lead Profile",
|
|
3920
4055
|
"crm.leadDetail.assignedTo": "Assigned to",
|
|
3921
4056
|
"crm.leadDetail.backToList": "Back to list",
|
|
4057
|
+
"crm.leadDetail.formAnswers": "Form answers",
|
|
3922
4058
|
"crm.leadDetail.company": "Company",
|
|
3923
4059
|
"crm.leadDetail.contactInfo": "Contact Information",
|
|
3924
4060
|
"crm.leadDetail.createQuote": "Create Quote",
|
|
@@ -4212,6 +4348,7 @@ var ptBR = {
|
|
|
4212
4348
|
"crm.dealSidebar.viewLeadProfile": "Ver Perfil Completo do Lead",
|
|
4213
4349
|
"crm.leadDetail.assignedTo": "Atribu\xEDdo a",
|
|
4214
4350
|
"crm.leadDetail.backToList": "Voltar \xE0 lista",
|
|
4351
|
+
"crm.leadDetail.formAnswers": "Dados do formul\xE1rio",
|
|
4215
4352
|
"crm.leadDetail.company": "Empresa",
|
|
4216
4353
|
"crm.leadDetail.contactInfo": "Informa\xE7\xF5es de Contato",
|
|
4217
4354
|
"crm.leadDetail.createQuote": "Criar Or\xE7amento",
|
|
@@ -4504,6 +4641,9 @@ function createCrmPlugin(options) {
|
|
|
4504
4641
|
version: "1.0.0",
|
|
4505
4642
|
scope: options?.scope ?? "universal",
|
|
4506
4643
|
verticalId: options?.verticalId,
|
|
4644
|
+
// Sales-pipeline/lead-management is a business-ops tool — targets the
|
|
4645
|
+
// saas/admin Panel world, not the ecommerce storefront.
|
|
4646
|
+
scaffolds: ["saas"],
|
|
4507
4647
|
defaultEnabled: true,
|
|
4508
4648
|
dependencies: [],
|
|
4509
4649
|
declaredFeatures: [
|
|
@@ -4512,6 +4652,15 @@ function createCrmPlugin(options) {
|
|
|
4512
4652
|
{ id: "crm.quotes", label: config.labels.quotes, group: config.labels.pageTitle },
|
|
4513
4653
|
{ id: "crm.pipeline", label: config.labels.pipeline, group: config.labels.pageTitle }
|
|
4514
4654
|
],
|
|
4655
|
+
// Stock quantity caps. leads/deals/quotes share core tables partitioned by
|
|
4656
|
+
// `kind` (people/orders), so each declaration carries a kindFilter. A lead
|
|
4657
|
+
// create auto-spawns a deal, so the lead guard also gates deal creation;
|
|
4658
|
+
// `deals` has no standalone create UI (declared for usage banners/counts).
|
|
4659
|
+
declaredLimits: [
|
|
4660
|
+
{ key: "leads", label: "Leads", table: "people", kindFilter: "lead" },
|
|
4661
|
+
{ key: "deals", label: "Deals", table: "orders", kindFilter: "deal" },
|
|
4662
|
+
{ key: "quotes", label: "Quotes", table: "orders", kindFilter: "quote" }
|
|
4663
|
+
],
|
|
4515
4664
|
navigation: [
|
|
4516
4665
|
{
|
|
4517
4666
|
section: options?.navSection ?? "main",
|