@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,482 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import { Phone, Mail, Users, FileText, CheckSquare, MessageCircle, Check, Calendar, DollarSign, User, Target, Clock, ArrowRight, UserPlus, ArrowRightLeft, MoveRight, Trophy, XCircle, FilePlus2, Send, FileCheck2, FileX2, Archive } from 'lucide-react'
|
|
3
|
-
import { useTranslation } from '@fayz-ai/core'
|
|
4
|
-
import { Sheet, SheetContent, SheetHeader, SheetBody, SheetFooter, SheetTitle, SheetDescription, SegmentedControl, PhoneLink, normalizePhone } from '@fayz-ai/ui'
|
|
5
|
-
import { PersonLink } from '@fayz-ai/saas'
|
|
6
|
-
import { useCrmProvider, useCrmConfig, useCrmStore, formatCurrency } from '../CrmContext'
|
|
7
|
-
import { QuoteStatusDropdown } from '../components/QuoteStatusDropdown'
|
|
8
|
-
import { TagChips } from '../components/TagChips'
|
|
9
|
-
import { answerEntries, humanizeKey, leadAttachments, renderFieldValue } from '../lib/form-answers'
|
|
10
|
-
import { LeadAttachments } from '../components/LeadAttachments'
|
|
11
|
-
import { formatDateTime, formatRelativeTime } from '../lib/relative-time'
|
|
12
|
-
import type { Deal, Lead, Quote, Activity } from '../types'
|
|
13
|
-
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// Activity icons
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
const TYPE_ICONS: Record<string, React.ElementType> = {
|
|
19
|
-
call: Phone, email: Mail, meeting: Users, note: FileText, task: CheckSquare, whatsapp: MessageCircle,
|
|
20
|
-
// System timeline events (auto-logged by the provider)
|
|
21
|
-
lead_created: UserPlus, lead_converted: ArrowRightLeft, deal_created: Target,
|
|
22
|
-
stage_changed: MoveRight, deal_won: Trophy, deal_lost: XCircle,
|
|
23
|
-
quote_created: FilePlus2, quote_sent: Send, quote_approved: FileCheck2, quote_rejected: FileX2,
|
|
24
|
-
lead_archived: Archive, deal_archived: Archive, quote_archived: Archive,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// Tabs
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
type TabId = 'overview' | 'activity' | 'quotes'
|
|
33
|
-
|
|
34
|
-
function TabBar({ active, counts, onChange }: { active: TabId; counts: { activity: number; quotes: number }; onChange: (id: TabId) => void }) {
|
|
35
|
-
const t = useTranslation()
|
|
36
|
-
|
|
37
|
-
const label = (text: string, count: number | undefined, isActive: boolean) => (
|
|
38
|
-
<span className="inline-flex items-center gap-1.5">
|
|
39
|
-
{text}
|
|
40
|
-
{count != null && count > 0 && (
|
|
41
|
-
<span className={`inline-flex items-center justify-center min-w-[16px] h-4 rounded-full px-1 text-[10px] font-semibold ${
|
|
42
|
-
isActive ? 'bg-background/20 text-background' : 'bg-muted text-muted-foreground'
|
|
43
|
-
}`}>
|
|
44
|
-
{count}
|
|
45
|
-
</span>
|
|
46
|
-
)}
|
|
47
|
-
</span>
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<div className="px-5 py-2 border-b shrink-0">
|
|
52
|
-
<SegmentedControl<TabId>
|
|
53
|
-
value={active}
|
|
54
|
-
onChange={onChange}
|
|
55
|
-
options={[
|
|
56
|
-
{ value: 'overview', label: label(t('crm.dealSidebar.overview'), undefined, active === 'overview') },
|
|
57
|
-
{ value: 'activity', label: label(t('crm.dealSidebar.activity'), counts.activity, active === 'activity') },
|
|
58
|
-
{ value: 'quotes', label: label(t('crm.dealSidebar.quotes'), counts.quotes, active === 'quotes') },
|
|
59
|
-
]}
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
// Overview tab
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
|
|
69
|
-
/** Whatever the public form captured, in the card. Same opaque-bag rendering
|
|
70
|
-
* the lead detail page uses — shared so the two cannot drift. */
|
|
71
|
-
function FormAnswers({ lead }: { lead: Lead | null }) {
|
|
72
|
-
const t = useTranslation()
|
|
73
|
-
const entries = answerEntries(lead?.metadata?.fields)
|
|
74
|
-
const attachments = leadAttachments(lead?.metadata)
|
|
75
|
-
if (entries.length === 0 && attachments.length === 0) return null
|
|
76
|
-
|
|
77
|
-
const formId = lead?.metadata?.formId
|
|
78
|
-
return (
|
|
79
|
-
<div className="space-y-3">
|
|
80
|
-
{entries.length > 0 && (
|
|
81
|
-
<div className="space-y-2">
|
|
82
|
-
<h4 className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
|
83
|
-
{formId ? `${t('crm.leadDetail.formAnswers')} · ${formId}` : t('crm.leadDetail.formAnswers')}
|
|
84
|
-
</h4>
|
|
85
|
-
<div className="rounded-xl border divide-y">
|
|
86
|
-
{entries.map(([key, value]) => (
|
|
87
|
-
<div key={key} className="flex items-start gap-3 px-4 py-2.5">
|
|
88
|
-
<span className="text-[11px] text-muted-foreground shrink-0 min-w-24">{humanizeKey(key)}</span>
|
|
89
|
-
<span className="text-xs text-right flex-1 break-words">
|
|
90
|
-
{renderFieldValue(value) ?? <span className="text-muted-foreground/50">—</span>}
|
|
91
|
-
</span>
|
|
92
|
-
</div>
|
|
93
|
-
))}
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
)}
|
|
97
|
-
{/* As fotos vêm DEPOIS das respostas: quem abre o card lê primeiro quem é
|
|
98
|
-
a pessoa e o que ela pediu, e só então olha o material que ela mandou. */}
|
|
99
|
-
<LeadAttachments attachments={attachments} variant="compact" />
|
|
100
|
-
</div>
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function OverviewTab({ deal, lead, currency }: { deal: Deal; lead: Lead | null; currency: { code: string; locale: string; symbol: string } }) {
|
|
105
|
-
const t = useTranslation()
|
|
106
|
-
const initial = (lead?.name ?? deal.contactName ?? deal.title).charAt(0).toUpperCase()
|
|
107
|
-
// O painel também abre a partir do detalhe do lead, onde o board nunca
|
|
108
|
-
// montou — por isso busca por conta própria em vez de herdar do funil.
|
|
109
|
-
const tagDefs = useCrmStore((s) => s.tagDefs)
|
|
110
|
-
const fetchTagDefs = useCrmStore((s) => s.fetchTagDefs)
|
|
111
|
-
useEffect(() => { fetchTagDefs() }, [])
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<div className="space-y-5">
|
|
115
|
-
{/* Lead / contact hero */}
|
|
116
|
-
<div className="flex items-center gap-3.5">
|
|
117
|
-
<div className="flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary text-xl font-bold">
|
|
118
|
-
{initial}
|
|
119
|
-
</div>
|
|
120
|
-
<div className="min-w-0 flex-1">
|
|
121
|
-
<PersonLink
|
|
122
|
-
personId={lead?.id ?? deal.contactId}
|
|
123
|
-
name={lead?.name ?? deal.contactName ?? deal.title}
|
|
124
|
-
size="default"
|
|
125
|
-
className="text-base"
|
|
126
|
-
/>
|
|
127
|
-
{lead && (lead.email || lead.phone) && (
|
|
128
|
-
<p className="text-xs text-muted-foreground truncate">{lead.email || lead.phone}</p>
|
|
129
|
-
)}
|
|
130
|
-
{lead?.company && (
|
|
131
|
-
<p className="text-[11px] text-muted-foreground">{lead.company}</p>
|
|
132
|
-
)}
|
|
133
|
-
</div>
|
|
134
|
-
</div>
|
|
135
|
-
|
|
136
|
-
{/* Deal metrics */}
|
|
137
|
-
<div className="rounded-xl border divide-y">
|
|
138
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
139
|
-
<DollarSign className="h-4 w-4 text-muted-foreground shrink-0" />
|
|
140
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.value')}</span>
|
|
141
|
-
<span className="text-sm font-bold">{formatCurrency(deal.value, currency)}</span>
|
|
142
|
-
</div>
|
|
143
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
144
|
-
<Target className="h-4 w-4 text-muted-foreground shrink-0" />
|
|
145
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.probability')}</span>
|
|
146
|
-
<span className="text-sm font-semibold">{deal.probability}%</span>
|
|
147
|
-
</div>
|
|
148
|
-
{deal.stageName && (
|
|
149
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
150
|
-
<div className="h-4 w-4 flex items-center justify-center shrink-0">
|
|
151
|
-
<div className="h-2.5 w-2.5 rounded-full" style={{ backgroundColor: deal.stageColor }} />
|
|
152
|
-
</div>
|
|
153
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.stage')}</span>
|
|
154
|
-
<span className="text-sm font-medium">{deal.stageName}</span>
|
|
155
|
-
</div>
|
|
156
|
-
)}
|
|
157
|
-
{deal.expectedCloseDate && (
|
|
158
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
159
|
-
<Calendar className="h-4 w-4 text-muted-foreground shrink-0" />
|
|
160
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.expectedClose')}</span>
|
|
161
|
-
<span className="text-xs font-medium">{deal.expectedCloseDate}</span>
|
|
162
|
-
</div>
|
|
163
|
-
)}
|
|
164
|
-
{deal.assignedToName && (
|
|
165
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
166
|
-
<User className="h-4 w-4 text-muted-foreground shrink-0" />
|
|
167
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.assignedTo')}</span>
|
|
168
|
-
<span className="text-xs font-medium">{deal.assignedToName}</span>
|
|
169
|
-
</div>
|
|
170
|
-
)}
|
|
171
|
-
{/* Quando entrou. Data e hora com a idade ao lado — o card mostra só o
|
|
172
|
-
relativo, e é aqui que se confere o horário exato antes de ligar. */}
|
|
173
|
-
{deal.createdAt && (
|
|
174
|
-
<div className="flex items-center gap-3 px-4 py-3">
|
|
175
|
-
<Clock className="h-4 w-4 text-muted-foreground shrink-0" />
|
|
176
|
-
<span className="text-xs text-muted-foreground flex-1">{t('crm.dealSidebar.created')}</span>
|
|
177
|
-
<span className="text-xs font-medium text-right">
|
|
178
|
-
{formatDateTime(deal.createdAt, currency.locale)}
|
|
179
|
-
<span className="ml-1.5 text-muted-foreground">
|
|
180
|
-
({formatRelativeTime(deal.createdAt, currency.locale)})
|
|
181
|
-
</span>
|
|
182
|
-
</span>
|
|
183
|
-
</div>
|
|
184
|
-
)}
|
|
185
|
-
</div>
|
|
186
|
-
|
|
187
|
-
{/* Contact links */}
|
|
188
|
-
{lead && (lead.email || lead.phone) && (
|
|
189
|
-
<div className="space-y-2">
|
|
190
|
-
<h4 className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{t('crm.dealSidebar.contact')}</h4>
|
|
191
|
-
<div className="rounded-xl border divide-y">
|
|
192
|
-
{lead.email && (
|
|
193
|
-
<a href={`mailto:${lead.email}`} className="flex items-center gap-3 px-4 py-2.5 text-xs text-primary hover:bg-muted/30 transition-colors">
|
|
194
|
-
<Mail className="h-3.5 w-3.5 shrink-0" /> <span className="truncate">{lead.email}</span>
|
|
195
|
-
</a>
|
|
196
|
-
)}
|
|
197
|
-
{lead.phone && (
|
|
198
|
-
<PhoneLink
|
|
199
|
-
phone={lead.phone}
|
|
200
|
-
className="flex items-center gap-3 px-4 py-2.5 text-xs text-primary hover:bg-muted/30 transition-colors hover:no-underline"
|
|
201
|
-
>
|
|
202
|
-
<MessageCircle className="h-3.5 w-3.5 shrink-0" />
|
|
203
|
-
<span>{normalizePhone(lead.phone).display}</span>
|
|
204
|
-
</PhoneLink>
|
|
205
|
-
)}
|
|
206
|
-
</div>
|
|
207
|
-
</div>
|
|
208
|
-
)}
|
|
209
|
-
|
|
210
|
-
{/* Form answers */}
|
|
211
|
-
<FormAnswers lead={lead} />
|
|
212
|
-
|
|
213
|
-
{/* Tags */}
|
|
214
|
-
{deal.tags && deal.tags.length > 0 && (
|
|
215
|
-
<div className="space-y-2">
|
|
216
|
-
<h4 className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{t('crm.dealSidebar.tags')}</h4>
|
|
217
|
-
{/* Sem `max`: no detalhe cabe tudo. É o card do funil que resume. */}
|
|
218
|
-
<TagChips tags={deal.tags} defs={tagDefs} size="sm" className="gap-1.5" />
|
|
219
|
-
</div>
|
|
220
|
-
)}
|
|
221
|
-
|
|
222
|
-
{/* Notes */}
|
|
223
|
-
{deal.notes && deal.notes !== deal.title && (
|
|
224
|
-
<div className="space-y-2">
|
|
225
|
-
<h4 className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{t('crm.dealSidebar.notes')}</h4>
|
|
226
|
-
<p className="text-xs text-muted-foreground whitespace-pre-wrap leading-relaxed">{deal.notes}</p>
|
|
227
|
-
</div>
|
|
228
|
-
)}
|
|
229
|
-
|
|
230
|
-
</div>
|
|
231
|
-
)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// ---------------------------------------------------------------------------
|
|
235
|
-
// Activity tab
|
|
236
|
-
// ---------------------------------------------------------------------------
|
|
237
|
-
|
|
238
|
-
function ActivityTab({ activities, loading }: { activities: Activity[]; loading: boolean }) {
|
|
239
|
-
const t = useTranslation()
|
|
240
|
-
if (loading) {
|
|
241
|
-
return (
|
|
242
|
-
<div className="space-y-3">
|
|
243
|
-
{[1, 2, 3].map((i) => (
|
|
244
|
-
<div key={i} className="flex items-start gap-3">
|
|
245
|
-
<div className="h-8 w-8 rounded-lg bg-muted/40 animate-pulse shrink-0" />
|
|
246
|
-
<div className="flex-1 space-y-1.5 pt-0.5">
|
|
247
|
-
<div className="h-3.5 w-2/3 rounded bg-muted/40 animate-pulse" />
|
|
248
|
-
<div className="h-2.5 w-1/3 rounded bg-muted/30 animate-pulse" />
|
|
249
|
-
</div>
|
|
250
|
-
</div>
|
|
251
|
-
))}
|
|
252
|
-
</div>
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (activities.length === 0) {
|
|
257
|
-
return (
|
|
258
|
-
<div className="flex flex-col items-center justify-center py-12 text-center">
|
|
259
|
-
<div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-muted/30 mb-3">
|
|
260
|
-
<Clock className="h-5 w-5 text-muted-foreground/40" />
|
|
261
|
-
</div>
|
|
262
|
-
<p className="text-sm text-muted-foreground">{t('crm.dealSidebar.noActivities')}</p>
|
|
263
|
-
<p className="text-[10px] text-muted-foreground/60 mt-0.5">{t('crm.dealSidebar.activitiesAppear')}</p>
|
|
264
|
-
</div>
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return (
|
|
269
|
-
<div className="space-y-1">
|
|
270
|
-
{activities.map((a, i) => {
|
|
271
|
-
const Icon = TYPE_ICONS[a.activityType] ?? FileText
|
|
272
|
-
return (
|
|
273
|
-
<div key={a.id} className="flex items-start gap-3 rounded-lg px-2 py-2.5 hover:bg-muted/20 transition-colors">
|
|
274
|
-
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-muted shrink-0">
|
|
275
|
-
<Icon className="h-3.5 w-3.5 text-muted-foreground" />
|
|
276
|
-
</div>
|
|
277
|
-
<div className="flex-1 min-w-0 pt-0.5">
|
|
278
|
-
<div className="flex items-center gap-1.5">
|
|
279
|
-
<p className="text-xs font-medium truncate">{a.title}</p>
|
|
280
|
-
{a.completedAt && <Check className="h-3 w-3 text-success shrink-0" />}
|
|
281
|
-
</div>
|
|
282
|
-
{a.description && <p className="text-[11px] text-muted-foreground mt-0.5 line-clamp-2">{a.description}</p>}
|
|
283
|
-
<p className="text-[10px] text-muted-foreground/50 mt-1 capitalize">{a.activityType} · {new Date(a.createdAt).toLocaleDateString()}</p>
|
|
284
|
-
</div>
|
|
285
|
-
</div>
|
|
286
|
-
)
|
|
287
|
-
})}
|
|
288
|
-
</div>
|
|
289
|
-
)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// ---------------------------------------------------------------------------
|
|
293
|
-
// Quotes tab
|
|
294
|
-
// ---------------------------------------------------------------------------
|
|
295
|
-
|
|
296
|
-
function QuotesTab({ quotes, loading, currency, onViewQuote, onQuoteUpdated }: { quotes: Quote[]; loading: boolean; currency: { code: string; locale: string; symbol: string }; onViewQuote?: (id: string) => void; onQuoteUpdated?: (q: Quote) => void }) {
|
|
297
|
-
const t = useTranslation()
|
|
298
|
-
if (loading) {
|
|
299
|
-
return (
|
|
300
|
-
<div className="space-y-2">
|
|
301
|
-
{[1, 2].map((i) => (
|
|
302
|
-
<div key={i} className="rounded-xl border p-4 space-y-2.5">
|
|
303
|
-
<div className="h-3.5 w-20 rounded bg-muted/40 animate-pulse" />
|
|
304
|
-
<div className="h-3 w-28 rounded bg-muted/30 animate-pulse" />
|
|
305
|
-
</div>
|
|
306
|
-
))}
|
|
307
|
-
</div>
|
|
308
|
-
)
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (quotes.length === 0) {
|
|
312
|
-
return (
|
|
313
|
-
<div className="flex flex-col items-center justify-center py-12 text-center">
|
|
314
|
-
<div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-muted/30 mb-3">
|
|
315
|
-
<FileText className="h-5 w-5 text-muted-foreground/40" />
|
|
316
|
-
</div>
|
|
317
|
-
<p className="text-sm text-muted-foreground">{t('crm.dealSidebar.noQuotes')}</p>
|
|
318
|
-
<p className="text-[10px] text-muted-foreground/60 mt-0.5">{t('crm.dealSidebar.quotesAppear')}</p>
|
|
319
|
-
</div>
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return (
|
|
324
|
-
<div className="space-y-2">
|
|
325
|
-
{quotes.map((q) => (
|
|
326
|
-
<button
|
|
327
|
-
key={q.id}
|
|
328
|
-
onClick={() => onViewQuote?.(q.id)}
|
|
329
|
-
className="w-full text-left rounded-xl border p-4 hover:bg-muted/20 hover:shadow-sm transition-all group"
|
|
330
|
-
>
|
|
331
|
-
<div className="flex items-center justify-between" onClick={(e) => e.stopPropagation()}>
|
|
332
|
-
<span className="text-sm font-semibold">{q.quoteNumber}</span>
|
|
333
|
-
<QuoteStatusDropdown quote={q} size="sm" onStatusChange={onQuoteUpdated} />
|
|
334
|
-
</div>
|
|
335
|
-
<div className="flex items-center justify-between mt-2">
|
|
336
|
-
<span className="text-[11px] text-muted-foreground">{q.quoteDate}</span>
|
|
337
|
-
<span className="text-sm font-bold">{formatCurrency(q.totalAmount, currency)}</span>
|
|
338
|
-
</div>
|
|
339
|
-
{q.contactName && (
|
|
340
|
-
<p className="text-[10px] text-muted-foreground mt-1.5 truncate">{q.contactName}</p>
|
|
341
|
-
)}
|
|
342
|
-
</button>
|
|
343
|
-
))}
|
|
344
|
-
</div>
|
|
345
|
-
)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// ---------------------------------------------------------------------------
|
|
349
|
-
// Deal sidebar
|
|
350
|
-
// ---------------------------------------------------------------------------
|
|
351
|
-
|
|
352
|
-
export function DealSidebar({ dealId, open, onClose, onViewLead, onViewQuote }: {
|
|
353
|
-
dealId: string
|
|
354
|
-
open: boolean
|
|
355
|
-
onClose: () => void
|
|
356
|
-
onViewLead?: (id: string) => void
|
|
357
|
-
onViewQuote?: (id: string) => void
|
|
358
|
-
}) {
|
|
359
|
-
const t = useTranslation()
|
|
360
|
-
const provider = useCrmProvider()
|
|
361
|
-
const { currency } = useCrmConfig()
|
|
362
|
-
const [deal, setDeal] = useState<Deal | null>(null)
|
|
363
|
-
const [lead, setLead] = useState<Lead | null>(null)
|
|
364
|
-
const [activities, setActivities] = useState<Activity[]>([])
|
|
365
|
-
const [quotes, setQuotes] = useState<Quote[]>([])
|
|
366
|
-
const [loading, setLoading] = useState(true)
|
|
367
|
-
const [activitiesLoading, setActivitiesLoading] = useState(true)
|
|
368
|
-
const [quotesLoading, setQuotesLoading] = useState(true)
|
|
369
|
-
const [activeTab, setActiveTab] = useState<TabId>('overview')
|
|
370
|
-
|
|
371
|
-
useEffect(() => {
|
|
372
|
-
if (!open) return
|
|
373
|
-
setLoading(true)
|
|
374
|
-
setActivitiesLoading(true)
|
|
375
|
-
setQuotesLoading(true)
|
|
376
|
-
setActiveTab('overview')
|
|
377
|
-
setLead(null)
|
|
378
|
-
setActivities([])
|
|
379
|
-
setQuotes([])
|
|
380
|
-
|
|
381
|
-
provider.getDealById(dealId).then(async (d) => {
|
|
382
|
-
setDeal(d)
|
|
383
|
-
if (d?.leadId) {
|
|
384
|
-
const l = await provider.getLeadById(d.leadId)
|
|
385
|
-
setLead(l)
|
|
386
|
-
}
|
|
387
|
-
setLoading(false)
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
provider.getActivities({ dealId }).then((r) => {
|
|
391
|
-
setActivities(r.data)
|
|
392
|
-
setActivitiesLoading(false)
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
provider.getQuotesByDealId(dealId).then((q) => {
|
|
396
|
-
setQuotes(q)
|
|
397
|
-
setQuotesLoading(false)
|
|
398
|
-
})
|
|
399
|
-
}, [dealId, open])
|
|
400
|
-
|
|
401
|
-
return (
|
|
402
|
-
<Sheet open={open} onOpenChange={(v) => { if (!v) onClose() }}>
|
|
403
|
-
<SheetContent width="max-w-md">
|
|
404
|
-
{/* Header */}
|
|
405
|
-
<SheetHeader>
|
|
406
|
-
{loading ? (
|
|
407
|
-
<div className="space-y-1.5 pr-8">
|
|
408
|
-
<div className="h-4 w-40 rounded bg-muted/40 animate-pulse" />
|
|
409
|
-
<div className="h-3 w-24 rounded bg-muted/30 animate-pulse" />
|
|
410
|
-
</div>
|
|
411
|
-
) : (
|
|
412
|
-
<div className="pr-8">
|
|
413
|
-
<SheetTitle>{deal?.title ?? t('crm.dealSidebar.deal')}</SheetTitle>
|
|
414
|
-
{deal?.contactName && <SheetDescription>{deal.contactName}</SheetDescription>}
|
|
415
|
-
</div>
|
|
416
|
-
)}
|
|
417
|
-
</SheetHeader>
|
|
418
|
-
|
|
419
|
-
{/* Tabs */}
|
|
420
|
-
<TabBar
|
|
421
|
-
active={activeTab}
|
|
422
|
-
counts={{ activity: activities.length, quotes: quotes.length }}
|
|
423
|
-
onChange={setActiveTab}
|
|
424
|
-
/>
|
|
425
|
-
|
|
426
|
-
{/* Content */}
|
|
427
|
-
<SheetBody>
|
|
428
|
-
{loading ? (
|
|
429
|
-
<div className="space-y-5">
|
|
430
|
-
<div className="flex items-center gap-3.5">
|
|
431
|
-
<div className="h-14 w-14 rounded-2xl bg-muted/40 animate-pulse" />
|
|
432
|
-
<div className="space-y-2 flex-1">
|
|
433
|
-
<div className="h-4 w-32 rounded bg-muted/40 animate-pulse" />
|
|
434
|
-
<div className="h-3 w-24 rounded bg-muted/30 animate-pulse" />
|
|
435
|
-
</div>
|
|
436
|
-
</div>
|
|
437
|
-
<div className="rounded-xl border divide-y">
|
|
438
|
-
{[1, 2, 3].map((i) => (
|
|
439
|
-
<div key={i} className="flex items-center justify-between px-4 py-3">
|
|
440
|
-
<div className="h-3 w-20 rounded bg-muted/30 animate-pulse" />
|
|
441
|
-
<div className="h-3 w-24 rounded bg-muted/40 animate-pulse" />
|
|
442
|
-
</div>
|
|
443
|
-
))}
|
|
444
|
-
</div>
|
|
445
|
-
</div>
|
|
446
|
-
) : deal ? (
|
|
447
|
-
<>
|
|
448
|
-
{activeTab === 'overview' && <OverviewTab deal={deal} lead={lead} currency={currency} />}
|
|
449
|
-
{activeTab === 'activity' && <ActivityTab activities={activities} loading={activitiesLoading} />}
|
|
450
|
-
{activeTab === 'quotes' && <QuotesTab quotes={quotes} loading={quotesLoading} currency={currency} onViewQuote={(id) => { onViewQuote?.(id); onClose() }} onQuoteUpdated={(updated) => setQuotes(quotes.map((q) => q.id === updated.id ? updated : q))} />}
|
|
451
|
-
</>
|
|
452
|
-
) : (
|
|
453
|
-
<div className="flex flex-col items-center justify-center py-12 text-center">
|
|
454
|
-
<p className="text-sm text-muted-foreground">{t('crm.dealSidebar.dealNotFound')}</p>
|
|
455
|
-
</div>
|
|
456
|
-
)}
|
|
457
|
-
</SheetBody>
|
|
458
|
-
|
|
459
|
-
{/* Timestamps pinned to the sheet foot — same pattern as the assistant
|
|
460
|
-
notes detail (border-t hairline, tiny muted line, `·` separator). */}
|
|
461
|
-
{deal && (
|
|
462
|
-
<p className="shrink-0 border-t border-border/40 px-5 py-1.5 text-[10px] text-muted-foreground/60">
|
|
463
|
-
{t('crm.dealSidebar.created')} {deal.createdAt?.slice(0, 10)}
|
|
464
|
-
{deal.updatedAt ? ` · ${t('crm.dealSidebar.updated')} ${deal.updatedAt.slice(0, 10)}` : ''}
|
|
465
|
-
</p>
|
|
466
|
-
)}
|
|
467
|
-
|
|
468
|
-
{/* Footer */}
|
|
469
|
-
{deal && lead && onViewLead && (
|
|
470
|
-
<SheetFooter>
|
|
471
|
-
<button
|
|
472
|
-
onClick={() => { onViewLead(lead.id); onClose() }}
|
|
473
|
-
className="flex-1 inline-flex items-center justify-center gap-2 rounded-lg border px-3 py-2.5 text-xs font-medium hover:bg-muted bg-card shadow-button active:shadow-button-inset transition-colors"
|
|
474
|
-
>
|
|
475
|
-
{t('crm.dealSidebar.viewLeadProfile')} <ArrowRight className="h-3 w-3" />
|
|
476
|
-
</button>
|
|
477
|
-
</SheetFooter>
|
|
478
|
-
)}
|
|
479
|
-
</SheetContent>
|
|
480
|
-
</Sheet>
|
|
481
|
-
)
|
|
482
|
-
}
|