@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
package/dist/index.js
CHANGED
|
@@ -1,13 +1,173 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, Button, SubpageHeader, ListView, useSaveBar, SearchSelect, DatePicker, DataTable, Breadcrumb, PhoneLink, DashboardCanvas, SegmentedControl, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter,
|
|
1
|
+
import React16, { useState, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { registerTranslations, registerMessageDefaults, createSafeDataProvider, usePluginRuntimeOptional, useTranslation, useActiveTenantId, getSupabaseClientOptional, getActiveTenantId, loadMessageOverrides, resolveMessages } from '@fayz-ai/core';
|
|
3
|
+
import { createPluginContext, PluginSettingsPanel, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, useTenantPluginSettings, SettingsGroup, ToggleRow, adminNavigateTo, useLimitGuard, OrderFormSkeleton, OrderFormBlock, OrderFormView, OrderFormItemsCard, OrderFormItemRow, OrderFormAddItemStep, formatCurrency, OrderDetailSkeleton, OrderDetailBlock, OrderDetailView, PersonLink, useAccessOptional, invalidateLimit, useOrganizationStore } from '@fayz-ai/admin';
|
|
4
|
+
import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, Button, SubpageHeader, ListView, useSaveBar, SearchSelect, DatePicker, DataTable, Breadcrumb, PhoneLink, DashboardCanvas, SegmentedControl, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter, Dropdown, DropdownTrigger, DropdownContent, DropdownLabel, DropdownSeparator, DropdownItem, ConfirmDialog, normalizePhone, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
|
|
5
5
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
|
-
import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, MoveRight, Target, ArrowRightLeft, UserPlus, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight,
|
|
6
|
+
import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, MoveRight, Target, ArrowRightLeft, UserPlus, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight, Sparkles, Clock, Calendar, ArrowRight, ChevronDown, Printer, X, Pencil, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Tag, Plus, Zap, Paperclip, ImageOff, CircleAlert, CircleDashed, Loader2, DollarSign, User } from 'lucide-react';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { createStore as createStore$1 } from 'zustand/vanilla';
|
|
9
9
|
|
|
10
10
|
// src/index.ts
|
|
11
|
+
|
|
12
|
+
// src/lib/message-events.ts
|
|
13
|
+
var CONTACT_FIELDS = [
|
|
14
|
+
{ name: "contact_name", label: "Contato", type: "string", example: "Maria Silva" },
|
|
15
|
+
{ name: "company_name", label: "Empresa", type: "string", example: "Sua Empresa" },
|
|
16
|
+
{ name: "owner_name", label: "Respons\xE1vel", type: "string", example: "Jo\xE3o Pereira" }
|
|
17
|
+
];
|
|
18
|
+
var DEAL_FIELDS = [
|
|
19
|
+
...CONTACT_FIELDS,
|
|
20
|
+
{ name: "deal_name", label: "Neg\xF3cio", type: "string", example: "Proposta \u2014 Reforma da fachada" },
|
|
21
|
+
{ name: "deal_value", label: "Valor", type: "money", example: "R$ 12.400,00" },
|
|
22
|
+
{ name: "stage_name", label: "Etapa", type: "string", example: "Negocia\xE7\xE3o" }
|
|
23
|
+
];
|
|
24
|
+
function buildCrmDomainEvents() {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
name: "crm.lead_created",
|
|
28
|
+
title: "Lead novo",
|
|
29
|
+
icon: "UserPlus",
|
|
30
|
+
audit: true,
|
|
31
|
+
description: "Um lead entrou no funil",
|
|
32
|
+
trigger: "Quando o lead \xE9 criado (formul\xE1rio, importa\xE7\xE3o ou manual)",
|
|
33
|
+
fields: CONTACT_FIELDS
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "crm.stage_changed",
|
|
37
|
+
title: "Neg\xF3cio mudou de etapa",
|
|
38
|
+
icon: "GitBranch",
|
|
39
|
+
audit: true,
|
|
40
|
+
description: "O neg\xF3cio avan\xE7ou (ou voltou) no funil",
|
|
41
|
+
trigger: "Quando o card muda de etapa",
|
|
42
|
+
fields: DEAL_FIELDS
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "crm.quote_sent",
|
|
46
|
+
title: "Or\xE7amento enviado",
|
|
47
|
+
icon: "FileText",
|
|
48
|
+
audit: true,
|
|
49
|
+
description: "A proposta foi enviada ao contato",
|
|
50
|
+
trigger: "Quando o or\xE7amento \xE9 marcado como enviado",
|
|
51
|
+
fields: DEAL_FIELDS
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "crm.quote_approved",
|
|
55
|
+
title: "Or\xE7amento aprovado",
|
|
56
|
+
icon: "FileCheck2",
|
|
57
|
+
audit: true,
|
|
58
|
+
description: "O cliente aprovou a proposta",
|
|
59
|
+
trigger: "Quando o or\xE7amento \xE9 marcado como aprovado",
|
|
60
|
+
fields: DEAL_FIELDS
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "crm.deal_won",
|
|
64
|
+
title: "Neg\xF3cio ganho",
|
|
65
|
+
icon: "Trophy",
|
|
66
|
+
audit: true,
|
|
67
|
+
description: "O neg\xF3cio foi fechado",
|
|
68
|
+
trigger: "Quando o neg\xF3cio \xE9 marcado como ganho",
|
|
69
|
+
fields: DEAL_FIELDS
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "crm.deal_idle",
|
|
73
|
+
title: "Neg\xF3cio parado",
|
|
74
|
+
icon: "Clock",
|
|
75
|
+
audit: false,
|
|
76
|
+
description: "O neg\xF3cio ficou sem movimento",
|
|
77
|
+
trigger: "Quando o neg\xF3cio passa dias sem avan\xE7ar",
|
|
78
|
+
fields: DEAL_FIELDS
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
function buildCrmMessageDefaults() {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
eventKey: "crm.lead_created",
|
|
86
|
+
kind: "transactional",
|
|
87
|
+
// WhatsApp primeiro: um lead que acabou de preencher formulário responde
|
|
88
|
+
// no canal em que ele está, e o primeiro contato decide a conversa.
|
|
89
|
+
channels: ["whatsapp", "email"],
|
|
90
|
+
defaults: {
|
|
91
|
+
whatsapp: {
|
|
92
|
+
body: "Oi {{contact_name}}! Aqui \xE9 {{owner_name}}, da {{company_name}} \u{1F44B}\n\nRecebi seu contato e j\xE1 estou a postos. Qual o melhor hor\xE1rio para falarmos?"
|
|
93
|
+
},
|
|
94
|
+
email: {
|
|
95
|
+
subject: "Recebemos seu contato \u2014 {{company_name}}",
|
|
96
|
+
body: "Ol\xE1 {{contact_name}},\n\nRecebemos seu contato e em breve retornamos.\n\n{{owner_name}}\n{{company_name}}"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
eventKey: "crm.stage_changed",
|
|
102
|
+
kind: "transactional",
|
|
103
|
+
channels: ["whatsapp", "email"],
|
|
104
|
+
defaults: {
|
|
105
|
+
whatsapp: {
|
|
106
|
+
body: "Oi {{contact_name}}! Seu atendimento avan\xE7ou para *{{stage_name}}*.\n\nQualquer d\xFAvida, \xE9 s\xF3 responder aqui. \u2014 {{owner_name}}"
|
|
107
|
+
},
|
|
108
|
+
email: {
|
|
109
|
+
subject: "{{deal_name}} \u2014 agora em {{stage_name}}",
|
|
110
|
+
body: "Ol\xE1 {{contact_name}},\n\nSeu atendimento avan\xE7ou para {{stage_name}}.\n\n{{owner_name}}\n{{company_name}}"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
eventKey: "crm.quote_sent",
|
|
116
|
+
kind: "transactional",
|
|
117
|
+
channels: ["email", "whatsapp"],
|
|
118
|
+
defaults: {
|
|
119
|
+
email: {
|
|
120
|
+
subject: "Sua proposta \u2014 {{deal_name}}",
|
|
121
|
+
body: "Ol\xE1 {{contact_name}},\n\nSegue a proposta de {{deal_value}} para {{deal_name}}.\n\nFico \xE0 disposi\xE7\xE3o para ajustar o que for preciso.\n\n{{owner_name}}\n{{company_name}}"
|
|
122
|
+
},
|
|
123
|
+
whatsapp: {
|
|
124
|
+
body: "Oi {{contact_name}}! Acabei de te enviar a proposta de {{deal_value}} \u{1F4C4}\n\nD\xE1 uma olhada e me diz o que achou. \u2014 {{owner_name}}"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
eventKey: "crm.quote_approved",
|
|
130
|
+
kind: "transactional",
|
|
131
|
+
channels: ["whatsapp", "email"],
|
|
132
|
+
defaults: {
|
|
133
|
+
whatsapp: {
|
|
134
|
+
body: "Oba, {{contact_name}}! Recebi sua aprova\xE7\xE3o de {{deal_name}} \u2705\n\nJ\xE1 come\xE7o a organizar tudo e te aviso os pr\xF3ximos passos por aqui. \u2014 {{owner_name}}"
|
|
135
|
+
},
|
|
136
|
+
email: {
|
|
137
|
+
subject: "Proposta aprovada \u2014 {{deal_name}}",
|
|
138
|
+
body: "Ol\xE1 {{contact_name}},\n\nRecebemos sua aprova\xE7\xE3o de {{deal_name}} ({{deal_value}}). J\xE1 estamos dando in\xEDcio.\n\n{{owner_name}}\n{{company_name}}"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
// Confirmar que a aprovação chegou é o mínimo: sem isso o cliente aprova
|
|
142
|
+
// e fica no escuro sem saber se alguém viu.
|
|
143
|
+
defaultEnabled: { email: true }
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
eventKey: "crm.deal_won",
|
|
147
|
+
kind: "transactional",
|
|
148
|
+
channels: ["whatsapp", "email"],
|
|
149
|
+
defaults: {
|
|
150
|
+
whatsapp: {
|
|
151
|
+
body: "Que \xF3timo, {{contact_name}}! \u{1F389} Fechamos {{deal_name}}.\n\nJ\xE1 estou tocando os pr\xF3ximos passos e te aviso por aqui. \u2014 {{owner_name}}"
|
|
152
|
+
},
|
|
153
|
+
email: {
|
|
154
|
+
subject: "Fechado! {{deal_name}}",
|
|
155
|
+
body: "Ol\xE1 {{contact_name}},\n\nObrigado pela confian\xE7a. J\xE1 estamos com {{deal_name}} em andamento.\n\n{{owner_name}}\n{{company_name}}"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
eventKey: "crm.deal_idle",
|
|
161
|
+
kind: "marketing",
|
|
162
|
+
channels: ["whatsapp"],
|
|
163
|
+
defaults: {
|
|
164
|
+
whatsapp: {
|
|
165
|
+
body: "Oi {{contact_name}}, tudo bem?\n\nPassando para saber se {{deal_name}} ainda faz sentido para voc\xEA. Se preferir, retomo mais para frente \u2014 \xE9 s\xF3 me dizer. \u2014 {{owner_name}}"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
}
|
|
11
171
|
var ctx = createPluginContext("CrmPage");
|
|
12
172
|
var CrmContextProvider = ctx.ContextProvider;
|
|
13
173
|
var useCrmConfig = ctx.useConfig;
|
|
@@ -462,6 +622,64 @@ function formatDateTime(iso, locale = "pt-BR") {
|
|
|
462
622
|
minute: "2-digit"
|
|
463
623
|
});
|
|
464
624
|
}
|
|
625
|
+
function automationKeyFor(activityType) {
|
|
626
|
+
return `crm.${activityType}`;
|
|
627
|
+
}
|
|
628
|
+
var CHANNEL_SHORT = {
|
|
629
|
+
email: "E-mail",
|
|
630
|
+
whatsapp: "WhatsApp",
|
|
631
|
+
sms: "SMS",
|
|
632
|
+
push: "Push",
|
|
633
|
+
webchat: "Chat"
|
|
634
|
+
};
|
|
635
|
+
function useActivityAutomations() {
|
|
636
|
+
const runtime = usePluginRuntimeOptional();
|
|
637
|
+
const hasAutomations = Boolean(runtime?.activePlugins.some((p) => p.id === "automations"));
|
|
638
|
+
const tenantId = useOrganizationStore((s) => s.currentOrg?.id);
|
|
639
|
+
const [messages, setMessages] = useState([]);
|
|
640
|
+
useEffect(() => {
|
|
641
|
+
if (!hasAutomations) {
|
|
642
|
+
setMessages([]);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
let cancelled = false;
|
|
646
|
+
void loadMessageOverrides(tenantId).then((overrides) => {
|
|
647
|
+
if (!cancelled) setMessages(resolveMessages(overrides, runtime?.events ?? []));
|
|
648
|
+
});
|
|
649
|
+
return () => {
|
|
650
|
+
cancelled = true;
|
|
651
|
+
};
|
|
652
|
+
}, [hasAutomations, tenantId, runtime]);
|
|
653
|
+
return messages;
|
|
654
|
+
}
|
|
655
|
+
function describe(hits) {
|
|
656
|
+
const on = hits.filter((m) => m.enabled).map((m) => CHANNEL_SHORT[m.channel] ?? m.channel);
|
|
657
|
+
const off = hits.filter((m) => !m.enabled).map((m) => CHANNEL_SHORT[m.channel] ?? m.channel);
|
|
658
|
+
const parts = [];
|
|
659
|
+
if (on.length) parts.push(`Envia por ${on.join(" e ")}`);
|
|
660
|
+
if (off.length) parts.push(`${off.join(" e ")} desligado${off.length > 1 ? "s" : ""}`);
|
|
661
|
+
return `${parts.join(" \xB7 ")} \u2014 clique para abrir a automa\xE7\xE3o`;
|
|
662
|
+
}
|
|
663
|
+
function AutomationBolt({ activityType, messages, className = "" }) {
|
|
664
|
+
const hits = messages.filter((m) => m.event.name === automationKeyFor(activityType));
|
|
665
|
+
if (hits.length === 0) return null;
|
|
666
|
+
const target = hits.find((m) => m.enabled) ?? hits[0];
|
|
667
|
+
const active = hits.some((m) => m.enabled);
|
|
668
|
+
return /* @__PURE__ */ jsx(
|
|
669
|
+
"button",
|
|
670
|
+
{
|
|
671
|
+
type: "button",
|
|
672
|
+
onClick: (e) => {
|
|
673
|
+
e.stopPropagation();
|
|
674
|
+
adminNavigateTo(`/automations/${target.event.name}/${target.channel}`);
|
|
675
|
+
},
|
|
676
|
+
title: describe(hits),
|
|
677
|
+
"aria-label": describe(hits),
|
|
678
|
+
className: `inline-flex shrink-0 items-center justify-center rounded transition-colors ${active ? "text-primary hover:text-primary/70" : "text-muted-foreground/40 hover:text-muted-foreground"} ${className}`,
|
|
679
|
+
children: /* @__PURE__ */ jsx(Zap, { className: `h-3.5 w-3.5 ${active ? "fill-current" : ""}` })
|
|
680
|
+
}
|
|
681
|
+
);
|
|
682
|
+
}
|
|
465
683
|
var TYPE_ICONS = {
|
|
466
684
|
call: Phone,
|
|
467
685
|
email: Mail,
|
|
@@ -621,6 +839,7 @@ function OverviewTab({ deal, lead, currency }) {
|
|
|
621
839
|
}
|
|
622
840
|
function ActivityTab({ activities, loading }) {
|
|
623
841
|
const t2 = useTranslation();
|
|
842
|
+
const messages = useActivityAutomations();
|
|
624
843
|
if (loading) {
|
|
625
844
|
return /* @__PURE__ */ jsx("div", { className: "space-y-3", children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
626
845
|
/* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-lg bg-muted/40 animate-pulse shrink-0" }),
|
|
@@ -644,7 +863,8 @@ function ActivityTab({ activities, loading }) {
|
|
|
644
863
|
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0 pt-0.5", children: [
|
|
645
864
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
646
865
|
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium truncate", children: a.title }),
|
|
647
|
-
a.completedAt && /* @__PURE__ */ jsx(Check, { className: "h-3 w-3 text-success shrink-0" })
|
|
866
|
+
a.completedAt && /* @__PURE__ */ jsx(Check, { className: "h-3 w-3 text-success shrink-0" }),
|
|
867
|
+
/* @__PURE__ */ jsx(AutomationBolt, { activityType: a.activityType, messages })
|
|
648
868
|
] }),
|
|
649
869
|
a.description && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-0.5 line-clamp-2", children: a.description }),
|
|
650
870
|
/* @__PURE__ */ jsxs("p", { className: "text-[10px] text-muted-foreground/50 mt-1 capitalize", children: [
|
|
@@ -1054,12 +1274,13 @@ function StageColumn({ stageId, stageName, stageColor, deals, savingDealIds, cur
|
|
|
1054
1274
|
}
|
|
1055
1275
|
);
|
|
1056
1276
|
}
|
|
1057
|
-
function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead }) {
|
|
1277
|
+
function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead, onOpenSettings }) {
|
|
1058
1278
|
const { currency } = useCrmConfig();
|
|
1059
1279
|
const pipelines = useCrmStore((s) => s.pipelines);
|
|
1060
1280
|
const stages = useCrmStore((s) => s.stages);
|
|
1061
1281
|
const dealsByStage = useCrmStore((s) => s.dealsByStage);
|
|
1062
1282
|
const dealsLoading = useCrmStore((s) => s.dealsLoading);
|
|
1283
|
+
const pipelinesLoading = useCrmStore((s) => s.pipelinesLoading);
|
|
1063
1284
|
const fetchPipelines = useCrmStore((s) => s.fetchPipelines);
|
|
1064
1285
|
const tagDefs = useCrmStore((s) => s.tagDefs);
|
|
1065
1286
|
const fetchTagDefs = useCrmStore((s) => s.fetchTagDefs);
|
|
@@ -1122,6 +1343,7 @@ function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead }) {
|
|
|
1122
1343
|
}, [dealsByStage, savingDealIds]);
|
|
1123
1344
|
const visibleStages = stages.filter((s) => !s.isLost);
|
|
1124
1345
|
const displayBoard = optimisticBoard ?? dealsByStage;
|
|
1346
|
+
const boardPending = dealsByStage.size === 0 && (pipelinesLoading || dealsLoading || pipelines.length > 0 && stages.length > 0);
|
|
1125
1347
|
function handleDragStart(dealId, fromStageId) {
|
|
1126
1348
|
dragRef.current = { dealId, fromStageId };
|
|
1127
1349
|
}
|
|
@@ -1194,7 +1416,18 @@ function PipelineView({ onDealClick, onViewLead, onViewQuote, onAddLead }) {
|
|
|
1194
1416
|
availableTags
|
|
1195
1417
|
}
|
|
1196
1418
|
),
|
|
1197
|
-
|
|
1419
|
+
boardPending ? /* @__PURE__ */ jsx(PipelineSkeleton, {}) : visibleStages.length === 0 ? (
|
|
1420
|
+
/* Sem etapas não existe quadro: o `flex` abaixo renderizava uma faixa
|
|
1421
|
+
em branco, que parece uma tela que não carregou. O funil é a única
|
|
1422
|
+
tela do CRM que não funciona com a configuração vazia — então ela
|
|
1423
|
+
diz isso, e leva para onde as etapas são criadas. */
|
|
1424
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1 rounded-lg border border-dashed border-border py-12 text-center", children: [
|
|
1425
|
+
/* @__PURE__ */ jsx(Filter, { className: "mb-2 h-9 w-9 text-muted-foreground/40", strokeWidth: 1.5 }),
|
|
1426
|
+
/* @__PURE__ */ jsx("p", { className: "text-base font-semibold text-foreground", children: t2("crm.pipeline.noStages") }),
|
|
1427
|
+
/* @__PURE__ */ jsx("p", { className: "max-w-sm text-sm text-muted-foreground", children: t2("crm.pipeline.noStagesHint") }),
|
|
1428
|
+
onOpenSettings && /* @__PURE__ */ jsx(Button, { className: "mt-3", onClick: onOpenSettings, children: t2("crm.pipeline.setupStages") })
|
|
1429
|
+
] })
|
|
1430
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex gap-3 overflow-x-auto pb-2", children: visibleStages.map((stage) => {
|
|
1198
1431
|
const deals = displayBoard.get(stage.id) ?? [];
|
|
1199
1432
|
return /* @__PURE__ */ jsx(
|
|
1200
1433
|
StageColumn,
|
|
@@ -1294,7 +1527,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
1294
1527
|
}, [statusFilter, search]);
|
|
1295
1528
|
const tags = useMemo(() => STATUS_OPTIONS.map((o) => ({ value: o.value, label: o.label })), []);
|
|
1296
1529
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
1297
|
-
/* @__PURE__ */ jsx(SubpageHeader, { title: t2("crm.leads.title")
|
|
1530
|
+
/* @__PURE__ */ jsx(SubpageHeader, { title: t2("crm.leads.title") }),
|
|
1298
1531
|
/* @__PURE__ */ jsx(
|
|
1299
1532
|
ListView,
|
|
1300
1533
|
{
|
|
@@ -1475,7 +1708,6 @@ function QuoteListView({ onNew, onEdit, onEditQuote }) {
|
|
|
1475
1708
|
SubpageHeader,
|
|
1476
1709
|
{
|
|
1477
1710
|
title: t2("crm.quotes.title"),
|
|
1478
|
-
subtitle: t2("crm.quotes.quotesCount", { count: String(quotes.length) }),
|
|
1479
1711
|
actions: onNew && /* @__PURE__ */ jsxs("button", { onClick: onNew, className: "inline-flex items-center gap-1.5 rounded-lg bg-primary border border-primary px-3 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 shadow-button-primary active:shadow-button-inset transition-colors", children: [
|
|
1480
1712
|
/* @__PURE__ */ jsx("span", { className: "h-3.5 w-3.5 inline-flex items-center justify-center", children: "+" }),
|
|
1481
1713
|
" ",
|
|
@@ -1483,16 +1715,25 @@ function QuoteListView({ onNew, onEdit, onEditQuote }) {
|
|
|
1483
1715
|
] })
|
|
1484
1716
|
}
|
|
1485
1717
|
),
|
|
1486
|
-
|
|
1487
|
-
/* @__PURE__ */ jsx(FileText, { className: "h-8 w-8 text-muted-foreground/30 mb-2" }),
|
|
1488
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t2("crm.quotes.noQuotes") }),
|
|
1489
|
-
onNew && /* @__PURE__ */ jsx("button", { onClick: onNew, className: "text-xs text-primary hover:underline mt-1", children: t2("crm.quotes.createFirst") })
|
|
1490
|
-
] }) : /* @__PURE__ */ jsx(
|
|
1718
|
+
/* @__PURE__ */ jsx(
|
|
1491
1719
|
DataTable,
|
|
1492
1720
|
{
|
|
1493
1721
|
columns: columns2,
|
|
1494
|
-
data: quotes,
|
|
1495
|
-
|
|
1722
|
+
data: quotesLoading ? [] : quotes,
|
|
1723
|
+
loading: quotesLoading,
|
|
1724
|
+
onRowClick: (row) => onEdit?.(row.id),
|
|
1725
|
+
emptyMessage: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1 py-6", children: [
|
|
1726
|
+
/* @__PURE__ */ jsx(FileText, { className: "mb-2 h-9 w-9 text-muted-foreground/40", strokeWidth: 1.5 }),
|
|
1727
|
+
/* @__PURE__ */ jsx("p", { className: "text-base font-semibold text-foreground", children: t2("crm.quotes.noQuotes") }),
|
|
1728
|
+
onNew && /* @__PURE__ */ jsx(
|
|
1729
|
+
"button",
|
|
1730
|
+
{
|
|
1731
|
+
onClick: onNew,
|
|
1732
|
+
className: "mt-3 inline-flex items-center gap-1.5 rounded-lg border border-primary bg-primary px-3 py-2 text-sm font-medium text-primary-foreground shadow-button-primary transition-colors hover:bg-primary/90 active:shadow-button-inset",
|
|
1733
|
+
children: t2("crm.quotes.createFirst")
|
|
1734
|
+
}
|
|
1735
|
+
)
|
|
1736
|
+
] })
|
|
1496
1737
|
}
|
|
1497
1738
|
)
|
|
1498
1739
|
] });
|
|
@@ -1508,103 +1749,6 @@ var fid = 1;
|
|
|
1508
1749
|
function nextId() {
|
|
1509
1750
|
return `qi${fid++}`;
|
|
1510
1751
|
}
|
|
1511
|
-
function QuoteItemRow({ item, index, itemTypes, currency, expanded, onToggle, onUpdate, onRemove, showDiscount, onShowDiscount, onHideDiscount, entityLookups }) {
|
|
1512
|
-
const t2 = useTranslation();
|
|
1513
|
-
const total = item.quantity * item.unitPrice - item.discount;
|
|
1514
|
-
const kindLabel = itemTypes.find((ty) => ty.value === item.itemKind)?.label ?? item.itemKind;
|
|
1515
|
-
return /* @__PURE__ */ jsxs("div", { className: "border-b last:border-0", children: [
|
|
1516
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-4 py-3 cursor-pointer hover:bg-muted/30 transition-colors group", onClick: onToggle, children: [
|
|
1517
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: `h-3 w-3 text-muted-foreground shrink-0 transition-transform ${expanded ? "rotate-0" : "-rotate-90"}` }),
|
|
1518
|
-
/* @__PURE__ */ jsxs("span", { className: "text-[10px] font-medium text-muted-foreground w-5 shrink-0", children: [
|
|
1519
|
-
index + 1,
|
|
1520
|
-
"."
|
|
1521
|
-
] }),
|
|
1522
|
-
/* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium bg-muted text-muted-foreground shrink-0", children: kindLabel }),
|
|
1523
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm truncate flex-1 min-w-0", children: item.description || /* @__PURE__ */ jsx("span", { className: "text-muted-foreground italic", children: t2("crm.quoteForm.noDescription") }) }),
|
|
1524
|
-
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground shrink-0", children: [
|
|
1525
|
-
item.quantity,
|
|
1526
|
-
" x ",
|
|
1527
|
-
formatCurrency(item.unitPrice, currency)
|
|
1528
|
-
] }),
|
|
1529
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold shrink-0 min-w-[80px] text-right", children: formatCurrency(total, currency) }),
|
|
1530
|
-
/* @__PURE__ */ jsx("button", { onClick: (e) => {
|
|
1531
|
-
e.stopPropagation();
|
|
1532
|
-
onRemove();
|
|
1533
|
-
}, className: "p-1 text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-destructive transition-all shrink-0", children: /* @__PURE__ */ jsx(Trash2, { className: "h-3 w-3" }) })
|
|
1534
|
-
] }),
|
|
1535
|
-
expanded && /* @__PURE__ */ jsxs("div", { className: "px-4 pb-4 pt-1 ml-8 space-y-3 bg-muted/10", children: [
|
|
1536
|
-
/* @__PURE__ */ jsx("div", { className: "flex gap-1.5", children: itemTypes.map((t3) => /* @__PURE__ */ jsx(
|
|
1537
|
-
"button",
|
|
1538
|
-
{
|
|
1539
|
-
onClick: () => onUpdate({ itemKind: t3.value }),
|
|
1540
|
-
className: `rounded-full px-2.5 py-1 text-[10px] font-medium transition-colors ${item.itemKind === t3.value ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground hover:bg-muted/80"}`,
|
|
1541
|
-
children: t3.label
|
|
1542
|
-
},
|
|
1543
|
-
t3.value
|
|
1544
|
-
)) }),
|
|
1545
|
-
/* @__PURE__ */ jsxs("div", { className: "grid gap-3 grid-cols-12", children: [
|
|
1546
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-6 sm:col-span-7", children: entityLookups[item.itemKind] ? /* @__PURE__ */ jsx(
|
|
1547
|
-
SearchSelect,
|
|
1548
|
-
{
|
|
1549
|
-
label: "Item",
|
|
1550
|
-
value: item._id,
|
|
1551
|
-
displayValue: item.description,
|
|
1552
|
-
loadOnOpen: true,
|
|
1553
|
-
onChange: (id, opt) => {
|
|
1554
|
-
onUpdate({
|
|
1555
|
-
description: opt?.label ?? "",
|
|
1556
|
-
unitPrice: opt?.data?.price ?? item.unitPrice
|
|
1557
|
-
});
|
|
1558
|
-
},
|
|
1559
|
-
onSearch: async (q) => {
|
|
1560
|
-
const results = await entityLookups[item.itemKind].search(q);
|
|
1561
|
-
return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
|
|
1562
|
-
},
|
|
1563
|
-
placeholder: `Search ${itemTypes.find((t3) => t3.value === item.itemKind)?.label?.toLowerCase() ?? "item"}...`,
|
|
1564
|
-
renderOption: (opt) => /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
1565
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm truncate", children: opt.label }),
|
|
1566
|
-
opt.subtitle && /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: opt.subtitle })
|
|
1567
|
-
] })
|
|
1568
|
-
}
|
|
1569
|
-
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1570
|
-
/* @__PURE__ */ jsx("label", { className: "text-[10px] font-medium text-muted-foreground", children: t2("crm.quoteForm.description") }),
|
|
1571
|
-
/* @__PURE__ */ jsx("input", { type: "text", value: item.description, onChange: (e) => onUpdate({ description: e.target.value }), placeholder: t2("crm.quoteForm.itemDescriptionPlaceholder"), autoFocus: true, className: "w-full mt-0.5 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-2.5 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-ring" })
|
|
1572
|
-
] }) }),
|
|
1573
|
-
/* @__PURE__ */ jsxs("div", { className: "col-span-2 sm:col-span-1", children: [
|
|
1574
|
-
/* @__PURE__ */ jsx("label", { className: "text-[10px] font-medium text-muted-foreground", children: t2("crm.quoteForm.qty") }),
|
|
1575
|
-
/* @__PURE__ */ jsx("input", { type: "number", min: 1, value: item.quantity, onChange: (e) => onUpdate({ quantity: Number(e.target.value) || 1 }), className: "w-full mt-0.5 rounded-input border border-input bg-card shadow-[inset_0_1px_0_rgb(0_0_0_/0.06)] px-2 py-1.5 text-sm text-center focus:outline-none focus:ring-2 focus:ring-ring" })
|
|
1576
|
-
] }),
|
|
1577
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-4", children: /* @__PURE__ */ jsx(CurrencyInput, { label: t2("crm.quoteForm.unitPrice"), value: item.unitPrice, onChange: (v) => onUpdate({ unitPrice: v }), symbol: currency.symbol, locale: currency.locale, currencyCode: currency.code }) })
|
|
1578
|
-
] }),
|
|
1579
|
-
!showDiscount ? /* @__PURE__ */ jsxs("button", { onClick: onShowDiscount, className: "inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors", children: [
|
|
1580
|
-
/* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
|
|
1581
|
-
" ",
|
|
1582
|
-
t2("crm.quoteForm.discount")
|
|
1583
|
-
] }) : /* @__PURE__ */ jsxs("div", { className: "grid gap-3 grid-cols-12 items-end", children: [
|
|
1584
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-4", children: /* @__PURE__ */ jsx(CurrencyInput, { label: t2("crm.quoteForm.discount"), value: item.discount, onChange: (v) => onUpdate({ discount: v }), symbol: currency.symbol, locale: currency.locale, currencyCode: currency.code }) }),
|
|
1585
|
-
/* @__PURE__ */ jsx("div", { className: "col-span-1", children: /* @__PURE__ */ jsx("button", { onClick: () => {
|
|
1586
|
-
onUpdate({ discount: 0 });
|
|
1587
|
-
onHideDiscount();
|
|
1588
|
-
}, className: "mb-2 p-1 text-muted-foreground hover:text-destructive transition-colors", children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }) }) })
|
|
1589
|
-
] }),
|
|
1590
|
-
/* @__PURE__ */ jsx("div", { className: "flex justify-end pt-1", children: /* @__PURE__ */ jsxs("button", { onClick: onToggle, className: "inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-[11px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors", children: [
|
|
1591
|
-
/* @__PURE__ */ jsx(Check, { className: "h-3 w-3" }),
|
|
1592
|
-
" ",
|
|
1593
|
-
t2("crm.quoteForm.done")
|
|
1594
|
-
] }) })
|
|
1595
|
-
] })
|
|
1596
|
-
] });
|
|
1597
|
-
}
|
|
1598
|
-
function AddItemStep({ itemTypes, onSelect, onCancel }) {
|
|
1599
|
-
const t2 = useTranslation();
|
|
1600
|
-
return /* @__PURE__ */ jsxs("div", { className: "border-b px-4 py-3 bg-primary/5 animate-in fade-in-0 slide-in-from-top-1", children: [
|
|
1601
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground mb-2", children: t2("crm.quoteForm.selectItemType") }),
|
|
1602
|
-
/* @__PURE__ */ jsxs("div", { className: "flex gap-2 flex-wrap", children: [
|
|
1603
|
-
itemTypes.map((t3) => /* @__PURE__ */ jsx("button", { onClick: () => onSelect(t3.value), className: "inline-flex items-center gap-1.5 rounded-lg border-2 border-transparent bg-card px-4 py-2 text-sm font-medium shadow-sm hover:border-primary hover:shadow-md transition-all", children: t3.label }, t3.value)),
|
|
1604
|
-
/* @__PURE__ */ jsx("button", { onClick: onCancel, className: "inline-flex items-center rounded-lg px-3 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors", children: t2("crm.quoteForm.cancel") })
|
|
1605
|
-
] })
|
|
1606
|
-
] });
|
|
1607
|
-
}
|
|
1608
1752
|
function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
1609
1753
|
const t2 = useTranslation();
|
|
1610
1754
|
const config = useCrmConfig();
|
|
@@ -1630,7 +1774,6 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1630
1774
|
const [observations, setObservations] = useState("");
|
|
1631
1775
|
const [items, setItems] = useState([]);
|
|
1632
1776
|
const [expandedItemId, setExpandedItemId] = useState(null);
|
|
1633
|
-
const [discountVisible, setDiscountVisible] = useState(/* @__PURE__ */ new Set());
|
|
1634
1777
|
const [addingItem, setAddingItem] = useState(false);
|
|
1635
1778
|
const [saving, setSaving] = useState(false);
|
|
1636
1779
|
useEffect(() => {
|
|
@@ -1654,7 +1797,6 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1654
1797
|
unitPrice: it.unitPrice,
|
|
1655
1798
|
discount: it.discount
|
|
1656
1799
|
})));
|
|
1657
|
-
setDiscountVisible(new Set(q.items.filter((it) => it.discount > 0).map((_, i) => `qi${fid - q.items.length + i}`)));
|
|
1658
1800
|
}
|
|
1659
1801
|
setLoadingExisting(false);
|
|
1660
1802
|
});
|
|
@@ -1736,7 +1878,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1736
1878
|
observations,
|
|
1737
1879
|
items: items.map((it) => ({ itemKind: it.itemKind, description: it.description, quantity: it.quantity, unitPrice: it.unitPrice, discount: it.discount }))
|
|
1738
1880
|
};
|
|
1739
|
-
const snapshot =
|
|
1881
|
+
const snapshot = React16.useRef(null);
|
|
1740
1882
|
useEffect(() => {
|
|
1741
1883
|
if (!loadingExisting && snapshot.current === null) snapshot.current = JSON.stringify(currentFields);
|
|
1742
1884
|
}, [loadingExisting]);
|
|
@@ -1750,132 +1892,136 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
1750
1892
|
onDiscard: () => onSaved?.(),
|
|
1751
1893
|
saveLabel: isEdit ? t2("crm.quoteForm.saveChanges") : t2("crm.quoteForm.saveQuote")
|
|
1752
1894
|
});
|
|
1753
|
-
if (loadingExisting) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1895
|
+
if (loadingExisting) return /* @__PURE__ */ jsx(OrderFormSkeleton, {});
|
|
1896
|
+
const money = (v) => formatCurrency(v, currency);
|
|
1897
|
+
const sideSections = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1898
|
+
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.client"), children: /* @__PURE__ */ jsx(
|
|
1899
|
+
SearchSelect,
|
|
1900
|
+
{
|
|
1901
|
+
value: contactId,
|
|
1902
|
+
displayValue: contactName,
|
|
1903
|
+
onChange: (id, opt) => {
|
|
1904
|
+
setContactId(id);
|
|
1905
|
+
setContactName(opt?.label ?? "");
|
|
1906
|
+
},
|
|
1907
|
+
onSearch: async (q) => {
|
|
1908
|
+
if (!config.contactLookup) return [];
|
|
1909
|
+
const results = await config.contactLookup.search(q);
|
|
1910
|
+
return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
|
|
1911
|
+
},
|
|
1912
|
+
required: true,
|
|
1913
|
+
placeholder: t2("crm.quoteForm.searchClient"),
|
|
1914
|
+
allowCreate: true,
|
|
1915
|
+
createLabel: t2("crm.quoteForm.addAsLead"),
|
|
1916
|
+
onCreate: async (name) => {
|
|
1917
|
+
const lead = await provider.createLead({ name });
|
|
1918
|
+
setContactId(lead.id);
|
|
1919
|
+
setContactName(lead.name);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
) }),
|
|
1923
|
+
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.quoteDetails"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
1924
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1925
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.quoteDate") }),
|
|
1926
|
+
/* @__PURE__ */ jsx(DatePicker, { value: quoteDate, onChange: setQuoteDate, className: "mt-1" })
|
|
1927
|
+
] }),
|
|
1928
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1929
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.validUntil") }),
|
|
1930
|
+
/* @__PURE__ */ jsx(DatePicker, { value: validUntil, onChange: setValidUntil, className: "mt-1" })
|
|
1769
1931
|
] })
|
|
1770
|
-
] })
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
/* @__PURE__ */ jsx(
|
|
1774
|
-
SubpageHeader,
|
|
1932
|
+
] }) }),
|
|
1933
|
+
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.paymentConditions"), children: /* @__PURE__ */ jsx(
|
|
1934
|
+
"textarea",
|
|
1775
1935
|
{
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1936
|
+
value: paymentConditions,
|
|
1937
|
+
onChange: (e) => setPaymentConditions(e.target.value),
|
|
1938
|
+
rows: 2,
|
|
1939
|
+
placeholder: t2("crm.quoteForm.paymentConditionsPlaceholder"),
|
|
1940
|
+
className: "w-full resize-none 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"
|
|
1780
1941
|
}
|
|
1781
|
-
),
|
|
1782
|
-
/* @__PURE__ */ jsx(
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1942
|
+
) }),
|
|
1943
|
+
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.notes"), children: /* @__PURE__ */ jsx(
|
|
1944
|
+
"textarea",
|
|
1945
|
+
{
|
|
1946
|
+
value: observations,
|
|
1947
|
+
onChange: (e) => setObservations(e.target.value),
|
|
1948
|
+
rows: 2,
|
|
1949
|
+
placeholder: t2("crm.quoteForm.notesPlaceholder"),
|
|
1950
|
+
className: "w-full resize-none 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"
|
|
1951
|
+
}
|
|
1952
|
+
) })
|
|
1953
|
+
] });
|
|
1954
|
+
return /* @__PURE__ */ jsx(
|
|
1955
|
+
OrderFormView,
|
|
1956
|
+
{
|
|
1957
|
+
sideSections,
|
|
1958
|
+
title: isEdit ? t2("crm.quoteForm.editTitle") : t2("crm.quoteForm.newTitle"),
|
|
1959
|
+
parentLabel: t2("crm.quotes.title"),
|
|
1960
|
+
onBack: () => onSaved?.(),
|
|
1961
|
+
badges: /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: STATUSES.map((s) => /* @__PURE__ */ jsx(
|
|
1962
|
+
"span",
|
|
1963
|
+
{
|
|
1964
|
+
className: `inline-flex items-center rounded-full px-3 py-1 text-xs font-medium ${s.value === currentStatus ? s.color : "bg-muted/30 text-muted-foreground/50"}`,
|
|
1965
|
+
children: t2(s.labelKey)
|
|
1966
|
+
},
|
|
1967
|
+
s.value
|
|
1968
|
+
)) }),
|
|
1969
|
+
children: /* @__PURE__ */ jsx(
|
|
1970
|
+
OrderFormItemsCard,
|
|
1971
|
+
{
|
|
1972
|
+
label: t2("crm.quoteForm.quoteItems"),
|
|
1973
|
+
addLabel: t2("crm.quoteForm.addItem"),
|
|
1974
|
+
onAdd: () => setAddingItem(true),
|
|
1975
|
+
count: items.length,
|
|
1976
|
+
countLabel: t2("crm.quoteForm.itemCount", { count: String(items.length) }),
|
|
1977
|
+
totalLabel: t2("crm.quoteForm.total"),
|
|
1978
|
+
total: money(totalAmount),
|
|
1979
|
+
emptyLabel: t2("crm.quoteForm.noItems"),
|
|
1980
|
+
emptyActionLabel: t2("crm.quoteForm.addFirstItem"),
|
|
1981
|
+
header: addingItem && /* @__PURE__ */ jsx(
|
|
1982
|
+
OrderFormAddItemStep,
|
|
1983
|
+
{
|
|
1984
|
+
itemTypes,
|
|
1985
|
+
onSelect: addItemOfKind,
|
|
1986
|
+
onCancel: () => setAddingItem(false),
|
|
1987
|
+
label: t2("crm.quoteForm.selectItemType"),
|
|
1988
|
+
cancelLabel: t2("crm.quoteForm.cancel")
|
|
1809
1989
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.quoteDate") }),
|
|
1814
|
-
/* @__PURE__ */ jsx(DatePicker, { value: quoteDate, onChange: setQuoteDate, className: "mt-1" })
|
|
1815
|
-
] }),
|
|
1816
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1817
|
-
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.validUntil") }),
|
|
1818
|
-
/* @__PURE__ */ jsx(DatePicker, { value: validUntil, onChange: setValidUntil, className: "mt-1" })
|
|
1819
|
-
] }),
|
|
1820
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1821
|
-
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.paymentConditions") }),
|
|
1822
|
-
/* @__PURE__ */ jsx("textarea", { value: paymentConditions, onChange: (e) => setPaymentConditions(e.target.value), rows: 2, placeholder: t2("crm.quoteForm.paymentConditionsPlaceholder"), 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" })
|
|
1823
|
-
] }),
|
|
1824
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1825
|
-
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.notes") }),
|
|
1826
|
-
/* @__PURE__ */ jsx("textarea", { value: observations, onChange: (e) => setObservations(e.target.value), rows: 2, placeholder: t2("crm.quoteForm.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" })
|
|
1827
|
-
] })
|
|
1828
|
-
] }),
|
|
1829
|
-
/* @__PURE__ */ jsxs("div", { className: "lg:col-span-2 rounded-lg border bg-card shadow-sm overflow-hidden flex flex-col", children: [
|
|
1830
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 border-b", children: [
|
|
1831
|
-
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t2("crm.quoteForm.quoteItems") }),
|
|
1832
|
-
/* @__PURE__ */ jsxs("button", { onClick: () => setAddingItem(true), 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", children: [
|
|
1833
|
-
/* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
|
|
1834
|
-
" ",
|
|
1835
|
-
t2("crm.quoteForm.addItem")
|
|
1836
|
-
] })
|
|
1837
|
-
] }),
|
|
1838
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
1839
|
-
addingItem && /* @__PURE__ */ jsx(AddItemStep, { itemTypes, onSelect: addItemOfKind, onCancel: () => setAddingItem(false) }),
|
|
1840
|
-
items.length === 0 && !addingItem ? /* @__PURE__ */ jsxs("div", { className: "py-12 text-center", children: [
|
|
1841
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t2("crm.quoteForm.noItems") }),
|
|
1842
|
-
/* @__PURE__ */ jsx("button", { onClick: () => setAddingItem(true), className: "text-xs text-primary hover:underline mt-1", children: t2("crm.quoteForm.addFirstItem") })
|
|
1843
|
-
] }) : items.map((item, i) => /* @__PURE__ */ jsx(
|
|
1844
|
-
QuoteItemRow,
|
|
1990
|
+
),
|
|
1991
|
+
children: items.map((item, i) => /* @__PURE__ */ jsx(
|
|
1992
|
+
OrderFormItemRow,
|
|
1845
1993
|
{
|
|
1846
|
-
item,
|
|
1847
1994
|
index: i,
|
|
1995
|
+
itemKind: item.itemKind,
|
|
1996
|
+
description: item.description,
|
|
1997
|
+
quantity: item.quantity,
|
|
1998
|
+
unitPrice: item.unitPrice,
|
|
1999
|
+
discount: item.discount,
|
|
1848
2000
|
itemTypes,
|
|
1849
2001
|
currency,
|
|
2002
|
+
formatMoney: money,
|
|
1850
2003
|
expanded: expandedItemId === item._id,
|
|
1851
2004
|
onToggle: () => setExpandedItemId(expandedItemId === item._id ? null : item._id),
|
|
1852
|
-
|
|
2005
|
+
onChange: (patch) => updateItem(item._id, patch),
|
|
1853
2006
|
onRemove: () => removeItem(item._id),
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
2007
|
+
entityLookups: config.entityLookups,
|
|
2008
|
+
labels: {
|
|
2009
|
+
item: t2("crm.quoteForm.description"),
|
|
2010
|
+
description: t2("crm.quoteForm.description"),
|
|
2011
|
+
descriptionPlaceholder: t2("crm.quoteForm.itemDescriptionPlaceholder"),
|
|
2012
|
+
noDescription: t2("crm.quoteForm.noDescription"),
|
|
2013
|
+
qty: t2("crm.quoteForm.qty"),
|
|
2014
|
+
unitPrice: t2("crm.quoteForm.unitPrice"),
|
|
2015
|
+
discount: t2("crm.quoteForm.discount"),
|
|
2016
|
+
done: t2("crm.quoteForm.done")
|
|
2017
|
+
}
|
|
1862
2018
|
},
|
|
1863
2019
|
item._id
|
|
1864
2020
|
))
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
1870
|
-
t2("crm.quoteForm.total"),
|
|
1871
|
-
": "
|
|
1872
|
-
] }),
|
|
1873
|
-
/* @__PURE__ */ jsx("span", { className: "text-lg font-bold", children: formatCurrency(totalAmount, currency) })
|
|
1874
|
-
] })
|
|
1875
|
-
] })
|
|
1876
|
-
] })
|
|
1877
|
-
] })
|
|
1878
|
-
] });
|
|
2021
|
+
}
|
|
2022
|
+
)
|
|
2023
|
+
}
|
|
2024
|
+
);
|
|
1879
2025
|
}
|
|
1880
2026
|
function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
1881
2027
|
const t2 = useTranslation();
|
|
@@ -1908,7 +2054,7 @@ function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
|
1908
2054
|
document.addEventListener("mousedown", h);
|
|
1909
2055
|
return () => document.removeEventListener("mousedown", h);
|
|
1910
2056
|
}, [sendMenuOpen]);
|
|
1911
|
-
async function handleSend(
|
|
2057
|
+
async function handleSend(_channel) {
|
|
1912
2058
|
setSending(true);
|
|
1913
2059
|
setSendMenuOpen(false);
|
|
1914
2060
|
try {
|
|
@@ -1923,9 +2069,7 @@ function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
|
1923
2069
|
try {
|
|
1924
2070
|
const updated = await approveQuote(quoteId);
|
|
1925
2071
|
setQuote(updated);
|
|
1926
|
-
if (onInvoiceCreated)
|
|
1927
|
-
onInvoiceCreated(quoteId);
|
|
1928
|
-
}
|
|
2072
|
+
if (onInvoiceCreated) onInvoiceCreated(quoteId);
|
|
1929
2073
|
} finally {
|
|
1930
2074
|
setApproving(false);
|
|
1931
2075
|
}
|
|
@@ -1942,249 +2086,123 @@ function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
|
1942
2086
|
setRejecting(false);
|
|
1943
2087
|
}
|
|
1944
2088
|
}
|
|
1945
|
-
if (loading) {
|
|
1946
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
|
|
1947
|
-
/* @__PURE__ */ jsx(SubpageHeader, { title: "", onBack, parentLabel: t2("crm.quotes.title") }),
|
|
1948
|
-
/* @__PURE__ */ jsxs("div", { className: "rounded-xl border bg-card shadow-sm overflow-hidden", children: [
|
|
1949
|
-
/* @__PURE__ */ jsx("div", { className: "h-1 bg-muted animate-pulse" }),
|
|
1950
|
-
/* @__PURE__ */ jsxs("div", { className: "p-5 pb-4", children: [
|
|
1951
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
|
|
1952
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
1953
|
-
/* @__PURE__ */ jsx("div", { className: "h-10 w-10 rounded-lg bg-muted/40 animate-pulse" }),
|
|
1954
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
1955
|
-
/* @__PURE__ */ jsx("div", { className: "h-3 w-20 rounded bg-muted/40 animate-pulse" }),
|
|
1956
|
-
/* @__PURE__ */ jsx("div", { className: "h-6 w-32 rounded bg-muted/40 animate-pulse" })
|
|
1957
|
-
] })
|
|
1958
|
-
] }),
|
|
1959
|
-
/* @__PURE__ */ jsx("div", { className: "h-6 w-20 rounded-full bg-muted/40 animate-pulse" })
|
|
1960
|
-
] }),
|
|
1961
|
-
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 sm:grid-cols-4 gap-3 mt-4 pt-4 border-t", children: [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1962
|
-
/* @__PURE__ */ jsx("div", { className: "h-3.5 w-3.5 rounded bg-muted/30 animate-pulse" }),
|
|
1963
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
1964
|
-
/* @__PURE__ */ jsx("div", { className: "h-2 w-10 rounded bg-muted/30 animate-pulse" }),
|
|
1965
|
-
/* @__PURE__ */ jsx("div", { className: "h-3 w-16 rounded bg-muted/40 animate-pulse" })
|
|
1966
|
-
] })
|
|
1967
|
-
] }, i)) })
|
|
1968
|
-
] })
|
|
1969
|
-
] })
|
|
1970
|
-
] });
|
|
1971
|
-
}
|
|
2089
|
+
if (loading) return /* @__PURE__ */ jsx(OrderDetailSkeleton, {});
|
|
1972
2090
|
if (!quote) {
|
|
1973
2091
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
|
|
1974
2092
|
/* @__PURE__ */ jsx(SubpageHeader, { title: t2("crm.quoteDetail.title"), onBack, parentLabel: t2("crm.quotes.title") }),
|
|
1975
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center
|
|
1976
|
-
/* @__PURE__ */ jsx(FileText, { className: "h-8 w-8 text-muted-foreground/30
|
|
2093
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted py-12 text-center", children: [
|
|
2094
|
+
/* @__PURE__ */ jsx(FileText, { className: "mb-2 h-8 w-8 text-muted-foreground/30" }),
|
|
1977
2095
|
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t2("crm.quoteDetail.notFound") }),
|
|
1978
|
-
/* @__PURE__ */ jsx("button", { onClick: onBack, className: "text-xs text-primary hover:underline
|
|
2096
|
+
/* @__PURE__ */ jsx("button", { onClick: onBack, className: "mt-1 text-xs text-primary hover:underline", children: t2("crm.quoteDetail.backToList") })
|
|
1979
2097
|
] })
|
|
1980
2098
|
] });
|
|
1981
2099
|
}
|
|
1982
2100
|
const subtotal = quote.items.reduce((sum, it) => sum + it.quantity * it.unitPrice, 0);
|
|
1983
2101
|
const totalDiscount = quote.items.reduce((sum, it) => sum + it.discount, 0);
|
|
1984
|
-
const
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
}
|
|
1998
|
-
{
|
|
1999
|
-
accessorKey: "quantity",
|
|
2000
|
-
header: () => /* @__PURE__ */ jsx("span", { className: "block text-right", children: t2("crm.quoteDetail.qty") }),
|
|
2001
|
-
cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "block text-right text-xs tabular-nums", children: getValue() })
|
|
2002
|
-
},
|
|
2003
|
-
{
|
|
2004
|
-
accessorKey: "unitPrice",
|
|
2005
|
-
header: () => /* @__PURE__ */ jsx("span", { className: "block text-right", children: t2("crm.quoteDetail.unitPrice") }),
|
|
2006
|
-
cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "block text-right text-xs tabular-nums", children: formatCurrency(getValue(), currency) })
|
|
2007
|
-
},
|
|
2008
|
-
{
|
|
2009
|
-
accessorKey: "totalAmount",
|
|
2010
|
-
header: () => /* @__PURE__ */ jsx("span", { className: "block text-right", children: t2("crm.quoteDetail.total") }),
|
|
2011
|
-
cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "block text-right font-medium tabular-nums", children: formatCurrency(getValue(), currency) })
|
|
2012
|
-
}
|
|
2102
|
+
const detailItems = quote.items.map((it, i) => ({
|
|
2103
|
+
id: it.id ?? String(i),
|
|
2104
|
+
name: it.description || "\u2014",
|
|
2105
|
+
description: it.itemKind,
|
|
2106
|
+
quantity: it.quantity,
|
|
2107
|
+
unitPrice: formatCurrency(it.unitPrice, currency),
|
|
2108
|
+
total: formatCurrency(it.totalAmount, currency)
|
|
2109
|
+
}));
|
|
2110
|
+
const totals = [
|
|
2111
|
+
...totalDiscount > 0 ? [
|
|
2112
|
+
{ label: t2("crm.quoteDetail.subtotal"), value: formatCurrency(subtotal, currency), muted: true },
|
|
2113
|
+
{ label: t2("crm.quoteDetail.discount"), value: `-${formatCurrency(totalDiscount, currency)}`, muted: true }
|
|
2114
|
+
] : [],
|
|
2115
|
+
{ label: t2("crm.quoteDetail.total"), value: formatCurrency(quote.totalAmount, currency), strong: true }
|
|
2013
2116
|
];
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
),
|
|
2037
|
-
sendMenuOpen && /* @__PURE__ */ jsxs("div", { className: "absolute right-0 top-full mt-1 w-48 rounded-lg border bg-card shadow-lg z-20 py-1 animate-in fade-in zoom-in-95 duration-100", children: [
|
|
2038
|
-
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs hover:bg-muted/50 transition-colors", children: [
|
|
2039
|
-
/* @__PURE__ */ jsx(Printer, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2040
|
-
" ",
|
|
2041
|
-
t2("crm.quoteDetail.sendPrint")
|
|
2042
|
-
] }),
|
|
2043
|
-
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs hover:bg-muted/50 transition-colors", children: [
|
|
2044
|
-
/* @__PURE__ */ jsx(Mail, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2045
|
-
" ",
|
|
2046
|
-
t2("crm.quoteDetail.sendEmail")
|
|
2047
|
-
] }),
|
|
2048
|
-
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs hover:bg-muted/50 transition-colors", children: [
|
|
2049
|
-
/* @__PURE__ */ jsx(MessageCircle, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2050
|
-
" ",
|
|
2051
|
-
t2("crm.quoteDetail.sendWhatsApp")
|
|
2052
|
-
] })
|
|
2053
|
-
] })
|
|
2054
|
-
] }),
|
|
2055
|
-
quote.status === "sent" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2056
|
-
/* @__PURE__ */ jsxs(
|
|
2057
|
-
Button,
|
|
2058
|
-
{
|
|
2059
|
-
type: "button",
|
|
2060
|
-
variant: "default",
|
|
2061
|
-
size: "sm",
|
|
2062
|
-
onClick: handleApprove,
|
|
2063
|
-
disabled: approving,
|
|
2064
|
-
className: "bg-success text-success-foreground hover:bg-success/90 border-success",
|
|
2065
|
-
children: [
|
|
2066
|
-
/* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5" }),
|
|
2067
|
-
approving ? t2("crm.quoteDetail.approving") : t2("crm.quoteDetail.approve")
|
|
2068
|
-
]
|
|
2069
|
-
}
|
|
2070
|
-
),
|
|
2071
|
-
/* @__PURE__ */ jsxs(
|
|
2072
|
-
Button,
|
|
2073
|
-
{
|
|
2074
|
-
type: "button",
|
|
2075
|
-
variant: "outline",
|
|
2076
|
-
size: "sm",
|
|
2077
|
-
onClick: () => setRejectOpen(true),
|
|
2078
|
-
className: "border-destructive/30 text-destructive hover:bg-destructive/10",
|
|
2079
|
-
children: [
|
|
2080
|
-
/* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }),
|
|
2081
|
-
t2("crm.quoteDetail.reject")
|
|
2082
|
-
]
|
|
2083
|
-
}
|
|
2084
|
-
)
|
|
2085
|
-
] }),
|
|
2086
|
-
onEdit && quote.status !== "approved" && quote.status !== "rejected" && quote.status !== "expired" && /* @__PURE__ */ jsxs("button", { type: "button", onClick: onEdit, className: "inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs font-medium hover:bg-muted bg-card shadow-button active:shadow-button-inset transition-colors", children: [
|
|
2087
|
-
/* @__PURE__ */ jsx(Pencil, { className: "h-3 w-3" }),
|
|
2088
|
-
" ",
|
|
2089
|
-
t2("crm.quoteDetail.edit")
|
|
2090
|
-
] })
|
|
2091
|
-
] })
|
|
2092
|
-
}
|
|
2093
|
-
),
|
|
2094
|
-
/* @__PURE__ */ jsxs("div", { className: "rounded-xl border bg-card shadow-sm overflow-hidden", children: [
|
|
2095
|
-
/* @__PURE__ */ jsx("div", { className: "h-1 bg-primary" }),
|
|
2096
|
-
/* @__PURE__ */ jsxs("div", { className: "p-5 pb-4", children: [
|
|
2097
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
2098
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
2099
|
-
/* @__PURE__ */ jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10 shrink-0", children: /* @__PURE__ */ jsx(FileText, { className: "h-5 w-5 text-primary" }) }),
|
|
2100
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2101
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: t2("crm.quoteDetail.quoteNumber", { number: quote.quoteNumber }) }),
|
|
2102
|
-
/* @__PURE__ */ jsx("p", { className: "text-xl font-bold mt-0.5", children: formatCurrency(quote.totalAmount, currency) })
|
|
2103
|
-
] })
|
|
2104
|
-
] }),
|
|
2105
|
-
/* @__PURE__ */ jsx(QuoteStatusDropdown, { quote, onStatusChange: (q) => setQuote(q) })
|
|
2117
|
+
const editable = quote.status !== "approved" && quote.status !== "rejected" && quote.status !== "expired";
|
|
2118
|
+
const actions = /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2119
|
+
quote.status === "draft" && /* @__PURE__ */ jsxs("div", { className: "relative", ref: sendMenuRef, children: [
|
|
2120
|
+
/* @__PURE__ */ jsxs(
|
|
2121
|
+
"button",
|
|
2122
|
+
{
|
|
2123
|
+
type: "button",
|
|
2124
|
+
onClick: () => setSendMenuOpen((p) => !p),
|
|
2125
|
+
disabled: sending,
|
|
2126
|
+
className: "inline-flex items-center gap-1.5 rounded-lg border border-primary bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-button-primary transition-colors hover:bg-primary/90 active:shadow-button-inset disabled:opacity-50",
|
|
2127
|
+
children: [
|
|
2128
|
+
/* @__PURE__ */ jsx(Send, { className: "h-3 w-3" }),
|
|
2129
|
+
sending ? t2("crm.quoteDetail.sending") : t2("crm.quoteDetail.send"),
|
|
2130
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 opacity-60" })
|
|
2131
|
+
]
|
|
2132
|
+
}
|
|
2133
|
+
),
|
|
2134
|
+
sendMenuOpen && /* @__PURE__ */ jsxs("div", { className: "animate-in fade-in zoom-in-95 absolute right-0 top-full z-20 mt-1 w-48 rounded-lg border bg-card py-1 shadow-lg duration-100", children: [
|
|
2135
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors hover:bg-muted/50", children: [
|
|
2136
|
+
/* @__PURE__ */ jsx(Printer, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2137
|
+
" ",
|
|
2138
|
+
t2("crm.quoteDetail.sendPrint")
|
|
2106
2139
|
] }),
|
|
2107
|
-
/* @__PURE__ */ jsxs("
|
|
2108
|
-
/* @__PURE__ */
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
/* @__PURE__ */ jsx(Calendar, { className: "h-3.5 w-3.5 text-muted-foreground shrink-0" }),
|
|
2117
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2118
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t2("crm.quoteDetail.date") }),
|
|
2119
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium", children: quote.quoteDate })
|
|
2120
|
-
] })
|
|
2121
|
-
] }),
|
|
2122
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2123
|
-
/* @__PURE__ */ jsx(Calendar, { className: "h-3.5 w-3.5 text-muted-foreground shrink-0" }),
|
|
2124
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2125
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t2("crm.quoteDetail.validUntil") }),
|
|
2126
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium", children: quote.validUntil })
|
|
2127
|
-
] })
|
|
2128
|
-
] }),
|
|
2129
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2130
|
-
/* @__PURE__ */ jsx(Hash, { className: "h-3.5 w-3.5 text-muted-foreground shrink-0" }),
|
|
2131
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2132
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t2("crm.quoteDetail.items") }),
|
|
2133
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium", children: quote.items.length })
|
|
2134
|
-
] })
|
|
2135
|
-
] })
|
|
2140
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors hover:bg-muted/50", children: [
|
|
2141
|
+
/* @__PURE__ */ jsx(Mail, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2142
|
+
" ",
|
|
2143
|
+
t2("crm.quoteDetail.sendEmail")
|
|
2144
|
+
] }),
|
|
2145
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => handleSend(), className: "flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors hover:bg-muted/50", children: [
|
|
2146
|
+
/* @__PURE__ */ jsx(MessageCircle, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2147
|
+
" ",
|
|
2148
|
+
t2("crm.quoteDetail.sendWhatsApp")
|
|
2136
2149
|
] })
|
|
2137
|
-
] }),
|
|
2138
|
-
quote.items.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2139
|
-
/* @__PURE__ */ jsx("div", { className: "px-5 pt-3 pb-1.5", children: /* @__PURE__ */ jsx("h3", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: t2("crm.quoteDetail.items") }) }),
|
|
2140
|
-
/* @__PURE__ */ jsx("div", { className: "px-5", children: /* @__PURE__ */ jsx(DataTable, { columns: itemColumns, data: quote.items, variant: "flat", compact: true }) }),
|
|
2141
|
-
/* @__PURE__ */ jsx("div", { className: "px-5 py-3 mt-1 border-t bg-muted/10", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-end gap-0.5", children: [
|
|
2142
|
-
totalDiscount > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2143
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 text-xs", children: [
|
|
2144
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t2("crm.quoteDetail.subtotal") }),
|
|
2145
|
-
/* @__PURE__ */ jsx("span", { className: "tabular-nums w-24 text-right", children: formatCurrency(subtotal, currency) })
|
|
2146
|
-
] }),
|
|
2147
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 text-xs text-success", children: [
|
|
2148
|
-
/* @__PURE__ */ jsx("span", { children: t2("crm.quoteDetail.discount") }),
|
|
2149
|
-
/* @__PURE__ */ jsxs("span", { className: "tabular-nums w-24 text-right", children: [
|
|
2150
|
-
"-",
|
|
2151
|
-
formatCurrency(totalDiscount, currency)
|
|
2152
|
-
] })
|
|
2153
|
-
] })
|
|
2154
|
-
] }),
|
|
2155
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 text-sm font-bold pt-1", children: [
|
|
2156
|
-
/* @__PURE__ */ jsx("span", { children: t2("crm.quoteDetail.total") }),
|
|
2157
|
-
/* @__PURE__ */ jsx("span", { className: "tabular-nums w-24 text-right", children: formatCurrency(quote.totalAmount, currency) })
|
|
2158
|
-
] })
|
|
2159
|
-
] }) })
|
|
2160
|
-
] }),
|
|
2161
|
-
quote.paymentConditions && /* @__PURE__ */ jsxs("div", { className: "px-5 py-3 border-t", children: [
|
|
2162
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1", children: t2("crm.quoteDetail.paymentConditions") }),
|
|
2163
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: quote.paymentConditions })
|
|
2164
|
-
] }),
|
|
2165
|
-
quote.observations && /* @__PURE__ */ jsxs("div", { className: "px-5 py-3 border-t", children: [
|
|
2166
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1", children: t2("crm.quoteDetail.notes") }),
|
|
2167
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground whitespace-pre-wrap", children: quote.observations })
|
|
2168
2150
|
] })
|
|
2169
2151
|
] }),
|
|
2170
|
-
|
|
2171
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
2172
|
-
/* @__PURE__ */ jsx(CircleCheckBig, { className: "h-3.5 w-3.5 text-success" }),
|
|
2173
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t2("crm.quoteDetail.invoiceCreated") })
|
|
2174
|
-
] }),
|
|
2152
|
+
quote.status === "sent" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2175
2153
|
/* @__PURE__ */ jsxs(
|
|
2176
|
-
|
|
2154
|
+
Button,
|
|
2177
2155
|
{
|
|
2178
|
-
|
|
2179
|
-
|
|
2156
|
+
type: "button",
|
|
2157
|
+
variant: "default",
|
|
2158
|
+
size: "sm",
|
|
2159
|
+
onClick: handleApprove,
|
|
2160
|
+
disabled: approving,
|
|
2161
|
+
className: "border-success bg-success text-success-foreground hover:bg-success/90",
|
|
2180
2162
|
children: [
|
|
2181
|
-
|
|
2182
|
-
" "
|
|
2183
|
-
|
|
2163
|
+
/* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5" }),
|
|
2164
|
+
approving ? t2("crm.quoteDetail.approving") : t2("crm.quoteDetail.approve")
|
|
2165
|
+
]
|
|
2166
|
+
}
|
|
2167
|
+
),
|
|
2168
|
+
/* @__PURE__ */ jsxs(
|
|
2169
|
+
Button,
|
|
2170
|
+
{
|
|
2171
|
+
type: "button",
|
|
2172
|
+
variant: "outline",
|
|
2173
|
+
size: "sm",
|
|
2174
|
+
onClick: () => setRejectOpen(true),
|
|
2175
|
+
className: "border-destructive/30 text-destructive hover:bg-destructive/10",
|
|
2176
|
+
children: [
|
|
2177
|
+
/* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }),
|
|
2178
|
+
t2("crm.quoteDetail.reject")
|
|
2184
2179
|
]
|
|
2185
2180
|
}
|
|
2186
2181
|
)
|
|
2187
2182
|
] }),
|
|
2183
|
+
onEdit && editable && /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: onEdit, children: [
|
|
2184
|
+
/* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5" }),
|
|
2185
|
+
" ",
|
|
2186
|
+
t2("crm.quoteDetail.edit")
|
|
2187
|
+
] })
|
|
2188
|
+
] });
|
|
2189
|
+
const sideBlocks = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2190
|
+
quote.paymentConditions && /* @__PURE__ */ jsx(OrderDetailBlock, { title: t2("crm.quoteDetail.paymentConditions"), children: /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap text-sm text-muted-foreground", children: quote.paymentConditions }) }),
|
|
2191
|
+
quote.observations && /* @__PURE__ */ jsx(OrderDetailBlock, { title: t2("crm.quoteDetail.notes"), children: /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap text-sm text-muted-foreground", children: quote.observations }) })
|
|
2192
|
+
] });
|
|
2193
|
+
const invoiced = ["approved", "invoiced", "paid", "partial", "overdue"].includes(quote.status);
|
|
2194
|
+
const banners = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2195
|
+
invoiced && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between rounded-lg border border-success/30 bg-success/5 px-4 py-2.5", children: [
|
|
2196
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
2197
|
+
/* @__PURE__ */ jsx(CircleCheckBig, { className: "h-3.5 w-3.5 text-success" }),
|
|
2198
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t2("crm.quoteDetail.invoiceCreated") })
|
|
2199
|
+
] }),
|
|
2200
|
+
/* @__PURE__ */ jsxs("a", { href: "#/financial/receivables/list", className: "inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline", children: [
|
|
2201
|
+
t2("crm.quoteDetail.viewInvoice"),
|
|
2202
|
+
" ",
|
|
2203
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "h-3 w-3" })
|
|
2204
|
+
] })
|
|
2205
|
+
] }),
|
|
2188
2206
|
quote.status === "rejected" && quote.rejectionReason && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-2.5", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
2189
2207
|
/* @__PURE__ */ jsx(Ban, { className: "h-3.5 w-3.5 text-destructive" }),
|
|
2190
2208
|
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
@@ -2192,10 +2210,37 @@ function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
|
2192
2210
|
": ",
|
|
2193
2211
|
/* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: quote.rejectionReason })
|
|
2194
2212
|
] })
|
|
2195
|
-
] }) })
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2213
|
+
] }) })
|
|
2214
|
+
] });
|
|
2215
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2216
|
+
/* @__PURE__ */ jsx(
|
|
2217
|
+
OrderDetailView,
|
|
2218
|
+
{
|
|
2219
|
+
title: `#${quote.quoteNumber}`,
|
|
2220
|
+
badgesNode: /* @__PURE__ */ jsx(QuoteStatusDropdown, { quote, onStatusChange: (q) => setQuote(q) }),
|
|
2221
|
+
subtitle: null,
|
|
2222
|
+
onBack,
|
|
2223
|
+
backLabel: t2("crm.quotes.title"),
|
|
2224
|
+
actions,
|
|
2225
|
+
stats: [
|
|
2226
|
+
{ id: "total", label: t2("crm.quoteDetail.total"), value: formatCurrency(quote.totalAmount, currency), icon: Receipt },
|
|
2227
|
+
{ id: "items", label: t2("crm.quoteDetail.items"), value: quote.items.length, icon: Package },
|
|
2228
|
+
{ id: "date", label: t2("crm.quoteDetail.date"), value: quote.quoteDate, icon: Calendar },
|
|
2229
|
+
{ id: "valid", label: t2("crm.quoteDetail.validUntil"), value: quote.validUntil, icon: CalendarClock }
|
|
2230
|
+
],
|
|
2231
|
+
errorBanner: banners,
|
|
2232
|
+
customer: { name: quote.contactName, email: null },
|
|
2233
|
+
customerNode: quote.contactName ? /* @__PURE__ */ jsx(PersonLink, { personId: quote.contactId ?? quote.leadId, name: quote.contactName, size: "sm" }) : /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" }),
|
|
2234
|
+
items: detailItems,
|
|
2235
|
+
itemsLabel: t2("crm.quoteDetail.items"),
|
|
2236
|
+
totals,
|
|
2237
|
+
totalsLabel: t2("crm.quoteDetail.summary"),
|
|
2238
|
+
extraSections: sideBlocks
|
|
2239
|
+
}
|
|
2240
|
+
),
|
|
2241
|
+
rejectOpen && /* @__PURE__ */ jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", onClick: () => setRejectOpen(false), children: /* @__PURE__ */ jsxs("div", { className: "mx-4 w-full max-w-sm rounded-modal border bg-card p-5 shadow-lg", onClick: (e) => e.stopPropagation(), children: [
|
|
2242
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center gap-3", children: [
|
|
2243
|
+
/* @__PURE__ */ jsx("div", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/10", children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5 text-destructive" }) }),
|
|
2199
2244
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
2200
2245
|
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t2("crm.quoteDetail.reject") }),
|
|
2201
2246
|
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t2("crm.quoteDetail.rejectDescription") })
|
|
@@ -2207,11 +2252,11 @@ function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
|
|
|
2207
2252
|
value: rejectReason,
|
|
2208
2253
|
onChange: (e) => setRejectReason(e.target.value),
|
|
2209
2254
|
placeholder: t2("crm.quoteDetail.rejectReasonPlaceholder"),
|
|
2210
|
-
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)]
|
|
2255
|
+
className: "h-20 w-full resize-none 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",
|
|
2211
2256
|
autoFocus: true
|
|
2212
2257
|
}
|
|
2213
2258
|
),
|
|
2214
|
-
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2
|
|
2259
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-3 flex justify-end gap-2", children: [
|
|
2215
2260
|
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => setRejectOpen(false), children: t2("common.cancel") }),
|
|
2216
2261
|
/* @__PURE__ */ jsx(
|
|
2217
2262
|
Button,
|
|
@@ -2546,16 +2591,9 @@ function ActivityListView({ onOpenLead, onOpenQuote } = {}) {
|
|
|
2546
2591
|
});
|
|
2547
2592
|
}, [typeFilter, showCompleted]);
|
|
2548
2593
|
const filtered = eventsFilter ? activities.filter((a) => SYSTEM_TYPES.has(a.activityType)) : activities;
|
|
2549
|
-
const
|
|
2550
|
-
const overdueCount = activities.filter((a) => !a.completedAt && a.dueDate && a.dueDate < (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)).length;
|
|
2594
|
+
const messages = useActivityAutomations();
|
|
2551
2595
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
2552
|
-
/* @__PURE__ */ jsx(
|
|
2553
|
-
SubpageHeader,
|
|
2554
|
-
{
|
|
2555
|
-
title: t2("crm.activities.title"),
|
|
2556
|
-
subtitle: `${activities.length} ${t2("crm.activities.title").toLowerCase()}${pendingCount > 0 ? ` \xB7 ${pendingCount} ${t2("crm.activities.pending")}` : ""}${overdueCount > 0 ? ` \xB7 ${overdueCount} ${t2("crm.activities.overdue")}` : ""}`
|
|
2557
|
-
}
|
|
2558
|
-
),
|
|
2596
|
+
/* @__PURE__ */ jsx(SubpageHeader, { title: t2("crm.activities.title") }),
|
|
2559
2597
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col sm:flex-row gap-3 sm:items-center", children: [
|
|
2560
2598
|
/* @__PURE__ */ jsxs("div", { className: "flex gap-1.5 flex-wrap", children: [
|
|
2561
2599
|
/* @__PURE__ */ jsx(
|
|
@@ -2648,6 +2686,7 @@ function ActivityListView({ onOpenLead, onOpenQuote } = {}) {
|
|
|
2648
2686
|
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0 pt-0.5", children: [
|
|
2649
2687
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2650
2688
|
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium truncate", children: a.title }),
|
|
2689
|
+
/* @__PURE__ */ jsx(AutomationBolt, { activityType: a.activityType, messages }),
|
|
2651
2690
|
a.completedAt && !isSystem && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-0.5 rounded-full bg-success/15 px-1.5 py-0.5 text-[9px] font-medium text-success dark:bg-success/20", children: [
|
|
2652
2691
|
/* @__PURE__ */ jsx(Check, { className: "h-2.5 w-2.5" }),
|
|
2653
2692
|
" ",
|
|
@@ -2706,7 +2745,7 @@ function ActivityListView({ onOpenLead, onOpenQuote } = {}) {
|
|
|
2706
2745
|
)
|
|
2707
2746
|
] });
|
|
2708
2747
|
}
|
|
2709
|
-
function buildNav(config, view, navigate) {
|
|
2748
|
+
function buildNav(config, view, navigate, hasAutomations) {
|
|
2710
2749
|
const items = [
|
|
2711
2750
|
{ id: "dashboard", label: config.labels.dashboard, icon: "BarChart3", active: view === "dashboard", onClick: () => navigate("dashboard") }
|
|
2712
2751
|
];
|
|
@@ -2736,6 +2775,15 @@ function buildNav(config, view, navigate) {
|
|
|
2736
2775
|
if (config.modules.activities) {
|
|
2737
2776
|
items.push({ id: "activities", label: config.labels.activities, icon: "MessageCircle", active: view === "activities", onClick: () => navigate("activities") });
|
|
2738
2777
|
}
|
|
2778
|
+
if (hasAutomations) {
|
|
2779
|
+
items.push({
|
|
2780
|
+
id: "automations",
|
|
2781
|
+
label: config.labels.automations ?? "Comunica\xE7\xE3o",
|
|
2782
|
+
icon: "Zap",
|
|
2783
|
+
active: false,
|
|
2784
|
+
onClick: () => adminNavigateTo("/automations")
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2739
2787
|
return items;
|
|
2740
2788
|
}
|
|
2741
2789
|
function CrmPage({ config, provider, store, registries }) {
|
|
@@ -2759,9 +2807,23 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
2759
2807
|
return false;
|
|
2760
2808
|
}
|
|
2761
2809
|
});
|
|
2810
|
+
useEffect(() => {
|
|
2811
|
+
if (onboardingComplete) return;
|
|
2812
|
+
let cancelled = false;
|
|
2813
|
+
void provider.getLeads({ pageSize: 1 }).then((res) => {
|
|
2814
|
+
if (!cancelled && res.total > 0) setOnboardingComplete(true);
|
|
2815
|
+
}).catch(() => {
|
|
2816
|
+
});
|
|
2817
|
+
return () => {
|
|
2818
|
+
cancelled = true;
|
|
2819
|
+
};
|
|
2820
|
+
}, [onboardingComplete, provider]);
|
|
2762
2821
|
const isSettings = view === "settings";
|
|
2763
2822
|
const isSummary = view === "dashboard";
|
|
2764
|
-
const
|
|
2823
|
+
const openStageSettings = () => adminNavigateTo("/settings/crm/_properties/stages");
|
|
2824
|
+
const runtime = usePluginRuntimeOptional();
|
|
2825
|
+
const hasAutomations = Boolean(runtime?.activePlugins.some((p) => p.id === "automations"));
|
|
2826
|
+
const nav = buildNav(config, view, navigate, hasAutomations);
|
|
2765
2827
|
const t2 = useTranslation();
|
|
2766
2828
|
const quickActions = useMemo(() => [
|
|
2767
2829
|
{ id: "new-lead", label: t2("crm.quickActions.newLead"), icon: "UserPlus", description: t2("crm.quickActions.newLeadDesc"), action: () => navigate("leads-new") },
|
|
@@ -2769,7 +2831,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
2769
2831
|
...config.modules.quotes ? [{ id: "new-quote", label: t2("crm.quickActions.newQuote"), icon: "FileText", description: t2("crm.quickActions.newQuoteDesc"), action: () => navigate("quotes-new") }] : [],
|
|
2770
2832
|
...config.modules.activities ? [{ id: "log-activity", label: t2("crm.quickActions.logActivity"), icon: "MessageCircle", description: t2("crm.quickActions.logActivityDesc"), action: () => navigate("activities") }] : []
|
|
2771
2833
|
], [config.modules]);
|
|
2772
|
-
if (!onboardingComplete) {
|
|
2834
|
+
if (!onboardingComplete && isSummary) {
|
|
2773
2835
|
return /* @__PURE__ */ jsx(CrmContextProvider, { config, provider, store, children: /* @__PURE__ */ jsx(CrmOnboarding, { onComplete: () => {
|
|
2774
2836
|
setOnboardingComplete(true);
|
|
2775
2837
|
try {
|
|
@@ -2788,7 +2850,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
2788
2850
|
] }) }) });
|
|
2789
2851
|
}
|
|
2790
2852
|
const renderView = createViewRouter([
|
|
2791
|
-
{ id: "pipeline", render: () => /* @__PURE__ */ jsx(PipelineView, { onViewLead: (id) => navigate(`leads-detail:${id}`), onViewQuote: (id) => navigate(`quotes-detail:${id}`), onAddLead: () => navigate("leads-new") }) },
|
|
2853
|
+
{ id: "pipeline", render: () => /* @__PURE__ */ jsx(PipelineView, { onViewLead: (id) => navigate(`leads-detail:${id}`), onViewQuote: (id) => navigate(`quotes-detail:${id}`), onAddLead: () => navigate("leads-new"), onOpenSettings: openStageSettings }) },
|
|
2792
2854
|
{ id: "leads-list", render: () => /* @__PURE__ */ jsx(LeadListView, { onNew: () => navigate("leads-new"), onEdit: (id) => navigate(`leads-detail:${id}`) }) },
|
|
2793
2855
|
{ id: "leads-new", render: () => /* @__PURE__ */ jsx(LeadFormView, { onSaved: (id) => id ? navigate(`leads-detail:${id}`) : navigate("leads-list") }) },
|
|
2794
2856
|
{ id: "quotes-new", render: () => {
|
|
@@ -2811,6 +2873,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
2811
2873
|
title: config.labels.pageTitle,
|
|
2812
2874
|
subtitle: config.labels.pageSubtitle,
|
|
2813
2875
|
nav,
|
|
2876
|
+
navVariant: config.moduleNav,
|
|
2814
2877
|
showHeader: isSummary,
|
|
2815
2878
|
viewKey: view,
|
|
2816
2879
|
direction,
|
|
@@ -3031,7 +3094,7 @@ function createCrmDashboardWidgets(ctx2) {
|
|
|
3031
3094
|
];
|
|
3032
3095
|
}
|
|
3033
3096
|
|
|
3034
|
-
// src/cascade.ts
|
|
3097
|
+
// src/lib/cascade.ts
|
|
3035
3098
|
function deriveLeadStatus(stage) {
|
|
3036
3099
|
if (stage.isWon) return "converted";
|
|
3037
3100
|
if (stage.isLost) return "lost";
|
|
@@ -4483,6 +4546,7 @@ function createCrmStore(provider) {
|
|
|
4483
4546
|
return createStore$1((set, get) => ({
|
|
4484
4547
|
pipelines: [],
|
|
4485
4548
|
stages: [],
|
|
4549
|
+
pipelinesLoading: true,
|
|
4486
4550
|
leads: [],
|
|
4487
4551
|
leadsTotal: 0,
|
|
4488
4552
|
leadsLoading: false,
|
|
@@ -4501,11 +4565,16 @@ function createCrmStore(provider) {
|
|
|
4501
4565
|
funnel: [],
|
|
4502
4566
|
tagDefs: /* @__PURE__ */ new Map(),
|
|
4503
4567
|
async fetchPipelines() {
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4568
|
+
set({ pipelinesLoading: true });
|
|
4569
|
+
try {
|
|
4570
|
+
return await dedup("crm:pipelines", async () => {
|
|
4571
|
+
const pipelines = await provider.getPipelines();
|
|
4572
|
+
const stages = pipelines.length > 0 ? await provider.getPipelineStages(pipelines[0].id) : [];
|
|
4573
|
+
set({ pipelines, stages });
|
|
4574
|
+
});
|
|
4575
|
+
} finally {
|
|
4576
|
+
set({ pipelinesLoading: false });
|
|
4577
|
+
}
|
|
4509
4578
|
},
|
|
4510
4579
|
async fetchTagDefs() {
|
|
4511
4580
|
return dedup("crm:tag-defs", async () => {
|
|
@@ -4836,7 +4905,7 @@ function createCrmStore(provider) {
|
|
|
4836
4905
|
}));
|
|
4837
4906
|
}
|
|
4838
4907
|
|
|
4839
|
-
// src/registries.ts
|
|
4908
|
+
// src/data/registries.ts
|
|
4840
4909
|
var leadSourceEntity = {
|
|
4841
4910
|
name: "Lead Source",
|
|
4842
4911
|
namePlural: "Lead Sources",
|
|
@@ -5117,6 +5186,9 @@ var en = {
|
|
|
5117
5186
|
"crm.pipeline.archive": "Archive",
|
|
5118
5187
|
"crm.pipeline.moveFailed": "Failed to move deal",
|
|
5119
5188
|
"crm.pipeline.movedTo": "Moved to {{stage}}",
|
|
5189
|
+
"crm.pipeline.noStages": "No stages configured",
|
|
5190
|
+
"crm.pipeline.noStagesHint": "A funnel needs stages to have columns \u2014 create yours (Contacted, Proposal, Closed\u2026) and deals start moving between them.",
|
|
5191
|
+
"crm.pipeline.setupStages": "Set up stages",
|
|
5120
5192
|
"crm.pipeline.noDeals": "No deals",
|
|
5121
5193
|
"crm.pipeline.subtitle": "Drag deals between stages",
|
|
5122
5194
|
"crm.pipeline.title": "Pipeline",
|
|
@@ -5148,6 +5220,7 @@ var en = {
|
|
|
5148
5220
|
"crm.quoteDetail.quoteNumber": "Quote {{number}}",
|
|
5149
5221
|
"crm.quoteDetail.rejectionReason": "Rejection reason",
|
|
5150
5222
|
"crm.quoteDetail.subtotal": "Subtotal",
|
|
5223
|
+
"crm.quoteDetail.summary": "Summary",
|
|
5151
5224
|
"crm.quoteDetail.title": "Quotes",
|
|
5152
5225
|
"crm.quoteDetail.total": "Total",
|
|
5153
5226
|
"crm.quoteDetail.unitPrice": "Unit Price",
|
|
@@ -5425,6 +5498,9 @@ var ptBR = {
|
|
|
5425
5498
|
"crm.pipeline.archive": "Arquivar",
|
|
5426
5499
|
"crm.pipeline.moveFailed": "Falha ao mover neg\xF3cio",
|
|
5427
5500
|
"crm.pipeline.movedTo": "Movido para {{stage}}",
|
|
5501
|
+
"crm.pipeline.noStages": "Nenhuma etapa configurada",
|
|
5502
|
+
"crm.pipeline.noStagesHint": "O funil precisa de etapas para ter colunas \u2014 crie as suas (Contato, Proposta, Fechado\u2026) e os neg\xF3cios passam a andar entre elas.",
|
|
5503
|
+
"crm.pipeline.setupStages": "Configurar etapas",
|
|
5428
5504
|
"crm.pipeline.noDeals": "Nenhum neg\xF3cio",
|
|
5429
5505
|
"crm.pipeline.subtitle": "Arraste neg\xF3cios entre etapas",
|
|
5430
5506
|
"crm.pipeline.title": "Pipeline",
|
|
@@ -5456,6 +5532,7 @@ var ptBR = {
|
|
|
5456
5532
|
"crm.quoteDetail.quoteNumber": "Or\xE7amento {{number}}",
|
|
5457
5533
|
"crm.quoteDetail.rejectionReason": "Motivo da rejei\xE7\xE3o",
|
|
5458
5534
|
"crm.quoteDetail.subtotal": "Subtotal",
|
|
5535
|
+
"crm.quoteDetail.summary": "Resumo",
|
|
5459
5536
|
"crm.quoteDetail.title": "Or\xE7amentos",
|
|
5460
5537
|
"crm.quoteDetail.total": "Total",
|
|
5461
5538
|
"crm.quoteDetail.unitPrice": "Pre\xE7o Unit\xE1rio",
|
|
@@ -5620,7 +5697,8 @@ var DEFAULT_LABELS = {
|
|
|
5620
5697
|
quotes: "Quotes",
|
|
5621
5698
|
quotesNew: "New",
|
|
5622
5699
|
quotesList: "List",
|
|
5623
|
-
activities: "Activities"
|
|
5700
|
+
activities: "Activities",
|
|
5701
|
+
automations: "Communication"
|
|
5624
5702
|
};
|
|
5625
5703
|
var DEFAULT_CURRENCY = { code: "BRL", locale: "pt-BR", symbol: "R$" };
|
|
5626
5704
|
var DEFAULT_ITEM_TYPES = [
|
|
@@ -5639,12 +5717,14 @@ function resolveConfig(options) {
|
|
|
5639
5717
|
currency: { ...DEFAULT_CURRENCY, ...options?.currency },
|
|
5640
5718
|
itemTypes: options?.itemTypes ?? DEFAULT_ITEM_TYPES,
|
|
5641
5719
|
entityLookups: options?.entityLookups ?? {},
|
|
5642
|
-
contactLookup: options?.contactLookup
|
|
5720
|
+
contactLookup: options?.contactLookup,
|
|
5721
|
+
moduleNav: options?.moduleNav
|
|
5643
5722
|
};
|
|
5644
5723
|
}
|
|
5645
5724
|
function createCrmPlugin(options) {
|
|
5646
5725
|
const config = resolveConfig(options);
|
|
5647
5726
|
registerTranslations(crmLocales);
|
|
5727
|
+
registerMessageDefaults(buildCrmMessageDefaults());
|
|
5648
5728
|
const activityTypes = options?.activityTypes ?? DEFAULT_ACTIVITY_TYPES;
|
|
5649
5729
|
const crmRegistries2 = buildCrmRegistries(activityTypes);
|
|
5650
5730
|
const provider = options?.dataProvider ?? createSafeDataProvider(
|
|
@@ -5652,7 +5732,7 @@ function createCrmPlugin(options) {
|
|
|
5652
5732
|
() => createMockCrmProvider({ activityTypes })
|
|
5653
5733
|
);
|
|
5654
5734
|
const store = createCrmStore(provider);
|
|
5655
|
-
const PageComponent = () =>
|
|
5735
|
+
const PageComponent = () => React16.createElement(CrmPage, { config, provider, store, registries: crmRegistries2 });
|
|
5656
5736
|
const dashboardWidgets = createCrmDashboardWidgets({ config, provider, store });
|
|
5657
5737
|
return {
|
|
5658
5738
|
id: "crm",
|
|
@@ -5666,6 +5746,11 @@ function createCrmPlugin(options) {
|
|
|
5666
5746
|
scaffolds: ["saas"],
|
|
5667
5747
|
defaultEnabled: true,
|
|
5668
5748
|
dependencies: [],
|
|
5749
|
+
// Os FATOS do funil. Vão no manifesto (e não num registro à parte) para que
|
|
5750
|
+
// o runtime só os exponha enquanto o CRM está ATIVO — automações, webhooks
|
|
5751
|
+
// e auditoria leem todos daqui. Sem esta linha os textos existiam mas não
|
|
5752
|
+
// tinham evento a que se ligar, e a lista de automações saía vazia.
|
|
5753
|
+
events: buildCrmDomainEvents(),
|
|
5669
5754
|
declaredFeatures: [
|
|
5670
5755
|
{ id: "sales", label: config.labels.pageTitle, group: config.labels.pageTitle },
|
|
5671
5756
|
{ id: "crm.leads", label: config.labels.leads, group: config.labels.pageTitle },
|
|
@@ -5911,13 +5996,13 @@ function createCrmPlugin(options) {
|
|
|
5911
5996
|
label: "Sales & CRM",
|
|
5912
5997
|
icon: "Filter",
|
|
5913
5998
|
component: (() => {
|
|
5914
|
-
const Tab = () =>
|
|
5999
|
+
const Tab = () => React16.createElement(
|
|
5915
6000
|
CrmContextProvider,
|
|
5916
6001
|
{ config, provider, store },
|
|
5917
|
-
|
|
6002
|
+
React16.createElement(PluginSettingsPanel, {
|
|
5918
6003
|
title: "Sales & CRM",
|
|
5919
6004
|
subtitle: "Pipeline, lead management, and CRM properties",
|
|
5920
|
-
generalSettings:
|
|
6005
|
+
generalSettings: React16.createElement(CrmGeneralSettings),
|
|
5921
6006
|
registries: crmRegistries2,
|
|
5922
6007
|
hostPluginId: "crm",
|
|
5923
6008
|
routeBase: "/settings/crm"
|
|
@@ -5934,6 +6019,6 @@ function createCrmPlugin(options) {
|
|
|
5934
6019
|
};
|
|
5935
6020
|
}
|
|
5936
6021
|
|
|
5937
|
-
export { TagChips, createCrmPlugin, humanizeTag };
|
|
6022
|
+
export { TagChips, buildCrmDomainEvents, buildCrmMessageDefaults, createCrmPlugin, humanizeTag };
|
|
5938
6023
|
//# sourceMappingURL=index.js.map
|
|
5939
6024
|
//# sourceMappingURL=index.js.map
|