@fayz-ai/plugin-crm 0.39.2 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{CrmPage-BJASPPQI.js → CrmPage-DLFFHQJP.js} +80 -1111
  2. package/dist/CrmPage-DLFFHQJP.js.map +1 -0
  3. package/dist/CrmQuotesSurface-KLH533QS.js +43 -0
  4. package/dist/CrmQuotesSurface-KLH533QS.js.map +1 -0
  5. package/dist/chunk-5AB4K3PY.js +1166 -0
  6. package/dist/chunk-5AB4K3PY.js.map +1 -0
  7. package/dist/chunk-VI25ZESQ.js +12 -0
  8. package/dist/chunk-VI25ZESQ.js.map +1 -0
  9. package/dist/chunk-ZWUFORDV.js +26 -0
  10. package/dist/chunk-ZWUFORDV.js.map +1 -0
  11. package/dist/components/QuoteAttachments.d.ts +18 -0
  12. package/dist/components/QuoteAttachments.d.ts.map +1 -0
  13. package/dist/components/QuoteClient.d.ts +26 -0
  14. package/dist/components/QuoteClient.d.ts.map +1 -0
  15. package/dist/components/QuoteStatusDropdown.d.ts +2 -0
  16. package/dist/components/QuoteStatusDropdown.d.ts.map +1 -1
  17. package/dist/components/TalkToPerson.d.ts +13 -0
  18. package/dist/components/TalkToPerson.d.ts.map +1 -1
  19. package/dist/data/mock.d.ts.map +1 -1
  20. package/dist/data/supabase.d.ts.map +1 -1
  21. package/dist/data/types.d.ts +7 -1
  22. package/dist/data/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +321 -22
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/crm-scope.d.ts +16 -0
  28. package/dist/lib/crm-scope.d.ts.map +1 -0
  29. package/dist/lib/customer-extensions.d.ts +64 -0
  30. package/dist/lib/customer-extensions.d.ts.map +1 -0
  31. package/dist/lib/deal-headline.d.ts +3 -2
  32. package/dist/lib/deal-headline.d.ts.map +1 -1
  33. package/dist/lib/quote-extensions.d.ts +87 -0
  34. package/dist/lib/quote-extensions.d.ts.map +1 -0
  35. package/dist/locales/en.d.ts.map +1 -1
  36. package/dist/locales/pt-BR.d.ts.map +1 -1
  37. package/dist/types.d.ts +26 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/views/CrmPage.d.ts.map +1 -1
  40. package/dist/views/CrmQuotesSurface.d.ts +26 -0
  41. package/dist/views/CrmQuotesSurface.d.ts.map +1 -0
  42. package/dist/views/CustomersCrudPage.d.ts +23 -0
  43. package/dist/views/CustomersCrudPage.d.ts.map +1 -0
  44. package/dist/views/DistributionView.d.ts.map +1 -1
  45. package/dist/views/LeadDetailView.d.ts.map +1 -1
  46. package/dist/views/LeadListView.d.ts.map +1 -1
  47. package/dist/views/QuoteDetailView.d.ts.map +1 -1
  48. package/dist/views/QuoteEditRoute.d.ts +7 -0
  49. package/dist/views/QuoteEditRoute.d.ts.map +1 -0
  50. package/dist/views/QuoteFormView.d.ts.map +1 -1
  51. package/dist/views/QuoteListView.d.ts +7 -1
  52. package/dist/views/QuoteListView.d.ts.map +1 -1
  53. package/package.json +6 -6
  54. package/dist/CrmPage-BJASPPQI.js.map +0 -1
@@ -2,13 +2,15 @@ import { AssigneeName, formatDocument, DEFAULT_ACTIVITY_TYPES, localPhoneKey, no
2
2
  import { CrmGeneralSettings } from './chunk-CA24LK57.js';
3
3
  import { useCrmUnitFilter, UnitPicker } from './chunk-VFLS65NL.js';
4
4
  import { DotChip, TagChips, loadTeamOrNull, loadMyUserId, humanizeTag, resolveSourceView } from './chunk-EHGAPCZF.js';
5
+ import { dealHeadline, dealHouseLine, QuoteFormView, QuoteListView, QuoteDetailView, QuoteEditRoute, useCanArchive, QuoteStatusDropdown } from './chunk-5AB4K3PY.js';
6
+ import './chunk-ZWUFORDV.js';
5
7
  import { formatCurrency, CrmContextProvider, useCrmProvider, useCrmStore, useCrmConfig } from './chunk-7V46TYYX.js';
6
8
  import React2, { 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, Loader2, Snowflake, Sun, Flame, ThumbsDown, UserRoundPlus, UserRound, Check, Filter, Globe, 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, Network, Building2, CheckCircle2, AlertTriangle, Star, Trash2, MessageSquareQuote, CalendarDays, SignalHigh, CalendarRange, TrendingDown, UserCheck, Settings2, Repeat, Zap, Merge, Fingerprint, Paperclip, ImageOff, CircleAlert, Link2, RefreshCw, ExternalLink, PhoneMissed, MessageSquareOff, PhoneOff, Clipboard, DollarSign, ThumbsUp, SlidersHorizontal, ChevronLeft } from 'lucide-react';
8
- import { Dropdown, DropdownTrigger, Button, PersonAvatar, DropdownContent, PageTransition, ModulePage, useIsWide, PageHeaderActions, usePageSize, toast, FilterChip, MultiSelect, FilterMenu, FilterMenuRow, 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, DropdownItem, PhoneLink, ComingSoon, StatTiles, 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
- import { useTranslation, usePluginRuntimeOptional, currentAppPath, navigateApp, useActiveTenantId, exportCSV, getCurrentLocale, appHref, getSupabaseClientOptional, loadMessageOverrides, resolveMessages, useActiveUnitId, getActiveTenantId } from '@fayz-ai/core';
9
+ import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, PhoneCall, MoveRight, Target, ArrowRightLeft, UserPlus, MapPin, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Loader2, Snowflake, Sun, Flame, ThumbsDown, UserRoundPlus, UserRound, Check, Filter, Globe, ChevronRight, Plus, Settings, Tag, Briefcase, CircleDot, User, Inbox, X, Play, Clock, Download, Sparkles, Calendar, ArrowRight, Network, Building2, CheckCircle2, AlertTriangle, Star, Pencil, Trash2, MessageSquareQuote, CalendarDays, SignalHigh, CalendarRange, TrendingDown, MoreHorizontal, UserCheck, Settings2, Repeat, Zap, Merge, Fingerprint, Paperclip, ImageOff, ChevronDown, Search, Link2, RefreshCw, ExternalLink, Ban, PhoneMissed, MessageSquareOff, PhoneOff, CalendarClock, Clipboard, DollarSign, ThumbsUp, SlidersHorizontal, ChevronLeft } from 'lucide-react';
10
+ import { Dropdown, DropdownTrigger, Button, PersonAvatar, DropdownContent, PageTransition, ModulePage, useIsWide, PageHeaderActions, usePageSize, toast, FilterChip, MultiSelect, FilterMenu, FilterMenuRow, SubpageHeader, ListView, ConfirmDialog, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Textarea, ModalFooter, DataTable, PhoneLink, ComingSoon, StatTiles, Card, Switch, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, DashboardCanvas, DatePicker, Pagination, DropdownItem, PersonPicker, ShellBanner, cn, HeaderTabs, SheetBody, SheetFooter, Popover, PopoverTrigger, PopoverContent, getLucideIcon, DictateButton, ModalDescription, normalizePhone } from '@fayz-ai/ui';
11
+ import { useTranslation, usePluginRuntimeOptional, currentAppPath, navigateApp, useActiveTenantId, exportCSV, getSupabaseClientOptional, appHref, loadMessageOverrides, resolveMessages, useActiveUnitId, getActiveTenantId } from '@fayz-ai/core';
10
12
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
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, invalidateLimit, useAccessOptional, useOrganizationStore, getRailPage, RightRailPage, ContactPicker, useAgentSurface } from '@fayz-ai/admin';
13
+ import { useModuleNavigation, usePluginOnboardingGate, useUnitStore, PluginOnboardingGateSkeleton, createViewRouter, ModuleActionBar, adminNavigateTo, PageActions, usePermissionOptional, usePersistedState, useScrollMemory, useLimitGuard, useRecordVisit, AddressesTab, CrudFormSkeleton, CrudFormPage, CrudDetailSkeleton, CrudDetailPage, AskAIButton, KanbanBoard, InlineField, invalidateLimit, useOrganizationStore, getRailPage, RightRailPage, ContactPicker, PersonLink, useAgentSurface } from '@fayz-ai/admin';
12
14
  import { createPortal } from 'react-dom';
13
15
  import { HelpdeskStatusPanel } from '@fayz-ai/plugin-support';
14
16
 
@@ -658,9 +660,6 @@ function CrmOnboarding({ onComplete }) {
658
660
  function DashboardView() {
659
661
  return /* @__PURE__ */ jsx(DashboardCanvas, { surface: "plugin-home", domain: "crm", showHeader: false, className: "space-y-6" });
660
662
  }
661
- function useCanArchive() {
662
- return useAccessOptional().can("sales", "delete").allowed;
663
- }
664
663
 
665
664
  // src/lib/lost-reasons.ts
666
665
  var LOST_REASONS = ["noInterest", "price", "noBudget", "competitor", "ghosted", "badFit"];
@@ -922,14 +921,6 @@ function dealMatches(deal, query, tagDefs) {
922
921
  ];
923
922
  return haystack.some((v) => v && fold(v).includes(text));
924
923
  }
