@fayz-ai/plugin-crm 0.33.4 → 0.35.0

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.
@@ -1,11 +1,11 @@
1
- import { loadTeamOrNull, loadMyUserId, DotChip, AssigneeName, formatDocument, humanizeTag, DEFAULT_ACTIVITY_TYPES, TagChips, localPhoneKey, normalizeDocument, isValidDocument } from './chunk-LDBCC67C.js';
1
+ import { loadTeamOrNull, loadMyUserId, DotChip, AssigneeName, formatDocument, humanizeTag, DEFAULT_ACTIVITY_TYPES, localPhoneKey, normalizeDocument, TagChips, isValidDocument } from './chunk-LDBCC67C.js';
2
2
  import { CrmGeneralSettings } from './chunk-CA24LK57.js';
3
3
  import { resolveSourceView } from './chunk-QJOLAGGN.js';
4
4
  import { CrmContextProvider, useCrmProvider, useCrmStore, useCrmConfig, formatCurrency } from './chunk-7V46TYYX.js';
5
5
  import * as React from 'react';
6
6
  import React__default, { useCallback, useMemo, useState, useEffect, useRef } from 'react';
7
- import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, PhoneCall, MoveRight, Target, ArrowRightLeft, UserPlus, MapPin, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight, Plus, Settings, Tag, Briefcase, CircleDot, User, Download, CircleDashed, Search, Inbox, X, Play, Clock, Sparkles, Calendar, ArrowRight, MoreHorizontal, ChevronDown, Printer, Pencil, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Loader2, Network, Building2, Star, Trash2, MessageSquareQuote, UserRound, CalendarDays, ThumbsDown, SignalHigh, CalendarRange, TrendingDown, UserCheck, AlertTriangle, Settings2, Repeat, Zap, Snowflake, Sun, Flame, Merge, Fingerprint, Paperclip, ImageOff, CircleAlert, Link2, CheckCircle2, SlidersHorizontal, ChevronLeft, ExternalLink, Clipboard, DollarSign, ThumbsUp, UserRoundPlus } from 'lucide-react';
8
- import { PageTransition, ModulePage, Button, useIsWide, PageHeaderActions, usePageSize, toast, FilterChip, MultiSelect, FilterMenu, FilterMenuRow, PersonAvatar, SubpageHeader, ListView, ConfirmDialog, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Textarea, ModalFooter, useSaveBar, SearchSelect, DatePicker, useFilterDraft, FilterPanel, FilterPanelField, RequiredFilter, Card, DataTable, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, PhoneLink, ComingSoon, Switch, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, DashboardCanvas, PageViewBar, Pagination, PersonPicker, cn, HeaderTabs, SheetBody, SheetFooter, Popover, PopoverTrigger, PopoverContent, getLucideIcon, DictateButton, DropdownLabel, DropdownSeparator, ModalDescription, normalizePhone } from '@fayz-ai/ui';
7
+ import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, PhoneCall, MoveRight, Target, ArrowRightLeft, UserPlus, MapPin, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight, Plus, Settings, Tag, Briefcase, CircleDot, User, Download, CircleDashed, Search, Inbox, X, Play, Clock, Sparkles, Calendar, ArrowRight, MoreHorizontal, ChevronDown, Printer, Pencil, CircleCheckBig, Ban, Receipt, Package, CalendarClock, Loader2, Network, Building2, Star, Trash2, MessageSquareQuote, UserRound, CalendarDays, ThumbsDown, SignalHigh, CalendarRange, TrendingDown, UserCheck, AlertTriangle, Settings2, Repeat, Zap, Snowflake, Sun, Flame, Merge, Fingerprint, Paperclip, ImageOff, CircleAlert, Link2, CheckCircle2, ExternalLink, Clipboard, DollarSign, ThumbsUp, SlidersHorizontal, ChevronLeft, UserRoundPlus } from 'lucide-react';
8
+ import { PageTransition, ModulePage, Button, useIsWide, PageHeaderActions, usePageSize, toast, FilterChip, MultiSelect, FilterMenu, FilterMenuRow, PersonAvatar, SubpageHeader, ListView, ConfirmDialog, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Textarea, ModalFooter, useSaveBar, SearchSelect, DatePicker, useFilterDraft, FilterPanel, FilterPanelField, RequiredFilter, Card, DataTable, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, PhoneLink, ComingSoon, Switch, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, DashboardCanvas, Pagination, PersonPicker, cn, HeaderTabs, SheetBody, SheetFooter, Popover, PopoverTrigger, PopoverContent, getLucideIcon, DictateButton, DropdownLabel, DropdownSeparator, ModalDescription, normalizePhone } from '@fayz-ai/ui';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import { usePluginRuntimeOptional, useTranslation, currentAppPath, navigateApp, useActiveTenantId, exportCSV, getCurrentLocale, appHref, getSupabaseClientOptional, loadMessageOverrides, resolveMessages, useActiveUnitId } from '@fayz-ai/core';
11
11
  import { useModuleNavigation, usePluginOnboardingGate, useUnitStore, PluginOnboardingGateSkeleton, createViewRouter, ModuleActionBar, adminNavigateTo, PageActions, usePermissionOptional, usePersistedState, useScrollMemory, useLimitGuard, useCatalogedItemTypes, OrderFormSkeleton, OrderFormBlock, OrderFormView, OrderFormItemsCard, OrderFormItemRow, OrderFormAddItemStep, createArchetypeLookup, useRecordVisit, AddressesTab, OrderDetailSkeleton, OrderDetailBlock, OrderDetailView, PersonLink, CrudFormSkeleton, CrudFormPage, CrudDetailSkeleton, CrudDetailPage, AskAIButton, KanbanBoard, InlineField, useUnitFilter, invalidateLimit, useAccessOptional, useOrganizationStore, getRailPage, RightRailPage, ContactPicker, useAgentSurface } from '@fayz-ai/admin';
@@ -597,6 +597,103 @@ function UnitPicker({ filter: f }) {
597
597
  ] })
598
598
  ] });
599
599
  }
