@fayz-ai/plugin-crm 0.31.1 → 0.31.4
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/LinkCompanyPrompt.d.ts.map +1 -1
- package/dist/components/UnitPicker.d.ts +12 -0
- package/dist/components/UnitPicker.d.ts.map +1 -0
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +542 -158
- package/dist/index.js.map +1 -1
- package/dist/lib/team.d.ts +6 -2
- package/dist/lib/team.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/CompanyListView.d.ts.map +1 -1
- package/dist/views/DealCardModal.d.ts.map +1 -1
- package/dist/views/DealListView.d.ts.map +1 -1
- package/dist/views/DealsView.d.ts.map +1 -1
- package/dist/views/LeadFormView.d.ts +8 -1
- package/dist/views/LeadFormView.d.ts.map +1 -1
- package/dist/views/LeadListView.d.ts.map +1 -1
- package/dist/views/PipelineView.d.ts +3 -1
- package/dist/views/PipelineView.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
3
|
+
import { tl, useTranslation, getSupabaseClientOptional, getActiveUnitId, RECORD_GROUP, recordRailFields, activeFacet, registerTranslations, registerMessageDefaults, createSafeDataProvider, getActiveTenantId, countByTenant, usePluginRuntimeOptional, useActiveTenantId, exportCSV, getCurrentLocale, loadMessageOverrides, resolveMessages, useActiveUnitId } from '@fayz-ai/core';
|
|
4
|
+
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, useUnitFilter, invalidateLimit, useAccessOptional, useOrganizationStore, getRailPage, ContactPicker, useAgentSurface } from '@fayz-ai/admin';
|
|
5
|
+
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, Briefcase, CircleDot, User, Download, CircleDashed, Search, Inbox, Play, Clock, Sparkles, Calendar, ArrowRight, MoreHorizontal, ChevronDown, Printer, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Loader2, Network, Building2, 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
6
|
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
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
8
|
import { createPortal } from 'react-dom';
|
|
@@ -190,13 +191,13 @@ var KINDS = [
|
|
|
190
191
|
];
|
|
191
192
|
function GroupRow({ g, onOpen, open, members, roll, onEdit, onAdd, onRemove, onDelete, search }) {
|
|
192
193
|
const { currency } = useCrmConfig();
|
|
193
|
-
const [editing, setEditing] =
|
|
194
|
-
const [draftName, setDraftName] =
|
|
195
|
-
const [draftKind, setDraftKind] =
|
|
196
|
-
const [term, setTerm] =
|
|
197
|
-
const [hits, setHits] =
|
|
198
|
-
const [busy, setBusy] =
|
|
199
|
-
|
|
194
|
+
const [editing, setEditing] = React__default.useState(false);
|
|
195
|
+
const [draftName, setDraftName] = React__default.useState(g.name);
|
|
196
|
+
const [draftKind, setDraftKind] = React__default.useState(g.kind ?? "economic_group");
|
|
197
|
+
const [term, setTerm] = React__default.useState("");
|
|
198
|
+
const [hits, setHits] = React__default.useState([]);
|
|
199
|
+
const [busy, setBusy] = React__default.useState(false);
|
|
200
|
+
React__default.useEffect(() => {
|
|
200
201
|
if (term.trim().length < 2) {
|
|
201
202
|
setHits([]);
|
|
202
203
|
return;
|
|
@@ -387,16 +388,16 @@ function GroupRow({ g, onOpen, open, members, roll, onEdit, onAdd, onRemove, onD
|
|
|
387
388
|
}
|
|
388
389
|
function CompanyGroupsView() {
|
|
389
390
|
const provider = useCrmProvider();
|
|
390
|
-
const [groups, setGroups] =
|
|
391
|
-
const [candidates, setCandidates] =
|
|
392
|
-
const [openId, setOpenId] =
|
|
393
|
-
const [members, setMembers] =
|
|
394
|
-
const [rollups, setRollups] =
|
|
395
|
-
const [names, setNames] =
|
|
396
|
-
const [busy, setBusy] =
|
|
397
|
-
const [novoAberto, setNovoAberto] =
|
|
398
|
-
const [novoNome, setNovoNome] =
|
|
399
|
-
const [criando, setCriando] =
|
|
391
|
+
const [groups, setGroups] = React__default.useState(null);
|
|
392
|
+
const [candidates, setCandidates] = React__default.useState([]);
|
|
393
|
+
const [openId, setOpenId] = React__default.useState(null);
|
|
394
|
+
const [members, setMembers] = React__default.useState({});
|
|
395
|
+
const [rollups, setRollups] = React__default.useState({});
|
|
396
|
+
const [names, setNames] = React__default.useState({});
|
|
397
|
+
const [busy, setBusy] = React__default.useState(null);
|
|
398
|
+
const [novoAberto, setNovoAberto] = React__default.useState(false);
|
|
399
|
+
const [novoNome, setNovoNome] = React__default.useState("");
|
|
400
|
+
const [criando, setCriando] = React__default.useState(false);
|
|
400
401
|
async function criarGrupo() {
|
|
401
402
|
const nome = novoNome.trim();
|
|
402
403
|
if (!nome || criando) return;
|
|
@@ -413,7 +414,7 @@ function CompanyGroupsView() {
|
|
|
413
414
|
setCriando(false);
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
|
-
const load =
|
|
417
|
+
const load = React__default.useCallback(async () => {
|
|
417
418
|
try {
|
|
418
419
|
const [g, c, r] = await Promise.all([
|
|
419
420
|
provider.getCompanyGroups(),
|
|
@@ -428,7 +429,7 @@ function CompanyGroupsView() {
|
|
|
428
429
|
setGroups([]);
|
|
429
430
|
}
|
|
430
431
|
}, [provider]);
|
|
431
|
-
|
|
432
|
+
React__default.useEffect(() => {
|
|
432
433
|
void load();
|
|
433
434
|
}, [load]);
|
|
434
435
|
async function toggle(id) {
|
|
@@ -599,9 +600,9 @@ function CompanyGroupsView() {
|
|
|
599
600
|
function EngagementLadderSettings() {
|
|
600
601
|
const t2 = useTranslation();
|
|
601
602
|
const provider = useCrmProvider();
|
|
602
|
-
const [cfg, setCfg] =
|
|
603
|
-
const [saving, setSaving] =
|
|
604
|
-
|
|
603
|
+
const [cfg, setCfg] = React__default.useState(null);
|
|
604
|
+
const [saving, setSaving] = React__default.useState(false);
|
|
605
|
+
React__default.useEffect(() => {
|
|
605
606
|
let alive = true;
|
|
606
607
|
provider.getEngagementSummary().then((d) => {
|
|
607
608
|
if (alive) setCfg(d.settings);
|
|
@@ -655,9 +656,9 @@ function EngagementLadderSettings() {
|
|
|
655
656
|
function LeadScoreWeights() {
|
|
656
657
|
const t2 = useTranslation();
|
|
657
658
|
const provider = useCrmProvider();
|
|
658
|
-
const [rows, setRows] =
|
|
659
|
-
const [saving, setSaving] =
|
|
660
|
-
|
|
659
|
+
const [rows, setRows] = React__default.useState(null);
|
|
660
|
+
const [saving, setSaving] = React__default.useState(null);
|
|
661
|
+
React__default.useEffect(() => {
|
|
661
662
|
let alive = true;
|
|
662
663
|
provider.getLeadScoreWeights().then((d) => {
|
|
663
664
|
if (alive) setRows(d);
|
|
@@ -929,6 +930,45 @@ function LostReasonDialog({
|
|
|
929
930
|
] })
|
|
930
931
|
] }) });
|
|
931
932
|
}
|
|
933
|
+
function useCrmUnitFilter() {
|
|
934
|
+
return useUnitFilter({ scope: "global" });
|
|
935
|
+
}
|
|
936
|
+
var ROW = "flex w-full items-center gap-2 rounded-button px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted";
|
|
937
|
+
function UnitPicker({ filter: f }) {
|
|
938
|
+
const [open, setOpen] = React.useState(false);
|
|
939
|
+
if (!f.visible) return null;
|
|
940
|
+
const current = f.value ? f.options.find((u) => u.id === f.value)?.name ?? f.allLabel : f.allLabel;
|
|
941
|
+
const pick = (id) => {
|
|
942
|
+
f.setValue(id);
|
|
943
|
+
setOpen(false);
|
|
944
|
+
};
|
|
945
|
+
return /* @__PURE__ */ jsxs(Dropdown, { open, onOpenChange: setOpen, children: [
|
|
946
|
+
/* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
947
|
+
"button",
|
|
948
|
+
{
|
|
949
|
+
type: "button",
|
|
950
|
+
title: f.label,
|
|
951
|
+
className: "inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full border bg-card px-3 text-xs font-medium text-foreground shadow-button transition-colors hover:bg-muted",
|
|
952
|
+
children: [
|
|
953
|
+
/* @__PURE__ */ jsx(Building2, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
|
|
954
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[10rem] truncate", children: current }),
|
|
955
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 shrink-0 opacity-60" })
|
|
956
|
+
]
|
|
957
|
+
}
|
|
958
|
+
) }),
|
|
959
|
+
/* @__PURE__ */ jsxs(DropdownContent, { align: "end", className: "w-56 p-1", children: [
|
|
960
|
+
/* @__PURE__ */ jsxs("button", { className: ROW, onClick: () => pick(void 0), children: [
|
|
961
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: f.allLabel }),
|
|
962
|
+
!f.value && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
963
|
+
] }),
|
|
964
|
+
/* @__PURE__ */ jsx("div", { className: "my-1 border-t" }),
|
|
965
|
+
/* @__PURE__ */ jsx("div", { className: "max-h-64 overflow-y-auto", children: f.options.map((u) => /* @__PURE__ */ jsxs("button", { className: ROW, onClick: () => pick(u.id), children: [
|
|
966
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: u.name }),
|
|
967
|
+
f.value === u.id && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
|
|
968
|
+
] }, u.id)) })
|
|
969
|
+
] })
|
|
970
|
+
] });
|
|
971
|
+
}
|
|
932
972
|
|
|
933
973
|
// src/lib/relative-time.ts
|
|
934
974
|
var MINUTE = 60;
|
|
@@ -1073,13 +1113,19 @@ function useBoardFilterValue(myUserId) {
|
|
|
1073
1113
|
owner: owner === "__me__" ? myUserId ?? void 0 : owner
|
|
1074
1114
|
});
|
|
1075
1115
|
}
|
|
1076
|
-
async function loadTeam() {
|
|
1116
|
+
async function loadTeam(opts) {
|
|
1077
1117
|
const supabase = getSupabaseClientOptional();
|
|
1078
1118
|
if (!supabase) return [];
|
|
1079
1119
|
const { data: memberships, error } = await supabase.from("v_authz_memberships").select("user_id, person_id").eq("active", true);
|
|
1080
1120
|
if (error) throw new Error(error.message);
|
|
1081
|
-
|
|
1121
|
+
let rows = memberships ?? [];
|
|
1082
1122
|
if (rows.length === 0) return [];
|
|
1123
|
+
const unitId = opts?.unitId ?? getActiveUnitId();
|
|
1124
|
+
if (unitId) {
|
|
1125
|
+
const { data: reach } = await supabase.from("v_authz_user_unit_access").select("user_id").eq("unit_id", unitId);
|
|
1126
|
+
const allowed = new Set((reach ?? []).map((r) => r.user_id));
|
|
1127
|
+
if (allowed.size > 0) rows = rows.filter((r) => allowed.has(r.user_id));
|
|
1128
|
+
}
|
|
1083
1129
|
const { data: people } = await supabase.from("people").select("id, name").in("id", rows.map((r) => r.person_id));
|
|
1084
1130
|
const nameById = new Map(
|
|
1085
1131
|
(people ?? []).map((p) => [p.id, p.name ?? ""])
|
|
@@ -1091,9 +1137,9 @@ async function loadTeam() {
|
|
|
1091
1137
|
}
|
|
1092
1138
|
return [...porUsuario.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
1093
1139
|
}
|
|
1094
|
-
async function loadTeamOrNull() {
|
|
1140
|
+
async function loadTeamOrNull(opts) {
|
|
1095
1141
|
try {
|
|
1096
|
-
return await loadTeam();
|
|
1142
|
+
return await loadTeam(opts);
|
|
1097
1143
|
} catch {
|
|
1098
1144
|
return null;
|
|
1099
1145
|
}
|
|
@@ -1406,7 +1452,7 @@ function usePipelineAgentSurface(deps) {
|
|
|
1406
1452
|
}
|
|
1407
1453
|
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";
|
|
1408
1454
|
function BoardFilterChip({ trigger, onClear, clearLabel, closeOnSelect, children }) {
|
|
1409
|
-
const [open, setOpen] =
|
|
1455
|
+
const [open, setOpen] = React__default.useState(false);
|
|
1410
1456
|
return /* @__PURE__ */ jsxs(Dropdown, { open, onOpenChange: setOpen, children: [
|
|
1411
1457
|
/* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
1412
1458
|
"button",
|
|
@@ -1854,6 +1900,7 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, onStageIntent })
|
|
|
1854
1900
|
void loadMyUserId().then(setMyUserId);
|
|
1855
1901
|
}, []);
|
|
1856
1902
|
const effectiveOwner = ownerFilter === "__me__" ? myUserId ?? void 0 : ownerFilter;
|
|
1903
|
+
const unitFilter = useCrmUnitFilter();
|
|
1857
1904
|
const [temps, setTemps] = useState(/* @__PURE__ */ new Map());
|
|
1858
1905
|
const [channels, setChannels] = useState(/* @__PURE__ */ new Map());
|
|
1859
1906
|
const [period, setPeriod] = usePersistedState("crm.board.period", "all");
|
|
@@ -2192,6 +2239,7 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, onStageIntent })
|
|
|
2192
2239
|
})
|
|
2193
2240
|
}
|
|
2194
2241
|
),
|
|
2242
|
+
/* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
|
|
2195
2243
|
/* @__PURE__ */ jsx(
|
|
2196
2244
|
FilterMenu,
|
|
2197
2245
|
{
|
|
@@ -2327,19 +2375,19 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, onStageIntent })
|
|
|
2327
2375
|
})),
|
|
2328
2376
|
count: (col) => query ? (displayBoard.get(col.id) ?? []).length : dealStageTotals.get(col.id) ?? (displayBoard.get(col.id) ?? []).length,
|
|
2329
2377
|
isOver: (col) => dragOverStageId === col.id,
|
|
2330
|
-
columnAction: onAddLead ? () => /* @__PURE__ */ jsx(
|
|
2378
|
+
columnAction: onAddLead ? (col) => /* @__PURE__ */ jsx(
|
|
2331
2379
|
"button",
|
|
2332
2380
|
{
|
|
2333
2381
|
onClick: (e) => {
|
|
2334
2382
|
e.stopPropagation();
|
|
2335
|
-
onAddLead();
|
|
2383
|
+
onAddLead(col.id);
|
|
2336
2384
|
},
|
|
2337
2385
|
title: t2("crm.pipeline.addLead"),
|
|
2338
2386
|
className: "flex h-5 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
|
|
2339
2387
|
children: /* @__PURE__ */ jsx(Plus, { className: "h-3.5 w-3.5" })
|
|
2340
2388
|
}
|
|
2341
2389
|
) : void 0,
|
|
2342
|
-
onAddCard: onAddLead ? () => onAddLead() : void 0,
|
|
2390
|
+
onAddCard: onAddLead ? (col) => onAddLead(col.id) : void 0,
|
|
2343
2391
|
addCardLabel: t2("crm.pipeline.addLead"),
|
|
2344
2392
|
dropProps: (col) => ({
|
|
2345
2393
|
onDragOver: (e) => handleDragOver(col.id, e),
|
|
@@ -2768,6 +2816,7 @@ function DealListView({ onOpenDeal }) {
|
|
|
2768
2816
|
cohort && t2("crm.deals.cohort"),
|
|
2769
2817
|
companyName && t2("crm.card.companyTitle")
|
|
2770
2818
|
].filter(Boolean);
|
|
2819
|
+
const unitFilter = useCrmUnitFilter();
|
|
2771
2820
|
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);
|
|
2772
2821
|
const limparFiltros = () => {
|
|
2773
2822
|
setStage(void 0);
|
|
@@ -2888,6 +2937,7 @@ function DealListView({ onOpenDeal }) {
|
|
|
2888
2937
|
)
|
|
2889
2938
|
] }),
|
|
2890
2939
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 flex-nowrap items-center justify-end gap-1.5 md:flex-wrap", children: [
|
|
2940
|
+
/* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
|
|
2891
2941
|
stage && /* @__PURE__ */ jsx(
|
|
2892
2942
|
FilterChip,
|
|
2893
2943
|
{
|
|
@@ -3958,11 +4008,11 @@ var partnerEntity = {
|
|
|
3958
4008
|
// escondido, e sem isto a coluna NOT NULL recebe null e o save volta 400.
|
|
3959
4009
|
defaultValue: [],
|
|
3960
4010
|
visibleWhen: (values) => values.allUnits === false,
|
|
3961
|
-
renderInput: ({ value, onChange }) =>
|
|
4011
|
+
renderInput: ({ value, onChange }) => React__default.createElement(PartnerUnitsInput, {
|
|
3962
4012
|
value,
|
|
3963
4013
|
onChange
|
|
3964
4014
|
}),
|
|
3965
|
-
renderCell: (value) =>
|
|
4015
|
+
renderCell: (value) => React__default.createElement(PartnerUnitsCell, { value })
|
|
3966
4016
|
},
|
|
3967
4017
|
{
|
|
3968
4018
|
key: "allowsOnlineBooking",
|
|
@@ -3971,7 +4021,7 @@ var partnerEntity = {
|
|
|
3971
4021
|
showInTable: true,
|
|
3972
4022
|
defaultValue: false,
|
|
3973
4023
|
hint: "Members can book on their own from the public page.",
|
|
3974
|
-
renderCell: (value) =>
|
|
4024
|
+
renderCell: (value) => React__default.createElement(PartnerOnlineBookingCell, { value })
|
|
3975
4025
|
},
|
|
3976
4026
|
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
3977
4027
|
],
|
|
@@ -4202,11 +4252,11 @@ var assignmentRuleEntity = {
|
|
|
4202
4252
|
defaultValue: [],
|
|
4203
4253
|
showInTable: true,
|
|
4204
4254
|
hint: "Who is offered a new lead, in order.",
|
|
4205
|
-
renderInput: ({ value, onChange }) =>
|
|
4255
|
+
renderInput: ({ value, onChange }) => React__default.createElement(AssigneeRotaInput, {
|
|
4206
4256
|
value,
|
|
4207
4257
|
onChange
|
|
4208
4258
|
}),
|
|
4209
|
-
renderCell: (value) =>
|
|
4259
|
+
renderCell: (value) => React__default.createElement(AssigneeRotaCell, { value })
|
|
4210
4260
|
},
|
|
4211
4261
|
// Where the rotation currently is. Read-only: editing it by hand would skew
|
|
4212
4262
|
// the next offer with nothing recording why.
|
|
@@ -4361,7 +4411,7 @@ function buildCrmRegistries(activityTypes) {
|
|
|
4361
4411
|
function LinkCompanyPrompt({ personId, companyText, onLinked }) {
|
|
4362
4412
|
const t2 = useTranslation();
|
|
4363
4413
|
const provider = useCrmProvider();
|
|
4364
|
-
const
|
|
4414
|
+
const refreshCompanies = useCrmStore((s) => s.refreshCompanies);
|
|
4365
4415
|
const [existente, setExistente] = useState(null);
|
|
4366
4416
|
const [ligando, setLigando] = useState(false);
|
|
4367
4417
|
const nome = companyText?.trim();
|
|
@@ -4387,8 +4437,9 @@ function LinkCompanyPrompt({ personId, companyText, onLinked }) {
|
|
|
4387
4437
|
if (!nome || ligando) return;
|
|
4388
4438
|
setLigando(true);
|
|
4389
4439
|
try {
|
|
4390
|
-
const companyId = existente?.id ?? (await saveCompany({ name: nome })).id;
|
|
4440
|
+
const companyId = existente?.id ?? (await provider.saveCompany({ name: nome })).id;
|
|
4391
4441
|
await provider.linkCompanyPerson({ companyId, personId, isPrimary: true });
|
|
4442
|
+
void refreshCompanies();
|
|
4392
4443
|
toast.success(t2("crm.linkCompany.done", { name: nome }));
|
|
4393
4444
|
onLinked?.(companyId);
|
|
4394
4445
|
} catch (err) {
|
|
@@ -4537,7 +4588,7 @@ function formatDocument(doc) {
|
|
|
4537
4588
|
return doc;
|
|
4538
4589
|
}
|
|
4539
4590
|
function CopyDocument({ document: doc, label: label2 }) {
|
|
4540
|
-
const [copied, setCopied] =
|
|
4591
|
+
const [copied, setCopied] = React__default.useState(false);
|
|
4541
4592
|
return /* @__PURE__ */ jsx(
|
|
4542
4593
|
"button",
|
|
4543
4594
|
{
|
|
@@ -4768,6 +4819,9 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4768
4819
|
setLoading(false);
|
|
4769
4820
|
return;
|
|
4770
4821
|
}
|
|
4822
|
+
void loadTeamOrNull({ unitId: d.unitId }).then((team2) => {
|
|
4823
|
+
if (!cancelled) setTeam(team2);
|
|
4824
|
+
});
|
|
4771
4825
|
if (d.pipelineId) {
|
|
4772
4826
|
void provider.getPipelineStages(d.pipelineId).then((s) => {
|
|
4773
4827
|
if (!cancelled) setStages(s);
|
|
@@ -4818,9 +4872,6 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
4818
4872
|
void provider.getQuotesByDealId(dealId).then((q) => {
|
|
4819
4873
|
if (!cancelled) setQuotes(q);
|
|
4820
4874
|
});
|
|
4821
|
-
void loadTeamOrNull().then((t3) => {
|
|
4822
|
-
if (!cancelled) setTeam(t3);
|
|
4823
|
-
});
|
|
4824
4875
|
void loadMyUserId().then((u) => {
|
|
4825
4876
|
if (!cancelled) setMyUserId(u);
|
|
4826
4877
|
});
|
|
@@ -5319,7 +5370,11 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
|
|
|
5319
5370
|
{
|
|
5320
5371
|
personId: pessoaDoCard.id,
|
|
5321
5372
|
companyText: pessoaDoCard.company ?? draft.company,
|
|
5322
|
-
onLinked: () => {
|
|
5373
|
+
onLinked: (companyId) => {
|
|
5374
|
+
void provider.getCompanyById(companyId).then((c) => {
|
|
5375
|
+
if (c) setCompany(c);
|
|
5376
|
+
});
|
|
5377
|
+
void provider.getCompanyGroupPeople(companyId).catch(() => []).then((gente) => setPessoasDaCasa(gente));
|
|
5323
5378
|
void provider.getLiveDealById(dealId).then((d) => d && setDeal(d));
|
|
5324
5379
|
}
|
|
5325
5380
|
}
|
|
@@ -5411,8 +5466,9 @@ function instagramUrl(handle) {
|
|
|
5411
5466
|
if (!h || !/^[A-Za-z0-9._]{1,30}$/.test(h)) return void 0;
|
|
5412
5467
|
return `https://instagram.com/${h}`;
|
|
5413
5468
|
}
|
|
5414
|
-
function LeadFormView({ onSaved }) {
|
|
5469
|
+
function LeadFormView({ onSaved, initialStageId, initialPipelineId }) {
|
|
5415
5470
|
const t2 = useTranslation();
|
|
5471
|
+
const provider = useCrmProvider();
|
|
5416
5472
|
const createLead = useCrmStore((s) => s.createLead);
|
|
5417
5473
|
const guardLeads = useLimitGuard("leads");
|
|
5418
5474
|
const resolveEntryPipeline = useCrmStore((s) => s.resolveEntryPipeline);
|
|
@@ -5430,19 +5486,24 @@ function LeadFormView({ onSaved }) {
|
|
|
5430
5486
|
void fetchLeadSources();
|
|
5431
5487
|
}, []);
|
|
5432
5488
|
const [stages, setStages] = useState([]);
|
|
5433
|
-
const [stageId, setStageId] = useState("");
|
|
5489
|
+
const [stageId, setStageId] = useState(initialStageId ?? "");
|
|
5434
5490
|
useEffect(() => {
|
|
5435
5491
|
let cancelled = false;
|
|
5436
|
-
|
|
5492
|
+
const carrega = initialPipelineId ? provider.getPipelineStages(initialPipelineId).then((entry) => ({ stages: entry })) : resolveEntryPipeline();
|
|
5493
|
+
void carrega.then(({ stages: entry }) => {
|
|
5437
5494
|
if (cancelled) return;
|
|
5438
5495
|
const open = entry.filter((s) => !s.isWon && !s.isLost).sort((a, b) => a.order - b.order);
|
|
5439
5496
|
setStages(open);
|
|
5440
|
-
setStageId((current) =>
|
|
5497
|
+
setStageId((current) => {
|
|
5498
|
+
if (current && open.some((s) => s.id === current)) return current;
|
|
5499
|
+
if (initialStageId && open.some((s) => s.id === initialStageId)) return initialStageId;
|
|
5500
|
+
return open[0]?.id || "";
|
|
5501
|
+
});
|
|
5441
5502
|
});
|
|
5442
5503
|
return () => {
|
|
5443
5504
|
cancelled = true;
|
|
5444
5505
|
};
|
|
5445
|
-
}, []);
|
|
5506
|
+
}, [initialPipelineId, initialStageId]);
|
|
5446
5507
|
async function handleSave() {
|
|
5447
5508
|
if (!name.trim()) {
|
|
5448
5509
|
toast.error(t2("common.formIncomplete"));
|
|
@@ -5463,7 +5524,8 @@ function LeadFormView({ onSaved }) {
|
|
|
5463
5524
|
notes: notes || void 0,
|
|
5464
5525
|
sourceId: source?.id,
|
|
5465
5526
|
sourceName: source?.name,
|
|
5466
|
-
stageId: stageId || void 0
|
|
5527
|
+
stageId: stageId || void 0,
|
|
5528
|
+
pipelineId: initialPipelineId
|
|
5467
5529
|
});
|
|
5468
5530
|
invalidateLimit("leads");
|
|
5469
5531
|
invalidateLimit("deals");
|
|
@@ -5579,11 +5641,11 @@ function DealsView({ mode, onChangeMode, openDealId, onOpenDeal, onCloseDeal, on
|
|
|
5579
5641
|
}
|
|
5580
5642
|
};
|
|
5581
5643
|
const [pendingStage, setPendingStage] = useState(null);
|
|
5582
|
-
const [novoLead, setNovoLead] = useState(
|
|
5644
|
+
const [novoLead, setNovoLead] = useState(null);
|
|
5583
5645
|
const refreshBoard = useCrmStore((s) => s.refreshBoard);
|
|
5584
|
-
const addLead = onAddLead ? () => setNovoLead(
|
|
5646
|
+
const addLead = onAddLead ? (stageId) => setNovoLead({ stageId }) : void 0;
|
|
5585
5647
|
const dealsByStage = useCrmStore((s) => s.dealsByStage);
|
|
5586
|
-
const seedDeal =
|
|
5648
|
+
const seedDeal = React__default.useMemo(() => {
|
|
5587
5649
|
if (!openId) return null;
|
|
5588
5650
|
for (const lista of dealsByStage.values()) {
|
|
5589
5651
|
const d = lista.find((x) => x.id === openId);
|
|
@@ -5615,7 +5677,7 @@ function DealsView({ mode, onChangeMode, openDealId, onOpenDeal, onCloseDeal, on
|
|
|
5615
5677
|
icon: Plus,
|
|
5616
5678
|
intent: "primary",
|
|
5617
5679
|
creates: true,
|
|
5618
|
-
onSelect: addLead ?? onAddLead
|
|
5680
|
+
onSelect: () => (addLead ?? onAddLead)?.()
|
|
5619
5681
|
}] : [],
|
|
5620
5682
|
...onOpenSettings ? [{
|
|
5621
5683
|
id: "pipeline-stages",
|
|
@@ -5669,15 +5731,22 @@ function DealsView({ mode, onChangeMode, openDealId, onOpenDeal, onCloseDeal, on
|
|
|
5669
5731
|
}
|
|
5670
5732
|
}
|
|
5671
5733
|
),
|
|
5672
|
-
novoLead && /* @__PURE__ */ jsx(
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5734
|
+
novoLead && /* @__PURE__ */ jsx(
|
|
5735
|
+
LeadFormView,
|
|
5736
|
+
{
|
|
5737
|
+
initialStageId: novoLead.stageId,
|
|
5738
|
+
initialPipelineId: novoLead.stageId ? activePipelineId ?? void 0 : void 0,
|
|
5739
|
+
onSaved: (id) => {
|
|
5740
|
+
setNovoLead(null);
|
|
5741
|
+
if (!id) return;
|
|
5742
|
+
void refreshBoard();
|
|
5743
|
+
void provider.getPipelineCardForLead(id).then((d) => {
|
|
5744
|
+
if (d) openCard(d.id);
|
|
5745
|
+
}).catch(() => {
|
|
5746
|
+
});
|
|
5747
|
+
}
|
|
5748
|
+
}
|
|
5749
|
+
),
|
|
5681
5750
|
/* @__PURE__ */ jsx(
|
|
5682
5751
|
DealCardModal,
|
|
5683
5752
|
{
|
|
@@ -6299,6 +6368,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
6299
6368
|
}
|
|
6300
6369
|
return vistos;
|
|
6301
6370
|
}, [team, leads2]);
|
|
6371
|
+
const unitFilter = useCrmUnitFilter();
|
|
6302
6372
|
const activeFilterCount = (statusFilter.length ? 1 : 0) + (sourceFilter ? 1 : 0) + (tagFilter.length ? 1 : 0) + (effectiveOwner ? 1 : 0) + (companyFilter ? 1 : 0) + (reachFilter ? 1 : 0) + (cityFilter ? 1 : 0);
|
|
6303
6373
|
const clearFilters = () => {
|
|
6304
6374
|
setStatusFilter([]);
|
|
@@ -6374,7 +6444,7 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
6374
6444
|
FilterChip,
|
|
6375
6445
|
{
|
|
6376
6446
|
label: t2("crm.leads.companyCol"),
|
|
6377
|
-
icon:
|
|
6447
|
+
icon: Briefcase,
|
|
6378
6448
|
allLabel: t2("crm.leads.filters.anyCompany"),
|
|
6379
6449
|
options: [
|
|
6380
6450
|
{ value: "yes", label: t2("crm.leads.filters.withCompany") },
|
|
@@ -6545,9 +6615,12 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
6545
6615
|
] })
|
|
6546
6616
|
},
|
|
6547
6617
|
{
|
|
6618
|
+
// Briefcase, not Building2: the unit field took the building icon the
|
|
6619
|
+
// rest of the product uses for a branch, and two identical icons in
|
|
6620
|
+
// one menu are two fields people confuse.
|
|
6548
6621
|
id: "company",
|
|
6549
6622
|
label: t2("crm.leads.companyCol"),
|
|
6550
|
-
icon:
|
|
6623
|
+
icon: Briefcase,
|
|
6551
6624
|
activeCount: companyFilter ? 1 : 0,
|
|
6552
6625
|
render: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6553
6626
|
/* @__PURE__ */ jsx(FilterMenuRow, { active: !companyFilter, onClick: () => {
|
|
@@ -6612,7 +6685,10 @@ function LeadListView({ onNew, onEdit }) {
|
|
|
6612
6685
|
search,
|
|
6613
6686
|
onSearchChange: setSearch,
|
|
6614
6687
|
filters: filtros,
|
|
6615
|
-
filtersTrigger:
|
|
6688
|
+
filtersTrigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6689
|
+
/* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
|
|
6690
|
+
filtersMenu
|
|
6691
|
+
] }),
|
|
6616
6692
|
activeFilterCount,
|
|
6617
6693
|
onClearFilters: activeFilterCount > 0 ? clearFilters : void 0,
|
|
6618
6694
|
clearFiltersLabel: t2("crm.leads.filters.clear"),
|
|
@@ -6961,7 +7037,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
6961
7037
|
const config = useCrmConfig();
|
|
6962
7038
|
const provider = useCrmProvider();
|
|
6963
7039
|
const { currency, itemTypes: declaredItemTypes } = config;
|
|
6964
|
-
const translatedItemTypes =
|
|
7040
|
+
const translatedItemTypes = React__default.useMemo(
|
|
6965
7041
|
() => declaredItemTypes.map((tp) => {
|
|
6966
7042
|
const traduzido = t2(`crm.itemType.${tp.value}`);
|
|
6967
7043
|
return traduzido === `crm.itemType.${tp.value}` ? tp : { ...tp, label: traduzido };
|
|
@@ -7036,7 +7112,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
7036
7112
|
setQuoteDate(iso);
|
|
7037
7113
|
if (validityDays !== null) setValidUntil(addDays(iso, validityDays));
|
|
7038
7114
|
}
|
|
7039
|
-
const openCustomOnMount =
|
|
7115
|
+
const openCustomOnMount = React__default.useRef(false);
|
|
7040
7116
|
function pickValidity(days) {
|
|
7041
7117
|
openCustomOnMount.current = days === null && validityDays !== null;
|
|
7042
7118
|
setValidityDays(days);
|
|
@@ -7113,7 +7189,7 @@ function QuoteFormView({ quoteId, leadId, onSaved }) {
|
|
|
7113
7189
|
observations,
|
|
7114
7190
|
items: items.map((it) => ({ itemKind: it.itemKind, description: it.description, quantity: it.quantity, unitPrice: it.unitPrice, discount: it.discount }))
|
|
7115
7191
|
};
|
|
7116
|
-
const snapshot =
|
|
7192
|
+
const snapshot = React__default.useRef(null);
|
|
7117
7193
|
useEffect(() => {
|
|
7118
7194
|
if (!loadingExisting && snapshot.current === null) snapshot.current = JSON.stringify(currentFields);
|
|
7119
7195
|
}, [loadingExisting]);
|
|
@@ -8583,6 +8659,7 @@ function CompanyListView({ onNew, onEdit }) {
|
|
|
8583
8659
|
pageSize: PAGE_SIZE2
|
|
8584
8660
|
});
|
|
8585
8661
|
}, [search, cityFilter, tagFilter, page]);
|
|
8662
|
+
const unitFilter = useCrmUnitFilter();
|
|
8586
8663
|
const activeFilterCount = (cityFilter ? 1 : 0) + (tagFilter.length ? 1 : 0);
|
|
8587
8664
|
const clearFilters = () => {
|
|
8588
8665
|
setCityFilter(void 0);
|
|
@@ -8705,7 +8782,10 @@ function CompanyListView({ onNew, onEdit }) {
|
|
|
8705
8782
|
search,
|
|
8706
8783
|
onSearchChange: setSearch,
|
|
8707
8784
|
filters: filtros,
|
|
8708
|
-
filtersTrigger:
|
|
8785
|
+
filtersTrigger: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
8786
|
+
/* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
|
|
8787
|
+
filtersMenu
|
|
8788
|
+
] }),
|
|
8709
8789
|
activeFilterCount,
|
|
8710
8790
|
onClearFilters: activeFilterCount > 0 ? clearFilters : void 0,
|
|
8711
8791
|
clearFiltersLabel: t2("crm.leads.filters.clear"),
|
|
@@ -8946,8 +9026,8 @@ function CompanyFormView({ companyId, onSaved }) {
|
|
|
8946
9026
|
function CompanyGroupBadge({ companyId, onOpenCompany }) {
|
|
8947
9027
|
const provider = useCrmProvider();
|
|
8948
9028
|
const { currency } = useCrmConfig();
|
|
8949
|
-
const [data, setData] =
|
|
8950
|
-
|
|
9029
|
+
const [data, setData] = React__default.useState(null);
|
|
9030
|
+
React__default.useEffect(() => {
|
|
8951
9031
|
let alive = true;
|
|
8952
9032
|
provider.getGroupOfCompany(companyId).then((d) => {
|
|
8953
9033
|
if (alive) setData(d);
|
|
@@ -9981,10 +10061,10 @@ function NetworkView() {
|
|
|
9981
10061
|
const t2 = useTranslation();
|
|
9982
10062
|
const provider = useCrmProvider();
|
|
9983
10063
|
const { currency } = useCrmConfig();
|
|
9984
|
-
const [days, setDays] =
|
|
9985
|
-
const [rows, setRows] =
|
|
9986
|
-
const [weights, setWeights] =
|
|
9987
|
-
|
|
10064
|
+
const [days, setDays] = React__default.useState("90");
|
|
10065
|
+
const [rows, setRows] = React__default.useState(null);
|
|
10066
|
+
const [weights, setWeights] = React__default.useState({});
|
|
10067
|
+
React__default.useEffect(() => {
|
|
9988
10068
|
let alive = true;
|
|
9989
10069
|
const to = (/* @__PURE__ */ new Date()).toISOString();
|
|
9990
10070
|
const from = new Date(Date.now() - Number(days) * 864e5).toISOString();
|
|
@@ -10001,9 +10081,9 @@ function NetworkView() {
|
|
|
10001
10081
|
alive = false;
|
|
10002
10082
|
};
|
|
10003
10083
|
}, [provider, days]);
|
|
10004
|
-
const scored =
|
|
10084
|
+
const scored = React__default.useMemo(() => scoreUnits(rows ?? [], weights), [rows, weights]);
|
|
10005
10085
|
const avg = networkScore(scored);
|
|
10006
|
-
const ranked =
|
|
10086
|
+
const ranked = React__default.useMemo(() => [...scored].sort((a, b) => b.revenue - a.revenue), [scored]);
|
|
10007
10087
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
10008
10088
|
/* @__PURE__ */ jsx(
|
|
10009
10089
|
SubpageHeader,
|
|
@@ -10184,11 +10264,11 @@ function SurveyScale({ type, value, onChange, readOnly, compact }) {
|
|
|
10184
10264
|
] });
|
|
10185
10265
|
}
|
|
10186
10266
|
function SurveyEditorDialog({ survey, provider, answeredQuestionIds, onClose, onSaved }) {
|
|
10187
|
-
const [name, setName] =
|
|
10188
|
-
const [isActive, setIsActive] =
|
|
10189
|
-
const [askOnCheckout, setAskOnCheckout] =
|
|
10190
|
-
const [thanks, setThanks] =
|
|
10191
|
-
const [questions, setQuestions] =
|
|
10267
|
+
const [name, setName] = React__default.useState(survey?.name ?? "Pesquisa p\xF3s-atendimento");
|
|
10268
|
+
const [isActive, setIsActive] = React__default.useState(survey?.isActive ?? true);
|
|
10269
|
+
const [askOnCheckout, setAskOnCheckout] = React__default.useState(survey?.askOnCheckout ?? true);
|
|
10270
|
+
const [thanks, setThanks] = React__default.useState(survey?.thankYouMessage ?? "");
|
|
10271
|
+
const [questions, setQuestions] = React__default.useState(
|
|
10192
10272
|
(survey?.questions ?? []).map((q) => ({
|
|
10193
10273
|
id: q.id,
|
|
10194
10274
|
text: q.text,
|
|
@@ -10198,8 +10278,8 @@ function SurveyEditorDialog({ survey, provider, answeredQuestionIds, onClose, on
|
|
|
10198
10278
|
answered: answeredQuestionIds?.has(q.id)
|
|
10199
10279
|
}))
|
|
10200
10280
|
);
|
|
10201
|
-
const [saving, setSaving] =
|
|
10202
|
-
const [error, setError] =
|
|
10281
|
+
const [saving, setSaving] = React__default.useState(false);
|
|
10282
|
+
const [error, setError] = React__default.useState(null);
|
|
10203
10283
|
function patch(i, changes) {
|
|
10204
10284
|
setQuestions((qs) => qs.map((q, j) => j === i ? { ...q, ...changes } : q));
|
|
10205
10285
|
}
|
|
@@ -10393,13 +10473,13 @@ function SurveyEditorDialog({ survey, provider, answeredQuestionIds, onClose, on
|
|
|
10393
10473
|
}
|
|
10394
10474
|
function SurveyCollectDialog({ survey, provider, contactLookup, onClose, onSaved }) {
|
|
10395
10475
|
const unitId = useActiveUnitId();
|
|
10396
|
-
const [contact, setContact] =
|
|
10397
|
-
const [answers, setAnswers] =
|
|
10476
|
+
const [contact, setContact] = React__default.useState(null);
|
|
10477
|
+
const [answers, setAnswers] = React__default.useState(
|
|
10398
10478
|
Object.fromEntries(survey.questions.map((q) => [q.id, { rating: null, comment: "" }]))
|
|
10399
10479
|
);
|
|
10400
|
-
const [saving, setSaving] =
|
|
10401
|
-
const [done, setDone] =
|
|
10402
|
-
const [error, setError] =
|
|
10480
|
+
const [saving, setSaving] = React__default.useState(false);
|
|
10481
|
+
const [done, setDone] = React__default.useState(false);
|
|
10482
|
+
const [error, setError] = React__default.useState(null);
|
|
10403
10483
|
function patch(id, changes) {
|
|
10404
10484
|
setAnswers((a) => ({ ...a, [id]: { ...a[id], ...changes } }));
|
|
10405
10485
|
}
|
|
@@ -10498,8 +10578,8 @@ function ResponseSkeleton() {
|
|
|
10498
10578
|
] }, i)) });
|
|
10499
10579
|
}
|
|
10500
10580
|
function SurveyResponsesRail({ survey, provider, onClose }) {
|
|
10501
|
-
const [responses, setResponses] =
|
|
10502
|
-
|
|
10581
|
+
const [responses, setResponses] = React__default.useState(null);
|
|
10582
|
+
React__default.useEffect(() => {
|
|
10503
10583
|
let cancelled = false;
|
|
10504
10584
|
setResponses(null);
|
|
10505
10585
|
void provider.getSurveyResponses(survey.id).then((r) => {
|
|
@@ -10559,19 +10639,19 @@ function SurveysView() {
|
|
|
10559
10639
|
const can = usePermissionOptional();
|
|
10560
10640
|
const canEdit = can("sales", "edit");
|
|
10561
10641
|
const canDelete = can("sales", "delete");
|
|
10562
|
-
const [surveys, setSurveys] =
|
|
10563
|
-
const [stats, setStats] =
|
|
10564
|
-
const [editing, setEditing] =
|
|
10565
|
-
const [collecting, setCollecting] =
|
|
10566
|
-
const [viewing, setViewing] =
|
|
10567
|
-
const [removing, setRemoving] =
|
|
10568
|
-
const [answeredIds, setAnsweredIds] =
|
|
10569
|
-
const load =
|
|
10642
|
+
const [surveys, setSurveys] = React__default.useState(null);
|
|
10643
|
+
const [stats, setStats] = React__default.useState({});
|
|
10644
|
+
const [editing, setEditing] = React__default.useState(void 0);
|
|
10645
|
+
const [collecting, setCollecting] = React__default.useState(null);
|
|
10646
|
+
const [viewing, setViewing] = React__default.useState(null);
|
|
10647
|
+
const [removing, setRemoving] = React__default.useState(null);
|
|
10648
|
+
const [answeredIds, setAnsweredIds] = React__default.useState(/* @__PURE__ */ new Set());
|
|
10649
|
+
const load = React__default.useCallback(async () => {
|
|
10570
10650
|
const [list, st] = await Promise.all([provider.getSurveys(), provider.getSurveyStats()]);
|
|
10571
10651
|
setSurveys(list);
|
|
10572
10652
|
setStats(Object.fromEntries(st.map((s) => [s.surveyId, s])));
|
|
10573
10653
|
}, [provider]);
|
|
10574
|
-
|
|
10654
|
+
React__default.useEffect(() => {
|
|
10575
10655
|
void load();
|
|
10576
10656
|
}, [load]);
|
|
10577
10657
|
const askers = (surveys ?? []).filter((s) => s.isActive && s.askOnCheckout);
|
|
@@ -10847,12 +10927,12 @@ function DistributionView() {
|
|
|
10847
10927
|
const t2 = useTranslation();
|
|
10848
10928
|
const can = usePermissionOptional();
|
|
10849
10929
|
const canDistribute = can("sales", "edit");
|
|
10850
|
-
const [rota, setRota] =
|
|
10851
|
-
const [backlog, setBacklog] =
|
|
10852
|
-
const [offers, setOffers] =
|
|
10853
|
-
const [preview, setPreview] =
|
|
10854
|
-
const [busy, setBusy] =
|
|
10855
|
-
const load =
|
|
10930
|
+
const [rota, setRota] = React__default.useState(void 0);
|
|
10931
|
+
const [backlog, setBacklog] = React__default.useState(null);
|
|
10932
|
+
const [offers, setOffers] = React__default.useState(null);
|
|
10933
|
+
const [preview, setPreview] = React__default.useState(null);
|
|
10934
|
+
const [busy, setBusy] = React__default.useState(false);
|
|
10935
|
+
const load = React__default.useCallback(async () => {
|
|
10856
10936
|
const [r, b, o] = await Promise.all([
|
|
10857
10937
|
provider.getRotaState().catch(() => null),
|
|
10858
10938
|
provider.getLeadBacklog(500).catch(() => []),
|
|
@@ -10862,7 +10942,7 @@ function DistributionView() {
|
|
|
10862
10942
|
setBacklog(b);
|
|
10863
10943
|
setOffers(o);
|
|
10864
10944
|
}, [provider]);
|
|
10865
|
-
|
|
10945
|
+
React__default.useEffect(() => {
|
|
10866
10946
|
void load();
|
|
10867
10947
|
}, [load]);
|
|
10868
10948
|
async function askPreview() {
|
|
@@ -10982,11 +11062,11 @@ function DistributionView() {
|
|
|
10982
11062
|
}
|
|
10983
11063
|
function Countdown({ seconds }) {
|
|
10984
11064
|
const t2 = useTranslation();
|
|
10985
|
-
const [left, setLeft] =
|
|
10986
|
-
|
|
11065
|
+
const [left, setLeft] = React__default.useState(seconds);
|
|
11066
|
+
React__default.useEffect(() => {
|
|
10987
11067
|
setLeft(seconds);
|
|
10988
11068
|
}, [seconds]);
|
|
10989
|
-
|
|
11069
|
+
React__default.useEffect(() => {
|
|
10990
11070
|
if (left <= 0) return;
|
|
10991
11071
|
const id = setInterval(() => setLeft((s2) => Math.max(0, s2 - 1)), 1e3);
|
|
10992
11072
|
return () => clearInterval(id);
|
|
@@ -11002,16 +11082,16 @@ function Countdown({ seconds }) {
|
|
|
11002
11082
|
function MyOffersView() {
|
|
11003
11083
|
const provider = useCrmProvider();
|
|
11004
11084
|
const t2 = useTranslation();
|
|
11005
|
-
const [offers, setOffers] =
|
|
11006
|
-
const [busy, setBusy] =
|
|
11007
|
-
const load =
|
|
11085
|
+
const [offers, setOffers] = React__default.useState(null);
|
|
11086
|
+
const [busy, setBusy] = React__default.useState(null);
|
|
11087
|
+
const load = React__default.useCallback(async () => {
|
|
11008
11088
|
try {
|
|
11009
11089
|
setOffers(await provider.getLeadOffers({ mine: true }));
|
|
11010
11090
|
} catch {
|
|
11011
11091
|
setOffers([]);
|
|
11012
11092
|
}
|
|
11013
11093
|
}, [provider]);
|
|
11014
|
-
|
|
11094
|
+
React__default.useEffect(() => {
|
|
11015
11095
|
void load();
|
|
11016
11096
|
const id = setInterval(() => {
|
|
11017
11097
|
void load();
|
|
@@ -11503,7 +11583,7 @@ function PerformancePanel() {
|
|
|
11503
11583
|
}
|
|
11504
11584
|
function NpsKpi() {
|
|
11505
11585
|
const provider = useCrmProvider();
|
|
11506
|
-
const [stats, setStats] =
|
|
11586
|
+
const [stats, setStats] = React__default.useState(null);
|
|
11507
11587
|
useEffect(() => {
|
|
11508
11588
|
let cancelled = false;
|
|
11509
11589
|
void provider.getSurveyStats().then((s) => {
|
|
@@ -11537,8 +11617,8 @@ function NpsKpi() {
|
|
|
11537
11617
|
}
|
|
11538
11618
|
function useEngagement() {
|
|
11539
11619
|
const provider = useCrmProvider();
|
|
11540
|
-
const [data, setData] =
|
|
11541
|
-
|
|
11620
|
+
const [data, setData] = React__default.useState(null);
|
|
11621
|
+
React__default.useEffect(() => {
|
|
11542
11622
|
let alive = true;
|
|
11543
11623
|
provider.getEngagementSummary().then((d) => {
|
|
11544
11624
|
if (alive) setData(d);
|
|
@@ -11669,8 +11749,8 @@ function ActiveCustomersKpi() {
|
|
|
11669
11749
|
function SourceConversionChart() {
|
|
11670
11750
|
const t2 = useTranslation();
|
|
11671
11751
|
const provider = useCrmProvider();
|
|
11672
|
-
const [rows, setRows] =
|
|
11673
|
-
|
|
11752
|
+
const [rows, setRows] = React__default.useState([]);
|
|
11753
|
+
React__default.useEffect(() => {
|
|
11674
11754
|
let alive = true;
|
|
11675
11755
|
provider.getSourceConversion(90).then((r) => {
|
|
11676
11756
|
if (alive) setRows(r);
|
|
@@ -11698,8 +11778,8 @@ function SourceConversionChart() {
|
|
|
11698
11778
|
function MonthlyTrendChart() {
|
|
11699
11779
|
const t2 = useTranslation();
|
|
11700
11780
|
const provider = useCrmProvider();
|
|
11701
|
-
const [rows, setRows] =
|
|
11702
|
-
|
|
11781
|
+
const [rows, setRows] = React__default.useState([]);
|
|
11782
|
+
React__default.useEffect(() => {
|
|
11703
11783
|
let alive = true;
|
|
11704
11784
|
provider.getMonthlySeries(6).then((r) => {
|
|
11705
11785
|
if (alive) setRows(r);
|
|
@@ -13250,6 +13330,9 @@ async function fetchMyTeamId(tenantId, userId) {
|
|
|
13250
13330
|
function orTerm(raw) {
|
|
13251
13331
|
return raw.replace(/[,()]/g, " ").replace(/\s+/g, " ").trim();
|
|
13252
13332
|
}
|
|
13333
|
+
function birthUnitId() {
|
|
13334
|
+
return getActiveUnitId() ?? null;
|
|
13335
|
+
}
|
|
13253
13336
|
function toCompany(r) {
|
|
13254
13337
|
return {
|
|
13255
13338
|
id: r.id,
|
|
@@ -13338,6 +13421,7 @@ function toDeal(r) {
|
|
|
13338
13421
|
// TÍTULO para cá: buscar na nota achava o que o título já achava, e nada
|
|
13339
13422
|
// do que estava escrito na nota.
|
|
13340
13423
|
notes: r.notes ?? void 0,
|
|
13424
|
+
unitId: r.unit_id ?? void 0,
|
|
13341
13425
|
tenantId: r.tenant_id,
|
|
13342
13426
|
createdAt: r.created_at,
|
|
13343
13427
|
updatedAt: r.updated_at
|
|
@@ -13448,6 +13532,9 @@ function createSupabaseCrmProvider(options) {
|
|
|
13448
13532
|
const { pub } = getClients();
|
|
13449
13533
|
await pub.from(T.activities).insert({
|
|
13450
13534
|
tenant_id: getTenantId(),
|
|
13535
|
+
// Same reason as createActivity: null here would show the event in
|
|
13536
|
+
// every branch.
|
|
13537
|
+
unit_id: birthUnitId(),
|
|
13451
13538
|
deal_id: input.dealId ?? null,
|
|
13452
13539
|
lead_id: input.leadId ?? null,
|
|
13453
13540
|
contact_id: input.contactId ?? null,
|
|
@@ -13633,6 +13720,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
13633
13720
|
tenant_id: tenantId,
|
|
13634
13721
|
kind: "lead",
|
|
13635
13722
|
name: input.name,
|
|
13723
|
+
unit_id: birthUnitId(),
|
|
13636
13724
|
email: input.email,
|
|
13637
13725
|
phone: input.phone,
|
|
13638
13726
|
instagram: input.instagram || null,
|
|
@@ -13759,6 +13847,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
13759
13847
|
const { data: row, error } = await pub.from(T.deals).insert({
|
|
13760
13848
|
tenant_id: tenantId,
|
|
13761
13849
|
status: "open",
|
|
13850
|
+
unit_id: birthUnitId(),
|
|
13762
13851
|
title: input.title,
|
|
13763
13852
|
value: input.value,
|
|
13764
13853
|
currency: "BRL",
|
|
@@ -13843,6 +13932,7 @@ function createSupabaseCrmProvider(options) {
|
|
|
13843
13932
|
probability: stageRow?.probability ?? 0,
|
|
13844
13933
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
13845
13934
|
};
|
|
13935
|
+
if (stageRow?.pipeline_id) patch.pipeline_id = stageRow.pipeline_id;
|
|
13846
13936
|
if (stageRow?.is_won) {
|
|
13847
13937
|
patch.status = "won";
|
|
13848
13938
|
patch.lost_at = null;
|
|
@@ -13962,6 +14052,10 @@ function createSupabaseCrmProvider(options) {
|
|
|
13962
14052
|
tenant_id: tenantId,
|
|
13963
14053
|
deal_id: input.dealId,
|
|
13964
14054
|
lead_id: input.leadId,
|
|
14055
|
+
// Where the contact HAPPENED. 062 inherited it for existing rows from
|
|
14056
|
+
// the deal; from here it comes from where the person stood, which is
|
|
14057
|
+
// the same answer without the join.
|
|
14058
|
+
unit_id: birthUnitId(),
|
|
13965
14059
|
contact_id: input.contactId,
|
|
13966
14060
|
activity_type: input.activityType,
|
|
13967
14061
|
title: input.title,
|
|
@@ -15664,19 +15758,31 @@ function createCrmStore(provider) {
|
|
|
15664
15758
|
async createLead(input) {
|
|
15665
15759
|
try {
|
|
15666
15760
|
const lead = await provider.createLead(input);
|
|
15667
|
-
|
|
15761
|
+
let { pipeline: pipeline2, stages: entryStages } = await get().resolveEntryPipeline();
|
|
15762
|
+
if (input.pipelineId && input.pipelineId !== pipeline2?.id) {
|
|
15763
|
+
const alvo = get().pipelines.find((p) => p.id === input.pipelineId);
|
|
15764
|
+
if (alvo) {
|
|
15765
|
+
pipeline2 = alvo;
|
|
15766
|
+
entryStages = get().activePipelineId === alvo.id && get().stages.length > 0 ? get().stages : await provider.getPipelineStages(alvo.id);
|
|
15767
|
+
}
|
|
15768
|
+
}
|
|
15668
15769
|
const chosen = input.stageId ? entryStages.find((s) => s.id === input.stageId) : void 0;
|
|
15669
15770
|
const stage = chosen ?? entryStage(entryStages);
|
|
15670
15771
|
if (pipeline2 && stage) {
|
|
15772
|
+
const existing = await Promise.resolve(provider.getPipelineCardForLead?.(lead.id)).catch(() => null);
|
|
15671
15773
|
try {
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15774
|
+
if (existing) {
|
|
15775
|
+
if (existing.stageId !== stage.id) await provider.moveDealToStage(existing.id, stage.id);
|
|
15776
|
+
} else {
|
|
15777
|
+
await provider.createDeal({
|
|
15778
|
+
leadId: lead.id,
|
|
15779
|
+
title: lead.name,
|
|
15780
|
+
value: input.value ?? 0,
|
|
15781
|
+
pipelineId: pipeline2.id,
|
|
15782
|
+
stageId: stage.id,
|
|
15783
|
+
contactName: lead.name
|
|
15784
|
+
});
|
|
15785
|
+
}
|
|
15680
15786
|
} catch {
|
|
15681
15787
|
}
|
|
15682
15788
|
}
|
|
@@ -30232,6 +30338,283 @@ REVOKE ALL ON FUNCTION public.crm_funnel(uuid, jsonb) FROM public;
|
|
|
30232
30338
|
GRANT EXECUTE ON FUNCTION public.crm_funnel(uuid, jsonb) TO authenticated;
|
|
30233
30339
|
GRANT EXECUTE ON FUNCTION public.crm_funnel(uuid, jsonb) TO service_role;
|
|
30234
30340
|
`;
|
|
30341
|
+
var MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS = `-- ---------------------------------------------------------------------------
|
|
30342
|
+
-- 062_the_whole_crm_says_which_unit_it_is.sql
|
|
30343
|
+
--
|
|
30344
|
+
-- The CRM was the last module blind to units. Two brands selling out of one
|
|
30345
|
+
-- tenant shared a single board: 335 cards of one brand on the screen of
|
|
30346
|
+
-- whoever runs the other, with no way to say "only mine".
|
|
30347
|
+
--
|
|
30348
|
+
-- Most of the fence already existed and nobody had noticed: \`plg_crm_deals.
|
|
30349
|
+
-- unit_id\` and \`people.unit_id\` have carried a restrictive policy since 052 and
|
|
30350
|
+
-- the spine's 042, and \`app.has_unit\` narrows to \`app.current_unit_id()\`. Three
|
|
30351
|
+
-- things were missing, and each one hid the other two:
|
|
30352
|
+
--
|
|
30353
|
+
-- 1. the COLUMN on the two tables that lacked it \u2014 company and activity;
|
|
30354
|
+
-- 2. the column reaching the VIEWS, which is where the screens read: none of
|
|
30355
|
+
-- them returned \`unit_id\`, so the client had nothing to narrow by;
|
|
30356
|
+
-- 3. the row in \`scoped_resources\`, which is how the visibility screen and
|
|
30357
|
+
-- the generic CRUD learn that these rows carry a unit.
|
|
30358
|
+
--
|
|
30359
|
+
-- Activity stays OUT of \`scoped_resources\`, same call as 055: that registry
|
|
30360
|
+
-- serves the resource the visibility screen offers and wants \`owner_id\`. An
|
|
30361
|
+
-- activity has \`created_by\` \u2014 who logged it, not who owns it \u2014 and inherits its
|
|
30362
|
+
-- unit from the deal or lead it reports. Its fence is the policy below.
|
|
30363
|
+
--
|
|
30364
|
+
-- A company is born shared (\`unit_id\` null = the whole house) and every existing
|
|
30365
|
+
-- one stays that way. Deliberate, and the opposite of the unit's usual
|
|
30366
|
+
-- deny-by-default: the same restaurant chain is a customer of both brands, and
|
|
30367
|
+
-- pinning it to one branch would hide a book of business from the people
|
|
30368
|
+
-- working it.
|
|
30369
|
+
--
|
|
30370
|
+
-- Idempotent and replay-safe. Views grow by CREATE OR REPLACE with the new
|
|
30371
|
+
-- column LAST, which is what spares the CASCADE and recreating
|
|
30372
|
+
-- \`plg_crm_rep_deals\` by hand.
|
|
30373
|
+
-- ---------------------------------------------------------------------------
|
|
30374
|
+
|
|
30375
|
+
-- \u2500\u2500 the column \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
|
|
30376
|
+
|
|
30377
|
+
ALTER TABLE public.plg_crm_companies ADD COLUMN IF NOT EXISTS unit_id uuid;
|
|
30378
|
+
ALTER TABLE public.plg_crm_activities ADD COLUMN IF NOT EXISTS unit_id uuid;
|
|
30379
|
+
|
|
30380
|
+
-- SET NULL, not CASCADE: closing a branch must not delete its book of business
|
|
30381
|
+
-- or 551 logged calls. The row going back to shared is the acceptable worst
|
|
30382
|
+
-- case; losing the history is not.
|
|
30383
|
+
ALTER TABLE public.plg_crm_companies DROP CONSTRAINT IF EXISTS plg_crm_companies_unit_fk;
|
|
30384
|
+
ALTER TABLE public.plg_crm_companies
|
|
30385
|
+
ADD CONSTRAINT plg_crm_companies_unit_fk
|
|
30386
|
+
FOREIGN KEY (tenant_id, unit_id) REFERENCES app.units(tenant_id, id) ON DELETE SET NULL;
|
|
30387
|
+
|
|
30388
|
+
ALTER TABLE public.plg_crm_activities DROP CONSTRAINT IF EXISTS plg_crm_activities_unit_fk;
|
|
30389
|
+
ALTER TABLE public.plg_crm_activities
|
|
30390
|
+
ADD CONSTRAINT plg_crm_activities_unit_fk
|
|
30391
|
+
FOREIGN KEY (tenant_id, unit_id) REFERENCES app.units(tenant_id, id) ON DELETE SET NULL;
|
|
30392
|
+
|
|
30393
|
+
-- (tenant, unit) in the order the query asks: the policy filters the tenant
|
|
30394
|
+
-- first, and that prefix is what keeps the predicate out of a row-by-row loop.
|
|
30395
|
+
CREATE INDEX IF NOT EXISTS plg_crm_companies_unit_idx
|
|
30396
|
+
ON public.plg_crm_companies (tenant_id, unit_id);
|
|
30397
|
+
CREATE INDEX IF NOT EXISTS plg_crm_activities_unit_idx
|
|
30398
|
+
ON public.plg_crm_activities (tenant_id, unit_id);
|
|
30399
|
+
|
|
30400
|
+
-- \u2500\u2500 the activity inherits the unit of what it reports \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
30401
|
+
--
|
|
30402
|
+
-- A loose activity (no deal, no lead) stays null: inventing its branch would
|
|
30403
|
+
-- hide somebody's phone call on a guess.
|
|
30404
|
+
UPDATE public.plg_crm_activities a
|
|
30405
|
+
SET unit_id = d.unit_id
|
|
30406
|
+
FROM public.plg_crm_deals d
|
|
30407
|
+
WHERE a.unit_id IS NULL AND a.deal_id = d.id AND d.unit_id IS NOT NULL;
|
|
30408
|
+
|
|
30409
|
+
UPDATE public.plg_crm_activities a
|
|
30410
|
+
SET unit_id = p.unit_id
|
|
30411
|
+
FROM public.people p
|
|
30412
|
+
WHERE a.unit_id IS NULL AND a.deal_id IS NULL
|
|
30413
|
+
AND a.lead_id = p.id AND p.unit_id IS NOT NULL;
|
|
30414
|
+
|
|
30415
|
+
-- \u2500\u2500 the fence \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
|
|
30416
|
+
--
|
|
30417
|
+
-- Same shape as the deal's policy (052): null passes, a unit asks
|
|
30418
|
+
-- \`app.has_unit\`. Additive \u2014 no row that was readable stops being readable.
|
|
30419
|
+
--
|
|
30420
|
+
-- The verb does not change here. Company stays on \`sales.read\`, activity stays
|
|
30421
|
+
-- on the tenant cut 012 wrote: widening permission and unit in one migration
|
|
30422
|
+
-- would be two changes with one test.
|
|
30423
|
+
|
|
30424
|
+
DROP POLICY IF EXISTS plg_crm_companies_authz_select ON public.plg_crm_companies;
|
|
30425
|
+
CREATE POLICY plg_crm_companies_authz_select ON public.plg_crm_companies
|
|
30426
|
+
FOR SELECT TO authenticated USING (
|
|
30427
|
+
tenant_id = (SELECT app.current_tenant_id())
|
|
30428
|
+
AND (unit_id IS NULL OR (SELECT app.has_unit(plg_crm_companies.unit_id)))
|
|
30429
|
+
AND (SELECT app.has_permission('sales.read', NULL::uuid)));
|
|
30430
|
+
|
|
30431
|
+
DROP POLICY IF EXISTS plg_crm_activities_select ON public.plg_crm_activities;
|
|
30432
|
+
CREATE POLICY plg_crm_activities_select ON public.plg_crm_activities
|
|
30433
|
+
FOR SELECT TO authenticated USING (
|
|
30434
|
+
tenant_id IN (SELECT user_tenant_ids())
|
|
30435
|
+
AND (unit_id IS NULL OR (SELECT app.has_unit(plg_crm_activities.unit_id))));
|
|
30436
|
+
|
|
30437
|
+
-- \u2500\u2500 the column reaches the view \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
|
|
30438
|
+
--
|
|
30439
|
+
-- Columns below are what 058 (v_deals), 054 (v_crm_leads) and 059
|
|
30440
|
+
-- (v_crm_companies_enriched) left, in the same order, plus \`unit_id\`.
|
|
30441
|
+
|
|
30442
|
+
CREATE OR REPLACE VIEW public.v_deals WITH (security_invoker = true) AS
|
|
30443
|
+
SELECT d.id,
|
|
30444
|
+
d.tenant_id,
|
|
30445
|
+
d.status,
|
|
30446
|
+
d.value,
|
|
30447
|
+
COALESCE(d.title, d.notes) AS title,
|
|
30448
|
+
d.contact_id,
|
|
30449
|
+
d.assigned_to_id,
|
|
30450
|
+
d.tags,
|
|
30451
|
+
COALESCE(pc.name, d.metadata ->> 'contactName'::text) AS contact_name,
|
|
30452
|
+
d.created_at,
|
|
30453
|
+
d.updated_at,
|
|
30454
|
+
d.pipeline_id,
|
|
30455
|
+
d.stage_id,
|
|
30456
|
+
d.probability,
|
|
30457
|
+
d.expected_close_date,
|
|
30458
|
+
d.lead_id,
|
|
30459
|
+
d.lost_reason,
|
|
30460
|
+
ps.name AS stage_name,
|
|
30461
|
+
ps.color AS stage_color,
|
|
30462
|
+
ps."order" AS stage_order,
|
|
30463
|
+
ps.name AS stage,
|
|
30464
|
+
d.won_at,
|
|
30465
|
+
d.lost_at,
|
|
30466
|
+
d.company_id,
|
|
30467
|
+
d.contact_status,
|
|
30468
|
+
d.contact_status_at,
|
|
30469
|
+
cs.name AS contact_status_name,
|
|
30470
|
+
cs.color AS contact_status_color,
|
|
30471
|
+
d.notes,
|
|
30472
|
+
cs.derived_from AS contact_status_derived_from,
|
|
30473
|
+
emp.name AS company_name,
|
|
30474
|
+
emp.document_number AS company_document,
|
|
30475
|
+
grp.group_id,
|
|
30476
|
+
grp.group_name,
|
|
30477
|
+
grp.group_companies,
|
|
30478
|
+
-- On the table since 052 and never here, so the board had no way to narrow
|
|
30479
|
+
-- without a second query per card.
|
|
30480
|
+
d.unit_id
|
|
30481
|
+
FROM plg_crm_deals d
|
|
30482
|
+
LEFT JOIN plg_crm_companies emp ON emp.id = d.company_id
|
|
30483
|
+
LEFT JOIN people pc ON pc.id = d.contact_id
|
|
30484
|
+
LEFT JOIN plg_crm_pipeline_stages ps ON ps.id = d.stage_id
|
|
30485
|
+
LEFT JOIN LATERAL ( SELECT s.name,
|
|
30486
|
+
s.color,
|
|
30487
|
+
s.derived_from
|
|
30488
|
+
FROM plg_crm_deal_statuses s
|
|
30489
|
+
WHERE s.tenant_id = d.tenant_id AND s.key = d.contact_status AND (s.stage_id IS NULL OR s.stage_id = d.stage_id)
|
|
30490
|
+
ORDER BY (s.stage_id IS NOT NULL) DESC
|
|
30491
|
+
LIMIT 1) cs ON true
|
|
30492
|
+
LEFT JOIN LATERAL ( SELECT g.id AS group_id,
|
|
30493
|
+
g.name AS group_name,
|
|
30494
|
+
( SELECT count(*)::integer AS count
|
|
30495
|
+
FROM plg_crm_company_group_members m2
|
|
30496
|
+
WHERE m2.group_id = g.id) AS group_companies
|
|
30497
|
+
FROM plg_crm_company_group_members m
|
|
30498
|
+
JOIN plg_crm_company_groups g ON g.id = m.group_id
|
|
30499
|
+
WHERE m.company_id = d.company_id AND m.tenant_id = d.tenant_id AND g.is_active
|
|
30500
|
+
ORDER BY m.created_at, m.id
|
|
30501
|
+
LIMIT 1) grp ON true;
|
|
30502
|
+
|
|
30503
|
+
GRANT SELECT ON public.v_deals TO authenticated, service_role;
|
|
30504
|
+
|
|
30505
|
+
CREATE OR REPLACE VIEW public.v_crm_leads WITH (security_invoker = true) AS
|
|
30506
|
+
SELECT l.id,
|
|
30507
|
+
l.tenant_id,
|
|
30508
|
+
l.name,
|
|
30509
|
+
l.email,
|
|
30510
|
+
l.phone,
|
|
30511
|
+
l.notes,
|
|
30512
|
+
l.tags,
|
|
30513
|
+
l.is_active,
|
|
30514
|
+
l.company,
|
|
30515
|
+
l.source_id,
|
|
30516
|
+
l.source_name,
|
|
30517
|
+
l.lead_status,
|
|
30518
|
+
l.lead_value,
|
|
30519
|
+
l.assigned_to_id,
|
|
30520
|
+
l.created_at,
|
|
30521
|
+
l.updated_at,
|
|
30522
|
+
l.form_id,
|
|
30523
|
+
l.custom_fields,
|
|
30524
|
+
l.utm,
|
|
30525
|
+
l.status,
|
|
30526
|
+
l.attachments,
|
|
30527
|
+
cp.company_id,
|
|
30528
|
+
cp.role AS company_role,
|
|
30529
|
+
c.name AS company_name,
|
|
30530
|
+
c.legal_name AS company_legal_name,
|
|
30531
|
+
c.document_number AS company_document,
|
|
30532
|
+
pess.instagram,
|
|
30533
|
+
pess.metadata ->> 'credential_company'::text AS credential_company,
|
|
30534
|
+
pess.metadata ->> 'phone_raw'::text AS phone_raw,
|
|
30535
|
+
pess.city,
|
|
30536
|
+
pess.state,
|
|
30537
|
+
-- From \`people\`, not \`v_leads\`: the spine's view does not expose it and is
|
|
30538
|
+
-- not this plugin's to widen \u2014 the reason 013 wrapped it instead.
|
|
30539
|
+
pess.unit_id
|
|
30540
|
+
FROM v_leads l
|
|
30541
|
+
LEFT JOIN people pess ON pess.id = l.id
|
|
30542
|
+
LEFT JOIN LATERAL ( SELECT x.company_id,
|
|
30543
|
+
x.role
|
|
30544
|
+
FROM plg_crm_company_people x
|
|
30545
|
+
WHERE x.person_id = l.id
|
|
30546
|
+
ORDER BY x.is_primary DESC, x.created_at
|
|
30547
|
+
LIMIT 1) cp ON true
|
|
30548
|
+
LEFT JOIN plg_crm_companies c ON c.id = cp.company_id;
|
|
30549
|
+
|
|
30550
|
+
GRANT SELECT ON public.v_crm_leads TO authenticated, service_role;
|
|
30551
|
+
|
|
30552
|
+
CREATE OR REPLACE VIEW public.v_crm_companies_enriched WITH (security_invoker = true) AS
|
|
30553
|
+
SELECT c.id,
|
|
30554
|
+
c.tenant_id,
|
|
30555
|
+
c.name,
|
|
30556
|
+
c.legal_name,
|
|
30557
|
+
c.document_number,
|
|
30558
|
+
c.document_kind,
|
|
30559
|
+
c.document_root,
|
|
30560
|
+
c.document_valid,
|
|
30561
|
+
c.email,
|
|
30562
|
+
c.phone,
|
|
30563
|
+
c.website,
|
|
30564
|
+
c.address,
|
|
30565
|
+
c.city,
|
|
30566
|
+
c.state,
|
|
30567
|
+
c.country,
|
|
30568
|
+
c.postal_code,
|
|
30569
|
+
c.tags,
|
|
30570
|
+
c.notes,
|
|
30571
|
+
c.metadata,
|
|
30572
|
+
c.custom_fields,
|
|
30573
|
+
c.owner_id,
|
|
30574
|
+
c.is_active,
|
|
30575
|
+
c.created_at,
|
|
30576
|
+
c.updated_at,
|
|
30577
|
+
COALESCE(p.people_count, 0) AS people_count,
|
|
30578
|
+
COALESCE(d.open_deals, 0) AS open_deals,
|
|
30579
|
+
COALESCE(d.won_value, 0::numeric) AS won_value,
|
|
30580
|
+
CASE
|
|
30581
|
+
WHEN c.document_root IS NULL THEN 0
|
|
30582
|
+
ELSE COALESCE(g.group_size, 1) - 1
|
|
30583
|
+
END AS group_siblings,
|
|
30584
|
+
c.instagram,
|
|
30585
|
+
c.unit_id
|
|
30586
|
+
FROM plg_crm_companies c
|
|
30587
|
+
LEFT JOIN LATERAL ( SELECT count(*)::integer AS people_count
|
|
30588
|
+
FROM plg_crm_company_people cp
|
|
30589
|
+
JOIN people pe ON pe.id = cp.person_id
|
|
30590
|
+
WHERE cp.company_id = c.id) p ON true
|
|
30591
|
+
LEFT JOIN LATERAL ( SELECT count(*) FILTER (WHERE dl.status = 'open'::text)::integer AS open_deals,
|
|
30592
|
+
COALESCE(sum(dl.value) FILTER (WHERE dl.status = 'won'::text), 0::numeric) AS won_value
|
|
30593
|
+
FROM plg_crm_deals dl
|
|
30594
|
+
WHERE dl.company_id = c.id) d ON true
|
|
30595
|
+
LEFT JOIN LATERAL ( SELECT count(*)::integer AS group_size
|
|
30596
|
+
FROM plg_crm_companies s
|
|
30597
|
+
WHERE s.tenant_id = c.tenant_id AND s.document_root = c.document_root) g ON true;
|
|
30598
|
+
|
|
30599
|
+
GRANT SELECT ON public.v_crm_companies_enriched TO authenticated, service_role;
|
|
30600
|
+
|
|
30601
|
+
-- \u2500\u2500 the row the visibility screen reads \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
|
|
30602
|
+
--
|
|
30603
|
+
-- \`shareable\` on both: a book of business and a funnel cross branches on
|
|
30604
|
+
-- purpose. \`default_visibility\` is what the screen OFFERS on create \u2014 unit for
|
|
30605
|
+
-- the deal, which is born where somebody is selling; the whole tenant for the
|
|
30606
|
+
-- company, which is the same chain for both brands.
|
|
30607
|
+
INSERT INTO public.scoped_resources (resource_table, unit_column, owner_column, shareable, default_visibility, label)
|
|
30608
|
+
VALUES
|
|
30609
|
+
('plg_crm_deals', 'unit_id', 'owner_id', true, 'unit', 'Neg\xF3cios'),
|
|
30610
|
+
('plg_crm_companies', 'unit_id', 'owner_id', true, 'tenant', 'Empresas')
|
|
30611
|
+
ON CONFLICT (resource_table) DO UPDATE
|
|
30612
|
+
SET unit_column = EXCLUDED.unit_column,
|
|
30613
|
+
owner_column = EXCLUDED.owner_column,
|
|
30614
|
+
shareable = EXCLUDED.shareable,
|
|
30615
|
+
default_visibility = EXCLUDED.default_visibility,
|
|
30616
|
+
label = EXCLUDED.label;
|
|
30617
|
+
`;
|
|
30235
30618
|
var MIGRATIONS = [
|
|
30236
30619
|
{ id: "000_baseline", sql: MIGRATION_000_BASELINE },
|
|
30237
30620
|
{ id: "001_de_onde_veio_e_quem_indicou", sql: MIGRATION_001_DE_ONDE_VEIO_E_QUEM_INDICOU },
|
|
@@ -30293,7 +30676,8 @@ var MIGRATIONS = [
|
|
|
30293
30676
|
{ id: "058_o_card_diz_o_nome_do_grupo", sql: MIGRATION_058_O_CARD_DIZ_O_NOME_DO_GRUPO },
|
|
30294
30677
|
{ id: "059_a_empresa_mostra_o_instagram_que_ela_guarda", sql: MIGRATION_059_A_EMPRESA_MOSTRA_O_INSTAGRAM_QUE_ELA_GUARDA },
|
|
30295
30678
|
{ 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 }
|
|
30679
|
+
{ id: "061_a_conversao_respeita_o_filtro_do_quadro", sql: MIGRATION_061_A_CONVERSAO_RESPEITA_O_FILTRO_DO_QUADRO },
|
|
30680
|
+
{ id: "062_the_whole_crm_says_which_unit_it_is", sql: MIGRATION_062_THE_WHOLE_CRM_SAYS_WHICH_UNIT_IT_IS }
|
|
30297
30681
|
];
|
|
30298
30682
|
|
|
30299
30683
|
// src/locales/en.ts
|
|
@@ -32186,15 +32570,15 @@ var crmLocales = {
|
|
|
32186
32570
|
var EMPTY_RULE = { column: "kind", op: "=", value: "lead" };
|
|
32187
32571
|
function SegmentEditorDialog({ open, segment, provider, onClose, onSaved }) {
|
|
32188
32572
|
const t2 = useTranslation();
|
|
32189
|
-
const [name, setName] =
|
|
32190
|
-
const [description, setDescription] =
|
|
32191
|
-
const [isActive, setIsActive] =
|
|
32192
|
-
const [rules, setRules] =
|
|
32193
|
-
const [saving, setSaving] =
|
|
32194
|
-
const [error, setError] =
|
|
32195
|
-
const [preview, setPreview] =
|
|
32196
|
-
const [previewing, setPreviewing] =
|
|
32197
|
-
|
|
32573
|
+
const [name, setName] = React__default.useState("");
|
|
32574
|
+
const [description, setDescription] = React__default.useState("");
|
|
32575
|
+
const [isActive, setIsActive] = React__default.useState(true);
|
|
32576
|
+
const [rules, setRules] = React__default.useState([EMPTY_RULE]);
|
|
32577
|
+
const [saving, setSaving] = React__default.useState(false);
|
|
32578
|
+
const [error, setError] = React__default.useState(null);
|
|
32579
|
+
const [preview, setPreview] = React__default.useState(null);
|
|
32580
|
+
const [previewing, setPreviewing] = React__default.useState(false);
|
|
32581
|
+
React__default.useEffect(() => {
|
|
32198
32582
|
if (!open) return;
|
|
32199
32583
|
setName(segment?.name ?? "");
|
|
32200
32584
|
setDescription(segment?.description ?? "");
|
|
@@ -32393,11 +32777,11 @@ function SegmentsView() {
|
|
|
32393
32777
|
const can = usePermissionOptional();
|
|
32394
32778
|
const canEdit = can("sales", "edit");
|
|
32395
32779
|
const canDelete = can("sales", "delete");
|
|
32396
|
-
const [segments, setSegments] =
|
|
32397
|
-
const [counts, setCounts] =
|
|
32398
|
-
const [editing, setEditing] =
|
|
32399
|
-
const [removing, setRemoving] =
|
|
32400
|
-
const load =
|
|
32780
|
+
const [segments, setSegments] = React__default.useState(null);
|
|
32781
|
+
const [counts, setCounts] = React__default.useState({});
|
|
32782
|
+
const [editing, setEditing] = React__default.useState(void 0);
|
|
32783
|
+
const [removing, setRemoving] = React__default.useState(null);
|
|
32784
|
+
const load = React__default.useCallback(async () => {
|
|
32401
32785
|
const list = await provider.getSegments();
|
|
32402
32786
|
setSegments(list);
|
|
32403
32787
|
try {
|
|
@@ -32407,7 +32791,7 @@ function SegmentsView() {
|
|
|
32407
32791
|
setCounts({});
|
|
32408
32792
|
}
|
|
32409
32793
|
}, [provider]);
|
|
32410
|
-
|
|
32794
|
+
React__default.useEffect(() => {
|
|
32411
32795
|
void load();
|
|
32412
32796
|
}, [load]);
|
|
32413
32797
|
async function toggleActive(segment, next) {
|
|
@@ -32793,7 +33177,7 @@ function createCrmPlugin(options) {
|
|
|
32793
33177
|
() => createMockCrmProvider({ activityTypes })
|
|
32794
33178
|
);
|
|
32795
33179
|
const store = createCrmStore(provider);
|
|
32796
|
-
const PageComponent = () =>
|
|
33180
|
+
const PageComponent = () => React__default.createElement(CrmPage, { config, provider, store, registries: crmRegistries2 });
|
|
32797
33181
|
const dashboardWidgets = createCrmDashboardWidgets({ config, provider, store });
|
|
32798
33182
|
const vocab = customerVocabulary(options?.tenantVerticalId);
|
|
32799
33183
|
const customerOne = config.labels.customersSingular ?? vocab.one;
|
|
@@ -33316,12 +33700,12 @@ function createCrmPlugin(options) {
|
|
|
33316
33700
|
label: "Sales & CRM",
|
|
33317
33701
|
icon: "Filter",
|
|
33318
33702
|
component: (() => {
|
|
33319
|
-
const Tab = () =>
|
|
33703
|
+
const Tab = () => React__default.createElement(
|
|
33320
33704
|
CrmContextProvider,
|
|
33321
33705
|
{ config, provider, store },
|
|
33322
|
-
|
|
33706
|
+
React__default.createElement(PluginSettingsPanel, {
|
|
33323
33707
|
title: "Sales & CRM",
|
|
33324
|
-
generalSettings:
|
|
33708
|
+
generalSettings: React__default.createElement(CrmGeneralSettings),
|
|
33325
33709
|
// Segmento é CADASTRO, e mora onde os outros moram. Etapas do
|
|
33326
33710
|
// funil, origens, parcerias e tags já estão aqui; ter o recorte
|
|
33327
33711
|
// fora, no rail de trabalho diário, era a inconsistência.
|
|
@@ -33329,7 +33713,7 @@ function createCrmPlugin(options) {
|
|
|
33329
33713
|
id: "segments",
|
|
33330
33714
|
label: "Segmentos",
|
|
33331
33715
|
icon: "Filter",
|
|
33332
|
-
content:
|
|
33716
|
+
content: React__default.createElement(SegmentsView)
|
|
33333
33717
|
}],
|
|
33334
33718
|
registries: crmRegistries2,
|
|
33335
33719
|
hostPluginId: "crm",
|
|
@@ -33362,6 +33746,6 @@ function createCrmPlugin(options) {
|
|
|
33362
33746
|
};
|
|
33363
33747
|
}
|
|
33364
33748
|
|
|
33365
|
-
export { TagChips, buildCrmDomainEvents, buildCrmMessageDefaults, createCrmPlugin, humanizeTag };
|
|
33749
|
+
export { TagChips, buildCrmCustomerEntity, buildCrmDomainEvents, buildCrmMessageDefaults, createCrmPlugin, customerVocabulary, humanizeTag };
|
|
33366
33750
|
//# sourceMappingURL=index.js.map
|
|
33367
33751
|
//# sourceMappingURL=index.js.map
|