@fayz-ai/plugin-crm 0.9.0 → 0.9.2

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.
Files changed (122) hide show
  1. package/README.md +3 -3
  2. package/dist/components/AutomationBolt.d.ts +22 -0
  3. package/dist/components/AutomationBolt.d.ts.map +1 -0
  4. package/dist/{CrmContext.d.ts → context.d.ts} +4 -2
  5. package/dist/context.d.ts.map +1 -0
  6. package/dist/data/mock.d.ts.map +1 -1
  7. package/dist/data/registries.d.ts.map +1 -0
  8. package/dist/data/types.d.ts +4 -1
  9. package/dist/data/types.d.ts.map +1 -1
  10. package/dist/index.d.ts +16 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +609 -493
  13. package/dist/index.js.map +1 -1
  14. package/dist/{cascade.d.ts → lib/cascade.d.ts} +1 -1
  15. package/dist/lib/cascade.d.ts.map +1 -0
  16. package/dist/lib/message-events.d.ts +13 -0
  17. package/dist/lib/message-events.d.ts.map +1 -0
  18. package/dist/lib/timeline-source.d.ts +10 -0
  19. package/dist/lib/timeline-source.d.ts.map +1 -0
  20. package/dist/locales/en.d.ts.map +1 -1
  21. package/dist/locales/pt-BR.d.ts.map +1 -1
  22. package/dist/public/context.d.ts +1 -1
  23. package/dist/public/context.d.ts.map +1 -1
  24. package/dist/public/createPublicFormsPlugin.d.ts +1 -1
  25. package/dist/public/createPublicFormsPlugin.d.ts.map +1 -1
  26. package/dist/public/{data.supabase.d.ts → data/supabase.d.ts} +2 -2
  27. package/dist/public/data/supabase.d.ts.map +1 -0
  28. package/dist/public/index.d.ts +6 -6
  29. package/dist/public/index.d.ts.map +1 -1
  30. package/dist/public/index.js +2 -2
  31. package/dist/public/index.js.map +1 -1
  32. package/dist/public/{inbox.d.ts → lib/inbox.d.ts} +1 -1
  33. package/dist/public/lib/inbox.d.ts.map +1 -0
  34. package/dist/public/{uploads.d.ts → lib/uploads.d.ts} +1 -1
  35. package/dist/public/lib/uploads.d.ts.map +1 -0
  36. package/dist/store.d.ts +9 -0
  37. package/dist/store.d.ts.map +1 -1
  38. package/dist/views/ActivityListView.d.ts.map +1 -1
  39. package/dist/{CrmPage.d.ts → views/CrmPage.d.ts} +3 -3
  40. package/dist/views/CrmPage.d.ts.map +1 -0
  41. package/dist/views/DealSidebar.d.ts.map +1 -1
  42. package/dist/views/LeadListView.d.ts.map +1 -1
  43. package/dist/views/PipelineView.d.ts +3 -1
  44. package/dist/views/PipelineView.d.ts.map +1 -1
  45. package/dist/views/QuoteDetailView.d.ts.map +1 -1
  46. package/dist/views/QuoteFormView.d.ts.map +1 -1
  47. package/dist/views/QuoteListView.d.ts.map +1 -1
  48. package/dist/views/dashboardWidgets.d.ts +1 -1
  49. package/dist/views/dashboardWidgets.d.ts.map +1 -1
  50. package/package.json +6 -10
  51. package/dist/CrmContext.d.ts.map +0 -1
  52. package/dist/CrmPage.d.ts.map +0 -1
  53. package/dist/cascade.d.ts.map +0 -1
  54. package/dist/public/data.supabase.d.ts.map +0 -1
  55. package/dist/public/inbox.d.ts.map +0 -1
  56. package/dist/public/uploads.d.ts.map +0 -1
  57. package/dist/registries.d.ts.map +0 -1
  58. package/src/CrmContext.tsx +0 -30
  59. package/src/CrmPage.tsx +0 -150
  60. package/src/README.md +0 -97
  61. package/src/cascade.ts +0 -26
  62. package/src/components/BoardFilters.tsx +0 -190
  63. package/src/components/CrmGeneralSettings.tsx +0 -56
  64. package/src/components/CrmOnboarding.tsx +0 -52
  65. package/src/components/LeadAttachments.tsx +0 -140
  66. package/src/components/PipelineSettings.tsx +0 -45
  67. package/src/components/QuoteStatusDropdown.tsx +0 -226
  68. package/src/components/TagChips.tsx +0 -80
  69. package/src/data/index.ts +0 -2
  70. package/src/data/mock.ts +0 -559
  71. package/src/data/supabase.ts +0 -928
  72. package/src/data/tables.ts +0 -11
  73. package/src/data/types.ts +0 -61
  74. package/src/index.ts +0 -429
  75. package/src/lib/access.ts +0 -11
  76. package/src/lib/form-answers.tsx +0 -80
  77. package/src/lib/relative-time.ts +0 -84
  78. package/src/lib/tenant.ts +0 -4
  79. package/src/locales/en.ts +0 -307
  80. package/src/locales/index.ts +0 -7
  81. package/src/locales/pt-BR.ts +0 -307
  82. package/src/migrations/000_plg_rename.sql +0 -28
  83. package/src/migrations/001_crm_base.sql +0 -73
  84. package/src/migrations/002_activities.sql +0 -33
  85. package/src/migrations/003_crm_views_rls.sql +0 -69
  86. package/src/migrations/004_seed_default_pipeline.sql +0 -31
  87. package/src/migrations/005_public_lead.sql +0 -189
  88. package/src/migrations/006_lead_enters_pipeline.sql +0 -265
  89. package/src/migrations/007_activity_log.sql +0 -55
  90. package/src/migrations/008_view_field_aliases.sql +0 -43
  91. package/src/migrations/009_deal_archived_status.sql +0 -30
  92. package/src/migrations/010_quote_archived_status.sql +0 -40
  93. package/src/migrations/011_agent_rpc_update_lead.sql +0 -153
  94. package/src/migrations/012_agent_rpc_create_lead.sql +0 -128
  95. package/src/migrations/013_tag_slugs.sql +0 -177
  96. package/src/migrations/014_public_lead_tags.sql +0 -172
  97. package/src/migrations/015_lead_attachments.sql +0 -357
  98. package/src/migrations/016_public_lead_activity.sql +0 -123
  99. package/src/migrations/index.ts +0 -2023
  100. package/src/public/context.tsx +0 -150
  101. package/src/public/createPublicFormsPlugin.ts +0 -282
  102. package/src/public/data.supabase.ts +0 -92
  103. package/src/public/inbox.ts +0 -143
  104. package/src/public/index.ts +0 -51
  105. package/src/public/types.ts +0 -173
  106. package/src/public/uploads.ts +0 -205
  107. package/src/registries.ts +0 -162
  108. package/src/schema/index.ts +0 -104
  109. package/src/store.ts +0 -472
  110. package/src/types.ts +0 -337
  111. package/src/views/ActivityListView.tsx +0 -264
  112. package/src/views/DashboardView.tsx +0 -12
  113. package/src/views/DealSidebar.tsx +0 -482
  114. package/src/views/LeadDetailView.tsx +0 -378
  115. package/src/views/LeadFormView.tsx +0 -66
  116. package/src/views/LeadListView.tsx +0 -100
  117. package/src/views/PipelineView.tsx +0 -446
  118. package/src/views/QuoteDetailView.tsx +0 -412
  119. package/src/views/QuoteFormView.tsx +0 -494
  120. package/src/views/QuoteListView.tsx +0 -115
  121. package/src/views/dashboardWidgets.tsx +0 -248
  122. /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