600
+ function DisplayPopover({ config }) {
601
+ const t = useTranslation();
602
+ const [page, setPage] = useState("root");
603
+ return /* @__PURE__ */ jsxs(Popover, { onOpenChange: (open) => {
604
+ if (!open) setPage("root");
605
+ }, children: [
606
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
607
+ Button,
608
+ {
609
+ variant: "bare",
610
+ size: "bare",
611
+ type: "button",
612
+ title: t("crm.board.display"),
613
+ className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full border bg-card text-muted-foreground shadow-button transition-colors hover:bg-muted hover:text-foreground",
614
+ children: /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-4 w-4" })
615
+ }
616
+ ) }),
617
+ /* @__PURE__ */ jsxs(PopoverContent, { align: "end", className: "w-72 p-1.5", children: [
618
+ page === "root" && /* @__PURE__ */ jsxs(Fragment, { children: [
619
+ /* @__PURE__ */ jsx("p", { className: "px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground", children: t("crm.board.display") }),
620
+ /* @__PURE__ */ jsxs(
621
+ Button,
622
+ {
623
+ variant: "bare",
624
+ size: "bare",
625
+ type: "button",
626
+ onClick: () => setPage("props"),
627
+ className: "flex w-full justify-start whitespace-normal font-normal gap-2 px-2 py-1.5 text-left text-xs hover:bg-muted",
628
+ children: [
629
+ /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-3.5 w-3.5 text-muted-foreground" }),
630
+ config.title,
631
+ /* @__PURE__ */ jsx("span", { className: "ml-auto text-muted-foreground", children: "\u203A" })
632
+ ]
633
+ }
634
+ )
635
+ ] }),
636
+ page === "props" && /* @__PURE__ */ jsxs(Fragment, { children: [
637
+ /* @__PURE__ */ jsxs(
638
+ Button,
639
+ {
640
+ variant: "bare",
641
+ size: "bare",
642
+ type: "button",
643
+ onClick: () => setPage("root"),
644
+ className: "flex w-full justify-start gap-1 px-1.5 py-1 text-left text-[11px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground",
645
+ children: [
646
+ /* @__PURE__ */ jsx(ChevronLeft, { className: "h-3.5 w-3.5" }),
647
+ " ",
648
+ t("common.back"),
649
+ /* @__PURE__ */ jsx("span", { className: "ml-auto pr-1 text-[10px] font-medium uppercase tracking-wide", children: config.title })
650
+ ]
651
+ }
652
+ ),
653
+ /* @__PURE__ */ jsx("div", { className: "my-1 border-t border-border" }),
654
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 p-1", children: config.options.map(({ key, label: label2 }) => {
655
+ const on = config.visible[key] !== false;
656
+ return /* @__PURE__ */ jsx(
657
+ Button,
658
+ {
659
+ variant: "bare",
660
+ size: "bare",
661
+ type: "button",
662
+ "aria-pressed": on,
663
+ onClick: () => config.onChange({ ...config.visible, [key]: !on }),
664
+ className: `rounded-full px-2.5 py-1 text-xs ${on ? "border border-primary/30 bg-primary/10 font-medium text-primary" : "border border-border font-normal text-muted-foreground hover:text-foreground"}`,
665
+ children: label2
666
+ },
667
+ key
668
+ );
669
+ }) })
670
+ ] })
671
+ ] })
672
+ ] });
673
+ }
674
+ function DealsToolbar({ search, onSearchChange, children, display, variant = "header" }) {
675
+ const t = useTranslation();
676
+ const row = /* @__PURE__ */ jsxs("div", { className: `flex flex-wrap items-center gap-2 px-3 py-2 ${variant === "header" ? "border-b border-border" : ""}`, children: [
677
+ /* @__PURE__ */ jsxs("div", { className: "relative min-w-[12rem] flex-1", children: [
678
+ /* @__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" }),
679
+ /* @__PURE__ */ jsx(
680
+ Input,
681
+ {
682
+ type: "text",
683
+ value: search,
684
+ onChange: (e) => onSearchChange(e.target.value),
685
+ placeholder: t("crm.deals.searchPlaceholder"),
686
+ className: "h-auto rounded-none border-0 bg-transparent py-1.5 pl-8 pr-3 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0"
687
+ }
688
+ )
689
+ ] }),
690
+ /* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 flex-nowrap items-center justify-end gap-1.5 md:flex-wrap", children: [
691
+ children,
692
+ display && /* @__PURE__ */ jsx(DisplayPopover, { config: display })
693
+ ] })
694
+ ] });
695
+ return variant === "card" ? /* @__PURE__ */ jsx(Card, { className: "overflow-visible", children: row }) : row;
696
+ }
600
697
 
601
698
  // src/lib/relative-time.ts
602
699
  var MINUTE = 60;
@@ -1137,80 +1234,6 @@ var TEMP_CHIP = {
1137
1234
  cold: { icon: Snowflake, cls: "bg-info-soft text-info-soft-foreground" }
1138
1235
  };
1139
1236
  var DISPLAY_DEFAULTS = { temperature: true, due: true, contact: true, tags: true, value: true, age: true };
