@fayz-ai/plugin-crm 0.41.0 → 0.42.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.
@@ -6,8 +6,8 @@ import { dealHeadline, dealHouseLine, QuoteFormView, QuoteListView, QuoteDetailV
6
6
  import './chunk-ZWUFORDV.js';
7
7
  import { formatCurrency, CrmContextProvider, useCrmProvider, useCrmStore, useCrmConfig } from './chunk-7V46TYYX.js';
8
8
  import React2, { useCallback, useMemo, useState, useEffect, useRef } from 'react';
9
- import { UserCheck, 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, 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';
9
+ import { UserCheck, 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, CheckCheck, AlertTriangle, CalendarClock, CheckCircle2, Star, Pencil, Trash2, MessageSquareQuote, CalendarDays, SignalHigh, CalendarRange, TrendingDown, MoreHorizontal, Settings2, Repeat, Zap, Merge, Fingerprint, Paperclip, ImageOff, ChevronDown, Search, Link2, RefreshCw, ExternalLink, Ban, PhoneMissed, MessageSquareOff, PhoneOff, 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, Card, cn, ComingSoon, StatTiles, Switch, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, DashboardCanvas, DatePicker, Pagination, DropdownItem, PersonPicker, ShellBanner, HeaderTabs, SheetBody, SheetFooter, Popover, PopoverTrigger, PopoverContent, getLucideIcon, DictateButton, ModalDescription, normalizePhone } from '@fayz-ai/ui';
11
11
  import { useTranslation, usePluginRuntimeOptional, currentAppPath, navigateApp, useActiveTenantId, exportCSV, getSupabaseClientOptional, appHref, loadMessageOverrides, resolveMessages, useActiveUnitId, getActiveTenantId } from '@fayz-ai/core';
12
12
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
13
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';
@@ -3504,11 +3504,11 @@ function defaultFutureContactDate(now = /* @__PURE__ */ new Date()) {
3504
3504
  }
3505
3505
  function FutureContactPicker({ value, onChange, required = false }) {
3506
3506
  const t = useTranslation();
3507
- const today = /* @__PURE__ */ new Date();
3507
+ const today2 = /* @__PURE__ */ new Date();
3508
3508
  const presets = [
3509
- { label: t("crm.followUp.inSevenDays"), value: addDaysToDate(today, 7) },
3510
- { label: t("crm.followUp.inOneMonth"), value: addMonthsToDate(today, 1) },
3511
- { label: t("crm.followUp.inThreeMonths"), value: addMonthsToDate(today, 3) }
3509
+ { label: t("crm.followUp.inSevenDays"), value: addDaysToDate(today2, 7) },
3510
+ { label: t("crm.followUp.inOneMonth"), value: addMonthsToDate(today2, 1) },
3511
+ { label: t("crm.followUp.inThreeMonths"), value: addMonthsToDate(today2, 3) }
3512
3512
  ];
3513
3513
  return /* @__PURE__ */ jsxs("div", { className: "w-full space-y-2 rounded-lg border border-amber-300/70 bg-amber-50/60 p-2.5 dark:border-amber-700/60 dark:bg-amber-950/20", children: [
3514
3514
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-xs font-medium text-foreground", children: [
@@ -5135,22 +5135,6 @@ function FranchisorGoalsView() {
5135
5135
  }
5136
5136
  );
5137
5137
  }
5138
- function TasksView() {
5139
- return /* @__PURE__ */ jsx(
5140
- ComingSoon,
5141
- {
5142
- title: "Tarefas",
5143
- summary: "O que algu\xE9m combinou de fazer com um lead: ligar na quinta, mandar a proposta, passar na loja. Com dono, prazo e o que aconteceu.",
5144
- v1Path: "CRM \u2192 Engajamento \u2192 Tarefas",
5145
- measured: "1 tarefa em todo o V1. A tela existe l\xE1 e praticamente n\xE3o foi usada.",
5146
- missing: [
5147
- "A tarefa ligada ao lead ou ao neg\xF3cio, n\xE3o solta \u2014 \xE9 isso que a torna \xFAtil",
5148
- "Atividades (que j\xE1 existe aqui) REGISTRA o que aconteceu; a tarefa \xE9 o que ainda vai acontecer",
5149
- "O atraso tem de aparecer sozinho, sen\xE3o a lista vira arquivo"
5150
- ]
5151
- }
5152
- );
5153
- }
5154
5138
  function FollowUpsView() {
5155
5139
  return /* @__PURE__ */ jsx(
5156
5140
  ComingSoon,
@@ -5228,6 +5212,180 @@ function PendingReturnsView() {
5228
5212
  }
5229
5213
  );
5230
5214
  }
5215
+ var OUTCOMES = [
5216
+ { id: "connected", label: "Atendeu" },
5217
+ { id: "no_answer", label: "N\xE3o atendeu" },
5218
+ { id: "left_message", label: "Deixei recado" },
5219
+ { id: "scheduled", label: "Agendou" }
5220
+ ];
5221
+ var PHONE_RE = /(\+?\(?\d[\d\s().-]{8,}\d)/g;
5222
+ function today() {
5223
+ const d = /* @__PURE__ */ new Date();
5224
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
5225
+ }
5226
+ function bucketOf(t, now) {
5227
+ const due = t.dueDate?.slice(0, 10);
5228
+ if (!due) return "undated";
5229
+ return due < now ? "late" : due === now ? "today" : "next";
5230
+ }
5231
+ var BUCKETS = [
5232
+ { id: "late", label: "Atrasadas" },
5233
+ { id: "today", label: "Para hoje" },
5234
+ { id: "next", label: "Pr\xF3ximas" },
5235
+ { id: "undated", label: "Sem prazo" }
5236
+ ];
5237
+ function TasksView({ onOpenDeal, onOpenLead }) {
5238
+ const provider = useCrmProvider();
5239
+ const [me, setMe] = React2.useState(null);
5240
+ const [team, setTeam] = React2.useState([]);
5241
+ const [who, setWho] = React2.useState(null);
5242
+ const [all, setAll] = React2.useState(null);
5243
+ const [closing, setClosing] = React2.useState(null);
5244
+ React2.useEffect(() => {
5245
+ void loadMyUserId().then(setMe);
5246
+ void loadTeamOrNull().then((t) => setTeam(t ?? []));
5247
+ }, []);
5248
+ const load = React2.useCallback(async () => {
5249
+ try {
5250
+ const r = await provider.getActivities({ activityType: "task", completed: false, orderByDue: true, pageSize: 1e3 });
5251
+ setAll(r.data);
5252
+ } catch (e) {
5253
+ toast.error(e.message);
5254
+ setAll([]);
5255
+ }
5256
+ }, [provider]);
5257
+ React2.useEffect(() => {
5258
+ void load();
5259
+ }, [load]);
5260
+ React2.useEffect(() => {
5261
+ if (who !== null || all === null) return;
5262
+ setWho(me && all.some((t) => t.assignedToId === me) ? me : "all");
5263
+ }, [who, all, me]);
5264
+ const tasks = all === null || who === null ? null : who === "all" ? all : all.filter((t) => t.assignedToId === who);
5265
+ const people = React2.useMemo(() => {
5266
+ const n = /* @__PURE__ */ new Map();
5267
+ for (const t of all ?? []) if (t.assignedToId) n.set(t.assignedToId, (n.get(t.assignedToId) ?? 0) + 1);
5268
+ return [...n].map(([userId, count]) => ({ userId, count })).sort((a, b) => b.count - a.count);
5269
+ }, [all]);
5270
+ const nameOf = (id) => id ? team.find((m) => m.userId === id)?.name : void 0;
5271
+ async function done(t, outcome) {
5272
+ setClosing(t.id);
5273
+ try {
5274
+ await provider.completeActivity(t.id, outcome);
5275
+ setAll((list) => (list ?? []).filter((x) => x.id !== t.id));
5276
+ toast.success("Tarefa conclu\xEDda");
5277
+ } catch (e) {
5278
+ toast.error(e.message);
5279
+ } finally {
5280
+ setClosing(null);
5281
+ }
5282
+ }
5283
+ const now = today();
5284
+ const grouped = BUCKETS.map((b) => ({ ...b, items: (tasks ?? []).filter((t) => bucketOf(t, now) === b.id) })).filter((g) => g.items.length > 0);
5285
+ const late = grouped.find((g) => g.id === "late")?.items.length ?? 0;
5286
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
5287
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-end justify-between gap-2", children: [
5288
+ /* @__PURE__ */ jsxs("div", { children: [
5289
+ /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: "Tarefas" }),
5290
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: tasks === null ? "Carregando\u2026" : tasks.length === 0 ? "Nada pendente." : `${tasks.length} pendente(s)${late ? ` \xB7 ${late} atrasada(s)` : ""}` })
5291
+ ] }),
5292
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1", children: [
5293
+ me && /* @__PURE__ */ jsxs(Button, { size: "sm", variant: who === me ? "secondary" : "ghost", className: "h-7 text-xs", onClick: () => setWho(me), children: [
5294
+ /* @__PURE__ */ jsx(User, { className: "h-3.5 w-3.5" }),
5295
+ " Minhas \xB7 ",
5296
+ people.find((x) => x.userId === me)?.count ?? 0
5297
+ ] }),
5298
+ /* @__PURE__ */ jsxs(Button, { size: "sm", variant: who === "all" ? "secondary" : "ghost", className: "h-7 text-xs", onClick: () => setWho("all"), children: [
5299
+ "Todas \xB7 ",
5300
+ all?.length ?? 0
5301
+ ] }),
5302
+ people.filter((x) => x.userId !== me).map((x) => /* @__PURE__ */ jsxs(Button, { size: "sm", variant: who === x.userId ? "secondary" : "ghost", className: "h-7 text-xs", onClick: () => setWho(x.userId), children: [
5303
+ (nameOf(x.userId) ?? "Sem nome").split(/\s+/)[0],
5304
+ " \xB7 ",
5305
+ x.count
5306
+ ] }, x.userId))
5307
+ ] })
5308
+ ] }),
5309
+ tasks === null && /* @__PURE__ */ jsx("div", { className: "flex justify-center py-10", children: /* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }) }),
5310
+ tasks !== null && tasks.length === 0 && /* @__PURE__ */ jsxs(Card, { className: "flex flex-col items-center gap-2 p-10 text-center text-muted-foreground", children: [
5311
+ /* @__PURE__ */ jsx(CheckCheck, { className: "h-7 w-7 text-success" }),
5312
+ /* @__PURE__ */ jsxs("p", { className: "text-sm", children: [
5313
+ "Nenhuma tarefa pendente",
5314
+ who !== "all" && who !== me ? ` para ${nameOf(who ?? void 0) ?? "esta pessoa"}` : "",
5315
+ "."
5316
+ ] })
5317
+ ] }),
5318
+ grouped.map((g) => /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
5319
+ /* @__PURE__ */ jsxs("p", { className: cn("flex items-center gap-1.5 text-xs font-medium", g.id === "late" ? "text-destructive" : "text-muted-foreground"), children: [
5320
+ g.id === "late" ? /* @__PURE__ */ jsx(AlertTriangle, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx(CalendarClock, { className: "h-3.5 w-3.5" }),
5321
+ g.label,
5322
+ " \xB7 ",
5323
+ g.items.length
5324
+ ] }),
5325
+ g.items.map((t) => {
5326
+ const phones = [...new Set((t.description ?? "").match(PHONE_RE) ?? [])].slice(0, 4);
5327
+ const owner = t.assignedToName ?? nameOf(t.assignedToId);
5328
+ return /* @__PURE__ */ jsxs(Card, { className: "p-3", "data-testid": "crm-task", children: [
5329
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-start justify-between gap-2", children: [
5330
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
5331
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t.title }),
5332
+ /* @__PURE__ */ jsxs("p", { className: "mt-0.5 text-[11px] text-muted-foreground", children: [
5333
+ t.dueDate ? (/* @__PURE__ */ new Date(`${t.dueDate.slice(0, 10)}T12:00:00`)).toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit" }) : "sem prazo",
5334
+ who === "all" && owner ? ` \xB7 ${owner.split(/\s+/)[0]}` : "",
5335
+ t.contactName ? ` \xB7 ${t.contactName}` : ""
5336
+ ] }),
5337
+ phones.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-2 flex flex-wrap gap-1.5", children: phones.map((p) => /* @__PURE__ */ jsxs(
5338
+ "a",
5339
+ {
5340
+ href: `tel:${p.replace(/[^\d+]/g, "")}`,
5341
+ className: "inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-xs font-medium hover:bg-muted",
5342
+ children: [
5343
+ /* @__PURE__ */ jsx(Phone, { className: "h-3 w-3" }),
5344
+ " ",
5345
+ p.trim()
5346
+ ]
5347
+ },
5348
+ p
5349
+ )) })
5350
+ ] }),
5351
+ (t.dealId || t.leadId) && /* @__PURE__ */ jsxs(
5352
+ Button,
5353
+ {
5354
+ size: "sm",
5355
+ variant: "ghost",
5356
+ className: "h-7 text-xs",
5357
+ onClick: () => t.dealId ? onOpenDeal?.(t.dealId) : t.leadId && onOpenLead?.(t.leadId),
5358
+ children: [
5359
+ "Abrir neg\xF3cio ",
5360
+ /* @__PURE__ */ jsx(ChevronRight, { className: "h-3.5 w-3.5" })
5361
+ ]
5362
+ }
5363
+ )
5364
+ ] }),
5365
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-1 border-t pt-2", children: [
5366
+ /* @__PURE__ */ jsx("span", { className: "mr-1 text-[11px] text-muted-foreground", children: "Feito:" }),
5367
+ OUTCOMES.map((o) => /* @__PURE__ */ jsxs(
5368
+ Button,
5369
+ {
5370
+ size: "sm",
5371
+ variant: "outline",
5372
+ className: "h-7 text-xs",
5373
+ disabled: closing === t.id,
5374
+ onClick: () => void done(t, o.id),
5375
+ children: [
5376
+ closing === t.id ? /* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }) : o.id === "connected" ? /* @__PURE__ */ jsx(Check, { className: "h-3 w-3" }) : null,
5377
+ " ",
5378
+ o.label
5379
+ ]
5380
+ },
5381
+ o.id
5382
+ ))
5383
+ ] })
5384
+ ] }, t.id);
5385
+ })
5386
+ ] }, g.id))
5387
+ ] });
5388
+ }
5231
5389
  var LEAD_STATUS_OPTIONS = [
5232
5390
  { value: "new", labelKey: "crm.leads.statusNew", dot: "#3B82F6" },
5233
5391
  { value: "contacted", labelKey: "crm.leads.statusContacted", dot: "#8B5CF6" },
@@ -6372,7 +6530,7 @@ function LeadQualification({ lead }) {
6372
6530
  }
6373
6531
  var PREFERRED_ORDER = ["whatsapp", "call", "visit", "email", "meeting", "note"];
6374
6532
  var CONTACT_TYPES = /* @__PURE__ */ new Set(["whatsapp", "call", "visit", "email", "meeting"]);
6375
- var OUTCOMES = ["connected", "no_answer", "left_message", "replied", "scheduled", "not_now"];
6533
+ var OUTCOMES2 = ["connected", "no_answer", "left_message", "replied", "scheduled", "not_now"];
6376
6534
  function LogActivityButton({ target, onLogged }) {
6377
6535
  const t = useTranslation();
6378
6536
  const provider = useCrmProvider();
@@ -6465,7 +6623,7 @@ function LogActivityButton({ target, onLogged }) {
6465
6623
  if (nextOutcome === "not_now" && !nextDate) setNextDate(defaultFutureContactDate());
6466
6624
  }, children: [
6467
6625
  /* @__PURE__ */ jsx(SelectTrigger, { className: "h-9 text-sm", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
6468
- /* @__PURE__ */ jsx(SelectContent, { children: OUTCOMES.map((o) => /* @__PURE__ */ jsx(SelectItem, { value: o, children: t(`crm.outcome.${o}`) }, o)) })
6626
+ /* @__PURE__ */ jsx(SelectContent, { children: OUTCOMES2.map((o) => /* @__PURE__ */ jsx(SelectItem, { value: o, children: t(`crm.outcome.${o}`) }, o)) })
6469
6627
  ] }),
6470
6628
  /* @__PURE__ */ jsxs("div", { className: "relative", children: [
6471
6629
  /* @__PURE__ */ jsx(
@@ -9747,7 +9905,7 @@ function CrmPage({ config, provider, store, registries }) {
9747
9905
  }
9748
9906
  ) },
9749
9907
  // As telas que ainda não existem — ver ./GapScreens.
9750
- { id: "tasks", render: () => /* @__PURE__ */ jsx(TasksView, {}) },
9908
+ { id: "tasks", render: () => /* @__PURE__ */ jsx(TasksView, { onOpenDeal: (id) => navigate(`pipeline-detail:${id}`, `/sales/pipeline/${id}`), onOpenLead: (id) => navigate(`leads-detail:${id}`) }) },
9751
9909
  { id: "follow-ups", render: () => /* @__PURE__ */ jsx(FollowUpsView, {}) },
9752
9910
  { id: "loyalty", render: () => /* @__PURE__ */ jsx(LoyaltyView, {}) },
9753
9911
  { id: "referrals", render: () => /* @__PURE__ */ jsx(ReferralsView, {}) },
@@ -9786,5 +9944,5 @@ function CrmPage({ config, provider, store, registries }) {
9786
9944
  }
9787
9945
 
9788
9946
  export { CrmPage };
9789
- //# sourceMappingURL=CrmPage-LPIRRUUT.js.map
9790
- //# sourceMappingURL=CrmPage-LPIRRUUT.js.map
9947
+ //# sourceMappingURL=CrmPage-F3YNUGTY.js.map
9948
+ //# sourceMappingURL=CrmPage-F3YNUGTY.js.map