@fayz-ai/plugin-crm 0.9.0-next.1 → 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.
Files changed (117) 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/registries.d.ts.map +1 -0
  7. package/dist/index.d.ts +16 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +573 -488
  10. package/dist/index.js.map +1 -1
  11. package/dist/{cascade.d.ts → lib/cascade.d.ts} +1 -1
  12. package/dist/lib/cascade.d.ts.map +1 -0
  13. package/dist/lib/message-events.d.ts +13 -0
  14. package/dist/lib/message-events.d.ts.map +1 -0
  15. package/dist/locales/en.d.ts.map +1 -1
  16. package/dist/locales/pt-BR.d.ts.map +1 -1
  17. package/dist/public/context.d.ts +1 -1
  18. package/dist/public/context.d.ts.map +1 -1
  19. package/dist/public/createPublicFormsPlugin.d.ts +1 -1
  20. package/dist/public/createPublicFormsPlugin.d.ts.map +1 -1
  21. package/dist/public/{data.supabase.d.ts → data/supabase.d.ts} +2 -2
  22. package/dist/public/data/supabase.d.ts.map +1 -0
  23. package/dist/public/index.d.ts +6 -6
  24. package/dist/public/index.d.ts.map +1 -1
  25. package/dist/public/index.js +2 -2
  26. package/dist/public/index.js.map +1 -1
  27. package/dist/public/{inbox.d.ts → lib/inbox.d.ts} +1 -1
  28. package/dist/public/lib/inbox.d.ts.map +1 -0
  29. package/dist/public/{uploads.d.ts → lib/uploads.d.ts} +1 -1
  30. package/dist/public/lib/uploads.d.ts.map +1 -0
  31. package/dist/store.d.ts +9 -0
  32. package/dist/store.d.ts.map +1 -1
  33. package/dist/views/ActivityListView.d.ts.map +1 -1
  34. package/dist/{CrmPage.d.ts → views/CrmPage.d.ts} +3 -3
  35. package/dist/views/CrmPage.d.ts.map +1 -0
  36. package/dist/views/DealSidebar.d.ts.map +1 -1
  37. package/dist/views/LeadListView.d.ts.map +1 -1
  38. package/dist/views/PipelineView.d.ts +3 -1
  39. package/dist/views/PipelineView.d.ts.map +1 -1
  40. package/dist/views/QuoteDetailView.d.ts.map +1 -1
  41. package/dist/views/QuoteFormView.d.ts.map +1 -1
  42. package/dist/views/QuoteListView.d.ts.map +1 -1
  43. package/dist/views/dashboardWidgets.d.ts +1 -1
  44. package/dist/views/dashboardWidgets.d.ts.map +1 -1
  45. package/package.json +6 -10
  46. package/dist/CrmContext.d.ts.map +0 -1
  47. package/dist/CrmPage.d.ts.map +0 -1
  48. package/dist/cascade.d.ts.map +0 -1
  49. package/dist/public/data.supabase.d.ts.map +0 -1
  50. package/dist/public/inbox.d.ts.map +0 -1
  51. package/dist/public/uploads.d.ts.map +0 -1
  52. package/dist/registries.d.ts.map +0 -1
  53. package/src/CrmContext.tsx +0 -30
  54. package/src/CrmPage.tsx +0 -150
  55. package/src/README.md +0 -97
  56. package/src/cascade.ts +0 -26
  57. package/src/components/BoardFilters.tsx +0 -190
  58. package/src/components/CrmGeneralSettings.tsx +0 -56
  59. package/src/components/CrmOnboarding.tsx +0 -52
  60. package/src/components/LeadAttachments.tsx +0 -140
  61. package/src/components/PipelineSettings.tsx +0 -45
  62. package/src/components/QuoteStatusDropdown.tsx +0 -226
  63. package/src/components/TagChips.tsx +0 -80
  64. package/src/data/index.ts +0 -2
  65. package/src/data/mock.ts +0 -559
  66. package/src/data/supabase.ts +0 -928
  67. package/src/data/tables.ts +0 -11
  68. package/src/data/types.ts +0 -61
  69. package/src/index.ts +0 -429
  70. package/src/lib/access.ts +0 -11
  71. package/src/lib/form-answers.tsx +0 -80
  72. package/src/lib/relative-time.ts +0 -84
  73. package/src/lib/tenant.ts +0 -4
  74. package/src/locales/en.ts +0 -307
  75. package/src/locales/index.ts +0 -7
  76. package/src/locales/pt-BR.ts +0 -307
  77. package/src/migrations/000_plg_rename.sql +0 -28
  78. package/src/migrations/001_crm_base.sql +0 -73
  79. package/src/migrations/002_activities.sql +0 -33
  80. package/src/migrations/003_crm_views_rls.sql +0 -69
  81. package/src/migrations/004_seed_default_pipeline.sql +0 -31
  82. package/src/migrations/005_public_lead.sql +0 -189
  83. package/src/migrations/006_lead_enters_pipeline.sql +0 -265
  84. package/src/migrations/007_activity_log.sql +0 -55
  85. package/src/migrations/008_view_field_aliases.sql +0 -43
  86. package/src/migrations/009_deal_archived_status.sql +0 -30
  87. package/src/migrations/010_quote_archived_status.sql +0 -40
  88. package/src/migrations/011_agent_rpc_update_lead.sql +0 -153
  89. package/src/migrations/012_agent_rpc_create_lead.sql +0 -128
  90. package/src/migrations/013_tag_slugs.sql +0 -177
  91. package/src/migrations/014_public_lead_tags.sql +0 -172
  92. package/src/migrations/015_lead_attachments.sql +0 -357
  93. package/src/migrations/016_public_lead_activity.sql +0 -123
  94. package/src/migrations/index.ts +0 -2023
  95. package/src/public/context.tsx +0 -150
  96. package/src/public/createPublicFormsPlugin.ts +0 -282
  97. package/src/public/data.supabase.ts +0 -92
  98. package/src/public/inbox.ts +0 -143
  99. package/src/public/index.ts +0 -51
  100. package/src/public/types.ts +0 -173
  101. package/src/public/uploads.ts +0 -205
  102. package/src/registries.ts +0 -162
  103. package/src/schema/index.ts +0 -104
  104. package/src/store.ts +0 -472
  105. package/src/types.ts +0 -337
  106. package/src/views/ActivityListView.tsx +0 -264
  107. package/src/views/DashboardView.tsx +0 -12
  108. package/src/views/DealSidebar.tsx +0 -482
  109. package/src/views/LeadDetailView.tsx +0 -378
  110. package/src/views/LeadFormView.tsx +0 -66
  111. package/src/views/LeadListView.tsx +0 -100
  112. package/src/views/PipelineView.tsx +0 -446
  113. package/src/views/QuoteDetailView.tsx +0 -412
  114. package/src/views/QuoteFormView.tsx +0 -494
  115. package/src/views/QuoteListView.tsx +0 -115
  116. package/src/views/dashboardWidgets.tsx +0 -248
  117. /package/dist/{registries.d.ts → data/registries.d.ts} +0 -0