1140
- function DisplayPopover({ display, onChange }) {
1141
- const t = useTranslation();
1142
- const [page, setPage] = useState("root");
1143
- return /* @__PURE__ */ jsxs(Popover, { onOpenChange: (open) => {
1144
- if (!open) setPage("root");
1145
- }, children: [
1146
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
1147
- Button,
1148
- {
1149
- variant: "bare",
1150
- size: "bare",
1151
- type: "button",
1152
- title: t("crm.board.display"),
1153
- className: "flex h-8 w-8 items-center justify-center rounded-full border bg-card text-muted-foreground shadow-button transition-colors hover:bg-muted hover:text-foreground",
1154
- children: /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-4 w-4" })
1155
- }
1156
- ) }),
1157
- /* @__PURE__ */ jsxs(PopoverContent, { align: "end", className: "w-72 p-1.5", children: [
1158
- page === "root" && /* @__PURE__ */ jsxs(Fragment, { children: [
1159
- /* @__PURE__ */ jsx("p", { className: "px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground", children: t("crm.board.display") }),
1160
- /* @__PURE__ */ jsxs(
1161
- Button,
1162
- {
1163
- variant: "bare",
1164
- size: "bare",
1165
- type: "button",
1166
- onClick: () => setPage("props"),
1167
- className: "flex w-full justify-start whitespace-normal font-normal gap-2 px-2 py-1.5 text-left text-xs hover:bg-muted",
1168
- children: [
1169
- /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-3.5 w-3.5 text-muted-foreground" }),
1170
- t("crm.board.cardProps"),
1171
- /* @__PURE__ */ jsx("span", { className: "ml-auto text-muted-foreground", children: "\u203A" })
1172
- ]
1173
- }
1174
- )
1175
- ] }),
1176
- page === "props" && /* @__PURE__ */ jsxs(Fragment, { children: [
1177
- /* @__PURE__ */ jsxs(
1178
- Button,
1179
- {
1180
- variant: "bare",
1181
- size: "bare",
1182
- type: "button",
1183
- onClick: () => setPage("root"),
1184
- className: "flex w-full justify-start gap-1 px-1.5 py-1 text-left text-[11px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground",
1185
- children: [
1186
- /* @__PURE__ */ jsx(ChevronLeft, { className: "h-3.5 w-3.5" }),
1187
- " ",
1188
- t("common.back"),
1189
- /* @__PURE__ */ jsx("span", { className: "ml-auto pr-1 text-[10px] font-medium uppercase tracking-wide", children: t("crm.board.cardProps") })
1190
- ]
1191
- }
1192
- ),
1193
- /* @__PURE__ */ jsx("div", { className: "my-1 border-t border-border" }),
1194
- /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5 p-1", children: Object.keys(DISPLAY_DEFAULTS).map((k) => {
1195
- const on = display[k];
1196
- return /* @__PURE__ */ jsx(
1197
- Button,
1198
- {
1199
- variant: "bare",
1200
- size: "bare",
1201
- type: "button",
1202
- "aria-pressed": on,
1203
- onClick: () => onChange({ ...display, [k]: !on }),
1204
- className: `rounded-full px-2.5 py-1 text-xs ${on ? "border border-primary/30 bg-primary/10 font-medium text-primary" : "border border-border font-normal text-muted-foreground hover:text-foreground"}`,
1205
- children: t(`crm.board.prop.${k}`)
1206
- },
1207
- k
1208
- );
1209
- }) })
1210
- ] })
1211
- ] })
1212
- ] });
1213
- }
1214
1237
  function shortDate(iso, locale) {
1215
1238
  try {
1216
1239
  return (/* @__PURE__ */ new Date(iso + (iso.length === 10 ? "T00:00:00" : ""))).toLocaleDateString(locale, { day: "numeric", month: "short" });
@@ -1763,196 +1786,195 @@ function PipelineView({ onDealClick, onAddLead, onOpenSettings, onStageIntent })
1763
1786
  setMenu({ x: e.clientX, y: e.clientY, deal, mode });
1764
1787
  }
1765
1788
  return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1766
- /* @__PURE__ */ jsx(PageViewBar, { children: /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
1767
- effectiveOwner && /* @__PURE__ */ jsxs(
1768
- BoardFilterChip,
1769
- {
1770
- closeOnSelect: true,
1771
- clearLabel: t("crm.board.clearFilters"),
1772
- onClear: () => setOwnerFilter(void 0),
1773
- trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1774
- effectiveOwner === "none" ? /* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? "Eu", size: "xs" }),
1775
- /* @__PURE__ */ jsx("span", { className: "max-w-[8rem] truncate", children: effectiveOwner === "none" ? t("crm.leads.filters.unassigned") : effectiveOwner === myUserId ? t("crm.leads.filters.mine") : (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? t("crm.leads.filters.owner") })
1776
- ] }),
1777
- children: [
1778
- myUserId && /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter("__me__"), children: [
1779
- /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === myUserId)?.name ?? "Eu", size: "xs" }),
1780
- " ",
1781
- t("crm.leads.filters.mine"),
1782
- effectiveOwner === myUserId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1783
- ] }),
1784
- /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter("none"), children: [
1785
- /* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3 text-muted-foreground" }),
1786
- " ",
1787
- t("crm.leads.filters.unassigned"),
1788
- effectiveOwner === "none" && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1789
- ] }),
1790
- (team ?? []).filter((m) => m.userId !== myUserId).map((m) => /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter(m.userId), children: [
1791
- /* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
1792
- " ",
1793
- /* @__PURE__ */ jsx("span", { className: "truncate", children: m.name }),
1794
- effectiveOwner === m.userId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1795
- ] }, m.userId))
1796
- ]
1797
- }
1798
- ),
1799
- period !== "all" && /* @__PURE__ */ jsx(
1800
- BoardFilterChip,
1801
- {
1802
- closeOnSelect: true,
1803
- clearLabel: t("crm.board.clearFilters"),
1804
- onClear: () => setPeriod("all"),
1805
- trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1806
- /* @__PURE__ */ jsx(CalendarDays, { className: "h-3 w-3" }),
1807
- t(`crm.filters.period${period === "custom" ? "Custom" : period}`)
1808
- ] }),
1809
- children: ["24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setPeriod(p), children: [
1810
- t(`crm.filters.period${p === "custom" ? "Custom" : p}`),
1811
- period === p && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1812
- ] }, p))
1813
- }
1814
- ),
1815
- selectedTags.length > 0 && /* @__PURE__ */ jsx(
1816
- BoardFilterChip,
1817
- {
1818
- clearLabel: t("crm.board.clearFilters"),
1819
- onClear: () => setSelectedTags([]),
1820
- trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1821
- /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(selectedTags[0])?.color ?? "#94A3B8" } }),
1822
- /* @__PURE__ */ jsxs("span", { className: "max-w-[8rem] truncate", children: [
1823
- tagDefs.get(selectedTags[0])?.name ?? humanizeTag(selectedTags[0]),
1824
- selectedTags.length > 1 ? ` +${selectedTags.length - 1}` : ""
1825
- ] })
1826
- ] }),
1827
- children: [.../* @__PURE__ */ new Set([...availableTags, ...selectedTags])].sort((a, b) => (tagDefs.get(a)?.name ?? humanizeTag(a)).localeCompare(tagDefs.get(b)?.name ?? humanizeTag(b))).map((slug) => {
1828
- const on = selectedTags.includes(slug);
1829
- return /* @__PURE__ */ jsxs(
1830
- Button,
1831
- {
1832
- variant: "bare",
1833
- size: "bare",
1834
- className: CHIP_ROW,
1835
- onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
1836
- children: [
1837
- /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
1838
- /* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) }),
1839
- on && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1840
- ]
1841
- },
1842
- slug
1843
- );
1844
- })
1845
- }
1846
- ),
1847
- /* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
1848
- /* @__PURE__ */ jsx(
1849
- FilterMenu,
1850
- {
1851
- label: t("crm.board.filters"),
1852
- activeCount: (period !== "all" ? 1 : 0) + (selectedTags.length ? 1 : 0) + (search.trim() ? 1 : 0) + (effectiveOwner ? 1 : 0),
1853
- onClear: () => {
1854
- setSearch("");
1855
- setPeriod("all");
1856
- setSelectedTags([]);
1857
- setOwnerFilter(void 0);
1858
- },
1859
- clearLabel: t("crm.board.clearFilters"),
1860
- header: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
1861
- /* @__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" }),
1862
- /* @__PURE__ */ jsx(
1863
- Input,
1864
- {
1865
- type: "text",
1866
- value: search,
1867
- onChange: (e) => setSearch(e.target.value),
1868
- placeholder: t("crm.deals.searchPlaceholder"),
1869
- className: "h-8 border-border bg-background pl-8 pr-3 text-xs shadow-none placeholder:text-muted-foreground/70 focus-visible:ring-offset-0"
1870
- }
1871
- )
1872
- ] }),
1873
- fields: [
1789
+ /* @__PURE__ */ jsxs(
1790
+ DealsToolbar,
1791
+ {
1792
+ variant: "card",
1793
+ search,
1794
+ onSearchChange: setSearch,
1795
+ display: {
1796
+ title: t("crm.board.cardProps"),
1797
+ options: Object.keys(DISPLAY_DEFAULTS).map((k) => ({ key: k, label: t(`crm.board.prop.${k}`) })),
1798
+ visible: display,
1799
+ onChange: (next) => setDisplay({ ...DISPLAY_DEFAULTS, ...next })
1800
+ },
1801
+ children: [
1802
+ effectiveOwner && /* @__PURE__ */ jsxs(
1803
+ BoardFilterChip,
1874
1804
  {
1875
- id: "owner",
1876
- label: t("crm.leads.filters.owner"),
1877
- icon: UserRound,
1878
- activeCount: effectiveOwner ? 1 : 0,
1879
- searchable: true,
1880
- render: (close, q) => /* @__PURE__ */ jsxs(Fragment, { children: [
1881
- /* @__PURE__ */ jsxs(FilterMenuRow, { active: !effectiveOwner, onClick: () => {
1882
- setOwnerFilter(void 0);
1883
- close();
1884
- }, children: [
1885
- /* @__PURE__ */ jsx(UserRound, { className: "h-3.5 w-3.5 text-muted-foreground" }),
1886
- " ",
1887
- t("crm.leads.filters.allOwners")
1888
- ] }),
1889
- myUserId && /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === myUserId, onClick: () => {
1890
- setOwnerFilter("__me__");
1891
- close();
1892
- }, children: [
1805
+ closeOnSelect: true,
1806
+ clearLabel: t("crm.board.clearFilters"),
1807
+ onClear: () => setOwnerFilter(void 0),
1808
+ trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1809
+ effectiveOwner === "none" ? /* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? "Eu", size: "xs" }),
1810
+ /* @__PURE__ */ jsx("span", { className: "max-w-[8rem] truncate", children: effectiveOwner === "none" ? t("crm.leads.filters.unassigned") : effectiveOwner === myUserId ? t("crm.leads.filters.mine") : (team ?? []).find((m) => m.userId === effectiveOwner)?.name ?? t("crm.leads.filters.owner") })
1811
+ ] }),
1812
+ children: [
1813
+ myUserId && /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter("__me__"), children: [
1893
1814
  /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === myUserId)?.name ?? "Eu", size: "xs" }),
1894
1815
  " ",
1895
- t("crm.leads.filters.mine")
1816
+ t("crm.leads.filters.mine"),
1817
+ effectiveOwner === myUserId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1896
1818
  ] }),
1897
- /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === "none", onClick: () => {
1898
- setOwnerFilter("none");
1899
- close();
1900
- }, children: [
1901
- /* @__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" }) }),
1902
- t("crm.leads.filters.unassigned")
1819
+ /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter("none"), children: [
1820
+ /* @__PURE__ */ jsx(UserRound, { className: "h-3 w-3 text-muted-foreground" }),
1821
+ " ",
1822
+ t("crm.leads.filters.unassigned"),
1823
+ effectiveOwner === "none" && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1903
1824
  ] }),
1904
- (team ?? []).filter((m) => m.userId !== myUserId && m.name.toLowerCase().includes(q.toLowerCase())).map((m) => /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === m.userId, onClick: () => {
1905
- setOwnerFilter(m.userId);
1906
- close();
1907
- }, children: [
1825
+ (team ?? []).filter((m) => m.userId !== myUserId).map((m) => /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setOwnerFilter(m.userId), children: [
1908
1826
  /* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
1909
- /* @__PURE__ */ jsx("span", { className: "truncate", children: m.name })
1827
+ " ",
1828
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: m.name }),
1829
+ effectiveOwner === m.userId && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1910
1830
  ] }, m.userId))
1911
- ] })
1912
- },
1831
+ ]
1832
+ }
1833
+ ),
1834
+ period !== "all" && /* @__PURE__ */ jsx(
1835
+ BoardFilterChip,
1913
1836
  {
1914
- id: "period",
1915
- label: t("crm.filters.period"),
1916
- icon: CalendarDays,
1917
- activeCount: period !== "all" ? 1 : 0,
1918
- render: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
1919
- ["all", "24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsx(FilterMenuRow, { active: period === p, onClick: () => {
1920
- setPeriod(p);
1921
- if (p !== "custom") close();
1922
- }, children: t(`crm.filters.period${p === "all" ? "All" : p === "custom" ? "Custom" : p}`) }, p)),
1923
- period === "custom" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 p-1.5", children: [
1924
- /* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customFrom, onChange: setCustomFrom }),
1925
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2013" }),
1926
- /* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customTo, onChange: setCustomTo })
1927
- ] })
1928
- ] })
1929
- },
1837
+ closeOnSelect: true,
1838
+ clearLabel: t("crm.board.clearFilters"),
1839
+ onClear: () => setPeriod("all"),
1840
+ trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1841
+ /* @__PURE__ */ jsx(CalendarDays, { className: "h-3 w-3" }),
1842
+ t(`crm.filters.period${period === "custom" ? "Custom" : period}`)
1843
+ ] }),
1844
+ children: ["24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsxs(Button, { variant: "bare", size: "bare", className: CHIP_ROW, onClick: () => setPeriod(p), children: [
1845
+ t(`crm.filters.period${p === "custom" ? "Custom" : p}`),
1846
+ period === p && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1847
+ ] }, p))
1848
+ }
1849
+ ),
1850
+ selectedTags.length > 0 && /* @__PURE__ */ jsx(
1851
+ BoardFilterChip,
1930
1852
  {
1931
- id: "tags",
1932
- label: t("crm.leads.filters.tag"),
1933
- icon: Tag,
1934
- activeCount: selectedTags.length,
1935
- 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) => {
1853
+ clearLabel: t("crm.board.clearFilters"),
1854
+ onClear: () => setSelectedTags([]),
1855
+ trigger: /* @__PURE__ */ jsxs(Fragment, { children: [
1856
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(selectedTags[0])?.color ?? "#94A3B8" } }),
1857
+ /* @__PURE__ */ jsxs("span", { className: "max-w-[8rem] truncate", children: [
1858
+ tagDefs.get(selectedTags[0])?.name ?? humanizeTag(selectedTags[0]),
1859
+ selectedTags.length > 1 ? ` +${selectedTags.length - 1}` : ""
1860
+ ] })
1861
+ ] }),
1862
+ children: [.../* @__PURE__ */ new Set([...availableTags, ...selectedTags])].sort((a, b) => (tagDefs.get(a)?.name ?? humanizeTag(a)).localeCompare(tagDefs.get(b)?.name ?? humanizeTag(b))).map((slug) => {
1936
1863
  const on = selectedTags.includes(slug);
1937
1864
  return /* @__PURE__ */ jsxs(
1938
- FilterMenuRow,
1865
+ Button,
1939
1866
  {
1940
- active: on,
1867
+ variant: "bare",
1868
+ size: "bare",
1869
+ className: CHIP_ROW,
1941
1870
  onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
1942
1871
  children: [
1943
1872
  /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
1944
- /* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) })
1873
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) }),
1874
+ on && /* @__PURE__ */ jsx(Check, { className: "ml-auto h-3 w-3 shrink-0" })
1945
1875
  ]
1946
1876
  },
1947
1877
  slug
1948
1878
  );
1949
- }) })
1879
+ })
1950
1880
  }
