@fayz-ai/plugin-crm 0.2.3 → 0.8.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/README.md +2 -0
- package/dist/CrmPage.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 +176 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +96 -73
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +10 -0
- package/dist/migrations/index.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/package.json +8 -5
- package/src/CrmPage.tsx +0 -2
- package/src/data/supabase.ts +30 -27
- package/src/data/tables.ts +11 -0
- package/src/index.ts +15 -11
- 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/index.ts +247 -0
- package/src/registries.ts +45 -4
- package/src/schema/index.ts +25 -25
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PluginManifest, PluginScope, VerticalId } from '@fayz-ai/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type EntityLookupMap } from '@fayz-ai/saas';
|
|
3
3
|
import type { CrmDataProvider } from './data/types';
|
|
4
4
|
export interface CrmPluginLabels {
|
|
5
5
|
pageTitle: string;
|
|
@@ -55,14 +55,14 @@ export interface CrmPluginOptions {
|
|
|
55
55
|
/** Contact/person lookup for client search in quotes and leads */
|
|
56
56
|
contactLookup?: import('@fayz-ai/saas').EntityLookup;
|
|
57
57
|
/** Client conversion config — when a lead is approved, CRM converts the person
|
|
58
|
-
* to a client by updating `
|
|
58
|
+
* to a client by updating `people.kind` and creating the extension table record.
|
|
59
59
|
* @example { archetypeKind: 'customer', extensionTable: 'clients', fkColumn: 'person_id' } */
|
|
60
60
|
clientConversion?: {
|
|
61
|
-
/** The archetype kind to set on
|
|
61
|
+
/** The archetype kind to set on people.kind (e.g., 'customer') */
|
|
62
62
|
archetypeKind: string;
|
|
63
63
|
/** Extension table name (e.g., 'clients') in public schema */
|
|
64
64
|
extensionTable: string;
|
|
65
|
-
/** FK column pointing to
|
|
65
|
+
/** FK column pointing to people.id (e.g., 'person_id') */
|
|
66
66
|
fkColumn: string;
|
|
67
67
|
};
|
|
68
68
|
}
|
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,KAAK,
|
|
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,CAAA;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IACjC,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9D,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACrD,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACxE,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACtE,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnD,YAAY,CAAC,EAAE,eAAe,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;IACjC,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,eAAe,CAAA;IAC/B,kEAAkE;IAClE,aAAa,CAAC,EAAE,OAAO,eAAe,EAAE,YAAY,CAAA;IACpD;;mGAE+F;IAC/F,gBAAgB,CAAC,EAAE;QACjB,kEAAkE;QAClE,aAAa,EAAE,MAAM,CAAA;QACrB,8DAA8D;QAC9D,cAAc,EAAE,MAAM,CAAA;QACtB,0DAA0D;QAC1D,QAAQ,EAAE,MAAM,CAAA;KACjB,CAAA;CACF;AAoDD,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CA0H1E;AAED,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React14, { useState, useMemo, useRef, useEffect } from 'react';
|
|
2
|
+
import { createPluginContext, PluginSettingsPanel, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, SettingsGroup, ToggleRow, formatCurrency, PersonLink } from '@fayz-ai/saas';
|
|
2
3
|
import { registerTranslations, createSafeDataProvider, useTranslation, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
|
|
3
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';
|
|
4
|
-
import { createPluginContext, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, SettingsGroup, ToggleRow, formatCurrency, PersonLink } from '@fayz-ai/saas';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import { Filter, Globe, Target, Check, ChevronRight, UserPlus, Plus, FileText, MessageCircle, CheckSquare, Users, Mail, Phone, Clock, Calendar, Send, ChevronDown, Printer, X, Pencil, User, Hash, CircleCheckBig, ArrowRight, Ban, Trash2, CircleAlert, CircleDashed, Loader2, DollarSign } from 'lucide-react';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
@@ -54,37 +54,6 @@ function CrmGeneralSettings() {
|
|
|
54
54
|
] })
|
|
55
55
|
] });
|
|
56
56
|
}
|
|
57
|
-
function PipelineSettings() {
|
|
58
|
-
const t2 = useTranslation();
|
|
59
|
-
const stages = useCrmStore((s) => s.stages);
|
|
60
|
-
useCrmStore((s) => s.pipelines);
|
|
61
|
-
const fetchPipelines = useCrmStore((s) => s.fetchPipelines);
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
fetchPipelines();
|
|
64
|
-
}, []);
|
|
65
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
66
|
-
/* @__PURE__ */ jsx(SettingsGroup, { title: t2("crm.pipelineSettings.title"), description: t2("crm.pipelineSettings.description"), children: stages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "py-6 text-center text-sm text-muted-foreground", children: t2("common.loading") }) : /* @__PURE__ */ jsx("div", { className: "space-y-0", children: stages.map((stage, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 py-3", children: [
|
|
67
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground w-5 shrink-0", children: i + 1 }),
|
|
68
|
-
/* @__PURE__ */ jsx("div", { className: "h-3 w-3 rounded-full shrink-0", style: { backgroundColor: stage.color } }),
|
|
69
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
70
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: stage.name }),
|
|
71
|
-
/* @__PURE__ */ jsxs("p", { className: "text-[10px] text-muted-foreground", children: [
|
|
72
|
-
t2("crm.pipelineSettings.probability"),
|
|
73
|
-
": ",
|
|
74
|
-
stage.probability,
|
|
75
|
-
"%",
|
|
76
|
-
stage.isWon && ` \u2014 ${t2("crm.pipelineSettings.winStage")}`,
|
|
77
|
-
stage.isLost && ` \u2014 ${t2("crm.pipelineSettings.lossStage")}`
|
|
78
|
-
] })
|
|
79
|
-
] }),
|
|
80
|
-
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
81
|
-
stage.probability,
|
|
82
|
-
"%"
|
|
83
|
-
] })
|
|
84
|
-
] }, stage.id)) }) }),
|
|
85
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground px-1", children: t2("crm.pipelineSettings.customizationNote") })
|
|
86
|
-
] });
|
|
87
|
-
}
|
|
88
57
|
var STEPS = [
|
|
89
58
|
{ id: "welcome", icon: Filter, titleKey: "crm.onboarding.welcome", descKey: "crm.onboarding.description" },
|
|
90
59
|
{ id: "sources", icon: Globe, titleKey: "crm.onboarding.sources.title", descKey: "crm.onboarding.sources.description" },
|
|
@@ -1248,7 +1217,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1248
1217
|
observations,
|
|
1249
1218
|
items: items.map((it) => ({ itemKind: it.itemKind, description: it.description, quantity: it.quantity, unitPrice: it.unitPrice, discount: it.discount }))
|
|
1250
1219
|
};
|
|
1251
|
-
const snapshot =
|
|
1220
|
+
const snapshot = React14.useRef(null);
|
|
1252
1221
|
useEffect(() => {
|
|
1253
1222
|
if (!loadingExisting && snapshot.current === null) snapshot.current = JSON.stringify(currentFields);
|
|
1254
1223
|
}, [loadingExisting]);
|
|
@@ -2129,8 +2098,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
2129
2098
|
/* @__PURE__ */ jsx("h1", { style: { fontSize: "20px", fontWeight: 600, margin: 0 }, children: t2("crm.settingsPage.title") }),
|
|
2130
2099
|
/* @__PURE__ */ jsx("p", { style: { color: "var(--muted-foreground, #6b7280)", margin: "4px 0 0", fontSize: "14px" }, children: t2("crm.settingsPage.subtitle") })
|
|
2131
2100
|
] }),
|
|
2132
|
-
/* @__PURE__ */ jsx(CrmGeneralSettings, {})
|
|
2133
|
-
/* @__PURE__ */ jsx(PipelineSettings, {})
|
|
2101
|
+
/* @__PURE__ */ jsx(CrmGeneralSettings, {})
|
|
2134
2102
|
] }) }) });
|
|
2135
2103
|
}
|
|
2136
2104
|
const renderView = createViewRouter([
|
|
@@ -2807,6 +2775,17 @@ function createMockCrmProvider(options) {
|
|
|
2807
2775
|
return provider;
|
|
2808
2776
|
}
|
|
2809
2777
|
|
|
2778
|
+
// src/data/tables.ts
|
|
2779
|
+
var T = {
|
|
2780
|
+
activities: "plg_crm_activities",
|
|
2781
|
+
tags: "plg_crm_tags",
|
|
2782
|
+
activityTypes: "plg_crm_activity_types",
|
|
2783
|
+
pipelines: "plg_crm_pipelines",
|
|
2784
|
+
pipelineStages: "plg_crm_pipeline_stages",
|
|
2785
|
+
dealExtensions: "plg_crm_deal_extensions",
|
|
2786
|
+
leadSources: "plg_crm_lead_sources"
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2810
2789
|
// src/data/supabase.ts
|
|
2811
2790
|
function getTenantId() {
|
|
2812
2791
|
return getActiveTenantId();
|
|
@@ -2821,19 +2800,19 @@ function snakeToCamel(obj) {
|
|
|
2821
2800
|
function getClients() {
|
|
2822
2801
|
const supabase = getSupabaseClientOptional();
|
|
2823
2802
|
if (!supabase) throw new Error("Supabase not initialized");
|
|
2824
|
-
return { core: supabase
|
|
2803
|
+
return { core: supabase, pub: supabase };
|
|
2825
2804
|
}
|
|
2826
2805
|
function createSupabaseCrmProvider(options) {
|
|
2827
2806
|
const provider = {
|
|
2828
|
-
// --- Pipelines (public.
|
|
2807
|
+
// --- Pipelines (public.plg_crm_pipelines + plg_crm_pipeline_stages) ---
|
|
2829
2808
|
async getPipelines() {
|
|
2830
2809
|
const { pub } = getClients();
|
|
2831
|
-
const { data } = await pub.from(
|
|
2810
|
+
const { data } = await pub.from(T.pipelines).select("*").eq("is_active", true).order("name");
|
|
2832
2811
|
return (data ?? []).map((r) => snakeToCamel(r));
|
|
2833
2812
|
},
|
|
2834
2813
|
async getPipelineStages(pipelineId) {
|
|
2835
2814
|
const { pub } = getClients();
|
|
2836
|
-
const { data } = await pub.from(
|
|
2815
|
+
const { data } = await pub.from(T.pipelineStages).select("*").eq("pipeline_id", pipelineId).order("order");
|
|
2837
2816
|
return (data ?? []).map((r) => snakeToCamel(r));
|
|
2838
2817
|
},
|
|
2839
2818
|
// --- Leads (via view — single query) ---
|
|
@@ -2891,7 +2870,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
2891
2870
|
async createLead(input) {
|
|
2892
2871
|
const { core } = getClients();
|
|
2893
2872
|
const tenantId = getTenantId();
|
|
2894
|
-
const { data, error } = await core.from("
|
|
2873
|
+
const { data, error } = await core.from("people").insert({
|
|
2895
2874
|
tenant_id: tenantId,
|
|
2896
2875
|
kind: "lead",
|
|
2897
2876
|
name: input.name,
|
|
@@ -2914,13 +2893,13 @@ function createSupabaseCrmProvider(options) {
|
|
|
2914
2893
|
if (partial.phone !== void 0) row.phone = partial.phone;
|
|
2915
2894
|
if (partial.notes !== void 0) row.notes = partial.notes;
|
|
2916
2895
|
if (partial.status) row.metadata = { status: partial.status };
|
|
2917
|
-
const { data, error } = await core.from("
|
|
2896
|
+
const { data, error } = await core.from("people").update(row).eq("id", id).select().single();
|
|
2918
2897
|
if (error) throw new Error(error.message);
|
|
2919
2898
|
return await provider.getLeadById(id);
|
|
2920
2899
|
},
|
|
2921
2900
|
async convertLeadToDeal(leadId, dealInput) {
|
|
2922
2901
|
const { core } = getClients();
|
|
2923
|
-
await core.from("
|
|
2902
|
+
await core.from("people").update({ metadata: { status: "converted" } }).eq("id", leadId);
|
|
2924
2903
|
return provider.createDeal({ ...dealInput, leadId });
|
|
2925
2904
|
},
|
|
2926
2905
|
// --- Deals (via view — single query with all joins) ---
|
|
@@ -3027,7 +3006,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3027
3006
|
metadata: { contactName: input.contactName }
|
|
3028
3007
|
}).select().single();
|
|
3029
3008
|
if (error) throw new Error(error.message);
|
|
3030
|
-
await pub.from(
|
|
3009
|
+
await pub.from(T.dealExtensions).insert({
|
|
3031
3010
|
order_id: order.id,
|
|
3032
3011
|
tenant_id: tenantId,
|
|
3033
3012
|
pipeline_id: input.pipelineId,
|
|
@@ -3065,14 +3044,14 @@ function createSupabaseCrmProvider(options) {
|
|
|
3065
3044
|
if (partial.stageId) row.stage_id = partial.stageId;
|
|
3066
3045
|
if (partial.probability != null) row.probability = partial.probability;
|
|
3067
3046
|
if (partial.expectedCloseDate) row.expected_close_date = partial.expectedCloseDate;
|
|
3068
|
-
await pub.from(
|
|
3047
|
+
await pub.from(T.dealExtensions).update(row).eq("order_id", id);
|
|
3069
3048
|
}
|
|
3070
3049
|
return await provider.getDealById(id);
|
|
3071
3050
|
},
|
|
3072
3051
|
async moveDealToStage(dealId, stageId) {
|
|
3073
3052
|
const { core, pub } = getClients();
|
|
3074
|
-
const { data: stageRow } = await pub.from(
|
|
3075
|
-
await pub.from(
|
|
3053
|
+
const { data: stageRow } = await pub.from(T.pipelineStages).select("*").eq("id", stageId).single();
|
|
3054
|
+
await pub.from(T.dealExtensions).update({
|
|
3076
3055
|
stage_id: stageId,
|
|
3077
3056
|
probability: stageRow?.probability ?? 0
|
|
3078
3057
|
}).eq("order_id", dealId);
|
|
@@ -3091,10 +3070,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
3091
3070
|
tenantId: stageRow.tenant_id,
|
|
3092
3071
|
createdAt: stageRow.created_at
|
|
3093
3072
|
};
|
|
3094
|
-
const { data: ext } = await pub.from(
|
|
3073
|
+
const { data: ext } = await pub.from(T.dealExtensions).select("lead_id").eq("order_id", dealId).single();
|
|
3095
3074
|
if (ext?.lead_id) {
|
|
3096
3075
|
const newLeadStatus = deriveLeadStatus(typedStage);
|
|
3097
|
-
await core.from("
|
|
3076
|
+
await core.from("people").update({ metadata: { status: newLeadStatus } }).eq("id", ext.lead_id);
|
|
3098
3077
|
}
|
|
3099
3078
|
const { data: quotes } = await core.from("orders").select("id, status").eq("kind", "quote");
|
|
3100
3079
|
for (const q of quotes ?? []) {
|
|
@@ -3109,10 +3088,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
3109
3088
|
}
|
|
3110
3089
|
return await provider.getDealById(dealId);
|
|
3111
3090
|
},
|
|
3112
|
-
// --- Activities (public.
|
|
3091
|
+
// --- Activities (public.plg_crm_activities) ---
|
|
3113
3092
|
async getActivities(query) {
|
|
3114
3093
|
const { pub } = getClients();
|
|
3115
|
-
let qb = pub.from(
|
|
3094
|
+
let qb = pub.from(T.activities).select("*", { count: "exact" });
|
|
3116
3095
|
if (query.dealId) qb = qb.eq("deal_id", query.dealId);
|
|
3117
3096
|
if (query.leadId) qb = qb.eq("lead_id", query.leadId);
|
|
3118
3097
|
if (query.activityType) qb = qb.eq("activity_type", query.activityType);
|
|
@@ -3127,7 +3106,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3127
3106
|
async createActivity(input) {
|
|
3128
3107
|
const { pub } = getClients();
|
|
3129
3108
|
const tenantId = getTenantId();
|
|
3130
|
-
const { data, error } = await pub.from(
|
|
3109
|
+
const { data, error } = await pub.from(T.activities).insert({
|
|
3131
3110
|
tenant_id: tenantId,
|
|
3132
3111
|
deal_id: input.dealId,
|
|
3133
3112
|
lead_id: input.leadId,
|
|
@@ -3143,11 +3122,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
3143
3122
|
},
|
|
3144
3123
|
async completeActivity(id) {
|
|
3145
3124
|
const { pub } = getClients();
|
|
3146
|
-
const { data, error } = await pub.from(
|
|
3125
|
+
const { data, error } = await pub.from(T.activities).update({ completed_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id).select().single();
|
|
3147
3126
|
if (error) throw new Error(error.message);
|
|
3148
3127
|
return snakeToCamel(data);
|
|
3149
3128
|
},
|
|
3150
|
-
// --- Quotes (
|
|
3129
|
+
// --- Quotes (public.orders kind='quote' + order_items) ---
|
|
3151
3130
|
async getQuotes(query) {
|
|
3152
3131
|
const { core } = getClients();
|
|
3153
3132
|
let qb = core.from("orders").select("*", { count: "exact" }).eq("kind", "quote");
|
|
@@ -3346,11 +3325,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
3346
3325
|
const personToConvert = quote.leadId ?? quote.contactId;
|
|
3347
3326
|
if (personToConvert) {
|
|
3348
3327
|
const clientKind = options?.clientConversion?.archetypeKind ?? "client";
|
|
3349
|
-
const { data: person } = await core.from("
|
|
3328
|
+
const { data: person } = await core.from("people").select("kind, name, email, phone, tenant_id, metadata").eq("id", personToConvert).single();
|
|
3350
3329
|
const personKind = person?.kind;
|
|
3351
3330
|
if (person && (personKind === "lead" || personKind === "contact")) {
|
|
3352
3331
|
const personMeta = person?.metadata ?? {};
|
|
3353
|
-
await core.from("
|
|
3332
|
+
await core.from("people").update({
|
|
3354
3333
|
kind: clientKind,
|
|
3355
3334
|
metadata: { ...personMeta, convertedFromLead: true }
|
|
3356
3335
|
}).eq("id", personToConvert);
|
|
@@ -3414,7 +3393,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
3414
3393
|
},
|
|
3415
3394
|
async getDealByLeadId(leadId) {
|
|
3416
3395
|
const { pub } = getClients();
|
|
3417
|
-
const { data } = await pub.from(
|
|
3396
|
+
const { data } = await pub.from(T.dealExtensions).select("order_id").eq("lead_id", leadId).limit(1);
|
|
3418
3397
|
if (!data || data.length === 0) return null;
|
|
3419
3398
|
return provider.getDealById(data[0].order_id);
|
|
3420
3399
|
},
|
|
@@ -3423,16 +3402,16 @@ function createSupabaseCrmProvider(options) {
|
|
|
3423
3402
|
const { core, pub } = getClients();
|
|
3424
3403
|
const monthStart = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7) + "-01";
|
|
3425
3404
|
const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
3426
|
-
const { count: totalLeads } = await core.from("
|
|
3427
|
-
const { count: newLeads } = await core.from("
|
|
3405
|
+
const { count: totalLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead");
|
|
3406
|
+
const { count: newLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead").gte("created_at", monthStart);
|
|
3428
3407
|
const { data: deals } = await core.from("orders").select("status, total, updated_at").eq("kind", "deal");
|
|
3429
3408
|
const allDeals = deals ?? [];
|
|
3430
3409
|
const openDeals = allDeals.filter((d) => d.status === "open");
|
|
3431
3410
|
const wonDeals = allDeals.filter((d) => d.status === "won");
|
|
3432
3411
|
const wonThisMonth = wonDeals.filter((d) => d.updated_at >= monthStart);
|
|
3433
3412
|
const convertedLeads = allDeals.length;
|
|
3434
|
-
const { count: pendingActs } = await pub.from(
|
|
3435
|
-
const { count: overdueActs } = await pub.from(
|
|
3413
|
+
const { count: pendingActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null);
|
|
3414
|
+
const { count: overdueActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null).lt("due_date", today2);
|
|
3436
3415
|
return {
|
|
3437
3416
|
totalLeads: totalLeads ?? 0,
|
|
3438
3417
|
newLeadsThisMonth: newLeads ?? 0,
|
|
@@ -3774,7 +3753,7 @@ var leadSourceEntity = {
|
|
|
3774
3753
|
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
3775
3754
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3776
3755
|
],
|
|
3777
|
-
data: { table:
|
|
3756
|
+
data: { table: T.leadSources, tenantScoped: true }
|
|
3778
3757
|
};
|
|
3779
3758
|
var tagEntity = {
|
|
3780
3759
|
name: "Tag",
|
|
@@ -3784,10 +3763,34 @@ var tagEntity = {
|
|
|
3784
3763
|
defaultSort: "name",
|
|
3785
3764
|
fields: [
|
|
3786
3765
|
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
3787
|
-
{ key: "color", label: "Color", type: "
|
|
3766
|
+
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
|
|
3788
3767
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3789
3768
|
],
|
|
3790
|
-
data: { table:
|
|
3769
|
+
data: { table: T.tags, tenantScoped: true }
|
|
3770
|
+
};
|
|
3771
|
+
var pipelineStageEntity = {
|
|
3772
|
+
name: "Stage",
|
|
3773
|
+
namePlural: "Stages",
|
|
3774
|
+
icon: "Workflow",
|
|
3775
|
+
displayField: "name",
|
|
3776
|
+
defaultSort: "order",
|
|
3777
|
+
fields: [
|
|
3778
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
3779
|
+
{
|
|
3780
|
+
key: "pipelineId",
|
|
3781
|
+
label: "Pipeline",
|
|
3782
|
+
type: "relation",
|
|
3783
|
+
relation: { table: T.pipelines, labelField: "name" },
|
|
3784
|
+
required: true,
|
|
3785
|
+
showInTable: true
|
|
3786
|
+
},
|
|
3787
|
+
{ key: "order", label: "Order", type: "number", required: true, showInTable: true, defaultValue: 0 },
|
|
3788
|
+
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
|
|
3789
|
+
{ key: "probability", label: "Probability %", type: "number", min: 0, max: 100, showInTable: true, defaultValue: 0 },
|
|
3790
|
+
{ key: "isWon", label: "Won Stage", type: "boolean", showInTable: true, defaultValue: false },
|
|
3791
|
+
{ key: "isLost", label: "Lost Stage", type: "boolean", showInTable: true, defaultValue: false }
|
|
3792
|
+
],
|
|
3793
|
+
data: { table: T.pipelineStages, tenantScoped: true }
|
|
3791
3794
|
};
|
|
3792
3795
|
var activityTypeEntity = {
|
|
3793
3796
|
name: "Activity Type",
|
|
@@ -3799,9 +3802,24 @@ var activityTypeEntity = {
|
|
|
3799
3802
|
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
3800
3803
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
3801
3804
|
],
|
|
3802
|
-
data: { table:
|
|
3805
|
+
data: { table: T.activityTypes, tenantScoped: true }
|
|
3803
3806
|
};
|
|
3804
3807
|
var crmRegistries = [
|
|
3808
|
+
{
|
|
3809
|
+
id: "stages",
|
|
3810
|
+
entity: pipelineStageEntity,
|
|
3811
|
+
icon: "Workflow",
|
|
3812
|
+
description: "Pipeline stages used by CRM deals",
|
|
3813
|
+
display: "table",
|
|
3814
|
+
seedData: [
|
|
3815
|
+
{ id: "stage-new", pipelineId: "pipe-default", name: "New Lead", order: 1, color: "#64748b", probability: 10, isWon: false, isLost: false },
|
|
3816
|
+
{ id: "stage-qualified", pipelineId: "pipe-default", name: "Qualified", order: 2, color: "#3b82f6", probability: 30, isWon: false, isLost: false },
|
|
3817
|
+
{ id: "stage-proposal", pipelineId: "pipe-default", name: "Proposal", order: 3, color: "#8b5cf6", probability: 60, isWon: false, isLost: false },
|
|
3818
|
+
{ id: "stage-negotiation", pipelineId: "pipe-default", name: "Negotiation", order: 4, color: "#f59e0b", probability: 80, isWon: false, isLost: false },
|
|
3819
|
+
{ id: "stage-won", pipelineId: "pipe-default", name: "Won", order: 5, color: "#10b981", probability: 100, isWon: true, isLost: false },
|
|
3820
|
+
{ id: "stage-lost", pipelineId: "pipe-default", name: "Lost", order: 6, color: "#ef4444", probability: 0, isWon: false, isLost: true }
|
|
3821
|
+
]
|
|
3822
|
+
},
|
|
3805
3823
|
{
|
|
3806
3824
|
id: "lead-sources",
|
|
3807
3825
|
entity: leadSourceEntity,
|
|
@@ -4482,7 +4500,7 @@ function createCrmPlugin(options) {
|
|
|
4482
4500
|
() => createMockCrmProvider()
|
|
4483
4501
|
);
|
|
4484
4502
|
const store = createCrmStore(provider);
|
|
4485
|
-
const PageComponent = () =>
|
|
4503
|
+
const PageComponent = () => React14.createElement(CrmPage, { config, provider, store, registries: crmRegistries });
|
|
4486
4504
|
const dashboardWidgets = createCrmDashboardWidgets({ config, provider, store });
|
|
4487
4505
|
return {
|
|
4488
4506
|
id: "crm",
|
|
@@ -4491,6 +4509,9 @@ function createCrmPlugin(options) {
|
|
|
4491
4509
|
version: "1.0.0",
|
|
4492
4510
|
scope: options?.scope ?? "universal",
|
|
4493
4511
|
verticalId: options?.verticalId,
|
|
4512
|
+
// Sales-pipeline/lead-management is a business-ops tool — targets the
|
|
4513
|
+
// saas/admin Panel world, not the ecommerce storefront.
|
|
4514
|
+
scaffolds: ["saas"],
|
|
4494
4515
|
defaultEnabled: true,
|
|
4495
4516
|
dependencies: [],
|
|
4496
4517
|
declaredFeatures: [
|
|
@@ -4569,15 +4590,17 @@ function createCrmPlugin(options) {
|
|
|
4569
4590
|
label: "Sales & CRM",
|
|
4570
4591
|
icon: "Filter",
|
|
4571
4592
|
component: (() => {
|
|
4572
|
-
const Tab = () =>
|
|
4593
|
+
const Tab = () => React14.createElement(
|
|
4573
4594
|
CrmContextProvider,
|
|
4574
4595
|
{ config, provider, store },
|
|
4575
|
-
|
|
4576
|
-
"
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4596
|
+
React14.createElement(PluginSettingsPanel, {
|
|
4597
|
+
title: "Sales & CRM",
|
|
4598
|
+
subtitle: "Pipeline, lead management, and CRM properties",
|
|
4599
|
+
generalSettings: React14.createElement(CrmGeneralSettings),
|
|
4600
|
+
registries: crmRegistries,
|
|
4601
|
+
hostPluginId: "crm",
|
|
4602
|
+
routeBase: "/settings/crm"
|
|
4603
|
+
})
|
|
4581
4604
|
);
|
|
4582
4605
|
Tab.displayName = "CrmSettingsTab";
|
|
4583
4606
|
return Tab;
|