@fayz-ai/plugin-crm 0.29.3 → 0.31.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/dist/components/LostReasonDialog.d.ts +19 -0
- package/dist/components/LostReasonDialog.d.ts.map +1 -0
- package/dist/data/mock.d.ts.map +1 -1
- package/dist/data/registries.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/tables.d.ts +3 -0
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/types.d.ts +3 -1
- package/dist/data/types.d.ts.map +1 -1
- package/dist/index.js +2525 -864
- package/dist/index.js.map +1 -1
- package/dist/lib/board-filter.d.ts +43 -0
- package/dist/lib/board-filter.d.ts.map +1 -0
- package/dist/lib/lost-reasons.d.ts +18 -0
- package/dist/lib/lost-reasons.d.ts.map +1 -0
- package/dist/lib/pipeline-agent-surface.d.ts +36 -0
- package/dist/lib/pipeline-agent-surface.d.ts.map +1 -0
- package/dist/lib/pipeline-scope.d.ts +19 -0
- package/dist/lib/pipeline-scope.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/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/store.d.ts +7 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/CrmPage.d.ts.map +1 -1
- package/dist/views/DealCardModal.d.ts +13 -2
- package/dist/views/DealCardModal.d.ts.map +1 -1
- package/dist/views/DealFunnelView.d.ts.map +1 -1
- package/dist/views/DealListView.d.ts.map +1 -1
- package/dist/views/DealsView.d.ts +10 -1
- package/dist/views/DealsView.d.ts.map +1 -1
- package/dist/views/GapScreens.d.ts +26 -0
- package/dist/views/GapScreens.d.ts.map +1 -0
- package/dist/views/LeadListView.d.ts.map +1 -1
- package/dist/views/PipelineView.d.ts +12 -4
- package/dist/views/PipelineView.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/customerEntity.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
2
|
-
import { tl, useTranslation, getSupabaseClientOptional, registerTranslations, registerMessageDefaults, createSafeDataProvider, getActiveTenantId, countByTenant, usePluginRuntimeOptional, useActiveTenantId, exportCSV, loadMessageOverrides, resolveMessages, useActiveUnitId } from '@fayz-ai/core';
|
|
3
|
-
import { createPluginContext, useUnitBootstrap, useUnitStore, createCrudPage, PluginSettingsPanel, registerTimelineSource, dedup, useModuleNavigation, usePluginOnboardingGate, PluginOnboardingGateSkeleton, createViewRouter, ModuleActionBar, usePermissionOptional, PageActions, useTenantPluginSettings, SettingsGroup, ToggleRow, adminNavigateTo, usePersistedState, useScrollMemory, useLimitGuard, OrderFormSkeleton, OrderFormBlock, OrderFormView, OrderFormItemsCard, OrderFormItemRow, OrderFormAddItemStep, formatCurrency, useRecordVisit, OrderDetailSkeleton, OrderDetailBlock, OrderDetailView, PersonLink, RightRailPage, KanbanBoard, invalidateLimit, useAccessOptional, useOrganizationStore, getRailPage, ContactPicker } from '@fayz-ai/admin';
|
|
4
|
-
import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, PhoneCall, MoveRight, Target, ArrowRightLeft, UserPlus, MapPin, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, ArrowUp, ArrowDown, X, Plus, Filter, Lock, Pencil, Trash2, Globe, Check, ChevronRight, Settings, Tag, Building2, CircleDot, User, Download, Inbox, Play, Clock, Sparkles, Calendar, ArrowRight, MoreHorizontal, ChevronDown, Printer, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Loader2, Network, Fingerprint, Link2, Star, MessageSquareQuote, UserRound, CalendarDays,
|
|
5
|
-
import { Badge, Checkbox, toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage,
|
|
2
|
+
import { tl, useTranslation, getSupabaseClientOptional, registerTranslations, registerMessageDefaults, createSafeDataProvider, getActiveTenantId, RECORD_GROUP, recordRailFields, activeFacet, countByTenant, usePluginRuntimeOptional, getActiveUnitId, useActiveTenantId, exportCSV, getCurrentLocale, loadMessageOverrides, resolveMessages, useActiveUnitId } from '@fayz-ai/core';
|
|
3
|
+
import { createPluginContext, useUnitBootstrap, useUnitStore, createCrudPage, PluginSettingsPanel, registerTimelineSource, dedup, useModuleNavigation, usePluginOnboardingGate, PluginOnboardingGateSkeleton, createViewRouter, ModuleActionBar, usePermissionOptional, PageActions, useTenantPluginSettings, SettingsGroup, ToggleRow, adminNavigateTo, usePersistedState, useScrollMemory, useLimitGuard, useCatalogedItemTypes, OrderFormSkeleton, OrderFormBlock, OrderFormView, OrderFormItemsCard, OrderFormItemRow, OrderFormAddItemStep, createArchetypeLookup, formatCurrency, useRecordVisit, OrderDetailSkeleton, OrderDetailBlock, OrderDetailView, PersonLink, RightRailPage, AskAIButton, KanbanBoard, invalidateLimit, useAccessOptional, useOrganizationStore, getRailPage, ContactPicker, useAgentSurface } from '@fayz-ai/admin';
|
|
4
|
+
import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, PhoneCall, MoveRight, Target, ArrowRightLeft, UserPlus, MapPin, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, ArrowUp, ArrowDown, X, Plus, Filter, Lock, Pencil, Trash2, Globe, Check, ChevronRight, Settings, Tag, Building2, CircleDot, User, Download, CircleDashed, Search, Inbox, Play, Clock, Sparkles, Calendar, ArrowRight, MoreHorizontal, ChevronDown, Printer, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Loader2, Network, Fingerprint, Link2, Star, MessageSquareQuote, UserRound, CalendarDays, ThumbsDown, SignalHigh, CalendarRange, ChevronLeft, TrendingDown, UserCheck, AlertTriangle, Settings2, Repeat, Zap, Snowflake, Sun, Flame, Merge, Paperclip, ImageOff, CircleAlert, CheckCircle2, SlidersHorizontal, ExternalLink, Clipboard, DollarSign, ThumbsUp, UserRoundPlus } from 'lucide-react';
|
|
5
|
+
import { Badge, Checkbox, toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, SubpageHeader, Button, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, Switch, ConfirmDialog, useIsWide, PageHeaderActions, FilterChip, MultiSelect, FilterMenu, FilterMenuRow, PersonAvatar, ListView, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, ModalFooter, useSaveBar, SearchSelect, DatePicker, FilterPanel, FilterPanelField, RequiredFilter, Card, DataTable, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, PhoneLink, SheetBody, SheetFooter, ComingSoon, DashboardCanvas, ModalDescription, PageViewBar, PersonPicker, CurrencyInput, HeaderTabs, Popover, PopoverTrigger, PopoverContent, getLucideIcon, DictateButton, DropdownLabel, DropdownSeparator, normalizePhone, KpiCard, ChartWidget, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { createStore as createStore$1 } from 'zustand/vanilla';
|
|
@@ -853,18 +853,81 @@ function TagChips({ tags, defs, max, size = "xs", className }) {
|
|
|
853
853
|
)
|
|
854
854
|
] });
|
|
855
855
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
return
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
856
|
+
|
|
857
|
+
// src/lib/lost-reasons.ts
|
|
858
|
+
var LOST_REASONS = ["noInterest", "price", "noBudget", "competitor", "ghosted", "badFit"];
|
|
859
|
+
var KNOWN = new Set(LOST_REASONS);
|
|
860
|
+
function isLostReasonKey(value) {
|
|
861
|
+
return !!value && KNOWN.has(value);
|
|
862
|
+
}
|
|
863
|
+
function lostReasonLabel(value, t2) {
|
|
864
|
+
if (!value) return void 0;
|
|
865
|
+
return isLostReasonKey(value) ? t2(`crm.lostReason.${value}`) : value;
|
|
866
|
+
}
|
|
867
|
+
function LostReasonDialog({
|
|
868
|
+
open,
|
|
869
|
+
saving,
|
|
870
|
+
onCancel,
|
|
871
|
+
onConfirm
|
|
872
|
+
}) {
|
|
873
|
+
const t2 = useTranslation();
|
|
874
|
+
const [picked, setPicked] = useState();
|
|
875
|
+
const [other, setOther] = useState("");
|
|
876
|
+
useEffect(() => {
|
|
877
|
+
if (!open) {
|
|
878
|
+
setPicked(void 0);
|
|
879
|
+
setOther("");
|
|
880
|
+
}
|
|
881
|
+
}, [open]);
|
|
882
|
+
const reason = picked ?? (other.trim() || void 0);
|
|
883
|
+
return /* @__PURE__ */ jsx(Modal, { open, onOpenChange: (v) => {
|
|
884
|
+
if (!v && !saving) onCancel();
|
|
885
|
+
}, children: /* @__PURE__ */ jsxs(ModalContent, { className: "max-w-md", children: [
|
|
886
|
+
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(ModalTitle, { children: t2("crm.card.lostReasonTitle") }) }),
|
|
887
|
+
/* @__PURE__ */ jsxs(ModalBody, { className: "space-y-4", children: [
|
|
888
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t2("crm.card.lostReasonHint") }),
|
|
889
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: LOST_REASONS.map((key) => {
|
|
890
|
+
const active = picked === key;
|
|
891
|
+
return /* @__PURE__ */ jsx(
|
|
892
|
+
"button",
|
|
893
|
+
{
|
|
894
|
+
type: "button",
|
|
895
|
+
"aria-pressed": active,
|
|
896
|
+
onClick: () => {
|
|
897
|
+
setPicked(active ? void 0 : key);
|
|
898
|
+
if (!active) setOther("");
|
|
899
|
+
},
|
|
900
|
+
className: "rounded-full border px-3 py-1.5 text-xs font-medium transition-colors " + (active ? "border-primary bg-primary/10 text-primary" : "border-border text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
901
|
+
children: t2(`crm.lostReason.${key}`)
|
|
902
|
+
},
|
|
903
|
+
key
|
|
904
|
+
);
|
|
905
|
+
}) }),
|
|
906
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
907
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.card.lostReasonOther") }),
|
|
908
|
+
/* @__PURE__ */ jsx(
|
|
909
|
+
Input,
|
|
910
|
+
{
|
|
911
|
+
value: other,
|
|
912
|
+
onChange: (e) => {
|
|
913
|
+
setOther(e.target.value);
|
|
914
|
+
if (e.target.value) setPicked(void 0);
|
|
915
|
+
},
|
|
916
|
+
placeholder: t2("crm.card.lostReasonPrompt"),
|
|
917
|
+
className: "mt-1"
|
|
918
|
+
}
|
|
919
|
+
)
|
|
920
|
+
] })
|
|
921
|
+
] }),
|
|
922
|
+
/* @__PURE__ */ jsxs(ModalFooter, { children: [
|
|
923
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", disabled: saving, onClick: onCancel, children: t2("common.cancel") }),
|
|
924
|
+
/* @__PURE__ */ jsxs(Button, { variant: "destructive", disabled: saving, onClick: () => onConfirm(reason), children: [
|
|
925
|
+
/* @__PURE__ */ jsx(ThumbsDown, { className: "h-3.5 w-3.5" }),
|
|
926
|
+
" ",
|
|
927
|
+
t2("crm.card.lostReasonConfirm")
|
|
928
|
+
] })
|
|
929
|
+
] })
|
|
930
|
+
] }) });
|
|
868
931
|
}
|
|
869
932
|
|
|
870
933
|
// src/lib/relative-time.ts
|
|
@@ -960,6 +1023,56 @@ function dealHeadline(deal) {
|
|
|
960
1023
|
function dealHouseLine(deal) {
|
|
961
1024
|
return deal.groupName && deal.companyName ? deal.companyName : null;
|
|
962
1025
|
}
|
|
1026
|
+
function periodToRange(period, customFrom, customTo) {
|
|
1027
|
+
if (period === "all") return {};
|
|
1028
|
+
if (period === "24h") {
|
|
1029
|
+
return { createdFrom: new Date(Date.now() - 24 * 60 * 60 * 1e3).toISOString() };
|
|
1030
|
+
}
|
|
1031
|
+
if (period === "7d") {
|
|
1032
|
+
return { createdFrom: new Date(Date.now() - 7 * 24 * 60 * 60 * 1e3).toISOString() };
|
|
1033
|
+
}
|
|
1034
|
+
return {
|
|
1035
|
+
...customFrom ? { createdFrom: (/* @__PURE__ */ new Date(`${customFrom}T00:00:00`)).toISOString() } : {},
|
|
1036
|
+
...customTo ? { createdTo: (/* @__PURE__ */ new Date(`${customTo}T23:59:59.999`)).toISOString() } : {}
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/lib/board-filter.ts
|
|
1041
|
+
function buildBoardFilter(input) {
|
|
1042
|
+
const termo = input.search?.trim();
|
|
1043
|
+
return {
|
|
1044
|
+
...input.selectedTags.length ? { tags: input.selectedTags } : {},
|
|
1045
|
+
...termo ? {
|
|
1046
|
+
search: termo,
|
|
1047
|
+
// O de-para nome→slug mora do lado da tela porque é lá que o cadastro de
|
|
1048
|
+
// etiquetas está: procura-se por "Coorte 1" e o banco guarda o slug.
|
|
1049
|
+
searchTags: [...input.tagDefs?.values() ?? []].filter((d) => d.name.toLowerCase().includes(termo.toLowerCase())).map((d) => d.slug)
|
|
1050
|
+
} : {},
|
|
1051
|
+
...periodToRange(input.period, input.customFrom, input.customTo),
|
|
1052
|
+
...input.owner ? { assignedToId: input.owner } : {}
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
var CHAVES_DO_QUADRO = {
|
|
1056
|
+
owner: "crm.board.owner",
|
|
1057
|
+
period: "crm.board.period",
|
|
1058
|
+
customFrom: "crm.board.customFrom",
|
|
1059
|
+
customTo: "crm.board.customTo",
|
|
1060
|
+
tags: "crm.board.tags"
|
|
1061
|
+
};
|
|
1062
|
+
function useBoardFilterValue(myUserId) {
|
|
1063
|
+
const [owner] = usePersistedState(CHAVES_DO_QUADRO.owner, void 0);
|
|
1064
|
+
const [period] = usePersistedState(CHAVES_DO_QUADRO.period, "all");
|
|
1065
|
+
const [customFrom] = usePersistedState(CHAVES_DO_QUADRO.customFrom, "");
|
|
1066
|
+
const [customTo] = usePersistedState(CHAVES_DO_QUADRO.customTo, "");
|
|
1067
|
+
const [selectedTags] = usePersistedState(CHAVES_DO_QUADRO.tags, []);
|
|
1068
|
+
return buildBoardFilter({
|
|
1069
|
+
selectedTags,
|
|
1070
|
+
period,
|
|
1071
|
+
customFrom,
|
|
1072
|
+
customTo,
|
|
1073
|
+
owner: owner === "__me__" ? myUserId ?? void 0 : owner
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
963
1076
|
async function loadTeam() {
|
|
964
1077
|
const supabase = getSupabaseClientOptional();
|
|
965
1078
|
if (!supabase) return [];
|
|
@@ -995,6 +1108,302 @@ async function loadMyUserId() {
|
|
|
995
1108
|
return null;
|
|
996
1109
|
}
|
|
997
1110
|
}
|
|
1111
|
+
var INSTRUCTIONS = `Voc\xEA est\xE1 com o FUNIL do CRM aberto e \xE9 VOC\xCA quem desenha as etapas com a pessoa.
|
|
1112
|
+
|
|
1113
|
+
COMO CONDUZIR (o padr\xE3o desta tela):
|
|
1114
|
+
- N\xE3o pe\xE7a "quais etapas voc\xEA quer" \u2014 quem sabe responder isso n\xE3o precisava de voc\xEA. Pergunte como a casa VENDE e derive as etapas disso.
|
|
1115
|
+
- Fa\xE7a UMA pergunta por vez, no m\xE1ximo quatro no total, e sempre com exemplos para a pessoa s\xF3 escolher. Nesta ordem:
|
|
1116
|
+
1. O que voc\xEAs vendem, e para quem (empresa ou pessoa)?
|
|
1117
|
+
2. Como o cliente chega at\xE9 voc\xEAs (indica\xE7\xE3o, an\xFAncio, WhatsApp, loja)?
|
|
1118
|
+
3. O que precisa acontecer ANTES de mandar pre\xE7o \u2014 reuni\xE3o, visita, or\xE7amento, amostra?
|
|
1119
|
+
4. Quando a venda \xE9 ganha: assinatura, pagamento, primeira entrega?
|
|
1120
|
+
- Se a pessoa j\xE1 disser tudo na primeira mensagem, n\xE3o pergunte de novo: proponha.
|
|
1121
|
+
|
|
1122
|
+
O QUE PROPOR:
|
|
1123
|
+
- Entre 4 e 7 etapas. Menos que 4 n\xE3o mede nada; mais que 7 vira um quadro que ningu\xE9m arrasta.
|
|
1124
|
+
- Uma etapa \xE9 um ESTADO do neg\xF3cio ("Proposta enviada"), nunca uma tarefa ("Ligar").
|
|
1125
|
+
- Sempre exatamente uma etapa de entrada, uma de ganho e uma de perda. \`probability\` sobe do come\xE7o ao fim: entrada baixa (5\u201315), ganho 100, perda 0.
|
|
1126
|
+
- Liste as etapas na resposta, uma linha cada, E CHAME \`applyFunnelStages\` NA MESMA RESPOSTA. A lista \xE9 o texto do cart\xE3o de confirma\xE7\xE3o, n\xE3o um pedido de autoriza\xE7\xE3o \u2014 quem autoriza \xE9 o cart\xE3o que a ferramenta abre.
|
|
1127
|
+
- NUNCA termine um turno com "vou aplicar agora", "vou configurar" ou "j\xE1 configuro" sem ter chamado a ferramenta nesse mesmo turno. Anunciar sem chamar deixa a pessoa esperando por uma coisa que n\xE3o vai acontecer.
|
|
1128
|
+
|
|
1129
|
+
FERRAMENTAS:
|
|
1130
|
+
- \`applyFunnelStages\` \xE9 a que desenha o funil inteiro de uma vez. Mande a lista COMPLETA, na ordem: o que j\xE1 existe com o mesmo nome \xE9 atualizado, o que falta \xE9 criado.
|
|
1131
|
+
- \`replaceExisting: true\` remove as etapas que ficaram de fora. S\xF3 use quando a pessoa disser que o funil atual n\xE3o serve. Etapa com neg\xF3cio dentro NUNCA \xE9 removida \u2014 a ferramenta devolve quais sobraram e voc\xEA conta isso a ela.
|
|
1132
|
+
- \`renameFunnelStage\`, \`reorderFunnelStages\` e \`removeFunnelStage\` s\xE3o para ajuste pontual depois \u2014 nunca para montar o funil inteiro.
|
|
1133
|
+
- \`createFunnel\` s\xF3 quando a pessoa quiser um SEGUNDO funil (outra linha de neg\xF3cio, outro time). Ele j\xE1 nasce com tr\xEAs etapas; redesenhe-as com \`applyFunnelStages\`.
|
|
1134
|
+
|
|
1135
|
+
Nunca invente que configurou algo que a ferramenta n\xE3o devolveu \`ok\`. E n\xE3o mande a pessoa ir em Configura\xE7\xF5es fazer \xE0 m\xE3o o que voc\xEA acabou de receber ferramenta para fazer.`;
|
|
1136
|
+
function normalizeStageName(raw) {
|
|
1137
|
+
return (raw ?? "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim().toLowerCase().replace(/\s+/g, " ");
|
|
1138
|
+
}
|
|
1139
|
+
var STAGE_COLORS = ["#64748B", "#0EA5E9", "#6366F1", "#8B5CF6", "#F59E0B", "#EC4899"];
|
|
1140
|
+
var WON_COLOR = "#16A34A";
|
|
1141
|
+
var LOST_COLOR = "#DC2626";
|
|
1142
|
+
function normalizeProposal(stages) {
|
|
1143
|
+
const fixed = [];
|
|
1144
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1145
|
+
const clean = stages.map((s) => ({ ...s, name: (s.name ?? "").trim() })).filter((s) => {
|
|
1146
|
+
if (!s.name) return false;
|
|
1147
|
+
const key = normalizeStageName(s.name);
|
|
1148
|
+
if (seen.has(key)) {
|
|
1149
|
+
fixed.push(`etapa repetida descartada: "${s.name}"`);
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
seen.add(key);
|
|
1153
|
+
return true;
|
|
1154
|
+
});
|
|
1155
|
+
if (!clean.length) return { stages: [], fixed };
|
|
1156
|
+
let initialAt = clean.findIndex((s) => s.isInitial);
|
|
1157
|
+
if (initialAt < 0) {
|
|
1158
|
+
initialAt = 0;
|
|
1159
|
+
fixed.push(`sem etapa de entrada declarada: "${clean[0].name}" virou a entrada`);
|
|
1160
|
+
}
|
|
1161
|
+
let wonAt = clean.findIndex((s) => s.isWon);
|
|
1162
|
+
let lostAt = clean.findIndex((s) => s.isLost);
|
|
1163
|
+
if (wonAt < 0) {
|
|
1164
|
+
wonAt = clean.length - 1;
|
|
1165
|
+
fixed.push(`sem etapa de ganho: "${clean[wonAt].name}" virou o ganho`);
|
|
1166
|
+
}
|
|
1167
|
+
if (lostAt < 0) {
|
|
1168
|
+
clean.push({ name: "Perdido", isLost: true, probability: 0 });
|
|
1169
|
+
lostAt = clean.length - 1;
|
|
1170
|
+
fixed.push('sem etapa de perda: "Perdido" foi acrescentada');
|
|
1171
|
+
}
|
|
1172
|
+
let colorAt = 0;
|
|
1173
|
+
const out = clean.map((s, i) => {
|
|
1174
|
+
const isInitial = i === initialAt;
|
|
1175
|
+
const isWon = i === wonAt;
|
|
1176
|
+
const isLost = i === lostAt;
|
|
1177
|
+
const probability = isWon ? 100 : isLost ? 0 : typeof s.probability === "number" && s.probability >= 0 && s.probability <= 100 ? Math.round(s.probability) : Math.min(90, 10 + Math.round(i / Math.max(1, clean.length - 1) * 80));
|
|
1178
|
+
const color = s.color && /^#[0-9a-fA-F]{6}$/.test(s.color) ? s.color : isWon ? WON_COLOR : isLost ? LOST_COLOR : STAGE_COLORS[colorAt++ % STAGE_COLORS.length];
|
|
1179
|
+
return { name: s.name, probability, color, isInitial, isWon, isLost };
|
|
1180
|
+
});
|
|
1181
|
+
return { stages: out, fixed };
|
|
1182
|
+
}
|
|
1183
|
+
function tool(id, name, description, properties, required, requiresConfirmation = false) {
|
|
1184
|
+
return {
|
|
1185
|
+
id,
|
|
1186
|
+
name,
|
|
1187
|
+
description,
|
|
1188
|
+
mode: "persist",
|
|
1189
|
+
parameters: { type: "object", properties, required },
|
|
1190
|
+
execution: { plane: "client" },
|
|
1191
|
+
requiresConfirmation,
|
|
1192
|
+
permission: { feature: "sales", action: "edit" }
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
function usePipelineAgentSurface(deps) {
|
|
1196
|
+
const contribution = useMemo(() => {
|
|
1197
|
+
const activePipeline = deps.pipelines.find((p) => p.id === deps.activePipelineId);
|
|
1198
|
+
const findStage = (name) => {
|
|
1199
|
+
const key = normalizeStageName(name);
|
|
1200
|
+
return deps.stages.find((s) => normalizeStageName(s.name) === key) ?? deps.stages.find((s) => normalizeStageName(s.name).includes(key));
|
|
1201
|
+
};
|
|
1202
|
+
const requirePipeline = () => {
|
|
1203
|
+
if (!deps.activePipelineId) {
|
|
1204
|
+
return { error: "no_pipeline", message: "Nenhum funil aberto. Crie um com createFunnel." };
|
|
1205
|
+
}
|
|
1206
|
+
return deps.activePipelineId;
|
|
1207
|
+
};
|
|
1208
|
+
const tools = [
|
|
1209
|
+
{
|
|
1210
|
+
tool: tool(
|
|
1211
|
+
"crm.funnel.apply-stages",
|
|
1212
|
+
"applyFunnelStages",
|
|
1213
|
+
"Desenha o funil aberto: cria as etapas que faltam, atualiza as que j\xE1 existem (casadas pelo NOME) e p\xF5e tudo na ordem da lista. Mande a lista COMPLETA e final.",
|
|
1214
|
+
{
|
|
1215
|
+
stages: {
|
|
1216
|
+
type: "array",
|
|
1217
|
+
description: "As etapas, da primeira \xE0 \xFAltima. Entre 4 e 7.",
|
|
1218
|
+
items: {
|
|
1219
|
+
type: "object",
|
|
1220
|
+
properties: {
|
|
1221
|
+
name: { type: "string", description: 'O estado do neg\xF3cio, como a casa fala. Ex.: "Proposta enviada".' },
|
|
1222
|
+
probability: { type: "number", description: "Chance de fechar nesta etapa, 0 a 100. Cresce ao longo do funil." },
|
|
1223
|
+
color: { type: "string", description: "Cor hex (#RRGGBB). Opcional \u2014 sem ela a paleta da tela escolhe." },
|
|
1224
|
+
isInitial: { type: "boolean", description: "Onde o lead entra. Exatamente uma." },
|
|
1225
|
+
isWon: { type: "boolean", description: "Venda fechada. Exatamente uma." },
|
|
1226
|
+
isLost: { type: "boolean", description: "Neg\xF3cio perdido. Exatamente uma." }
|
|
1227
|
+
},
|
|
1228
|
+
required: ["name"]
|
|
1229
|
+
}
|
|
1230
|
+
},
|
|
1231
|
+
replaceExisting: {
|
|
1232
|
+
type: "boolean",
|
|
1233
|
+
description: "Remove as etapas atuais que n\xE3o est\xE3o na lista. Etapa com neg\xF3cio dentro \xE9 mantida e devolvida em `kept`."
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
["stages"],
|
|
1237
|
+
// O único write que redesenha o quadro inteiro. O cartão de
|
|
1238
|
+
// confirmação é onde a pessoa lê as seis etapas como lista antes de
|
|
1239
|
+
// elas existirem — a decisão é dela, não da conversa.
|
|
1240
|
+
true
|
|
1241
|
+
),
|
|
1242
|
+
execute: async ({ stages, replaceExisting }) => {
|
|
1243
|
+
const pipelineId = requirePipeline();
|
|
1244
|
+
if (typeof pipelineId !== "string") return pipelineId;
|
|
1245
|
+
const proposal = normalizeProposal(stages ?? []);
|
|
1246
|
+
if (!proposal.stages.length) return { error: "empty_proposal" };
|
|
1247
|
+
const before = deps.stages;
|
|
1248
|
+
const created = [];
|
|
1249
|
+
const updated = [];
|
|
1250
|
+
const orderedIds = [];
|
|
1251
|
+
for (const [i, s] of proposal.stages.entries()) {
|
|
1252
|
+
const existing = before.find((e) => normalizeStageName(e.name) === normalizeStageName(s.name));
|
|
1253
|
+
const saved = await deps.provider.saveStage({
|
|
1254
|
+
...existing ? { id: existing.id } : {},
|
|
1255
|
+
pipelineId,
|
|
1256
|
+
name: s.name,
|
|
1257
|
+
color: s.color,
|
|
1258
|
+
probability: s.probability,
|
|
1259
|
+
isInitial: s.isInitial,
|
|
1260
|
+
isWon: s.isWon,
|
|
1261
|
+
isLost: s.isLost,
|
|
1262
|
+
order: i + 1
|
|
1263
|
+
});
|
|
1264
|
+
orderedIds.push(saved.id);
|
|
1265
|
+
(existing ? updated : created).push(s.name);
|
|
1266
|
+
}
|
|
1267
|
+
const removed = [];
|
|
1268
|
+
const kept = [];
|
|
1269
|
+
if (replaceExisting === true) {
|
|
1270
|
+
const keepIds = new Set(orderedIds);
|
|
1271
|
+
for (const stage of before) {
|
|
1272
|
+
if (keepIds.has(stage.id)) continue;
|
|
1273
|
+
try {
|
|
1274
|
+
await deps.provider.deleteStage(stage.id);
|
|
1275
|
+
removed.push(stage.name);
|
|
1276
|
+
} catch {
|
|
1277
|
+
kept.push(`${stage.name} (${deps.dealCountByStage.get(stage.id) ?? 0} neg\xF3cio(s))`);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
await deps.provider.reorderStages(pipelineId, orderedIds);
|
|
1282
|
+
await deps.refresh();
|
|
1283
|
+
return {
|
|
1284
|
+
ok: true,
|
|
1285
|
+
funnel: activePipeline?.name,
|
|
1286
|
+
stages: proposal.stages.map((s) => s.name),
|
|
1287
|
+
created,
|
|
1288
|
+
updated,
|
|
1289
|
+
...removed.length ? { removed } : {},
|
|
1290
|
+
...kept.length ? { kept } : {},
|
|
1291
|
+
...proposal.fixed.length ? { adjusted: proposal.fixed } : {}
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
{
|
|
1296
|
+
tool: tool(
|
|
1297
|
+
"crm.funnel.rename-stage",
|
|
1298
|
+
"renameFunnelStage",
|
|
1299
|
+
"Renomeia UMA etapa do funil aberto. O c\xF3digo interno n\xE3o muda, ent\xE3o nenhuma automa\xE7\xE3o apontada para ela quebra.",
|
|
1300
|
+
{
|
|
1301
|
+
currentName: { type: "string" },
|
|
1302
|
+
newName: { type: "string" }
|
|
1303
|
+
},
|
|
1304
|
+
["currentName", "newName"]
|
|
1305
|
+
),
|
|
1306
|
+
execute: async ({ currentName, newName }) => {
|
|
1307
|
+
const pipelineId = requirePipeline();
|
|
1308
|
+
if (typeof pipelineId !== "string") return pipelineId;
|
|
1309
|
+
const stage = findStage(String(currentName ?? ""));
|
|
1310
|
+
if (!stage) return { error: "stage_not_found", currentName, available: deps.stages.map((s) => s.name) };
|
|
1311
|
+
await deps.provider.saveStage({ id: stage.id, pipelineId, name: String(newName ?? "").trim() });
|
|
1312
|
+
await deps.refresh();
|
|
1313
|
+
return { ok: true, from: stage.name, to: newName };
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
tool: tool(
|
|
1318
|
+
"crm.funnel.reorder-stages",
|
|
1319
|
+
"reorderFunnelStages",
|
|
1320
|
+
"P\xF5e as etapas do funil aberto nesta ordem. Mande TODOS os nomes \u2014 o que ficar de fora vai para o fim.",
|
|
1321
|
+
{ orderedNames: { type: "array", items: { type: "string" } } },
|
|
1322
|
+
["orderedNames"]
|
|
1323
|
+
),
|
|
1324
|
+
execute: async ({ orderedNames }) => {
|
|
1325
|
+
const pipelineId = requirePipeline();
|
|
1326
|
+
if (typeof pipelineId !== "string") return pipelineId;
|
|
1327
|
+
const named = (orderedNames ?? []).map((n) => findStage(n)).filter((s) => !!s);
|
|
1328
|
+
const missing = (orderedNames ?? []).filter((n) => !findStage(n));
|
|
1329
|
+
const rest = deps.stages.filter((s) => !named.some((n) => n.id === s.id));
|
|
1330
|
+
if (!named.length) return { error: "no_match", available: deps.stages.map((s) => s.name) };
|
|
1331
|
+
await deps.provider.reorderStages(pipelineId, [...named, ...rest].map((s) => s.id));
|
|
1332
|
+
await deps.refresh();
|
|
1333
|
+
return { ok: true, order: [...named, ...rest].map((s) => s.name), ...missing.length ? { unknown: missing } : {} };
|
|
1334
|
+
}
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
tool: tool(
|
|
1338
|
+
"crm.funnel.remove-stage",
|
|
1339
|
+
"removeFunnelStage",
|
|
1340
|
+
"Remove UMA etapa do funil aberto. Recusa quando a etapa tem neg\xF3cio dentro \u2014 mova os cards primeiro.",
|
|
1341
|
+
{ name: { type: "string" } },
|
|
1342
|
+
["name"],
|
|
1343
|
+
true
|
|
1344
|
+
),
|
|
1345
|
+
execute: async ({ name }) => {
|
|
1346
|
+
const stage = findStage(String(name ?? ""));
|
|
1347
|
+
if (!stage) return { error: "stage_not_found", name, available: deps.stages.map((s) => s.name) };
|
|
1348
|
+
try {
|
|
1349
|
+
await deps.provider.deleteStage(stage.id);
|
|
1350
|
+
} catch (e) {
|
|
1351
|
+
return { error: "stage_has_deals", name: stage.name, deals: deps.dealCountByStage.get(stage.id) ?? 0, message: e.message };
|
|
1352
|
+
}
|
|
1353
|
+
await deps.refresh();
|
|
1354
|
+
return { ok: true, removed: stage.name };
|
|
1355
|
+
}
|
|
1356
|
+
},
|
|
1357
|
+
{
|
|
1358
|
+
tool: tool(
|
|
1359
|
+
"crm.funnel.create",
|
|
1360
|
+
"createFunnel",
|
|
1361
|
+
"Cria um SEGUNDO funil (outra linha de neg\xF3cio, outro time). Nasce com tr\xEAs etapas padr\xE3o \u2014 redesenhe com applyFunnelStages depois.",
|
|
1362
|
+
{
|
|
1363
|
+
name: { type: "string" },
|
|
1364
|
+
makeDefault: { type: "boolean", description: "Passa a ser o funil padr\xE3o da casa." }
|
|
1365
|
+
},
|
|
1366
|
+
["name"],
|
|
1367
|
+
true
|
|
1368
|
+
),
|
|
1369
|
+
execute: async ({ name, makeDefault }) => {
|
|
1370
|
+
const created = await deps.provider.savePipeline({
|
|
1371
|
+
name: String(name ?? "").trim(),
|
|
1372
|
+
...makeDefault === true ? { isDefault: true } : {}
|
|
1373
|
+
});
|
|
1374
|
+
await deps.refresh();
|
|
1375
|
+
return { ok: true, funnel: created.name, id: created.id };
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
];
|
|
1379
|
+
return {
|
|
1380
|
+
id: "crm.funnel",
|
|
1381
|
+
pluginId: "crm",
|
|
1382
|
+
instructions: INSTRUCTIONS,
|
|
1383
|
+
tools,
|
|
1384
|
+
describe: () => ({
|
|
1385
|
+
title: activePipeline ? `Funil \u2014 ${activePipeline.name}` : "Funil do CRM",
|
|
1386
|
+
state: {
|
|
1387
|
+
funnel: activePipeline?.name,
|
|
1388
|
+
allFunnels: deps.pipelines.map((p) => p.name),
|
|
1389
|
+
// O estado que decide a conversa: um funil ainda no padrão de fábrica
|
|
1390
|
+
// (Novo / Ganho / Perdido) é o caso que esta tela existe para
|
|
1391
|
+
// resolver, e o modelo precisa reconhecê-lo sem perguntar.
|
|
1392
|
+
stages: deps.stages.map((s) => ({
|
|
1393
|
+
name: s.name,
|
|
1394
|
+
probability: s.probability,
|
|
1395
|
+
entry: s.isInitial || void 0,
|
|
1396
|
+
won: s.isWon || void 0,
|
|
1397
|
+
lost: s.isLost || void 0,
|
|
1398
|
+
openDeals: deps.dealCountByStage.get(s.id) ?? 0
|
|
1399
|
+
})),
|
|
1400
|
+
looksUnconfigured: deps.stages.length > 0 && deps.stages.length <= 3
|
|
1401
|
+
}
|
|
1402
|
+
})
|
|
1403
|
+
};
|
|
1404
|
+
}, [deps.provider, deps.pipelines, deps.activePipelineId, deps.stages, deps.dealCountByStage, deps.refresh]);
|
|
1405
|
+
useAgentSurface(contribution);
|
|
1406
|
+
}
|
|
998
1407
|
var CHIP_ROW = "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted";
|
|
999
1408
|
function BoardFilterChip({ trigger, onClear, clearLabel, closeOnSelect, children }) {
|
|
1000
1409
|
const [open, setOpen] = React.useState(false);
|
|
@@ -1226,7 +1635,11 @@ function DealCard({ deal, saving, currency, tagDefs, temperature, risk, display,
|
|
|
1226
1635
|
}
|
|
1227
1636
|
),
|
|
1228
1637
|
display.contact && deal.contactStatusName && deal.contactStatusDerivedFrom !== "no_activity" && /* @__PURE__ */ jsx(DotChip, { color: deal.contactStatusColor ?? "#64748b", label: deal.contactStatusName }),
|
|
1229
|
-
display.tags && /* @__PURE__ */ jsx(TagChips, { tags: deal.tags, defs: tagDefs, max: 3 })
|
|
1638
|
+
display.tags && /* @__PURE__ */ jsx(TagChips, { tags: deal.tags, defs: tagDefs, max: 3 }),
|
|
1639
|
+
deal.status === "lost" && deal.lostReason && /* @__PURE__ */ jsxs("span", { className: "inline-flex h-[18px] items-center gap-1 rounded-full bg-destructive-soft px-1.5 text-[9px] font-medium text-destructive-soft-foreground", children: [
|
|
1640
|
+
/* @__PURE__ */ jsx(ThumbsDown, { className: "h-2.5 w-2.5 shrink-0" }),
|
|
1641
|
+
lostReasonLabel(deal.lostReason, t2)
|
|
1642
|
+
] })
|
|
1230
1643
|
] }),
|
|
1231
1644
|
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-between gap-2 empty:mt-0", children: [
|
|
1232
1645
|
display.value && deal.value > 0 ? /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold", children: formatCurrency(deal.value, currency) }) : /* @__PURE__ */ jsx("span", {}),
|
|
@@ -1405,10 +1818,11 @@ function StageCards({ stageId, deals, total, onLoadMore, loadMoreLabel, savingDe
|
|
|
1405
1818
|
)
|
|
1406
1819
|
] });
|
|
1407
1820
|
}
|
|
1408
|
-
function PipelineView({ onDealClick, onAddLead, onOpenSettings,
|
|
1821
|
+
function PipelineView({ onDealClick, onAddLead, onOpenSettings, onStageIntent }) {
|
|
1409
1822
|
const { currency } = useCrmConfig();
|
|
1410
1823
|
const pipelines = useCrmStore((s) => s.pipelines);
|
|
1411
1824
|
const activePipelineId = useCrmStore((s) => s.activePipelineId);
|
|
1825
|
+
const stagesPipelineId = useCrmStore((s) => s.stagesPipelineId);
|
|
1412
1826
|
const stages = useCrmStore((s) => s.stages);
|
|
1413
1827
|
const dealsByStage = useCrmStore((s) => s.dealsByStage);
|
|
1414
1828
|
const dealStageTotals = useCrmStore((s) => s.dealStageTotals);
|
|
@@ -1429,6 +1843,7 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1429
1843
|
const canArchive = useCanArchive();
|
|
1430
1844
|
const provider = useCrmProvider();
|
|
1431
1845
|
const [menu, setMenu] = useState(null);
|
|
1846
|
+
const [pendingLost, setPendingLost] = useState(null);
|
|
1432
1847
|
const [team, setTeam] = useState(null);
|
|
1433
1848
|
useEffect(() => {
|
|
1434
1849
|
void loadTeamOrNull().then(setTeam);
|
|
@@ -1457,18 +1872,41 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1457
1872
|
const [savingDealIds, setSavingDealIds] = useState(/* @__PURE__ */ new Set());
|
|
1458
1873
|
const [optimisticBoard, setOptimisticBoard] = useState(null);
|
|
1459
1874
|
const t2 = useTranslation();
|
|
1875
|
+
const refreshFunnel = useCallback(async () => {
|
|
1876
|
+
await fetchPipelines();
|
|
1877
|
+
await refreshBoard();
|
|
1878
|
+
}, [fetchPipelines, refreshBoard]);
|
|
1879
|
+
usePipelineAgentSurface({
|
|
1880
|
+
provider,
|
|
1881
|
+
pipelines,
|
|
1882
|
+
activePipelineId,
|
|
1883
|
+
stages,
|
|
1884
|
+
dealCountByStage: dealStageTotals,
|
|
1885
|
+
refresh: refreshFunnel
|
|
1886
|
+
});
|
|
1887
|
+
const funnelAI = {
|
|
1888
|
+
prompt: t2("crm.pipeline.ai.prompt"),
|
|
1889
|
+
hint: t2("crm.pipeline.ai.hint"),
|
|
1890
|
+
intro: {
|
|
1891
|
+
pitch: t2("crm.pipeline.ai.pitch"),
|
|
1892
|
+
description: t2("crm.pipeline.ai.description"),
|
|
1893
|
+
suggestions: [
|
|
1894
|
+
{ label: t2("crm.pipeline.ai.suggestionDescribe") },
|
|
1895
|
+
{ label: t2("crm.pipeline.ai.suggestionReview") }
|
|
1896
|
+
]
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1460
1899
|
const dragRef = useRef(null);
|
|
1461
1900
|
const savingRef = useRef(savingDealIds);
|
|
1462
1901
|
savingRef.current = savingDealIds;
|
|
1463
|
-
const boardFilter = useMemo(() => ({
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
...effectiveOwner ? { assignedToId: effectiveOwner } : {}
|
|
1902
|
+
const boardFilter = useMemo(() => buildBoardFilter({
|
|
1903
|
+
selectedTags,
|
|
1904
|
+
search: searchNoBanco,
|
|
1905
|
+
tagDefs,
|
|
1906
|
+
period,
|
|
1907
|
+
customFrom,
|
|
1908
|
+
customTo,
|
|
1909
|
+
owner: effectiveOwner
|
|
1472
1910
|
}), [selectedTags, searchNoBanco, tagDefs, period, customFrom, customTo, effectiveOwner]);
|
|
1473
1911
|
const filterKey = JSON.stringify(boardFilter);
|
|
1474
1912
|
const availableTags = useMemo(() => [...tagDefs.keys()], [tagDefs]);
|
|
@@ -1556,7 +1994,7 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1556
1994
|
if (!c) return false;
|
|
1557
1995
|
return !c.phone && !c.email;
|
|
1558
1996
|
}, [channels]);
|
|
1559
|
-
const visibleStages = stages
|
|
1997
|
+
const visibleStages = stages;
|
|
1560
1998
|
const rawBoard = optimisticBoard ?? dealsByStage;
|
|
1561
1999
|
const query = useMemo(() => prepareDealQuery(search), [search]);
|
|
1562
2000
|
const displayBoard = useMemo(() => {
|
|
@@ -1567,7 +2005,8 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1567
2005
|
}
|
|
1568
2006
|
return next;
|
|
1569
2007
|
}, [rawBoard, query, tagDefs, unreachable]);
|
|
1570
|
-
const
|
|
2008
|
+
const stagesLoadedForActive = !!activePipelineId && stagesPipelineId === activePipelineId;
|
|
2009
|
+
const boardPending = dealsByStage.size === 0 && (pipelinesLoading || dealsLoading || pipelines.length > 0 && !stagesLoadedForActive);
|
|
1571
2010
|
function handleDragStart(dealId, fromStageId) {
|
|
1572
2011
|
dragRef.current = { dealId, fromStageId };
|
|
1573
2012
|
}
|
|
@@ -1582,6 +2021,21 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1582
2021
|
}
|
|
1583
2022
|
function commitMove(dealId, fromStageId, toStageId) {
|
|
1584
2023
|
if (fromStageId === toStageId) return;
|
|
2024
|
+
const target = stages.find((s) => s.id === toStageId);
|
|
2025
|
+
if (target?.isLost) {
|
|
2026
|
+
setPendingLost({ dealId, fromStageId, toStageId });
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
if (onStageIntent && !target?.isWon) {
|
|
2030
|
+
const card = (optimisticBoard ?? dealsByStage).get(fromStageId)?.find((d) => d.id === dealId);
|
|
2031
|
+
if (card && target) {
|
|
2032
|
+
onStageIntent(card, target);
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
applyMove(dealId, fromStageId, toStageId);
|
|
2037
|
+
}
|
|
2038
|
+
function applyMove(dealId, fromStageId, toStageId, lostReason) {
|
|
1585
2039
|
const targetStage = stages.find((s) => s.id === toStageId);
|
|
1586
2040
|
const currentBoard = optimisticBoard ?? dealsByStage;
|
|
1587
2041
|
const nextBoard = new Map(currentBoard);
|
|
@@ -1590,6 +2044,8 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1590
2044
|
if (!movedDeal) return;
|
|
1591
2045
|
const updatedDeal = {
|
|
1592
2046
|
...movedDeal,
|
|
2047
|
+
status: targetStage?.isWon ? "won" : targetStage?.isLost ? "lost" : "open",
|
|
2048
|
+
lostReason: targetStage?.isLost ? lostReason : void 0,
|
|
1593
2049
|
stageId: toStageId,
|
|
1594
2050
|
stageName: targetStage?.name,
|
|
1595
2051
|
stageColor: targetStage?.color,
|
|
@@ -1599,7 +2055,12 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1599
2055
|
nextBoard.set(toStageId, [...nextBoard.get(toStageId) ?? [], updatedDeal]);
|
|
1600
2056
|
setOptimisticBoard(nextBoard);
|
|
1601
2057
|
setSavingDealIds((prev) => new Set(prev).add(dealId));
|
|
1602
|
-
moveDealToStage(dealId, toStageId).then(() => {
|
|
2058
|
+
moveDealToStage(dealId, toStageId).then(async () => {
|
|
2059
|
+
const reasonWrite = targetStage?.isLost ? lostReason : movedDeal.lostReason ? "" : void 0;
|
|
2060
|
+
if (reasonWrite !== void 0) {
|
|
2061
|
+
await provider.updateDeal(dealId, { lostReason: reasonWrite });
|
|
2062
|
+
patchBoardDeal(dealId, { lostReason: reasonWrite || void 0 });
|
|
2063
|
+
}
|
|
1603
2064
|
toast.success(t2("crm.pipeline.movedTo", { stage: targetStage?.name ?? "stage" }));
|
|
1604
2065
|
}).catch(() => {
|
|
1605
2066
|
setOptimisticBoard(null);
|
|
@@ -1652,196 +2113,193 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1652
2113
|
setMenu({ x: e.clientX, y: e.clientY, deal, mode });
|
|
1653
2114
|
}
|
|
1654
2115
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
1655
|
-
/* @__PURE__ */
|
|
1656
|
-
/* @__PURE__ */
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
t2("crm.leads.filters.mine"),
|
|
1673
|
-
effectiveOwner === myUserId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1674
|
-
] }),
|
|
1675
|
-
/* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setOwnerFilter("none"), children: [
|
|
1676
|
-
/* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3 text-muted-foreground" }),
|
|
1677
|
-
" ",
|
|
1678
|
-
t2("crm.leads.filters.unassigned"),
|
|
1679
|
-
effectiveOwner === "none" && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1680
|
-
] }),
|
|
1681
|
-
(team ?? []).filter((m) => m.userId !== myUserId).map((m) => /* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setOwnerFilter(m.userId), children: [
|
|
1682
|
-
/* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
|
|
1683
|
-
" ",
|
|
1684
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children: m.name }),
|
|
1685
|
-
effectiveOwner === m.userId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1686
|
-
] }, m.userId))
|
|
1687
|
-
]
|
|
1688
|
-
}
|
|
1689
|
-
),
|
|
1690
|
-
period !== "all" && /* @__PURE__ */ jsx(
|
|
1691
|
-
BoardFilterChip,
|
|
1692
|
-
{
|
|
1693
|
-
closeOnSelect: true,
|
|
1694
|
-
clearLabel: t2("crm.board.clearFilters"),
|
|
1695
|
-
onClear: () => setPeriod("all"),
|
|
1696
|
-
trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1697
|
-
/* @__PURE__ */ jsx(CalendarDays, { className: "h-3 w-3" }),
|
|
1698
|
-
t2(`crm.filters.period${period === "custom" ? "Custom" : period}`)
|
|
1699
|
-
] }),
|
|
1700
|
-
children: ["24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setPeriod(p), children: [
|
|
1701
|
-
t2(`crm.filters.period${p === "custom" ? "Custom" : p}`),
|
|
1702
|
-
period === p && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1703
|
-
] }, p))
|
|
1704
|
-
}
|
|
1705
|
-
),
|
|
1706
|
-
selectedTags.length > 0 && /* @__PURE__ */ jsx(
|
|
1707
|
-
BoardFilterChip,
|
|
1708
|
-
{
|
|
1709
|
-
clearLabel: t2("crm.board.clearFilters"),
|
|
1710
|
-
onClear: () => setSelectedTags([]),
|
|
1711
|
-
trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1712
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(selectedTags[0])?.color ?? "#94A3B8" } }),
|
|
1713
|
-
/* @__PURE__ */ jsxs("span", { className: "max-w-[8rem] truncate", children: [
|
|
1714
|
-
tagDefs.get(selectedTags[0])?.name ?? humanizeTag(selectedTags[0]),
|
|
1715
|
-
selectedTags.length > 1 ? ` +${selectedTags.length - 1}` : ""
|
|
1716
|
-
] })
|
|
2116
|
+
/* @__PURE__ */ jsx(PageViewBar, { children: /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
2117
|
+
effectiveOwner && /* @__PURE__ */ jsxs(
|
|
2118
|
+
BoardFilterChip,
|
|
2119
|
+
{
|
|
2120
|
+
closeOnSelect: true,
|
|
2121
|
+
clearLabel: t2("crm.board.clearFilters"),
|
|
2122
|
+
onClear: () => setOwnerFilter(void 0),
|
|
2123
|
+
trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2124
|
+
effectiveOwner === "none" ? /* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? "Eu", size: "xs" }),
|
|
2125
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[8rem] truncate", children: effectiveOwner === "none" ? t2("crm.leads.filters.unassigned") : effectiveOwner === myUserId ? t2("crm.leads.filters.mine") : (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? t2("crm.leads.filters.owner") })
|
|
2126
|
+
] }),
|
|
2127
|
+
children: [
|
|
2128
|
+
myUserId && /* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setOwnerFilter("__me__"), children: [
|
|
2129
|
+
/* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === myUserId)?.name ?? "Eu", size: "xs" }),
|
|
2130
|
+
" ",
|
|
2131
|
+
t2("crm.leads.filters.mine"),
|
|
2132
|
+
effectiveOwner === myUserId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1717
2133
|
] }),
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
className: CHIP_ROW,
|
|
1724
|
-
onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
|
|
1725
|
-
children: [
|
|
1726
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
|
|
1727
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) }),
|
|
1728
|
-
on && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1729
|
-
]
|
|
1730
|
-
},
|
|
1731
|
-
slug
|
|
1732
|
-
);
|
|
1733
|
-
})
|
|
1734
|
-
}
|
|
1735
|
-
),
|
|
1736
|
-
/* @__PURE__ */ jsx(
|
|
1737
|
-
FilterMenu,
|
|
1738
|
-
{
|
|
1739
|
-
label: t2("crm.board.filters"),
|
|
1740
|
-
activeCount: (period !== "all" ? 1 : 0) + (selectedTags.length ? 1 : 0) + (search.trim() ? 1 : 0) + (effectiveOwner ? 1 : 0),
|
|
1741
|
-
onClear: () => {
|
|
1742
|
-
setSearch("");
|
|
1743
|
-
setPeriod("all");
|
|
1744
|
-
setSelectedTags([]);
|
|
1745
|
-
setOwnerFilter(void 0);
|
|
1746
|
-
},
|
|
1747
|
-
clearLabel: t2("crm.board.clearFilters"),
|
|
1748
|
-
header: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
1749
|
-
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
|
|
1750
|
-
/* @__PURE__ */ jsx(
|
|
1751
|
-
"input",
|
|
1752
|
-
{
|
|
1753
|
-
type: "text",
|
|
1754
|
-
value: search,
|
|
1755
|
-
onChange: (e) => setSearch(e.target.value),
|
|
1756
|
-
placeholder: t2("crm.deals.searchPlaceholder"),
|
|
1757
|
-
className: "h-8 w-full rounded-input border bg-background pl-8 pr-3 text-xs outline-none placeholder:text-muted-foreground/70 focus:ring-2 focus:ring-ring"
|
|
1758
|
-
}
|
|
1759
|
-
)
|
|
2134
|
+
/* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setOwnerFilter("none"), children: [
|
|
2135
|
+
/* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3 text-muted-foreground" }),
|
|
2136
|
+
" ",
|
|
2137
|
+
t2("crm.leads.filters.unassigned"),
|
|
2138
|
+
effectiveOwner === "none" && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
1760
2139
|
] }),
|
|
1761
|
-
|
|
1762
|
-
{
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
2140
|
+
(team ?? []).filter((m) => m.userId !== myUserId).map((m) => /* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setOwnerFilter(m.userId), children: [
|
|
2141
|
+
/* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
|
|
2142
|
+
" ",
|
|
2143
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: m.name }),
|
|
2144
|
+
effectiveOwner === m.userId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
2145
|
+
] }, m.userId))
|
|
2146
|
+
]
|
|
2147
|
+
}
|
|
2148
|
+
),
|
|
2149
|
+
period !== "all" && /* @__PURE__ */ jsx(
|
|
2150
|
+
BoardFilterChip,
|
|
2151
|
+
{
|
|
2152
|
+
closeOnSelect: true,
|
|
2153
|
+
clearLabel: t2("crm.board.clearFilters"),
|
|
2154
|
+
onClear: () => setPeriod("all"),
|
|
2155
|
+
trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2156
|
+
/* @__PURE__ */ jsx(CalendarDays, { className: "h-3 w-3" }),
|
|
2157
|
+
t2(`crm.filters.period${period === "custom" ? "Custom" : period}`)
|
|
2158
|
+
] }),
|
|
2159
|
+
children: ["24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsxs("button", { className: CHIP_ROW, onClick: () => setPeriod(p), children: [
|
|
2160
|
+
t2(`crm.filters.period${p === "custom" ? "Custom" : p}`),
|
|
2161
|
+
period === p && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
2162
|
+
] }, p))
|
|
2163
|
+
}
|
|
2164
|
+
),
|
|
2165
|
+
selectedTags.length > 0 && /* @__PURE__ */ jsx(
|
|
2166
|
+
BoardFilterChip,
|
|
2167
|
+
{
|
|
2168
|
+
clearLabel: t2("crm.board.clearFilters"),
|
|
2169
|
+
onClear: () => setSelectedTags([]),
|
|
2170
|
+
trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2171
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(selectedTags[0])?.color ?? "#94A3B8" } }),
|
|
2172
|
+
/* @__PURE__ */ jsxs("span", { className: "max-w-[8rem] truncate", children: [
|
|
2173
|
+
tagDefs.get(selectedTags[0])?.name ?? humanizeTag(selectedTags[0]),
|
|
2174
|
+
selectedTags.length > 1 ? ` +${selectedTags.length - 1}` : ""
|
|
2175
|
+
] })
|
|
2176
|
+
] }),
|
|
2177
|
+
children: [.../* @__PURE__ */ new Set([...availableTags, ...selectedTags])].sort((a, b) => (tagDefs.get(a)?.name ?? humanizeTag(a)).localeCompare(tagDefs.get(b)?.name ?? humanizeTag(b))).map((slug) => {
|
|
2178
|
+
const on = selectedTags.includes(slug);
|
|
2179
|
+
return /* @__PURE__ */ jsxs(
|
|
2180
|
+
"button",
|
|
1801
2181
|
{
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
if (p !== "custom") close();
|
|
1810
|
-
}, children: t2(`crm.filters.period${p === "all" ? "All" : p === "custom" ? "Custom" : p}`) }, p)),
|
|
1811
|
-
period === "custom" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 p-1.5", children: [
|
|
1812
|
-
/* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customFrom, onChange: setCustomFrom }),
|
|
1813
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2013" }),
|
|
1814
|
-
/* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customTo, onChange: setCustomTo })
|
|
1815
|
-
] })
|
|
1816
|
-
] })
|
|
2182
|
+
className: CHIP_ROW,
|
|
2183
|
+
onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
|
|
2184
|
+
children: [
|
|
2185
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
|
|
2186
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) }),
|
|
2187
|
+
on && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
2188
|
+
]
|
|
1817
2189
|
},
|
|
2190
|
+
slug
|
|
2191
|
+
);
|
|
2192
|
+
})
|
|
2193
|
+
}
|
|
2194
|
+
),
|
|
2195
|
+
/* @__PURE__ */ jsx(
|
|
2196
|
+
FilterMenu,
|
|
2197
|
+
{
|
|
2198
|
+
label: t2("crm.board.filters"),
|
|
2199
|
+
activeCount: (period !== "all" ? 1 : 0) + (selectedTags.length ? 1 : 0) + (search.trim() ? 1 : 0) + (effectiveOwner ? 1 : 0),
|
|
2200
|
+
onClear: () => {
|
|
2201
|
+
setSearch("");
|
|
2202
|
+
setPeriod("all");
|
|
2203
|
+
setSelectedTags([]);
|
|
2204
|
+
setOwnerFilter(void 0);
|
|
2205
|
+
},
|
|
2206
|
+
clearLabel: t2("crm.board.clearFilters"),
|
|
2207
|
+
header: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
2208
|
+
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
|
|
2209
|
+
/* @__PURE__ */ jsx(
|
|
2210
|
+
"input",
|
|
1818
2211
|
{
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
const on = selectedTags.includes(slug);
|
|
1825
|
-
return /* @__PURE__ */ jsxs(
|
|
1826
|
-
FilterMenuRow,
|
|
1827
|
-
{
|
|
1828
|
-
active: on,
|
|
1829
|
-
onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
|
|
1830
|
-
children: [
|
|
1831
|
-
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
|
|
1832
|
-
/* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) })
|
|
1833
|
-
]
|
|
1834
|
-
},
|
|
1835
|
-
slug
|
|
1836
|
-
);
|
|
1837
|
-
}) })
|
|
2212
|
+
type: "text",
|
|
2213
|
+
value: search,
|
|
2214
|
+
onChange: (e) => setSearch(e.target.value),
|
|
2215
|
+
placeholder: t2("crm.deals.searchPlaceholder"),
|
|
2216
|
+
className: "h-8 w-full rounded-input border bg-background pl-8 pr-3 text-xs outline-none placeholder:text-muted-foreground/70 focus:ring-2 focus:ring-ring"
|
|
1838
2217
|
}
|
|
1839
|
-
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2218
|
+
)
|
|
2219
|
+
] }),
|
|
2220
|
+
fields: [
|
|
2221
|
+
{
|
|
2222
|
+
id: "owner",
|
|
2223
|
+
label: t2("crm.leads.filters.owner"),
|
|
2224
|
+
icon: UserRound,
|
|
2225
|
+
activeCount: effectiveOwner ? 1 : 0,
|
|
2226
|
+
searchable: true,
|
|
2227
|
+
render: (close, q) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2228
|
+
/* @__PURE__ */ jsxs(FilterMenuRow, { active: !effectiveOwner, onClick: () => {
|
|
2229
|
+
setOwnerFilter(void 0);
|
|
2230
|
+
close();
|
|
2231
|
+
}, children: [
|
|
2232
|
+
/* @__PURE__ */ jsx(UserRound, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
2233
|
+
" ",
|
|
2234
|
+
t2("crm.leads.filters.allOwners")
|
|
2235
|
+
] }),
|
|
2236
|
+
myUserId && /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === myUserId, onClick: () => {
|
|
2237
|
+
setOwnerFilter("__me__");
|
|
2238
|
+
close();
|
|
2239
|
+
}, children: [
|
|
2240
|
+
/* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === myUserId)?.name ?? "Eu", size: "xs" }),
|
|
2241
|
+
" ",
|
|
2242
|
+
t2("crm.leads.filters.mine")
|
|
2243
|
+
] }),
|
|
2244
|
+
/* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === "none", onClick: () => {
|
|
2245
|
+
setOwnerFilter("none");
|
|
2246
|
+
close();
|
|
2247
|
+
}, children: [
|
|
2248
|
+
/* @__PURE__ */ jsx("span", { className: "flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-muted-foreground/50", children: /* @__PURE__ */ jsx(UserRound, { className: "h-2.5 w-2.5 text-muted-foreground" }) }),
|
|
2249
|
+
t2("crm.leads.filters.unassigned")
|
|
2250
|
+
] }),
|
|
2251
|
+
(team ?? []).filter((m) => m.userId !== myUserId && m.name.toLowerCase().includes(q.toLowerCase())).map((m) => /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === m.userId, onClick: () => {
|
|
2252
|
+
setOwnerFilter(m.userId);
|
|
2253
|
+
close();
|
|
2254
|
+
}, children: [
|
|
2255
|
+
/* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
|
|
2256
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: m.name })
|
|
2257
|
+
] }, m.userId))
|
|
2258
|
+
] })
|
|
2259
|
+
},
|
|
2260
|
+
{
|
|
2261
|
+
id: "period",
|
|
2262
|
+
label: t2("crm.filters.period"),
|
|
2263
|
+
icon: CalendarDays,
|
|
2264
|
+
activeCount: period !== "all" ? 1 : 0,
|
|
2265
|
+
render: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2266
|
+
["all", "24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsx(FilterMenuRow, { active: period === p, onClick: () => {
|
|
2267
|
+
setPeriod(p);
|
|
2268
|
+
if (p !== "custom") close();
|
|
2269
|
+
}, children: t2(`crm.filters.period${p === "all" ? "All" : p === "custom" ? "Custom" : p}`) }, p)),
|
|
2270
|
+
period === "custom" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 p-1.5", children: [
|
|
2271
|
+
/* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customFrom, onChange: setCustomFrom }),
|
|
2272
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2013" }),
|
|
2273
|
+
/* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customTo, onChange: setCustomTo })
|
|
2274
|
+
] })
|
|
2275
|
+
] })
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
id: "tags",
|
|
2279
|
+
label: t2("crm.leads.filters.tag"),
|
|
2280
|
+
icon: Tag,
|
|
2281
|
+
activeCount: selectedTags.length,
|
|
2282
|
+
render: () => /* @__PURE__ */ jsx(Fragment, { children: [.../* @__PURE__ */ new Set([...availableTags, ...selectedTags])].sort((a, b) => (tagDefs.get(a)?.name ?? humanizeTag(a)).localeCompare(tagDefs.get(b)?.name ?? humanizeTag(b))).map((slug) => {
|
|
2283
|
+
const on = selectedTags.includes(slug);
|
|
2284
|
+
return /* @__PURE__ */ jsxs(
|
|
2285
|
+
FilterMenuRow,
|
|
2286
|
+
{
|
|
2287
|
+
active: on,
|
|
2288
|
+
onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
|
|
2289
|
+
children: [
|
|
2290
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
|
|
2291
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) })
|
|
2292
|
+
]
|
|
2293
|
+
},
|
|
2294
|
+
slug
|
|
2295
|
+
);
|
|
2296
|
+
}) })
|
|
2297
|
+
}
|
|
2298
|
+
]
|
|
2299
|
+
}
|
|
2300
|
+
),
|
|
2301
|
+
/* @__PURE__ */ jsx(DisplayPopover, { display, onChange: setDisplay })
|
|
2302
|
+
] }) }),
|
|
1845
2303
|
boardPending ? /* @__PURE__ */ jsx(PipelineSkeleton, {}) : visibleStages.length === 0 ? (
|
|
1846
2304
|
/* Sem etapas não existe quadro: o `flex` abaixo renderizava uma faixa
|
|
1847
2305
|
em branco, que parece uma tela que não carregou. O funil é a única
|
|
@@ -1851,7 +2309,10 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1851
2309
|
/* @__PURE__ */ jsx(Filter, { className: "mb-2 h-9 w-9 text-muted-foreground/40", strokeWidth: 1.5 }),
|
|
1852
2310
|
/* @__PURE__ */ jsx("p", { className: "text-base font-semibold text-foreground", children: t2("crm.pipeline.noStages") }),
|
|
1853
2311
|
/* @__PURE__ */ jsx("p", { className: "max-w-sm text-sm text-muted-foreground", children: t2("crm.pipeline.noStagesHint") }),
|
|
1854
|
-
|
|
2312
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-3 flex flex-wrap items-center justify-center gap-2", children: [
|
|
2313
|
+
/* @__PURE__ */ jsx(AskAIButton, { ...funnelAI, label: t2("crm.pipeline.setupWithAI") }),
|
|
2314
|
+
onOpenSettings && /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onOpenSettings, children: t2("crm.pipeline.setupStages") })
|
|
2315
|
+
] })
|
|
1855
2316
|
] })
|
|
1856
2317
|
) : /* @__PURE__ */ jsx(
|
|
1857
2318
|
KanbanBoard,
|
|
@@ -1882,7 +2343,14 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1882
2343
|
addCardLabel: t2("crm.pipeline.addLead"),
|
|
1883
2344
|
dropProps: (col) => ({
|
|
1884
2345
|
onDragOver: (e) => handleDragOver(col.id, e),
|
|
1885
|
-
|
|
2346
|
+
// O PISCA-PISCA. `dragleave` BORBULHA: passar do fundo da coluna
|
|
2347
|
+
// para cima de um card dispara "saí" na coluna, o `dragover`
|
|
2348
|
+
// seguinte repinta, e o realce liga e desliga a cada movimento do
|
|
2349
|
+
// mouse. Só é saída de verdade quando o destino do ponteiro está
|
|
2350
|
+
// fora desta coluna — `relatedTarget` é quem diz isso.
|
|
2351
|
+
onDragLeave: (e) => {
|
|
2352
|
+
const indo = e.relatedTarget;
|
|
2353
|
+
if (indo && e.currentTarget.contains(indo)) return;
|
|
1886
2354
|
if (dragOverStageId === col.id) setDragOverStageId(null);
|
|
1887
2355
|
},
|
|
1888
2356
|
onDrop: () => handleDrop(col.id)
|
|
@@ -1913,6 +2381,18 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, modeControl }) {
|
|
|
1913
2381
|
)
|
|
1914
2382
|
}
|
|
1915
2383
|
),
|
|
2384
|
+
/* @__PURE__ */ jsx(
|
|
2385
|
+
LostReasonDialog,
|
|
2386
|
+
{
|
|
2387
|
+
open: pendingLost !== null,
|
|
2388
|
+
onCancel: () => setPendingLost(null),
|
|
2389
|
+
onConfirm: (reason) => {
|
|
2390
|
+
const p = pendingLost;
|
|
2391
|
+
setPendingLost(null);
|
|
2392
|
+
if (p) applyMove(p.dealId, p.fromStageId, p.toStageId, reason);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
),
|
|
1916
2396
|
menu && /* @__PURE__ */ jsx(
|
|
1917
2397
|
BoardMenu,
|
|
1918
2398
|
{
|
|
@@ -2096,6 +2576,7 @@ function DealListView({ onOpenDeal }) {
|
|
|
2096
2576
|
const [search, setSearch] = usePersistedState("crm.deals.search", "");
|
|
2097
2577
|
const [stage, setStage] = usePersistedState("crm.deals.stage", void 0);
|
|
2098
2578
|
const [status, setStatus] = usePersistedState("crm.deals.status", void 0);
|
|
2579
|
+
const [outcome, setOutcome] = usePersistedState("crm.deals.outcome", "open");
|
|
2099
2580
|
const [cohort, setCohort] = usePersistedState("crm.deals.cohort", void 0);
|
|
2100
2581
|
const [city, setCity] = usePersistedState("crm.deals.city", void 0);
|
|
2101
2582
|
const [companyName, setCompanyName] = usePersistedState("crm.deals.company", void 0);
|
|
@@ -2114,12 +2595,19 @@ function DealListView({ onOpenDeal }) {
|
|
|
2114
2595
|
}, []);
|
|
2115
2596
|
useEffect(() => {
|
|
2116
2597
|
if (!activePipelineId) return;
|
|
2117
|
-
|
|
2118
|
-
|
|
2598
|
+
const desfecho = outcome === "all" ? ["open", "won", "lost"] : outcome;
|
|
2599
|
+
void fetchDeals({ pipelineId: activePipelineId, status: desfecho, pageSize: LOAD_CAP });
|
|
2600
|
+
}, [activePipelineId, outcome]);
|
|
2119
2601
|
const stageOptions = useMemo(
|
|
2120
|
-
() => stages.
|
|
2602
|
+
() => stages.map((s) => ({ value: s.id, label: s.name, dot: s.color })),
|
|
2121
2603
|
[stages]
|
|
2122
2604
|
);
|
|
2605
|
+
const outcomeOptions = useMemo(() => [
|
|
2606
|
+
{ value: "open", label: t2("crm.deals.outcomeOpen") },
|
|
2607
|
+
{ value: "won", label: t2("crm.deals.outcomeWon") },
|
|
2608
|
+
{ value: "lost", label: t2("crm.deals.outcomeLost") },
|
|
2609
|
+
{ value: "all", label: t2("crm.deals.outcomeAll") }
|
|
2610
|
+
], [t2]);
|
|
2123
2611
|
const statusOptions = useMemo(() => {
|
|
2124
2612
|
const base = optionsFrom(deals.map((d) => d.contactStatusName));
|
|
2125
2613
|
const cores = /* @__PURE__ */ new Map();
|
|
@@ -2280,11 +2768,12 @@ function DealListView({ onOpenDeal }) {
|
|
|
2280
2768
|
cohort && t2("crm.deals.cohort"),
|
|
2281
2769
|
companyName && t2("crm.card.companyTitle")
|
|
2282
2770
|
].filter(Boolean);
|
|
2283
|
-
const filtrosAtivos = (stage ? 1 : 0) + (status ? 1 : 0) + (cohort ? 1 : 0) + (city ? 1 : 0) + (companyName ? 1 : 0) + (tags.length ? 1 : 0) + (owner ? 1 : 0);
|
|
2771
|
+
const filtrosAtivos = (stage ? 1 : 0) + (status ? 1 : 0) + (cohort ? 1 : 0) + (outcome !== "open" ? 1 : 0) + (city ? 1 : 0) + (companyName ? 1 : 0) + (tags.length ? 1 : 0) + (owner ? 1 : 0);
|
|
2284
2772
|
const limparFiltros = () => {
|
|
2285
2773
|
setStage(void 0);
|
|
2286
2774
|
setStatus(void 0);
|
|
2287
2775
|
setCohort(void 0);
|
|
2776
|
+
setOutcome("open");
|
|
2288
2777
|
setCity(void 0);
|
|
2289
2778
|
setCompanyName(void 0);
|
|
2290
2779
|
setTags([]);
|
|
@@ -2336,6 +2825,24 @@ function DealListView({ onOpenDeal }) {
|
|
|
2336
2825
|
clearLabel: t2("crm.leads.filters.clear"),
|
|
2337
2826
|
fields: [
|
|
2338
2827
|
...stageOptions.length > 0 ? [singleField("stage", t2("crm.dealSidebar.stage"), Filter, t2("crm.deals.allStages"), stageOptions, stage, setStage)] : [],
|
|
2828
|
+
{
|
|
2829
|
+
id: "outcome",
|
|
2830
|
+
label: t2("crm.deals.outcome"),
|
|
2831
|
+
icon: ThumbsDown,
|
|
2832
|
+
activeCount: outcome !== "open" ? 1 : 0,
|
|
2833
|
+
render: (close) => /* @__PURE__ */ jsx(Fragment, { children: outcomeOptions.map((o) => /* @__PURE__ */ jsx(
|
|
2834
|
+
FilterMenuRow,
|
|
2835
|
+
{
|
|
2836
|
+
active: outcome === o.value,
|
|
2837
|
+
onClick: () => {
|
|
2838
|
+
setOutcome(o.value);
|
|
2839
|
+
close();
|
|
2840
|
+
},
|
|
2841
|
+
children: /* @__PURE__ */ jsx("span", { className: "truncate", children: o.label })
|
|
2842
|
+
},
|
|
2843
|
+
o.value
|
|
2844
|
+
)) })
|
|
2845
|
+
},
|
|
2339
2846
|
...statusOptions.length > 0 ? [singleField("status", t2("crm.deals.colStatus"), SignalHigh, t2("crm.deals.allStatuses"), statusOptions, status, setStatus)] : [],
|
|
2340
2847
|
...cohortOptions.length > 0 ? [singleField("cohort", t2("crm.deals.cohort"), CalendarRange, t2("crm.deals.allCohorts"), cohortOptions, cohort, setCohort)] : [],
|
|
2341
2848
|
...tagOptions.length > 0 ? [{
|
|
@@ -2392,6 +2899,17 @@ function DealListView({ onOpenDeal }) {
|
|
|
2392
2899
|
onChange: setStage
|
|
2393
2900
|
}
|
|
2394
2901
|
),
|
|
2902
|
+
outcome !== "open" && /* @__PURE__ */ jsx(
|
|
2903
|
+
FilterChip,
|
|
2904
|
+
{
|
|
2905
|
+
label: t2("crm.deals.outcome"),
|
|
2906
|
+
icon: ThumbsDown,
|
|
2907
|
+
allLabel: t2("crm.deals.outcomeOpen"),
|
|
2908
|
+
options: outcomeOptions,
|
|
2909
|
+
value: outcome,
|
|
2910
|
+
onChange: (v) => setOutcome(v ?? "open")
|
|
2911
|
+
}
|
|
2912
|
+
),
|
|
2395
2913
|
status && /* @__PURE__ */ jsx(
|
|
2396
2914
|
FilterChip,
|
|
2397
2915
|
{
|
|
@@ -2616,9 +3134,15 @@ function DealFunnelView({ onStageClick }) {
|
|
|
2616
3134
|
const funnel = useCrmStore((s) => s.funnel);
|
|
2617
3135
|
const fetchFunnel = useCrmStore((s) => s.fetchFunnel);
|
|
2618
3136
|
const activePipelineId = useCrmStore((s) => s.activePipelineId);
|
|
3137
|
+
const [myUserId, setMyUserId] = useState(null);
|
|
2619
3138
|
useEffect(() => {
|
|
2620
|
-
|
|
2621
|
-
}, [
|
|
3139
|
+
void loadMyUserId().then(setMyUserId);
|
|
3140
|
+
}, []);
|
|
3141
|
+
const boardFilter = useBoardFilterValue(myUserId);
|
|
3142
|
+
const filterKey = JSON.stringify(boardFilter);
|
|
3143
|
+
useEffect(() => {
|
|
3144
|
+
if (activePipelineId) void fetchFunnel(activePipelineId, boardFilter);
|
|
3145
|
+
}, [activePipelineId, filterKey]);
|
|
2622
3146
|
if (!funnel.length) {
|
|
2623
3147
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1 rounded-lg border border-dashed py-12 text-center", children: [
|
|
2624
3148
|
/* @__PURE__ */ jsx(Filter, { className: "mb-2 h-9 w-9 text-muted-foreground/40", strokeWidth: 1.5 }),
|
|
@@ -3241,7 +3765,12 @@ var T = {
|
|
|
3241
3765
|
// são invisíveis para a raiz do CNPJ, e são metade dos casos reais.
|
|
3242
3766
|
companyBrandCandidates: "v_crm_company_brand_candidates",
|
|
3243
3767
|
companyGroupRollup: "v_crm_company_group_rollup",
|
|
3244
|
-
leadDuplicates: "v_crm_lead_duplicates"
|
|
3768
|
+
leadDuplicates: "v_crm_lead_duplicates",
|
|
3769
|
+
// O funil com os vínculos já agregados (060). A tela lê daqui; as duas
|
|
3770
|
+
// tabelas abaixo são para ESCREVER o vínculo.
|
|
3771
|
+
pipelinesView: "v_crm_pipelines",
|
|
3772
|
+
pipelineUnits: "plg_crm_pipeline_units",
|
|
3773
|
+
pipelineTeams: "plg_crm_pipeline_teams"
|
|
3245
3774
|
};
|
|
3246
3775
|
function PartnerUnitsInput({ value, onChange }) {
|
|
3247
3776
|
const t2 = useTranslation();
|
|
@@ -3466,20 +3995,43 @@ var tagEntity = {
|
|
|
3466
3995
|
],
|
|
3467
3996
|
data: { table: T.tags, tenantScoped: true }
|
|
3468
3997
|
};
|
|
3469
|
-
var
|
|
3470
|
-
name: "
|
|
3471
|
-
namePlural: "
|
|
3472
|
-
icon: "
|
|
3473
|
-
displayField: "
|
|
3474
|
-
defaultSort: "name",
|
|
3998
|
+
var pipelineUnitEntity = {
|
|
3999
|
+
name: "Unit",
|
|
4000
|
+
namePlural: "Units",
|
|
4001
|
+
icon: "Building2",
|
|
4002
|
+
displayField: "unitId",
|
|
3475
4003
|
fields: [
|
|
3476
|
-
{
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
4004
|
+
{
|
|
4005
|
+
key: "unitId",
|
|
4006
|
+
label: "Unit",
|
|
4007
|
+
type: "relation",
|
|
4008
|
+
required: true,
|
|
4009
|
+
showInTable: true,
|
|
4010
|
+
relation: { table: "v_units", labelField: "name" }
|
|
4011
|
+
},
|
|
4012
|
+
{ key: "pipelineId", label: "Pipeline", type: "relation", required: true, relation: { table: T.pipelines, labelField: "name" } }
|
|
3481
4013
|
],
|
|
3482
|
-
data: { table: T.
|
|
4014
|
+
data: { table: T.pipelineUnits, tenantScoped: true }
|
|
4015
|
+
};
|
|
4016
|
+
var pipelineTeamEntity = {
|
|
4017
|
+
name: "Team",
|
|
4018
|
+
namePlural: "Teams",
|
|
4019
|
+
icon: "Users",
|
|
4020
|
+
displayField: "teamId",
|
|
4021
|
+
fields: [
|
|
4022
|
+
{
|
|
4023
|
+
key: "teamId",
|
|
4024
|
+
label: "Team",
|
|
4025
|
+
type: "relation",
|
|
4026
|
+
required: true,
|
|
4027
|
+
showInTable: true,
|
|
4028
|
+
// A equipe é a categoria `staff_team` (139 do espinha) — a mesma que os
|
|
4029
|
+
// Cadastros criam na aba Equipes dos Profissionais.
|
|
4030
|
+
relation: { table: "categories", labelField: "name", filter: { kind: "staff_team" } }
|
|
4031
|
+
},
|
|
4032
|
+
{ key: "pipelineId", label: "Pipeline", type: "relation", required: true, relation: { table: T.pipelines, labelField: "name" } }
|
|
4033
|
+
],
|
|
4034
|
+
data: { table: T.pipelineTeams, tenantScoped: true }
|
|
3483
4035
|
};
|
|
3484
4036
|
var pipelineStageEntity = {
|
|
3485
4037
|
name: "Stage",
|
|
@@ -3515,6 +4067,50 @@ var pipelineStageEntity = {
|
|
|
3515
4067
|
],
|
|
3516
4068
|
data: { table: T.pipelineStages, tenantScoped: true }
|
|
3517
4069
|
};
|
|
4070
|
+
var pipelineEntity = {
|
|
4071
|
+
name: "Pipeline",
|
|
4072
|
+
namePlural: "Pipelines",
|
|
4073
|
+
icon: "GitBranch",
|
|
4074
|
+
displayField: "name",
|
|
4075
|
+
defaultSort: "name",
|
|
4076
|
+
fields: [
|
|
4077
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
4078
|
+
// One default per tenant; the provider clears the flag on the others when
|
|
4079
|
+
// this one is set. It is the funnel a lead falls into when nobody chose.
|
|
4080
|
+
{ key: "isDefault", label: "Default", type: "boolean", showInTable: true, defaultValue: false },
|
|
4081
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
4082
|
+
],
|
|
4083
|
+
// O funil ABERTO mostra o que é dele: as etapas primeiro, porque são o
|
|
4084
|
+
// funil, e depois para quem ele serve. Antes as etapas moravam numa lista
|
|
4085
|
+
// irmã com uma coluna "Pipeline" — para saber as etapas DESTE funil era
|
|
4086
|
+
// preciso sair dele e filtrar uma lista de todos.
|
|
4087
|
+
relatedLists: [
|
|
4088
|
+
{ id: "stages", label: "Stages", icon: "Workflow", entity: pipelineStageEntity, foreignKey: "pipelineId" }
|
|
4089
|
+
],
|
|
4090
|
+
// Unidades e equipes são SEÇÃO, não aba: são duas ou três pastilhas, e para
|
|
4091
|
+
// quem o funil serve se lê junto com o nome dele. Numa aba própria seriam
|
|
4092
|
+
// dois cliques para descobrir uma linha de configuração — e quem abre o
|
|
4093
|
+
// funil para conferir o recorte teria de abrir as duas.
|
|
4094
|
+
relatedSections: [
|
|
4095
|
+
{
|
|
4096
|
+
id: "units",
|
|
4097
|
+
label: "Units",
|
|
4098
|
+
icon: "Building2",
|
|
4099
|
+
entity: pipelineUnitEntity,
|
|
4100
|
+
foreignKey: "pipelineId",
|
|
4101
|
+
emptyHint: "Sem unidade: este funil serve a conta inteira."
|
|
4102
|
+
},
|
|
4103
|
+
{
|
|
4104
|
+
id: "teams",
|
|
4105
|
+
label: "Teams",
|
|
4106
|
+
icon: "Users",
|
|
4107
|
+
entity: pipelineTeamEntity,
|
|
4108
|
+
foreignKey: "pipelineId",
|
|
4109
|
+
emptyHint: "Sem equipe: este funil serve todas as equipes."
|
|
4110
|
+
}
|
|
4111
|
+
],
|
|
4112
|
+
data: { table: T.pipelines, tenantScoped: true }
|
|
4113
|
+
};
|
|
3518
4114
|
var dealStatusEntity = {
|
|
3519
4115
|
name: "Contact status",
|
|
3520
4116
|
namePlural: "Contact statuses",
|
|
@@ -3961,7 +4557,7 @@ function CopyDocument({ document: doc, label: label2 }) {
|
|
|
3961
4557
|
}
|
|
3962
4558
|
);
|
|
3963
4559
|
}
|
|
3964
|
-
function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewCompany, onCreateQuote, seed }) {
|
|
4560
|
+
function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewCompany, onCreateQuote, seed, pendingStage, onPendingResolved }) {
|
|
3965
4561
|
const t2 = useTranslation();
|
|
3966
4562
|
const provider = useCrmProvider();
|
|
3967
4563
|
const { currency } = useCrmConfig();
|
|
@@ -3971,6 +4567,7 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
3971
4567
|
const moveDealToStage = useCrmStore((s) => s.moveDealToStage);
|
|
3972
4568
|
const patchBoardDeal = useCrmStore((s) => s.patchBoardDeal);
|
|
3973
4569
|
const removeBoardDeal = useCrmStore((s) => s.removeBoardDeal);
|
|
4570
|
+
const refreshBoard = useCrmStore((s) => s.refreshBoard);
|
|
3974
4571
|
const tagDefs = useCrmStore((s) => s.tagDefs);
|
|
3975
4572
|
const fetchTagDefs = useCrmStore((s) => s.fetchTagDefs);
|
|
3976
4573
|
const [deal, setDeal] = useState(null);
|
|
@@ -3984,6 +4581,7 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
3984
4581
|
const [movingStage, setMovingStage] = useState(false);
|
|
3985
4582
|
const [saving, setSaving] = useState(false);
|
|
3986
4583
|
const [closing, setClosing] = useState(false);
|
|
4584
|
+
const [askingLost, setAskingLost] = useState(false);
|
|
3987
4585
|
const [draft, setDraft] = useState(null);
|
|
3988
4586
|
const [company, setCompany] = useState(null);
|
|
3989
4587
|
const [pessoasDaCasa, setPessoasDaCasa] = useState([]);
|
|
@@ -4060,6 +4658,9 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4060
4658
|
const id = requestAnimationFrame(() => composerRef.current?.focus());
|
|
4061
4659
|
return () => cancelAnimationFrame(id);
|
|
4062
4660
|
}, [composerOpen]);
|
|
4661
|
+
useEffect(() => {
|
|
4662
|
+
if (open && pendingStage) setComposerOpen(true);
|
|
4663
|
+
}, [open, pendingStage?.id]);
|
|
4063
4664
|
useEffect(() => {
|
|
4064
4665
|
if (!seed || seed.id !== dealId) return;
|
|
4065
4666
|
setDeal((d) => d && d.id === seed.id && d.stageId !== seed.stageId ? { ...d, stageId: seed.stageId, stageName: seed.stageName, stageColor: seed.stageColor, probability: seed.probability } : d);
|
|
@@ -4131,6 +4732,11 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4131
4732
|
assignedToId: deal?.assignedToId
|
|
4132
4733
|
}) : void 0;
|
|
4133
4734
|
setActivities((prev) => futureTask ? [futureTask, logged, ...prev] : [logged, ...prev]);
|
|
4735
|
+
if (pendingStage && deal && pendingStage.id !== deal.stageId) {
|
|
4736
|
+
await moveDealToStage(deal.id, pendingStage.id);
|
|
4737
|
+
setDeal({ ...deal, stageId: pendingStage.id, stageName: pendingStage.name, stageColor: pendingStage.color, probability: pendingStage.probability });
|
|
4738
|
+
onPendingResolved?.(true);
|
|
4739
|
+
}
|
|
4134
4740
|
setCnote("");
|
|
4135
4741
|
setCoutcome("connected");
|
|
4136
4742
|
setCfutureDate("");
|
|
@@ -4249,20 +4855,18 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4249
4855
|
setMovingStage(false);
|
|
4250
4856
|
}
|
|
4251
4857
|
}
|
|
4252
|
-
async function close(outcome) {
|
|
4858
|
+
async function close(outcome, reason) {
|
|
4253
4859
|
if (!deal || closing) return;
|
|
4254
|
-
let reason;
|
|
4255
|
-
if (outcome === "lost") {
|
|
4256
|
-
const answer = window.prompt(t2("crm.card.lostReasonPrompt"));
|
|
4257
|
-
if (answer === null) return;
|
|
4258
|
-
reason = answer.trim() || void 0;
|
|
4259
|
-
}
|
|
4260
4860
|
setClosing(true);
|
|
4261
4861
|
try {
|
|
4862
|
+
const lostStage = outcome === "lost" ? stages.find((s) => s.isLost) : void 0;
|
|
4863
|
+
if (lostStage && lostStage.id !== deal.stageId) await moveDealToStage(deal.id, lostStage.id);
|
|
4262
4864
|
const patched = await provider.updateDeal(deal.id, { status: outcome, lostReason: reason });
|
|
4263
4865
|
setDeal(patched);
|
|
4264
|
-
if (outcome === "lost")
|
|
4265
|
-
|
|
4866
|
+
if (outcome === "lost") {
|
|
4867
|
+
if (lostStage) void refreshBoard();
|
|
4868
|
+
else removeBoardDeal(deal.id);
|
|
4869
|
+
} else patchBoardDeal(deal.id, { status: "won" });
|
|
4266
4870
|
const refreshed = await provider.getActivities({ dealId });
|
|
4267
4871
|
setActivities(refreshed.data);
|
|
4268
4872
|
toast.success(t2(outcome === "won" ? "crm.card.markedWon" : "crm.card.markedLost"));
|
|
@@ -4338,424 +4942,460 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4338
4942
|
setSaving(false);
|
|
4339
4943
|
}
|
|
4340
4944
|
}
|
|
4341
|
-
return /* @__PURE__ */
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
/* @__PURE__ */ jsxs(
|
|
4345
|
-
/* @__PURE__ */ jsxs(
|
|
4346
|
-
/* @__PURE__ */
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4945
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4946
|
+
/* @__PURE__ */ jsx(Modal, { open, onOpenChange: (o) => {
|
|
4947
|
+
if (!o) onClose();
|
|
4948
|
+
}, children: /* @__PURE__ */ jsxs(ModalContent, { size: "5xl", noPadding: true, children: [
|
|
4949
|
+
/* @__PURE__ */ jsxs(ModalHeader, { className: "flex-col items-stretch gap-2 border-b px-5 py-3", children: [
|
|
4950
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
4951
|
+
/* @__PURE__ */ jsx(ModalTitle, { className: "min-w-0 flex-1 truncate text-base", children: loading && !deal ? /* @__PURE__ */ jsx("span", { className: "inline-block h-5 w-40 animate-pulse rounded bg-muted/40 align-middle" }) : deal ? dealHeadline(deal) || t2("crm.dealSidebar.deal") : t2("crm.dealSidebar.deal") }),
|
|
4952
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2 pr-8", children: [
|
|
4953
|
+
deal?.status === "open" ? /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "ghost", disabled: closing, onClick: () => setAskingLost(true), children: [
|
|
4954
|
+
/* @__PURE__ */ jsx(ThumbsDown, { className: "h-3 w-3" }),
|
|
4955
|
+
" ",
|
|
4956
|
+
t2("crm.card.markLost")
|
|
4957
|
+
] }) : deal ? /* @__PURE__ */ jsxs(
|
|
4958
|
+
"span",
|
|
4959
|
+
{
|
|
4960
|
+
className: "inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[11px] font-medium " + (deal.status === "won" ? "bg-success-soft text-success-soft-foreground" : "bg-destructive-soft text-destructive-soft-foreground"),
|
|
4961
|
+
title: lostReasonLabel(deal.lostReason, t2),
|
|
4962
|
+
children: [
|
|
4963
|
+
deal.status === "won" ? /* @__PURE__ */ jsx(Trophy, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(ThumbsDown, { className: "h-3 w-3" }),
|
|
4964
|
+
t2(deal.status === "won" ? "crm.card.won" : "crm.card.lost"),
|
|
4965
|
+
deal.lostReason && /* @__PURE__ */ jsxs("span", { className: "font-normal opacity-80", children: [
|
|
4966
|
+
"\xB7 ",
|
|
4967
|
+
lostReasonLabel(deal.lostReason, t2)
|
|
4968
|
+
] })
|
|
4969
|
+
]
|
|
4970
|
+
}
|
|
4971
|
+
) : null,
|
|
4972
|
+
deal && (onCreateQuote || onViewLead || canArchive) && /* @__PURE__ */ jsxs(Dropdown, { children: [
|
|
4973
|
+
/* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", "aria-label": t2("crm.card.moreActions"), className: "h-8 w-8 p-0", children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" }) }) }),
|
|
4974
|
+
/* @__PURE__ */ jsxs(DropdownContent, { align: "end", children: [
|
|
4975
|
+
onCreateQuote && lead && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => onCreateQuote(lead.id), children: [
|
|
4976
|
+
/* @__PURE__ */ jsx(FileText, { className: "h-3.5 w-3.5" }),
|
|
4977
|
+
" ",
|
|
4978
|
+
t2("crm.leadDetail.createQuote")
|
|
4979
|
+
] }),
|
|
4980
|
+
onViewLead && lead && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => onViewLead(lead.id), children: [
|
|
4981
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "h-3.5 w-3.5" }),
|
|
4982
|
+
" ",
|
|
4983
|
+
t2("crm.dealSidebar.viewLeadProfile")
|
|
4984
|
+
] }),
|
|
4985
|
+
canArchive && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => {
|
|
4986
|
+
void archiveDeal(deal.id).then(onClose);
|
|
4987
|
+
}, children: [
|
|
4988
|
+
/* @__PURE__ */ jsx(Archive, { className: "h-3.5 w-3.5" }),
|
|
4989
|
+
" ",
|
|
4990
|
+
t2("crm.pipeline.archive")
|
|
4365
4991
|
] })
|
|
4366
|
-
]
|
|
4367
|
-
}
|
|
4368
|
-
) : null,
|
|
4369
|
-
deal && (onCreateQuote || onViewLead || canArchive) && /* @__PURE__ */ jsxs(Dropdown, { children: [
|
|
4370
|
-
/* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", "aria-label": t2("crm.card.moreActions"), className: "h-8 w-8 p-0", children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" }) }) }),
|
|
4371
|
-
/* @__PURE__ */ jsxs(DropdownContent, { align: "end", children: [
|
|
4372
|
-
onCreateQuote && lead && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => onCreateQuote(lead.id), children: [
|
|
4373
|
-
/* @__PURE__ */ jsx(FileText, { className: "h-3.5 w-3.5" }),
|
|
4374
|
-
" ",
|
|
4375
|
-
t2("crm.leadDetail.createQuote")
|
|
4376
|
-
] }),
|
|
4377
|
-
onViewLead && lead && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => onViewLead(lead.id), children: [
|
|
4378
|
-
/* @__PURE__ */ jsx(ArrowRight, { className: "h-3.5 w-3.5" }),
|
|
4379
|
-
" ",
|
|
4380
|
-
t2("crm.dealSidebar.viewLeadProfile")
|
|
4381
|
-
] }),
|
|
4382
|
-
canArchive && /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => {
|
|
4383
|
-
void archiveDeal(deal.id).then(onClose);
|
|
4384
|
-
}, children: [
|
|
4385
|
-
/* @__PURE__ */ jsx(Archive, { className: "h-3.5 w-3.5" }),
|
|
4386
|
-
" ",
|
|
4387
|
-
t2("crm.pipeline.archive")
|
|
4388
4992
|
] })
|
|
4389
4993
|
] })
|
|
4390
4994
|
] })
|
|
4391
|
-
] })
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4995
|
+
] }),
|
|
4996
|
+
deal?.status === "open" && (journeyStages.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
4997
|
+
journeyStages.map((s) => {
|
|
4998
|
+
const active = s.id === deal?.stageId;
|
|
4999
|
+
return /* @__PURE__ */ jsxs(
|
|
5000
|
+
"button",
|
|
5001
|
+
{
|
|
5002
|
+
type: "button",
|
|
5003
|
+
disabled: movingStage,
|
|
5004
|
+
onClick: () => {
|
|
5005
|
+
void changeStage(s);
|
|
5006
|
+
},
|
|
5007
|
+
"aria-pressed": active,
|
|
5008
|
+
className: "inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium transition-colors disabled:opacity-60 " + (active ? "border-primary bg-primary/10 text-primary" : "border-border text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
5009
|
+
children: [
|
|
5010
|
+
/* @__PURE__ */ jsx("span", { className: "h-2 w-2 rounded-full", style: { backgroundColor: s.color } }),
|
|
5011
|
+
s.name
|
|
5012
|
+
]
|
|
4403
5013
|
},
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
/* @__PURE__ */
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-4 p-5", style: wide ? { width: "18rem" } : void 0, children: [
|
|
4429
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
4430
|
-
/* @__PURE__ */ jsx("div", { className: "h-14 w-14 animate-pulse rounded-full bg-muted/40" }),
|
|
4431
|
-
/* @__PURE__ */ jsx("div", { className: "h-4 w-32 animate-pulse rounded bg-muted/40" }),
|
|
4432
|
-
/* @__PURE__ */ jsx("div", { className: "h-3 w-24 animate-pulse rounded bg-muted/30" })
|
|
5014
|
+
s.id
|
|
5015
|
+
);
|
|
5016
|
+
}),
|
|
5017
|
+
movingStage && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }),
|
|
5018
|
+
/* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outline", disabled: closing, onClick: () => {
|
|
5019
|
+
void close("won");
|
|
5020
|
+
}, children: [
|
|
5021
|
+
/* @__PURE__ */ jsx(Trophy, { className: "h-3 w-3 text-success" }),
|
|
5022
|
+
" ",
|
|
5023
|
+
t2("crm.card.markWon")
|
|
5024
|
+
] })
|
|
5025
|
+
] }) : /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1.5", "aria-hidden": true, children: [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsx("div", { className: "h-[26px] w-20 animate-pulse rounded-full bg-muted/40" }, i)) }))
|
|
5026
|
+
] }),
|
|
5027
|
+
/* @__PURE__ */ jsx(ModalBody, { className: wide ? "overflow-hidden p-0" : "sm:max-h-[70vh] overflow-y-auto p-0", children: loading || !draft ? (
|
|
5028
|
+
// O esqueleto tem a MESMA silhueta das três colunas — carregar não
|
|
5029
|
+
// pode trocar o desenho da tela no meio.
|
|
5030
|
+
/* @__PURE__ */ jsxs("div", { className: "flex", style: wide ? { height: "70vh" } : { flexDirection: "column" }, children: [
|
|
5031
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4 p-5", style: wide ? { width: "18rem" } : void 0, children: [
|
|
5032
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
5033
|
+
/* @__PURE__ */ jsx("div", { className: "h-14 w-14 animate-pulse rounded-full bg-muted/40" }),
|
|
5034
|
+
/* @__PURE__ */ jsx("div", { className: "h-4 w-32 animate-pulse rounded bg-muted/40" }),
|
|
5035
|
+
/* @__PURE__ */ jsx("div", { className: "h-3 w-24 animate-pulse rounded bg-muted/30" })
|
|
5036
|
+
] }),
|
|
5037
|
+
[1, 2, 3, 4].map((i) => /* @__PURE__ */ jsx("div", { className: "h-10 animate-pulse rounded-lg bg-muted/30" }, i))
|
|
4433
5038
|
] }),
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
[1, 2, 3].map((i) => /* @__PURE__ */ jsx("div", { className: "h-
|
|
4439
|
-
] })
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
5039
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-3 p-5" + (wide ? " min-h-0 overflow-y-auto" : ""), children: [
|
|
5040
|
+
/* @__PURE__ */ jsx("div", { className: "h-10 animate-pulse rounded-lg bg-muted/40" }),
|
|
5041
|
+
[1, 2, 3].map((i) => /* @__PURE__ */ jsx("div", { className: "h-14 animate-pulse rounded-lg bg-muted/30" }, i))
|
|
5042
|
+
] }),
|
|
5043
|
+
wide && /* @__PURE__ */ jsx("div", { className: "space-y-3 p-5", style: { width: "18rem" }, children: [1, 2, 3].map((i) => /* @__PURE__ */ jsx("div", { className: "h-16 animate-pulse rounded-lg bg-muted/30" }, i)) })
|
|
5044
|
+
] })
|
|
5045
|
+
) : /* @__PURE__ */ jsxs("div", { className: "flex", style: wide ? { height: "70vh" } : { flexDirection: "column" }, children: [
|
|
5046
|
+
/* @__PURE__ */ jsxs("div", { className: (wide ? "min-h-0 shrink-0 overflow-y-auto border-r" : "border-b") + " space-y-5 p-5", style: wide ? { width: "18rem" } : void 0, children: [
|
|
5047
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 text-center", children: [
|
|
5048
|
+
/* @__PURE__ */ jsx(PersonAvatar, { name: draft.name || deal?.contactName || "?", size: "md", className: "h-14 w-14 text-lg" }),
|
|
5049
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
5050
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm font-semibold", children: draft.name || deal?.contactName || "\u2014" }),
|
|
5051
|
+
(company?.name || draft.company) && /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: company?.name ?? draft.company }),
|
|
5052
|
+
pessoaDoCard?.companyRole && /* @__PURE__ */ jsx("p", { className: "truncate text-[11px] text-muted-foreground/80", children: pessoaDoCard.companyRole })
|
|
5053
|
+
] }),
|
|
5054
|
+
score === void 0 ? /* @__PURE__ */ jsx("span", { className: "h-5 w-20 animate-pulse rounded-full bg-muted/40", "aria-hidden": true }) : score ? /* @__PURE__ */ jsx(TemperatureBadge, { score }) : null,
|
|
5055
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-center gap-3 pt-1", children: [
|
|
5056
|
+
pessoaDoCard?.id && /* @__PURE__ */ jsxs("span", { className: "flex flex-col items-center gap-1", onClickCapture: () => prepActivity("whatsapp"), children: [
|
|
5057
|
+
/* @__PURE__ */ jsx(
|
|
5058
|
+
TalkToPerson,
|
|
5059
|
+
{
|
|
5060
|
+
personId: pessoaDoCard.id,
|
|
5061
|
+
name: pessoaDoCard.name,
|
|
5062
|
+
phone: pessoaDoCard.phone,
|
|
5063
|
+
variant: "icon",
|
|
5064
|
+
className: "flex h-9 w-9 items-center justify-center rounded-full text-white shadow-sm transition-opacity hover:opacity-85"
|
|
5065
|
+
}
|
|
5066
|
+
),
|
|
5067
|
+
/* @__PURE__ */ jsx("span", { className: "text-[10px] text-muted-foreground", children: t2("crm.card.quickTalk") })
|
|
5068
|
+
] }),
|
|
5069
|
+
/* @__PURE__ */ jsx(QuickAction, { icon: Phone, label: t2("crm.card.quickCall"), href: draft.phone ? `tel:${draft.phone}` : void 0, onClick: draft.phone ? () => prepActivity("call") : void 0 }),
|
|
5070
|
+
/* @__PURE__ */ jsx(QuickAction, { icon: Mail, label: t2("crm.card.quickEmail"), href: draft.email ? `mailto:${draft.email}` : void 0, onClick: draft.email ? () => prepActivity("email") : void 0 }),
|
|
5071
|
+
/* @__PURE__ */ jsx(QuickAction, { icon: Pencil, label: t2("crm.card.quickNote"), onClick: () => prepActivity("note") })
|
|
5072
|
+
] })
|
|
4450
5073
|
] }),
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
5074
|
+
/* @__PURE__ */ jsx(Section, { title: t2("crm.card.pointOfContact"), children: /* @__PURE__ */ jsx(
|
|
5075
|
+
PersonPicker,
|
|
5076
|
+
{
|
|
5077
|
+
options: pessoasDaCasa.map((x) => ({
|
|
5078
|
+
id: x.personId,
|
|
5079
|
+
name: x.personName ?? "\u2014",
|
|
5080
|
+
// De QUAL casa, quando o negócio carrega mais de uma
|
|
5081
|
+
// (057). Sem isto, duas pessoas de CNPJs diferentes
|
|
5082
|
+
// ficam duas linhas iguais, e escolher vira sorteio.
|
|
5083
|
+
subtitle: [x.role, casasDoNegocio > 1 ? x.companyName : null].filter(Boolean).join(" \xB7 ") || null
|
|
5084
|
+
})),
|
|
5085
|
+
value: deal?.contactId ?? null,
|
|
5086
|
+
onChange: (id) => {
|
|
5087
|
+
void trocarPontoDeContato(id);
|
|
5088
|
+
},
|
|
5089
|
+
placeholder: t2("crm.card.pointOfContactEmpty"),
|
|
5090
|
+
disabled: trocandoContato || pessoasDaCasa.length === 0
|
|
5091
|
+
}
|
|
5092
|
+
) }),
|
|
5093
|
+
/* @__PURE__ */ jsx(
|
|
5094
|
+
Section,
|
|
5095
|
+
{
|
|
5096
|
+
title: t2("crm.card.about"),
|
|
5097
|
+
action: /* @__PURE__ */ jsx(
|
|
5098
|
+
"button",
|
|
5099
|
+
{
|
|
5100
|
+
type: "button",
|
|
5101
|
+
onClick: () => setEditing((e) => !e),
|
|
5102
|
+
title: t2("crm.card.edit"),
|
|
5103
|
+
className: "rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
|
|
5104
|
+
children: /* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5" })
|
|
5105
|
+
}
|
|
5106
|
+
),
|
|
5107
|
+
children: !editing ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
5108
|
+
/* @__PURE__ */ jsx(InfoRow, { label: t2("crm.leadDetail.phone"), value: draft.phone }),
|
|
5109
|
+
/* @__PURE__ */ jsx(InfoRow, { label: t2("crm.leadDetail.email"), value: draft.email }),
|
|
5110
|
+
/* @__PURE__ */ jsx(InfoRow, { label: t2("crm.dealSidebar.value"), value: draft.value ? formatCurrency(draft.value, currency) : void 0 }),
|
|
5111
|
+
/* @__PURE__ */ jsx(InfoRow, { label: t2("crm.dealSidebar.expectedClose"), value: draft.expectedCloseDate }),
|
|
5112
|
+
draft.notes && /* @__PURE__ */ jsx(InfoRow, { label: t2("crm.leadDetail.notes"), value: /* @__PURE__ */ jsx("span", { className: "whitespace-pre-wrap text-xs", children: draft.notes }) })
|
|
5113
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
5114
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.leadDetail.name"), children: /* @__PURE__ */ jsx(Input, { className: "h-9", value: draft.name, onChange: (e) => setDraft({ ...draft, name: e.target.value }) }) }),
|
|
5115
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.leadDetail.phone"), children: /* @__PURE__ */ jsx(Input, { className: "h-9", value: draft.phone, onChange: (e) => setDraft({ ...draft, phone: e.target.value }) }) }),
|
|
5116
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.leadDetail.email"), children: /* @__PURE__ */ jsx(Input, { className: "h-9", type: "email", value: draft.email, onChange: (e) => setDraft({ ...draft, email: e.target.value }) }) }),
|
|
5117
|
+
!company && /* @__PURE__ */ jsx(Field, { label: t2("crm.leadDetail.company"), children: /* @__PURE__ */ jsx(Input, { className: "h-9", value: draft.company, onChange: (e) => setDraft({ ...draft, company: e.target.value }) }) }),
|
|
5118
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.dealSidebar.value"), children: /* @__PURE__ */ jsx(CurrencyInput, { value: draft.value, onChange: (v) => setDraft({ ...draft, value: v ?? 0 }) }) }),
|
|
5119
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.dealSidebar.expectedClose"), children: /* @__PURE__ */ jsx(DatePicker, { value: draft.expectedCloseDate, onChange: (v) => setDraft({ ...draft, expectedCloseDate: v }) }) }),
|
|
5120
|
+
/* @__PURE__ */ jsx(Field, { label: t2("crm.leadDetail.notes"), children: /* @__PURE__ */ jsx(
|
|
5121
|
+
"textarea",
|
|
5122
|
+
{
|
|
5123
|
+
rows: 3,
|
|
5124
|
+
value: draft.notes,
|
|
5125
|
+
onChange: (e) => setDraft({ ...draft, notes: e.target.value }),
|
|
5126
|
+
className: "w-full resize-none rounded-lg border bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-ring"
|
|
5127
|
+
}
|
|
5128
|
+
) }),
|
|
5129
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
5130
|
+
/* @__PURE__ */ jsxs(Button, { className: "flex-1", onClick: () => {
|
|
5131
|
+
void save().then(() => setEditing(false));
|
|
5132
|
+
}, disabled: saving, children: [
|
|
5133
|
+
saving && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
5134
|
+
t2("crm.card.save")
|
|
5135
|
+
] }),
|
|
5136
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setEditing(false), children: t2("crm.card.cancelEdit") })
|
|
5137
|
+
] })
|
|
5138
|
+
] })
|
|
5139
|
+
}
|
|
5140
|
+
),
|
|
5141
|
+
/* @__PURE__ */ jsx(Section, { title: t2("crm.card.owner"), children: team === null ? /* @__PURE__ */ jsx("div", { className: "h-9 animate-pulse rounded-lg bg-muted/40", "aria-hidden": true }) : team.length === 0 ? (
|
|
5142
|
+
// Lista vazia aqui quase sempre é falta de `members.read`, e
|
|
5143
|
+
// não uma casa sem equipe. Dizer "ninguém" seria mentir.
|
|
5144
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t2("crm.rota.cannotRead") })
|
|
5145
|
+
) : (
|
|
5146
|
+
// Uma linha só: quem é o dono (PersonPicker, com o retrato
|
|
5147
|
+
// — o rosto é o que distingue duas Anas em meio segundo) e,
|
|
5148
|
+
// ao lado, o ASSUMIR de um clique. Pegar a fila é o gesto
|
|
5149
|
+
// mais repetido do dia de prospecção; o botão some quando o
|
|
5150
|
+
// negócio já é de quem olha.
|
|
5151
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4454
5152
|
/* @__PURE__ */ jsx(
|
|
4455
|
-
|
|
5153
|
+
PersonPicker,
|
|
4456
5154
|
{
|
|
4457
|
-
|
|
4458
|
-
name:
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
5155
|
+
className: "min-w-0 flex-1",
|
|
5156
|
+
options: team.map((m) => ({ id: m.userId, name: m.name })),
|
|
5157
|
+
value: deal?.assignedToId ?? null,
|
|
5158
|
+
onChange: (id) => {
|
|
5159
|
+
void changeOwner(id);
|
|
5160
|
+
},
|
|
5161
|
+
placeholder: t2("crm.card.noOwner"),
|
|
5162
|
+
clearable: true,
|
|
5163
|
+
onClear: () => {
|
|
5164
|
+
void changeOwner(void 0);
|
|
5165
|
+
},
|
|
5166
|
+
disabled: savingOwner
|
|
4462
5167
|
}
|
|
4463
5168
|
),
|
|
4464
|
-
|
|
5169
|
+
myUserId && deal?.assignedToId !== myUserId && /* @__PURE__ */ jsxs(
|
|
5170
|
+
"button",
|
|
5171
|
+
{
|
|
5172
|
+
onClick: () => {
|
|
5173
|
+
void changeOwner(myUserId);
|
|
5174
|
+
},
|
|
5175
|
+
disabled: savingOwner,
|
|
5176
|
+
className: "inline-flex h-9 shrink-0 items-center gap-1.5 rounded-button border border-primary/30 bg-primary/5 px-3 text-xs font-medium text-primary transition-colors hover:bg-primary/10 disabled:opacity-60",
|
|
5177
|
+
children: [
|
|
5178
|
+
/* @__PURE__ */ jsx(UserCheck, { className: "h-3.5 w-3.5" }),
|
|
5179
|
+
deal?.assignedToId ? t2("crm.card.takeOverFrom") : t2("crm.card.takeOver")
|
|
5180
|
+
]
|
|
5181
|
+
}
|
|
5182
|
+
)
|
|
5183
|
+
] })
|
|
5184
|
+
) }),
|
|
5185
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-5 gap-y-1 text-[11px] text-muted-foreground", children: [
|
|
5186
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
5187
|
+
t2("crm.dealSidebar.probability"),
|
|
5188
|
+
": ",
|
|
5189
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium text-foreground", children: [
|
|
5190
|
+
deal?.probability ?? 0,
|
|
5191
|
+
"%"
|
|
5192
|
+
] })
|
|
4465
5193
|
] }),
|
|
4466
|
-
/* @__PURE__ */
|
|
4467
|
-
|
|
4468
|
-
|
|
5194
|
+
deal?.createdAt && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
5195
|
+
/* @__PURE__ */ jsx(Clock, { className: "h-3 w-3" }),
|
|
5196
|
+
formatDateTime(deal.createdAt, currency.locale),
|
|
5197
|
+
" (",
|
|
5198
|
+
formatRelativeTime(deal.createdAt, currency.locale),
|
|
5199
|
+
")"
|
|
5200
|
+
] })
|
|
4469
5201
|
] })
|
|
4470
5202
|
] }),
|
|
4471
|
-
/* @__PURE__ */
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
) }),
|
|
4490
|
-
/* @__PURE__ */ jsx(
|
|
4491
|
-
Section,
|
|
4492
|
-
{
|
|
4493
|
-
title: t2("crm.card.about"),
|
|
4494
|
-
action: /* @__PURE__ */ jsx(
|
|
5203
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-3 p-5" + (wide ? " min-h-0 overflow-y-auto" : ""), children: [
|
|
5204
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
5205
|
+
/* @__PURE__ */ jsx("h3", { className: "text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: t2("crm.card.timeline") }),
|
|
5206
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: [["all", t2("crm.card.tabAll")], ["contact", t2("crm.card.tabContacts")], ["note", t2("crm.card.tabNotes")], ["task", t2("crm.card.tabTasks")]].map(([v, label2]) => /* @__PURE__ */ jsx(
|
|
5207
|
+
"button",
|
|
5208
|
+
{
|
|
5209
|
+
type: "button",
|
|
5210
|
+
onClick: () => setTimelineTab(v),
|
|
5211
|
+
className: "rounded-button px-2 py-0.5 text-xs transition-colors " + (timelineTab === v ? "bg-primary/10 font-medium text-primary" : "text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
5212
|
+
children: label2
|
|
5213
|
+
},
|
|
5214
|
+
v
|
|
5215
|
+
)) })
|
|
5216
|
+
] }),
|
|
5217
|
+
pendingStage && deal && pendingStage.id !== deal.stageId && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 rounded-card border border-primary/30 bg-primary/5 px-3 py-2 text-xs", children: [
|
|
5218
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "h-3.5 w-3.5 shrink-0 text-primary" }),
|
|
5219
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground", children: t2("crm.card.stageIntent").replace("{from}", deal.stageName ?? "\u2014").replace("{to}", pendingStage.name) }),
|
|
5220
|
+
/* @__PURE__ */ jsx(
|
|
4495
5221
|
"button",
|
|
4496
5222
|
{
|
|
4497
5223
|
type: "button",
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
children: /* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5" })
|
|
5224
|
+
className: "ml-auto text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",
|
|
5225
|
+
onClick: () => onPendingResolved?.(false),
|
|
5226
|
+
children: t2("crm.card.stageIntentCancel")
|
|
4502
5227
|
}
|
|
4503
|
-
)
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
}
|
|
4525
|
-
) }),
|
|
4526
|
-
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
4527
|
-
/* @__PURE__ */ jsxs(Button, { className: "flex-1", onClick: () => {
|
|
4528
|
-
void save().then(() => setEditing(false));
|
|
4529
|
-
}, disabled: saving, children: [
|
|
4530
|
-
saving && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
4531
|
-
t2("crm.card.save")
|
|
4532
|
-
] }),
|
|
4533
|
-
/* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => setEditing(false), children: t2("crm.card.cancelEdit") })
|
|
4534
|
-
] })
|
|
4535
|
-
] })
|
|
4536
|
-
}
|
|
4537
|
-
),
|
|
4538
|
-
/* @__PURE__ */ jsx(Section, { title: t2("crm.card.owner"), children: team === null ? /* @__PURE__ */ jsx("div", { className: "h-9 animate-pulse rounded-lg bg-muted/40", "aria-hidden": true }) : team.length === 0 ? (
|
|
4539
|
-
// Lista vazia aqui quase sempre é falta de `members.read`, e
|
|
4540
|
-
// não uma casa sem equipe. Dizer "ninguém" seria mentir.
|
|
4541
|
-
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t2("crm.rota.cannotRead") })
|
|
4542
|
-
) : (
|
|
4543
|
-
// Uma linha só: quem é o dono (PersonPicker, com o retrato
|
|
4544
|
-
// — o rosto é o que distingue duas Anas em meio segundo) e,
|
|
4545
|
-
// ao lado, o ASSUMIR de um clique. Pegar a fila é o gesto
|
|
4546
|
-
// mais repetido do dia de prospecção; o botão some quando o
|
|
4547
|
-
// negócio já é de quem olha.
|
|
4548
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
5228
|
+
)
|
|
5229
|
+
] }),
|
|
5230
|
+
!composerOpen ? /* @__PURE__ */ jsx(
|
|
5231
|
+
"button",
|
|
5232
|
+
{
|
|
5233
|
+
type: "button",
|
|
5234
|
+
onClick: () => prepActivity(ctype),
|
|
5235
|
+
className: "w-full rounded-card border bg-card px-3 py-2.5 text-left text-sm text-muted-foreground shadow-sm transition-colors hover:bg-muted/30",
|
|
5236
|
+
children: t2("crm.followUp.placeholder")
|
|
5237
|
+
}
|
|
5238
|
+
) : /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-card border bg-card p-3 shadow-sm", children: [
|
|
5239
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: orderedTypes.map((tp) => /* @__PURE__ */ jsx(
|
|
5240
|
+
"button",
|
|
5241
|
+
{
|
|
5242
|
+
type: "button",
|
|
5243
|
+
onClick: () => setCtype(tp.value),
|
|
5244
|
+
className: "rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors " + (ctype === tp.value ? "border-primary bg-primary/10 text-primary" : "border-border text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
5245
|
+
children: tp.label
|
|
5246
|
+
},
|
|
5247
|
+
tp.value
|
|
5248
|
+
)) }),
|
|
4549
5249
|
/* @__PURE__ */ jsx(
|
|
4550
|
-
|
|
5250
|
+
"textarea",
|
|
4551
5251
|
{
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
value:
|
|
4555
|
-
onChange: (
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
void changeOwner(void 0);
|
|
5252
|
+
ref: composerRef,
|
|
5253
|
+
rows: 2,
|
|
5254
|
+
value: cnote,
|
|
5255
|
+
onChange: (e) => setCnote(e.target.value),
|
|
5256
|
+
onKeyDown: (e) => {
|
|
5257
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
5258
|
+
e.preventDefault();
|
|
5259
|
+
void logFromComposer();
|
|
5260
|
+
}
|
|
4562
5261
|
},
|
|
4563
|
-
|
|
5262
|
+
placeholder: t2("crm.followUp.placeholder"),
|
|
5263
|
+
className: "w-full resize-none rounded-lg border bg-background px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus:ring-2 focus:ring-ring"
|
|
4564
5264
|
}
|
|
4565
5265
|
),
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
5266
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
5267
|
+
CONTACT_TYPES2.has(ctype) && /* @__PURE__ */ jsxs(Select, { value: coutcome, onValueChange: (v) => {
|
|
5268
|
+
const nextOutcome = v;
|
|
5269
|
+
setCoutcome(nextOutcome);
|
|
5270
|
+
if (nextOutcome === "not_now" && !cfutureDate) setCfutureDate(defaultFutureContactDate());
|
|
5271
|
+
}, children: [
|
|
5272
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: "h-8 w-auto min-w-[10rem] text-xs", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
|
|
5273
|
+
/* @__PURE__ */ jsx(SelectContent, { children: ["connected", "no_answer", "left_message", "replied", "scheduled", "not_now"].map((o) => /* @__PURE__ */ jsx(SelectItem, { value: o, children: t2(`crm.outcome.${o}`) }, o)) })
|
|
5274
|
+
] }),
|
|
5275
|
+
ctype === "task" && /* @__PURE__ */ jsx(
|
|
5276
|
+
"input",
|
|
5277
|
+
{
|
|
5278
|
+
type: "date",
|
|
5279
|
+
value: cdue,
|
|
5280
|
+
onChange: (e) => setCdue(e.target.value),
|
|
5281
|
+
className: "h-8 rounded-lg border bg-background px-2 text-xs outline-none focus:ring-2 focus:ring-ring"
|
|
5282
|
+
}
|
|
5283
|
+
),
|
|
5284
|
+
CONTACT_TYPES2.has(ctype) && coutcome === "not_now" && /* @__PURE__ */ jsx(FutureContactPicker, { value: cfutureDate, onChange: setCfutureDate, required: true }),
|
|
5285
|
+
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-1.5", children: [
|
|
5286
|
+
/* @__PURE__ */ jsx(
|
|
5287
|
+
Button,
|
|
5288
|
+
{
|
|
5289
|
+
size: "sm",
|
|
5290
|
+
variant: "ghost",
|
|
5291
|
+
onClick: () => {
|
|
5292
|
+
setComposerOpen(false);
|
|
5293
|
+
if (pendingStage) onPendingResolved?.(false);
|
|
5294
|
+
},
|
|
5295
|
+
children: t2("crm.card.cancelEdit")
|
|
5296
|
+
}
|
|
5297
|
+
),
|
|
5298
|
+
/* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => {
|
|
5299
|
+
void logFromComposer();
|
|
5300
|
+
}, disabled: csaving || CONTACT_TYPES2.has(ctype) && coutcome === "not_now" && !cfutureDate, children: [
|
|
5301
|
+
csaving && /* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }),
|
|
5302
|
+
pendingStage ? t2("crm.card.stageIntentSave") : t2("crm.followUp.save")
|
|
5303
|
+
] })
|
|
5304
|
+
] })
|
|
4589
5305
|
] })
|
|
4590
5306
|
] }),
|
|
4591
|
-
|
|
4592
|
-
/* @__PURE__ */ jsx(Clock, { className: "h-3 w-3" }),
|
|
4593
|
-
formatDateTime(deal.createdAt, currency.locale),
|
|
4594
|
-
" (",
|
|
4595
|
-
formatRelativeTime(deal.createdAt, currency.locale),
|
|
4596
|
-
")"
|
|
4597
|
-
] })
|
|
4598
|
-
] })
|
|
4599
|
-
] }),
|
|
4600
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-3 p-5" + (wide ? " min-h-0 overflow-y-auto" : ""), children: [
|
|
4601
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
4602
|
-
/* @__PURE__ */ jsx("h3", { className: "text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: t2("crm.card.timeline") }),
|
|
4603
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: [["all", t2("crm.card.tabAll")], ["contact", t2("crm.card.tabContacts")], ["note", t2("crm.card.tabNotes")], ["task", t2("crm.card.tabTasks")]].map(([v, label2]) => /* @__PURE__ */ jsx(
|
|
4604
|
-
"button",
|
|
4605
|
-
{
|
|
4606
|
-
type: "button",
|
|
4607
|
-
onClick: () => setTimelineTab(v),
|
|
4608
|
-
className: "rounded-button px-2 py-0.5 text-xs transition-colors " + (timelineTab === v ? "bg-primary/10 font-medium text-primary" : "text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
4609
|
-
children: label2
|
|
4610
|
-
},
|
|
4611
|
-
v
|
|
4612
|
-
)) })
|
|
5307
|
+
/* @__PURE__ */ jsx(ActivityTimeline, { activities: shownActivities, loading: activitiesLoading, locale: currency.locale, contactName: deal?.contactName })
|
|
4613
5308
|
] }),
|
|
4614
|
-
|
|
4615
|
-
"
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
}
|
|
4622
|
-
|
|
4623
|
-
|
|
5309
|
+
/* @__PURE__ */ jsxs("div", { className: (wide ? "min-h-0 shrink-0 overflow-y-auto border-l" : "border-t") + " space-y-5 p-5", style: wide ? { width: "18rem" } : void 0, children: [
|
|
5310
|
+
deal?.groupName && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.groupTitle"), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-card border bg-muted/20 px-3 py-3", children: [
|
|
5311
|
+
/* @__PURE__ */ jsx(Network, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
5312
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
5313
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: deal.groupName }),
|
|
5314
|
+
deal.groupCompanies ? /* @__PURE__ */ jsx("span", { className: "block truncate text-[11px] text-muted-foreground", children: t2("crm.card.groupCompanies", { count: String(deal.groupCompanies) }) }) : null
|
|
5315
|
+
] })
|
|
5316
|
+
] }) }),
|
|
5317
|
+
!company && pessoaDoCard?.id && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsx(
|
|
5318
|
+
LinkCompanyPrompt,
|
|
5319
|
+
{
|
|
5320
|
+
personId: pessoaDoCard.id,
|
|
5321
|
+
companyText: pessoaDoCard.company ?? draft.company,
|
|
5322
|
+
onLinked: () => {
|
|
5323
|
+
void provider.getLiveDealById(dealId).then((d) => d && setDeal(d));
|
|
5324
|
+
}
|
|
5325
|
+
}
|
|
5326
|
+
) }),
|
|
5327
|
+
company && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsxs(
|
|
4624
5328
|
"button",
|
|
4625
5329
|
{
|
|
4626
5330
|
type: "button",
|
|
4627
|
-
onClick: () =>
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
5331
|
+
onClick: () => onViewCompany?.(company.id),
|
|
5332
|
+
disabled: !onViewCompany,
|
|
5333
|
+
className: "flex w-full items-center gap-3 rounded-card border bg-card px-3 py-3 text-left shadow-sm transition-colors enabled:hover:bg-muted/20",
|
|
5334
|
+
children: [
|
|
5335
|
+
/* @__PURE__ */ jsx(Building2, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
5336
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
5337
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: company.name }),
|
|
5338
|
+
/* @__PURE__ */ jsxs("span", { className: "block truncate text-[11px] text-muted-foreground", children: [
|
|
5339
|
+
company.documentNumber ? `CNPJ ${formatDocument(company.documentNumber)}` : t2("crm.card.noDocument"),
|
|
5340
|
+
company.peopleCount ? ` \xB7 ${t2("crm.card.peopleCount", { count: String(company.peopleCount) })}` : ""
|
|
5341
|
+
] })
|
|
5342
|
+
] }),
|
|
5343
|
+
company.documentNumber && /* @__PURE__ */ jsx(CopyDocument, { document: company.documentNumber, label: t2("crm.card.copyDocument") }),
|
|
5344
|
+
onViewCompany && /* @__PURE__ */ jsx(ArrowRight, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" })
|
|
5345
|
+
]
|
|
5346
|
+
}
|
|
5347
|
+
) }),
|
|
4633
5348
|
/* @__PURE__ */ jsx(
|
|
4634
|
-
|
|
5349
|
+
Section,
|
|
4635
5350
|
{
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
5351
|
+
title: t2("crm.dealSidebar.quotes"),
|
|
5352
|
+
action: onCreateQuote && lead ? /* @__PURE__ */ jsx(
|
|
5353
|
+
"button",
|
|
5354
|
+
{
|
|
5355
|
+
type: "button",
|
|
5356
|
+
onClick: () => onCreateQuote(lead.id),
|
|
5357
|
+
className: "text-[11px] font-medium text-primary hover:underline",
|
|
5358
|
+
children: t2("crm.leadDetail.createQuote")
|
|
4644
5359
|
}
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
5360
|
+
) : void 0,
|
|
5361
|
+
children: quotes2.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "\u2014" }) : /* @__PURE__ */ jsx("div", { className: "divide-y rounded-card border", children: quotes2.map((q) => /* @__PURE__ */ jsxs(
|
|
5362
|
+
"div",
|
|
5363
|
+
{
|
|
5364
|
+
onClick: () => onViewQuote?.(q.id),
|
|
5365
|
+
className: "flex cursor-pointer items-center justify-between px-3 py-2.5 transition-colors hover:bg-muted/20",
|
|
5366
|
+
children: [
|
|
5367
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
5368
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: q.quoteNumber }),
|
|
5369
|
+
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: q.quoteDate })
|
|
5370
|
+
] }),
|
|
5371
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", onClick: (e) => e.stopPropagation(), children: [
|
|
5372
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: formatCurrency(q.totalAmount, currency) }),
|
|
5373
|
+
/* @__PURE__ */ jsx(QuoteStatusDropdown, { quote: q, size: "sm", onStatusChange: (u) => setQuotes(quotes2.map((x) => x.id === u.id ? u : x)) })
|
|
5374
|
+
] })
|
|
5375
|
+
]
|
|
5376
|
+
},
|
|
5377
|
+
q.id
|
|
5378
|
+
)) })
|
|
4648
5379
|
}
|
|
4649
5380
|
),
|
|
4650
|
-
/* @__PURE__ */
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
CONTACT_TYPES2.has(ctype) && coutcome === "not_now" && /* @__PURE__ */ jsx(FutureContactPicker, { value: cfutureDate, onChange: setCfutureDate, required: true }),
|
|
4669
|
-
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-1.5", children: [
|
|
4670
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: () => setComposerOpen(false), children: t2("crm.card.cancelEdit") }),
|
|
4671
|
-
/* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => {
|
|
4672
|
-
void logFromComposer();
|
|
4673
|
-
}, disabled: csaving || CONTACT_TYPES2.has(ctype) && coutcome === "not_now" && !cfutureDate, children: [
|
|
4674
|
-
csaving && /* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }),
|
|
4675
|
-
t2("crm.followUp.save")
|
|
4676
|
-
] })
|
|
4677
|
-
] })
|
|
4678
|
-
] })
|
|
4679
|
-
] }),
|
|
4680
|
-
/* @__PURE__ */ jsx(ActivityTimeline, { activities: shownActivities, loading: activitiesLoading, locale: currency.locale, contactName: deal?.contactName })
|
|
4681
|
-
] }),
|
|
4682
|
-
/* @__PURE__ */ jsxs("div", { className: (wide ? "min-h-0 shrink-0 overflow-y-auto border-l" : "border-t") + " space-y-5 p-5", style: wide ? { width: "18rem" } : void 0, children: [
|
|
4683
|
-
deal?.groupName && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.groupTitle"), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-card border bg-muted/20 px-3 py-3", children: [
|
|
4684
|
-
/* @__PURE__ */ jsx(Network, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
4685
|
-
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
4686
|
-
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: deal.groupName }),
|
|
4687
|
-
deal.groupCompanies ? /* @__PURE__ */ jsx("span", { className: "block truncate text-[11px] text-muted-foreground", children: t2("crm.card.groupCompanies", { count: String(deal.groupCompanies) }) }) : null
|
|
4688
|
-
] })
|
|
4689
|
-
] }) }),
|
|
4690
|
-
!company && pessoaDoCard?.id && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsx(
|
|
4691
|
-
LinkCompanyPrompt,
|
|
4692
|
-
{
|
|
4693
|
-
personId: pessoaDoCard.id,
|
|
4694
|
-
companyText: pessoaDoCard.company ?? draft.company,
|
|
4695
|
-
onLinked: () => {
|
|
4696
|
-
void provider.getLiveDealById(dealId).then((d) => d && setDeal(d));
|
|
4697
|
-
}
|
|
4698
|
-
}
|
|
4699
|
-
) }),
|
|
4700
|
-
company && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsxs(
|
|
4701
|
-
"button",
|
|
4702
|
-
{
|
|
4703
|
-
type: "button",
|
|
4704
|
-
onClick: () => onViewCompany?.(company.id),
|
|
4705
|
-
disabled: !onViewCompany,
|
|
4706
|
-
className: "flex w-full items-center gap-3 rounded-card border bg-card px-3 py-3 text-left shadow-sm transition-colors enabled:hover:bg-muted/20",
|
|
4707
|
-
children: [
|
|
4708
|
-
/* @__PURE__ */ jsx(Building2, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
4709
|
-
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
4710
|
-
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: company.name }),
|
|
4711
|
-
/* @__PURE__ */ jsxs("span", { className: "block truncate text-[11px] text-muted-foreground", children: [
|
|
4712
|
-
company.documentNumber ? `CNPJ ${formatDocument(company.documentNumber)}` : t2("crm.card.noDocument"),
|
|
4713
|
-
company.peopleCount ? ` \xB7 ${t2("crm.card.peopleCount", { count: String(company.peopleCount) })}` : ""
|
|
4714
|
-
] })
|
|
4715
|
-
] }),
|
|
4716
|
-
company.documentNumber && /* @__PURE__ */ jsx(CopyDocument, { document: company.documentNumber, label: t2("crm.card.copyDocument") }),
|
|
4717
|
-
onViewCompany && /* @__PURE__ */ jsx(ArrowRight, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" })
|
|
4718
|
-
]
|
|
4719
|
-
}
|
|
4720
|
-
) }),
|
|
4721
|
-
/* @__PURE__ */ jsx(
|
|
4722
|
-
Section,
|
|
4723
|
-
{
|
|
4724
|
-
title: t2("crm.dealSidebar.quotes"),
|
|
4725
|
-
action: onCreateQuote && lead ? /* @__PURE__ */ jsx(
|
|
4726
|
-
"button",
|
|
4727
|
-
{
|
|
4728
|
-
type: "button",
|
|
4729
|
-
onClick: () => onCreateQuote(lead.id),
|
|
4730
|
-
className: "text-[11px] font-medium text-primary hover:underline",
|
|
4731
|
-
children: t2("crm.leadDetail.createQuote")
|
|
4732
|
-
}
|
|
4733
|
-
) : void 0,
|
|
4734
|
-
children: quotes2.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "\u2014" }) : /* @__PURE__ */ jsx("div", { className: "divide-y rounded-card border", children: quotes2.map((q) => /* @__PURE__ */ jsxs(
|
|
4735
|
-
"div",
|
|
4736
|
-
{
|
|
4737
|
-
onClick: () => onViewQuote?.(q.id),
|
|
4738
|
-
className: "flex cursor-pointer items-center justify-between px-3 py-2.5 transition-colors hover:bg-muted/20",
|
|
4739
|
-
children: [
|
|
4740
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
4741
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: q.quoteNumber }),
|
|
4742
|
-
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: q.quoteDate })
|
|
4743
|
-
] }),
|
|
4744
|
-
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", onClick: (e) => e.stopPropagation(), children: [
|
|
4745
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: formatCurrency(q.totalAmount, currency) }),
|
|
4746
|
-
/* @__PURE__ */ jsx(QuoteStatusDropdown, { quote: q, size: "sm", onStatusChange: (u) => setQuotes(quotes2.map((x) => x.id === u.id ? u : x)) })
|
|
4747
|
-
] })
|
|
4748
|
-
]
|
|
4749
|
-
},
|
|
4750
|
-
q.id
|
|
4751
|
-
)) })
|
|
4752
|
-
}
|
|
4753
|
-
),
|
|
4754
|
-
deal && deal.tags.length > 0 && /* @__PURE__ */ jsx(Section, { title: t2("crm.dealSidebar.tags"), children: /* @__PURE__ */ jsx(TagChips, { tags: deal.tags, defs: tagDefs, size: "sm", className: "gap-1.5" }) }),
|
|
4755
|
-
/* @__PURE__ */ jsx(FormAnswers, { lead })
|
|
4756
|
-
] })
|
|
4757
|
-
] }) })
|
|
4758
|
-
] }) });
|
|
5381
|
+
deal && deal.tags.length > 0 && /* @__PURE__ */ jsx(Section, { title: t2("crm.dealSidebar.tags"), children: /* @__PURE__ */ jsx(TagChips, { tags: deal.tags, defs: tagDefs, size: "sm", className: "gap-1.5" }) }),
|
|
5382
|
+
/* @__PURE__ */ jsx(FormAnswers, { lead })
|
|
5383
|
+
] })
|
|
5384
|
+
] }) })
|
|
5385
|
+
] }) }),
|
|
5386
|
+
/* @__PURE__ */ jsx(
|
|
5387
|
+
LostReasonDialog,
|
|
5388
|
+
{
|
|
5389
|
+
open: askingLost,
|
|
5390
|
+
saving: closing,
|
|
5391
|
+
onCancel: () => setAskingLost(false),
|
|
5392
|
+
onConfirm: (reason) => {
|
|
5393
|
+
setAskingLost(false);
|
|
5394
|
+
void close("lost", reason);
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
)
|
|
5398
|
+
] });
|
|
4759
5399
|
}
|
|
4760
5400
|
|
|
4761
5401
|
// src/lib/instagram.ts
|
|
@@ -4914,11 +5554,11 @@ function readMode() {
|
|
|
4914
5554
|
}
|
|
4915
5555
|
return "board";
|
|
4916
5556
|
}
|
|
4917
|
-
function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuote, onViewCompany, onCreateQuote, onAddLead, onOpenSettings }) {
|
|
5557
|
+
function DealsView({ mode, onChangeMode, openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuote, onViewCompany, onCreateQuote, onAddLead, onOpenSettings }) {
|
|
4918
5558
|
const t2 = useTranslation();
|
|
4919
5559
|
const provider = useCrmProvider();
|
|
4920
5560
|
const isWide = useIsWide();
|
|
4921
|
-
const
|
|
5561
|
+
const modo = mode ?? readMode();
|
|
4922
5562
|
const pipelines = useCrmStore((s) => s.pipelines);
|
|
4923
5563
|
const [openId, setOpenId] = useState(openDealId ?? null);
|
|
4924
5564
|
useEffect(() => {
|
|
@@ -4938,6 +5578,7 @@ function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuot
|
|
|
4938
5578
|
} catch {
|
|
4939
5579
|
}
|
|
4940
5580
|
};
|
|
5581
|
+
const [pendingStage, setPendingStage] = useState(null);
|
|
4941
5582
|
const [novoLead, setNovoLead] = useState(false);
|
|
4942
5583
|
const refreshBoard = useCrmStore((s) => s.refreshBoard);
|
|
4943
5584
|
const addLead = onAddLead ? () => setNovoLead(true) : void 0;
|
|
@@ -4959,23 +5600,10 @@ function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuot
|
|
|
4959
5600
|
const selectPipeline = useCrmStore((s) => s.selectPipeline);
|
|
4960
5601
|
useEffect(() => {
|
|
4961
5602
|
try {
|
|
4962
|
-
localStorage.setItem(STORAGE_KEY,
|
|
5603
|
+
localStorage.setItem(STORAGE_KEY, modo);
|
|
4963
5604
|
} catch {
|
|
4964
5605
|
}
|
|
4965
|
-
}, [
|
|
4966
|
-
const modeControl = /* @__PURE__ */ jsx(
|
|
4967
|
-
ViewTabs,
|
|
4968
|
-
{
|
|
4969
|
-
value: mode,
|
|
4970
|
-
onChange: setMode,
|
|
4971
|
-
"aria-label": t2("crm.deals.switchView"),
|
|
4972
|
-
options: [
|
|
4973
|
-
{ value: "board", label: t2("crm.deals.viewBoard") },
|
|
4974
|
-
{ value: "list", label: t2("crm.deals.viewList") },
|
|
4975
|
-
{ value: "funnel", label: t2("crm.deals.viewFunnel") }
|
|
4976
|
-
]
|
|
4977
|
-
}
|
|
4978
|
-
);
|
|
5606
|
+
}, [modo]);
|
|
4979
5607
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
4980
5608
|
!isWide && /* @__PURE__ */ jsx(PageHeaderActions, { children: /* @__PURE__ */ jsx(
|
|
4981
5609
|
PageActions,
|
|
@@ -5016,32 +5644,31 @@ function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuot
|
|
|
5016
5644
|
p.id
|
|
5017
5645
|
);
|
|
5018
5646
|
}) }),
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
}
|
|
5040
|
-
setMode("list");
|
|
5647
|
+
modo === "board" && /* @__PURE__ */ jsx(
|
|
5648
|
+
PipelineView,
|
|
5649
|
+
{
|
|
5650
|
+
onDealClick: openCard,
|
|
5651
|
+
onAddLead: addLead,
|
|
5652
|
+
onOpenSettings,
|
|
5653
|
+
onStageIntent: (deal, stage) => {
|
|
5654
|
+
setPendingStage(stage);
|
|
5655
|
+
openCard(deal.id);
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
),
|
|
5659
|
+
modo === "list" && /* @__PURE__ */ jsx(DealListView, { onOpenDeal: openCard }),
|
|
5660
|
+
modo === "funnel" && /* @__PURE__ */ jsx(
|
|
5661
|
+
DealFunnelView,
|
|
5662
|
+
{
|
|
5663
|
+
onStageClick: (stageId) => {
|
|
5664
|
+
try {
|
|
5665
|
+
sessionStorage.setItem("fayz.list.crm.deals.stage", JSON.stringify(stageId));
|
|
5666
|
+
} catch {
|
|
5041
5667
|
}
|
|
5668
|
+
onChangeMode?.("list");
|
|
5042
5669
|
}
|
|
5043
|
-
|
|
5044
|
-
|
|
5670
|
+
}
|
|
5671
|
+
),
|
|
5045
5672
|
novoLead && /* @__PURE__ */ jsx(LeadFormView, { onSaved: (id) => {
|
|
5046
5673
|
setNovoLead(false);
|
|
5047
5674
|
if (!id) return;
|
|
@@ -5057,7 +5684,15 @@ function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuot
|
|
|
5057
5684
|
dealId: openId ?? "",
|
|
5058
5685
|
open: !!openId,
|
|
5059
5686
|
seed: seedDeal,
|
|
5060
|
-
|
|
5687
|
+
pendingStage,
|
|
5688
|
+
onPendingResolved: (moved) => {
|
|
5689
|
+
setPendingStage(null);
|
|
5690
|
+
if (!moved) closeCard();
|
|
5691
|
+
},
|
|
5692
|
+
onClose: () => {
|
|
5693
|
+
setPendingStage(null);
|
|
5694
|
+
closeCard();
|
|
5695
|
+
},
|
|
5061
5696
|
onViewLead,
|
|
5062
5697
|
onViewQuote,
|
|
5063
5698
|
onViewCompany,
|
|
@@ -5066,6 +5701,189 @@ function DealsView({ openDealId, onOpenDeal, onCloseDeal, onViewLead, onViewQuot
|
|
|
5066
5701
|
)
|
|
5067
5702
|
] });
|
|
5068
5703
|
}
|
|
5704
|
+
function UnitGoalsView() {
|
|
5705
|
+
return /* @__PURE__ */ jsx(
|
|
5706
|
+
ComingSoon,
|
|
5707
|
+
{
|
|
5708
|
+
title: "Metas das unidades",
|
|
5709
|
+
summary: "Quanto cada unidade precisa vender no m\xEAs, e quanto j\xE1 vendeu. \xC9 a r\xE9gua contra a qual o resto do m\xF3dulo \xE9 lido.",
|
|
5710
|
+
v1Path: "CRM \u2192 Metas \u2192 Metas das Unidades",
|
|
5711
|
+
measured: "11 metas de unidade no V1 inteiro, nenhuma da Artorius.",
|
|
5712
|
+
missing: [
|
|
5713
|
+
"A meta por unidade e por m\xEAs, com o realizado ao lado",
|
|
5714
|
+
"O Financeiro j\xE1 tem uma tela de Metas (desligada no aplicativo central) \u2014 decidir se s\xE3o a mesma coisa antes de construir duas"
|
|
5715
|
+
]
|
|
5716
|
+
}
|
|
5717
|
+
);
|
|
5718
|
+
}
|
|
5719
|
+
function KpiGoalsView() {
|
|
5720
|
+
return /* @__PURE__ */ jsx(
|
|
5721
|
+
ComingSoon,
|
|
5722
|
+
{
|
|
5723
|
+
title: "Metas por indicador",
|
|
5724
|
+
summary: "A meta que n\xE3o \xE9 de faturamento: ticket m\xE9dio, taxa de retorno, n\xFAmero de atendimentos.",
|
|
5725
|
+
v1Path: "CRM \u2192 Metas \u2192 Metas por Indicador",
|
|
5726
|
+
measured: "ZERO no V1 inteiro (`unit_kpi_goals` vazia). A tela existe l\xE1 e nunca foi usada \u2014 antes de construir, confirmar que algu\xE9m quer.",
|
|
5727
|
+
missing: [
|
|
5728
|
+
"O cat\xE1logo de indicadores, que \xE9 a parte dif\xEDcil: cada um tem uma conta pr\xF3pria",
|
|
5729
|
+
"Sem isso, a tela \xE9 um formul\xE1rio para um n\xFAmero que ningu\xE9m compara com nada"
|
|
5730
|
+
]
|
|
5731
|
+
}
|
|
5732
|
+
);
|
|
5733
|
+
}
|
|
5734
|
+
function ProfessionalGoalsView() {
|
|
5735
|
+
return /* @__PURE__ */ jsx(
|
|
5736
|
+
ComingSoon,
|
|
5737
|
+
{
|
|
5738
|
+
title: "Metas por profissional",
|
|
5739
|
+
summary: "Quanto cada pessoa da equipe precisa vender \u2014 e o que ela j\xE1 vendeu no per\xEDodo.",
|
|
5740
|
+
v1Path: "CRM \u2192 Metas \u2192 Metas Profissionais",
|
|
5741
|
+
measured: "4 metas no V1 inteiro, nenhuma da Artorius.",
|
|
5742
|
+
missing: [
|
|
5743
|
+
"A meta por pessoa e per\xEDodo, lendo o realizado das vendas",
|
|
5744
|
+
"Liga-se \xE0 comiss\xE3o: quem bate meta costuma ter regra diferente"
|
|
5745
|
+
]
|
|
5746
|
+
}
|
|
5747
|
+
);
|
|
5748
|
+
}
|
|
5749
|
+
function FranchisorGoalsView() {
|
|
5750
|
+
return /* @__PURE__ */ jsx(
|
|
5751
|
+
ComingSoon,
|
|
5752
|
+
{
|
|
5753
|
+
title: "Metas do franqueador",
|
|
5754
|
+
summary: "A meta que a rede define para as unidades, vista de cima: quem bateu, quem n\xE3o bateu, e o consolidado.",
|
|
5755
|
+
v1Path: "CRM \u2192 Metas \u2192 Metas do Franqueador",
|
|
5756
|
+
measured: "1 meta em todo o V1. \xC9 tela de rede, e a Artorius \xE9 uma casa s\xF3.",
|
|
5757
|
+
missing: [
|
|
5758
|
+
"S\xF3 faz sentido com o escopo de rede resolvido \u2014 a unidade \xE9 o alcance que a RLS usa",
|
|
5759
|
+
"Depende de Metas das unidades existir primeiro"
|
|
5760
|
+
]
|
|
5761
|
+
}
|
|
5762
|
+
);
|
|
5763
|
+
}
|
|
5764
|
+
function TasksView() {
|
|
5765
|
+
return /* @__PURE__ */ jsx(
|
|
5766
|
+
ComingSoon,
|
|
5767
|
+
{
|
|
5768
|
+
title: "Tarefas",
|
|
5769
|
+
summary: "O que algu\xE9m combinou de fazer com um lead: ligar na quinta, mandar a proposta, passar na loja. Com dono, prazo e o que aconteceu.",
|
|
5770
|
+
v1Path: "CRM \u2192 Engajamento \u2192 Tarefas",
|
|
5771
|
+
measured: "1 tarefa em todo o V1. A tela existe l\xE1 e praticamente n\xE3o foi usada.",
|
|
5772
|
+
missing: [
|
|
5773
|
+
"A tarefa ligada ao lead ou ao neg\xF3cio, n\xE3o solta \u2014 \xE9 isso que a torna \xFAtil",
|
|
5774
|
+
"Atividades (que j\xE1 existe aqui) REGISTRA o que aconteceu; a tarefa \xE9 o que ainda vai acontecer",
|
|
5775
|
+
"O atraso tem de aparecer sozinho, sen\xE3o a lista vira arquivo"
|
|
5776
|
+
]
|
|
5777
|
+
}
|
|
5778
|
+
);
|
|
5779
|
+
}
|
|
5780
|
+
function FollowUpsView() {
|
|
5781
|
+
return /* @__PURE__ */ jsx(
|
|
5782
|
+
ComingSoon,
|
|
5783
|
+
{
|
|
5784
|
+
title: "Follow-ups",
|
|
5785
|
+
summary: "Os retornos combinados que est\xE3o vencendo: quem prometeu voltar a falar com quem, e quando.",
|
|
5786
|
+
v1Path: "CRM \u2192 Engajamento \u2192 Follow-ups",
|
|
5787
|
+
measured: "Vista de leitura no V1 \u2014 recorta as mesmas tarefas por data. Sem tarefa, n\xE3o h\xE1 follow-up.",
|
|
5788
|
+
missing: [
|
|
5789
|
+
"Depende de Tarefas existir: \xE9 o mesmo dado visto pela data",
|
|
5790
|
+
"A pergunta aqui \xE9 \xABo que eu devia ter feito e n\xE3o fiz\xBB, e ela se responde com um recorte, n\xE3o com uma tabela nova"
|
|
5791
|
+
]
|
|
5792
|
+
}
|
|
5793
|
+
);
|
|
5794
|
+
}
|
|
5795
|
+
function LoyaltyView() {
|
|
5796
|
+
return /* @__PURE__ */ jsx(
|
|
5797
|
+
ComingSoon,
|
|
5798
|
+
{
|
|
5799
|
+
title: "Clube de fidelidade",
|
|
5800
|
+
summary: "As regras do clube \u2014 quanto vale cada real gasto, o que o ponto compra, quando expira \u2014 e quem est\xE1 dentro.",
|
|
5801
|
+
v1Path: "CRM \u2192 Fideliza\xE7\xE3o \u2192 Programa de Fidelidade",
|
|
5802
|
+
measured: "1 programa cadastrado no V1 e ZERO membros (`loyalty_members` vazia). O clube existe no papel e n\xE3o tem s\xF3cio.",
|
|
5803
|
+
missing: [
|
|
5804
|
+
"As regras de ac\xFAmulo e de resgate, que \xE9 onde o programa vira ou n\xE3o vira dinheiro",
|
|
5805
|
+
"O saldo por cliente e o extrato dele \u2014 sem extrato, ningu\xE9m confia no saldo",
|
|
5806
|
+
"Antes de construir: 1 programa e 0 membros diz que a vers\xE3o do V1 n\xE3o convenceu ningu\xE9m"
|
|
5807
|
+
]
|
|
5808
|
+
}
|
|
5809
|
+
);
|
|
5810
|
+
}
|
|
5811
|
+
function ReferralsView() {
|
|
5812
|
+
return /* @__PURE__ */ jsx(
|
|
5813
|
+
ComingSoon,
|
|
5814
|
+
{
|
|
5815
|
+
title: "Indica\xE7\xF5es",
|
|
5816
|
+
summary: "Quem trouxe quem \u2014 e o que o indicador ganha por isso.",
|
|
5817
|
+
v1Path: "CRM \u2192 Fideliza\xE7\xE3o \u2192 Indica\xE7\xF5es",
|
|
5818
|
+
measured: "No V1 a indica\xE7\xE3o \xE9 um campo na ficha do cliente, n\xE3o um m\xF3dulo: n\xE3o h\xE1 tabela pr\xF3pria nem recompensa autom\xE1tica.",
|
|
5819
|
+
missing: [
|
|
5820
|
+
"Registrar a indica\xE7\xE3o no cadastro \xE9 f\xE1cil; PAGAR por ela \xE9 o que falta",
|
|
5821
|
+
"A recompensa liga isto ao Financeiro (cr\xE9dito) ou ao clube (pontos) \u2014 decidir qual antes"
|
|
5822
|
+
]
|
|
5823
|
+
}
|
|
5824
|
+
);
|
|
5825
|
+
}
|
|
5826
|
+
function BirthdaysView() {
|
|
5827
|
+
return /* @__PURE__ */ jsx(
|
|
5828
|
+
ComingSoon,
|
|
5829
|
+
{
|
|
5830
|
+
title: "Aniversariantes",
|
|
5831
|
+
summary: "Quem faz anivers\xE1rio nos pr\xF3ximos dias, para a casa fazer alguma coisa a respeito.",
|
|
5832
|
+
v1Path: "CRM \u2192 Fideliza\xE7\xE3o \u2192 Aniversariantes",
|
|
5833
|
+
measured: "Vista de leitura no V1 \u2014 recorta a data de nascimento da ficha do cliente. O dado j\xE1 atravessou para c\xE1.",
|
|
5834
|
+
missing: [
|
|
5835
|
+
"\xC9 um recorte da base de clientes, n\xE3o um cadastro novo \u2014 a tela mais barata desta lista",
|
|
5836
|
+
"O valor est\xE1 em disparar a mensagem a partir dela; sozinha \xE9 uma lista que algu\xE9m tem de lembrar de abrir",
|
|
5837
|
+
"Com o Marketing ao lado no mesmo menu, virar campanha recorrente \xE9 o caminho natural"
|
|
5838
|
+
]
|
|
5839
|
+
}
|
|
5840
|
+
);
|
|
5841
|
+
}
|
|
5842
|
+
function PendingReturnsView() {
|
|
5843
|
+
return /* @__PURE__ */ jsx(
|
|
5844
|
+
ComingSoon,
|
|
5845
|
+
{
|
|
5846
|
+
title: "Retornos pendentes",
|
|
5847
|
+
summary: "O cliente que costumava vir e parou: quem est\xE1 atrasado em rela\xE7\xE3o ao pr\xF3prio h\xE1bito.",
|
|
5848
|
+
v1Path: "CRM \u2192 Retornos Pendentes",
|
|
5849
|
+
measured: "Vista de leitura no V1 \u2014 calcula o intervalo entre atendimentos e marca quem passou dele. A Artorius n\xE3o atende, ent\xE3o l\xE1 ela \xE9 vazia.",
|
|
5850
|
+
missing: [
|
|
5851
|
+
"O c\xE1lculo do intervalo esperado POR CLIENTE \u2014 a m\xE9dia da casa acusa todo mundo ou ningu\xE9m",
|
|
5852
|
+
"\xC9 a tela que mais gera receita desta lista numa casa de servi\xE7o, e a que menos serve numa de compras"
|
|
5853
|
+
]
|
|
5854
|
+
}
|
|
5855
|
+
);
|
|
5856
|
+
}
|
|
5857
|
+
function OperationalDashboardView() {
|
|
5858
|
+
return /* @__PURE__ */ jsx(
|
|
5859
|
+
ComingSoon,
|
|
5860
|
+
{
|
|
5861
|
+
title: "Painel operacional",
|
|
5862
|
+
summary: "O dia da opera\xE7\xE3o num quadro: agenda ocupada, atendimentos, ticket, o que est\xE1 atrasado.",
|
|
5863
|
+
v1Path: "CRM \u2192 Dashboard Operacional",
|
|
5864
|
+
measured: "Vista de leitura no V1, montada sobre agendamentos e faturas. Sem venda pelo sistema n\xE3o tem o que mostrar.",
|
|
5865
|
+
missing: [
|
|
5866
|
+
"Definir os cinco n\xFAmeros que importam antes de desenhar \u2014 um painel com vinte cart\xF5es n\xE3o \xE9 lido",
|
|
5867
|
+
"O Resumo do CRM j\xE1 responde parte disto; decidir se s\xE3o duas telas ou uma"
|
|
5868
|
+
]
|
|
5869
|
+
}
|
|
5870
|
+
);
|
|
5871
|
+
}
|
|
5872
|
+
function MaturityView() {
|
|
5873
|
+
return /* @__PURE__ */ jsx(
|
|
5874
|
+
ComingSoon,
|
|
5875
|
+
{
|
|
5876
|
+
title: "Maturidade operacional",
|
|
5877
|
+
summary: "O quanto a casa usa o sistema de verdade: o que est\xE1 configurado, o que est\xE1 pela metade, o que nunca foi ligado.",
|
|
5878
|
+
v1Path: "CRM \u2192 Maturidade Operacional",
|
|
5879
|
+
measured: "Vista de leitura no V1 \u2014 pontua a conta contra uma lista de checagens.",
|
|
5880
|
+
missing: [
|
|
5881
|
+
"A lista de checagens \xE9 a tela: sem ela combinada, a nota n\xE3o quer dizer nada",
|
|
5882
|
+
"Os \xABPrimeiros passos\xBB daqui j\xE1 fazem parte disto, e para a conta nova s\xE3o melhores \u2014 isto \xE9 a mesma pergunta para quem j\xE1 rodou um ano"
|
|
5883
|
+
]
|
|
5884
|
+
}
|
|
5885
|
+
);
|
|
5886
|
+
}
|
|
5069
5887
|
var LEAD_STATUS_OPTIONS = [
|
|
5070
5888
|
{ value: "new", labelKey: "crm.leads.statusNew", dot: "#3B82F6" },
|
|
5071
5889
|
{ value: "contacted", labelKey: "crm.leads.statusContacted", dot: "#8B5CF6" },
|
|
@@ -5392,46 +6210,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
5392
6210
|
});
|
|
5393
6211
|
}
|
|
5394
6212
|
}));
|
|
5395
|
-
const whatsappAction = {
|
|
5396
|
-
id: "whatsapp-campaign",
|
|
5397
|
-
label: t2("crm.leads.bulkWhatsapp"),
|
|
5398
|
-
icon: Send,
|
|
5399
|
-
disabled: bulkBusy,
|
|
5400
|
-
onSelect: async (rows) => {
|
|
5401
|
-
const comFone = rows.filter((l) => (l.phone ?? "").replace(/\D/g, "").length >= 10);
|
|
5402
|
-
if (comFone.length === 0) {
|
|
5403
|
-
toast.error(t2("crm.leads.bulkWhatsappNoPhone"));
|
|
5404
|
-
return;
|
|
5405
|
-
}
|
|
5406
|
-
try {
|
|
5407
|
-
const sb = getSupabaseClientOptional();
|
|
5408
|
-
if (!sb) throw new Error(t2("crm.leads.bulkWhatsappFailed"));
|
|
5409
|
-
const tenantId = getActiveTenantId();
|
|
5410
|
-
const nome = `Leads \xB7 ${(/* @__PURE__ */ new Date()).toLocaleDateString()} \xB7 ${comFone.length}`;
|
|
5411
|
-
const { data: camp, error: e1 } = await sb.from("plg_conversations_campaigns").insert({ tenant_id: tenantId, name: nome, status: "draft" }).select("id").single();
|
|
5412
|
-
if (e1) throw new Error(e1.message);
|
|
5413
|
-
const alvos = comFone.map((l) => ({
|
|
5414
|
-
tenant_id: tenantId,
|
|
5415
|
-
campaign_id: camp.id,
|
|
5416
|
-
phone_e164: (l.phone ?? "").replace(/\D/g, ""),
|
|
5417
|
-
person_id: l.id
|
|
5418
|
-
}));
|
|
5419
|
-
for (let i = 0; i < alvos.length; i += 200) {
|
|
5420
|
-
const { error: e2 } = await sb.from("plg_conversations_campaign_targets").upsert(alvos.slice(i, i + 200), {
|
|
5421
|
-
onConflict: "campaign_id,phone_e164,rotation",
|
|
5422
|
-
ignoreDuplicates: true
|
|
5423
|
-
});
|
|
5424
|
-
if (e2) throw new Error(e2.message);
|
|
5425
|
-
}
|
|
5426
|
-
toast.success(t2("crm.leads.bulkWhatsappQueued", { count: String(comFone.length) }));
|
|
5427
|
-
window.location.hash = "#/conversations/campaigns";
|
|
5428
|
-
} catch (e) {
|
|
5429
|
-
toast.error(e?.message ?? t2("crm.leads.bulkWhatsappFailed"));
|
|
5430
|
-
}
|
|
5431
|
-
}
|
|
5432
|
-
};
|
|
5433
6213
|
return [
|
|
5434
|
-
whatsappAction,
|
|
5435
6214
|
...statusActions,
|
|
5436
6215
|
...can("sales", "delete") ? [{
|
|
5437
6216
|
id: "archive",
|
|
@@ -5873,6 +6652,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
5873
6652
|
)
|
|
5874
6653
|
] });
|
|
5875
6654
|
}
|
|
6655
|
+
var QUOTE_STATUSES = ["draft", "sent", "approved", "rejected", "expired", "archived"];
|
|
5876
6656
|
var STATUS_COLORS = {
|
|
5877
6657
|
draft: "bg-muted text-muted-foreground",
|
|
5878
6658
|
sent: "bg-info-soft text-info-soft-foreground",
|
|
@@ -5901,7 +6681,7 @@ function useQuoteColumns(currency, onEditQuote, onArchive) {
|
|
|
5901
6681
|
header: t2("crm.quotes.status"),
|
|
5902
6682
|
cell: ({ getValue }) => {
|
|
5903
6683
|
const status = getValue();
|
|
5904
|
-
return /* @__PURE__ */ jsx("span", { className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium
|
|
6684
|
+
return /* @__PURE__ */ jsx("span", { className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${STATUS_COLORS[status] ?? "bg-muted text-muted-foreground"}`, children: t2(`crm.quotes.status.${status}`) });
|
|
5905
6685
|
}
|
|
5906
6686
|
}
|
|
5907
6687
|
];
|
|
@@ -5951,9 +6731,50 @@ function QuoteListView({ onNew, onEdit, onEditQuote }) {
|
|
|
5951
6731
|
const fetchQuotes = useCrmStore((s) => s.fetchQuotes);
|
|
5952
6732
|
const archiveQuote = useCrmStore((s) => s.archiveQuote);
|
|
5953
6733
|
const canArchive = useCanArchive();
|
|
6734
|
+
const hoje = () => {
|
|
6735
|
+
const d = /* @__PURE__ */ new Date();
|
|
6736
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
6737
|
+
};
|
|
6738
|
+
const noventaDiasAtras = useMemo(() => {
|
|
6739
|
+
const d = /* @__PURE__ */ new Date();
|
|
6740
|
+
d.setDate(d.getDate() - 89);
|
|
6741
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
6742
|
+
}, []);
|
|
6743
|
+
const [dateFrom, setDateFrom] = useState(noventaDiasAtras);
|
|
6744
|
+
const [dateTo, setDateTo] = useState(hoje);
|
|
6745
|
+
const [statusFilter, setStatusFilter] = useState([]);
|
|
6746
|
+
const [contactId, setContactId] = useState("");
|
|
6747
|
+
const [contactName, setContactName] = useState("");
|
|
6748
|
+
const [search, setSearch] = useState("");
|
|
6749
|
+
const contactLookup = useMemo(
|
|
6750
|
+
() => createArchetypeLookup({ archetype: "person", kind: ["customer", "lead"] }),
|
|
6751
|
+
[]
|
|
6752
|
+
);
|
|
6753
|
+
const rascunho = useMemo(
|
|
6754
|
+
() => ({ from: dateFrom, to: dateTo, status: statusFilter, contactId, search: search.trim() }),
|
|
6755
|
+
[dateFrom, dateTo, statusFilter, contactId, search]
|
|
6756
|
+
);
|
|
6757
|
+
const [emVigor, setEmVigor] = useState(rascunho);
|
|
6758
|
+
const filtrosPendentes = useMemo(
|
|
6759
|
+
() => JSON.stringify(rascunho) !== JSON.stringify(emVigor),
|
|
6760
|
+
[rascunho, emVigor]
|
|
6761
|
+
);
|
|
6762
|
+
const aplicarFiltros = useCallback(() => setEmVigor(() => rascunho), [rascunho]);
|
|
6763
|
+
const limparFiltros = () => {
|
|
6764
|
+
setStatusFilter([]);
|
|
6765
|
+
setContactId("");
|
|
6766
|
+
setContactName("");
|
|
6767
|
+
setSearch("");
|
|
6768
|
+
};
|
|
6769
|
+
const filtrosAtivos = (statusFilter.length > 0 ? 1 : 0) + (contactId ? 1 : 0) + (search.trim() ? 1 : 0);
|
|
5954
6770
|
useEffect(() => {
|
|
5955
|
-
fetchQuotes({
|
|
5956
|
-
|
|
6771
|
+
fetchQuotes({
|
|
6772
|
+
dateRange: { from: emVigor.from, to: emVigor.to },
|
|
6773
|
+
status: emVigor.status.length > 0 ? emVigor.status : void 0,
|
|
6774
|
+
contactId: emVigor.contactId || void 0,
|
|
6775
|
+
search: emVigor.search || void 0
|
|
6776
|
+
});
|
|
6777
|
+
}, [emVigor]);
|
|
5957
6778
|
const [alvoArquivo, setAlvoArquivo] = useState(null);
|
|
5958
6779
|
const columns = useQuoteColumns(currency, onEditQuote, canArchive ? setAlvoArquivo : void 0);
|
|
5959
6780
|
const exportRows = useCallback(() => {
|
|
@@ -5990,6 +6811,89 @@ function QuoteListView({ onNew, onEdit, onEditQuote }) {
|
|
|
5990
6811
|
) })
|
|
5991
6812
|
}
|
|
5992
6813
|
),
|
|
6814
|
+
/* @__PURE__ */ jsxs(
|
|
6815
|
+
FilterPanel,
|
|
6816
|
+
{
|
|
6817
|
+
title: t2("crm.quotes.filtersTitle"),
|
|
6818
|
+
dirty: filtrosPendentes,
|
|
6819
|
+
onApply: aplicarFiltros,
|
|
6820
|
+
applyLabel: t2("crm.quotes.filterApply"),
|
|
6821
|
+
pendingTitle: t2("crm.quotes.filterPending"),
|
|
6822
|
+
pendingHint: t2("crm.quotes.filterPendingHint"),
|
|
6823
|
+
onClear: filtrosAtivos > 0 ? limparFiltros : void 0,
|
|
6824
|
+
clearLabel: t2("crm.quotes.filterClear"),
|
|
6825
|
+
busy: quotesLoading,
|
|
6826
|
+
children: [
|
|
6827
|
+
/* @__PURE__ */ jsx(FilterPanelField, { label: t2("crm.quotes.filterFrom"), children: /* @__PURE__ */ jsx(DatePicker, { variant: "input", format: "numeric", className: "w-full", value: dateFrom, onChange: (v) => v && setDateFrom(v) }) }),
|
|
6828
|
+
/* @__PURE__ */ jsx(FilterPanelField, { label: t2("crm.quotes.filterTo"), children: /* @__PURE__ */ jsx(DatePicker, { variant: "input", format: "numeric", className: "w-full", value: dateTo, onChange: (v) => v && setDateTo(v) }) }),
|
|
6829
|
+
/* @__PURE__ */ jsx(FilterPanelField, { label: t2("crm.quotes.status"), children: /* @__PURE__ */ jsx(
|
|
6830
|
+
RequiredFilter,
|
|
6831
|
+
{
|
|
6832
|
+
label: t2("crm.quotes.status"),
|
|
6833
|
+
value: statusFilter.length === 0 ? t2("crm.quotes.filterAllStatuses") : statusFilter.length === 1 ? t2(`crm.quotes.status.${statusFilter[0]}`) : t2("crud.list.selectedMany", { count: statusFilter.length }),
|
|
6834
|
+
icon: CircleDashed,
|
|
6835
|
+
className: "h-9 w-full justify-start",
|
|
6836
|
+
align: "start",
|
|
6837
|
+
children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
|
|
6838
|
+
/* @__PURE__ */ jsx(FilterMenuRow, { active: statusFilter.length === 0, onClick: () => setStatusFilter([]), children: t2("crm.quotes.filterAllStatuses") }),
|
|
6839
|
+
QUOTE_STATUSES.map((st) => {
|
|
6840
|
+
const on = statusFilter.includes(st);
|
|
6841
|
+
return /* @__PURE__ */ jsx(
|
|
6842
|
+
FilterMenuRow,
|
|
6843
|
+
{
|
|
6844
|
+
active: on,
|
|
6845
|
+
onClick: () => setStatusFilter(on ? statusFilter.filter((v) => v !== st) : [...statusFilter, st]),
|
|
6846
|
+
children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t2(`crm.quotes.status.${st}`) })
|
|
6847
|
+
},
|
|
6848
|
+
st
|
|
6849
|
+
);
|
|
6850
|
+
})
|
|
6851
|
+
] })
|
|
6852
|
+
}
|
|
6853
|
+
) }),
|
|
6854
|
+
/* @__PURE__ */ jsx(FilterPanelField, { label: t2("crm.quotes.contact"), compact: true, children: /* @__PURE__ */ jsx(
|
|
6855
|
+
SearchSelect,
|
|
6856
|
+
{
|
|
6857
|
+
className: "w-full",
|
|
6858
|
+
value: contactId,
|
|
6859
|
+
displayValue: contactName,
|
|
6860
|
+
placeholder: t2("crm.quotes.filterContactPlaceholder"),
|
|
6861
|
+
minChars: 2,
|
|
6862
|
+
minCharsLabel: t2("crm.quotes.filterMinChars"),
|
|
6863
|
+
noResultsLabel: t2("crm.quotes.filterNoContact"),
|
|
6864
|
+
searchingLabel: t2("crm.quotes.filterSearching"),
|
|
6865
|
+
loadOnOpen: false,
|
|
6866
|
+
clearLabel: t2("crm.quotes.filterAllContacts"),
|
|
6867
|
+
onChange: (id, option) => {
|
|
6868
|
+
setContactId(id);
|
|
6869
|
+
setContactName(option?.label ?? "");
|
|
6870
|
+
},
|
|
6871
|
+
onSearch: async (termo) => {
|
|
6872
|
+
const results = await contactLookup.search(termo);
|
|
6873
|
+
return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
|
|
6874
|
+
}
|
|
6875
|
+
}
|
|
6876
|
+
) })
|
|
6877
|
+
]
|
|
6878
|
+
}
|
|
6879
|
+
),
|
|
6880
|
+
/* @__PURE__ */ jsxs(Card, { className: "relative px-3 py-1.5", children: [
|
|
6881
|
+
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
|
|
6882
|
+
/* @__PURE__ */ jsx(
|
|
6883
|
+
"input",
|
|
6884
|
+
{
|
|
6885
|
+
type: "text",
|
|
6886
|
+
value: search,
|
|
6887
|
+
onChange: (e) => setSearch(e.target.value),
|
|
6888
|
+
onKeyDown: (e) => {
|
|
6889
|
+
if (e.key === "Enter") aplicarFiltros();
|
|
6890
|
+
},
|
|
6891
|
+
placeholder: t2("crm.quotes.searchPlaceholder"),
|
|
6892
|
+
"aria-label": t2("crm.quotes.searchPlaceholder"),
|
|
6893
|
+
className: "w-full bg-transparent py-1.5 pl-8 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none"
|
|
6894
|
+
}
|
|
6895
|
+
)
|
|
6896
|
+
] }),
|
|
5993
6897
|
/* @__PURE__ */ jsx(
|
|
5994
6898
|
DataTable,
|
|
5995
6899
|
{
|
|
@@ -6035,6 +6939,19 @@ var STATUSES = [
|
|
|
6035
6939
|
{ value: "rejected", labelKey: "crm.quoteForm.statusRejected", color: "bg-destructive-soft text-destructive-soft-foreground border border-destructive/30 dark:border-destructive/30" },
|
|
6036
6940
|
{ value: "expired", labelKey: "crm.quoteForm.statusExpired", color: "bg-muted text-muted-foreground border" }
|
|
6037
6941
|
];
|
|
6942
|
+
var VALIDITY_PRESETS = [
|
|
6943
|
+
{ days: 7, labelKey: "crm.quoteForm.validOneWeek" },
|
|
6944
|
+
{ days: 30, labelKey: "crm.quoteForm.validThirtyDays" }
|
|
6945
|
+
];
|
|
6946
|
+
function addDays(iso, days) {
|
|
6947
|
+
const d = /* @__PURE__ */ new Date(`${iso}T12:00:00`);
|
|
6948
|
+
d.setDate(d.getDate() + days);
|
|
6949
|
+
return d.toISOString().slice(0, 10);
|
|
6950
|
+
}
|
|
6951
|
+
function daysBetween2(from, to) {
|
|
6952
|
+
const ms = (/* @__PURE__ */ new Date(`${to}T12:00:00`)).getTime() - (/* @__PURE__ */ new Date(`${from}T12:00:00`)).getTime();
|
|
6953
|
+
return Math.round(ms / 864e5);
|
|
6954
|
+
}
|
|
6038
6955
|
var fid = 1;
|
|
6039
6956
|
function nextId() {
|
|
6040
6957
|
return `qi${fid++}`;
|
|
@@ -6043,7 +6960,15 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6043
6960
|
const t2 = useTranslation();
|
|
6044
6961
|
const config = useCrmConfig();
|
|
6045
6962
|
const provider = useCrmProvider();
|
|
6046
|
-
const { currency, itemTypes } = config;
|
|
6963
|
+
const { currency, itemTypes: declaredItemTypes } = config;
|
|
6964
|
+
const translatedItemTypes = React.useMemo(
|
|
6965
|
+
() => declaredItemTypes.map((tp) => {
|
|
6966
|
+
const traduzido = t2(`crm.itemType.${tp.value}`);
|
|
6967
|
+
return traduzido === `crm.itemType.${tp.value}` ? tp : { ...tp, label: traduzido };
|
|
6968
|
+
}),
|
|
6969
|
+
[declaredItemTypes, t2]
|
|
6970
|
+
);
|
|
6971
|
+
const itemTypes = useCatalogedItemTypes(translatedItemTypes, config.entityLookups);
|
|
6047
6972
|
const createQuote = useCrmStore((s) => s.createQuote);
|
|
6048
6973
|
const updateQuote = useCrmStore((s) => s.updateQuote);
|
|
6049
6974
|
const guardQuotes = useLimitGuard("quotes");
|
|
@@ -6059,6 +6984,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6059
6984
|
d.setDate(d.getDate() + 30);
|
|
6060
6985
|
return d.toISOString().slice(0, 10);
|
|
6061
6986
|
});
|
|
6987
|
+
const [validityDays, setValidityDays] = useState(30);
|
|
6062
6988
|
const [currentStatus, setCurrentStatus] = useState("draft");
|
|
6063
6989
|
const [paymentConditions, setPaymentConditions] = useState("");
|
|
6064
6990
|
const [observations, setObservations] = useState("");
|
|
@@ -6076,6 +7002,8 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6076
7002
|
setLinkedDealId(q.dealId ?? "");
|
|
6077
7003
|
setQuoteDate(q.quoteDate);
|
|
6078
7004
|
setValidUntil(q.validUntil);
|
|
7005
|
+
const span = daysBetween2(q.quoteDate, q.validUntil);
|
|
7006
|
+
setValidityDays(VALIDITY_PRESETS.some((pr) => pr.days === span) ? span : null);
|
|
6079
7007
|
setCurrentStatus(q.status);
|
|
6080
7008
|
setPaymentConditions(q.paymentConditions ?? "");
|
|
6081
7009
|
setObservations(q.observations ?? "");
|
|
@@ -6104,7 +7032,24 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6104
7032
|
setLoadingExisting(false);
|
|
6105
7033
|
});
|
|
6106
7034
|
}, [leadId]);
|
|
7035
|
+
function changeQuoteDate(iso) {
|
|
7036
|
+
setQuoteDate(iso);
|
|
7037
|
+
if (validityDays !== null) setValidUntil(addDays(iso, validityDays));
|
|
7038
|
+
}
|
|
7039
|
+
const openCustomOnMount = React.useRef(false);
|
|
7040
|
+
function pickValidity(days) {
|
|
7041
|
+
openCustomOnMount.current = days === null && validityDays !== null;
|
|
7042
|
+
setValidityDays(days);
|
|
7043
|
+
if (days !== null) setValidUntil(addDays(quoteDate, days));
|
|
7044
|
+
}
|
|
6107
7045
|
const totalAmount = items.reduce((sum, it) => sum + (it.quantity * it.unitPrice - it.discount), 0);
|
|
7046
|
+
function startAddItem() {
|
|
7047
|
+
if (itemTypes.length === 1) {
|
|
7048
|
+
addItemOfKind(itemTypes[0].value);
|
|
7049
|
+
return;
|
|
7050
|
+
}
|
|
7051
|
+
setAddingItem(true);
|
|
7052
|
+
}
|
|
6108
7053
|
function addItemOfKind(kind) {
|
|
6109
7054
|
const newItem = { _id: nextId(), itemKind: kind, description: "", quantity: 1, unitPrice: 0, discount: 0 };
|
|
6110
7055
|
setItems([...items, newItem]);
|
|
@@ -6184,40 +7129,73 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6184
7129
|
});
|
|
6185
7130
|
if (loadingExisting) return /* @__PURE__ */ jsx(OrderFormSkeleton, { parentLabel: t2("crm.quotes.title"), onBack: () => onSaved?.() });
|
|
6186
7131
|
const money2 = (v) => formatCurrency(v, currency);
|
|
6187
|
-
const
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
}
|
|
7132
|
+
const validUntilLabel = (/* @__PURE__ */ new Date(`${validUntil}T12:00:00`)).toLocaleDateString(getCurrentLocale());
|
|
7133
|
+
const contactSection = /* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.client"), children: /* @__PURE__ */ jsx(
|
|
7134
|
+
SearchSelect,
|
|
7135
|
+
{
|
|
7136
|
+
value: contactId,
|
|
7137
|
+
displayValue: contactName,
|
|
7138
|
+
onChange: (id, opt) => {
|
|
7139
|
+
setContactId(id);
|
|
7140
|
+
setContactName(opt?.label ?? "");
|
|
7141
|
+
},
|
|
7142
|
+
onSearch: async (q) => {
|
|
7143
|
+
if (!config.contactLookup) return [];
|
|
7144
|
+
const results = await config.contactLookup.search(q);
|
|
7145
|
+
return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
|
|
7146
|
+
},
|
|
7147
|
+
required: true,
|
|
7148
|
+
placeholder: t2("crm.quoteForm.searchClient"),
|
|
7149
|
+
allowCreate: true,
|
|
7150
|
+
createLabel: t2("crm.quoteForm.addAsLead"),
|
|
7151
|
+
onCreate: async (name) => {
|
|
7152
|
+
const lead = await provider.createLead({ name });
|
|
7153
|
+
setContactId(lead.id);
|
|
7154
|
+
setContactName(lead.name);
|
|
6211
7155
|
}
|
|
6212
|
-
|
|
7156
|
+
}
|
|
7157
|
+
) });
|
|
7158
|
+
const sideSections = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6213
7159
|
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.quoteDetails"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
6214
7160
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
6215
7161
|
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.quoteDate") }),
|
|
6216
|
-
/* @__PURE__ */ jsx(DatePicker, { value: quoteDate, onChange:
|
|
7162
|
+
/* @__PURE__ */ jsx(DatePicker, { value: quoteDate, onChange: changeQuoteDate, className: "mt-1" })
|
|
6217
7163
|
] }),
|
|
6218
7164
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
6219
|
-
/* @__PURE__ */
|
|
6220
|
-
|
|
7165
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
|
|
7166
|
+
/* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t2("crm.quoteForm.validUntil") }),
|
|
7167
|
+
validityDays === null ? /* @__PURE__ */ jsx(
|
|
7168
|
+
DatePicker,
|
|
7169
|
+
{
|
|
7170
|
+
variant: "inline",
|
|
7171
|
+
format: "numeric",
|
|
7172
|
+
value: validUntil,
|
|
7173
|
+
onChange: setValidUntil,
|
|
7174
|
+
defaultOpen: openCustomOnMount.current
|
|
7175
|
+
}
|
|
7176
|
+
) : /* @__PURE__ */ jsx("span", { className: "text-xs tabular-nums text-foreground", children: validUntilLabel })
|
|
7177
|
+
] }),
|
|
7178
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex flex-wrap gap-1.5", children: [
|
|
7179
|
+
VALIDITY_PRESETS.map((preset) => /* @__PURE__ */ jsx(
|
|
7180
|
+
"button",
|
|
7181
|
+
{
|
|
7182
|
+
type: "button",
|
|
7183
|
+
onClick: () => pickValidity(preset.days),
|
|
7184
|
+
className: `rounded-full border px-2.5 py-1 text-xs transition-colors ${validityDays === preset.days ? "border-primary bg-primary text-primary-foreground" : "border-input bg-card text-muted-foreground hover:bg-muted/50"}`,
|
|
7185
|
+
children: t2(preset.labelKey)
|
|
7186
|
+
},
|
|
7187
|
+
preset.days
|
|
7188
|
+
)),
|
|
7189
|
+
/* @__PURE__ */ jsx(
|
|
7190
|
+
"button",
|
|
7191
|
+
{
|
|
7192
|
+
type: "button",
|
|
7193
|
+
onClick: () => pickValidity(null),
|
|
7194
|
+
className: `rounded-full border px-2.5 py-1 text-xs transition-colors ${validityDays === null ? "border-primary bg-primary text-primary-foreground" : "border-input bg-card text-muted-foreground hover:bg-muted/50"}`,
|
|
7195
|
+
children: t2("crm.quoteForm.validCustom")
|
|
7196
|
+
}
|
|
7197
|
+
)
|
|
7198
|
+
] })
|
|
6221
7199
|
] })
|
|
6222
7200
|
] }) }),
|
|
6223
7201
|
/* @__PURE__ */ jsx(OrderFormBlock, { title: t2("crm.quoteForm.paymentConditions"), children: /* @__PURE__ */ jsx(
|
|
@@ -6241,7 +7219,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6241
7219
|
}
|
|
6242
7220
|
) })
|
|
6243
7221
|
] });
|
|
6244
|
-
return /* @__PURE__ */
|
|
7222
|
+
return /* @__PURE__ */ jsxs(
|
|
6245
7223
|
OrderFormView,
|
|
6246
7224
|
{
|
|
6247
7225
|
sideSections,
|
|
@@ -6256,60 +7234,65 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6256
7234
|
},
|
|
6257
7235
|
s.value
|
|
6258
7236
|
)) }),
|
|
6259
|
-
children:
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
{
|
|
6284
|
-
index: i,
|
|
6285
|
-
itemKind: item.itemKind,
|
|
6286
|
-
description: item.description,
|
|
6287
|
-
quantity: item.quantity,
|
|
6288
|
-
unitPrice: item.unitPrice,
|
|
6289
|
-
discount: item.discount,
|
|
6290
|
-
itemTypes,
|
|
6291
|
-
currency,
|
|
6292
|
-
formatMoney: money2,
|
|
6293
|
-
expanded: expandedItemId === item._id,
|
|
6294
|
-
onToggle: () => setExpandedItemId(expandedItemId === item._id ? null : item._id),
|
|
6295
|
-
onChange: (patch) => updateItem(item._id, patch),
|
|
6296
|
-
onRemove: () => removeItem(item._id),
|
|
6297
|
-
entityLookups: config.entityLookups,
|
|
6298
|
-
labels: {
|
|
6299
|
-
item: t2("crm.quoteForm.description"),
|
|
6300
|
-
description: t2("crm.quoteForm.description"),
|
|
6301
|
-
descriptionPlaceholder: t2("crm.quoteForm.itemDescriptionPlaceholder"),
|
|
6302
|
-
noDescription: t2("crm.quoteForm.noDescription"),
|
|
6303
|
-
qty: t2("crm.quoteForm.qty"),
|
|
6304
|
-
unitPrice: t2("crm.quoteForm.unitPrice"),
|
|
6305
|
-
discount: t2("crm.quoteForm.discount"),
|
|
6306
|
-
done: t2("crm.quoteForm.done")
|
|
7237
|
+
children: [
|
|
7238
|
+
contactSection,
|
|
7239
|
+
/* @__PURE__ */ jsx(
|
|
7240
|
+
OrderFormItemsCard,
|
|
7241
|
+
{
|
|
7242
|
+
label: t2("crm.quoteForm.quoteItems"),
|
|
7243
|
+
addLabel: t2("crm.quoteForm.addItem"),
|
|
7244
|
+
onAdd: startAddItem,
|
|
7245
|
+
addDisabled: !contactId,
|
|
7246
|
+
addDisabledHint: t2("crm.quoteForm.selectClientFirst"),
|
|
7247
|
+
count: items.length,
|
|
7248
|
+
countLabel: t2("crm.quoteForm.itemCount", { count: String(items.length) }),
|
|
7249
|
+
totalLabel: t2("crm.quoteForm.total"),
|
|
7250
|
+
total: money2(totalAmount),
|
|
7251
|
+
emptyLabel: contactId ? t2("crm.quoteForm.noItems") : t2("crm.quoteForm.selectClientFirst"),
|
|
7252
|
+
emptyActionLabel: t2("crm.quoteForm.addFirstItem"),
|
|
7253
|
+
header: addingItem && /* @__PURE__ */ jsx(
|
|
7254
|
+
OrderFormAddItemStep,
|
|
7255
|
+
{
|
|
7256
|
+
itemTypes,
|
|
7257
|
+
onSelect: addItemOfKind,
|
|
7258
|
+
onCancel: () => setAddingItem(false),
|
|
7259
|
+
label: t2("crm.quoteForm.selectItemType"),
|
|
7260
|
+
cancelLabel: t2("crm.quoteForm.cancel")
|
|
6307
7261
|
}
|
|
6308
|
-
|
|
6309
|
-
item
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
7262
|
+
),
|
|
7263
|
+
children: items.map((item, i) => /* @__PURE__ */ jsx(
|
|
7264
|
+
OrderFormItemRow,
|
|
7265
|
+
{
|
|
7266
|
+
index: i,
|
|
7267
|
+
itemKind: item.itemKind,
|
|
7268
|
+
description: item.description,
|
|
7269
|
+
quantity: item.quantity,
|
|
7270
|
+
unitPrice: item.unitPrice,
|
|
7271
|
+
discount: item.discount,
|
|
7272
|
+
itemTypes,
|
|
7273
|
+
currency,
|
|
7274
|
+
formatMoney: money2,
|
|
7275
|
+
expanded: expandedItemId === item._id,
|
|
7276
|
+
onToggle: () => setExpandedItemId(expandedItemId === item._id ? null : item._id),
|
|
7277
|
+
onChange: (patch) => updateItem(item._id, patch),
|
|
7278
|
+
onRemove: () => removeItem(item._id),
|
|
7279
|
+
entityLookups: config.entityLookups,
|
|
7280
|
+
labels: {
|
|
7281
|
+
item: t2("crm.quoteForm.description"),
|
|
7282
|
+
description: t2("crm.quoteForm.description"),
|
|
7283
|
+
descriptionPlaceholder: t2("crm.quoteForm.itemDescriptionPlaceholder"),
|
|
7284
|
+
noDescription: t2("crm.quoteForm.noDescription"),
|
|
7285
|
+
qty: t2("crm.quoteForm.qty"),
|
|
7286
|
+
unitPrice: t2("crm.quoteForm.unitPrice"),
|
|
7287
|
+
discount: t2("crm.quoteForm.discount"),
|
|
7288
|
+
done: t2("crm.quoteForm.done")
|
|
7289
|
+
}
|
|
7290
|
+
},
|
|
7291
|
+
item._id
|
|
7292
|
+
))
|
|
7293
|
+
}
|
|
7294
|
+
)
|
|
7295
|
+
]
|
|
6313
7296
|
}
|
|
6314
7297
|
);
|
|
6315
7298
|
}
|
|
@@ -10089,10 +11072,32 @@ function buildNav(config, view, navigate, hasAutomations, surveysLabel, networkL
|
|
|
10089
11072
|
{ id: "dashboard", label: config.labels.dashboard ?? t2("crm.nav.dashboard"), icon: "BarChart3", active: view === "dashboard", onClick: () => navigate("dashboard") }
|
|
10090
11073
|
];
|
|
10091
11074
|
if (config.modules.pipeline) {
|
|
10092
|
-
items.push({
|
|
11075
|
+
items.push({
|
|
11076
|
+
id: "pipeline",
|
|
11077
|
+
label: config.labels.pipeline ?? t2("crm.deals.title"),
|
|
11078
|
+
icon: "Filter",
|
|
11079
|
+
active: view.startsWith("pipeline"),
|
|
11080
|
+
children: [
|
|
11081
|
+
{ id: "pipeline", label: t2("crm.deals.viewBoard"), defaultChild: true, active: view === "pipeline" || view.startsWith("pipeline-detail"), onClick: () => navigate("pipeline") },
|
|
11082
|
+
{ id: "pipeline-list", label: t2("crm.deals.viewList"), active: view === "pipeline-list", onClick: () => navigate("pipeline-list") },
|
|
11083
|
+
{ id: "pipeline-funnel", label: t2("crm.deals.viewFunnel"), active: view === "pipeline-funnel", onClick: () => navigate("pipeline-funnel") }
|
|
11084
|
+
]
|
|
11085
|
+
});
|
|
10093
11086
|
}
|
|
10094
11087
|
if (flat) {
|
|
10095
|
-
items.push({
|
|
11088
|
+
items.push({
|
|
11089
|
+
id: "leads",
|
|
11090
|
+
label: config.labels.leads ?? t2("crm.leads.title"),
|
|
11091
|
+
icon: "UserPlus",
|
|
11092
|
+
active: view.startsWith("leads-") || view.startsWith("companies-") || view === "company-groups",
|
|
11093
|
+
children: [
|
|
11094
|
+
{ id: "leads-list", label: config.labels.leads ?? t2("crm.leads.title"), defaultChild: true, active: view === "leads-list" || view === "leads-new" || view.startsWith("leads-detail:"), onClick: () => navigate("leads-list") },
|
|
11095
|
+
...config.modules.companies ? [
|
|
11096
|
+
{ id: "companies-list", label: config.labels.companies ?? t2("crm.companies.title"), active: view === "companies-list" || view === "companies-new" || view.startsWith("companies-detail:") || view.startsWith("companies-edit:"), onClick: () => navigate("companies-list") },
|
|
11097
|
+
{ id: "company-groups", label: config.labels.groups ?? t2("crm.groups.title"), active: view === "company-groups", onClick: () => navigate("company-groups") }
|
|
11098
|
+
] : []
|
|
11099
|
+
]
|
|
11100
|
+
});
|
|
10096
11101
|
} else {
|
|
10097
11102
|
items.push({
|
|
10098
11103
|
id: "leads",
|
|
@@ -10146,9 +11151,50 @@ function buildNav(config, view, navigate, hasAutomations, surveysLabel, networkL
|
|
|
10146
11151
|
]
|
|
10147
11152
|
});
|
|
10148
11153
|
}
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
11154
|
+
items.push({
|
|
11155
|
+
id: "engagement",
|
|
11156
|
+
label: t2("crm.engagement.title"),
|
|
11157
|
+
icon: "Clock",
|
|
11158
|
+
active: view === "tasks" || view === "follow-ups",
|
|
11159
|
+
children: [
|
|
11160
|
+
{ id: "tasks", label: t2("crm.engagement.tasks"), defaultChild: true, active: view === "tasks", onClick: () => navigate("tasks") },
|
|
11161
|
+
{ id: "follow-ups", label: t2("crm.engagement.followUps"), active: view === "follow-ups", onClick: () => navigate("follow-ups") }
|
|
11162
|
+
]
|
|
11163
|
+
});
|
|
11164
|
+
items.push({
|
|
11165
|
+
id: "retention",
|
|
11166
|
+
label: t2("crm.retention.title"),
|
|
11167
|
+
icon: "Gift",
|
|
11168
|
+
active: ["loyalty", "referrals", "birthdays", "pending-returns"].includes(view),
|
|
11169
|
+
children: [
|
|
11170
|
+
{ id: "loyalty", label: t2("crm.retention.loyalty"), defaultChild: true, active: view === "loyalty", onClick: () => navigate("loyalty") },
|
|
11171
|
+
{ id: "referrals", label: t2("crm.retention.referrals"), active: view === "referrals", onClick: () => navigate("referrals") },
|
|
11172
|
+
{ id: "birthdays", label: t2("crm.retention.birthdays"), active: view === "birthdays", onClick: () => navigate("birthdays") },
|
|
11173
|
+
{ id: "pending-returns", label: t2("crm.retention.pendingReturns"), active: view === "pending-returns", onClick: () => navigate("pending-returns") }
|
|
11174
|
+
]
|
|
11175
|
+
});
|
|
11176
|
+
items.push({
|
|
11177
|
+
id: "goals",
|
|
11178
|
+
label: t2("crm.goals.title"),
|
|
11179
|
+
icon: "Target",
|
|
11180
|
+
active: ["goals-units", "goals-kpi", "goals-professionals", "goals-franchisor"].includes(view),
|
|
11181
|
+
children: [
|
|
11182
|
+
{ id: "goals-units", label: t2("crm.goals.units"), defaultChild: true, active: view === "goals-units", onClick: () => navigate("goals-units") },
|
|
11183
|
+
{ id: "goals-kpi", label: t2("crm.goals.kpi"), active: view === "goals-kpi", onClick: () => navigate("goals-kpi") },
|
|
11184
|
+
{ id: "goals-professionals", label: t2("crm.goals.professionals"), active: view === "goals-professionals", onClick: () => navigate("goals-professionals") },
|
|
11185
|
+
{ id: "goals-franchisor", label: t2("crm.goals.franchisor"), active: view === "goals-franchisor", onClick: () => navigate("goals-franchisor") }
|
|
11186
|
+
]
|
|
11187
|
+
});
|
|
11188
|
+
items.push({
|
|
11189
|
+
id: "panels",
|
|
11190
|
+
label: t2("crm.panels.title"),
|
|
11191
|
+
icon: "LayoutDashboard",
|
|
11192
|
+
active: view === "operational-dashboard" || view === "maturity",
|
|
11193
|
+
children: [
|
|
11194
|
+
{ id: "operational-dashboard", label: t2("crm.panels.operational"), defaultChild: true, active: view === "operational-dashboard", onClick: () => navigate("operational-dashboard") },
|
|
11195
|
+
{ id: "maturity", label: t2("crm.panels.maturity"), active: view === "maturity", onClick: () => navigate("maturity") }
|
|
11196
|
+
]
|
|
11197
|
+
});
|
|
10152
11198
|
if (config.modules.surveys) {
|
|
10153
11199
|
items.push({ id: "surveys", label: surveysLabel, icon: "Star", active: view === "surveys", onClick: () => navigate("surveys") });
|
|
10154
11200
|
}
|
|
@@ -10193,7 +11239,6 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
10193
11239
|
const onboarding = usePluginOnboardingGate("saas-core:crm-onboarded", checkExistingData);
|
|
10194
11240
|
const isSettings = view === "settings";
|
|
10195
11241
|
const isSummary = view === "dashboard";
|
|
10196
|
-
const leadsFamilyTab = view === "leads-list" || view === "leads-new" ? "leads" : view === "companies-list" || view === "companies-new" ? "companies" : view === "company-groups" ? "groups" : null;
|
|
10197
11242
|
const openStageSettings = () => adminNavigateTo("/settings/crm/_properties/stages");
|
|
10198
11243
|
const runtime = usePluginRuntimeOptional();
|
|
10199
11244
|
const hasAutomations = Boolean(runtime?.activePlugins.some((p) => p.id === "automations"));
|
|
@@ -10203,8 +11248,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
10203
11248
|
const quickActions = useMemo(() => [
|
|
10204
11249
|
{ id: "new-lead", label: t2("crm.quickActions.newLead"), icon: "UserPlus", description: t2("crm.quickActions.newLeadDesc"), action: () => navigate("leads-new") },
|
|
10205
11250
|
{ id: "new-deal", label: t2("crm.quickActions.newDeal"), icon: "Target", description: t2("crm.quickActions.newDealDesc"), action: () => navigate("pipeline") },
|
|
10206
|
-
...config.modules.quotes ? [{ id: "new-quote", label: t2("crm.quickActions.newQuote"), icon: "FileText", description: t2("crm.quickActions.newQuoteDesc"), action: () => navigate("quotes-new") }] : []
|
|
10207
|
-
...config.modules.activities ? [{ id: "log-activity", label: t2("crm.quickActions.logActivity"), icon: "MessageCircle", description: t2("crm.quickActions.logActivityDesc"), action: () => navigate("activities") }] : []
|
|
11251
|
+
...config.modules.quotes ? [{ id: "new-quote", label: t2("crm.quickActions.newQuote"), icon: "FileText", description: t2("crm.quickActions.newQuoteDesc"), action: () => navigate("quotes-new") }] : []
|
|
10208
11252
|
], [config.modules]);
|
|
10209
11253
|
if (isSummary && onboarding.status === "checking") {
|
|
10210
11254
|
return /* @__PURE__ */ jsx(CrmContextProvider, { config, provider, store, children: /* @__PURE__ */ jsx(PluginOnboardingGateSkeleton, {}) });
|
|
@@ -10225,11 +11269,13 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
10225
11269
|
// O funil e o funil COM UM CARD ABERTO são a mesma view: só muda a prop.
|
|
10226
11270
|
// Assim a URL carrega o id (`/sales/pipeline/<id>` — um link que o colega
|
|
10227
11271
|
// abre no card certo) sem que o quadro desmonte a cada card aberto.
|
|
10228
|
-
...["pipeline", "pipeline-detail"].map((id) => ({
|
|
11272
|
+
...["pipeline", "pipeline-detail", "pipeline-list", "pipeline-funnel"].map((id) => ({
|
|
10229
11273
|
id,
|
|
10230
11274
|
render: ({ id: dealId }) => /* @__PURE__ */ jsx(
|
|
10231
11275
|
DealsView,
|
|
10232
11276
|
{
|
|
11277
|
+
mode: id === "pipeline-list" ? "list" : id === "pipeline-funnel" ? "funnel" : "board",
|
|
11278
|
+
onChangeMode: (m) => navigate(m === "list" ? "pipeline-list" : m === "funnel" ? "pipeline-funnel" : "pipeline"),
|
|
10233
11279
|
openDealId: dealId,
|
|
10234
11280
|
onOpenDeal: (did) => navigate(`pipeline-detail:${did}`),
|
|
10235
11281
|
onCloseDeal: () => navigate("pipeline"),
|
|
@@ -10281,11 +11327,24 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
10281
11327
|
onOpenDeal: (did) => navigate(`pipeline-detail:${did}`, `/sales/pipeline/${did}`)
|
|
10282
11328
|
}
|
|
10283
11329
|
) },
|
|
11330
|
+
// As telas que ainda não existem — ver ./GapScreens.
|
|
11331
|
+
{ id: "tasks", render: () => /* @__PURE__ */ jsx(TasksView, {}) },
|
|
11332
|
+
{ id: "follow-ups", render: () => /* @__PURE__ */ jsx(FollowUpsView, {}) },
|
|
11333
|
+
{ id: "loyalty", render: () => /* @__PURE__ */ jsx(LoyaltyView, {}) },
|
|
11334
|
+
{ id: "referrals", render: () => /* @__PURE__ */ jsx(ReferralsView, {}) },
|
|
11335
|
+
{ id: "birthdays", render: () => /* @__PURE__ */ jsx(BirthdaysView, {}) },
|
|
11336
|
+
{ id: "pending-returns", render: () => /* @__PURE__ */ jsx(PendingReturnsView, {}) },
|
|
11337
|
+
{ id: "goals-units", render: () => /* @__PURE__ */ jsx(UnitGoalsView, {}) },
|
|
11338
|
+
{ id: "goals-kpi", render: () => /* @__PURE__ */ jsx(KpiGoalsView, {}) },
|
|
11339
|
+
{ id: "goals-professionals", render: () => /* @__PURE__ */ jsx(ProfessionalGoalsView, {}) },
|
|
11340
|
+
{ id: "goals-franchisor", render: () => /* @__PURE__ */ jsx(FranchisorGoalsView, {}) },
|
|
11341
|
+
{ id: "operational-dashboard", render: () => /* @__PURE__ */ jsx(OperationalDashboardView, {}) },
|
|
11342
|
+
{ id: "maturity", render: () => /* @__PURE__ */ jsx(MaturityView, {}) },
|
|
10284
11343
|
{ id: "surveys", render: () => /* @__PURE__ */ jsx(SurveysView, {}) },
|
|
10285
11344
|
{ id: "network", render: () => /* @__PURE__ */ jsx(NetworkView, {}) },
|
|
10286
11345
|
{ id: "dashboard", render: () => /* @__PURE__ */ jsx(DashboardView, {}) }
|
|
10287
11346
|
], "dashboard");
|
|
10288
|
-
return /* @__PURE__ */ jsx(CrmContextProvider, { config, provider, store, children: /* @__PURE__ */
|
|
11347
|
+
return /* @__PURE__ */ jsx(CrmContextProvider, { config, provider, store, children: /* @__PURE__ */ jsx(
|
|
10289
11348
|
ModulePage,
|
|
10290
11349
|
{
|
|
10291
11350
|
title: config.labels.pageTitle,
|
|
@@ -10302,24 +11361,7 @@ function CrmPage({ config, provider, store, registries }) {
|
|
|
10302
11361
|
settingsPath: registries && registries.length > 0 ? "/settings/crm" : void 0
|
|
10303
11362
|
}
|
|
10304
11363
|
),
|
|
10305
|
-
children:
|
|
10306
|
-
config.navStyle === "flat" && leadsFamilyTab && /* @__PURE__ */ jsxs(PageViewBar, { children: [
|
|
10307
|
-
/* @__PURE__ */ jsx(
|
|
10308
|
-
ViewTabs,
|
|
10309
|
-
{
|
|
10310
|
-
value: leadsFamilyTab,
|
|
10311
|
-
onChange: (v) => navigate(v === "leads" ? "leads-list" : v === "companies" ? "companies-list" : "company-groups"),
|
|
10312
|
-
options: [
|
|
10313
|
-
{ value: "leads", label: config.labels.leads ?? t2("crm.leads.title") },
|
|
10314
|
-
{ value: "companies", label: config.labels.companies ?? t2("crm.companies.title") },
|
|
10315
|
-
{ value: "groups", label: config.labels.groups ?? t2("crm.groups.title") }
|
|
10316
|
-
]
|
|
10317
|
-
}
|
|
10318
|
-
),
|
|
10319
|
-
/* @__PURE__ */ jsx("span", {})
|
|
10320
|
-
] }),
|
|
10321
|
-
renderView(view)
|
|
10322
|
-
]
|
|
11364
|
+
children: renderView(view)
|
|
10323
11365
|
}
|
|
10324
11366
|
) });
|
|
10325
11367
|
}
|
|
@@ -11136,7 +12178,8 @@ function createMockCrmProvider(options) {
|
|
|
11136
12178
|
const map = /* @__PURE__ */ new Map();
|
|
11137
12179
|
const totals = /* @__PURE__ */ new Map();
|
|
11138
12180
|
for (const stage of stages) {
|
|
11139
|
-
const
|
|
12181
|
+
const cabe = (d) => stage.isLost ? d.status === "lost" : d.status !== "lost" && d.status !== "archived";
|
|
12182
|
+
const todos = store.deals.filter((d) => d.stageId === stage.id && cabe(d) && matches2(d));
|
|
11140
12183
|
totals.set(stage.id, todos.length);
|
|
11141
12184
|
map.set(stage.id, todos.slice(0, limits?.[stage.id] ?? MOCK_DEALS_POR_ETAPA));
|
|
11142
12185
|
}
|
|
@@ -11309,6 +12352,9 @@ function createMockCrmProvider(options) {
|
|
|
11309
12352
|
results = results.filter((q) => statuses.includes(q.status));
|
|
11310
12353
|
}
|
|
11311
12354
|
if (query.contactId) results = results.filter((q) => q.contactId === query.contactId);
|
|
12355
|
+
if (query.dateRange) {
|
|
12356
|
+
results = results.filter((q) => q.quoteDate >= query.dateRange.from && q.quoteDate <= query.dateRange.to);
|
|
12357
|
+
}
|
|
11312
12358
|
if (query.search) {
|
|
11313
12359
|
const s = query.search.toLowerCase();
|
|
11314
12360
|
results = results.filter((q) => q.quoteNumber.includes(s) || q.contactName?.toLowerCase().includes(s));
|
|
@@ -12079,10 +13125,10 @@ function createMockCrmProvider(options) {
|
|
|
12079
13125
|
if (!key) return [];
|
|
12080
13126
|
return store.personPhones.filter((p) => p.phoneKey === key);
|
|
12081
13127
|
},
|
|
12082
|
-
async getFunnel(pipelineId) {
|
|
13128
|
+
async getFunnel(pipelineId, filter) {
|
|
12083
13129
|
const stages = store.stages.filter((s) => s.pipelineId === pipelineId && !s.isLost).sort((a, b) => a.order - b.order);
|
|
12084
13130
|
return stages.map((stage) => {
|
|
12085
|
-
const deals = store.deals.filter((d) => d.stageId === stage.id);
|
|
13131
|
+
const deals = store.deals.filter((d) => d.stageId === stage.id && (!filter?.tags?.length || (d.tags ?? []).some((t2) => filter.tags.includes(t2))) && (!filter?.assignedToId || (filter.assignedToId === "none" ? !d.assignedToId : d.assignedToId === filter.assignedToId)) && (!filter?.createdFrom || (d.createdAt ?? "") >= filter.createdFrom) && (!filter?.createdTo || (d.createdAt ?? "") <= filter.createdTo));
|
|
12086
13132
|
return {
|
|
12087
13133
|
stageId: stage.id,
|
|
12088
13134
|
stageName: stage.name,
|
|
@@ -12179,6 +13225,26 @@ var t;
|
|
|
12179
13225
|
function getCrmTenantId() {
|
|
12180
13226
|
return t;
|
|
12181
13227
|
}
|
|
13228
|
+
function serves(pipeline2, scope) {
|
|
13229
|
+
const units = pipeline2.unitIds ?? [];
|
|
13230
|
+
const teams = pipeline2.teamIds ?? [];
|
|
13231
|
+
if (units.length > 0 && scope.unitId && !units.includes(scope.unitId)) return false;
|
|
13232
|
+
if (teams.length > 0 && scope.teamId && !teams.includes(scope.teamId)) return false;
|
|
13233
|
+
return true;
|
|
13234
|
+
}
|
|
13235
|
+
function pipelinesForSession(pipelines, scope) {
|
|
13236
|
+
const mine = pipelines.filter((p) => serves(p, scope));
|
|
13237
|
+
return mine.length > 0 ? mine : pipelines;
|
|
13238
|
+
}
|
|
13239
|
+
async function fetchMyTeamId(tenantId, userId) {
|
|
13240
|
+
const db = getSupabaseClientOptional();
|
|
13241
|
+
if (!db) return null;
|
|
13242
|
+
const { data: membership } = await db.from("v_team_members").select("person_id").eq("tenant_id", tenantId).eq("user_id", userId).maybeSingle();
|
|
13243
|
+
if (!membership?.person_id) return null;
|
|
13244
|
+
const { data: person } = await db.from("people").select("custom_fields").eq("id", membership.person_id).maybeSingle();
|
|
13245
|
+
const teamId = person?.custom_fields?.teamId;
|
|
13246
|
+
return typeof teamId === "string" && teamId ? teamId : null;
|
|
13247
|
+
}
|
|
12182
13248
|
|
|
12183
13249
|
// src/data/supabase.ts
|
|
12184
13250
|
function orTerm(raw) {
|
|
@@ -12428,8 +13494,17 @@ function createSupabaseCrmProvider(options) {
|
|
|
12428
13494
|
const { pub } = getClients();
|
|
12429
13495
|
const tenantId = getTenantId();
|
|
12430
13496
|
if (!tenantId) return [];
|
|
12431
|
-
const
|
|
12432
|
-
|
|
13497
|
+
const ler = (from) => pub.from(from).select("*").eq("tenant_id", tenantId).eq("is_active", true).order("is_default", { ascending: false }).order("name");
|
|
13498
|
+
let { data, error } = await ler(T.pipelinesView);
|
|
13499
|
+
if (error) ({ data } = await ler(T.pipelines));
|
|
13500
|
+
const todos = (data ?? []).map((r) => ({
|
|
13501
|
+
...snakeToCamel(r),
|
|
13502
|
+
unitIds: r.unit_ids ?? [],
|
|
13503
|
+
teamIds: r.team_ids ?? []
|
|
13504
|
+
}));
|
|
13505
|
+
const userId = await loadMyUserId();
|
|
13506
|
+
const teamId = userId ? await fetchMyTeamId(tenantId, userId).catch(() => null) : null;
|
|
13507
|
+
return pipelinesForSession(todos, { unitId: getActiveUnitId(), teamId });
|
|
12433
13508
|
},
|
|
12434
13509
|
async getPipelineStages(pipelineId) {
|
|
12435
13510
|
const { pub } = getClients();
|
|
@@ -12646,8 +13721,9 @@ function createSupabaseCrmProvider(options) {
|
|
|
12646
13721
|
async getDealsByStage(pipelineId, filter, knownStages, limits) {
|
|
12647
13722
|
const { pub } = getClients();
|
|
12648
13723
|
const stages = knownStages ?? await provider.getPipelineStages(pipelineId);
|
|
12649
|
-
const montar = async (
|
|
12650
|
-
let qb = pub.from("v_deals").select("*", { count: "exact" }).eq("pipeline_id", pipelineId).eq("stage_id",
|
|
13724
|
+
const montar = async (stage) => {
|
|
13725
|
+
let qb = pub.from("v_deals").select("*", { count: "exact" }).eq("pipeline_id", pipelineId).eq("stage_id", stage.id);
|
|
13726
|
+
qb = stage.isLost ? qb.neq("status", "archived") : qb.not("status", "in", "(lost,archived)");
|
|
12651
13727
|
if (filter?.tags?.length) qb = qb.overlaps("tags", filter.tags);
|
|
12652
13728
|
if (filter?.search) {
|
|
12653
13729
|
const t2 = filter.search.replace(/[(),]/g, " ").trim();
|
|
@@ -12661,11 +13737,11 @@ function createSupabaseCrmProvider(options) {
|
|
|
12661
13737
|
if (filter?.createdTo) qb = qb.lte("created_at", filter.createdTo);
|
|
12662
13738
|
if (filter?.assignedToId === "none") qb = qb.is("assigned_to_id", null);
|
|
12663
13739
|
else if (filter?.assignedToId) qb = qb.eq("assigned_to_id", filter.assignedToId);
|
|
12664
|
-
const teto = limits?.[
|
|
13740
|
+
const teto = limits?.[stage.id] ?? DEALS_POR_ETAPA;
|
|
12665
13741
|
const { data: data2, count } = await qb.order("updated_at", { ascending: false }).limit(teto);
|
|
12666
|
-
return { stageId, rows: data2 ?? [], total: count ?? (data2?.length ?? 0) };
|
|
13742
|
+
return { stageId: stage.id, rows: data2 ?? [], total: count ?? (data2?.length ?? 0) };
|
|
12667
13743
|
};
|
|
12668
|
-
const porEtapa = await Promise.all(stages.map((s) => montar(s
|
|
13744
|
+
const porEtapa = await Promise.all(stages.map((s) => montar(s)));
|
|
12669
13745
|
const totals = new Map(porEtapa.map((r) => [r.stageId, r.total]));
|
|
12670
13746
|
const data = porEtapa.flatMap((r) => r.rows);
|
|
12671
13747
|
const deals = (data ?? []).map(toDeal);
|
|
@@ -12955,6 +14031,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
12955
14031
|
qb = qb.neq("status", "archived");
|
|
12956
14032
|
}
|
|
12957
14033
|
if (query.search) qb = qb.or(`number.ilike.%${query.search}%,notes.ilike.%${query.search}%`);
|
|
14034
|
+
if (query.contactId) qb = qb.eq("party_id", query.contactId);
|
|
14035
|
+
if (query.dateRange) {
|
|
14036
|
+
qb = qb.gte("created_at", query.dateRange.from).lte("created_at", `${query.dateRange.to}T23:59:59.999`);
|
|
14037
|
+
}
|
|
12958
14038
|
const page = query.page ?? 1;
|
|
12959
14039
|
const pageSize = query.pageSize ?? 50;
|
|
12960
14040
|
qb = qb.range((page - 1) * pageSize, page * pageSize - 1).order("created_at", { ascending: false });
|
|
@@ -14016,10 +15096,13 @@ function createSupabaseCrmProvider(options) {
|
|
|
14016
15096
|
const { data } = await pub.from(T.personPhones).select("*").eq("phone_key", key);
|
|
14017
15097
|
return (data ?? []).map((r) => snakeToCamel(r));
|
|
14018
15098
|
},
|
|
14019
|
-
async getFunnel(pipelineId) {
|
|
15099
|
+
async getFunnel(pipelineId, filter) {
|
|
14020
15100
|
const { pub } = getClients();
|
|
14021
15101
|
const stages = await provider.getPipelineStages(pipelineId);
|
|
14022
|
-
const { data, error } = await pub.rpc("crm_funnel", {
|
|
15102
|
+
const { data, error } = await pub.rpc("crm_funnel", {
|
|
15103
|
+
p_pipeline_id: pipelineId,
|
|
15104
|
+
p_filter: filter ?? {}
|
|
15105
|
+
});
|
|
14023
15106
|
if (error) throw new Error(error.message);
|
|
14024
15107
|
const porEtapa = /* @__PURE__ */ new Map();
|
|
14025
15108
|
for (const r of data ?? []) {
|
|
@@ -14372,6 +15455,7 @@ function createCrmStore(provider) {
|
|
|
14372
15455
|
stages: [],
|
|
14373
15456
|
activePipelineId: null,
|
|
14374
15457
|
pipelinesLoading: true,
|
|
15458
|
+
stagesPipelineId: null,
|
|
14375
15459
|
leads: [],
|
|
14376
15460
|
leadsTotal: 0,
|
|
14377
15461
|
leadsLoading: false,
|
|
@@ -14465,16 +15549,17 @@ function createCrmStore(provider) {
|
|
|
14465
15549
|
set({ pipelines });
|
|
14466
15550
|
return;
|
|
14467
15551
|
}
|
|
14468
|
-
set({ pipelines, stages, activePipelineId: active });
|
|
15552
|
+
set({ pipelines, stages, stagesPipelineId: active, activePipelineId: active });
|
|
14469
15553
|
});
|
|
14470
15554
|
} finally {
|
|
14471
15555
|
set({ pipelinesLoading: false });
|
|
14472
15556
|
}
|
|
14473
15557
|
},
|
|
14474
15558
|
async selectPipeline(pipelineId) {
|
|
14475
|
-
|
|
15559
|
+
const { activePipelineId, stagesPipelineId } = get();
|
|
15560
|
+
if (activePipelineId === pipelineId && stagesPipelineId === pipelineId) return;
|
|
14476
15561
|
const stages = await provider.getPipelineStages(pipelineId);
|
|
14477
|
-
set({ stages, activePipelineId: pipelineId, dealsByStage: /* @__PURE__ */ new Map(), dealStageTotals: /* @__PURE__ */ new Map(), dealStageLimits: {} });
|
|
15562
|
+
set({ stages, stagesPipelineId: pipelineId, activePipelineId: pipelineId, dealsByStage: /* @__PURE__ */ new Map(), dealStageTotals: /* @__PURE__ */ new Map(), dealStageLimits: {} });
|
|
14478
15563
|
},
|
|
14479
15564
|
async fetchTagDefs() {
|
|
14480
15565
|
return dedup(sid + "crm:tag-defs", async () => {
|
|
@@ -14500,9 +15585,9 @@ function createCrmStore(provider) {
|
|
|
14500
15585
|
set({ summary, summaryLoading: false });
|
|
14501
15586
|
});
|
|
14502
15587
|
},
|
|
14503
|
-
async fetchFunnel(pipelineId) {
|
|
14504
|
-
return dedup(sid + "crm:funnel:" + pipelineId, async () => {
|
|
14505
|
-
const funnel = await provider.getFunnel(pipelineId);
|
|
15588
|
+
async fetchFunnel(pipelineId, filter) {
|
|
15589
|
+
return dedup(sid + "crm:funnel:" + pipelineId + ":" + JSON.stringify(filter ?? {}), async () => {
|
|
15590
|
+
const funnel = await provider.getFunnel(pipelineId, filter);
|
|
14506
15591
|
set({ funnel });
|
|
14507
15592
|
});
|
|
14508
15593
|
},
|
|
@@ -14852,7 +15937,11 @@ function createCrmStore(provider) {
|
|
|
14852
15937
|
stageId,
|
|
14853
15938
|
stageName: alvo?.name ?? movido.stageName,
|
|
14854
15939
|
stageColor: alvo?.color ?? movido.stageColor,
|
|
14855
|
-
probability: alvo?.probability ?? movido.probability
|
|
15940
|
+
probability: alvo?.probability ?? movido.probability,
|
|
15941
|
+
// The outcome follows the column here too — the provider writes it
|
|
15942
|
+
// from the stage, and a patched card that kept 'open' inside the lost
|
|
15943
|
+
// column read as open until the next refetch.
|
|
15944
|
+
status: alvo ? alvo.isWon ? "won" : alvo.isLost ? "lost" : "open" : movido.status
|
|
14856
15945
|
};
|
|
14857
15946
|
novo.set(stageId, [atualizado, ...novo.get(stageId) ?? []]);
|
|
14858
15947
|
totais.set(stageId, (totais.get(stageId) ?? 0) + 1);
|
|
@@ -28845,6 +29934,304 @@ SELECT c.id,
|
|
|
28845
29934
|
GRANT SELECT ON public.v_crm_companies_enriched TO authenticated;
|
|
28846
29935
|
GRANT SELECT ON public.v_crm_companies_enriched TO service_role;
|
|
28847
29936
|
`;
|
|
29937
|
+
var MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E = `-- ---------------------------------------------------------------------------
|
|
29938
|
+
-- 060_o_funil_sabe_de_quem_ele_e.sql \u2014 o funil deixa de ser um s\xF3, para todos.
|
|
29939
|
+
-- ---------------------------------------------------------------------------
|
|
29940
|
+
-- \`plg_crm_pipelines\` j\xE1 aceita mais de uma linha e a tela j\xE1 troca entre elas.
|
|
29941
|
+
-- O que n\xE3o existia era o RECORTE: um funil valia para a conta inteira, ent\xE3o
|
|
29942
|
+
-- abrir dois significava mostrar os dois a todo mundo e torcer para que cada um
|
|
29943
|
+
-- clicasse no seu. Numa casa com duas marcas e duas equipes de venda isso n\xE3o \xE9
|
|
29944
|
+
-- inconveni\xEAncia, \xE9 o funil errado carregado por padr\xE3o todo dia.
|
|
29945
|
+
--
|
|
29946
|
+
-- \u2500\u2500 duas tabelas de v\xEDnculo, e n\xE3o duas colunas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29947
|
+
--
|
|
29948
|
+
-- Um funil pode servir duas unidades (a marca que vende nas duas pra\xE7as) e duas
|
|
29949
|
+
-- equipes (SDR e closer trabalhando o mesmo pipe). Coluna \`unit_id\` no funil
|
|
29950
|
+
-- responderia "uma", e a segunda casa chegaria no m\xEAs seguinte.
|
|
29951
|
+
--
|
|
29952
|
+
-- \u2500\u2500 e o vazio quer dizer TODOS \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29953
|
+
--
|
|
29954
|
+
-- Funil sem v\xEDnculo nenhum vale para a conta inteira. \xC9 o oposto do
|
|
29955
|
+
-- deny-by-default que a RLS de unidade usa, e de prop\xF3sito: ali o vazio \xE9 "n\xE3o
|
|
29956
|
+
-- disse quem pode ver" e o risco \xE9 vazar; aqui o vazio \xE9 "n\xE3o disse para quem
|
|
29957
|
+
-- serve" e o risco \xE9 a conta acordar sem funil nenhum na tela depois de uma
|
|
29958
|
+
-- migration. O recorte \xE9 de APRESENTA\xC7\xC3O \u2014 quem pode LER o funil continua sendo
|
|
29959
|
+
-- pergunta da RLS, que n\xE3o muda aqui.
|
|
29960
|
+
--
|
|
29961
|
+
-- A equipe \xE9 a categoria \`staff_team\` da 139 do espinha. Sem FK para
|
|
29962
|
+
-- \`categories\` porque a tabela \xE9 do n\xFAcleo e o v\xEDnculo \xE9 do plugin: o mesmo
|
|
29963
|
+
-- motivo pelo qual \`plg_crm_deals.assigned_to_id\` n\xE3o referencia \`auth.users\`.
|
|
29964
|
+
-- O ON DELETE que importa \xE9 o do funil, e esse existe.
|
|
29965
|
+
-- ---------------------------------------------------------------------------
|
|
29966
|
+
|
|
29967
|
+
CREATE TABLE IF NOT EXISTS public.plg_crm_pipeline_units (
|
|
29968
|
+
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
29969
|
+
tenant_id uuid NOT NULL,
|
|
29970
|
+
pipeline_id uuid NOT NULL,
|
|
29971
|
+
unit_id uuid NOT NULL,
|
|
29972
|
+
created_at timestamptz DEFAULT now() NOT NULL,
|
|
29973
|
+
CONSTRAINT plg_crm_pipeline_units_pkey PRIMARY KEY (id),
|
|
29974
|
+
CONSTRAINT plg_crm_pipeline_units_pair_key UNIQUE (pipeline_id, unit_id)
|
|
29975
|
+
);
|
|
29976
|
+
|
|
29977
|
+
CREATE TABLE IF NOT EXISTS public.plg_crm_pipeline_teams (
|
|
29978
|
+
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
29979
|
+
tenant_id uuid NOT NULL,
|
|
29980
|
+
pipeline_id uuid NOT NULL,
|
|
29981
|
+
team_id uuid NOT NULL,
|
|
29982
|
+
created_at timestamptz DEFAULT now() NOT NULL,
|
|
29983
|
+
CONSTRAINT plg_crm_pipeline_teams_pkey PRIMARY KEY (id),
|
|
29984
|
+
CONSTRAINT plg_crm_pipeline_teams_pair_key UNIQUE (pipeline_id, team_id)
|
|
29985
|
+
);
|
|
29986
|
+
|
|
29987
|
+
-- \u2500\u2500 constraints \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
29988
|
+
|
|
29989
|
+
ALTER TABLE public.plg_crm_pipeline_units
|
|
29990
|
+
DROP CONSTRAINT IF EXISTS plg_crm_pipeline_units_tenant_fkey;
|
|
29991
|
+
ALTER TABLE public.plg_crm_pipeline_units
|
|
29992
|
+
ADD CONSTRAINT plg_crm_pipeline_units_tenant_fkey
|
|
29993
|
+
FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;
|
|
29994
|
+
|
|
29995
|
+
ALTER TABLE public.plg_crm_pipeline_units
|
|
29996
|
+
DROP CONSTRAINT IF EXISTS plg_crm_pipeline_units_pipeline_fkey;
|
|
29997
|
+
ALTER TABLE public.plg_crm_pipeline_units
|
|
29998
|
+
ADD CONSTRAINT plg_crm_pipeline_units_pipeline_fkey
|
|
29999
|
+
FOREIGN KEY (pipeline_id) REFERENCES public.plg_crm_pipelines(id) ON DELETE CASCADE;
|
|
30000
|
+
|
|
30001
|
+
ALTER TABLE public.plg_crm_pipeline_teams
|
|
30002
|
+
DROP CONSTRAINT IF EXISTS plg_crm_pipeline_teams_tenant_fkey;
|
|
30003
|
+
ALTER TABLE public.plg_crm_pipeline_teams
|
|
30004
|
+
ADD CONSTRAINT plg_crm_pipeline_teams_tenant_fkey
|
|
30005
|
+
FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;
|
|
30006
|
+
|
|
30007
|
+
ALTER TABLE public.plg_crm_pipeline_teams
|
|
30008
|
+
DROP CONSTRAINT IF EXISTS plg_crm_pipeline_teams_pipeline_fkey;
|
|
30009
|
+
ALTER TABLE public.plg_crm_pipeline_teams
|
|
30010
|
+
ADD CONSTRAINT plg_crm_pipeline_teams_pipeline_fkey
|
|
30011
|
+
FOREIGN KEY (pipeline_id) REFERENCES public.plg_crm_pipelines(id) ON DELETE CASCADE;
|
|
30012
|
+
|
|
30013
|
+
-- \u2500\u2500 index \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30014
|
+
|
|
30015
|
+
CREATE INDEX IF NOT EXISTS plg_crm_pipeline_units_pipeline_idx
|
|
30016
|
+
ON public.plg_crm_pipeline_units (tenant_id, pipeline_id);
|
|
30017
|
+
CREATE INDEX IF NOT EXISTS plg_crm_pipeline_units_unit_idx
|
|
30018
|
+
ON public.plg_crm_pipeline_units (tenant_id, unit_id);
|
|
30019
|
+
CREATE INDEX IF NOT EXISTS plg_crm_pipeline_teams_pipeline_idx
|
|
30020
|
+
ON public.plg_crm_pipeline_teams (tenant_id, pipeline_id);
|
|
30021
|
+
CREATE INDEX IF NOT EXISTS plg_crm_pipeline_teams_team_idx
|
|
30022
|
+
ON public.plg_crm_pipeline_teams (tenant_id, team_id);
|
|
30023
|
+
|
|
30024
|
+
-- \u2500\u2500 RLS \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30025
|
+
--
|
|
30026
|
+
-- Ler o v\xEDnculo \xE9 ler a configura\xE7\xE3o do funil: \`sales.read\`. Escrev\xEA-lo \xE9
|
|
30027
|
+
-- configurar, e configura\xE7\xE3o de funil segue o mesmo verbo que criar a etapa.
|
|
30028
|
+
|
|
30029
|
+
ALTER TABLE public.plg_crm_pipeline_units ENABLE ROW LEVEL SECURITY;
|
|
30030
|
+
ALTER TABLE public.plg_crm_pipeline_units FORCE ROW LEVEL SECURITY;
|
|
30031
|
+
ALTER TABLE public.plg_crm_pipeline_teams ENABLE ROW LEVEL SECURITY;
|
|
30032
|
+
ALTER TABLE public.plg_crm_pipeline_teams FORCE ROW LEVEL SECURITY;
|
|
30033
|
+
|
|
30034
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_units_authz_select ON public.plg_crm_pipeline_units;
|
|
30035
|
+
CREATE POLICY plg_crm_pipeline_units_authz_select ON public.plg_crm_pipeline_units
|
|
30036
|
+
FOR SELECT TO authenticated USING (
|
|
30037
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30038
|
+
AND (SELECT app.has_permission('sales.read', NULL::uuid)));
|
|
30039
|
+
|
|
30040
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_units_authz_insert ON public.plg_crm_pipeline_units;
|
|
30041
|
+
CREATE POLICY plg_crm_pipeline_units_authz_insert ON public.plg_crm_pipeline_units
|
|
30042
|
+
FOR INSERT TO authenticated WITH CHECK (
|
|
30043
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30044
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30045
|
+
|
|
30046
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_units_authz_update ON public.plg_crm_pipeline_units;
|
|
30047
|
+
CREATE POLICY plg_crm_pipeline_units_authz_update ON public.plg_crm_pipeline_units
|
|
30048
|
+
FOR UPDATE TO authenticated USING (
|
|
30049
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30050
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)))
|
|
30051
|
+
WITH CHECK (
|
|
30052
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30053
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30054
|
+
|
|
30055
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_units_authz_delete ON public.plg_crm_pipeline_units;
|
|
30056
|
+
CREATE POLICY plg_crm_pipeline_units_authz_delete ON public.plg_crm_pipeline_units
|
|
30057
|
+
FOR DELETE TO authenticated USING (
|
|
30058
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30059
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30060
|
+
|
|
30061
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_teams_authz_select ON public.plg_crm_pipeline_teams;
|
|
30062
|
+
CREATE POLICY plg_crm_pipeline_teams_authz_select ON public.plg_crm_pipeline_teams
|
|
30063
|
+
FOR SELECT TO authenticated USING (
|
|
30064
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30065
|
+
AND (SELECT app.has_permission('sales.read', NULL::uuid)));
|
|
30066
|
+
|
|
30067
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_teams_authz_insert ON public.plg_crm_pipeline_teams;
|
|
30068
|
+
CREATE POLICY plg_crm_pipeline_teams_authz_insert ON public.plg_crm_pipeline_teams
|
|
30069
|
+
FOR INSERT TO authenticated WITH CHECK (
|
|
30070
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30071
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30072
|
+
|
|
30073
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_teams_authz_update ON public.plg_crm_pipeline_teams;
|
|
30074
|
+
CREATE POLICY plg_crm_pipeline_teams_authz_update ON public.plg_crm_pipeline_teams
|
|
30075
|
+
FOR UPDATE TO authenticated USING (
|
|
30076
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30077
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)))
|
|
30078
|
+
WITH CHECK (
|
|
30079
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30080
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30081
|
+
|
|
30082
|
+
DROP POLICY IF EXISTS plg_crm_pipeline_teams_authz_delete ON public.plg_crm_pipeline_teams;
|
|
30083
|
+
CREATE POLICY plg_crm_pipeline_teams_authz_delete ON public.plg_crm_pipeline_teams
|
|
30084
|
+
FOR DELETE TO authenticated USING (
|
|
30085
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30086
|
+
AND (SELECT app.has_permission('sales.edit', NULL::uuid)));
|
|
30087
|
+
|
|
30088
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON public.plg_crm_pipeline_units TO authenticated;
|
|
30089
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON public.plg_crm_pipeline_teams TO authenticated;
|
|
30090
|
+
GRANT ALL ON public.plg_crm_pipeline_units TO service_role;
|
|
30091
|
+
GRANT ALL ON public.plg_crm_pipeline_teams TO service_role;
|
|
30092
|
+
|
|
30093
|
+
-- \u2500\u2500 a vista que a tela l\xEA \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30094
|
+
--
|
|
30095
|
+
-- O funil com os v\xEDnculos J\xC1 AGREGADOS: sem ela o quadro faria tr\xEAs consultas
|
|
30096
|
+
-- para responder "qual funil \xE9 meu" \u2014 e faria isso a cada montagem, antes de
|
|
30097
|
+
-- poder sequer come\xE7ar a buscar os cards.
|
|
30098
|
+
--
|
|
30099
|
+
-- \`security_invoker\`: a RLS acima \xE9 que decide as linhas. Uma vista definidora
|
|
30100
|
+
-- aqui devolveria o funil de outra casa para quem soubesse o id.
|
|
30101
|
+
CREATE OR REPLACE VIEW public.v_crm_pipelines WITH (security_invoker = true) AS
|
|
30102
|
+
SELECT p.id, p.tenant_id, p.name, p.is_default, p.is_active,
|
|
30103
|
+
p.created_at, p.updated_at,
|
|
30104
|
+
coalesce((SELECT array_agg(u.unit_id)
|
|
30105
|
+
FROM public.plg_crm_pipeline_units u
|
|
30106
|
+
WHERE u.pipeline_id = p.id), '{}'::uuid[]) AS unit_ids,
|
|
30107
|
+
coalesce((SELECT array_agg(t.team_id)
|
|
30108
|
+
FROM public.plg_crm_pipeline_teams t
|
|
30109
|
+
WHERE t.pipeline_id = p.id), '{}'::uuid[]) AS team_ids
|
|
30110
|
+
FROM public.plg_crm_pipelines p;
|
|
30111
|
+
|
|
30112
|
+
GRANT SELECT ON public.v_crm_pipelines TO authenticated;
|
|
30113
|
+
GRANT SELECT ON public.v_crm_pipelines TO service_role;
|
|
30114
|
+
`;
|
|
30115
|
+
var MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO = `-- 061 \u2014 The conversion chart answers the question the filter asked.
|
|
30116
|
+
--
|
|
30117
|
+
-- \u2500\u2500 The bug \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30118
|
+
--
|
|
30119
|
+
-- Board, List and Conversion are three modes of one screen, and the board's
|
|
30120
|
+
-- filters are persisted (\`crm.board.owner\`, \`crm.board.period\`, the tag chips).
|
|
30121
|
+
-- The board is honest: \`getDealsByStage\` asks the database once per stage with
|
|
30122
|
+
-- \`count: 'exact'\` and every predicate applied, so its column numbers shrink
|
|
30123
|
+
-- with the filter.
|
|
30124
|
+
--
|
|
30125
|
+
-- \`crm_funnel(p_pipeline_id uuid)\` takes ONE argument. It never saw a filter.
|
|
30126
|
+
-- So: filter the board, switch to Conversion, and the chart counts the whole
|
|
30127
|
+
-- funnel while the filter bar above it still says otherwise. Switch back and
|
|
30128
|
+
-- the numbers are right again. That is why it was reported as real and could
|
|
30129
|
+
-- not be reproduced on demand \u2014 through the board's SEARCH box it never fails
|
|
30130
|
+
-- (the header count has a special case for it), and through the filter menu it
|
|
30131
|
+
-- fails every time, but only after changing mode.
|
|
30132
|
+
--
|
|
30133
|
+
-- \u2500\u2500 Why an overload and not a wider signature \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30134
|
+
--
|
|
30135
|
+
-- Replacing \`crm_funnel(uuid)\` with a wider one is not replay-safe: the chain
|
|
30136
|
+
-- is replayed, 034 creates the 1-arg version, and a later DROP/CREATE of a
|
|
30137
|
+
-- different signature leaves two functions anyway. So the 1-arg stays exactly
|
|
30138
|
+
-- as 034 left it \u2014 untouched, still correct for a caller with no filter \u2014 and
|
|
30139
|
+
-- the filtered read is a second, 2-arg function. No DEFAULT on the new one:
|
|
30140
|
+
-- \`crm_funnel(uuid)\` and \`crm_funnel(uuid, jsonb DEFAULT \u2026)\` would be ambiguous
|
|
30141
|
+
-- for a one-argument call and Postgres would refuse to choose.
|
|
30142
|
+
--
|
|
30143
|
+
-- \u2500\u2500 The filter is jsonb on purpose \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30144
|
+
--
|
|
30145
|
+
-- \`BoardFilter\` has grown twice already (tags, then search+searchTags, then the
|
|
30146
|
+
-- period, then the owner). A positional signature would need a migration each
|
|
30147
|
+
-- time and would break every caller on the way. A bag costs one cast per key
|
|
30148
|
+
-- and the shape stays the board's to decide.
|
|
30149
|
+
|
|
30150
|
+
CREATE OR REPLACE FUNCTION public.crm_funnel(p_pipeline_id uuid, p_filter jsonb)
|
|
30151
|
+
RETURNS TABLE(stage_id uuid, deals bigint, total_value numeric)
|
|
30152
|
+
LANGUAGE plpgsql
|
|
30153
|
+
STABLE
|
|
30154
|
+
SECURITY DEFINER
|
|
30155
|
+
SET search_path TO ''
|
|
30156
|
+
AS $function$
|
|
30157
|
+
declare
|
|
30158
|
+
v_tenant uuid := app.current_tenant_id();
|
|
30159
|
+
v_foco uuid := nullif(app.current_unit_id(), '00000000-0000-0000-0000-000000000000'::uuid);
|
|
30160
|
+
v_negado boolean := app.current_unit_id() = '00000000-0000-0000-0000-000000000000'::uuid;
|
|
30161
|
+
v_unidades uuid[];
|
|
30162
|
+
v_sem_unidade boolean;
|
|
30163
|
+
v_dono boolean;
|
|
30164
|
+
v_uid uuid := auth.uid();
|
|
30165
|
+
-- O recorte, lido do saco. Tudo opcional: um \`{}\` devolve o mesmo que a
|
|
30166
|
+
-- fun\xE7\xE3o de um argumento.
|
|
30167
|
+
v_tags text[] := case when p_filter ? 'tags'
|
|
30168
|
+
then array(select jsonb_array_elements_text(p_filter->'tags')) end;
|
|
30169
|
+
v_busca text := nullif(trim(coalesce(p_filter->>'search', '')), '');
|
|
30170
|
+
v_busca_tags text[] := case when p_filter ? 'searchTags'
|
|
30171
|
+
then array(select jsonb_array_elements_text(p_filter->'searchTags')) end;
|
|
30172
|
+
v_de timestamptz := nullif(p_filter->>'createdFrom', '')::timestamptz;
|
|
30173
|
+
v_ate timestamptz := nullif(p_filter->>'createdTo', '')::timestamptz;
|
|
30174
|
+
v_dono_f text := nullif(p_filter->>'assignedToId', '');
|
|
30175
|
+
begin
|
|
30176
|
+
if v_tenant is null or v_negado then
|
|
30177
|
+
return;
|
|
30178
|
+
end if;
|
|
30179
|
+
|
|
30180
|
+
select coalesce(array_agg(a.unit_id), '{}'::uuid[])
|
|
30181
|
+
into v_unidades
|
|
30182
|
+
from app.user_unit_access a
|
|
30183
|
+
where a.tenant_id = v_tenant
|
|
30184
|
+
and a.user_id = v_uid
|
|
30185
|
+
and (v_foco is null or a.unit_id = v_foco)
|
|
30186
|
+
and app.has_permission('crm.pipeline.read', a.unit_id);
|
|
30187
|
+
|
|
30188
|
+
v_sem_unidade := app.has_permission('crm.pipeline.read', null::uuid);
|
|
30189
|
+
v_dono := app.owner_scoped('crm.deal');
|
|
30190
|
+
|
|
30191
|
+
return query
|
|
30192
|
+
-- A TABELA para a cerca, a VISTA para o texto.
|
|
30193
|
+
--
|
|
30194
|
+
-- \`v_deals\` n\xE3o exp\xF5e \`unit_id\` nem \`owner_id\` \u2014 s\xE3o exatamente as duas
|
|
30195
|
+
-- colunas de que a permiss\xE3o depende, e ler a permiss\xE3o de uma linha que n\xE3o
|
|
30196
|
+
-- as tem seria escrever uma cerca que n\xE3o fecha. Ent\xE3o a base continua sendo
|
|
30197
|
+
-- \`plg_crm_deals\`, como na 034, e a vista entra s\xF3 para dar ao termo de busca
|
|
30198
|
+
-- as mesmas colunas que a coluna do quadro procura.
|
|
30199
|
+
select d.stage_id, count(*), coalesce(sum(d.value), 0)
|
|
30200
|
+
from public.plg_crm_deals d
|
|
30201
|
+
join public.v_deals v on v.id = d.id
|
|
30202
|
+
where d.tenant_id = v_tenant
|
|
30203
|
+
and d.pipeline_id = p_pipeline_id
|
|
30204
|
+
and d.status = 'open'
|
|
30205
|
+
and ( (d.unit_id is null and v_sem_unidade)
|
|
30206
|
+
or (d.unit_id = any (v_unidades)))
|
|
30207
|
+
and (not v_dono or d.owner_id is null or d.owner_id = v_uid)
|
|
30208
|
+
-- Os MESMOS predicados que \`getDealsByStage\` aplica, para que a coluna e
|
|
30209
|
+
-- o gr\xE1fico n\xE3o possam divergir por um detalhe.
|
|
30210
|
+
and (v_tags is null or d.tags && v_tags)
|
|
30211
|
+
and (v_de is null or d.created_at >= v_de)
|
|
30212
|
+
and (v_ate is null or d.created_at <= v_ate)
|
|
30213
|
+
and (v_dono_f is null
|
|
30214
|
+
or (v_dono_f = 'none' and d.assigned_to_id is null)
|
|
30215
|
+
or (v_dono_f <> 'none' and d.assigned_to_id = v_dono_f::uuid))
|
|
30216
|
+
-- A busca \xE9 um OU entre as colunas do quadro e as etiquetas resolvidas no
|
|
30217
|
+
-- cliente \u2014 alternativa ao texto, n\xE3o afunilamento dele.
|
|
30218
|
+
and (v_busca is null
|
|
30219
|
+
or v.title ilike '%' || v_busca || '%'
|
|
30220
|
+
or v.contact_name ilike '%' || v_busca || '%'
|
|
30221
|
+
or v.company_name ilike '%' || v_busca || '%'
|
|
30222
|
+
or v.notes ilike '%' || v_busca || '%'
|
|
30223
|
+
or v.lost_reason ilike '%' || v_busca || '%'
|
|
30224
|
+
or v.stage_name ilike '%' || v_busca || '%'
|
|
30225
|
+
or v.contact_status_name ilike '%' || v_busca || '%'
|
|
30226
|
+
or (v_busca_tags is not null and d.tags && v_busca_tags))
|
|
30227
|
+
group by d.stage_id;
|
|
30228
|
+
end
|
|
30229
|
+
$function$;
|
|
30230
|
+
|
|
30231
|
+
REVOKE ALL ON FUNCTION public.crm_funnel(uuid, jsonb) FROM public;
|
|
30232
|
+
GRANT EXECUTE ON FUNCTION public.crm_funnel(uuid, jsonb) TO authenticated;
|
|
30233
|
+
GRANT EXECUTE ON FUNCTION public.crm_funnel(uuid, jsonb) TO service_role;
|
|
30234
|
+
`;
|
|
28848
30235
|
var MIGRATIONS = [
|
|
28849
30236
|
{ id: "000_baseline", sql: MIGRATION_000_BASELINE },
|
|
28850
30237
|
{ id: "001_de_onde_veio_e_quem_indicou", sql: MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU },
|
|
@@ -28904,7 +30291,9 @@ var MIGRATIONS = [
|
|
|
28904
30291
|
{ id: "056_o_interesse_entra_pelo_agendamento", sql: MIGRATION_056_O_INTERESSE_ENTRA_PELO_AGENDAMENTO },
|
|
28905
30292
|
{ id: "057_o_negocio_e_do_grupo_nao_do_cnpj", sql: MIGRATION_057_O_NEGOCIO_E_DO_GRUPO_NAO_DO_CNPJ },
|
|
28906
30293
|
{ id: "058_o_card_diz_o_nome_do_grupo", sql: MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO },
|
|
28907
|
-
{ id: "059_a_empresa_mostra_o_instagram_que_ela_guarda", sql: MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA }
|
|
30294
|
+
{ id: "059_a_empresa_mostra_o_instagram_que_ela_guarda", sql: MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA },
|
|
30295
|
+
{ id: "060_o_funil_sabe_de_quem_ele_e", sql: MIGRATION_060_O_FUNIL_SABE_DE_QUEM_ELE_E },
|
|
30296
|
+
{ id: "061_a_conversao_respeita_o_filtro_do_quadro", sql: MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO }
|
|
28908
30297
|
];
|
|
28909
30298
|
|
|
28910
30299
|
// src/locales/en.ts
|
|
@@ -29127,6 +30516,26 @@ var en = {
|
|
|
29127
30516
|
"crm.rota.count": "{{count}} in the rota",
|
|
29128
30517
|
"crm.pipeline.pickFunnel": "Pick a funnel",
|
|
29129
30518
|
"crm.pipeline.setupStages": "Set up stages",
|
|
30519
|
+
"chat.tool.applyFunnelStages": "Draw the funnel stages",
|
|
30520
|
+
"chat.tool.renameFunnelStage": "Rename the stage",
|
|
30521
|
+
"chat.tool.reorderFunnelStages": "Reorder the stages",
|
|
30522
|
+
"chat.tool.removeFunnelStage": "Delete the stage",
|
|
30523
|
+
"chat.tool.createFunnel": "Create a funnel",
|
|
30524
|
+
"chat.field.applyFunnelStages.stages": "Stages",
|
|
30525
|
+
"chat.field.applyFunnelStages.replaceExisting": "Replace the current ones",
|
|
30526
|
+
"chat.field.renameFunnelStage.currentName": "Stage",
|
|
30527
|
+
"chat.field.renameFunnelStage.newName": "New name",
|
|
30528
|
+
"chat.field.reorderFunnelStages.orderedNames": "New order",
|
|
30529
|
+
"chat.field.removeFunnelStage.name": "Stage",
|
|
30530
|
+
"chat.field.createFunnel.name": "Funnel name",
|
|
30531
|
+
"chat.field.createFunnel.makeDefault": "Make it the default funnel",
|
|
30532
|
+
"crm.pipeline.setupWithAI": "Set up with AI",
|
|
30533
|
+
"crm.pipeline.ai.pitch": "Let's design your funnel",
|
|
30534
|
+
"crm.pipeline.ai.description": "Tell me in two sentences how your company sells and I'll build the board's stages \u2014 name, order and odds of closing in each. You read the list before anything is created.",
|
|
30535
|
+
"crm.pipeline.ai.prompt": "I want to set up my funnel stages. Ask me whatever you need.",
|
|
30536
|
+
"crm.pipeline.ai.hint": "e.g. we sell consulting to companies, clients come by referral\u2026",
|
|
30537
|
+
"crm.pipeline.ai.suggestionDescribe": "Design the funnel from scratch",
|
|
30538
|
+
"crm.pipeline.ai.suggestionReview": "Review the stages I already have",
|
|
29130
30539
|
"crm.pipeline.loadMore": "Show {n} more",
|
|
29131
30540
|
"crm.pipeline.noDeals": "No deals",
|
|
29132
30541
|
"crm.pipeline.addLead": "Add lead",
|
|
@@ -29150,6 +30559,22 @@ var en = {
|
|
|
29150
30559
|
"crm.board.prop.value": "Value",
|
|
29151
30560
|
"crm.board.prop.age": "Age",
|
|
29152
30561
|
"crm.deals.switchView": "Switch deals view",
|
|
30562
|
+
"crm.engagement.title": "Engagement",
|
|
30563
|
+
"crm.engagement.tasks": "Tasks",
|
|
30564
|
+
"crm.engagement.followUps": "Follow-ups",
|
|
30565
|
+
"crm.retention.title": "Retention",
|
|
30566
|
+
"crm.retention.loyalty": "Loyalty Club",
|
|
30567
|
+
"crm.retention.referrals": "Referrals",
|
|
30568
|
+
"crm.retention.birthdays": "Birthdays",
|
|
30569
|
+
"crm.retention.pendingReturns": "Pending Returns",
|
|
30570
|
+
"crm.goals.title": "Goals",
|
|
30571
|
+
"crm.goals.units": "Units",
|
|
30572
|
+
"crm.goals.kpi": "Indicators",
|
|
30573
|
+
"crm.goals.professionals": "Professionals",
|
|
30574
|
+
"crm.goals.franchisor": "Franchisor",
|
|
30575
|
+
"crm.panels.title": "Panels",
|
|
30576
|
+
"crm.panels.operational": "Operational",
|
|
30577
|
+
"crm.panels.maturity": "Maturity",
|
|
29153
30578
|
"crm.deals.viewBoard": "Board",
|
|
29154
30579
|
"crm.deals.viewList": "List",
|
|
29155
30580
|
"crm.deals.viewFunnel": "Conversion",
|
|
@@ -29220,6 +30645,25 @@ var en = {
|
|
|
29220
30645
|
"crm.card.markedWon": "Deal marked won",
|
|
29221
30646
|
"crm.card.markedLost": "Deal marked lost",
|
|
29222
30647
|
"crm.card.lostReasonPrompt": "Why was it lost? (price, went quiet, went with a competitor\u2026)",
|
|
30648
|
+
"crm.card.stageIntent": "Moving from {from} to {to} \u2014 log what happened to confirm.",
|
|
30649
|
+
"crm.card.stageIntentSave": "Save and move",
|
|
30650
|
+
"crm.card.stageIntentCancel": "Cancel move",
|
|
30651
|
+
"crm.card.lostReasonTitle": "Why was this deal lost?",
|
|
30652
|
+
"crm.card.lostReasonHint": "The reason is what turns a column of lost deals into a decision. Pick one or write your own.",
|
|
30653
|
+
"crm.card.lostReasonOther": "Another reason (optional)",
|
|
30654
|
+
"crm.card.lostReasonConfirm": "Mark as lost",
|
|
30655
|
+
"crm.lostReason.label": "Lost reason",
|
|
30656
|
+
"crm.lostReason.noInterest": "Not interested",
|
|
30657
|
+
"crm.lostReason.price": "Price",
|
|
30658
|
+
"crm.lostReason.noBudget": "No budget right now",
|
|
30659
|
+
"crm.lostReason.competitor": "Went with a competitor",
|
|
30660
|
+
"crm.lostReason.ghosted": "Went quiet",
|
|
30661
|
+
"crm.lostReason.badFit": "Not a fit",
|
|
30662
|
+
"crm.deals.outcome": "Outcome",
|
|
30663
|
+
"crm.deals.outcomeOpen": "Open",
|
|
30664
|
+
"crm.deals.outcomeWon": "Won",
|
|
30665
|
+
"crm.deals.outcomeLost": "Lost",
|
|
30666
|
+
"crm.deals.outcomeAll": "All",
|
|
29223
30667
|
"crm.deals.colCity": "City",
|
|
29224
30668
|
"crm.deals.cohort": "Cohort",
|
|
29225
30669
|
"crm.deals.campaign": "Campaign",
|
|
@@ -29287,6 +30731,9 @@ var en = {
|
|
|
29287
30731
|
"crm.quoteDetail.unitPrice": "Unit Price",
|
|
29288
30732
|
"crm.quoteDetail.validUntil": "Valid Until",
|
|
29289
30733
|
"crm.quoteDetail.viewInvoice": "View Invoice",
|
|
30734
|
+
"crm.itemType.service": "Service",
|
|
30735
|
+
"crm.itemType.product": "Product",
|
|
30736
|
+
"crm.itemType.other": "Other",
|
|
29290
30737
|
"crm.quoteForm.addFirstItem": "Add your first item",
|
|
29291
30738
|
"crm.quoteForm.addItem": "Add Item",
|
|
29292
30739
|
"crm.quoteForm.cancel": "Cancel",
|
|
@@ -29317,6 +30764,7 @@ var en = {
|
|
|
29317
30764
|
"crm.quoteForm.saving": "Saving...",
|
|
29318
30765
|
"crm.quoteForm.searchClient": "Search client...",
|
|
29319
30766
|
"crm.quoteForm.addAsLead": "Add as lead",
|
|
30767
|
+
"crm.quoteForm.selectClientFirst": "Select the client before adding items.",
|
|
29320
30768
|
"crm.quoteForm.selectItemType": "Select item type:",
|
|
29321
30769
|
"crm.quoteForm.statusApproved": "Approved",
|
|
29322
30770
|
"crm.quoteForm.statusDraft": "Draft",
|
|
@@ -29325,7 +30773,30 @@ var en = {
|
|
|
29325
30773
|
"crm.quoteForm.statusSent": "Sent",
|
|
29326
30774
|
"crm.quoteForm.total": "Total",
|
|
29327
30775
|
"crm.quoteForm.unitPrice": "Unit Price",
|
|
30776
|
+
"crm.quoteForm.validCustom": "Custom",
|
|
30777
|
+
"crm.quoteForm.validOneWeek": "1 week",
|
|
30778
|
+
"crm.quoteForm.validThirtyDays": "30 days",
|
|
29328
30779
|
"crm.quoteForm.validUntil": "Valid Until",
|
|
30780
|
+
"crm.quotes.filtersTitle": "Filters",
|
|
30781
|
+
"crm.quotes.filterApply": "Search",
|
|
30782
|
+
"crm.quotes.filterClear": "Clear",
|
|
30783
|
+
"crm.quotes.filterPending": "Filters changed",
|
|
30784
|
+
"crm.quotes.filterPendingHint": "The list still shows the previous selection. Click Search to apply.",
|
|
30785
|
+
"crm.quotes.filterFrom": "From",
|
|
30786
|
+
"crm.quotes.filterTo": "To",
|
|
30787
|
+
"crm.quotes.filterAllStatuses": "All",
|
|
30788
|
+
"crm.quotes.filterAllContacts": "All",
|
|
30789
|
+
"crm.quotes.filterContactPlaceholder": "Type...",
|
|
30790
|
+
"crm.quotes.filterMinChars": "Type at least 2 characters to search.",
|
|
30791
|
+
"crm.quotes.filterNoContact": "No record found.",
|
|
30792
|
+
"crm.quotes.filterSearching": "Searching records...",
|
|
30793
|
+
"crm.quotes.searchPlaceholder": "Search by number or notes...",
|
|
30794
|
+
"crm.quotes.status.draft": "Draft",
|
|
30795
|
+
"crm.quotes.status.sent": "Sent",
|
|
30796
|
+
"crm.quotes.status.approved": "Approved",
|
|
30797
|
+
"crm.quotes.status.rejected": "Rejected",
|
|
30798
|
+
"crm.quotes.status.expired": "Expired",
|
|
30799
|
+
"crm.quotes.status.archived": "Archived",
|
|
29329
30800
|
"crm.quotes.amount": "Amount",
|
|
29330
30801
|
"crm.quotes.archive": "Archive",
|
|
29331
30802
|
"crm.quotes.archiveTitle": "Archive this quote?",
|
|
@@ -29986,6 +31457,26 @@ var ptBR = {
|
|
|
29986
31457
|
"crm.rota.count": "{{count}} na rota",
|
|
29987
31458
|
"crm.pipeline.pickFunnel": "Escolher funil",
|
|
29988
31459
|
"crm.pipeline.setupStages": "Configurar etapas",
|
|
31460
|
+
"chat.tool.applyFunnelStages": "Desenhar as etapas do funil",
|
|
31461
|
+
"chat.tool.renameFunnelStage": "Renomear a etapa",
|
|
31462
|
+
"chat.tool.reorderFunnelStages": "Reordenar as etapas",
|
|
31463
|
+
"chat.tool.removeFunnelStage": "Excluir a etapa",
|
|
31464
|
+
"chat.tool.createFunnel": "Criar um funil",
|
|
31465
|
+
"chat.field.applyFunnelStages.stages": "Etapas",
|
|
31466
|
+
"chat.field.applyFunnelStages.replaceExisting": "Substituir as atuais",
|
|
31467
|
+
"chat.field.renameFunnelStage.currentName": "Etapa",
|
|
31468
|
+
"chat.field.renameFunnelStage.newName": "Novo nome",
|
|
31469
|
+
"chat.field.reorderFunnelStages.orderedNames": "Nova ordem",
|
|
31470
|
+
"chat.field.removeFunnelStage.name": "Etapa",
|
|
31471
|
+
"chat.field.createFunnel.name": "Nome do funil",
|
|
31472
|
+
"chat.field.createFunnel.makeDefault": "Virar o funil padr\xE3o",
|
|
31473
|
+
"crm.pipeline.setupWithAI": "Configurar com IA",
|
|
31474
|
+
"crm.pipeline.ai.pitch": "Vamos desenhar o seu funil",
|
|
31475
|
+
"crm.pipeline.ai.description": "Me conta em duas frases como a sua empresa vende e eu monto as etapas do quadro \u2014 nome, ordem e chance de fechar em cada uma. Voc\xEA confere a lista antes de qualquer coisa ser criada.",
|
|
31476
|
+
"crm.pipeline.ai.prompt": "Quero configurar as etapas do meu funil. Me pergunte o que precisar.",
|
|
31477
|
+
"crm.pipeline.ai.hint": "Ex.: vendemos consultoria para empresas, o cliente chega por indica\xE7\xE3o\u2026",
|
|
31478
|
+
"crm.pipeline.ai.suggestionDescribe": "Desenhar o funil do zero",
|
|
31479
|
+
"crm.pipeline.ai.suggestionReview": "Revisar as etapas que j\xE1 tenho",
|
|
29989
31480
|
"crm.pipeline.loadMore": "Ver mais {n}",
|
|
29990
31481
|
"crm.pipeline.noDeals": "Nenhum neg\xF3cio",
|
|
29991
31482
|
"crm.pipeline.addLead": "Adicionar lead",
|
|
@@ -30009,7 +31500,23 @@ var ptBR = {
|
|
|
30009
31500
|
"crm.board.prop.value": "Valor",
|
|
30010
31501
|
"crm.board.prop.age": "Idade",
|
|
30011
31502
|
"crm.deals.switchView": "Trocar a vis\xE3o dos neg\xF3cios",
|
|
30012
|
-
"crm.
|
|
31503
|
+
"crm.engagement.title": "Engajamento",
|
|
31504
|
+
"crm.engagement.tasks": "Tarefas",
|
|
31505
|
+
"crm.engagement.followUps": "Follow-ups",
|
|
31506
|
+
"crm.retention.title": "Fideliza\xE7\xE3o",
|
|
31507
|
+
"crm.retention.loyalty": "Clube de Fidelidade",
|
|
31508
|
+
"crm.retention.referrals": "Indica\xE7\xF5es",
|
|
31509
|
+
"crm.retention.birthdays": "Aniversariantes",
|
|
31510
|
+
"crm.retention.pendingReturns": "Retornos Pendentes",
|
|
31511
|
+
"crm.goals.title": "Metas",
|
|
31512
|
+
"crm.goals.units": "Unidades",
|
|
31513
|
+
"crm.goals.kpi": "Indicadores",
|
|
31514
|
+
"crm.goals.professionals": "Profissionais",
|
|
31515
|
+
"crm.goals.franchisor": "Franqueador",
|
|
31516
|
+
"crm.panels.title": "Pain\xE9is",
|
|
31517
|
+
"crm.panels.operational": "Operacional",
|
|
31518
|
+
"crm.panels.maturity": "Maturidade",
|
|
31519
|
+
"crm.deals.viewBoard": "Quadro",
|
|
30013
31520
|
"crm.deals.viewList": "Lista",
|
|
30014
31521
|
"crm.deals.viewFunnel": "Convers\xE3o",
|
|
30015
31522
|
"crm.deals.colDeal": "Neg\xF3cio",
|
|
@@ -30079,6 +31586,25 @@ var ptBR = {
|
|
|
30079
31586
|
"crm.card.markedWon": "Neg\xF3cio marcado como ganho",
|
|
30080
31587
|
"crm.card.markedLost": "Neg\xF3cio marcado como perdido",
|
|
30081
31588
|
"crm.card.lostReasonPrompt": "Por que foi perdido? (pre\xE7o, sumiu, fechou com o concorrente\u2026)",
|
|
31589
|
+
"crm.card.stageIntent": "Mudando de {from} para {to} \u2014 registre o que aconteceu para confirmar.",
|
|
31590
|
+
"crm.card.stageIntentSave": "Salvar e mover",
|
|
31591
|
+
"crm.card.stageIntentCancel": "Cancelar mudan\xE7a",
|
|
31592
|
+
"crm.card.lostReasonTitle": "Por que este neg\xF3cio foi perdido?",
|
|
31593
|
+
"crm.card.lostReasonHint": "O motivo \xE9 o que transforma uma coluna de perdidos numa decis\xE3o. Escolha um ou escreva o seu.",
|
|
31594
|
+
"crm.card.lostReasonOther": "Outro motivo (opcional)",
|
|
31595
|
+
"crm.card.lostReasonConfirm": "Marcar como perdido",
|
|
31596
|
+
"crm.lostReason.label": "Motivo da perda",
|
|
31597
|
+
"crm.lostReason.noInterest": "N\xE3o tenho interesse",
|
|
31598
|
+
"crm.lostReason.price": "Pre\xE7o",
|
|
31599
|
+
"crm.lostReason.noBudget": "Sem verba agora",
|
|
31600
|
+
"crm.lostReason.competitor": "Fechou com o concorrente",
|
|
31601
|
+
"crm.lostReason.ghosted": "Sumiu / n\xE3o respondeu",
|
|
31602
|
+
"crm.lostReason.badFit": "Fora do perfil",
|
|
31603
|
+
"crm.deals.outcome": "Desfecho",
|
|
31604
|
+
"crm.deals.outcomeOpen": "Em aberto",
|
|
31605
|
+
"crm.deals.outcomeWon": "Ganhos",
|
|
31606
|
+
"crm.deals.outcomeLost": "Perdidos",
|
|
31607
|
+
"crm.deals.outcomeAll": "Todos",
|
|
30082
31608
|
"crm.deals.colCity": "Cidade",
|
|
30083
31609
|
"crm.deals.cohort": "Safra",
|
|
30084
31610
|
"crm.deals.campaign": "Campanha",
|
|
@@ -30146,6 +31672,9 @@ var ptBR = {
|
|
|
30146
31672
|
"crm.quoteDetail.unitPrice": "Pre\xE7o Unit\xE1rio",
|
|
30147
31673
|
"crm.quoteDetail.validUntil": "V\xE1lido At\xE9",
|
|
30148
31674
|
"crm.quoteDetail.viewInvoice": "Ver Fatura",
|
|
31675
|
+
"crm.itemType.service": "Servi\xE7o",
|
|
31676
|
+
"crm.itemType.product": "Produto",
|
|
31677
|
+
"crm.itemType.other": "Outro",
|
|
30149
31678
|
"crm.quoteForm.addFirstItem": "Adicione seu primeiro item",
|
|
30150
31679
|
"crm.quoteForm.addItem": "Adicionar Item",
|
|
30151
31680
|
"crm.quoteForm.cancel": "Cancelar",
|
|
@@ -30176,6 +31705,7 @@ var ptBR = {
|
|
|
30176
31705
|
"crm.quoteForm.saving": "Salvando...",
|
|
30177
31706
|
"crm.quoteForm.searchClient": "Buscar cliente...",
|
|
30178
31707
|
"crm.quoteForm.addAsLead": "Adicionar como lead",
|
|
31708
|
+
"crm.quoteForm.selectClientFirst": "Selecione o cliente antes de adicionar itens.",
|
|
30179
31709
|
"crm.quoteForm.selectItemType": "Selecione o tipo de item:",
|
|
30180
31710
|
"crm.quoteForm.statusApproved": "Aprovado",
|
|
30181
31711
|
"crm.quoteForm.statusDraft": "Rascunho",
|
|
@@ -30184,7 +31714,30 @@ var ptBR = {
|
|
|
30184
31714
|
"crm.quoteForm.statusSent": "Enviado",
|
|
30185
31715
|
"crm.quoteForm.total": "Total",
|
|
30186
31716
|
"crm.quoteForm.unitPrice": "Pre\xE7o Unit\xE1rio",
|
|
31717
|
+
"crm.quoteForm.validCustom": "Personalizado",
|
|
31718
|
+
"crm.quoteForm.validOneWeek": "1 semana",
|
|
31719
|
+
"crm.quoteForm.validThirtyDays": "30 dias",
|
|
30187
31720
|
"crm.quoteForm.validUntil": "V\xE1lido At\xE9",
|
|
31721
|
+
"crm.quotes.filtersTitle": "Filtros",
|
|
31722
|
+
"crm.quotes.filterApply": "Buscar",
|
|
31723
|
+
"crm.quotes.filterClear": "Limpar",
|
|
31724
|
+
"crm.quotes.filterPending": "Filtros alterados",
|
|
31725
|
+
"crm.quotes.filterPendingHint": "A lista ainda mostra o recorte anterior. Clique em Buscar para aplicar.",
|
|
31726
|
+
"crm.quotes.filterFrom": "De",
|
|
31727
|
+
"crm.quotes.filterTo": "At\xE9",
|
|
31728
|
+
"crm.quotes.filterAllStatuses": "Todos",
|
|
31729
|
+
"crm.quotes.filterAllContacts": "Todos",
|
|
31730
|
+
"crm.quotes.filterContactPlaceholder": "Digite...",
|
|
31731
|
+
"crm.quotes.filterMinChars": "Digite pelo menos 2 caracteres para buscar.",
|
|
31732
|
+
"crm.quotes.filterNoContact": "Nenhum cadastro encontrado.",
|
|
31733
|
+
"crm.quotes.filterSearching": "Buscando cadastros...",
|
|
31734
|
+
"crm.quotes.searchPlaceholder": "Buscar por n\xFAmero ou observa\xE7\xE3o...",
|
|
31735
|
+
"crm.quotes.status.draft": "Rascunho",
|
|
31736
|
+
"crm.quotes.status.sent": "Enviado",
|
|
31737
|
+
"crm.quotes.status.approved": "Aprovado",
|
|
31738
|
+
"crm.quotes.status.rejected": "Recusado",
|
|
31739
|
+
"crm.quotes.status.expired": "Expirado",
|
|
31740
|
+
"crm.quotes.status.archived": "Arquivado",
|
|
30188
31741
|
"crm.quotes.amount": "Valor",
|
|
30189
31742
|
"crm.quotes.archive": "Arquivar",
|
|
30190
31743
|
"crm.quotes.archiveTitle": "Arquivar este or\xE7amento?",
|
|
@@ -31027,8 +32580,17 @@ function registerCrmTimelineSource() {
|
|
|
31027
32580
|
}
|
|
31028
32581
|
});
|
|
31029
32582
|
}
|
|
31030
|
-
|
|
31031
|
-
|
|
32583
|
+
var PJ_LABELS = {
|
|
32584
|
+
name: "Raz\xE3o Social",
|
|
32585
|
+
socialName: "Nome Fantasia",
|
|
32586
|
+
dateOfBirth: "Funda\xE7\xE3o",
|
|
32587
|
+
documentNumber: "CNPJ",
|
|
32588
|
+
rg: "Inscri\xE7\xE3o Estadual",
|
|
32589
|
+
profession: "Ramo de Atua\xE7\xE3o"
|
|
32590
|
+
};
|
|
32591
|
+
var isPJ = (v) => v.personType === "pessoa_juridica";
|
|
32592
|
+
var pjLabel = (key) => (v) => isPJ(v) ? PJ_LABELS[key] : void 0;
|
|
32593
|
+
var onlyPF = (v) => !isPJ(v);
|
|
31032
32594
|
function buildCrmCustomerEntity(name, namePlural, kind = "customer") {
|
|
31033
32595
|
return {
|
|
31034
32596
|
name,
|
|
@@ -31040,37 +32602,136 @@ function buildCrmCustomerEntity(name, namePlural, kind = "customer") {
|
|
|
31040
32602
|
subtitleField: "documentNumber",
|
|
31041
32603
|
defaultSort: "name",
|
|
31042
32604
|
formColumns: 2,
|
|
32605
|
+
facets: [activeFacet({ active: "Ativos", inactive: "Inativos", all: "Todos" })],
|
|
31043
32606
|
fieldGroups: [
|
|
32607
|
+
{ id: "identity", label: "Dados pessoais", columns: 2 },
|
|
31044
32608
|
{ id: "contact", label: "Contato", columns: 2 },
|
|
31045
|
-
{ id: "
|
|
32609
|
+
{ id: "where", label: "Endere\xE7o", columns: 1 },
|
|
32610
|
+
{ id: "origin", label: "Como chegou", columns: 2 },
|
|
32611
|
+
{ ...RECORD_GROUP }
|
|
31046
32612
|
],
|
|
31047
32613
|
fields: [
|
|
31048
|
-
{
|
|
31049
|
-
|
|
31050
|
-
|
|
31051
|
-
|
|
31052
|
-
|
|
31053
|
-
|
|
31054
|
-
|
|
31055
|
-
|
|
31056
|
-
|
|
31057
|
-
|
|
31058
|
-
|
|
31059
|
-
|
|
31060
|
-
{ key: "
|
|
31061
|
-
{ key: "
|
|
31062
|
-
|
|
31063
|
-
|
|
32614
|
+
{
|
|
32615
|
+
key: "personType",
|
|
32616
|
+
label: "Tipo",
|
|
32617
|
+
type: "segmented",
|
|
32618
|
+
defaultValue: "pessoa_fisica",
|
|
32619
|
+
group: "identity",
|
|
32620
|
+
span: 2,
|
|
32621
|
+
options: [
|
|
32622
|
+
{ value: "pessoa_fisica", label: "Pessoa f\xEDsica" },
|
|
32623
|
+
{ value: "pessoa_juridica", label: "Pessoa jur\xEDdica" }
|
|
32624
|
+
]
|
|
32625
|
+
},
|
|
32626
|
+
{ key: "name", label: "Nome", labelWhen: pjLabel("name"), type: "text", required: true, searchable: true, showInTable: true, group: "identity", span: 2 },
|
|
32627
|
+
{ key: "socialName", label: "Nome Social", labelWhen: pjLabel("socialName"), type: "text", showInTable: false, group: "identity", span: 2 },
|
|
32628
|
+
// CPF only para pessoa FÍSICA. Um CNPJ numa linha de pessoa física ou
|
|
32629
|
+
// colide em `people_tenant_document_uidx` ou vira uma segunda identidade
|
|
32630
|
+
// da casa — por isso o tipo vem antes, e é ele que decide o rótulo.
|
|
32631
|
+
{ key: "documentNumber", label: kind === "supplier" ? "CNPJ / CPF" : "CPF", labelWhen: pjLabel("documentNumber"), type: "text", searchable: true, showInTable: true, group: "identity" },
|
|
32632
|
+
{ key: "rg", label: "Documento", labelWhen: pjLabel("rg"), type: "text", showInTable: false, group: "identity" },
|
|
32633
|
+
{ key: "dateOfBirth", label: "Nascimento", labelWhen: pjLabel("dateOfBirth"), type: "date", showInTable: false, group: "identity" },
|
|
32634
|
+
{ key: "profession", label: "Profiss\xE3o", labelWhen: pjLabel("profession"), type: "text", showInTable: false, group: "identity" },
|
|
32635
|
+
// Os sete que o V1 esconde em PJ. Uma empresa não tem sexo, estado civil,
|
|
32636
|
+
// escolaridade nem naturalidade — perguntar é convidar a preencher o que
|
|
32637
|
+
// ninguém vai ler.
|
|
32638
|
+
{
|
|
32639
|
+
key: "gender",
|
|
32640
|
+
label: "Sexo",
|
|
32641
|
+
type: "select",
|
|
32642
|
+
showInTable: false,
|
|
32643
|
+
group: "identity",
|
|
32644
|
+
visibleWhen: onlyPF,
|
|
32645
|
+
options: [
|
|
32646
|
+
{ value: "masculino", label: "Masculino" },
|
|
32647
|
+
{ value: "feminino", label: "Feminino" },
|
|
32648
|
+
{ value: "outro", label: "Outro" }
|
|
32649
|
+
]
|
|
32650
|
+
},
|
|
32651
|
+
{
|
|
32652
|
+
key: "maritalStatus",
|
|
32653
|
+
label: "Estado Civil",
|
|
32654
|
+
type: "select",
|
|
32655
|
+
showInTable: false,
|
|
32656
|
+
group: "identity",
|
|
32657
|
+
visibleWhen: onlyPF,
|
|
32658
|
+
options: [
|
|
32659
|
+
{ value: "solteiro", label: "Solteiro(a)" },
|
|
32660
|
+
{ value: "casado", label: "Casado(a)" },
|
|
32661
|
+
{ value: "divorciado", label: "Divorciado(a)" },
|
|
32662
|
+
{ value: "viuvo", label: "Vi\xFAvo(a)" }
|
|
32663
|
+
]
|
|
32664
|
+
},
|
|
32665
|
+
{
|
|
32666
|
+
key: "education",
|
|
32667
|
+
label: "Escolaridade",
|
|
32668
|
+
type: "select",
|
|
32669
|
+
showInTable: false,
|
|
32670
|
+
group: "identity",
|
|
32671
|
+
visibleWhen: onlyPF,
|
|
32672
|
+
options: [
|
|
32673
|
+
{ value: "fundamental", label: "Fundamental" },
|
|
32674
|
+
{ value: "medio", label: "M\xE9dio" },
|
|
32675
|
+
{ value: "superior", label: "Superior" },
|
|
32676
|
+
{ value: "pos", label: "P\xF3s-gradua\xE7\xE3o" }
|
|
32677
|
+
]
|
|
32678
|
+
},
|
|
32679
|
+
{ key: "nationality", label: "Naturalidade", type: "text", showInTable: false, group: "identity", visibleWhen: onlyPF },
|
|
32680
|
+
...crmContactChannels(),
|
|
32681
|
+
{ key: "address", label: "Endere\xE7o", type: "address", showInTable: false, showInDetail: false, group: "where" },
|
|
32682
|
+
// COMO CHEGOU. A origem é catálogo (o cadastro de Origens); a indicação é
|
|
32683
|
+
// quem trouxe, em texto — no V1 ela vira obrigatória quando a origem
|
|
32684
|
+
// escolhida pede pessoa (`origins.requires_person`).
|
|
32685
|
+
{
|
|
32686
|
+
key: "originId",
|
|
32687
|
+
label: "Origem",
|
|
32688
|
+
type: "relation",
|
|
32689
|
+
showInTable: false,
|
|
32690
|
+
group: "origin",
|
|
32691
|
+
relation: { table: "categories", labelField: "name", filter: { kind: "origin" } }
|
|
32692
|
+
},
|
|
32693
|
+
{ key: "referral", label: "Indica\xE7\xE3o", type: "text", showInTable: false, group: "origin" },
|
|
32694
|
+
...recordRailFields({ tagsTable: "people", activeLabel: "Ativo" }),
|
|
32695
|
+
// AVISOS não é observação: é o que a recepção precisa ver ANTES de
|
|
32696
|
+
// atender («não pode níquel», «paga sempre no cartão da mãe»). No V1 ele
|
|
32697
|
+
// tem campo próprio, e misturá-lo com as observações é perdê-lo.
|
|
32698
|
+
{ key: "warnings", label: "Avisos e Pend\xEAncias", type: "textarea", showInTable: false, group: "record", span: 2 }
|
|
31064
32699
|
],
|
|
31065
32700
|
data: {
|
|
31066
32701
|
table: "people",
|
|
31067
32702
|
tenantScoped: true,
|
|
31068
32703
|
archetype: "person",
|
|
31069
32704
|
archetypeKind: kind,
|
|
32705
|
+
customFields: [
|
|
32706
|
+
"personType",
|
|
32707
|
+
"socialName",
|
|
32708
|
+
"rg",
|
|
32709
|
+
"profession",
|
|
32710
|
+
"gender",
|
|
32711
|
+
"maritalStatus",
|
|
32712
|
+
"education",
|
|
32713
|
+
"nationality",
|
|
32714
|
+
"originId",
|
|
32715
|
+
"referral",
|
|
32716
|
+
"warnings",
|
|
32717
|
+
...CRM_CONTACT_CUSTOM
|
|
32718
|
+
],
|
|
31070
32719
|
searchColumns: ["name", "email", "phone", "document_number"]
|
|
31071
32720
|
}
|
|
31072
32721
|
};
|
|
31073
32722
|
}
|
|
32723
|
+
function crmContactChannels() {
|
|
32724
|
+
return [
|
|
32725
|
+
{ key: "phone", label: "Telefone", type: "phone", showInTable: true, searchable: true, group: "contact" },
|
|
32726
|
+
{ key: "mobile", label: "Celular", type: "phone", showInTable: true, group: "contact" },
|
|
32727
|
+
{ key: "email", label: "E-mail", type: "email", showInTable: true, searchable: true, group: "contact", span: 2 }
|
|
32728
|
+
// Desligados: seis caixas de contato onde a resposta costuma ser um número
|
|
32729
|
+
// e um e-mail. As chaves continuam em `customFields` para o que já foi
|
|
32730
|
+
// gravado não virar lixo no jsonb.
|
|
32731
|
+
// { key: 'phone2', ... }, { key: 'mobile2', ... }, { key: 'email2', ... }
|
|
32732
|
+
];
|
|
32733
|
+
}
|
|
32734
|
+
var CRM_CONTACT_CUSTOM = ["mobile", "phone2", "mobile2", "email2"];
|
|
31074
32735
|
var VOCABULARY = {
|
|
31075
32736
|
education: { one: "Aluno", many: "Alunos" },
|
|
31076
32737
|
health: { one: "Paciente", many: "Pacientes" }
|