1951
- ]
1952
- }
1953
- ),
1954
- /* @__PURE__ */ jsx(DisplayPopover, { display, onChange: setDisplay })
1955
- ] }) }),
1881
+ ),
1882
+ /* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
1883
+ /* @__PURE__ */ jsx(
1884
+ FilterMenu,
1885
+ {
1886
+ label: t("crm.board.filters"),
1887
+ activeCount: (period !== "all" ? 1 : 0) + (selectedTags.length ? 1 : 0) + (effectiveOwner ? 1 : 0),
1888
+ onClear: () => {
1889
+ setPeriod("all");
1890
+ setSelectedTags([]);
1891
+ setOwnerFilter(void 0);
1892
+ },
1893
+ clearLabel: t("crm.board.clearFilters"),
1894
+ fields: [
1895
+ {
1896
+ id: "owner",
1897
+ label: t("crm.leads.filters.owner"),
1898
+ icon: UserRound,
1899
+ activeCount: effectiveOwner ? 1 : 0,
1900
+ searchable: true,
1901
+ render: (close, q) => /* @__PURE__ */ jsxs(Fragment, { children: [
1902
+ /* @__PURE__ */ jsxs(FilterMenuRow, { active: !effectiveOwner, onClick: () => {
1903
+ setOwnerFilter(void 0);
1904
+ close();
1905
+ }, children: [
1906
+ /* @__PURE__ */ jsx(UserRound, { className: "h-3.5 w-3.5 text-muted-foreground" }),
1907
+ " ",
1908
+ t("crm.leads.filters.allOwners")
1909
+ ] }),
1910
+ myUserId && /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === myUserId, onClick: () => {
1911
+ setOwnerFilter("__me__");
1912
+ close();
1913
+ }, children: [
1914
+ /* @__PURE__ */ jsx(PersonAvatar, { name: (team ?? []).find((m) => m.userId === myUserId)?.name ?? "Eu", size: "xs" }),
1915
+ " ",
1916
+ t("crm.leads.filters.mine")
1917
+ ] }),
1918
+ /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === "none", onClick: () => {
1919
+ setOwnerFilter("none");
1920
+ close();
1921
+ }, children: [
1922
+ /* @__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" }) }),
1923
+ t("crm.leads.filters.unassigned")
1924
+ ] }),
1925
+ (team ?? []).filter((m) => m.userId !== myUserId && m.name.toLowerCase().includes(q.toLowerCase())).map((m) => /* @__PURE__ */ jsxs(FilterMenuRow, { active: effectiveOwner === m.userId, onClick: () => {
1926
+ setOwnerFilter(m.userId);
1927
+ close();
1928
+ }, children: [
1929
+ /* @__PURE__ */ jsx(PersonAvatar, { name: m.name, size: "xs" }),
1930
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: m.name })
1931
+ ] }, m.userId))
1932
+ ] })
1933
+ },
1934
+ {
1935
+ id: "period",
1936
+ label: t("crm.filters.period"),
1937
+ icon: CalendarDays,
1938
+ activeCount: period !== "all" ? 1 : 0,
1939
+ render: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
1940
+ ["all", "24h", "7d", "custom"].map((p) => /* @__PURE__ */ jsx(FilterMenuRow, { active: period === p, onClick: () => {
1941
+ setPeriod(p);
1942
+ if (p !== "custom") close();
1943
+ }, children: t(`crm.filters.period${p === "all" ? "All" : p === "custom" ? "Custom" : p}`) }, p)),
1944
+ period === "custom" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 p-1.5", children: [
1945
+ /* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customFrom, onChange: setCustomFrom }),
1946
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2013" }),
1947
+ /* @__PURE__ */ jsx(DatePicker, { variant: "chip", format: "numeric", className: "w-full", value: customTo, onChange: setCustomTo })
1948
+ ] })
1949
+ ] })
1950
+ },
1951
+ {
1952
+ id: "tags",
1953
+ label: t("crm.leads.filters.tag"),
1954
+ icon: Tag,
1955
+ activeCount: selectedTags.length,
1956
+ 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) => {
1957
+ const on = selectedTags.includes(slug);
1958
+ return /* @__PURE__ */ jsxs(
1959
+ FilterMenuRow,
1960
+ {
1961
+ active: on,
1962
+ onClick: () => setSelectedTags(on ? selectedTags.filter((s) => s !== slug) : [...selectedTags, slug]),
1963
+ children: [
1964
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: tagDefs.get(slug)?.color ?? "#94A3B8" } }),
1965
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: tagDefs.get(slug)?.name ?? humanizeTag(slug) })
1966
+ ]
1967
+ },
1968
+ slug
1969
+ );
1970
+ }) })
1971
+ }
1972
+ ]
1973
+ }
1974
+ )
1975
+ ]
1976
+ }
1977
+ ),
1956
1978
  boardPending ? /* @__PURE__ */ jsx(PipelineSkeleton, {}) : visibleStages.length === 0 ? (
1957
1979
  /* Sem etapas não existe quadro: o `flex` abaixo renderizava uma faixa
1958
1980
  em branco, que parece uma tela que não carregou. O funil é a única
@@ -2197,6 +2219,7 @@ function DealListView({ onOpenDeal }) {
2197
2219
  }, [deals, query, stage, status, city, tags, cohort, companyName, owner, tagDefs, currency.locale]);
2198
2220
  const columns = useMemo(() => [
2199
2221
  {
2222
+ id: "title",
2200
2223
  accessorKey: "title",
2201
2224
  header: t("crm.deals.colDeal"),
2202
2225
  cell: ({ row }) => /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
@@ -2207,6 +2230,7 @@ function DealListView({ onOpenDeal }) {
2207
2230
  {
2208
2231
  // A empresa (024). Três pessoas da mesma casa viram três linhas, e sem
2209
2232
  // esta coluna nada na lista diz que são a mesma casa.
2233
+ id: "companyName",
2210
2234
  accessorKey: "companyName",
2211
2235
  header: t("crm.card.companyTitle"),
2212
2236
  cell: ({ row }) => row.original.companyName ? /* @__PURE__ */ jsxs("div", { className: "min-w-0 max-w-[14rem]", children: [
@@ -2221,6 +2245,7 @@ function DealListView({ onOpenDeal }) {
2221
2245
  ] }) : /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "\u2014" })