925
-
926
- // src/lib/deal-headline.ts
927
- function dealHeadline(deal) {
928
- return deal.groupName || deal.companyName || deal.contactName || deal.title || "";
929
- }
930
- function dealHouseLine(deal) {
931
- return deal.groupName && deal.companyName ? deal.companyName : null;
932
- }
933
924
  function periodToRange(period, customFrom, customTo) {
934
925
  if (period === "all") return {};
935
926
  if (period === "24h") {
@@ -2898,173 +2889,6 @@ function DealFunnelView({ onStageClick }) {
2898
2889
  }) })
2899
2890
  ] }) }) });
2900
2891
  }
2901
- var STATUS_CONFIG = {
2902
- draft: { bg: "bg-muted text-muted-foreground", dot: "bg-muted-foreground", icon: CircleDashed, label: "Draft" },
2903
- sent: { bg: "bg-info-soft text-info-soft-foreground", dot: "bg-info", icon: Send, label: "Sent" },
2904
- approved: { bg: "bg-success-soft text-success-soft-foreground", dot: "bg-success", icon: CircleCheckBig, label: "Approved" },
2905
- rejected: { bg: "bg-destructive-soft text-destructive-soft-foreground", dot: "bg-destructive", icon: Ban, label: "Rejected" },
2906
- expired: { bg: "bg-warning-soft text-warning-soft-foreground", dot: "bg-warning", icon: CircleAlert, label: "Expired" },
2907
- archived: { bg: "bg-muted text-muted-foreground", dot: "bg-muted-foreground", icon: Archive, label: "Archived" },
2908
- invoiced: { bg: "bg-warning-soft text-warning-soft-foreground", dot: "bg-warning", icon: Receipt, label: "Invoiced" },
2909
- paid: { bg: "bg-success-soft text-success-soft-foreground", dot: "bg-success", icon: Receipt, label: "Paid" },
2910
- partial: { bg: "bg-warning-soft text-warning-soft-foreground", dot: "bg-warning", icon: Receipt, label: "Partial" },
2911
- overdue: { bg: "bg-destructive-soft text-destructive-soft-foreground", dot: "bg-destructive", icon: Receipt, label: "Overdue" }
2912
- };
2913
- var TRANSITIONS = {
2914
- draft: ["sent", "expired"],
2915
- sent: ["approved", "rejected", "expired"],
2916
- approved: [],
2917
- rejected: [],
2918
- expired: [],
2919
- archived: []
2920
- };
2921
- function RejectModal({ onConfirm, onCancel }) {
2922
- const [reason, setReason] = useState("");
2923
- return /* @__PURE__ */ jsx(Modal, { open: true, onOpenChange: (open) => {
2924
- if (!open) onCancel();
2925
- }, children: /* @__PURE__ */ jsxs(ModalContent, { className: "max-w-sm", children: [
2926
- /* @__PURE__ */ jsxs(ModalHeader, { children: [
2927
- /* @__PURE__ */ jsx(ModalTitle, { children: "Reject Quote" }),
2928
- /* @__PURE__ */ jsx(ModalDescription, { children: "Provide a reason for the rejection." })
2929
- ] }),
2930
- /* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsx(
2931
- Textarea,
2932
- {
2933
- value: reason,
2934
- onChange: (e) => setReason(e.target.value),
2935
- rows: 3,
2936
- placeholder: "Reason for rejection...",
2937
- autoFocus: true,
2938
- className: "resize-none"
2939
- }
2940
- ) }),
2941
- /* @__PURE__ */ jsxs(ModalFooter, { children: [
2942
- /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: onCancel, children: "Cancel" }),
2943
- /* @__PURE__ */ jsx(Button, { variant: "destructive", size: "sm", onClick: () => onConfirm(reason), disabled: !reason.trim(), children: "Reject Quote" })
2944
- ] })
2945
- ] }) });
2946
- }
2947
- function QuoteStatusDropdown({ quote, onStatusChange, size = "default" }) {
2948
- const sendQuote = useCrmStore((s) => s.sendQuote);
2949
- const approveQuote = useCrmStore((s) => s.approveQuote);
2950
- const rejectQuote = useCrmStore((s) => s.rejectQuote);
2951
- const expireQuote = useCrmStore((s) => s.expireQuote);
2952
- const [loading, setLoading] = useState(false);
2953
- const [showApprove, setShowApprove] = useState(false);
2954
- const [showReject, setShowReject] = useState(false);
2955
- const config = STATUS_CONFIG[quote.status] ?? STATUS_CONFIG.draft;
2956
- const StatusIcon = config.icon;
2957
- const transitions = TRANSITIONS[quote.status] ?? [];
2958
- async function handleTransition(target) {
2959
- if (loading) return;
2960
- setLoading(true);
2961
- try {
2962
- let updated;
2963
- switch (target) {
2964
- case "sent":
2965
- updated = await sendQuote(quote.id);
2966
- break;
2967
- case "approved":
2968
- setShowApprove(true);
2969
- setLoading(false);
2970
- return;
2971
- case "expired":
2972
- updated = await expireQuote(quote.id);
2973
- break;
2974
- default:
2975
- setLoading(false);
2976
- return;
2977
- }
2978
- onStatusChange?.(updated);
2979
- } catch {
2980
- } finally {
2981
- setLoading(false);
2982
- }
2983
- }
2984
- async function handleReject(reason) {
2985
- setShowReject(false);
2986
- setLoading(true);
2987
- try {
2988
- const updated = await rejectQuote(quote.id, reason);
2989
- onStatusChange?.(updated);
2990
- } catch {
2991
- } finally {
2992
- setLoading(false);
2993
- }
2994
- }
2995
- const isSmall = size === "sm";
2996
- if (transitions.length === 0) {
2997
- return /* @__PURE__ */ jsxs("span", { className: `inline-flex items-center gap-1 rounded-full font-medium capitalize ${config.bg} ${isSmall ? "px-1.5 py-0.5 text-[9px]" : "px-2.5 py-1 text-[11px]"}`, children: [
2998
- !isSmall && /* @__PURE__ */ jsx(StatusIcon, { className: "h-3 w-3" }),
2999
- config.label
3000
- ] });
3001
- }
3002
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3003
- /* @__PURE__ */ jsxs(Dropdown, { children: [
3004
- /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
3005
- Button,
3006
- {
3007
- variant: "bare",
3008
- size: "bare",
3009
- onClick: (e) => e.stopPropagation(),
3010
- disabled: loading,
3011
- className: `gap-1 rounded-full font-medium capitalize transition-all ${config.bg} ${isSmall ? "px-1.5 py-0.5 text-[9px]" : "px-2.5 py-1 text-[11px]"} hover:ring-2 hover:ring-primary/20 focus:outline-none focus:ring-2 focus:ring-ring`,
3012
- children: [
3013
- !isSmall && /* @__PURE__ */ jsx(StatusIcon, { className: "h-3 w-3" }),
3014
- config.label,
3015
- loading ? /* @__PURE__ */ jsx(Loader2, { className: `animate-spin ${isSmall ? "h-2.5 w-2.5" : "h-3 w-3"}` }) : /* @__PURE__ */ jsx(ChevronDown, { className: `opacity-50 ${isSmall ? "h-2.5 w-2.5" : "h-3 w-3"}` })
3016
- ]
3017
- }
3018
- ) }),
3019
- /* @__PURE__ */ jsxs(DropdownContent, { align: "end", sideOffset: 4, onClick: (e) => e.stopPropagation(), children: [
3020
- /* @__PURE__ */ jsx(DropdownLabel, { children: "Change status" }),
3021
- /* @__PURE__ */ jsx(DropdownSeparator, {}),
3022
- transitions.map((target) => {
3023
- const t = STATUS_CONFIG[target];
3024
- const TargetIcon = t.icon;
3025
- return /* @__PURE__ */ jsxs(
3026
- DropdownItem,
3027
- {
3028
- onClick: () => target === "rejected" ? setShowReject(true) : handleTransition(target),
3029
- className: "gap-2.5",
3030
- children: [
3031
- /* @__PURE__ */ jsx("span", { className: `h-2 w-2 rounded-full shrink-0 ${t.dot}` }),
3032
- /* @__PURE__ */ jsx(TargetIcon, { className: "h-3.5 w-3.5 shrink-0" }),
3033
- /* @__PURE__ */ jsx("span", { children: t.label })
3034
- ]
3035
- },
3036
- target
3037
- );
3038
- })
3039
- ] })
3040
- ] }),
3041
- /* @__PURE__ */ jsx(
3042
- ConfirmDialog,
3043
- {
3044
- open: showApprove,
3045
- variant: "success",
3046
- title: "Approve this quote?",
3047
- description: "This will create an invoice and convert the lead to a client. This action cannot be undone.",
3048
- confirmLabel: "Approve",
3049
- cancelLabel: "Cancel",
3050
- loading,
3051
- onConfirm: async () => {
3052
- setLoading(true);
3053
- try {
3054
- const updated = await approveQuote(quote.id);
3055
- setShowApprove(false);
3056
- onStatusChange?.(updated);
3057
- } catch {
3058
- } finally {
3059
- setLoading(false);
3060
- }
3061
- },
3062
- onCancel: () => setShowApprove(false)
3063
- }
3064
- ),
3065
- showReject && /* @__PURE__ */ jsx(RejectModal, { onConfirm: handleReject, onCancel: () => setShowReject(false) })
3066
- ] });
3067
- }
3068
2892
 
3069
2893
  // src/lib/form-answers.tsx
3070
2894
  function humanizeKey(key) {
@@ -3360,6 +3184,24 @@ function href(personId, name, phone) {
3360
3184
  function WhatsAppGlyph({ className }) {
3361
3185
  return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", className, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.52.149-.174.198-.298.297-.497.1-.198.05-.371-.025-.52-.074-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z" }) });
3362
3186
  }
