@fayz-ai/plugin-crm 0.41.0 → 0.43.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,13 +6,15 @@ 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';
14
14
  import { createPortal } from 'react-dom';
15
15
  import { HelpdeskStatusPanel } from '@fayz-ai/plugin-support';
16
+ import { getTasksProvider } from '@fayz-ai/tasks/store';
17
+ import { TaskCallBlock } from '@fayz-ai/tasks/components/TaskCallBlock';
16
18
 
17
19
  function usePanel(fn, args = {}) {
18
20
  const [data, setData] = React2.useState(null);
@@ -3504,11 +3506,11 @@ function defaultFutureContactDate(now = /* @__PURE__ */ new Date()) {
3504
3506
  }
3505
3507
  function FutureContactPicker({ value, onChange, required = false }) {
3506
3508
  const t = useTranslation();
3507
- const today = /* @__PURE__ */ new Date();
3509
+ const today2 = /* @__PURE__ */ new Date();
3508
3510
  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) }
3511
+ { label: t("crm.followUp.inSevenDays"), value: addDaysToDate(today2, 7) },
3512
+ { label: t("crm.followUp.inOneMonth"), value: addMonthsToDate(today2, 1) },
3513
+ { label: t("crm.followUp.inThreeMonths"), value: addMonthsToDate(today2, 3) }
3512
3514
  ];
3513
3515
  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
3516
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-xs font-medium text-foreground", children: [
@@ -5135,22 +5137,6 @@ function FranchisorGoalsView() {
5135
5137
  }
5136
5138
  );
5137
5139
  }
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
5140
  function FollowUpsView() {
5155
5141
  return /* @__PURE__ */ jsx(
5156
5142
  ComingSoon,
@@ -5228,6 +5214,129 @@ function PendingReturnsView() {
5228
5214
  }
5229
5215
  );
5230
5216
  }