2222
2246
  },
2223
2247
  {
2248
+ id: "stageName",
2224
2249
  accessorKey: "stageName",
2225
2250
  header: t("crm.dealSidebar.stage"),
2226
2251
  cell: ({ row }) => /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5 whitespace-nowrap text-xs", children: [
@@ -2230,6 +2255,7 @@ function DealListView({ onOpenDeal }) {
2230
2255
  },
2231
2256
  {
2232
2257
  // Derivado (020) — a coluna que ordena por "quem ainda não foi contatado".
2258
+ id: "contactStatusName",
2233
2259
  accessorKey: "contactStatusName",
2234
2260
  header: t("crm.deals.colStatus"),
2235
2261
  cell: ({ row }) => row.original.contactStatusName ? /* @__PURE__ */ jsx(
@@ -2245,6 +2271,7 @@ function DealListView({ onOpenDeal }) {
2245
2271
  ) : /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "\u2014" })
2246
2272
  },
2247
2273
  {
2274
+ id: "contactCity",
2248
2275
  accessorKey: "contactCity",
2249
2276
  header: t("crm.deals.colCity"),
2250
2277
  cell: ({ row }) => row.original.contactCity ? /* @__PURE__ */ jsxs("span", { className: "whitespace-nowrap text-xs", children: [
@@ -2256,11 +2283,13 @@ function DealListView({ onOpenDeal }) {
2256
2283
  ] }) : /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "\u2014" })
2257
2284
  },
2258
2285
  {
2286
+ id: "value",
2259
2287
  accessorKey: "value",
2260
2288
  header: t("crm.dealSidebar.value"),
2261
2289
  cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap text-sm font-semibold tabular-nums", children: formatCurrency(getValue(), currency) })
2262
2290
  },