3187
+ function useTalkToPersonAction(personId, name, phone) {
3188
+ const t = useTranslation();
3189
+ let talkChannel = "whatsapp";
3190
+ try {
3191
+ talkChannel = useCrmConfig().talkChannel ?? "whatsapp";
3192
+ } catch {
3193
+ }
3194
+ const canTalk = useCanTalk();
3195
+ if (!phone) return null;
3196
+ const viaInbox = talkChannel === "conversations" && canTalk;
3197
+ return {
3198
+ label: t("crm.leadDetail.whatsapp"),
3199
+ go: () => {
3200
+ if (viaInbox) adminNavigateTo(href(personId, name ?? "", phone));
3201
+ else window.open(`https://wa.me/${phone.replace(/\D/g, "")}`, "_blank", "noopener,noreferrer");
3202
+ }
3203
+ };
3204
+ }
3363
3205
  function TalkToPerson({ personId, name, phone, variant = "button", className }) {
3364
3206
  const t = useTranslation();
3365
3207
  let talkChannel = "whatsapp";
@@ -5560,7 +5402,9 @@ var buildColumns = (t, leads, scores) => [
5560
5402
  //
5561
5403
  // Coluna sem cabeçalho e ícone só: um rótulo aqui rouba largura das
5562
5404
  // colunas que a pessoa está lendo para decidir com quem falar.
5563
- id: "talk",
5405
+ // `actions` by name: the table pins that column to the right edge, so the
5406
+ // button stays in view while the wide list scrolls — as the invoice list does.
5407
+ id: "actions",
5564
5408
  header: "",
5565
5409
  enableSorting: false,
5566
5410
  cell: ({ row }) => /* @__PURE__ */ jsx(
@@ -6168,863 +6012,6 @@ function LeadListView({ onNew, onEdit }) {
6168
6012
  )
6169
6013
  ] });
6170
6014
  }
