@fayz-ai/plugin-crm 0.9.0 → 0.9.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 +3 -3
- package/dist/components/AutomationBolt.d.ts +22 -0
- package/dist/components/AutomationBolt.d.ts.map +1 -0
- package/dist/{CrmContext.d.ts → context.d.ts} +4 -2
- package/dist/context.d.ts.map +1 -0
- package/dist/data/registries.d.ts.map +1 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +573 -488
- package/dist/index.js.map +1 -1
- package/dist/{cascade.d.ts → lib/cascade.d.ts} +1 -1
- package/dist/lib/cascade.d.ts.map +1 -0
- package/dist/lib/message-events.d.ts +13 -0
- package/dist/lib/message-events.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/public/context.d.ts +1 -1
- package/dist/public/context.d.ts.map +1 -1
- package/dist/public/createPublicFormsPlugin.d.ts +1 -1
- package/dist/public/createPublicFormsPlugin.d.ts.map +1 -1
- package/dist/public/{data.supabase.d.ts → data/supabase.d.ts} +2 -2
- package/dist/public/data/supabase.d.ts.map +1 -0
- package/dist/public/index.d.ts +6 -6
- package/dist/public/index.d.ts.map +1 -1
- package/dist/public/index.js +2 -2
- package/dist/public/index.js.map +1 -1
- package/dist/public/{inbox.d.ts → lib/inbox.d.ts} +1 -1
- package/dist/public/lib/inbox.d.ts.map +1 -0
- package/dist/public/{uploads.d.ts → lib/uploads.d.ts} +1 -1
- package/dist/public/lib/uploads.d.ts.map +1 -0
- package/dist/store.d.ts +9 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/views/ActivityListView.d.ts.map +1 -1
- package/dist/{CrmPage.d.ts → views/CrmPage.d.ts} +3 -3
- package/dist/views/CrmPage.d.ts.map +1 -0
- package/dist/views/DealSidebar.d.ts.map +1 -1
- package/dist/views/LeadListView.d.ts.map +1 -1
- package/dist/views/PipelineView.d.ts +3 -1
- package/dist/views/PipelineView.d.ts.map +1 -1
- package/dist/views/QuoteDetailView.d.ts.map +1 -1
- package/dist/views/QuoteFormView.d.ts.map +1 -1
- package/dist/views/QuoteListView.d.ts.map +1 -1
- package/dist/views/dashboardWidgets.d.ts +1 -1
- package/dist/views/dashboardWidgets.d.ts.map +1 -1
- package/package.json +6 -10
- package/dist/CrmContext.d.ts.map +0 -1
- package/dist/CrmPage.d.ts.map +0 -1
- package/dist/cascade.d.ts.map +0 -1
- package/dist/public/data.supabase.d.ts.map +0 -1
- package/dist/public/inbox.d.ts.map +0 -1
- package/dist/public/uploads.d.ts.map +0 -1
- package/dist/registries.d.ts.map +0 -1
- package/src/CrmContext.tsx +0 -30
- package/src/CrmPage.tsx +0 -150
- package/src/README.md +0 -97
- package/src/cascade.ts +0 -26
- package/src/components/BoardFilters.tsx +0 -190
- package/src/components/CrmGeneralSettings.tsx +0 -56
- package/src/components/CrmOnboarding.tsx +0 -52
- package/src/components/LeadAttachments.tsx +0 -140
- package/src/components/PipelineSettings.tsx +0 -45
- package/src/components/QuoteStatusDropdown.tsx +0 -226
- package/src/components/TagChips.tsx +0 -80
- package/src/data/index.ts +0 -2
- package/src/data/mock.ts +0 -559
- package/src/data/supabase.ts +0 -928
- package/src/data/tables.ts +0 -11
- package/src/data/types.ts +0 -61
- package/src/index.ts +0 -429
- package/src/lib/access.ts +0 -11
- package/src/lib/form-answers.tsx +0 -80
- package/src/lib/relative-time.ts +0 -84
- package/src/lib/tenant.ts +0 -4
- package/src/locales/en.ts +0 -307
- package/src/locales/index.ts +0 -7
- package/src/locales/pt-BR.ts +0 -307
- package/src/migrations/000_plg_rename.sql +0 -28
- package/src/migrations/001_crm_base.sql +0 -73
- package/src/migrations/002_activities.sql +0 -33
- package/src/migrations/003_crm_views_rls.sql +0 -69
- package/src/migrations/004_seed_default_pipeline.sql +0 -31
- package/src/migrations/005_public_lead.sql +0 -189
- package/src/migrations/006_lead_enters_pipeline.sql +0 -265
- package/src/migrations/007_activity_log.sql +0 -55
- package/src/migrations/008_view_field_aliases.sql +0 -43
- package/src/migrations/009_deal_archived_status.sql +0 -30
- package/src/migrations/010_quote_archived_status.sql +0 -40
- package/src/migrations/011_agent_rpc_update_lead.sql +0 -153
- package/src/migrations/012_agent_rpc_create_lead.sql +0 -128
- package/src/migrations/013_tag_slugs.sql +0 -177
- package/src/migrations/014_public_lead_tags.sql +0 -172
- package/src/migrations/015_lead_attachments.sql +0 -357
- package/src/migrations/016_public_lead_activity.sql +0 -123
- package/src/migrations/index.ts +0 -2023
- package/src/public/context.tsx +0 -150
- package/src/public/createPublicFormsPlugin.ts +0 -282
- package/src/public/data.supabase.ts +0 -92
- package/src/public/inbox.ts +0 -143
- package/src/public/index.ts +0 -51
- package/src/public/types.ts +0 -173
- package/src/public/uploads.ts +0 -205
- package/src/registries.ts +0 -162
- package/src/schema/index.ts +0 -104
- package/src/store.ts +0 -472
- package/src/types.ts +0 -337
- package/src/views/ActivityListView.tsx +0 -264
- package/src/views/DashboardView.tsx +0 -12
- package/src/views/DealSidebar.tsx +0 -482
- package/src/views/LeadDetailView.tsx +0 -378
- package/src/views/LeadFormView.tsx +0 -66
- package/src/views/LeadListView.tsx +0 -100
- package/src/views/PipelineView.tsx +0 -446
- package/src/views/QuoteDetailView.tsx +0 -412
- package/src/views/QuoteFormView.tsx +0 -494
- package/src/views/QuoteListView.tsx +0 -115
- package/src/views/dashboardWidgets.tsx +0 -248
- /package/dist/{registries.d.ts → data/registries.d.ts} +0 -0
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
2
|
-
import type { ColumnDef } from '@tanstack/react-table'
|
|
3
|
-
import type { StoreApi } from 'zustand'
|
|
4
|
-
import type { DashboardWidgetDef } from '@fayz-ai/core'
|
|
5
|
-
import { useTranslation } from '@fayz-ai/core'
|
|
6
|
-
import {
|
|
7
|
-
KpiCard, ChartWidget, TableWidget,
|
|
8
|
-
defineKpiWidget, defineChartWidget, defineTableWidget, defineCustomWidget,
|
|
9
|
-
Card, CardHeader, CardTitle, CardContent,
|
|
10
|
-
} from '@fayz-ai/ui'
|
|
11
|
-
import { CrmContextProvider, useCrmConfig, useCrmStore, formatCurrency, type ResolvedCrmConfig } from '../CrmContext'
|
|
12
|
-
import type { CrmDataProvider } from '../data/types'
|
|
13
|
-
import type { CrmUIState } from '../store'
|
|
14
|
-
import type { Lead, Quote } from '../types'
|
|
15
|
-
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Data-loading hooks (the store dedups, so widgets can each ensure their data).
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
function useEnsureSummary() {
|
|
21
|
-
const fetchSummary = useCrmStore((s) => s.fetchSummary)
|
|
22
|
-
useEffect(() => { void fetchSummary() }, [])
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function useEnsureFunnel() {
|
|
26
|
-
const pipelines = useCrmStore((s) => s.pipelines)
|
|
27
|
-
const fetchPipelines = useCrmStore((s) => s.fetchPipelines)
|
|
28
|
-
const fetchFunnel = useCrmStore((s) => s.fetchFunnel)
|
|
29
|
-
useEffect(() => { void fetchPipelines() }, [])
|
|
30
|
-
useEffect(() => { if (pipelines.length > 0) void fetchFunnel(pipelines[0]!.id) }, [pipelines])
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function StatusDot({ status, palette }: { status: string; palette: Record<string, string> }) {
|
|
34
|
-
return (
|
|
35
|
-
<span className="inline-flex items-center gap-1.5">
|
|
36
|
-
<span className={`h-1.5 w-1.5 rounded-full ${palette[status] ?? 'bg-muted-foreground/40'}`} />
|
|
37
|
-
<span className="text-xs capitalize text-muted-foreground">{status}</span>
|
|
38
|
-
</span>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// KPI widgets
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
function TotalLeadsKpi() {
|
|
47
|
-
const t = useTranslation()
|
|
48
|
-
const summary = useCrmStore((s) => s.summary)
|
|
49
|
-
useEnsureSummary()
|
|
50
|
-
return (
|
|
51
|
-
<KpiCard
|
|
52
|
-
label={t('crm.dashboard.totalLeads')}
|
|
53
|
-
icon="Users"
|
|
54
|
-
value={String(summary?.totalLeads ?? 0)}
|
|
55
|
-
sub={t('crm.dashboard.newThisMonth', { count: String(summary?.newLeadsThisMonth ?? 0) })}
|
|
56
|
-
/>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function OpenPipelineKpi() {
|
|
61
|
-
const t = useTranslation()
|
|
62
|
-
const { currency } = useCrmConfig()
|
|
63
|
-
const summary = useCrmStore((s) => s.summary)
|
|
64
|
-
useEnsureSummary()
|
|
65
|
-
return (
|
|
66
|
-
<KpiCard
|
|
67
|
-
label={t('crm.dashboard.openPipeline')}
|
|
68
|
-
icon="Target"
|
|
69
|
-
value={formatCurrency(summary?.openDealsValue ?? 0, currency)}
|
|
70
|
-
sub={t('crm.dashboard.activeDeals', { count: String(summary?.totalDeals ?? 0) })}
|
|
71
|
-
/>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function ConversionRateKpi() {
|
|
76
|
-
const t = useTranslation()
|
|
77
|
-
const summary = useCrmStore((s) => s.summary)
|
|
78
|
-
useEnsureSummary()
|
|
79
|
-
return (
|
|
80
|
-
<KpiCard
|
|
81
|
-
label={t('crm.dashboard.conversionRate')}
|
|
82
|
-
icon="TrendingUp"
|
|
83
|
-
value={`${(summary?.conversionRate ?? 0).toFixed(1)}%`}
|
|
84
|
-
sub={t('crm.dashboard.leadToDeal')}
|
|
85
|
-
/>
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function PendingTasksKpi() {
|
|
90
|
-
const t = useTranslation()
|
|
91
|
-
const summary = useCrmStore((s) => s.summary)
|
|
92
|
-
useEnsureSummary()
|
|
93
|
-
return (
|
|
94
|
-
<KpiCard
|
|
95
|
-
label={t('crm.dashboard.pendingTasks')}
|
|
96
|
-
icon={summary?.overdueActivities ? 'AlertTriangle' : 'Clock'}
|
|
97
|
-
value={String(summary?.pendingActivities ?? 0)}
|
|
98
|
-
sub={t('crm.dashboard.overdueCount', { count: String(summary?.overdueActivities ?? 0) })}
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
// Chart widgets (recharts)
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
|
|
107
|
-
function SalesFunnelChart() {
|
|
108
|
-
const t = useTranslation()
|
|
109
|
-
const funnel = useCrmStore((s) => s.funnel)
|
|
110
|
-
useEnsureFunnel()
|
|
111
|
-
const data = funnel.map((s) => ({ name: s.stageName, deals: s.dealCount }))
|
|
112
|
-
return (
|
|
113
|
-
<ChartWidget
|
|
114
|
-
type="bar"
|
|
115
|
-
title={t('crm.dashboard.pipelineOverview')}
|
|
116
|
-
icon="BarChart3"
|
|
117
|
-
categoryKey="name"
|
|
118
|
-
data={data}
|
|
119
|
-
series={[{ dataKey: 'deals' }]}
|
|
120
|
-
/>
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function PipelineValueChart() {
|
|
125
|
-
const t = useTranslation()
|
|
126
|
-
const funnel = useCrmStore((s) => s.funnel)
|
|
127
|
-
useEnsureFunnel()
|
|
128
|
-
const data = funnel.map((s) => ({ name: s.stageName, value: s.totalValue }))
|
|
129
|
-
return (
|
|
130
|
-
<ChartWidget
|
|
131
|
-
type="bar"
|
|
132
|
-
title={t('crm.dashboard.pipelineValue')}
|
|
133
|
-
icon="Target"
|
|
134
|
-
categoryKey="name"
|
|
135
|
-
data={data}
|
|
136
|
-
series={[{ dataKey: 'value', label: t('crm.dashboard.pipelineValue'), color: 'hsl(var(--magic))' }]}
|
|
137
|
-
/>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function PerformancePanel() {
|
|
142
|
-
const t = useTranslation()
|
|
143
|
-
const { currency } = useCrmConfig()
|
|
144
|
-
const summary = useCrmStore((s) => s.summary)
|
|
145
|
-
useEnsureSummary()
|
|
146
|
-
const rows = [
|
|
147
|
-
{ label: t('crm.dashboard.dealsWon'), value: String(summary?.wonDealsThisMonth ?? 0) },
|
|
148
|
-
{ label: t('crm.dashboard.revenueWon'), value: formatCurrency(summary?.wonDealsValueThisMonth ?? 0, currency), accent: true },
|
|
149
|
-
{ label: t('crm.dashboard.avgDealValue'), value: formatCurrency(summary?.averageDealValue ?? 0, currency) },
|
|
150
|
-
{ label: t('crm.dashboard.conversionRateLabel'), value: `${(summary?.conversionRate ?? 0).toFixed(1)}%` },
|
|
151
|
-
]
|
|
152
|
-
return (
|
|
153
|
-
<Card>
|
|
154
|
-
<CardHeader>
|
|
155
|
-
<CardTitle className="flex items-center gap-2">
|
|
156
|
-
<span className="text-warning">★</span>
|
|
157
|
-
{t('crm.dashboard.performance')}
|
|
158
|
-
</CardTitle>
|
|
159
|
-
</CardHeader>
|
|
160
|
-
<CardContent className="space-y-3">
|
|
161
|
-
{rows.map((r) => (
|
|
162
|
-
<div key={r.label} className="flex items-center justify-between">
|
|
163
|
-
<span className="text-sm text-muted-foreground">{r.label}</span>
|
|
164
|
-
<span className={`text-sm font-semibold ${r.accent ? 'text-success' : ''}`}>{r.value}</span>
|
|
165
|
-
</div>
|
|
166
|
-
))}
|
|
167
|
-
</CardContent>
|
|
168
|
-
</Card>
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// ---------------------------------------------------------------------------
|
|
173
|
-
// Table widgets
|
|
174
|
-
// ---------------------------------------------------------------------------
|
|
175
|
-
|
|
176
|
-
const LEAD_STATUS: Record<string, string> = {
|
|
177
|
-
new: 'bg-info', contacted: 'bg-magic', qualified: 'bg-success', converted: 'bg-warning', lost: 'bg-destructive',
|
|
178
|
-
}
|
|
179
|
-
const QUOTE_STATUS: Record<string, string> = {
|
|
180
|
-
draft: 'bg-muted-foreground', sent: 'bg-info', approved: 'bg-success', rejected: 'bg-destructive', expired: 'bg-warning',
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function RecentLeadsTable() {
|
|
184
|
-
const t = useTranslation()
|
|
185
|
-
const leads = useCrmStore((s) => s.leads)
|
|
186
|
-
const fetchLeads = useCrmStore((s) => s.fetchLeads)
|
|
187
|
-
useEffect(() => { void fetchLeads({ pageSize: 5 }) }, [])
|
|
188
|
-
const columns: ColumnDef<Lead, unknown>[] = [
|
|
189
|
-
{ accessorKey: 'name', header: t('crm.dashboard.recentLeads'), cell: ({ row }) => <span className="font-medium">{row.original.name}</span> },
|
|
190
|
-
{ id: 'contact', header: '', cell: ({ row }) => <span className="text-xs text-muted-foreground">{row.original.email || row.original.phone || row.original.sourceName || '—'}</span> },
|
|
191
|
-
{ accessorKey: 'status', header: '', cell: ({ row }) => <StatusDot status={row.original.status} palette={LEAD_STATUS} /> },
|
|
192
|
-
]
|
|
193
|
-
return <TableWidget title={t('crm.dashboard.recentLeads')} icon="Users" columns={columns} data={leads.slice(0, 5)} emptyMessage={t('crm.dashboard.noLeadsYet')} />
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function RecentQuotesTable() {
|
|
197
|
-
const t = useTranslation()
|
|
198
|
-
const { currency } = useCrmConfig()
|
|
199
|
-
const quotes = useCrmStore((s) => s.quotes)
|
|
200
|
-
const fetchQuotes = useCrmStore((s) => s.fetchQuotes)
|
|
201
|
-
useEffect(() => { void fetchQuotes({ pageSize: 5 }) }, [])
|
|
202
|
-
const columns: ColumnDef<Quote, unknown>[] = [
|
|
203
|
-
{ accessorKey: 'quoteNumber', header: t('crm.dashboard.recentQuotes'), cell: ({ row }) => <span className="font-medium">{row.original.quoteNumber}</span> },
|
|
204
|
-
{ id: 'contact', header: '', cell: ({ row }) => <span className="text-xs text-muted-foreground">{row.original.contactName || '—'}</span> },
|
|
205
|
-
{ accessorKey: 'status', header: '', cell: ({ row }) => <StatusDot status={row.original.status} palette={QUOTE_STATUS} /> },
|
|
206
|
-
{ accessorKey: 'totalAmount', header: '', cell: ({ row }) => <span className="font-semibold">{formatCurrency(row.original.totalAmount, currency)}</span> },
|
|
207
|
-
]
|
|
208
|
-
return <TableWidget title={t('crm.dashboard.recentQuotes')} icon="FileText" columns={columns} data={quotes.slice(0, 5)} emptyMessage={t('crm.dashboard.noQuotesYet')} />
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// ---------------------------------------------------------------------------
|
|
212
|
-
// Registry builder — wraps each widget in CrmContextProvider so it renders on
|
|
213
|
-
// both the global home (no CRM page around it) and the CRM plugin-home.
|
|
214
|
-
// ---------------------------------------------------------------------------
|
|
215
|
-
|
|
216
|
-
export function createCrmDashboardWidgets(ctx: {
|
|
217
|
-
config: ResolvedCrmConfig
|
|
218
|
-
provider: CrmDataProvider
|
|
219
|
-
store: StoreApi<CrmUIState>
|
|
220
|
-
}): DashboardWidgetDef[] {
|
|
221
|
-
const withCtx = (Inner: React.ComponentType): React.ComponentType<unknown> => {
|
|
222
|
-
const Wrapped = () => (
|
|
223
|
-
<CrmContextProvider config={ctx.config} provider={ctx.provider} store={ctx.store}>
|
|
224
|
-
<Inner />
|
|
225
|
-
</CrmContextProvider>
|
|
226
|
-
)
|
|
227
|
-
Wrapped.displayName = `CrmWidget(${Inner.displayName ?? Inner.name})`
|
|
228
|
-
return Wrapped
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return [
|
|
232
|
-
// Open pipeline is CRM's headline KPI — visible on the global home by
|
|
233
|
-
// default. The rest are hidden on the home (defaultVisible:false) but show
|
|
234
|
-
// on the CRM plugin-home and can be added to the home via Customize.
|
|
235
|
-
defineKpiWidget({ id: 'crm.kpi.open-pipeline', title: 'crm.dashboard.openPipeline', domain: 'crm', defaultOrder: 1, component: withCtx(OpenPipelineKpi) }),
|
|
236
|
-
defineKpiWidget({ id: 'crm.kpi.total-leads', title: 'crm.dashboard.totalLeads', domain: 'crm', defaultOrder: 0, defaultVisible: false, component: withCtx(TotalLeadsKpi) }),
|
|
237
|
-
defineKpiWidget({ id: 'crm.kpi.conversion-rate', title: 'crm.dashboard.conversionRate', domain: 'crm', defaultOrder: 2, defaultVisible: false, component: withCtx(ConversionRateKpi) }),
|
|
238
|
-
defineKpiWidget({ id: 'crm.kpi.pending-tasks', title: 'crm.dashboard.pendingTasks', domain: 'crm', defaultOrder: 3, defaultVisible: false, component: withCtx(PendingTasksKpi) }),
|
|
239
|
-
// Charts/tables are richer — default them to the CRM plugin-home only, so
|
|
240
|
-
// the global app home stays a clean cross-domain KPI overview. Users can
|
|
241
|
-
// still surface them via the Customize menu / app layout.
|
|
242
|
-
defineChartWidget({ id: 'crm.chart.funnel', title: 'crm.dashboard.pipelineOverview', domain: 'crm', span: 2, defaultOrder: 10, surfaces: ['plugin-home'], component: withCtx(SalesFunnelChart) }),
|
|
243
|
-
defineCustomWidget({ id: 'crm.panel.performance', title: 'crm.dashboard.performance', domain: 'crm', span: 2, defaultOrder: 11, surfaces: ['plugin-home'], component: withCtx(PerformancePanel) }),
|
|
244
|
-
defineChartWidget({ id: 'crm.chart.pipeline-value', title: 'crm.dashboard.pipelineValue', domain: 'crm', span: 4, defaultOrder: 12, surfaces: ['plugin-home'], component: withCtx(PipelineValueChart) }),
|
|
245
|
-
defineTableWidget({ id: 'crm.table.recent-leads', title: 'crm.dashboard.recentLeads', domain: 'crm', span: 2, defaultOrder: 20, surfaces: ['plugin-home'], component: withCtx(RecentLeadsTable) }),
|
|
246
|
-
defineTableWidget({ id: 'crm.table.recent-quotes', title: 'crm.dashboard.recentQuotes', domain: 'crm', span: 2, defaultOrder: 21, surfaces: ['plugin-home'], component: withCtx(RecentQuotesTable) }),
|
|
247
|
-
]
|
|
248
|
-
}
|
|
File without changes
|