@fayz-ai/plugin-crm 0.27.1 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +109 -57
- package/dist/index.js.map +1 -1
- package/dist/views/DealListView.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1472,6 +1472,41 @@ function evaluateSegment(segment, rows, nowMs = Date.now()) {
|
|
|
1472
1472
|
const where = segment.rules?.where ?? [];
|
|
1473
1473
|
return rows.filter((r) => where.every((rule) => matches(r, rule, nowMs))).map((r) => r.id);
|
|
1474
1474
|
}
|
|
1475
|
+
async function loadTeam() {
|
|
1476
|
+
const supabase = getSupabaseClientOptional();
|
|
1477
|
+
if (!supabase) return [];
|
|
1478
|
+
const { data: memberships, error } = await supabase.from("v_authz_memberships").select("user_id, person_id").eq("active", true);
|
|
1479
|
+
if (error) throw new Error(error.message);
|
|
1480
|
+
const rows = memberships ?? [];
|
|
1481
|
+
if (rows.length === 0) return [];
|
|
1482
|
+
const { data: people } = await supabase.from("people").select("id, name").in("id", rows.map((r) => r.person_id));
|
|
1483
|
+
const nameById = new Map(
|
|
1484
|
+
(people ?? []).map((p) => [p.id, p.name ?? ""])
|
|
1485
|
+
);
|
|
1486
|
+
const porUsuario = /* @__PURE__ */ new Map();
|
|
1487
|
+
for (const r of rows) {
|
|
1488
|
+
if (porUsuario.has(r.user_id)) continue;
|
|
1489
|
+
porUsuario.set(r.user_id, { userId: r.user_id, name: nameById.get(r.person_id) || r.user_id.slice(0, 8) });
|
|
1490
|
+
}
|
|
1491
|
+
return [...porUsuario.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
1492
|
+
}
|
|
1493
|
+
async function loadTeamOrNull() {
|
|
1494
|
+
try {
|
|
1495
|
+
return await loadTeam();
|
|
1496
|
+
} catch {
|
|
1497
|
+
return null;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
async function loadMyUserId() {
|
|
1501
|
+
const supabase = getSupabaseClientOptional();
|
|
1502
|
+
if (!supabase) return null;
|
|
1503
|
+
try {
|
|
1504
|
+
const { data } = await supabase.auth.getUser();
|
|
1505
|
+
return data?.user?.id ?? null;
|
|
1506
|
+
} catch {
|
|
1507
|
+
return null;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1475
1510
|
var LOAD_CAP = 1e3;
|
|
1476
1511
|
var PAGE_SIZE = 50;
|
|
1477
1512
|
function ageInDays(iso) {
|
|
@@ -1508,14 +1543,21 @@ function DealListView({ onOpenDeal }) {
|
|
|
1508
1543
|
const tagDefs = useCrmStore((s) => s.tagDefs);
|
|
1509
1544
|
const fetchTagDefs = useCrmStore((s) => s.fetchTagDefs);
|
|
1510
1545
|
const [search, setSearch] = usePersistedState("crm.deals.search", "");
|
|
1511
|
-
const [stage, setStage] =
|
|
1512
|
-
const [status, setStatus] =
|
|
1513
|
-
const [cohort, setCohort] =
|
|
1514
|
-
const [city, setCity] =
|
|
1515
|
-
const [companyName, setCompanyName] =
|
|
1546
|
+
const [stage, setStage] = usePersistedState("crm.deals.stage", void 0);
|
|
1547
|
+
const [status, setStatus] = usePersistedState("crm.deals.status", void 0);
|
|
1548
|
+
const [cohort, setCohort] = usePersistedState("crm.deals.cohort", void 0);
|
|
1549
|
+
const [city, setCity] = usePersistedState("crm.deals.city", void 0);
|
|
1550
|
+
const [companyName, setCompanyName] = usePersistedState("crm.deals.company", void 0);
|
|
1551
|
+
const [owner, setOwner] = usePersistedState("crm.deals.owner", void 0);
|
|
1516
1552
|
const [page, setPage] = usePersistedState("crm.deals.page", 1);
|
|
1517
1553
|
const [segmentOpen, setSegmentOpen] = useState(false);
|
|
1518
|
-
const [
|
|
1554
|
+
const [tags, setTags] = usePersistedState("crm.deals.tags", []);
|
|
1555
|
+
const [team, setTeam] = useState(null);
|
|
1556
|
+
const [myUserId, setMyUserId] = useState();
|
|
1557
|
+
useEffect(() => {
|
|
1558
|
+
void loadTeamOrNull().then(setTeam);
|
|
1559
|
+
void loadMyUserId().then((id) => setMyUserId(id ?? void 0));
|
|
1560
|
+
}, []);
|
|
1519
1561
|
useEffect(() => {
|
|
1520
1562
|
void fetchTagDefs();
|
|
1521
1563
|
}, []);
|
|
@@ -1539,10 +1581,23 @@ function DealListView({ onOpenDeal }) {
|
|
|
1539
1581
|
() => optionsFrom(deals.map((d) => d.companyName)),
|
|
1540
1582
|
[deals]
|
|
1541
1583
|
);
|
|
1542
|
-
const tagOptions = useMemo(
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1584
|
+
const tagOptions = useMemo(() => {
|
|
1585
|
+
const doCadastro = [...tagDefs.values()].map((d) => ({ value: d.slug, label: d.name ?? d.slug, color: d.color }));
|
|
1586
|
+
if (doCadastro.length) return doCadastro;
|
|
1587
|
+
return optionsFrom(deals.flatMap((d) => d.tags), (slug) => tagDefs.get(slug)?.name ?? humanizeTag(slug));
|
|
1588
|
+
}, [deals, tagDefs]);
|
|
1589
|
+
const ownerOptions = useMemo(() => {
|
|
1590
|
+
const vistos = /* @__PURE__ */ new Map();
|
|
1591
|
+
for (const m of team ?? []) vistos.set(m.userId, m.name);
|
|
1592
|
+
if (!team) {
|
|
1593
|
+
for (const d of deals) if (d.assignedToId) vistos.set(d.assignedToId, d.assignedToName ?? d.assignedToId);
|
|
1594
|
+
}
|
|
1595
|
+
return [
|
|
1596
|
+
...myUserId && vistos.has(myUserId) ? [{ value: myUserId, label: t2("crm.leads.filters.mine") }] : [],
|
|
1597
|
+
{ value: "none", label: t2("crm.leads.filters.unassigned") },
|
|
1598
|
+
...[...vistos].filter(([id]) => id !== myUserId).map(([id, nome]) => ({ value: id, label: nome }))
|
|
1599
|
+
];
|
|
1600
|
+
}, [team, deals, myUserId, t2]);
|
|
1546
1601
|
const cohortOptions = useMemo(() => {
|
|
1547
1602
|
const seen = /* @__PURE__ */ new Map();
|
|
1548
1603
|
for (const d of deals) {
|
|
@@ -1553,7 +1608,7 @@ function DealListView({ onOpenDeal }) {
|
|
|
1553
1608
|
}, [deals, currency.locale]);
|
|
1554
1609
|
useEffect(() => {
|
|
1555
1610
|
setPage(1);
|
|
1556
|
-
}, [search, stage, status, city,
|
|
1611
|
+
}, [search, stage, status, city, tags, cohort, companyName, owner]);
|
|
1557
1612
|
const query = useMemo(() => prepareDealQuery(search), [search]);
|
|
1558
1613
|
const rows = useMemo(() => {
|
|
1559
1614
|
return deals.filter((d) => {
|
|
@@ -1561,12 +1616,14 @@ function DealListView({ onOpenDeal }) {
|
|
|
1561
1616
|
if (status && d.contactStatusName !== status) return false;
|
|
1562
1617
|
if (city && (d.contactCity ?? "") !== city) return false;
|
|
1563
1618
|
if (companyName && (d.companyName ?? "") !== companyName) return false;
|
|
1564
|
-
if (
|
|
1619
|
+
if (tags.length && !tags.some((x) => d.tags.includes(x))) return false;
|
|
1565
1620
|
if (cohort && cohortOf(d.createdAt, currency.locale)?.key !== cohort) return false;
|
|
1621
|
+
if (owner === "none" && d.assignedToId) return false;
|
|
1622
|
+
if (owner && owner !== "none" && d.assignedToId !== owner) return false;
|
|
1566
1623
|
if (!query) return true;
|
|
1567
1624
|
return dealMatches(d, query, tagDefs);
|
|
1568
1625
|
});
|
|
1569
|
-
}, [deals, query, stage, status, city,
|
|
1626
|
+
}, [deals, query, stage, status, city, tags, cohort, companyName, owner, tagDefs, currency.locale]);
|
|
1570
1627
|
const columns = useMemo(() => [
|
|
1571
1628
|
{
|
|
1572
1629
|
accessorKey: "title",
|
|
@@ -1656,15 +1713,25 @@ function DealListView({ onOpenDeal }) {
|
|
|
1656
1713
|
const segmentRules = useMemo(() => {
|
|
1657
1714
|
const out = [];
|
|
1658
1715
|
if (city) out.push({ column: "city", op: "=", value: city });
|
|
1659
|
-
|
|
1716
|
+
for (const x of tags) out.push({ column: "tags", op: "has_tag", value: x });
|
|
1660
1717
|
return out;
|
|
1661
|
-
}, [city,
|
|
1718
|
+
}, [city, tags]);
|
|
1662
1719
|
const droppedFilters = [
|
|
1663
1720
|
stage && t2("crm.dealSidebar.stage"),
|
|
1664
1721
|
status && t2("crm.deals.colStatus"),
|
|
1665
1722
|
cohort && t2("crm.deals.cohort"),
|
|
1666
1723
|
companyName && t2("crm.card.companyTitle")
|
|
1667
1724
|
].filter(Boolean);
|
|
1725
|
+
const filtrosAtivos = (stage ? 1 : 0) + (status ? 1 : 0) + (cohort ? 1 : 0) + (city ? 1 : 0) + (companyName ? 1 : 0) + (tags.length ? 1 : 0) + (owner ? 1 : 0);
|
|
1726
|
+
const limparFiltros = () => {
|
|
1727
|
+
setStage(void 0);
|
|
1728
|
+
setStatus(void 0);
|
|
1729
|
+
setCohort(void 0);
|
|
1730
|
+
setCity(void 0);
|
|
1731
|
+
setCompanyName(void 0);
|
|
1732
|
+
setTags([]);
|
|
1733
|
+
setOwner(void 0);
|
|
1734
|
+
};
|
|
1668
1735
|
const ancoraRolagem = useScrollMemory("crm.deals");
|
|
1669
1736
|
return /* @__PURE__ */ jsxs("div", { ref: ancoraRolagem, className: "space-y-3", children: [
|
|
1670
1737
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
@@ -1760,14 +1827,27 @@ function DealListView({ onOpenDeal }) {
|
|
|
1760
1827
|
}
|
|
1761
1828
|
),
|
|
1762
1829
|
tagOptions.length > 0 && /* @__PURE__ */ jsx(
|
|
1763
|
-
|
|
1830
|
+
MultiSelect,
|
|
1764
1831
|
{
|
|
1765
|
-
|
|
1832
|
+
variant: "chip",
|
|
1766
1833
|
icon: Tag,
|
|
1767
|
-
allLabel: t2("crm.deals.allCampaigns"),
|
|
1768
1834
|
options: tagOptions,
|
|
1769
|
-
value:
|
|
1770
|
-
onChange:
|
|
1835
|
+
value: tags,
|
|
1836
|
+
onChange: setTags,
|
|
1837
|
+
allLabel: t2("crm.leads.filters.allTags"),
|
|
1838
|
+
searchPlaceholder: t2("crm.leads.filters.searchTag"),
|
|
1839
|
+
emptyLabel: t2("crm.leads.filters.noTag")
|
|
1840
|
+
}
|
|
1841
|
+
),
|
|
1842
|
+
ownerOptions.length > 1 && /* @__PURE__ */ jsx(
|
|
1843
|
+
FilterChip,
|
|
1844
|
+
{
|
|
1845
|
+
label: t2("crm.leads.filters.owner"),
|
|
1846
|
+
icon: User,
|
|
1847
|
+
allLabel: t2("crm.leads.filters.allOwners"),
|
|
1848
|
+
options: ownerOptions,
|
|
1849
|
+
value: owner,
|
|
1850
|
+
onChange: setOwner
|
|
1771
1851
|
}
|
|
1772
1852
|
),
|
|
1773
1853
|
companyOptions.length > 0 && /* @__PURE__ */ jsx(
|
|
@@ -1791,7 +1871,14 @@ function DealListView({ onOpenDeal }) {
|
|
|
1791
1871
|
value: city,
|
|
1792
1872
|
onChange: setCity
|
|
1793
1873
|
}
|
|
1794
|
-
)
|
|
1874
|
+
),
|
|
1875
|
+
filtrosAtivos > 0 && /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", onClick: limparFiltros, className: "h-8 gap-1 px-2 text-xs", children: [
|
|
1876
|
+
/* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }),
|
|
1877
|
+
t2("crm.leads.filters.clear"),
|
|
1878
|
+
" (",
|
|
1879
|
+
filtrosAtivos,
|
|
1880
|
+
")"
|
|
1881
|
+
] })
|
|
1795
1882
|
] })
|
|
1796
1883
|
] }),
|
|
1797
1884
|
/* @__PURE__ */ jsx(
|
|
@@ -1850,7 +1937,7 @@ function DealListView({ onOpenDeal }) {
|
|
|
1850
1937
|
onClose: () => setSegmentOpen(false),
|
|
1851
1938
|
rules: segmentRules,
|
|
1852
1939
|
dropped: droppedFilters,
|
|
1853
|
-
suggestedName: [city,
|
|
1940
|
+
suggestedName: [city, ...tags.map((x) => tagDefs.get(x)?.name ?? humanizeTag(x))].filter(Boolean).join(" \xB7 ")
|
|
1854
1941
|
}
|
|
1855
1942
|
)
|
|
1856
1943
|
] });
|
|
@@ -2503,41 +2590,6 @@ function PartnerOnlineBookingCell({ value }) {
|
|
|
2503
2590
|
const t2 = useTranslation();
|
|
2504
2591
|
return value ? /* @__PURE__ */ jsx(Badge, { children: t2("common.yes") }) : /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: t2("common.no") });
|
|
2505
2592
|
}
|
|
2506
|
-
async function loadTeam() {
|
|
2507
|
-
const supabase = getSupabaseClientOptional();
|
|
2508
|
-
if (!supabase) return [];
|
|
2509
|
-
const { data: memberships, error } = await supabase.from("v_authz_memberships").select("user_id, person_id").eq("active", true);
|
|
2510
|
-
if (error) throw new Error(error.message);
|
|
2511
|
-
const rows = memberships ?? [];
|
|
2512
|
-
if (rows.length === 0) return [];
|
|
2513
|
-
const { data: people } = await supabase.from("people").select("id, name").in("id", rows.map((r) => r.person_id));
|
|
2514
|
-
const nameById = new Map(
|
|
2515
|
-
(people ?? []).map((p) => [p.id, p.name ?? ""])
|
|
2516
|
-
);
|
|
2517
|
-
const porUsuario = /* @__PURE__ */ new Map();
|
|
2518
|
-
for (const r of rows) {
|
|
2519
|
-
if (porUsuario.has(r.user_id)) continue;
|
|
2520
|
-
porUsuario.set(r.user_id, { userId: r.user_id, name: nameById.get(r.person_id) || r.user_id.slice(0, 8) });
|
|
2521
|
-
}
|
|
2522
|
-
return [...porUsuario.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
2523
|
-
}
|
|
2524
|
-
async function loadTeamOrNull() {
|
|
2525
|
-
try {
|
|
2526
|
-
return await loadTeam();
|
|
2527
|
-
} catch {
|
|
2528
|
-
return null;
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
async function loadMyUserId() {
|
|
2532
|
-
const supabase = getSupabaseClientOptional();
|
|
2533
|
-
if (!supabase) return null;
|
|
2534
|
-
try {
|
|
2535
|
-
const { data } = await supabase.auth.getUser();
|
|
2536
|
-
return data?.user?.id ?? null;
|
|
2537
|
-
} catch {
|
|
2538
|
-
return null;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
2593
|
var loadMembers = loadTeam;
|
|
2542
2594
|
function AssigneeRotaInput({ value, onChange }) {
|
|
2543
2595
|
const t2 = useTranslation();
|