6171
- var QUOTE_STATUSES = ["draft", "sent", "approved", "rejected", "expired", "archived"];
6172
- var STATUS_COLORS = {
6173
- draft: "bg-muted text-muted-foreground",
6174
- sent: "bg-info-soft text-info-soft-foreground",
6175
- approved: "bg-success-soft text-success-soft-foreground",
6176
- rejected: "bg-destructive-soft text-destructive-soft-foreground",
6177
- expired: "bg-warning-soft text-warning-soft-foreground",
6178
- invoiced: "bg-warning-soft text-warning-soft-foreground",
6179
- paid: "bg-success-soft text-success-soft-foreground",
6180
- partial: "bg-warning-soft text-warning-soft-foreground",
6181
- overdue: "bg-destructive-soft text-destructive-soft-foreground",
6182
- cancelled: "bg-muted text-muted-foreground"
6183
- };
6184
- function useQuoteColumns(currency, onEditQuote, onArchive) {
6185
- const t = useTranslation();
6186
- const cols = [
6187
- { accessorKey: "quoteNumber", header: "#", cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: getValue() }) },
6188
- { accessorKey: "contactName", header: t("crm.quotes.contact"), cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "font-medium", children: getValue() || "\u2014" }) },
6189
- { accessorKey: "quoteDate", header: t("crm.quotes.date"), cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: getValue() }) },
6190
- {
6191
- accessorKey: "totalAmount",
6192
- header: t("crm.quotes.amount"),
6193
- cell: ({ getValue }) => /* @__PURE__ */ jsx("span", { className: "font-medium", children: formatCurrency(getValue(), currency) })
6194
- },
6195
- {
6196
- accessorKey: "status",
6197
- header: t("crm.quotes.status"),
6198
- cell: ({ getValue }) => {
6199
- const status = getValue();
6200
- return /* @__PURE__ */ jsx("span", { className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${STATUS_COLORS[status] ?? "bg-muted text-muted-foreground"}`, children: t(`crm.quotes.status.${status}`) });
6201
- }
6202
- }
6203
- ];
6204
- if (onEditQuote || onArchive) {
6205
- cols.push({
6206
- id: "actions",
6207
- header: "",
6208
- cell: ({ row }) => /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-0.5", children: [
6209
- onEditQuote && /* @__PURE__ */ jsx(
6210
- Button,
6211
- {
6212
- variant: "ghost",
6213
- size: "icon",
6214
- onClick: (e) => {
6215
- e.stopPropagation();
6216
- onEditQuote(row.original.id);
6217
- },
6218
- className: "h-7 w-7 rounded-md text-muted-foreground",
6219
- title: "Edit quote",
6220
- children: /* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5" })
6221
- }
6222
- ),
6223
- onArchive && /* @__PURE__ */ jsxs(Dropdown, { children: [
6224
- /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
6225
- Button,
6226
- {
6227
- variant: "ghost",
6228
- size: "icon",
6229
- onClick: (e) => e.stopPropagation(),
6230
- "aria-label": t("crm.quotes.moreActions"),
6231
- className: "h-7 w-7 rounded-md text-muted-foreground",
6232
- children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-3.5 w-3.5" })
6233
- }
6234
- ) }),
6235
- /* @__PURE__ */ jsx(DropdownContent, { align: "end", children: /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => onArchive(row.original.id), children: [
6236
- /* @__PURE__ */ jsx(Archive, { className: "h-3.5 w-3.5" }),
6237
- " ",
6238
- t("crm.quotes.archive")
6239
- ] }) })
6240
- ] })
6241
- ] })
6242
- });
6243
- }
6244
- return cols;
6245
- }
6246
- function QuoteListView({ onNew, onEdit, onEditQuote }) {
6247
- const t = useTranslation();
6248
- const { currency } = useCrmConfig();
6249
- const quotes = useCrmStore((s) => s.quotes);
6250
- const quotesLoading = useCrmStore((s) => s.quotesLoading);
6251
- const fetchQuotes = useCrmStore((s) => s.fetchQuotes);
6252
- const archiveQuote = useCrmStore((s) => s.archiveQuote);
6253
- const canArchive = useCanArchive();
6254
- const hoje = useMemo(() => {
6255
- const d = /* @__PURE__ */ new Date();
6256
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
6257
- }, []);
6258
- const noventaDiasAtras = useMemo(() => {
6259
- const d = /* @__PURE__ */ new Date();
6260
- d.setDate(d.getDate() - 89);
6261
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
6262
- }, []);
6263
- const filtros = useFilterDraft(
6264
- { from: noventaDiasAtras, to: hoje, status: [], contactId: "", contactName: "", search: "" },
6265
- { persistKey: "crm.quotes" }
6266
- );
6267
- const { draft, applied, patch } = filtros;
6268
- const contactLookup = useMemo(
6269
- () => createArchetypeLookup({ archetype: "person", kind: ["customer", "lead"] }),
6270
- []
6271
- );
6272
- const limparFiltros = () => patch({ status: [], contactId: "", contactName: "", search: "" });
6273
- const filtrosAtivos = (draft.status.length > 0 ? 1 : 0) + (draft.contactId ? 1 : 0) + (draft.search.trim() ? 1 : 0);
6274
- useEffect(() => {
6275
- const search = applied.search.trim();
6276
- fetchQuotes({
6277
- dateRange: { from: applied.from, to: applied.to },
6278
- status: applied.status.length > 0 ? applied.status : void 0,
6279
- contactId: applied.contactId || void 0,
6280
- search: search || void 0
6281
- });
6282
- }, [applied]);
6283
- const [alvoArquivo, setAlvoArquivo] = useState(null);
6284
- const columns = useQuoteColumns(currency, onEditQuote, canArchive ? setAlvoArquivo : void 0);
6285
- const exportRows = useCallback(() => {
6286
- exportCSV(
6287
- [
6288
- { key: "quoteNumber", label: "#" },
6289
- { key: "quoteDate", label: t("crm.quotes.date") },
6290
- { key: "contactName", label: t("crm.quotes.contact") },
6291
- { key: "totalAmount", label: t("crm.quotes.amount"), format: (v) => formatCurrency(Number(v) || 0, currency) },
6292
- { key: "status", label: t("crm.quotes.status") },
6293
- { key: "validUntil", label: t("crm.quoteForm.validUntil") }
6294
- ],
6295
- quotes,
6296
- "orcamentos"
6297
- );
6298
- toast.success(t("crud.export.toastSuccess", { count: String(quotes.length) }));
6299
- }, [quotes, currency, t]);
6300
- const ancoraRolagem = useScrollMemory("crm.quotes");
6301
- return /* @__PURE__ */ jsxs("div", { ref: ancoraRolagem, className: "space-y-4", children: [
6302
- /* @__PURE__ */ jsx(
6303
- SubpageHeader,
6304
- {
6305
- title: t("crm.quotes.title"),
6306
- actions: /* @__PURE__ */ jsx(Fragment, { children: (onNew || quotes.length > 0) && /* @__PURE__ */ jsx(
6307
- PageActions,
6308
- {
6309
- actions: [
6310
- ...onNew ? [{ id: "new-quote", label: t("crm.quotes.newQuote"), icon: Plus, intent: "primary", onSelect: onNew }] : [],
6311
- // 'utility': ícone só, ao lado do primário — o mesmo lugar que o
6312
- // exportar ocupa em toda lista de CRUD.
6313
- ...quotes.length > 0 ? [{ id: "export", label: t("crud.export.action"), icon: Download, intent: "utility", desktopOnly: true, onSelect: exportRows }] : []
6314
- ]
6315
- }
6316
- ) })
6317
- }
6318
- ),
6319
- /* @__PURE__ */ jsxs(
6320
- FilterPanel,
6321
- {
6322
- title: t("crm.quotes.filtersTitle"),
6323
- onApply: filtros.apply,
6324
- applyLabel: t("crm.quotes.filterApply"),
6325
- onClear: filtrosAtivos > 0 ? limparFiltros : void 0,
6326
- clearLabel: t("crm.quotes.filterClear"),
6327
- busy: quotesLoading,
6328
- children: [
6329
- /* @__PURE__ */ jsx(FilterPanelField, { label: t("crm.quotes.filterFrom"), children: /* @__PURE__ */ jsx(DatePicker, { variant: "input", format: "numeric", className: "w-full", value: draft.from, onChange: (v) => v && patch({ from: v }) }) }),
6330
- /* @__PURE__ */ jsx(FilterPanelField, { label: t("crm.quotes.filterTo"), children: /* @__PURE__ */ jsx(DatePicker, { variant: "input", format: "numeric", className: "w-full", value: draft.to, onChange: (v) => v && patch({ to: v }) }) }),
6331
- /* @__PURE__ */ jsx(FilterPanelField, { label: t("crm.quotes.status"), children: /* @__PURE__ */ jsx(
6332
- RequiredFilter,
6333
- {
6334
- label: t("crm.quotes.status"),
6335
- value: draft.status.length === 0 ? t("crm.quotes.filterAllStatuses") : draft.status.length === 1 ? t(`crm.quotes.status.${draft.status[0]}`) : t("crud.list.selectedMany", { count: draft.status.length }),
6336
- icon: CircleDashed,
6337
- className: "h-9 w-full justify-start",
6338
- align: "start",
6339
- children: /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
6340
- /* @__PURE__ */ jsx(FilterMenuRow, { active: draft.status.length === 0, onClick: () => patch({ status: [] }), children: t("crm.quotes.filterAllStatuses") }),
6341
- QUOTE_STATUSES.map((st) => {
6342
- const on = draft.status.includes(st);
6343
- return /* @__PURE__ */ jsx(
6344
- FilterMenuRow,
6345
- {
6346
- active: on,
6347
- onClick: () => patch({ status: on ? draft.status.filter((v) => v !== st) : [...draft.status, st] }),
6348
- children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t(`crm.quotes.status.${st}`) })
6349
- },
6350
- st
6351
- );
6352
- })
6353
- ] })
6354
- }
6355
- ) }),
6356
- /* @__PURE__ */ jsx(FilterPanelField, { label: t("crm.quotes.contact"), compact: true, children: /* @__PURE__ */ jsx(
6357
- SearchSelect,
6358
- {
6359
- className: "w-full",
6360
- value: draft.contactId,
6361
- displayValue: draft.contactName,
6362
- placeholder: t("crm.quotes.filterContactPlaceholder"),
6363
- minChars: 2,
6364
- minCharsLabel: t("crm.quotes.filterMinChars"),
6365
- noResultsLabel: t("crm.quotes.filterNoContact"),
6366
- searchingLabel: t("crm.quotes.filterSearching"),
6367
- loadOnOpen: false,
6368
- clearLabel: t("crm.quotes.filterAllContacts"),
6369
- onChange: (id, option) => patch({ contactId: id, contactName: option?.label ?? "" }),
6370
- onSearch: async (termo) => {
6371
- const results = await contactLookup.search(termo);
6372
- return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
6373
- }
6374
- }
6375
- ) })
6376
- ]
6377
- }
6378
- ),
6379
- /* @__PURE__ */ jsxs(Card, { className: "relative px-3 py-1.5", children: [
6380
- /* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
6381
- /* @__PURE__ */ jsx(
6382
- Input,
6383
- {
6384
- type: "text",
6385
- value: draft.search,
6386
- onChange: (e) => patch({ search: e.target.value }),
6387
- onKeyDown: (e) => {
6388
- if (e.key === "Enter") filtros.apply();
6389
- },
6390
- placeholder: t("crm.quotes.searchPlaceholder"),
6391
- "aria-label": t("crm.quotes.searchPlaceholder"),
6392
- 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"
6393
- }
6394
- )
6395
- ] }),
6396
- /* @__PURE__ */ jsx(
6397
- DataTable,
6398
- {
6399
- columns,
6400
- data: quotesLoading ? [] : quotes,
6401
- loading: quotesLoading,
6402
- onRowClick: (row) => onEdit?.(row.id),
6403
- emptyMessage: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1 py-6", children: [
6404
- /* @__PURE__ */ jsx(FileText, { className: "mb-2 h-9 w-9 text-muted-foreground/40", strokeWidth: 1.5 }),
6405
- /* @__PURE__ */ jsx("p", { className: "text-base font-semibold text-foreground", children: t("crm.quotes.noQuotes") }),
6406
- onNew && /* @__PURE__ */ jsx(Button, { size: "lg", onClick: onNew, className: "mt-3 px-3 font-medium", children: t("crm.quotes.createFirst") })
6407
- ] })
6408
- }
6409
- ),
6410
- /* @__PURE__ */ jsx(
6411
- ConfirmDialog,
6412
- {
6413
- open: alvoArquivo !== null,
6414
- onCancel: () => setAlvoArquivo(null),
6415
- variant: "destructive",
6416
- title: t("crm.quotes.archiveTitle"),
6417
- description: t("crm.quotes.archiveDescription"),
6418
- confirmLabel: t("crm.quotes.archive"),
6419
- onConfirm: async () => {
6420
- if (alvoArquivo) await archiveQuote(alvoArquivo);
6421
- setAlvoArquivo(null);
6422
- }
6423
- }
6424
- )
6425
- ] });
6426
- }
6427
- var STATUSES = [
6428
- { value: "draft", labelKey: "crm.quoteForm.statusDraft", color: "bg-primary text-primary-foreground" },
6429
- { value: "sent", labelKey: "crm.quoteForm.statusSent", color: "bg-info-soft text-info-soft-foreground border border-info/30 dark:border-info/30" },
6430
- { value: "approved", labelKey: "crm.quoteForm.statusApproved", color: "bg-success-soft text-success-soft-foreground border border-success/30 dark:border-success/30" },
6431
- { value: "rejected", labelKey: "crm.quoteForm.statusRejected", color: "bg-destructive-soft text-destructive-soft-foreground border border-destructive/30 dark:border-destructive/30" },
6432
- { value: "expired", labelKey: "crm.quoteForm.statusExpired", color: "bg-muted text-muted-foreground border" }
6433
- ];
6434
- var VALIDITY_PRESETS = [
6435
- { days: 7, labelKey: "crm.quoteForm.validOneWeek" },
6436
- { days: 30, labelKey: "crm.quoteForm.validThirtyDays" }
6437
- ];
6438
- function addDays(iso, days) {
6439
- const d = /* @__PURE__ */ new Date(`${iso}T12:00:00`);
6440
- d.setDate(d.getDate() + days);
6441
- return d.toISOString().slice(0, 10);
6442
- }
6443
- function daysBetween(from, to) {
6444
- const ms = (/* @__PURE__ */ new Date(`${to}T12:00:00`)).getTime() - (/* @__PURE__ */ new Date(`${from}T12:00:00`)).getTime();
6445
- return Math.round(ms / 864e5);
6446
- }
6447
- var fid = 1;
6448
- function nextId() {
6449
- return `qi${fid++}`;
6450
- }
6451
- function QuoteFormView({ quoteId, leadId, onSaved }) {
6452
- const t = useTranslation();
6453
- const config = useCrmConfig();
6454
- const provider = useCrmProvider();
6455
- const { currency, itemTypes: declaredItemTypes } = config;
6456
- const translatedItemTypes = React2.useMemo(
6457
- () => declaredItemTypes.map((tp) => {
6458
- const traduzido = t(`crm.itemType.${tp.value}`);
6459
- return traduzido === `crm.itemType.${tp.value}` ? tp : { ...tp, label: traduzido };
6460
- }),
6461
- [declaredItemTypes, t]
6462
- );
6463
- const itemTypes = useCatalogedItemTypes(translatedItemTypes, config.entityLookups);
6464
- const createQuote = useCrmStore((s) => s.createQuote);
6465
- const updateQuote = useCrmStore((s) => s.updateQuote);
6466
- const guardQuotes = useLimitGuard("quotes");
6467
- const isEdit = !!quoteId;
6468
- const [loadingExisting, setLoadingExisting] = useState(isEdit || !!leadId);
6469
- const [linkedLeadId, setLinkedLeadId] = useState(leadId ?? "");
6470
- const [linkedDealId, setLinkedDealId] = useState("");
6471
- const [contactName, setContactName] = useState("");
6472
- const [contactId, setContactId] = useState("");
6473
- const [quoteDate, setQuoteDate] = useState((/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
6474
- const [validUntil, setValidUntil] = useState(() => {
6475
- const d = /* @__PURE__ */ new Date();
6476
- d.setDate(d.getDate() + 30);
6477
- return d.toISOString().slice(0, 10);
6478
- });
6479
- const [validityDays, setValidityDays] = useState(30);
6480
- const [currentStatus, setCurrentStatus] = useState("draft");
6481
- const [paymentConditions, setPaymentConditions] = useState("");
6482
- const [observations, setObservations] = useState("");
6483
- const [items, setItems] = useState([]);
6484
- const [expandedItemId, setExpandedItemId] = useState(null);
6485
- const [addingItem, setAddingItem] = useState(false);
6486
- const [saving, setSaving] = useState(false);
6487
- useEffect(() => {
6488
- if (!quoteId) return;
6489
- provider.getQuoteById(quoteId).then((q) => {
6490
- if (q) {
6491
- setContactName(q.contactName ?? "");
6492
- setContactId(q.contactId ?? "");
6493
- setLinkedLeadId(q.leadId ?? "");
6494
- setLinkedDealId(q.dealId ?? "");
6495
- setQuoteDate(q.quoteDate);
6496
- setValidUntil(q.validUntil);
6497
- const span = daysBetween(q.quoteDate, q.validUntil);
6498
- setValidityDays(VALIDITY_PRESETS.some((pr) => pr.days === span) ? span : null);
6499
- setCurrentStatus(q.status);
6500
- setPaymentConditions(q.paymentConditions ?? "");
6501
- setObservations(q.observations ?? "");
6502
- setItems(q.items.map((it) => ({
6503
- _id: nextId(),
6504
- itemKind: it.itemKind,
6505
- description: it.description,
6506
- quantity: it.quantity,
6507
- unitPrice: it.unitPrice,
6508
- discount: it.discount
6509
- })));
6510
- }
6511
- setLoadingExisting(false);
6512
- });
6513
- }, [quoteId]);
6514
- useEffect(() => {
6515
- if (!leadId || quoteId) return;
6516
- provider.getLeadById(leadId).then(async (lead) => {
6517
- if (lead) {
6518
- setContactName(lead.name);
6519
- setContactId(lead.id);
6520
- setLinkedLeadId(lead.id);
6521
- const deal = await provider.getDealByLeadId(lead.id);
6522
- if (deal) setLinkedDealId(deal.id);
6523
- }
6524
- setLoadingExisting(false);
6525
- });
6526
- }, [leadId]);
6527
- function changeQuoteDate(iso) {
6528
- setQuoteDate(iso);
6529
- if (validityDays !== null) setValidUntil(addDays(iso, validityDays));
6530
- }
6531
- const openCustomOnMount = React2.useRef(false);
6532
- function pickValidity(days) {
6533
- openCustomOnMount.current = days === null && validityDays !== null;
6534
- setValidityDays(days);
6535
- if (days !== null) setValidUntil(addDays(quoteDate, days));
6536
- }
6537
- const totalAmount = items.reduce((sum, it) => sum + (it.quantity * it.unitPrice - it.discount), 0);
6538
- function startAddItem() {
6539
- if (itemTypes.length === 1) {
6540
- addItemOfKind(itemTypes[0].value);
6541
- return;
6542
- }
6543
- setAddingItem(true);
6544
- }
6545
- function addItemOfKind(kind) {
6546
- const newItem = { _id: nextId(), itemKind: kind, description: "", quantity: 1, unitPrice: 0, discount: 0 };
6547
- setItems([...items, newItem]);
6548
- setExpandedItemId(newItem._id);
6549
- setAddingItem(false);
6550
- }
6551
- function updateItem(id, data) {
6552
- setItems(items.map((it) => it._id === id ? { ...it, ...data } : it));
6553
- }
6554
- function removeItem(id) {
6555
- setItems(items.filter((it) => it._id !== id));
6556
- if (expandedItemId === id) setExpandedItemId(null);
6557
- }
6558
- async function handleSave() {
6559
- if (items.length === 0) {
6560
- toast.error(t("crm.quoteForm.errNoItems"));
6561
- return;
6562
- }
6563
- if (!isEdit && await guardQuotes() === "blocked") return;
6564
- setSaving(true);
6565
- try {
6566
- const input = {
6567
- contactId: contactId || void 0,
6568
- contactName: contactName || void 0,
6569
- leadId: linkedLeadId || void 0,
6570
- dealId: linkedDealId || void 0,
6571
- quoteDate,
6572
- validUntil,
6573
- paymentConditions: paymentConditions || void 0,
6574
- observations: observations || void 0,
6575
- items: items.map((it) => ({
6576
- itemKind: it.itemKind,
6577
- description: it.description,
6578
- quantity: it.quantity,
6579
- unitPrice: it.unitPrice,
6580
- discount: it.discount,
6581
- totalAmount: it.quantity * it.unitPrice - it.discount
6582
- }))
6583
- };
6584
- if (isEdit) {
6585
- await updateQuote(quoteId, input);
6586
- onSaved?.(quoteId);
6587
- } else {
6588
- const created = await createQuote(input);
6589
- invalidateLimit("quotes");
6590
- onSaved?.(created?.id);
6591
- }
6592
- } finally {
6593
- setSaving(false);
6594
- }
6595
- }
6596
- const currentFields = {
6597
- contactId,
6598
- contactName,
6599
- linkedLeadId,
6600
- linkedDealId,
6601
- quoteDate,
6602
- validUntil,
6603
- currentStatus,
6604
- paymentConditions,
6605
- observations,
6606
- items: items.map((it) => ({ itemKind: it.itemKind, description: it.description, quantity: it.quantity, unitPrice: it.unitPrice, discount: it.discount }))
6607
- };
6608
- const snapshot = React2.useRef(null);
6609
- useEffect(() => {
6610
- if (!loadingExisting && snapshot.current === null) snapshot.current = JSON.stringify(currentFields);
6611
- }, [loadingExisting]);
6612
- const dirty = snapshot.current !== null && JSON.stringify(currentFields) !== snapshot.current;
6613
- useSaveBar({
6614
- dirty,
6615
- saving,
6616
- onSave: () => {
6617
- void handleSave();
6618
- },
6619
- onDiscard: () => onSaved?.(),
6620
- saveLabel: isEdit ? t("crm.quoteForm.saveChanges") : t("crm.quoteForm.saveQuote")
6621
- });
6622
- if (loadingExisting) return /* @__PURE__ */ jsx(OrderFormSkeleton, { parentLabel: t("crm.quotes.title"), onBack: () => onSaved?.() });
6623
- const money = (v) => formatCurrency(v, currency);
6624
- const validUntilLabel = (/* @__PURE__ */ new Date(`${validUntil}T12:00:00`)).toLocaleDateString(getCurrentLocale());
6625
- const contactSection = /* @__PURE__ */ jsx(OrderFormBlock, { title: t("crm.quoteForm.client"), children: /* @__PURE__ */ jsx(
6626
- SearchSelect,
6627
- {
6628
- value: contactId,
6629
- displayValue: contactName,
6630
- onChange: (id, opt) => {
6631
- setContactId(id);
6632
- setContactName(opt?.label ?? "");
6633
- },
6634
- onSearch: async (q) => {
6635
- if (!config.contactLookup) return [];
6636
- const results = await config.contactLookup.search(q);
6637
- return results.map((r) => ({ id: r.id, label: r.label, subtitle: r.subtitle, group: r.group, data: r }));
6638
- },
6639
- required: true,
6640
- placeholder: t("crm.quoteForm.searchClient"),
6641
- allowCreate: true,
6642
- createLabel: t("crm.quoteForm.addAsLead"),
6643
- onCreate: async (name) => {
6644
- const lead = await provider.createLead({ name });
6645
- setContactId(lead.id);
6646
- setContactName(lead.name);
6647
- }
6648
- }
6649
- ) });
6650
- const sideSections = /* @__PURE__ */ jsxs(Fragment, { children: [
6651
- /* @__PURE__ */ jsx(OrderFormBlock, { title: t("crm.quoteForm.quoteDetails"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
6652
- /* @__PURE__ */ jsxs("div", { children: [
6653
- /* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t("crm.quoteForm.quoteDate") }),
6654
- /* @__PURE__ */ jsx(DatePicker, { value: quoteDate, onChange: changeQuoteDate, className: "mt-1" })
6655
- ] }),
6656
- /* @__PURE__ */ jsxs("div", { children: [
6657
- /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
6658
- /* @__PURE__ */ jsx("label", { className: "text-xs font-medium text-muted-foreground", children: t("crm.quoteForm.validUntil") }),
6659
- validityDays === null ? /* @__PURE__ */ jsx(
6660
- DatePicker,
6661
- {
6662
- variant: "inline",
6663
- format: "numeric",
6664
- value: validUntil,
6665
- onChange: setValidUntil,
6666
- defaultOpen: openCustomOnMount.current
6667
- }
6668
- ) : /* @__PURE__ */ jsx("span", { className: "text-xs tabular-nums text-foreground", children: validUntilLabel })
6669
- ] }),
6670
- /* @__PURE__ */ jsxs("div", { className: "mt-1 flex flex-wrap gap-1.5", children: [
6671
- VALIDITY_PRESETS.map((preset) => /* @__PURE__ */ jsx(
6672
- Button,
6673
- {
6674
- type: "button",
6675
- variant: "bare",
6676
- size: "bare",
6677
- onClick: () => pickValidity(preset.days),
6678
- className: `rounded-full border px-2.5 py-1 text-xs font-normal ${validityDays === preset.days ? "border-primary bg-primary text-primary-foreground" : "border-input bg-card text-muted-foreground hover:bg-muted/50"}`,
6679
- children: t(preset.labelKey)
6680
- },
6681
- preset.days
6682
- )),
6683
- /* @__PURE__ */ jsx(
6684
- Button,
6685
- {
6686
- type: "button",
6687
- variant: "bare",
6688
- size: "bare",
6689
- onClick: () => pickValidity(null),
6690
- className: `rounded-full border px-2.5 py-1 text-xs font-normal ${validityDays === null ? "border-primary bg-primary text-primary-foreground" : "border-input bg-card text-muted-foreground hover:bg-muted/50"}`,
6691
- children: t("crm.quoteForm.validCustom")
6692
- }
6693
- )
6694
- ] })
6695
- ] })
6696
- ] }) }),
6697
- /* @__PURE__ */ jsx(OrderFormBlock, { title: t("crm.quoteForm.paymentConditions"), children: /* @__PURE__ */ jsx(
6698
- Textarea,
6699
- {
6700
- value: paymentConditions,
6701
- onChange: (e) => setPaymentConditions(e.target.value),
6702
- rows: 2,
6703
- placeholder: t("crm.quoteForm.paymentConditionsPlaceholder"),
6704
- className: "min-h-0 resize-none"
6705
- }
6706
- ) }),
6707
- /* @__PURE__ */ jsx(OrderFormBlock, { title: t("crm.quoteForm.notes"), children: /* @__PURE__ */ jsx(
6708
- Textarea,
6709
- {
6710
- value: observations,
6711
- onChange: (e) => setObservations(e.target.value),
6712
- rows: 2,
6713
- placeholder: t("crm.quoteForm.notesPlaceholder"),
6714
- className: "min-h-0 resize-none"
6715
- }
6716
- ) })
6717
- ] });
6718
- return /* @__PURE__ */ jsxs(
6719
- OrderFormView,
6720
- {
6721
- sideSections,
6722
- title: isEdit ? t("crm.quoteForm.editTitle") : t("crm.quoteForm.newTitle"),
6723
- parentLabel: t("crm.quotes.title"),
6724
- onBack: () => onSaved?.(),
6725
- badges: /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: STATUSES.map((s) => /* @__PURE__ */ jsx(
6726
- "span",
6727
- {
6728
- className: `inline-flex items-center rounded-full px-3 py-1 text-xs font-medium ${s.value === currentStatus ? s.color : "bg-muted/30 text-muted-foreground/50"}`,
6729
- children: t(s.labelKey)
6730
- },
6731
- s.value
6732
- )) }),
6733
- children: [
6734
- contactSection,
6735
- /* @__PURE__ */ jsx(
6736
- OrderFormItemsCard,
6737
- {
6738
- label: t("crm.quoteForm.quoteItems"),
6739
- addLabel: t("crm.quoteForm.addItem"),
6740
- onAdd: startAddItem,
6741
- addDisabled: !contactId,
6742
- addDisabledHint: t("crm.quoteForm.selectClientFirst"),
6743
- count: items.length,
6744
- countLabel: t("crm.quoteForm.itemCount", { count: String(items.length) }),
6745
- totalLabel: t("crm.quoteForm.total"),
6746
- total: money(totalAmount),
6747
- emptyLabel: contactId ? t("crm.quoteForm.noItems") : t("crm.quoteForm.selectClientFirst"),
6748
- emptyActionLabel: t("crm.quoteForm.addFirstItem"),
6749
- header: addingItem && /* @__PURE__ */ jsx(
6750
- OrderFormAddItemStep,
6751
- {
6752
- itemTypes,
6753
- onSelect: addItemOfKind,
6754
- onCancel: () => setAddingItem(false),
6755
- label: t("crm.quoteForm.selectItemType"),
6756
- cancelLabel: t("crm.quoteForm.cancel")
6757
- }
6758
- ),
6759
- children: items.map((item, i) => /* @__PURE__ */ jsx(
6760
- OrderFormItemRow,
6761
- {
6762
- index: i,
6763
- itemKind: item.itemKind,
6764
- description: item.description,
6765
- quantity: item.quantity,
6766
- unitPrice: item.unitPrice,
6767
- discount: item.discount,
6768
- itemTypes,
6769
- currency,
6770
- formatMoney: money,
6771
- expanded: expandedItemId === item._id,
6772
- onToggle: () => setExpandedItemId(expandedItemId === item._id ? null : item._id),
6773
- onChange: (patch) => updateItem(item._id, patch),
6774
- onRemove: () => removeItem(item._id),
6775
- entityLookups: config.entityLookups,
6776
- labels: {
6777
- item: t("crm.quoteForm.description"),
6778
- description: t("crm.quoteForm.description"),
6779
- descriptionPlaceholder: t("crm.quoteForm.itemDescriptionPlaceholder"),
6780
- noDescription: t("crm.quoteForm.noDescription"),
6781
- qty: t("crm.quoteForm.qty"),
6782
- unitPrice: t("crm.quoteForm.unitPrice"),
6783
- discount: t("crm.quoteForm.discount"),
6784
- done: t("crm.quoteForm.done")
6785
- }
6786
- },
6787
- item._id
6788
- ))
6789
- }
6790
- )
6791
- ]
6792
- }
6793
- );
6794
- }
6795
- var SEND_ITEM = "gap-2 px-3 py-2 text-xs";
6796
- function QuoteDetailView({ quoteId, onBack, onEdit, onInvoiceCreated }) {
6797
- const t = useTranslation();
6798
- const { currency } = useCrmConfig();
6799
- const provider = useCrmProvider();
6800
- const sendQuote = useCrmStore((s) => s.sendQuote);
6801
- const approveQuote = useCrmStore((s) => s.approveQuote);
6802
- const rejectQuote = useCrmStore((s) => s.rejectQuote);
6803
- const [quote, setQuote] = useState(null);
6804
- const [loading, setLoading] = useState(true);
6805
- const [sending, setSending] = useState(false);
6806
- const [approving, setApproving] = useState(false);
6807
- const [rejectOpen, setRejectOpen] = useState(false);
6808
- const [rejectReason, setRejectReason] = useState("");
6809
- const [rejecting, setRejecting] = useState(false);
6810
- useEffect(() => {
6811
- setLoading(true);
6812
- provider.getQuoteById(quoteId).then((q) => {
6813
- setQuote(q);
6814
- setLoading(false);
6815
- });
6816
- }, [quoteId]);
6817
- async function handleSend(_channel) {
6818
- setSending(true);
6819
- try {
6820
- const updated = await sendQuote(quoteId);
6821
- setQuote(updated);
6822
- } finally {
6823
- setSending(false);
6824
- }
6825
- }
6826
- async function handleApprove() {
6827
- setApproving(true);
6828
- try {
6829
- const updated = await approveQuote(quoteId);
6830
- setQuote(updated);
6831
- if (onInvoiceCreated) onInvoiceCreated(quoteId);
6832
- } finally {
6833
- setApproving(false);
6834
- }
6835
- }
6836
- async function handleReject() {
6837
- if (!rejectReason.trim()) return;
6838
- setRejecting(true);
6839
- try {
6840
- const updated = await rejectQuote(quoteId, rejectReason.trim());
6841
- setQuote(updated);
6842
- setRejectOpen(false);
6843
- setRejectReason("");
6844
- } finally {
6845
- setRejecting(false);
6846
- }
6847
- }
6848
- if (loading) return /* @__PURE__ */ jsx(OrderDetailSkeleton, { parentLabel: t("crm.quotes.title"), onBack });
6849
- if (!quote) {
6850
- return /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
6851
- /* @__PURE__ */ jsx(SubpageHeader, { title: t("crm.quoteDetail.title"), onBack, parentLabel: t("crm.quotes.title") }),
6852
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-muted py-12 text-center", children: [
6853
- /* @__PURE__ */ jsx(FileText, { className: "mb-2 h-8 w-8 text-muted-foreground/30" }),
6854
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("crm.quoteDetail.notFound") }),
6855
- /* @__PURE__ */ jsx(Button, { variant: "bare", size: "bare", onClick: onBack, className: "mt-1 text-xs font-normal text-primary hover:underline", children: t("crm.quoteDetail.backToList") })
6856
- ] })
6857
- ] });
6858
- }
6859
- const subtotal = quote.items.reduce((sum, it) => sum + it.quantity * it.unitPrice, 0);
6860
- const totalDiscount = quote.items.reduce((sum, it) => sum + it.discount, 0);
6861
- const detailItems = quote.items.map((it, i) => ({
6862
- id: it.id ?? String(i),
6863
- name: it.description || "\u2014",
6864
- description: it.itemKind,
6865
- quantity: it.quantity,
6866
- unitPrice: formatCurrency(it.unitPrice, currency),
6867
- total: formatCurrency(it.totalAmount, currency)
6868
- }));
6869
- const totals = [
6870
- ...totalDiscount > 0 ? [
6871
- { label: t("crm.quoteDetail.subtotal"), value: formatCurrency(subtotal, currency), muted: true },
6872
- { label: t("crm.quoteDetail.discount"), value: `-${formatCurrency(totalDiscount, currency)}`, muted: true }
6873
- ] : [],
6874
- { label: t("crm.quoteDetail.total"), value: formatCurrency(quote.totalAmount, currency), strong: true }
6875
- ];
6876
- const editable = quote.status !== "approved" && quote.status !== "rejected" && quote.status !== "expired";
6877
- const actions = /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
6878
- quote.status === "draft" && /* @__PURE__ */ jsxs(Dropdown, { children: [
6879
- /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", disabled: sending, className: "h-auto px-3 py-1.5 font-medium", children: [
6880
- /* @__PURE__ */ jsx(Send, { className: "h-3 w-3" }),
6881
- sending ? t("crm.quoteDetail.sending") : t("crm.quoteDetail.send"),
6882
- /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 opacity-60" })
6883
- ] }) }),
6884
- /* @__PURE__ */ jsxs(DropdownContent, { align: "end", className: "w-48", children: [
6885
- /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => void handleSend(), className: SEND_ITEM, children: [
6886
- /* @__PURE__ */ jsx(Printer, { className: "h-3.5 w-3.5 text-muted-foreground" }),
6887
- " ",
6888
- t("crm.quoteDetail.sendPrint")
6889
- ] }),
6890
- /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => void handleSend(), className: SEND_ITEM, children: [
6891
- /* @__PURE__ */ jsx(Mail, { className: "h-3.5 w-3.5 text-muted-foreground" }),
6892
- " ",
6893
- t("crm.quoteDetail.sendEmail")
6894
- ] }),
6895
- /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => void handleSend(), className: SEND_ITEM, children: [
6896
- /* @__PURE__ */ jsx(MessageCircle, { className: "h-3.5 w-3.5 text-muted-foreground" }),
6897
- " ",
6898
- t("crm.quoteDetail.sendWhatsApp")
6899
- ] })
6900
- ] })
6901
- ] }),
6902
- quote.status === "sent" && /* @__PURE__ */ jsxs(Fragment, { children: [
6903
- /* @__PURE__ */ jsxs(
6904
- Button,
6905
- {
6906
- type: "button",
6907
- variant: "default",
6908
- size: "sm",
6909
- onClick: handleApprove,
6910
- disabled: approving,
6911
- className: "border-success bg-success text-success-foreground hover:bg-success/90",
6912
- children: [
6913
- /* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5" }),
6914
- approving ? t("crm.quoteDetail.approving") : t("crm.quoteDetail.approve")
6915
- ]
6916
- }
6917
- ),
6918
- /* @__PURE__ */ jsxs(
6919
- Button,
6920
- {
6921
- type: "button",
6922
- variant: "outline",
6923
- size: "sm",
6924
- onClick: () => setRejectOpen(true),
6925
- className: "border-destructive/30 text-destructive hover:bg-destructive/10",
6926
- children: [
6927
- /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }),
6928
- t("crm.quoteDetail.reject")
6929
- ]
6930
- }
6931
- )
6932
- ] }),
6933
- onEdit && editable && /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: onEdit, children: [
6934
- /* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5" }),
6935
- " ",
6936
- t("crm.quoteDetail.edit")
6937
- ] })
6938
- ] });
6939
- const sideBlocks = /* @__PURE__ */ jsxs(Fragment, { children: [
6940
- quote.paymentConditions && /* @__PURE__ */ jsx(OrderDetailBlock, { title: t("crm.quoteDetail.paymentConditions"), children: /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap text-sm text-muted-foreground", children: quote.paymentConditions }) }),
6941
- quote.observations && /* @__PURE__ */ jsx(OrderDetailBlock, { title: t("crm.quoteDetail.notes"), children: /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap text-sm text-muted-foreground", children: quote.observations }) })
6942
- ] });
6943
- const invoiced = ["approved", "invoiced", "paid", "partial", "overdue"].includes(quote.status);
6944
- const banners = /* @__PURE__ */ jsxs(Fragment, { children: [
6945
- invoiced && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between rounded-lg border border-success/30 bg-success/5 px-4 py-2.5", children: [
6946
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
6947
- /* @__PURE__ */ jsx(CircleCheckBig, { className: "h-3.5 w-3.5 text-success" }),
6948
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t("crm.quoteDetail.invoiceCreated") })
6949
- ] }),
6950
- /* @__PURE__ */ jsxs("a", { href: appHref("/financial/receivables/list"), className: "inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline", children: [
6951
- t("crm.quoteDetail.viewInvoice"),
6952
- " ",
6953
- /* @__PURE__ */ jsx(ArrowRight, { className: "h-3 w-3" })
6954
- ] })
6955
- ] }),
6956
- quote.status === "rejected" && quote.rejectionReason && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-2.5", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
6957
- /* @__PURE__ */ jsx(Ban, { className: "h-3.5 w-3.5 text-destructive" }),
6958
- /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
6959
- t("crm.quoteDetail.rejectionReason"),
6960
- ": ",
6961
- /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: quote.rejectionReason })
6962
- ] })
6963
- ] }) })
6964
- ] });
6965
- return /* @__PURE__ */ jsxs(Fragment, { children: [
6966
- /* @__PURE__ */ jsx(
6967
- OrderDetailView,
6968
- {
6969
- title: `#${quote.quoteNumber}`,
6970
- badgesNode: /* @__PURE__ */ jsx(QuoteStatusDropdown, { quote, onStatusChange: (q) => setQuote(q) }),
6971
- subtitle: null,
6972
- onBack,
6973
- backLabel: t("crm.quotes.title"),
6974
- actions,
6975
- stats: [
6976
- { id: "total", label: t("crm.quoteDetail.total"), value: formatCurrency(quote.totalAmount, currency), icon: Receipt },
6977
- { id: "items", label: t("crm.quoteDetail.items"), value: quote.items.length, icon: Package },
6978
- { id: "date", label: t("crm.quoteDetail.date"), value: quote.quoteDate, icon: Calendar },
6979
- { id: "valid", label: t("crm.quoteDetail.validUntil"), value: quote.validUntil, icon: CalendarClock }
6980
- ],
6981
- errorBanner: banners,
6982
- customer: { name: quote.contactName, email: null },
6983
- customerNode: quote.contactName ? /* @__PURE__ */ jsx(PersonLink, { personId: quote.contactId ?? quote.leadId, name: quote.contactName, size: "sm" }) : /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" }),
6984
- items: detailItems,
6985
- itemsLabel: t("crm.quoteDetail.items"),
6986
- totals,
6987
- totalsLabel: t("crm.quoteDetail.summary"),
6988
- extraSections: sideBlocks
6989
- }
6990
- ),
6991
- /* @__PURE__ */ jsx(Modal, { open: rejectOpen, onOpenChange: setRejectOpen, children: /* @__PURE__ */ jsxs(ModalContent, { className: "max-w-sm", children: [
6992
- /* @__PURE__ */ jsxs(ModalBody, { children: [
6993
- /* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center gap-3", children: [
6994
- /* @__PURE__ */ jsx("div", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/10", children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5 text-destructive" }) }),
6995
- /* @__PURE__ */ jsxs("div", { children: [
6996
- /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t("crm.quoteDetail.reject") }),
6997
- /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("crm.quoteDetail.rejectDescription") })
6998
- ] })
6999
- ] }),
7000
- /* @__PURE__ */ jsx(
7001
- Textarea,
7002
- {
7003
- value: rejectReason,
7004
- onChange: (e) => setRejectReason(e.target.value),
7005
- placeholder: t("crm.quoteDetail.rejectReasonPlaceholder"),
7006
- className: "h-20 resize-none",
7007
- autoFocus: true
7008
- }
7009
- )
7010
- ] }),
7011
- /* @__PURE__ */ jsxs(ModalFooter, { children: [
7012
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => setRejectOpen(false), children: t("common.cancel") }),
7013
- /* @__PURE__ */ jsx(
7014
- Button,
7015
- {
7016
- type: "button",
7017
- variant: "destructive",
7018
- size: "sm",
7019
- onClick: handleReject,
7020
- disabled: rejecting || !rejectReason.trim(),
7021
- children: rejecting ? t("crm.quoteDetail.rejecting") : t("crm.quoteDetail.confirmReject")
7022
- }
7023
- )
7024
- ] })
7025
- ] }) })
7026
- ] });
7027
- }
7028
6015
  function PersonPhones({ personId, onOpenPerson }) {
7029
6016
  const t = useTranslation();
7030
6017
  const provider = useCrmProvider();
@@ -7559,6 +6546,7 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7559
6546
  const [archiving, setArchiving] = useState(false);
7560
6547
  const [confirmandoArquivo, setConfirmandoArquivo] = useState(false);
7561
6548
  const [lead, setLead] = useState(null);
6549
+ const talk = useTalkToPersonAction(leadId, lead?.name, lead?.phone);
7562
6550
  const [recarga, setRecarga] = useState(0);
7563
6551
  useRecordVisit(lead ? {
7564
6552
  id: lead.id,
@@ -7648,7 +6636,20 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7648
6636
  }
7649
6637
  const initial = lead.name.charAt(0).toUpperCase();
7650
6638
  return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
7651
- /* @__PURE__ */ jsx(SubpageHeader, { title: lead.name, parentLabel: t("crm.leads.title"), onBack }),
6639
+ /* @__PURE__ */ jsx(
6640
+ SubpageHeader,
6641
+ {
6642
+ title: lead.name,
6643
+ parentLabel: t("crm.leads.title"),
6644
+ onBack,
6645
+ actions: /* @__PURE__ */ jsx(PageActions, { actions: [
6646
+ ...onCreateQuote && lead.status !== "converted" && lead.status !== "lost" ? [{ id: "create-quote", label: t("crm.leadDetail.createQuote"), icon: FileText, intent: "primary", onSelect: () => onCreateQuote(leadId) }] : [],
6647
+ ...deal && onOpenDeal ? [{ id: "open-deal", label: t("crm.leadDetail.openDeal"), icon: Filter, intent: "secondary", onSelect: () => onOpenDeal(deal.id) }] : [],
6648
+ ...talk ? [{ id: "talk", label: talk.label, icon: WhatsAppGlyph, intent: "secondary", onSelect: talk.go }] : [],
6649
+ ...canArchive ? [{ id: "archive", label: t("crm.leadDetail.archive"), icon: Archive, intent: "danger", disabled: archiving, onSelect: () => setConfirmandoArquivo(true) }] : []
6650
+ ] })
6651
+ }
6652
+ ),
7652
6653
  /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-5", children: [
7653
6654
  /* @__PURE__ */ jsx("div", { className: "flex h-20 w-20 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary text-2xl font-bold shadow-sm", children: initial }),
7654
6655
  /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
@@ -7658,52 +6659,6 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7658
6659
  /* @__PURE__ */ jsx(LeadStatusBadge, { status: lead.status }),
7659
6660
  lead.sourceName && /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 text-[10px] font-medium text-muted-foreground", children: lead.sourceName })
7660
6661
  ] })