@@ -1,378 +0,0 @@
1
- import React, { useEffect, useState } from 'react'
2
- import { UserPlus, FileText, Archive } from 'lucide-react'
3
- import { useCrmProvider, useCrmConfig, formatCurrency, useCrmStore } from '../CrmContext'
4
- import { useCanArchive } from '../lib/access'
5
- import { useTranslation } from '@fayz-ai/core'
6
- import { QuoteStatusDropdown } from '../components/QuoteStatusDropdown'
7
- import { LeadAttachments } from '../components/LeadAttachments'
8
- import { leadAttachments } from '../lib/form-answers'
9
- import { formatDateTime, formatRelativeTime } from '../lib/relative-time'
10
- import { Breadcrumb, PhoneLink } from '@fayz-ai/ui'
11
- import type { Lead, Deal, Quote } from '../types'
12
-
13
- const STATUS_COLORS: Record<string, string> = {
14
- new: 'bg-info-soft text-info-soft-foreground',
15
- contacted: 'bg-magic-soft text-magic-soft-foreground',
16
- qualified: 'bg-success-soft text-success-soft-foreground',
17
- unqualified: 'bg-muted text-muted-foreground',
18
- converted: 'bg-warning-soft text-warning-soft-foreground',
19
- lost: 'bg-destructive-soft text-destructive-soft-foreground',
20
- }
21
-
22
-
23
- /** "hair_remaining" → "Hair remaining". Form answers arrive keyed by whatever
24
- * the landing page called them, so they get humanized rather than shown raw. */
25
- function humanizeKey(key: string): string {
26
- const spaced = key.replace(/[_-]+/g, ' ').replace(/([a-z\d])([A-Z])/g, '$1 $2')
27
- return spaced.charAt(0).toUpperCase() + spaced.slice(1)
28
- }
29
-
30
- function renderFieldValue(value: unknown): React.ReactNode {
31
- if (value === null || value === undefined || value === '') return null
32
- if (Array.isArray(value)) return value.length ? value.join(', ') : null
33
- if (typeof value === 'boolean') return value ? 'Sim' : 'Não'
34
- if (typeof value === 'object') return JSON.stringify(value)
35
- return String(value)
36
- }
37
-
38
- function FieldRow({ label, value }: { label: string; value: React.ReactNode }) {
39
- return (
40
- <div className="grid grid-cols-3 gap-4 py-3">
41
- <dt className="text-sm font-medium text-muted-foreground">{label}</dt>
42
- <dd className="col-span-2 text-sm text-foreground">{value ?? <span className="text-muted-foreground/50">—</span>}</dd>
43
- </div>
44
- )
45
- }
46
-
47
- export function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }: {
48
- leadId: string
49
- onBack: () => void
50
- onCreateQuote?: (leadId: string) => void
51
- onViewQuote?: (quoteId: string) => void
52
- }) {
53
- const provider = useCrmProvider()
54
- const { currency } = useCrmConfig()
55
- // Mesmo idioma do dinheiro: quem configurou pt-BR para o valor não quer
56
- // "2 days ago" na data ao lado.
57
- const locale = currency.locale
58
- const t = useTranslation()
59
- const archiveLead = useCrmStore((s) => s.archiveLead)
60
- const canArchive = useCanArchive()
61
- const [archiving, setArchiving] = useState(false)
62
- const [lead, setLead] = useState<Lead | null>(null)
63
- const [deal, setDeal] = useState<Deal | null>(null)
64
- const [quotes, setQuotes] = useState<Quote[]>([])
65
- const [loading, setLoading] = useState(true)
66
-
67
- useEffect(() => {
68
- setLoading(true)
69
- provider.getLeadById(leadId).then(async (l) => {
70
- setLead(l)
71
- if (l) {
72
- const d = await provider.getDealByLeadId(leadId)
73
- setDeal(d)
74
- if (d) {
75
- const q = await provider.getQuotesByDealId(d.id)
76
- setQuotes(q)
77
- }
78
- }
79
- setLoading(false)
80
- })
81
- }, [leadId])
82
-
83
- if (loading) {
84
- return (
85
- <div className="space-y-6">
86
- <Breadcrumb parent={t('crm.leads.title')} current={t('crm.leadDetail.loading')} onBack={onBack} />
87
- <div className="flex items-start gap-5">
88
- <div className="h-20 w-20 shrink-0 rounded-2xl bg-muted/40 animate-pulse" />
89
- <div className="flex-1 space-y-2 pt-1">
90
- <div className="h-6 w-40 rounded bg-muted/40 animate-pulse" />
91
- <div className="h-4 w-28 rounded bg-muted/30 animate-pulse" />
92
- <div className="h-5 w-16 rounded-full bg-muted/30 animate-pulse" />
93
- </div>
94
- </div>
95
- <div className="border-t" />
96
- <div className="space-y-4">
97
- <div className="h-4 w-36 rounded bg-muted/30 animate-pulse" />
98
- <div className="rounded-xl border bg-card shadow-sm p-5 space-y-3">
99
- {[1, 2, 3, 4].map((i) => (
100
- <div key={i} className="grid grid-cols-3 gap-4">
101
- <div className="h-3 w-16 rounded bg-muted/30 animate-pulse" />
102
- <div className="col-span-2 h-3 w-24 rounded bg-muted/40 animate-pulse" />
103
- </div>
104
- ))}
105
- </div>
106
- </div>
107
- </div>
108
- )
109
- }
110
-
111
- if (!lead) {
112
- return (
113
- <div className="space-y-6">
114
- <Breadcrumb parent={t('crm.leads.title')} current={t('crm.leadDetail.notFound')} onBack={onBack} />
115
- <div className="flex flex-col items-center justify-center py-12 text-center rounded-lg border-2 border-dashed border-muted">
116
- <UserPlus className="h-8 w-8 text-muted-foreground/30 mb-2" />
117
- <p className="text-sm text-muted-foreground">{t('crm.leadDetail.leadNotFound')}</p>
118
- <button onClick={onBack} className="text-xs text-primary hover:underline mt-1">{t('crm.leadDetail.backToList')}</button>
119
- </div>
120
- </div>
121
- )
122
- }
123
-
124
- const initial = lead.name.charAt(0).toUpperCase()
125
-
126
- return (
127
- <div className="space-y-6">
128
- {/* Breadcrumb */}
129
- <Breadcrumb parent={t('crm.leads.title')} current={lead.name} onBack={onBack} />
130
-
131
- {/* Hero */}
132
- <div className="flex items-start gap-5">
133
- <div className="flex h-20 w-20 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary text-2xl font-bold shadow-sm">
134
- {initial}
135
- </div>
136
- <div className="flex-1 min-w-0">
137
- <h1 className="text-2xl font-bold text-foreground truncate">{lead.name}</h1>
138
- {(lead.email || lead.phone) && (
139
- <p className="text-muted-foreground mt-0.5">{lead.email || lead.phone}</p>
140
- )}
141
- <div className="flex items-center gap-2 mt-2">
142
- <span className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-[10px] font-medium capitalize ${STATUS_COLORS[lead.status] ?? 'bg-muted text-muted-foreground'}`}>
143
- {lead.status}
144
- </span>
145
- {lead.sourceName && (
146
- <span className="inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-medium text-muted-foreground">
147
- {lead.sourceName}
148
- </span>
149
- )}
150
- </div>
151
- </div>
152
- {/* Actions */}
153
- <div className="flex items-center gap-2 shrink-0">
154
- {canArchive && (
155
- <button
156
- onClick={() => {
157
- setArchiving(true)
158
- archiveLead(leadId).then(onBack).catch(() => setArchiving(false))
159
- }}
160
- disabled={archiving}
161
- title={t('crm.leadDetail.archive')}
162
- className="inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground bg-card shadow-button active:shadow-button-inset transition-colors disabled:opacity-60"
163
- >
164
- <Archive className="h-3 w-3" /> {t('crm.leadDetail.archive')}
165
- </button>
166
- )}
167
- {onCreateQuote && lead.status !== 'converted' && lead.status !== 'lost' && (
168
- <button
169
- onClick={() => onCreateQuote(leadId)}
170
- className="inline-flex items-center gap-1.5 rounded-lg bg-primary border border-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 shadow-button-primary active:shadow-button-inset transition-colors"
171
- >
172
- <FileText className="h-3 w-3" /> {t('crm.leadDetail.createQuote')}
173
- </button>
174
- )}
175
- </div>
176
- </div>
177
-
178
- {/* Separator */}
179
- <div className="border-t" />
180
-
181
- {/* Contact Information */}
182
- <div>
183
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.contactInfo')}</h3>
184
- <div className="rounded-xl border bg-card shadow-sm">
185
- <dl className="grid divide-y md:grid-cols-2 md:divide-y-0">
186
- <div className="px-5 md:border-b">
187
- <FieldRow label={t('crm.leadDetail.email')} value={lead.email ? <a href={`mailto:${lead.email}`} className="text-primary hover:underline">{lead.email}</a> : null} />
188
- </div>
189
- <div className="px-5 md:border-b">
190
- <FieldRow
191
- label={t('crm.leadDetail.phone')}
192
- value={lead.phone ? <PhoneLink phone={lead.phone} className="text-primary" /> : null}
193
- />
194
- </div>
195
- <div className="px-5 md:border-b md:last:border-b-0">
196
- <FieldRow label={t('crm.leadDetail.company')} value={lead.company} />
197
- </div>
198
- <div className="px-5 md:border-b md:last:border-b-0">
199
- <FieldRow label={t('crm.leadDetail.source')} value={lead.sourceName} />
200
- </div>
201
- </dl>
202
- </div>
203
- </div>
204
-
205
- {/* Form answers — whatever the landing page asked. Rendered generically
206
- so a new form never needs a change here. */}
207
- {(() => {
208
- const meta = (lead.metadata ?? {}) as {
209
- fields?: Record<string, unknown>
210
- utm?: Record<string, unknown>
211
- }
212
- const fields = Object.entries(meta.fields ?? {}).filter(([, v]) => renderFieldValue(v) !== null)
213
- const utm = Object.entries(meta.utm ?? {}).filter(([, v]) => renderFieldValue(v) !== null)
214
- const attachments = leadAttachments(lead.metadata)
215
- if (!fields.length && !utm.length && !attachments.length) return null
216
- return (
217
- <div>
218
- <h3 className="text-sm font-semibold text-foreground mb-1">
219
- {t('crm.leadDetail.formAnswers')}
220
- </h3>
221
- <div className="rounded-xl border bg-card shadow-sm">
222
- <dl className="grid divide-y md:grid-cols-2 md:divide-y-0">
223
- {fields.map(([key, value]) => (
224
- <div key={key} className="px-5 md:border-b md:last:border-b-0">
225
- <FieldRow label={humanizeKey(key)} value={renderFieldValue(value)} />
226
- </div>
227
- ))}
228
- </dl>
229
- {attachments.length > 0 && (
230
- <div className="border-t px-5 py-3">
231
- <LeadAttachments attachments={attachments} />
232
- </div>
233
- )}
234
- {utm.length > 0 && (
235
- <div className="border-t px-5 py-3 flex flex-wrap gap-x-4 gap-y-1">
236
- {utm.map(([key, value]) => (
237
- <span key={key} className="text-xs text-muted-foreground">
238
- {humanizeKey(key.replace(/^utm_/, ''))}:{' '}
239
- <span className="text-foreground">{renderFieldValue(value)}</span>
240
- </span>
241
- ))}
242
- </div>
243
- )}
244
- </div>
245
- </div>
246
- )
247
- })()}
248
-
249
- {/* Pipeline / Deal */}
250
- {deal && (
251
- <div>
252
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.pipeline')}</h3>
253
- <div className="rounded-xl border bg-card shadow-sm">
254
- <dl className="grid divide-y md:grid-cols-2 md:divide-y-0">
255
- <div className="px-5 md:border-b">
256
- <FieldRow label={t('crm.leadDetail.stage')} value={deal.stageName ? (
257
- <span className="inline-flex items-center gap-1.5">
258
- {deal.stageColor && <span className="h-2 w-2 rounded-full" style={{ backgroundColor: deal.stageColor }} />}
259
- {deal.stageName}
260
- </span>
261
- ) : null} />
262
- </div>
263
- <div className="px-5 md:border-b">
264
- <FieldRow label={t('crm.leadDetail.dealValue')} value={deal.value > 0 ? formatCurrency(deal.value, currency) : null} />
265
- </div>
266
- <div className="px-5 md:border-b md:last:border-b-0">
267
- <FieldRow label={t('crm.leadDetail.probability')} value={`${deal.probability}%`} />
268
- </div>
269
- <div className="px-5 md:border-b md:last:border-b-0">
270
- <FieldRow label={t('crm.leadDetail.dealStatus')} value={deal.status} />
271
- </div>
272
- </dl>
273
- </div>
274
- </div>
275
- )}
276
-
277
- {/* Quotes */}
278
- {quotes.length > 0 && (
279
- <div>
280
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.quotes')}</h3>
281
- <div className="rounded-xl border bg-card shadow-sm divide-y">
282
- {quotes.map((q) => (
283
- <div
284
- key={q.id}
285
- onClick={() => onViewQuote?.(q.id)}
286
- className="flex items-center justify-between px-5 py-3 hover:bg-muted/20 transition-colors cursor-pointer"
287
- >
288
- <div className="flex items-center gap-3 min-w-0">
289
- <FileText className="h-4 w-4 text-muted-foreground shrink-0" />
290
- <div className="min-w-0">
291
- <p className="text-sm font-medium">{q.quoteNumber}</p>
292
- <p className="text-[10px] text-muted-foreground">{q.quoteDate}</p>
293
- </div>
294
- </div>
295
- <div className="flex items-center gap-3 shrink-0" onClick={(e) => e.stopPropagation()}>
296
- <span className="text-sm font-semibold">{formatCurrency(q.totalAmount, currency)}</span>
297
- <QuoteStatusDropdown quote={q} size="sm" onStatusChange={(updated) => setQuotes(quotes.map((existing) => existing.id === updated.id ? updated : existing))} />
298
- </div>
299
- </div>
300
- ))}
301
- </div>
302
- </div>
303
- )}
304
-
305
- {/* Details */}
306
- <div>
307
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.details')}</h3>
308
- <div className="rounded-xl border bg-card shadow-sm">
309
- <dl className="grid divide-y md:grid-cols-2 md:divide-y-0">
310
- <div className="px-5 md:border-b">
311
- <FieldRow label={t('crm.leadDetail.value')} value={lead.value != null && lead.value > 0 ? lead.value : null} />
312
- </div>
313
- <div className="px-5 md:border-b">
314
- <FieldRow label={t('crm.leadDetail.assignedTo')} value={lead.assignedToName} />
315
- </div>
316
- {/* Data e hora completas, com a idade ao lado. `slice(0,10)` mostrava
317
- só o dia — e num lead que chegou hoje de manhã, saber se foi às
318
- 8h ou às 18h é o que decide se ainda dá para ligar hoje. */}
319
- <div className="px-5 md:border-b md:last:border-b-0">
320
- <FieldRow
321
- label={t('crm.leadDetail.created')}
322
- value={
323
- lead.createdAt ? (
324
- <span className="inline-flex flex-wrap items-baseline gap-x-1.5">
325
- <span>{formatDateTime(lead.createdAt, locale)}</span>
326
- <span className="text-xs text-muted-foreground">
327
- ({formatRelativeTime(lead.createdAt, locale)})
328
- </span>
329
- </span>
330
- ) : null
331
- }
332
- />
333
- </div>
334
- <div className="px-5 md:border-b md:last:border-b-0">
335
- <FieldRow
336
- label={t('crm.leadDetail.updated')}
337
- value={
338
- lead.updatedAt ? (
339
- <span className="inline-flex flex-wrap items-baseline gap-x-1.5">
340
- <span>{formatDateTime(lead.updatedAt, locale)}</span>
341
- <span className="text-xs text-muted-foreground">
342
- ({formatRelativeTime(lead.updatedAt, locale)})
343
- </span>
344
- </span>
345
- ) : null
346
- }
347
- />
348
- </div>
349
- </dl>
350
- </div>
351
- </div>
352
-
353
- {/* Tags */}
354
- {lead.tags && lead.tags.length > 0 && (
355
- <div>
356
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.tags')}</h3>
357
- <div className="rounded-xl border bg-card shadow-sm px-5 py-4">
358
- <div className="flex gap-1.5 flex-wrap">
359
- {lead.tags.map((tag) => (
360
- <span key={tag} className="inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-medium text-muted-foreground">{tag}</span>
361
- ))}
362
- </div>
363
- </div>
364
- </div>
365
- )}
366
-
367
- {/* Notes */}
368
- {lead.notes && (
369
- <div>
370
- <h3 className="text-sm font-semibold text-foreground mb-1">{t('crm.leadDetail.notes')}</h3>
371
- <div className="rounded-xl border bg-card shadow-sm px-5 py-4">
372
- <p className="text-sm text-muted-foreground whitespace-pre-wrap">{lead.notes}</p>
373
- </div>
374
- </div>
375
- )}
376
- </div>
377
- )
378
- }
@@ -1,66 +0,0 @@
1
- import React, { useState, useEffect } from 'react'
2
- import { useCrmStore } from '../CrmContext'
3
- import { useTranslation } from '@fayz-ai/core'
4
- import { useLimitGuard, invalidateLimit } from '@fayz-ai/saas'
5
- import { SubpageHeader, useSaveBar, toast } from '@fayz-ai/ui'
6
-
7
- export function LeadFormView({ onSaved }: { onSaved?: (id?: string) => void }) {
8
- const t = useTranslation()
9
- const createLead = useCrmStore((s) => s.createLead)
10
- // Creating a lead also auto-creates a deal (store.createLead), so this path is
11
- // the create surface for both the pipeline board ("+ Add") and the lead form.
12
- const guardLeads = useLimitGuard('leads')
13
- const fetchPipelines = useCrmStore((s) => s.fetchPipelines)
14
- const pipelines = useCrmStore((s) => s.pipelines)
15
-
16
- // Ensure pipelines are loaded so createLead can auto-create a deal
17
- useEffect(() => { if (pipelines.length === 0) fetchPipelines() }, [])
18
-
19
- const [name, setName] = useState('')
20
- const [email, setEmail] = useState('')
21
- const [phone, setPhone] = useState('')
22
- const [company, setCompany] = useState('')
23
- const [notes, setNotes] = useState('')
24
- const [saving, setSaving] = useState(false)
25
-
26
- async function handleSave() {
27
- if (!name.trim()) { toast.error(t('common.formIncomplete')); return }
28
- // Plan quantity guard (client-side, before the store call): opens the global
29
- // UpgradeModal and aborts when the lead cap is reached.
30
- if ((await guardLeads()) === 'blocked') return
31
- setSaving(true)
32
- try {
33
- const lead = await createLead({ name, email: email || undefined, phone: phone || undefined, company: company || undefined, notes: notes || undefined })
34
- // A lead spawns a deal too — refresh both live counts.
35
- invalidateLimit('leads')
36
- invalidateLimit('deals')
37
- onSaved?.(lead.id)
38
- } finally { setSaving(false) }
39
- }
40
-
41
- const dirty = !!(name || email || phone || company || notes)
42
- useSaveBar({
43
- dirty,
44
- saving,
45
- onSave: () => { void handleSave() },
46
- onDiscard: () => onSaved?.(),
47
- saveLabel: t('crm.leadForm.save'),
48
- })
49
-
50
- return (
51
- <div className="space-y-5">
52
- <SubpageHeader title={t('crm.leadForm.title')} subtitle={t('crm.leadForm.subtitle')} onBack={onSaved} parentLabel={t('crm.leads.title')} />
53
- <div className="rounded-lg border bg-card shadow-sm p-5 space-y-4">
54
- <div className="grid gap-4 sm:grid-cols-2">
55
- <div><label className="text-xs font-medium text-muted-foreground">{t('crm.leadForm.name')}</label><input type="text" value={name} onChange={(e) => setName(e.target.value)} placeholder={t('crm.leadForm.namePlaceholder')} autoFocus className="w-full mt-1 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring" /></div>
56
- <div><label className="text-xs font-medium text-muted-foreground">{t('crm.leadForm.company')}</label><input type="text" value={company} onChange={(e) => setCompany(e.target.value)} placeholder={t('crm.leadForm.companyPlaceholder')} className="w-full mt-1 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring" /></div>
57
- </div>
58
- <div className="grid gap-4 sm:grid-cols-2">
59
- <div><label className="text-xs font-medium text-muted-foreground">{t('crm.leadForm.email')}</label><input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder={t('crm.leadForm.emailPlaceholder')} className="w-full mt-1 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring" /></div>
60
- <div><label className="text-xs font-medium text-muted-foreground">{t('crm.leadForm.phone')}</label><input type="tel" value={phone} onChange={(e) => setPhone(e.target.value)} placeholder={t('crm.leadForm.phonePlaceholder')} className="w-full mt-1 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring" /></div>
61
- </div>
62
- <div><label className="text-xs font-medium text-muted-foreground">{t('crm.leadForm.notes')}</label><textarea value={notes} onChange={(e) => setNotes(e.target.value)} rows={2} placeholder={t('crm.leadForm.notesPlaceholder')} className="w-full mt-1 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring resize-none" /></div>
63
- </div>
64
- </div>
65
- )
66
- }
@@ -1,100 +0,0 @@
1
- import React, { useEffect, useState, useMemo } from 'react'
2
- import { UserPlus } from 'lucide-react'
3
- import type { ColumnDef } from '@tanstack/react-table'
4
- import { ListView } from '@fayz-ai/ui'
5
- import { useCrmStore } from '../CrmContext'
6
- import { useTranslation } from '@fayz-ai/core'
7
- import { SubpageHeader } from '@fayz-ai/ui'
8
- import type { Lead, LeadStatus } from '../types'
9
-
10
- const STATUS_OPTIONS: { value: LeadStatus; label: string; color: string }[] = [
11
- { value: 'new', label: 'New', color: 'bg-info-soft text-info-soft-foreground' },
12
- { value: 'contacted', label: 'Contacted', color: 'bg-magic-soft text-magic-soft-foreground' },
13
- { value: 'qualified', label: 'Qualified', color: 'bg-success-soft text-success-soft-foreground' },
14
- { value: 'unqualified', label: 'Unqualified', color: 'bg-muted text-muted-foreground' },
15
- { value: 'converted', label: 'Converted', color: 'bg-warning-soft text-warning-soft-foreground' },
16
- ]
17
-
18
- const columns: ColumnDef<Lead, any>[] = [
19
- { accessorKey: 'name', header: 'Name', cell: ({ getValue }) => <span className="font-medium">{getValue() as string}</span> },
20
- {
21
- id: 'contact', header: 'Contact',
22
- cell: ({ row }) => <span className="text-muted-foreground text-xs">{row.original.email || row.original.phone || '—'}</span>,
23
- },
24
- {
25
- accessorKey: 'sourceName', header: 'Source',
26
- cell: ({ getValue }) => <span className="text-muted-foreground text-xs">{(getValue() as string) || '—'}</span>,
27
- },
28
- {
29
- accessorKey: 'status', header: 'Status',
30
- cell: ({ getValue }) => {
31
- const status = getValue() as string
32
- const opt = STATUS_OPTIONS.find((o) => o.value === status)
33
- return (
34
- <span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${opt?.color ?? 'bg-muted text-muted-foreground'}`}>
35
- {opt?.label ?? status}
36
- </span>
37
- )
38
- },
39
- },
40
- {
41
- // When the lead came in. The list is already sorted by it (provider orders
42
- // created_at desc) but never showed it, so "is this enquiry from today or
43
- // from March?" was unanswerable without opening the record.
44
- accessorKey: 'createdAt', header: 'Entrada',
45
- cell: ({ getValue }) => {
46
- const raw = getValue() as string | undefined
47
- if (!raw) return <span className="text-muted-foreground text-xs">—</span>
48
- const at = new Date(raw)
49
- if (Number.isNaN(at.getTime())) return <span className="text-muted-foreground text-xs">—</span>
50
- return (
51
- <span className="text-muted-foreground text-xs whitespace-nowrap" title={at.toLocaleString()}>
52
- {at.toLocaleDateString(undefined, { day: '2-digit', month: '2-digit', year: '2-digit' })}
53
- {' · '}
54
- {at.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })}
55
- </span>
56
- )
57
- },
58
- },
59
- ]
60
-
61
- export function LeadListView({ onNew, onEdit }: { onNew?: () => void; onEdit?: (id: string) => void }) {
62
- const t = useTranslation()
63
- const leads = useCrmStore((s) => s.leads)
64
- const leadsLoading = useCrmStore((s) => s.leadsLoading)
65
- const fetchLeads = useCrmStore((s) => s.fetchLeads)
66
- const [search, setSearch] = useState('')
67
- const [statusFilter, setStatusFilter] = useState<LeadStatus[]>([])
68
-
69
- useEffect(() => {
70
- fetchLeads({ status: statusFilter.length > 0 ? statusFilter : undefined, search: search || undefined })
71
- }, [statusFilter, search])
72
-
73
- // Multi-select tag filter: toggle individual statuses
74
- const tags = useMemo(() => STATUS_OPTIONS.map((o) => ({ value: o.value, label: o.label })), [])
75
-
76
- return (
77
- <div className="space-y-4">
78
- <SubpageHeader title={t('crm.leads.title')} subtitle={`${leads.length} leads`} />
79
- <ListView<Lead>
80
- columns={columns}
81
- data={leads}
82
- loading={leadsLoading}
83
- searchPlaceholder={t('crm.leads.searchPlaceholder')}
84
- search={search}
85
- onSearchChange={setSearch}
86
- searchDebounce={0}
87
- tags={tags}
88
- activeTag={statusFilter.length === 1 ? statusFilter[0] : undefined}
89
- onTagChange={(v) => setStatusFilter(v ? [v as LeadStatus] : [])}
90
- newLabel={t('crm.leads.newLead')}
91
- onNew={onNew}
92
- onRowClick={(row) => onEdit?.(row.id)}
93
- emptyIcon={UserPlus}
94
- emptyMessage={t('crm.leads.noLeads')}
95
- emptyActionLabel={onNew ? t('crm.leads.captureFirst') : undefined}
96
- onEmptyAction={onNew}
97
- />
98
- </div>
99
- )
100
- }