2263
2291
  {
2292
+ id: "assignedToName",
2264
2293
  accessorKey: "assignedToName",
2265
2294
  header: t("crm.dealSidebar.assignedTo"),
2266
2295
  cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap text-xs text-muted-foreground", children: getValue() || "\u2014" })
@@ -2278,6 +2307,11 @@ function DealListView({ onOpenDeal }) {
2278
2307
  }
2279
2308
  }
2280
2309
  ], [currency, t]);
2310
+ const [visibleColumns, setVisibleColumns] = usePersistedState("crm.deals.columns", {});
2311
+ const shownColumns = useMemo(
2312
+ () => columns.filter((c) => c.id === "title" || visibleColumns[c.id] !== false),
2313
+ [columns, visibleColumns]
2314
+ );
2281
2315
  const pageRows = useMemo(
2282
2316
  () => rows.slice((page - 1) * pageSize, page * pageSize),
2283
2317
  [rows, page]
@@ -2401,150 +2435,148 @@ function DealListView({ onOpenDeal }) {
2401
2435
  );
2402
2436
  return /* @__PURE__ */ jsxs("div", { ref: ancoraRolagem, className: "space-y-3", children: [
2403
2437
  /* @__PURE__ */ jsxs(Card, { className: "overflow-hidden", children: [
2404
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 border-b border-border px-3 py-2", children: [
2405
- /* @__PURE__ */ jsxs("div", { className: "relative min-w-[12rem] flex-1", children: [
2406
- /* @__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" }),
2407
- /* @__PURE__ */ jsx(
2408
- Input,
2409
- {
2410
- type: "text",
2411
- value: search,
2412
- onChange: (e) => setSearch(e.target.value),
2413
- placeholder: t("crm.deals.searchPlaceholder"),
2414
- className: "h-auto rounded-none border-0 bg-transparent py-1.5 pl-8 pr-3 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0"
2415
- }
2416
- )
2417
- ] }),
2418
- /* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 flex-nowrap items-center justify-end gap-1.5 md:flex-wrap", children: [
2419
- /* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
2420
- stage && /* @__PURE__ */ jsx(
2421
- FilterChip,
2422
- {
2423
- label: t("crm.dealSidebar.stage"),
2424
- icon: Filter,
2425
- allLabel: t("crm.deals.allStages"),
2426
- options: stageOptions,
2427
- value: stage,
2428
- onChange: setStage
2429
- }
2430
- ),
2431
- outcome !== "open" && /* @__PURE__ */ jsx(
2432
- FilterChip,
2433
- {
2434
- label: t("crm.deals.outcome"),
2435
- icon: ThumbsDown,
2436
- allLabel: t("crm.deals.outcomeOpen"),
2437
- options: outcomeOptions,
2438
- value: outcome,
2439
- onChange: (v) => setOutcome(v ?? "open")
2440
- }
2441
- ),
2442
- status && /* @__PURE__ */ jsx(
2443
- FilterChip,
2444
- {
2445
- label: t("crm.deals.colStatus"),
2446
- icon: SignalHigh,
2447
- allLabel: t("crm.deals.allStatuses"),
2448
- options: statusOptions,
2449
- value: status,
2450
- onChange: setStatus
2451
- }
2452
- ),
2453
- cohort && /* @__PURE__ */ jsx(
2454
- FilterChip,
2455
- {
2456
- label: t("crm.deals.cohort"),
2457
- icon: CalendarRange,
2458
- allLabel: t("crm.deals.allCohorts"),
2459
- options: cohortOptions,
2460
- value: cohort,
2461
- onChange: setCohort
2462
- }
2463
- ),
2464
- tags.length > 0 && /* @__PURE__ */ jsx(
2465
- MultiSelect,
2466
- {
2467
- variant: "chip",
2468
- icon: Tag,
2469
- options: tagOptions,
2470
- value: tags,
2471
- onChange: setTags,
2472
- allLabel: t("crm.leads.filters.allTags"),
2473
- searchPlaceholder: t("crm.leads.filters.searchTag"),
2474
- emptyLabel: t("crm.leads.filters.noTag")
2475
- }
2476
- ),
2477
- owner && /* @__PURE__ */ jsx(
2478
- FilterChip,
2479
- {
2480
- label: t("crm.leads.filters.owner"),
2481
- icon: User,
2482
- allLabel: t("crm.leads.filters.allOwners"),
2483
- options: ownerOptions,
2484
- value: owner,
2485
- onChange: setOwner
2486
- }
2487
- ),
2488
- companyName && /* @__PURE__ */ jsx(
2489
- FilterChip,
2490
- {
2491
- label: t("crm.card.companyTitle"),
2492
- icon: Building2,
2493
- allLabel: t("crm.deals.allCompanies"),
2494
- options: companyOptions,
2495
- value: companyName,
2496
- onChange: setCompanyName
2497
- }
2498
- ),
2499
- city && /* @__PURE__ */ jsx(
2500
- FilterChip,
2501
- {
2502
- label: t("crm.deals.colCity"),
2503
- icon: MapPin,
2504
- allLabel: t("crm.deals.allCities"),
2505
- options: cityOptions,
2506
- value: city,
2507
- onChange: setCity
2508
- }
2509
- ),
2510
- filtersMenu,
2511
- filtrosAtivos > 0 && /* @__PURE__ */ jsxs(
2512
- Button,
2513
- {
2514
- type: "button",
2515
- variant: "ghost",
2516
- onClick: limparFiltros,
2517
- className: "h-auto shrink-0 gap-1 rounded-full px-2 py-1 text-xs font-medium text-muted-foreground",
2518
- children: [
2519
- /* @__PURE__ */ jsx(X, { className: "h-3 w-3 shrink-0" }),
2520
- t("crm.leads.filters.clear")
2521
- ]
2522
- }
2523
- ),
2524
- segmentRules.length > 0 && /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", onClick: () => setSegmentOpen(true), className: "h-8 gap-1 px-2 text-xs", children: [
2525
- /* @__PURE__ */ jsx(Filter, { className: "h-3.5 w-3.5" }),
2526
- t("crm.deals.saveSegment")
2527
- ] }),
2528
- /* @__PURE__ */ jsx(
2529
- Button,
2530
- {
2531
- type: "button",
2532
- variant: "ghost",
2533
- size: "icon",
2534
- "aria-label": t("crud.export.action"),
2535
- title: t("crud.export.action"),
2536
- onClick: exportRows,
2537
- className: "h-8 w-8 shrink-0",
2538
- children: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" })
2539
- }
2540
- )
2541
- ] })
2542
- ] }),
2438
+ /* @__PURE__ */ jsxs(
2439
+ DealsToolbar,
2440
+ {
2441
+ search,
2442
+ onSearchChange: setSearch,
2443
+ display: {
2444
+ title: t("crm.deals.columns"),
2445
+ options: columns.filter((c) => c.id !== "title").map((c) => ({ key: c.id, label: String(c.header) })),
2446
+ visible: visibleColumns,
2447
+ onChange: setVisibleColumns
2448
+ },
2449
+ children: [
2450
+ /* @__PURE__ */ jsx(UnitPicker, { filter: unitFilter }),
2451
+ stage && /* @__PURE__ */ jsx(
2452
+ FilterChip,
2453
+ {
2454
+ label: t("crm.dealSidebar.stage"),
2455
+ icon: Filter,
2456
+ allLabel: t("crm.deals.allStages"),
2457
+ options: stageOptions,
2458
+ value: stage,
2459
+ onChange: setStage
2460
+ }
2461
+ ),
2462
+ outcome !== "open" && /* @__PURE__ */ jsx(
2463
+ FilterChip,
2464
+ {
2465
+ label: t("crm.deals.outcome"),
2466
+ icon: ThumbsDown,
2467
+ allLabel: t("crm.deals.outcomeOpen"),
2468
+ options: outcomeOptions,
2469
+ value: outcome,
2470
+ onChange: (v) => setOutcome(v ?? "open")
2471
+ }
2472
+ ),
2473
+ status && /* @__PURE__ */ jsx(
2474
+ FilterChip,
2475
+ {
2476
+ label: t("crm.deals.colStatus"),
2477
+ icon: SignalHigh,
2478
+ allLabel: t("crm.deals.allStatuses"),
2479
+ options: statusOptions,
2480
+ value: status,
2481
+ onChange: setStatus
2482
+ }
2483
+ ),
2484
+ cohort && /* @__PURE__ */ jsx(
2485
+ FilterChip,
2486
+ {
2487
+ label: t("crm.deals.cohort"),
2488
+ icon: CalendarRange,
2489
+ allLabel: t("crm.deals.allCohorts"),
2490
+ options: cohortOptions,
2491
+ value: cohort,
2492
+ onChange: setCohort
2493
+ }
2494
+ ),
2495
+ tags.length > 0 && /* @__PURE__ */ jsx(
2496
+ MultiSelect,
2497
+ {
2498
+ variant: "chip",
2499
+ icon: Tag,
2500
+ options: tagOptions,
2501
+ value: tags,
2502
+ onChange: setTags,
2503
+ allLabel: t("crm.leads.filters.allTags"),
2504
+ searchPlaceholder: t("crm.leads.filters.searchTag"),
2505
+ emptyLabel: t("crm.leads.filters.noTag")
2506
+ }
2507
+ ),
2508
+ owner && /* @__PURE__ */ jsx(
2509
+ FilterChip,
2510
+ {
2511
+ label: t("crm.leads.filters.owner"),
2512
+ icon: User,
2513
+ allLabel: t("crm.leads.filters.allOwners"),
2514
+ options: ownerOptions,
2515
+ value: owner,
2516
+ onChange: setOwner
2517
+ }
2518
+ ),
2519
+ companyName && /* @__PURE__ */ jsx(
2520
+ FilterChip,
2521
+ {
2522
+ label: t("crm.card.companyTitle"),
2523
+ icon: Building2,
2524
+ allLabel: t("crm.deals.allCompanies"),
2525
+ options: companyOptions,
2526
+ value: companyName,
2527
+ onChange: setCompanyName
2528
+ }
2529
+ ),
2530
+ city && /* @__PURE__ */ jsx(
2531
+ FilterChip,
2532
+ {
2533
+ label: t("crm.deals.colCity"),
2534
+ icon: MapPin,
2535
+ allLabel: t("crm.deals.allCities"),
2536
+ options: cityOptions,
2537
+ value: city,
2538
+ onChange: setCity
2539
+ }
2540
+ ),
2541
+ filtersMenu,
2542
+ filtrosAtivos > 0 && /* @__PURE__ */ jsxs(
2543
+ Button,
2544
+ {
2545
+ type: "button",
2546
+ variant: "ghost",
2547
+ onClick: limparFiltros,
2548
+ className: "h-auto shrink-0 gap-1 rounded-full px-2 py-1 text-xs font-medium text-muted-foreground",
2549
+ children: [
2550
+ /* @__PURE__ */ jsx(X, { className: "h-3 w-3 shrink-0" }),
2551
+ t("crm.leads.filters.clear")
2552
+ ]
2553
+ }
2554
+ ),
2555
+ segmentRules.length > 0 && /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", onClick: () => setSegmentOpen(true), className: "h-8 gap-1 px-2 text-xs", children: [
2556
+ /* @__PURE__ */ jsx(Filter, { className: "h-3.5 w-3.5" }),
2557
+ t("crm.deals.saveSegment")
2558
+ ] }),
2559
+ /* @__PURE__ */ jsx(
2560
+ Button,
2561
+ {
2562
+ type: "button",
2563
+ variant: "ghost",
2564
+ size: "icon",
2565
+ "aria-label": t("crud.export.action"),
2566
+ title: t("crud.export.action"),
2567
+ onClick: exportRows,
2568
+ className: "h-8 w-8 shrink-0",
2569
+ children: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" })
2570
+ }
2571
+ )
2572
+ ]
2573
+ }
2574
+ ),
2543
2575
  /* @__PURE__ */ jsx(
2544
2576
  DataTable,
2545
2577
  {
2546
2578
  variant: "bare",
2547
- columns,
2579
+ columns: shownColumns,
2548
2580
  data: pageRows,
2549
2581
  loading: dealsLoading,
2550
2582
  onRowClick: onOpenDeal ? (row) => onOpenDeal(row.id) : void 0,
@@ -3313,6 +3345,148 @@ function TemperatureBadge({ score, size = "sm", className }) {
3313
3345
  }
3314
3346
  );
3315
3347
  }