7661
- ] }),
7662
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 shrink-0", children: [
7663
- deal && onOpenDeal && /* @__PURE__ */ jsxs(
7664
- Button,
7665
- {
7666
- variant: "outline",
7667
- onClick: () => onOpenDeal(deal.id),
7668
- className: "h-auto px-3 py-1.5 text-xs font-medium",
7669
- children: [
7670
- /* @__PURE__ */ jsx(Filter, { className: "h-3 w-3" }),
7671
- " ",
7672
- t("crm.leadDetail.openDeal")
7673
- ]
7674
- }
7675
- ),
7676
- /* @__PURE__ */ jsx(TalkToPerson, { personId: leadId, name: lead.name, phone: lead.phone }),
7677
- canArchive && /* @__PURE__ */ jsxs(Dropdown, { children: [
7678
- /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
7679
- Button,
7680
- {
7681
- variant: "outline",
7682
- size: "icon",
7683
- "aria-label": t("crm.leadDetail.moreActions"),
7684
- disabled: archiving,
7685
- className: "rounded-lg text-muted-foreground hover:text-foreground disabled:opacity-60",
7686
- children: /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" })
7687
- }
7688
- ) }),
7689
- /* @__PURE__ */ jsx(DropdownContent, { align: "end", children: /* @__PURE__ */ jsxs(DropdownItem, { onSelect: () => setConfirmandoArquivo(true), children: [
7690
- /* @__PURE__ */ jsx(Archive, { className: "h-3.5 w-3.5" }),
7691
- " ",
7692
- t("crm.leadDetail.archive")
7693
- ] }) })
7694
- ] }),
7695
- onCreateQuote && lead.status !== "converted" && lead.status !== "lost" && /* @__PURE__ */ jsxs(
7696
- Button,
7697
- {
7698
- onClick: () => onCreateQuote(leadId),
7699
- className: "h-auto px-3 py-1.5 text-xs font-medium",
7700
- children: [
7701
- /* @__PURE__ */ jsx(FileText, { className: "h-3 w-3" }),
7702
- " ",
7703
- t("crm.leadDetail.createQuote")
7704
- ]
7705
- }
7706
- )
7707
6662
  ] })