5217
+ function today() {
5218
+ const d = /* @__PURE__ */ new Date();
5219
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
5220
+ }
5221
+ function bucketOf(t, now) {
5222
+ const due = t.dueDate?.slice(0, 10);
5223
+ if (!due) return "undated";
5224
+ return due < now ? "late" : due === now ? "today" : "next";
5225
+ }
5226
+ var BUCKETS = [
5227
+ { id: "late", label: "Atrasadas" },
5228
+ { id: "today", label: "Para hoje" },
5229
+ { id: "next", label: "Pr\xF3ximas" },
5230
+ { id: "undated", label: "Sem prazo" }
5231
+ ];
5232
+ var isCrm = (t) => t.source === "crm" || (t.subjectType ?? "").startsWith("crm.");
5233
+ var byDue = (a, b) => (a.dueDate ?? "9999").localeCompare(b.dueDate ?? "9999") || a.createdAt.localeCompare(b.createdAt);
5234
+ function TasksView() {
5235
+ const [me, setMe] = React2.useState(null);
5236
+ const [team, setTeam] = React2.useState([]);
5237
+ const [who, setWho] = React2.useState(null);
5238
+ const [all, setAll] = React2.useState(null);
5239
+ const [closing, setClosing] = React2.useState(null);
5240
+ React2.useEffect(() => {
5241
+ void loadMyUserId().then(setMe);
5242
+ void loadTeamOrNull().then((t) => setTeam(t ?? []));
5243
+ }, []);
5244
+ const load = React2.useCallback(async () => {
5245
+ try {
5246
+ const rows = await getTasksProvider().getTasks({ status: ["todo", "in_progress"] });
5247
+ setAll(rows.filter(isCrm).sort(byDue));
5248
+ } catch (e) {
5249
+ toast.error(e.message);
5250
+ setAll([]);
5251
+ }
5252
+ }, []);
5253
+ React2.useEffect(() => {
5254
+ void load();
5255
+ }, [load]);
5256
+ React2.useEffect(() => {
5257
+ if (who !== null || all === null) return;
5258
+ setWho(me && all.some((t) => t.assignedToId === me) ? me : "all");
5259
+ }, [who, all, me]);
5260
+ const tasks = all === null || who === null ? null : who === "all" ? all : all.filter((t) => t.assignedToId === who);
5261
+ const people = React2.useMemo(() => {
5262
+ const n = /* @__PURE__ */ new Map();
5263
+ for (const t of all ?? []) if (t.assignedToId) n.set(t.assignedToId, (n.get(t.assignedToId) ?? 0) + 1);
5264
+ return [...n].map(([userId, count]) => ({ userId, count })).sort((a, b) => b.count - a.count);
5265
+ }, [all]);
5266
+ const nameOf = (id) => id ? team.find((m) => m.userId === id)?.name : void 0;
5267
+ async function update(id, input) {
5268
+ setClosing(id);
5269
+ try {
5270
+ await getTasksProvider().updateTask(id, input);
5271
+ if (input.status === "done") {
5272
+ setAll((list) => (list ?? []).filter((x) => x.id !== id));
5273
+ toast.success("Feito \u2014 registrado no neg\xF3cio");
5274
+ }
5275
+ } catch (e) {
5276
+ toast.error(e.message);
5277
+ } finally {
5278
+ setClosing(null);
5279
+ }
5280
+ }
5281
+ const now = today();
5282
+ const grouped = BUCKETS.map((b) => ({ ...b, items: (tasks ?? []).filter((t) => bucketOf(t, now) === b.id) })).filter((g) => g.items.length > 0);
5283
+ const late = grouped.find((g) => g.id === "late")?.items.length ?? 0;
5284
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
5285
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-end justify-between gap-2", children: [
5286
+ /* @__PURE__ */ jsxs("div", { children: [
5287
+ /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: "Tarefas" }),
5288
+ /* @__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)` : ""}` })
5289
+ ] }),
5290
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1", children: [
5291
+ me && /* @__PURE__ */ jsxs(Button, { size: "sm", variant: who === me ? "secondary" : "ghost", className: "h-7 text-xs", onClick: () => setWho(me), children: [
5292
+ /* @__PURE__ */ jsx(User, { className: "h-3.5 w-3.5" }),
5293
+ " Minhas \xB7 ",
5294
+ people.find((x) => x.userId === me)?.count ?? 0
5295
+ ] }),
5296
+ /* @__PURE__ */ jsxs(Button, { size: "sm", variant: who === "all" ? "secondary" : "ghost", className: "h-7 text-xs", onClick: () => setWho("all"), children: [
5297
+ "Todas \xB7 ",
5298
+ all?.length ?? 0
5299
+ ] }),
5300
+ 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: [
5301
+ (nameOf(x.userId) ?? "Sem nome").split(/\s+/)[0],
5302
+ " \xB7 ",
5303
+ x.count
5304
+ ] }, x.userId))
5305
+ ] })
5306
+ ] }),
5307
+ 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" }) }),
5308
+ tasks !== null && tasks.length === 0 && /* @__PURE__ */ jsxs(Card, { className: "flex flex-col items-center gap-2 p-10 text-center text-muted-foreground", children: [
5309
+ /* @__PURE__ */ jsx(CheckCheck, { className: "h-7 w-7 text-success" }),
5310
+ /* @__PURE__ */ jsxs("p", { className: "text-sm", children: [
5311
+ "Nenhuma tarefa pendente",
5312
+ who !== "all" && who !== me ? ` para ${nameOf(who ?? void 0) ?? "esta pessoa"}` : "",
5313
+ "."
5314
+ ] })
5315
+ ] }),
5316
+ grouped.map((g) => /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
5317
+ /* @__PURE__ */ jsxs("p", { className: cn("flex items-center gap-1.5 text-xs font-medium", g.id === "late" ? "text-destructive" : "text-muted-foreground"), children: [
5318
+ g.id === "late" ? /* @__PURE__ */ jsx(AlertTriangle, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx(CalendarClock, { className: "h-3.5 w-3.5" }),
5319
+ g.label,
5320
+ " \xB7 ",
5321
+ g.items.length
5322
+ ] }),
5323
+ g.items.map((t) => {
5324
+ const owner = t.assignedToName ?? nameOf(t.assignedToId ?? void 0);
5325
+ return /* @__PURE__ */ jsxs(Card, { className: "p-3", "data-testid": "crm-task", children: [
5326
+ /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-sm font-medium", children: [
5327
+ t.kind === "call" && /* @__PURE__ */ jsx(Phone, { className: "h-3.5 w-3.5 shrink-0 text-info" }),
5328
+ t.title
5329
+ ] }),
5330
+ /* @__PURE__ */ jsxs("p", { className: "mb-2 mt-0.5 text-[11px] text-muted-foreground", children: [
5331
+ t.dueDate ? (/* @__PURE__ */ new Date(`${t.dueDate.slice(0, 10)}T12:00:00`)).toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit" }) : "sem prazo",
5332
+ who === "all" && owner ? ` \xB7 ${owner.split(/\s+/)[0]}` : ""
5333
+ ] }),
5334
+ /* @__PURE__ */ jsx(TaskCallBlock, { task: t, onUpdate: update, busy: closing === t.id })
5335
+ ] }, t.id);
5336
+ })
5337
+ ] }, g.id))
5338
+ ] });
5339
+ }
5231
5340
  var LEAD_STATUS_OPTIONS = [
5232
5341
  { value: "new", labelKey: "crm.leads.statusNew", dot: "#3B82F6" },
5233
5342
  { value: "contacted", labelKey: "crm.leads.statusContacted", dot: "#8B5CF6" },
@@ -9786,5 +9895,5 @@ function CrmPage({ config, provider, store, registries }) {
9786
9895
  }
9787
9896
 
9788
9897
  export { CrmPage };
9789
- //# sourceMappingURL=CrmPage-LPIRRUUT.js.map
9790
- //# sourceMappingURL=CrmPage-LPIRRUUT.js.map
9898
+ //# sourceMappingURL=CrmPage-UNNYOINI.js.map
9899
+ //# sourceMappingURL=CrmPage-UNNYOINI.js.map