3348
+ function slugifyTag(text) {
3349
+ return text.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().trim().replace(/[^a-z0-9:]+/g, "-").replace(/^-+|-+$/g, "");
3350
+ }
3351
+ function dotColor(color) {
3352
+ return color && /^#[0-9a-f]{6}$/i.test(color) ? color : "#94A3B8";
3353
+ }
3354
+ function TagEditor({ tags, defs, onChange, disabled }) {
3355
+ const t = useTranslation();
3356
+ const [adding, setAdding] = useState(false);
3357
+ const [query, setQuery] = useState("");
3358
+ const inputRef = useRef(null);
3359
+ const label2 = (slug) => defs?.get(slug)?.name ?? humanizeTag(slug);
3360
+ const suggestions = useMemo(() => {
3361
+ const q = slugifyTag(query);
3362
+ const taken = new Set(tags);
3363
+ return [...defs?.values() ?? []].filter((d) => d.isActive && !taken.has(d.slug)).filter((d) => !q || d.slug.includes(q) || slugifyTag(d.name).includes(q)).sort((a, b) => a.name.localeCompare(b.name)).slice(0, 8);
3364
+ }, [defs, tags, query]);
3365
+ const add = (slug) => {
3366
+ if (!slug || tags.includes(slug)) return;
3367
+ onChange([...tags, slug]);
3368
+ setQuery("");
3369
+ inputRef.current?.focus();
3370
+ };
3371
+ const remove = (slug) => onChange(tags.filter((s) => s !== slug));
3372
+ const typed = slugifyTag(query);
3373
+ const canCreate = !!typed && !tags.includes(typed) && !defs?.has(typed);
3374
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
3375
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
3376
+ tags.map((slug) => /* @__PURE__ */ jsxs(
3377
+ "span",
3378
+ {
3379
+ title: label2(slug),
3380
+ className: "inline-flex max-w-[12rem] items-center gap-1 rounded-full border border-border bg-card px-2 py-0.5 text-[10px] font-medium text-foreground/80",
3381
+ children: [
3382
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: dotColor(defs?.get(slug)?.color) } }),
3383
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: label2(slug) }),
3384
+ !disabled && /* @__PURE__ */ jsx(
3385
+ Button,
3386
+ {
3387
+ variant: "bare",
3388
+ size: "bare",
3389
+ type: "button",
3390
+ onClick: () => remove(slug),
3391
+ className: "shrink-0 opacity-50 hover:opacity-100",
3392
+ "aria-label": t("crm.tagEditor.remove", { tag: label2(slug) }),
3393
+ children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" })
3394
+ }
3395
+ )
3396
+ ]
3397
+ },
3398
+ slug
3399
+ )),
3400
+ !disabled && !adding && /* @__PURE__ */ jsxs(
3401
+ Button,
3402
+ {
3403
+ variant: "bare",
3404
+ size: "bare",
3405
+ type: "button",
3406
+ onClick: () => {
3407
+ setAdding(true);
3408
+ setTimeout(() => inputRef.current?.focus(), 0);
3409
+ },
3410
+ className: "inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] font-medium text-muted-foreground hover:text-foreground",
3411
+ children: [
3412
+ /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
3413
+ " ",
3414
+ t("crm.tagEditor.add")
3415
+ ]
3416
+ }
3417
+ )
3418
+ ] }),
3419
+ adding && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3420
+ /* @__PURE__ */ jsx(
3421
+ "input",
3422
+ {
3423
+ ref: inputRef,
3424
+ value: query,
3425
+ onChange: (e) => setQuery(e.target.value),
3426
+ onKeyDown: (e) => {
3427
+ if (e.key === "Enter") {
3428
+ e.preventDefault();
3429
+ if (suggestions[0] && !canCreate) add(suggestions[0].slug);
3430
+ else add(typed);
3431
+ } else if (e.key === "Escape") {
3432
+ e.stopPropagation();
3433
+ setAdding(false);
3434
+ setQuery("");
3435
+ }
3436
+ },
3437
+ placeholder: t("crm.tagEditor.placeholder"),
3438
+ className: "h-8 w-full rounded-md border border-border bg-background px-2 text-xs outline-none focus:border-primary"
3439
+ }
3440
+ ),
3441
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1", children: [
3442
+ canCreate && /* @__PURE__ */ jsxs(
3443
+ Button,
3444
+ {
3445
+ variant: "bare",
3446
+ size: "bare",
3447
+ type: "button",
3448
+ onClick: () => add(typed),
3449
+ className: "inline-flex items-center gap-1 rounded-full border border-dashed border-primary/50 px-2 py-0.5 text-[10px] font-medium text-primary",
3450
+ children: [
3451
+ /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
3452
+ " ",
3453
+ t("crm.tagEditor.create", { tag: humanizeTag(typed) })
3454
+ ]
3455
+ }
3456
+ ),
3457
+ suggestions.map((d) => /* @__PURE__ */ jsxs(
3458
+ Button,
3459
+ {
3460
+ variant: "bare",
3461
+ size: "bare",
3462
+ type: "button",
3463
+ onClick: () => add(d.slug),
3464
+ className: "inline-flex items-center gap-1 rounded-full border border-border bg-card px-2 py-0.5 text-[10px] font-medium text-foreground/80 hover:bg-muted",
3465
+ children: [
3466
+ /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: dotColor(d.color) } }),
3467
+ d.name
3468
+ ]
3469
+ },
3470
+ d.slug
3471
+ ))
3472
+ ] }),
3473
+ /* @__PURE__ */ jsx(
3474
+ Button,
3475
+ {
3476
+ variant: "bare",
3477
+ size: "bare",
3478
+ type: "button",
3479
+ onClick: () => {
3480
+ setAdding(false);
3481
+ setQuery("");
3482
+ },
3483
+ className: "self-start text-[10px] text-muted-foreground hover:text-foreground",
3484
+ children: t("crm.tagEditor.done")
3485
+ }
3486
+ )
3487
+ ] })
3488
+ ] });
3489
+ }
3316
3490
  function toLocalDate(value) {
3317
3491
  const year = value.getFullYear();
3318
3492
  const month = String(value.getMonth() + 1).padStart(2, "0");
@@ -3729,6 +3903,17 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
3729
3903
  setMovingStage(false);
3730
3904
  }