7708
6663
  ] }),
7709
6664
  /* @__PURE__ */ jsx("div", { className: "border-t" }),
@@ -10256,34 +9211,48 @@ function Skeleton() {
10256
9211
  /* @__PURE__ */ jsx("div", { className: "mt-2 h-3 w-72 animate-pulse rounded bg-muted/20" })
10257
9212
  ] }, i)) });
10258
9213
  }
9214
+ var STRIP = "flex w-full flex-wrap items-center gap-x-3 gap-y-2 border-t px-4 py-1.5 text-sm text-foreground md:flex-nowrap md:pl-6 md:pr-[calc(2rem+var(--fz-fab-clearance,0px))]";
9215
+ var STRIP_WARNING = "border-amber-300/60 bg-amber-50 dark:border-amber-500/30 dark:bg-amber-500/10";
9216
+ var STRIP_INFO = "border-border bg-muted/60";
10259
9217
  function RotaBanner({ rota, t }) {
10260
9218
  const settings = () => adminNavigateTo("/settings/crm/_properties/assignment-rota");
9219
+ const configure = /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", className: "w-full max-sm:h-9 sm:w-auto sm:shrink-0", onClick: settings, children: [
9220
+ /* @__PURE__ */ jsx(Settings2, { className: "mr-1.5 h-4 w-4" }),
9221
+ t("crm.distribution.configure")
9222
+ ] });
10261
9223
  if (!rota || !rota.isActive) {
10262
- return /* @__PURE__ */ jsx("div", { className: "rounded-card border border-amber-500/40 bg-amber-500/5 p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
10263
- /* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-5 w-5 shrink-0 text-amber-600" }),
10264
- /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
10265
- /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("crm.distribution.rotaOff") }),
10266
- /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: rota ? t("crm.distribution.rotaOffExists") : t("crm.distribution.rotaMissing") })
9224
+ return /* @__PURE__ */ jsx(ShellBanner, { urgency: "warning", children: /* @__PURE__ */ jsxs("section", { role: "region", "aria-label": t("crm.distribution.rotaOff"), className: `${STRIP} ${STRIP_WARNING}`, "data-testid": "crm-rota-banner", children: [
9225
+ /* @__PURE__ */ jsx(AlertTriangle, { className: "h-4 w-4 shrink-0 text-amber-600", "aria-hidden": "true" }),
9226
+ /* @__PURE__ */ jsxs("p", { className: "min-w-0 flex-1", children: [
9227
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: t("crm.distribution.rotaOff") }),
9228
+ /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
9229
+ " \u2014 ",
9230
+ rota ? t("crm.distribution.rotaOffExists") : t("crm.distribution.rotaMissing")
9231
+ ] })
10267
9232
  ] }),
10268
- /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: settings, children: [
10269
- /* @__PURE__ */ jsx(Settings2, { className: "mr-1.5 h-4 w-4" }),
10270
- t("crm.distribution.configure")
10271
- ] })
9233
+ configure
10272
9234
  ] }) });
