@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.
- 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/mock.d.ts.map +1 -1
- package/dist/data/registries.d.ts.map +1 -0
- package/dist/data/types.d.ts +4 -1
- package/dist/data/types.d.ts.map +1 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +609 -493
- 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/lib/timeline-source.d.ts +10 -0
- package/dist/lib/timeline-source.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,52 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { Filter, Globe, Target, ChevronRight, Check } from 'lucide-react'
|
|
3
|
-
import { useTranslation } from '@fayz-ai/core'
|
|
4
|
-
import { Button } from '@fayz-ai/ui'
|
|
5
|
-
|
|
6
|
-
const STEPS = [
|
|
7
|
-
{ id: 'welcome', icon: Filter, titleKey: 'crm.onboarding.welcome', descKey: 'crm.onboarding.description' },
|
|
8
|
-
{ id: 'sources', icon: Globe, titleKey: 'crm.onboarding.sources.title', descKey: 'crm.onboarding.sources.description' },
|
|
9
|
-
{ id: 'pipeline', icon: Target, titleKey: 'crm.onboarding.pipeline.title', descKey: 'crm.onboarding.pipeline.description' },
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
export function CrmOnboarding({ onComplete }: { onComplete: () => void }) {
|
|
13
|
-
const t = useTranslation()
|
|
14
|
-
const [step, setStep] = useState(0)
|
|
15
|
-
const current = STEPS[step]
|
|
16
|
-
const isLast = step === STEPS.length - 1
|
|
17
|
-
const Icon = current.icon
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<div className="flex items-center justify-center py-12">
|
|
21
|
-
<div className="w-full max-w-lg">
|
|
22
|
-
<div className="flex items-center gap-1 mb-8">
|
|
23
|
-
{STEPS.map((_, i) => <div key={i} className={`h-1 flex-1 rounded-full transition-colors ${i <= step ? 'bg-primary' : 'bg-muted'}`} />)}
|
|
24
|
-
</div>
|
|
25
|
-
<div className="rounded-card border bg-card p-8 text-center space-y-6 shadow-sm">
|
|
26
|
-
<div className="flex justify-center">
|
|
27
|
-
<div className="flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10">
|
|
28
|
-
<Icon className="h-8 w-8 text-primary" />
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
<div>
|
|
32
|
-
<h2 className="text-xl font-bold">{t(current.titleKey)}</h2>
|
|
33
|
-
<p className="text-sm text-muted-foreground mt-2 max-w-sm mx-auto">{t(current.descKey)}</p>
|
|
34
|
-
</div>
|
|
35
|
-
<div className="flex items-center justify-center gap-3 pt-2">
|
|
36
|
-
{step > 0 && <Button variant="outline" size="lg" onClick={() => setStep(step - 1)}>{t('common.back')}</Button>}
|
|
37
|
-
{isLast ? (
|
|
38
|
-
<Button variant="default" size="lg" onClick={onComplete}>
|
|
39
|
-
<Check className="h-4 w-4" /> {t('crm.onboarding.startSelling')}
|
|
40
|
-
</Button>
|
|
41
|
-
) : (
|
|
42
|
-
<Button variant="default" size="lg" onClick={() => setStep(step + 1)}>
|
|
43
|
-
{step === 0 ? t('crm.onboarding.getStarted') : t('crm.onboarding.next')} <ChevronRight className="h-4 w-4" />
|
|
44
|
-
</Button>
|
|
45
|
-
)}
|
|
46
|
-
</div>
|
|
47
|
-
{step === 0 && <button onClick={onComplete} className="text-xs text-muted-foreground hover:text-foreground transition-colors">{t('crm.onboarding.skip')}</button>}
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Os anexos do lead, no backoffice.
|
|
3
|
-
//
|
|
4
|
-
// O bucket é PRIVADO (plugin-crm 015): não existe URL pública para pendurar num
|
|
5
|
-
// <img>. Cada exibição pede uma URL ASSINADA, de vida curta, e quem assina é a
|
|
6
|
-
// sessão de quem está logado — a policy de leitura só devolve objeto que esteja
|
|
7
|
-
// na pasta de um tenant do qual a pessoa é membro. Ou seja: o controle de
|
|
8
|
-
// acesso continua no banco, e esta tela não tem como furá-lo.
|
|
9
|
-
//
|
|
10
|
-
// Some inteiro quando o lead não tem anexo: card de funil é espaço caro.
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
import { useEffect, useState } from 'react'
|
|
14
|
-
import { FileText, ImageOff, Paperclip } from 'lucide-react'
|
|
15
|
-
import { getSupabaseClientOptional, useTranslation } from '@fayz-ai/core'
|
|
16
|
-
import type { LeadAttachmentRef } from '../lib/form-answers'
|
|
17
|
-
|
|
18
|
-
/** Uma hora: o suficiente para abrir, ampliar e voltar; curto para vazar. */
|
|
19
|
-
const SIGNED_URL_TTL_SECONDS = 3600
|
|
20
|
-
|
|
21
|
-
interface SignedAttachment extends LeadAttachmentRef {
|
|
22
|
-
url: string | null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isImage(mime?: string): boolean {
|
|
26
|
-
return !!mime && mime.startsWith('image/')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** "frente" → "Frente"; sem slot, cai no nome do arquivo. */
|
|
30
|
-
function label(attachment: LeadAttachmentRef): string {
|
|
31
|
-
const raw = attachment.slot || attachment.path.split('/').pop() || 'anexo'
|
|
32
|
-
return raw.charAt(0).toUpperCase() + raw.slice(1)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Assina em lote, por bucket. Em lote porque um lead traz tipicamente 2–4
|
|
37
|
-
* arquivos, e quatro round-trips para montar um card seria desperdício visível.
|
|
38
|
-
*/
|
|
39
|
-
async function signAll(attachments: LeadAttachmentRef[]): Promise<SignedAttachment[]> {
|
|
40
|
-
const client = getSupabaseClientOptional() as {
|
|
41
|
-
storage: {
|
|
42
|
-
from(bucket: string): {
|
|
43
|
-
createSignedUrls(
|
|
44
|
-
paths: string[],
|
|
45
|
-
expiresIn: number,
|
|
46
|
-
): PromiseLike<{ data: Array<{ path?: string | null; signedUrl?: string | null }> | null }>
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} | null
|
|
50
|
-
if (!client) return attachments.map((a) => ({ ...a, url: null }))
|
|
51
|
-
|
|
52
|
-
const byBucket = new Map<string, LeadAttachmentRef[]>()
|
|
53
|
-
for (const a of attachments) {
|
|
54
|
-
byBucket.set(a.bucket, [...(byBucket.get(a.bucket) ?? []), a])
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const urlByPath = new Map<string, string>()
|
|
58
|
-
for (const [bucket, items] of byBucket) {
|
|
59
|
-
try {
|
|
60
|
-
const { data } = await client.storage
|
|
61
|
-
.from(bucket)
|
|
62
|
-
.createSignedUrls(items.map((i) => i.path), SIGNED_URL_TTL_SECONDS)
|
|
63
|
-
for (const row of data ?? []) {
|
|
64
|
-
if (row?.path && row.signedUrl) urlByPath.set(row.path, row.signedUrl)
|
|
65
|
-
}
|
|
66
|
-
} catch {
|
|
67
|
-
// Assinatura é best-effort: um bucket indisponível vira placeholder, não
|
|
68
|
-
// uma tela de lead quebrada.
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return attachments.map((a) => ({ ...a, url: urlByPath.get(a.path) ?? null }))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface LeadAttachmentsProps {
|
|
76
|
-
attachments: LeadAttachmentRef[]
|
|
77
|
-
/** `compact` é a versão do card no funil; `full`, a do detalhe do lead. */
|
|
78
|
-
variant?: 'compact' | 'full'
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function LeadAttachments({ attachments, variant = 'full' }: LeadAttachmentsProps) {
|
|
82
|
-
const t = useTranslation()
|
|
83
|
-
const [signed, setSigned] = useState<SignedAttachment[]>([])
|
|
84
|
-
|
|
85
|
-
// A chave do efeito são os caminhos, não o array: o painel remonta a cada
|
|
86
|
-
// abertura e re-assinar os mesmos arquivos a cada render seria gratuito.
|
|
87
|
-
const key = attachments.map((a) => a.path).join('|')
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
let alive = true
|
|
90
|
-
if (!attachments.length) {
|
|
91
|
-
setSigned([])
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
signAll(attachments).then((rows) => {
|
|
95
|
-
if (alive) setSigned(rows)
|
|
96
|
-
})
|
|
97
|
-
return () => {
|
|
98
|
-
alive = false
|
|
99
|
-
}
|
|
100
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
-
}, [key])
|
|
102
|
-
|
|
103
|
-
if (!attachments.length) return null
|
|
104
|
-
|
|
105
|
-
const size = variant === 'compact' ? 'h-16 w-16' : 'h-24 w-24'
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div className="space-y-2">
|
|
109
|
-
<h4 className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider inline-flex items-center gap-1.5">
|
|
110
|
-
<Paperclip className="h-3 w-3" />
|
|
111
|
-
{t('crm.leadDetail.attachments')} · {attachments.length}
|
|
112
|
-
</h4>
|
|
113
|
-
<div className="flex flex-wrap gap-2">
|
|
114
|
-
{(signed.length ? signed : attachments.map((a) => ({ ...a, url: null }))).map((a) => (
|
|
115
|
-
<a
|
|
116
|
-
key={a.path}
|
|
117
|
-
href={a.url ?? undefined}
|
|
118
|
-
target="_blank"
|
|
119
|
-
rel="noopener noreferrer"
|
|
120
|
-
title={label(a)}
|
|
121
|
-
className={`group relative ${size} shrink-0 overflow-hidden rounded-lg border bg-muted ${
|
|
122
|
-
a.url ? 'cursor-pointer hover:border-primary' : 'cursor-default'
|
|
123
|
-
}`}
|
|
124
|
-
>
|
|
125
|
-
{a.url && isImage(a.mime) ? (
|
|
126
|
-
<img src={a.url} alt={label(a)} className="h-full w-full object-cover" loading="lazy" />
|
|
127
|
-
) : (
|
|
128
|
-
<span className="flex h-full w-full items-center justify-center text-muted-foreground">
|
|
129
|
-
{isImage(a.mime) ? <ImageOff className="h-5 w-5" /> : <FileText className="h-5 w-5" />}
|
|
130
|
-
</span>
|
|
131
|
-
)}
|
|
132
|
-
<span className="absolute inset-x-0 bottom-0 truncate bg-background/80 px-1 py-0.5 text-[9px] font-medium">
|
|
133
|
-
{label(a)}
|
|
134
|
-
</span>
|
|
135
|
-
</a>
|
|
136
|
-
))}
|
|
137
|
-
</div>
|
|
138
|
-
</div>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
2
|
-
import { useCrmStore } from '../CrmContext'
|
|
3
|
-
import { SettingsGroup } from '@fayz-ai/saas'
|
|
4
|
-
import { useTranslation } from '@fayz-ai/core'
|
|
5
|
-
|
|
6
|
-
export function PipelineSettings() {
|
|
7
|
-
const t = useTranslation()
|
|
8
|
-
const stages = useCrmStore((s) => s.stages)
|
|
9
|
-
const pipelines = useCrmStore((s) => s.pipelines)
|
|
10
|
-
const fetchPipelines = useCrmStore((s) => s.fetchPipelines)
|
|
11
|
-
|
|
12
|
-
useEffect(() => { fetchPipelines() }, [])
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<div className="space-y-4">
|
|
16
|
-
<SettingsGroup title={t('crm.pipelineSettings.title')} description={t('crm.pipelineSettings.description')}>
|
|
17
|
-
{stages.length === 0 ? (
|
|
18
|
-
<div className="py-6 text-center text-sm text-muted-foreground">{t('common.loading')}</div>
|
|
19
|
-
) : (
|
|
20
|
-
<div className="space-y-0">
|
|
21
|
-
{stages.map((stage, i) => (
|
|
22
|
-
<div key={stage.id} className="flex items-center gap-3 py-3">
|
|
23
|
-
<span className="text-xs text-muted-foreground w-5 shrink-0">{i + 1}</span>
|
|
24
|
-
<div className="h-3 w-3 rounded-full shrink-0" style={{ backgroundColor: stage.color }} />
|
|
25
|
-
<div className="flex-1 min-w-0">
|
|
26
|
-
<p className="text-sm font-medium">{stage.name}</p>
|
|
27
|
-
<p className="text-[10px] text-muted-foreground">
|
|
28
|
-
{t('crm.pipelineSettings.probability')}: {stage.probability}%
|
|
29
|
-
{stage.isWon && ` — ${t('crm.pipelineSettings.winStage')}`}
|
|
30
|
-
{stage.isLost && ` — ${t('crm.pipelineSettings.lossStage')}`}
|
|
31
|
-
</p>
|
|
32
|
-
</div>
|
|
33
|
-
<span className="text-xs text-muted-foreground">{stage.probability}%</span>
|
|
34
|
-
</div>
|
|
35
|
-
))}
|
|
36
|
-
</div>
|
|
37
|
-
)}
|
|
38
|
-
</SettingsGroup>
|
|
39
|
-
|
|
40
|
-
<p className="text-[10px] text-muted-foreground px-1">
|
|
41
|
-
{t('crm.pipelineSettings.customizationNote')}
|
|
42
|
-
</p>
|
|
43
|
-
</div>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { createPortal } from 'react-dom'
|
|
3
|
-
import { ChevronDown, Loader2, Send, CircleDashed, CircleCheckBig, CircleAlert, Ban, Archive, Receipt } from 'lucide-react'
|
|
4
|
-
import { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator } from '@fayz-ai/ui'
|
|
5
|
-
import { ConfirmDialog } from '@fayz-ai/ui'
|
|
6
|
-
import { Button } from '@fayz-ai/ui'
|
|
7
|
-
import { useCrmStore } from '../CrmContext'
|
|
8
|
-
import type { Quote, QuoteStatus } from '../types'
|
|
9
|
-
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
// Status config
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
// Keyed by string, not QuoteStatus: after fn_invoice_from_order promotes the
|
|
15
|
-
// order in place, getQuoteById surfaces the FINANCIAL stage (invoiced/paid/
|
|
16
|
-
// partial/overdue) as the display status — without entries here those fell
|
|
17
|
-
// into the '?? draft' fallback and an invoiced quote read as "Draft".
|
|
18
|
-
const STATUS_CONFIG: Record<string, { bg: string; dot: string; icon: React.ElementType; label: string }> = {
|
|
19
|
-
draft: { bg: 'bg-muted text-muted-foreground', dot: 'bg-muted-foreground', icon: CircleDashed, label: 'Draft' },
|
|
20
|
-
sent: { bg: 'bg-info-soft text-info-soft-foreground', dot: 'bg-info', icon: Send, label: 'Sent' },
|
|
21
|
-
approved: { bg: 'bg-success-soft text-success-soft-foreground', dot: 'bg-success', icon: CircleCheckBig, label: 'Approved' },
|
|
22
|
-
rejected: { bg: 'bg-destructive-soft text-destructive-soft-foreground', dot: 'bg-destructive', icon: Ban, label: 'Rejected' },
|
|
23
|
-
expired: { bg: 'bg-warning-soft text-warning-soft-foreground', dot: 'bg-warning', icon: CircleAlert, label: 'Expired' },
|
|
24
|
-
archived: { bg: 'bg-muted text-muted-foreground', dot: 'bg-muted-foreground', icon: Archive, label: 'Archived' },
|
|
25
|
-
invoiced: { bg: 'bg-warning-soft text-warning-soft-foreground', dot: 'bg-warning', icon: Receipt, label: 'Invoiced' },
|
|
26
|
-
paid: { bg: 'bg-success-soft text-success-soft-foreground', dot: 'bg-success', icon: Receipt, label: 'Paid' },
|
|
27
|
-
partial: { bg: 'bg-warning-soft text-warning-soft-foreground', dot: 'bg-warning', icon: Receipt, label: 'Partial' },
|
|
28
|
-
overdue: { bg: 'bg-destructive-soft text-destructive-soft-foreground', dot: 'bg-destructive', icon: Receipt, label: 'Overdue' },
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Archived is reached via the archive action and the financial stages via the
|
|
32
|
-
// invoice lifecycle — none are dropdown transitions, all terminal here.
|
|
33
|
-
const TRANSITIONS: Record<string, QuoteStatus[]> = {
|
|
34
|
-
draft: ['sent', 'expired'],
|
|
35
|
-
sent: ['approved', 'rejected', 'expired'],
|
|
36
|
-
approved: [],
|
|
37
|
-
rejected: [],
|
|
38
|
-
expired: [],
|
|
39
|
-
archived: [],
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// Rejection reason modal
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
function RejectModal({ onConfirm, onCancel }: { onConfirm: (reason: string) => void; onCancel: () => void }) {
|
|
47
|
-
const [reason, setReason] = useState('')
|
|
48
|
-
|
|
49
|
-
return createPortal(
|
|
50
|
-
<div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/50" onClick={onCancel}>
|
|
51
|
-
<div
|
|
52
|
-
className="w-full max-w-sm rounded-modal border bg-card shadow-lg mx-4 p-5"
|
|
53
|
-
onClick={(e) => e.stopPropagation()}
|
|
54
|
-
style={{ animation: 'saas-sheet-fade-in 150ms ease-out' }}
|
|
55
|
-
>
|
|
56
|
-
<div className="mb-3">
|
|
57
|
-
<h3 className="text-sm font-semibold">Reject Quote</h3>
|
|
58
|
-
<p className="text-xs text-muted-foreground mt-0.5">Provide a reason for the rejection.</p>
|
|
59
|
-
</div>
|
|
60
|
-
<textarea
|
|
61
|
-
value={reason}
|
|
62
|
-
onChange={(e) => setReason(e.target.value)}
|
|
63
|
-
rows={3}
|
|
64
|
-
placeholder="Reason for rejection..."
|
|
65
|
-
autoFocus
|
|
66
|
-
className="w-full rounded-input border border-input bg-card px-3 py-2 text-sm shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] focus:outline-none focus:ring-2 focus:ring-ring resize-none"
|
|
67
|
-
/>
|
|
68
|
-
<div className="flex justify-end gap-2 mt-3">
|
|
69
|
-
<Button variant="outline" size="sm" onClick={onCancel}>
|
|
70
|
-
Cancel
|
|
71
|
-
</Button>
|
|
72
|
-
<Button variant="destructive" size="sm" onClick={() => onConfirm(reason)} disabled={!reason.trim()}>
|
|
73
|
-
Reject Quote
|
|
74
|
-
</Button>
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
</div>,
|
|
78
|
-
document.body
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// QuoteStatusDropdown
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
export function QuoteStatusDropdown({ quote, onStatusChange, size = 'default' }: {
|
|
87
|
-
quote: Quote
|
|
88
|
-
onStatusChange?: (q: Quote) => void
|
|
89
|
-
size?: 'sm' | 'default'
|
|
90
|
-
}) {
|
|
91
|
-
const sendQuote = useCrmStore((s) => s.sendQuote)
|
|
92
|
-
const approveQuote = useCrmStore((s) => s.approveQuote)
|
|
93
|
-
const rejectQuote = useCrmStore((s) => s.rejectQuote)
|
|
94
|
-
const expireQuote = useCrmStore((s) => s.expireQuote)
|
|
95
|
-
|
|
96
|
-
const [loading, setLoading] = useState(false)
|
|
97
|
-
const [showApprove, setShowApprove] = useState(false)
|
|
98
|
-
const [showReject, setShowReject] = useState(false)
|
|
99
|
-
|
|
100
|
-
const config = STATUS_CONFIG[quote.status] ?? STATUS_CONFIG.draft
|
|
101
|
-
const StatusIcon = config.icon
|
|
102
|
-
const transitions = TRANSITIONS[quote.status] ?? []
|
|
103
|
-
|
|
104
|
-
async function handleTransition(target: QuoteStatus) {
|
|
105
|
-
if (loading) return
|
|
106
|
-
setLoading(true)
|
|
107
|
-
try {
|
|
108
|
-
let updated: Quote
|
|
109
|
-
switch (target) {
|
|
110
|
-
case 'sent':
|
|
111
|
-
updated = await sendQuote(quote.id)
|
|
112
|
-
break
|
|
113
|
-
case 'approved':
|
|
114
|
-
setShowApprove(true)
|
|
115
|
-
setLoading(false)
|
|
116
|
-
return
|
|
117
|
-
case 'expired':
|
|
118
|
-
updated = await expireQuote(quote.id)
|
|
119
|
-
break
|
|
120
|
-
default:
|
|
121
|
-
setLoading(false)
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
onStatusChange?.(updated)
|
|
125
|
-
} catch {
|
|
126
|
-
// toast handled by store
|
|
127
|
-
} finally {
|
|
128
|
-
setLoading(false)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function handleReject(reason: string) {
|
|
133
|
-
setShowReject(false)
|
|
134
|
-
setLoading(true)
|
|
135
|
-
try {
|
|
136
|
-
const updated = await rejectQuote(quote.id, reason)
|
|
137
|
-
onStatusChange?.(updated)
|
|
138
|
-
} catch {
|
|
139
|
-
// toast handled by store
|
|
140
|
-
} finally {
|
|
141
|
-
setLoading(false)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const isSmall = size === 'sm'
|
|
146
|
-
|
|
147
|
-
// Terminal states — static badge, no dropdown
|
|
148
|
-
if (transitions.length === 0) {
|
|
149
|
-
return (
|
|
150
|
-
<span className={`inline-flex items-center gap-1 rounded-full font-medium capitalize ${config.bg} ${isSmall ? 'px-1.5 py-0.5 text-[9px]' : 'px-2.5 py-1 text-[11px]'}`}>
|
|
151
|
-
{!isSmall && <StatusIcon className="h-3 w-3" />}
|
|
152
|
-
{config.label}
|
|
153
|
-
</span>
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<>
|
|
159
|
-
<Dropdown>
|
|
160
|
-
<DropdownTrigger asChild>
|
|
161
|
-
<button
|
|
162
|
-
onClick={(e) => e.stopPropagation()}
|
|
163
|
-
disabled={loading}
|
|
164
|
-
className={`inline-flex items-center gap-1 rounded-full font-medium capitalize transition-all ${config.bg} ${
|
|
165
|
-
isSmall ? 'px-1.5 py-0.5 text-[9px]' : 'px-2.5 py-1 text-[11px]'
|
|
166
|
-
} hover:ring-2 hover:ring-primary/20 focus:outline-none focus:ring-2 focus:ring-ring`}
|
|
167
|
-
>
|
|
168
|
-
{!isSmall && <StatusIcon className="h-3 w-3" />}
|
|
169
|
-
{config.label}
|
|
170
|
-
{loading ? (
|
|
171
|
-
<Loader2 className={`animate-spin ${isSmall ? 'h-2.5 w-2.5' : 'h-3 w-3'}`} />
|
|
172
|
-
) : (
|
|
173
|
-
<ChevronDown className={`opacity-50 ${isSmall ? 'h-2.5 w-2.5' : 'h-3 w-3'}`} />
|
|
174
|
-
)}
|
|
175
|
-
</button>
|
|
176
|
-
</DropdownTrigger>
|
|
177
|
-
<DropdownContent align="end" sideOffset={4} onClick={(e: React.MouseEvent) => e.stopPropagation()}>
|
|
178
|
-
<DropdownLabel>Change status</DropdownLabel>
|
|
179
|
-
<DropdownSeparator />
|
|
180
|
-
{transitions.map((target) => {
|
|
181
|
-
const t = STATUS_CONFIG[target]
|
|
182
|
-
const TargetIcon = t.icon
|
|
183
|
-
return (
|
|
184
|
-
<DropdownItem
|
|
185
|
-
key={target}
|
|
186
|
-
onClick={() => target === 'rejected' ? setShowReject(true) : handleTransition(target)}
|
|
187
|
-
className="gap-2.5"
|
|
188
|
-
>
|
|
189
|
-
<span className={`h-2 w-2 rounded-full shrink-0 ${t.dot}`} />
|
|
190
|
-
<TargetIcon className="h-3.5 w-3.5 shrink-0" />
|
|
191
|
-
<span>{t.label}</span>
|
|
192
|
-
</DropdownItem>
|
|
193
|
-
)
|
|
194
|
-
})}
|
|
195
|
-
</DropdownContent>
|
|
196
|
-
</Dropdown>
|
|
197
|
-
|
|
198
|
-
<ConfirmDialog
|
|
199
|
-
open={showApprove}
|
|
200
|
-
variant="success"
|
|
201
|
-
title="Approve this quote?"
|
|
202
|
-
description="This will create an invoice and convert the lead to a client. This action cannot be undone."
|
|
203
|
-
confirmLabel="Approve"
|
|
204
|
-
cancelLabel="Cancel"
|
|
205
|
-
loading={loading}
|
|
206
|
-
onConfirm={async () => {
|
|
207
|
-
setLoading(true)
|
|
208
|
-
try {
|
|
209
|
-
const updated = await approveQuote(quote.id)
|
|
210
|
-
setShowApprove(false)
|
|
211
|
-
onStatusChange?.(updated)
|
|
212
|
-
} catch {
|
|
213
|
-
// toast handled by store
|
|
214
|
-
} finally {
|
|
215
|
-
setLoading(false)
|
|
216
|
-
}
|
|
217
|
-
}}
|
|
218
|
-
onCancel={() => setShowApprove(false)}
|
|
219
|
-
/>
|
|
220
|
-
|
|
221
|
-
{showReject && (
|
|
222
|
-
<RejectModal onConfirm={handleReject} onCancel={() => setShowReject(false)} />
|
|
223
|
-
)}
|
|
224
|
-
</>
|
|
225
|
-
)
|
|
226
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import type { TagDef } from '../types'
|
|
3
|
-
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Chips de tag — a mesma leitura no card do funil e no detalhe.
|
|
6
|
-
//
|
|
7
|
-
// O array do registro guarda SLUG; rótulo e cor vêm do cadastro (plg_crm_tags).
|
|
8
|
-
// Um slug sem cadastro não é erro: é uma tag que uma campanha usou antes de
|
|
9
|
-
// alguém curar o vocabulário. Ela renderiza com o rótulo derivado do slug num
|
|
10
|
-
// chip neutro, e passa a ter cor no momento em que a linha existir.
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
/** 'camp:promo-verao' -> 'Promo Verao'. O namespace some do rótulo: quem lê o
|
|
14
|
-
* card quer ver a campanha, não o prefixo que a marcou. */
|
|
15
|
-
export function humanizeTag(slug: string): string {
|
|
16
|
-
return slug
|
|
17
|
-
.replace(/^[a-z]+:/, '')
|
|
18
|
-
.replace(/-/g, ' ')
|
|
19
|
-
.replace(/\b\w/g, (c) => c.toUpperCase())
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Fundo translúcido derivado da cor da tag.
|
|
24
|
-
*
|
|
25
|
-
* `${cor}1f` é a mesma cor a ~12% de opacidade: o chip fica legível em tema
|
|
26
|
-
* claro e escuro sem precisar de duas paletas, e o texto usa a cor cheia.
|
|
27
|
-
*/
|
|
28
|
-
function chipStyle(color?: string): React.CSSProperties | undefined {
|
|
29
|
-
if (!color || !/^#[0-9a-f]{6}$/i.test(color)) return undefined
|
|
30
|
-
return { backgroundColor: `${color}1f`, color, borderColor: `${color}59` }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface TagChipsProps {
|
|
34
|
-
tags?: string[]
|
|
35
|
-
/** Cadastro por slug. Ausente = todos os chips saem neutros. */
|
|
36
|
-
defs?: Map<string, TagDef>
|
|
37
|
-
/** Acima disso vira "+N" — um card de funil não pode virar nuvem de tags. */
|
|
38
|
-
max?: number
|
|
39
|
-
size?: 'xs' | 'sm'
|
|
40
|
-
className?: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function TagChips({ tags, defs, max, size = 'xs', className }: TagChipsProps) {
|
|
44
|
-
if (!tags?.length) return null
|
|
45
|
-
|
|
46
|
-
const shown = max ? tags.slice(0, max) : tags
|
|
47
|
-
const hidden = max ? tags.length - shown.length : 0
|
|
48
|
-
const text = size === 'xs' ? 'text-[9px] px-1.5 py-px' : 'text-[10px] px-2 py-0.5'
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<div className={`flex flex-wrap items-center gap-1 ${className ?? ''}`}>
|
|
52
|
-
{shown.map((slug) => {
|
|
53
|
-
const def = defs?.get(slug)
|
|
54
|
-
const style = chipStyle(def?.color)
|
|
55
|
-
return (
|
|
56
|
-
<span
|
|
57
|
-
key={slug}
|
|
58
|
-
// title completo: o chip trunca, e "de qual campanha veio" é
|
|
59
|
-
// exatamente o que a pessoa quer confirmar ao passar o mouse.
|
|
60
|
-
title={def?.name ?? humanizeTag(slug)}
|
|
61
|
-
className={`inline-flex max-w-[10rem] items-center truncate rounded-full border font-medium ${text} ${
|
|
62
|
-
style ? '' : 'border-border bg-muted text-muted-foreground'
|
|
63
|
-
}`}
|
|
64
|
-
style={style}
|
|
65
|
-
>
|
|
66
|
-
{def?.name ?? humanizeTag(slug)}
|
|
67
|
-
</span>
|
|
68
|
-
)
|
|
69
|
-
})}
|
|
70
|
-
{hidden > 0 && (
|
|
71
|
-
<span
|
|
72
|
-
title={tags.slice(shown.length).map((s) => defs?.get(s)?.name ?? humanizeTag(s)).join(', ')}
|
|
73
|
-
className={`inline-flex items-center rounded-full border border-border bg-muted font-medium text-muted-foreground ${text}`}
|
|
74
|
-
>
|
|
75
|
-
+{hidden}
|
|
76
|
-
</span>
|
|
77
|
-
)}
|
|
78
|
-
</div>
|
|
79
|
-
)
|
|
80
|
-
}
|
package/src/data/index.ts
DELETED