3731
3905
  }
3906
+ async function saveTags(next) {
3907
+ if (!deal) return;
3908
+ const prev = deal.tags;
3909
+ setDeal({ ...deal, tags: next });
3910
+ try {
3911
+ await provider.updateDeal(deal.id, { tags: next });
3912
+ } catch {
3913
+ setDeal((d) => d && d.id === deal.id ? { ...d, tags: prev } : d);
3914
+ toast.error(t("crm.tagEditor.saveError"));
3915
+ }
3916
+ }
3732
3917
  async function close(outcome, reason) {
3733
3918
  if (!deal || closing) return;
3734
3919
  setClosing(true);
@@ -3846,7 +4031,7 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
3846
4031
  /* @__PURE__ */ jsx(ThumbsDown, { className: "h-3 w-3" }),
3847
4032
  " ",
3848
4033
  t("crm.card.markLost")
3849
- ] }) : deal ? /* @__PURE__ */ jsxs(
4034
+ ] }) : deal?.status === "won" ? /* @__PURE__ */ jsxs(
3850
4035
  "span",
3851
4036
  {
3852
4037
  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"),
@@ -4326,7 +4511,7 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
4326
4511
  )) })
4327
4512
  }
4328
4513
  ),
4329
- deal && deal.tags.length > 0 && /* @__PURE__ */ jsx(Section, { title: t("crm.dealSidebar.tags"), children: /* @__PURE__ */ jsx(TagChips, { tags: deal.tags, defs: tagDefs, size: "sm", className: "gap-1.5" }) }),
4514
+ deal && /* @__PURE__ */ jsx(Section, { title: t("crm.dealSidebar.tags"), children: /* @__PURE__ */ jsx(TagEditor, { tags: deal.tags, defs: tagDefs, onChange: saveTags }) }),
4330
4515
  /* @__PURE__ */ jsx(FormAnswers, { lead })
4331
4516
  ] })
4332
4517
  ] }) })
@@ -10277,5 +10462,5 @@ function CrmPage({ config, provider, store, registries }) {
10277
10462
  }
10278
10463
 
10279
10464
  export { CrmPage };
10280
- //# sourceMappingURL=CrmPage-QR3MSBZP.js.map
10281
- //# sourceMappingURL=CrmPage-QR3MSBZP.js.map
10465
+ //# sourceMappingURL=CrmPage-ZOHVY2FA.js.map
10466
+ //# sourceMappingURL=CrmPage-ZOHVY2FA.js.map