10273
9235
  }
10274
9236
  const dropped = rota.assigneeIds.length - rota.eligibleIds.length;
10275
- return /* @__PURE__ */ jsx("div", { className: "rounded-card border bg-card p-4 shadow-sm", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
10276
- /* @__PURE__ */ jsx(Repeat, { className: "mt-0.5 h-5 w-5 shrink-0 text-emerald-600" }),
10277
- /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
10278
- /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("crm.distribution.rotaOn", { count: rota.eligibleIds.length }) }),
10279
- /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: t("crm.distribution.window", { minutes: rota.offerMinutes }) }),
10280
- dropped > 0 && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-amber-700", children: t("crm.distribution.someLeft", { count: dropped }) }),
10281
- rota.eligibleIds.length === 0 && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-amber-700", children: t("crm.distribution.nobodyEligible") })
9237
+ const nobody = rota.eligibleIds.length === 0;
9238
+ const attention = dropped > 0 || nobody;
9239
+ return /* @__PURE__ */ jsx(ShellBanner, { urgency: attention ? "warning" : "info", children: /* @__PURE__ */ jsxs("section", { role: "region", "aria-label": t("crm.distribution.rotaOn", { count: rota.eligibleIds.length }), className: `${STRIP} ${attention ? STRIP_WARNING : STRIP_INFO}`, "data-testid": "crm-rota-banner", children: [
9240
+ /* @__PURE__ */ jsx(Repeat, { className: "h-4 w-4 shrink-0 text-emerald-600", "aria-hidden": "true" }),
9241
+ /* @__PURE__ */ jsxs("p", { className: "min-w-0 flex-1", children: [
9242
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: t("crm.distribution.rotaOn", { count: rota.eligibleIds.length }) }),
9243
+ /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
9244
+ " \u2014 ",
9245
+ t("crm.distribution.window", { minutes: rota.offerMinutes })
9246
+ ] }),
9247
+ nobody ? /* @__PURE__ */ jsxs("span", { className: "text-amber-700 dark:text-amber-400", children: [
9248
+ " ",
9249
+ t("crm.distribution.nobodyEligible")
9250
+ ] }) : dropped > 0 && /* @__PURE__ */ jsxs("span", { className: "text-amber-700 dark:text-amber-400", children: [
9251
+ " ",
9252
+ t("crm.distribution.someLeft", { count: dropped })
9253
+ ] })
10282
9254
  ] }),
10283
- /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: settings, children: [
10284
- /* @__PURE__ */ jsx(Settings2, { className: "mr-1.5 h-4 w-4" }),
10285
- t("crm.distribution.configure")
10286
- ] })
9255
+ configure
10287
9256
  ] }) });
10288
9257
  }
10289
9258
  function DistributionView() {
@@ -10376,7 +9345,7 @@ function DistributionView() {
10376
9345
  icon: "Repeat"
10377
9346
  }
10378
9347
  ),
10379
- rota === void 0 ? /* @__PURE__ */ jsx(Skeleton, {}) : /* @__PURE__ */ jsx(RotaBanner, { rota, t }),
9348
+ rota !== void 0 && /* @__PURE__ */ jsx(RotaBanner, { rota, t }),
10380
9349
  /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
10381
9350
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
10382
9351
  /* @__PURE__ */ jsxs("div", { children: [
@@ -10758,7 +9727,7 @@ function CrmPage({ config, provider, store, registries }) {
10758
9727
  { id: "quotes-detail", render: ({ id }) => /* @__PURE__ */ jsx(QuoteDetailView, { quoteId: id, onBack: () => navigate("quotes-list"), onEdit: () => navigate(`quotes-edit:${id}`), onInvoiceCreated: (invoiceId) => {
10759
9728
  navigateApp(`/financial/receivables/detail/${invoiceId}`);
10760
9729
  } }) },
10761
- { id: "quotes-edit", render: ({ id }) => /* @__PURE__ */ jsx(QuoteFormView, { quoteId: id, onSaved: () => navigate(`quotes-detail:${id}`) }) },
9730
+ { id: "quotes-edit", render: ({ id }) => /* @__PURE__ */ jsx(QuoteEditRoute, { quoteId: id, onSaved: () => navigate(`quotes-detail:${id}`), onBack: () => navigate(`quotes-detail:${id}`) }) },
10762
9731
  { id: "company-groups", render: () => /* @__PURE__ */ jsx(CompanyGroupsView, {}) },
10763
9732
  { id: "companies-list", render: () => /* @__PURE__ */ jsx(CompanyListView, { onNew: () => navigate("companies-new"), onEdit: (id) => navigate(`companies-detail:${id}`) }) },
10764
9733
  { id: "companies-new", render: () => /* @__PURE__ */ jsx(CompanyFormView, { onSaved: (id) => navigate(id ? `companies-detail:${id}` : "companies-list"), onCancel: () => navigate("companies-list") }) },
@@ -10814,5 +9783,5 @@ function CrmPage({ config, provider, store, registries }) {
10814
9783
  }
10815
9784
 
10816
9785
  export { CrmPage };
10817
- //# sourceMappingURL=CrmPage-BJASPPQI.js.map
10818
- //# sourceMappingURL=CrmPage-BJASPPQI.js.map
9786
+ //# sourceMappingURL=CrmPage-DLFFHQJP.js.map
9787
+ //# sourceMappingURL=CrmPage-DLFFHQJP.js.map