@fayz-ai/plugin-crm 0.9.0-next.0 → 0.9.0-next.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 (52) hide show
  1. package/dist/components/LeadAttachments.d.ts +8 -0
  2. package/dist/components/LeadAttachments.d.ts.map +1 -0
  3. package/dist/data/supabase.d.ts.map +1 -1
  4. package/dist/index.js +244 -30
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/form-answers.d.ts +21 -0
  7. package/dist/lib/form-answers.d.ts.map +1 -1
  8. package/dist/lib/relative-time.d.ts +10 -0
  9. package/dist/lib/relative-time.d.ts.map +1 -0
  10. package/dist/locales/en.d.ts.map +1 -1
  11. package/dist/locales/pt-BR.d.ts.map +1 -1
  12. package/dist/migrations/index.d.ts +2 -0
  13. package/dist/migrations/index.d.ts.map +1 -1
  14. package/dist/public/context.d.ts +25 -2
  15. package/dist/public/context.d.ts.map +1 -1
  16. package/dist/public/createPublicFormsPlugin.d.ts +9 -0
  17. package/dist/public/createPublicFormsPlugin.d.ts.map +1 -1
  18. package/dist/public/data.supabase.d.ts.map +1 -1
  19. package/dist/public/inbox.d.ts.map +1 -1
  20. package/dist/public/index.d.ts +4 -2
  21. package/dist/public/index.d.ts.map +1 -1
  22. package/dist/public/index.js +150 -8
  23. package/dist/public/index.js.map +1 -1
  24. package/dist/public/types.d.ts +32 -1
  25. package/dist/public/types.d.ts.map +1 -1
  26. package/dist/public/uploads.d.ts +61 -0
  27. package/dist/public/uploads.d.ts.map +1 -0
  28. package/dist/views/ActivityListView.d.ts.map +1 -1
  29. package/dist/views/DealSidebar.d.ts.map +1 -1
  30. package/dist/views/LeadDetailView.d.ts.map +1 -1
  31. package/dist/views/PipelineView.d.ts.map +1 -1
  32. package/package.json +6 -6
  33. package/src/components/LeadAttachments.tsx +140 -0
  34. package/src/data/supabase.ts +3 -0
  35. package/src/lib/form-answers.tsx +41 -0
  36. package/src/lib/relative-time.ts +84 -0
  37. package/src/locales/en.ts +1 -0
  38. package/src/locales/pt-BR.ts +1 -0
  39. package/src/migrations/015_lead_attachments.sql +357 -0
  40. package/src/migrations/016_public_lead_activity.sql +123 -0
  41. package/src/migrations/index.ts +487 -1
  42. package/src/public/context.tsx +85 -4
  43. package/src/public/createPublicFormsPlugin.ts +25 -1
  44. package/src/public/data.supabase.ts +5 -0
  45. package/src/public/inbox.ts +7 -0
  46. package/src/public/index.ts +22 -1
  47. package/src/public/types.ts +33 -1
  48. package/src/public/uploads.ts +205 -0
  49. package/src/views/ActivityListView.tsx +16 -3
  50. package/src/views/DealSidebar.tsx +47 -19
  51. package/src/views/LeadDetailView.tsx +47 -5
  52. package/src/views/PipelineView.tsx +13 -0
@@ -0,0 +1,8 @@
1
+ import type { LeadAttachmentRef } from '../lib/form-answers';
2
+ export interface LeadAttachmentsProps {
3
+ attachments: LeadAttachmentRef[];
4
+ /** `compact` é a versão do card no funil; `full`, a do detalhe do lead. */
5
+ variant?: 'compact' | 'full';
6
+ }
7
+ export declare function LeadAttachments({ attachments, variant }: LeadAttachmentsProps): import("react").JSX.Element | null;
8
+ //# sourceMappingURL=LeadAttachments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LeadAttachments.d.ts","sourceRoot":"","sources":["../../src/components/LeadAttachments.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AA2D5D,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,iBAAiB,EAAE,CAAA;IAChC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;CAC7B;AAED,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,OAAgB,EAAE,EAAE,oBAAoB,sCA2DtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAiE9C,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,gBAAgB,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;IACtF,kFAAkF;IAClF,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACvE,GAAG,eAAe,CAu1BlB"}
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAiE9C,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,gBAAgB,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;IACtF,kFAAkF;IAClF,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACvE,GAAG,eAAe,CA01BlB"}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import React15, { useState, useMemo, useRef, useEffect } from 'react';
2
2
  import { createPluginContext, PluginSettingsPanel, dedup, useModuleNavigation, createViewRouter, ModuleActionBar, useTenantPluginSettings, SettingsGroup, ToggleRow, useLimitGuard, formatCurrency, PersonLink, useAccessOptional, invalidateLimit } from '@fayz-ai/saas';
3
3
  import { registerTranslations, createSafeDataProvider, useTranslation, useActiveTenantId, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
4
- import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, Button, SubpageHeader, ListView, useSaveBar, SearchSelect, DatePicker, DataTable, Breadcrumb, DashboardCanvas, SegmentedControl, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter, CurrencyInput, Dropdown, DropdownTrigger, DropdownContent, DropdownLabel, DropdownSeparator, DropdownItem, ConfirmDialog, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
4
+ import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, PageTransition, ModulePage, Button, SubpageHeader, ListView, useSaveBar, SearchSelect, DatePicker, DataTable, Breadcrumb, PhoneLink, DashboardCanvas, SegmentedControl, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter, CurrencyInput, Dropdown, DropdownTrigger, DropdownContent, DropdownLabel, DropdownSeparator, DropdownItem, ConfirmDialog, normalizePhone, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
- import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, MoveRight, Target, ArrowRightLeft, UserPlus, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight, Plus, Sparkles, Clock, Calendar, ArrowRight, ChevronDown, Printer, X, Pencil, User, Hash, CircleCheckBig, Ban, Tag, Trash2, Receipt, CircleAlert, CircleDashed, Loader2, DollarSign } from 'lucide-react';
6
+ import { Archive, FileX2, FileCheck2, Send, FilePlus2, XCircle, Trophy, MoveRight, Target, ArrowRightLeft, UserPlus, MessageCircle, CheckSquare, FileText, Users, Mail, Phone, Filter, Globe, Check, ChevronRight, Plus, Sparkles, Clock, Calendar, ArrowRight, ChevronDown, Printer, X, Pencil, User, Hash, CircleCheckBig, Ban, Tag, Trash2, Paperclip, ImageOff, Receipt, CircleAlert, CircleDashed, Loader2, DollarSign } from 'lucide-react';
7
7
  import { createPortal } from 'react-dom';
8
8
  import { createStore as createStore$1 } from 'zustand/vanilla';
9
9
 
@@ -329,6 +329,139 @@ function answerEntries(fields) {
329
329
  if (!fields || typeof fields !== "object" || Array.isArray(fields)) return [];
330
330
  return Object.entries(fields).filter(([, v]) => v !== null && v !== void 0 && v !== "");
331
331
  }
332
+ var DEFAULT_ATTACHMENT_BUCKET = "crm-lead-uploads";
333
+ function leadAttachments(metadata) {
334
+ const raw = metadata?.attachments;
335
+ if (!Array.isArray(raw)) return [];
336
+ return raw.flatMap((entry) => {
337
+ if (!entry || typeof entry !== "object") return [];
338
+ const a = entry;
339
+ if (typeof a.path !== "string" || !a.path) return [];
340
+ return [{
341
+ bucket: typeof a.bucket === "string" && a.bucket ? a.bucket : DEFAULT_ATTACHMENT_BUCKET,
342
+ path: a.path,
343
+ slot: typeof a.slot === "string" ? a.slot : void 0,
344
+ mime: typeof a.mime === "string" ? a.mime : void 0,
345
+ size: typeof a.size === "number" ? a.size : void 0
346
+ }];
347
+ });
348
+ }
349
+ var SIGNED_URL_TTL_SECONDS = 3600;
350
+ function isImage(mime) {
351
+ return !!mime && mime.startsWith("image/");
352
+ }
353
+ function label(attachment) {
354
+ const raw = attachment.slot || attachment.path.split("/").pop() || "anexo";
355
+ return raw.charAt(0).toUpperCase() + raw.slice(1);
356
+ }
357
+ async function signAll(attachments) {
358
+ const client = getSupabaseClientOptional();
359
+ if (!client) return attachments.map((a) => ({ ...a, url: null }));
360
+ const byBucket = /* @__PURE__ */ new Map();
361
+ for (const a of attachments) {
362
+ byBucket.set(a.bucket, [...byBucket.get(a.bucket) ?? [], a]);
363
+ }
364
+ const urlByPath = /* @__PURE__ */ new Map();
365
+ for (const [bucket, items] of byBucket) {
366
+ try {
367
+ const { data } = await client.storage.from(bucket).createSignedUrls(items.map((i) => i.path), SIGNED_URL_TTL_SECONDS);
368
+ for (const row of data ?? []) {
369
+ if (row?.path && row.signedUrl) urlByPath.set(row.path, row.signedUrl);
370
+ }
371
+ } catch {
372
+ }
373
+ }
374
+ return attachments.map((a) => ({ ...a, url: urlByPath.get(a.path) ?? null }));
375
+ }
376
+ function LeadAttachments({ attachments, variant = "full" }) {
377
+ const t2 = useTranslation();
378
+ const [signed, setSigned] = useState([]);
379
+ const key = attachments.map((a) => a.path).join("|");
380
+ useEffect(() => {
381
+ let alive = true;
382
+ if (!attachments.length) {
383
+ setSigned([]);
384
+ return;
385
+ }
386
+ signAll(attachments).then((rows) => {
387
+ if (alive) setSigned(rows);
388
+ });
389
+ return () => {
390
+ alive = false;
391
+ };
392
+ }, [key]);
393
+ if (!attachments.length) return null;
394
+ const size = variant === "compact" ? "h-16 w-16" : "h-24 w-24";
395
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
396
+ /* @__PURE__ */ jsxs("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider inline-flex items-center gap-1.5", children: [
397
+ /* @__PURE__ */ jsx(Paperclip, { className: "h-3 w-3" }),
398
+ t2("crm.leadDetail.attachments"),
399
+ " \xB7 ",
400
+ attachments.length
401
+ ] }),
402
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: (signed.length ? signed : attachments.map((a) => ({ ...a, url: null }))).map((a) => /* @__PURE__ */ jsxs(
403
+ "a",
404
+ {
405
+ href: a.url ?? void 0,
406
+ target: "_blank",
407
+ rel: "noopener noreferrer",
408
+ title: label(a),
409
+ className: `group relative ${size} shrink-0 overflow-hidden rounded-lg border bg-muted ${a.url ? "cursor-pointer hover:border-primary" : "cursor-default"}`,
410
+ children: [
411
+ a.url && isImage(a.mime) ? /* @__PURE__ */ jsx("img", { src: a.url, alt: label(a), className: "h-full w-full object-cover", loading: "lazy" }) : /* @__PURE__ */ jsx("span", { className: "flex h-full w-full items-center justify-center text-muted-foreground", children: isImage(a.mime) ? /* @__PURE__ */ jsx(ImageOff, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(FileText, { className: "h-5 w-5" }) }),
412
+ /* @__PURE__ */ jsx("span", { className: "absolute inset-x-0 bottom-0 truncate bg-background/80 px-1 py-0.5 text-[9px] font-medium", children: label(a) })
413
+ ]
414
+ },
415
+ a.path
416
+ )) })
417
+ ] });
418
+ }
419
+
420
+ // src/lib/relative-time.ts
421
+ var MINUTE = 60;
422
+ var HOUR = 60 * MINUTE;
423
+ var DAY = 24 * HOUR;
424
+ var WEEK = 7 * DAY;
425
+ var MONTH = 30 * DAY;
426
+ var YEAR = 365 * DAY;
427
+ var STEPS2 = [
428
+ ["year", YEAR],
429
+ ["month", MONTH],
430
+ ["week", WEEK],
431
+ ["day", DAY],
432
+ ["hour", HOUR],
433
+ ["minute", MINUTE]
434
+ ];
435
+ function formatRelativeTime(iso, locale = "pt-BR", now2 = /* @__PURE__ */ new Date()) {
436
+ if (!iso) return "";
437
+ const then = new Date(iso);
438
+ const at = then.getTime();
439
+ if (Number.isNaN(at)) return "";
440
+ const elapsed = Math.round((now2.getTime() - at) / 1e3);
441
+ const abs = Math.abs(elapsed);
442
+ if (abs < 45) {
443
+ return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(0, "second");
444
+ }
445
+ const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "always" });
446
+ for (const [unit, seconds] of STEPS2) {
447
+ if (abs >= seconds) {
448
+ return rtf.format(-Math.round(elapsed / seconds), unit);
449
+ }
450
+ }
451
+ return rtf.format(0, "second");
452
+ }
453
+ function formatDateTime(iso, locale = "pt-BR") {
454
+ if (!iso) return "";
455
+ const at = new Date(iso);
456
+ if (Number.isNaN(at.getTime())) return "";
457
+ return at.toLocaleString(locale, {
458
+ day: "2-digit",
459
+ month: "2-digit",
460
+ year: "numeric",
461
+ hour: "2-digit",
462
+ minute: "2-digit"
463
+ });
464
+ }
332
465
  var TYPE_ICONS = {
333
466
  call: Phone,
334
467
  email: Mail,
@@ -353,7 +486,7 @@ var TYPE_ICONS = {
353
486
  };
354
487
  function TabBar({ active, counts, onChange }) {
355
488
  const t2 = useTranslation();
356
- const label = (text, count, isActive) => /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
489
+ const label2 = (text, count, isActive) => /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
357
490
  text,
358
491
  count != null && count > 0 && /* @__PURE__ */ jsx("span", { className: `inline-flex items-center justify-center min-w-[16px] h-4 rounded-full px-1 text-[10px] font-semibold ${isActive ? "bg-background/20 text-background" : "bg-muted text-muted-foreground"}`, children: count })
359
492
  ] });
@@ -363,9 +496,9 @@ function TabBar({ active, counts, onChange }) {
363
496
  value: active,
364
497
  onChange,
365
498
  options: [
366
- { value: "overview", label: label(t2("crm.dealSidebar.overview"), void 0, active === "overview") },
367
- { value: "activity", label: label(t2("crm.dealSidebar.activity"), counts.activity, active === "activity") },
368
- { value: "quotes", label: label(t2("crm.dealSidebar.quotes"), counts.quotes, active === "quotes") }
499
+ { value: "overview", label: label2(t2("crm.dealSidebar.overview"), void 0, active === "overview") },
500
+ { value: "activity", label: label2(t2("crm.dealSidebar.activity"), counts.activity, active === "activity") },
501
+ { value: "quotes", label: label2(t2("crm.dealSidebar.quotes"), counts.quotes, active === "quotes") }
369
502
  ]
370
503
  }
371
504
  ) });
@@ -373,14 +506,18 @@ function TabBar({ active, counts, onChange }) {
373
506
  function FormAnswers({ lead }) {
374
507
  const t2 = useTranslation();
375
508
  const entries = answerEntries(lead?.metadata?.fields);
376
- if (entries.length === 0) return null;
509
+ const attachments = leadAttachments(lead?.metadata);
510
+ if (entries.length === 0 && attachments.length === 0) return null;
377
511
  const formId = lead?.metadata?.formId;
378
- return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
379
- /* @__PURE__ */ jsx("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: formId ? `${t2("crm.leadDetail.formAnswers")} \xB7 ${formId}` : t2("crm.leadDetail.formAnswers") }),
380
- /* @__PURE__ */ jsx("div", { className: "rounded-xl border divide-y", children: entries.map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3 px-4 py-2.5", children: [
381
- /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground shrink-0 min-w-24", children: humanizeKey(key) }),
382
- /* @__PURE__ */ jsx("span", { className: "text-xs text-right flex-1 break-words", children: renderFieldValue(value) ?? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/50", children: "\u2014" }) })
383
- ] }, key)) })
512
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
513
+ entries.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
514
+ /* @__PURE__ */ jsx("h4", { className: "text-[11px] font-semibold text-muted-foreground uppercase tracking-wider", children: formId ? `${t2("crm.leadDetail.formAnswers")} \xB7 ${formId}` : t2("crm.leadDetail.formAnswers") }),
515
+ /* @__PURE__ */ jsx("div", { className: "rounded-xl border divide-y", children: entries.map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3 px-4 py-2.5", children: [
516
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground shrink-0 min-w-24", children: humanizeKey(key) }),
517
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-right flex-1 break-words", children: renderFieldValue(value) ?? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/50", children: "\u2014" }) })
518
+ ] }, key)) })
519
+ ] }),
520
+ /* @__PURE__ */ jsx(LeadAttachments, { attachments, variant: "compact" })
384
521
  ] });
385
522
  }
386
523
  function OverviewTab({ deal, lead, currency }) {
@@ -436,6 +573,18 @@ function OverviewTab({ deal, lead, currency }) {
436
573
  /* @__PURE__ */ jsx(User, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
437
574
  /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground flex-1", children: t2("crm.dealSidebar.assignedTo") }),
438
575
  /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: deal.assignedToName })
576
+ ] }),
577
+ deal.createdAt && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-3", children: [
578
+ /* @__PURE__ */ jsx(Clock, { className: "h-4 w-4 text-muted-foreground shrink-0" }),
579
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground flex-1", children: t2("crm.dealSidebar.created") }),
580
+ /* @__PURE__ */ jsxs("span", { className: "text-xs font-medium text-right", children: [
581
+ formatDateTime(deal.createdAt, currency.locale),
582
+ /* @__PURE__ */ jsxs("span", { className: "ml-1.5 text-muted-foreground", children: [
583
+ "(",
584
+ formatRelativeTime(deal.createdAt, currency.locale),
585
+ ")"
586
+ ] })
587
+ ] })
439
588
  ] })
440
589
  ] }),
441
590
  lead && (lead.email || lead.phone) && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
@@ -446,11 +595,17 @@ function OverviewTab({ deal, lead, currency }) {
446
595
  " ",
447
596
  /* @__PURE__ */ jsx("span", { className: "truncate", children: lead.email })
448
597
  ] }),
449
- lead.phone && /* @__PURE__ */ jsxs("a", { href: `tel:${lead.phone}`, className: "flex items-center gap-3 px-4 py-2.5 text-xs text-primary hover:bg-muted/30 transition-colors", children: [
450
- /* @__PURE__ */ jsx(Phone, { className: "h-3.5 w-3.5 shrink-0" }),
451
- " ",
452
- /* @__PURE__ */ jsx("span", { children: lead.phone })
453
- ] })
598
+ lead.phone && /* @__PURE__ */ jsxs(
599
+ PhoneLink,
600
+ {
601
+ phone: lead.phone,
602
+ className: "flex items-center gap-3 px-4 py-2.5 text-xs text-primary hover:bg-muted/30 transition-colors hover:no-underline",
603
+ children: [
604
+ /* @__PURE__ */ jsx(MessageCircle, { className: "h-3.5 w-3.5 shrink-0" }),
605
+ /* @__PURE__ */ jsx("span", { children: normalizePhone(lead.phone).display })
606
+ ]
607
+ }
608
+ )
454
609
  ] })
455
610
  ] }),
456
611
  /* @__PURE__ */ jsx(FormAnswers, { lead }),
@@ -826,7 +981,15 @@ function DealCard({ deal, saving, currency, tagDefs, onClick, onArchive, onDragS
826
981
  deal.probability,
827
982
  "%"
828
983
  ] })
829
- ] })
984
+ ] }),
985
+ deal.createdAt && /* @__PURE__ */ jsx(
986
+ "p",
987
+ {
988
+ className: "mt-1 text-[10px] text-muted-foreground",
989
+ title: formatDateTime(deal.createdAt, currency.locale),
990
+ children: formatRelativeTime(deal.createdAt, currency.locale)
991
+ }
992
+ )
830
993
  ]
831
994
  }
832
995
  );
@@ -2084,15 +2247,16 @@ function renderFieldValue2(value) {
2084
2247
  if (typeof value === "object") return JSON.stringify(value);
2085
2248
  return String(value);
2086
2249
  }
2087
- function FieldRow({ label, value }) {
2250
+ function FieldRow({ label: label2, value }) {
2088
2251
  return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-3 gap-4 py-3", children: [
2089
- /* @__PURE__ */ jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: label }),
2252
+ /* @__PURE__ */ jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: label2 }),
2090
2253
  /* @__PURE__ */ jsx("dd", { className: "col-span-2 text-sm text-foreground", children: value ?? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/50", children: "\u2014" }) })
2091
2254
  ] });
2092
2255
  }
2093
2256
  function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
2094
2257
  const provider = useCrmProvider();
2095
2258
  const { currency } = useCrmConfig();
2259
+ const locale = currency.locale;
2096
2260
  const t2 = useTranslation();
2097
2261
  const archiveLead = useCrmStore((s) => s.archiveLead);
2098
2262
  const canArchive = useCanArchive();
@@ -2197,7 +2361,13 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
2197
2361
  /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.contactInfo") }),
2198
2362
  /* @__PURE__ */ jsx("div", { className: "rounded-xl border bg-card shadow-sm", children: /* @__PURE__ */ jsxs("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: [
2199
2363
  /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.email"), value: lead.email ? /* @__PURE__ */ jsx("a", { href: `mailto:${lead.email}`, className: "text-primary hover:underline", children: lead.email }) : null }) }),
2200
- /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.phone"), value: lead.phone ? /* @__PURE__ */ jsx("a", { href: `tel:${lead.phone}`, className: "text-primary hover:underline", children: lead.phone }) : null }) }),
2364
+ /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b", children: /* @__PURE__ */ jsx(
2365
+ FieldRow,
2366
+ {
2367
+ label: t2("crm.leadDetail.phone"),
2368
+ value: lead.phone ? /* @__PURE__ */ jsx(PhoneLink, { phone: lead.phone, className: "text-primary" }) : null
2369
+ }
2370
+ ) }),
2201
2371
  /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.company"), value: lead.company }) }),
2202
2372
  /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.source"), value: lead.sourceName }) })
2203
2373
  ] }) })
@@ -2206,11 +2376,13 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
2206
2376
  const meta = lead.metadata ?? {};
2207
2377
  const fields = Object.entries(meta.fields ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
2208
2378
  const utm = Object.entries(meta.utm ?? {}).filter(([, v]) => renderFieldValue2(v) !== null);
2209
- if (!fields.length && !utm.length) return null;
2379
+ const attachments = leadAttachments(lead.metadata);
2380
+ if (!fields.length && !utm.length && !attachments.length) return null;
2210
2381
  return /* @__PURE__ */ jsxs("div", { children: [
2211
2382
  /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground mb-1", children: t2("crm.leadDetail.formAnswers") }),
2212
2383
  /* @__PURE__ */ jsxs("div", { className: "rounded-xl border bg-card shadow-sm", children: [
2213
2384
  /* @__PURE__ */ jsx("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: fields.map(([key, value]) => /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: humanizeKey2(key), value: renderFieldValue2(value) }) }, key)) }),
2385
+ attachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "border-t px-5 py-3", children: /* @__PURE__ */ jsx(LeadAttachments, { attachments }) }),
2214
2386
  utm.length > 0 && /* @__PURE__ */ jsx("div", { className: "border-t px-5 py-3 flex flex-wrap gap-x-4 gap-y-1", children: utm.map(([key, value]) => /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
2215
2387
  humanizeKey2(key.replace(/^utm_/, "")),
2216
2388
  ":",
@@ -2261,8 +2433,34 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote }) {
2261
2433
  /* @__PURE__ */ jsx("div", { className: "rounded-xl border bg-card shadow-sm", children: /* @__PURE__ */ jsxs("dl", { className: "grid divide-y md:grid-cols-2 md:divide-y-0", children: [
2262
2434
  /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.value"), value: lead.value != null && lead.value > 0 ? lead.value : null }) }),
2263
2435
  /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.assignedTo"), value: lead.assignedToName }) }),
2264
- /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.created"), value: lead.createdAt?.slice(0, 10) }) }),
2265
- /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(FieldRow, { label: t2("crm.leadDetail.updated"), value: lead.updatedAt?.slice(0, 10) }) })
2436
+ /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(
2437
+ FieldRow,
2438
+ {
2439
+ label: t2("crm.leadDetail.created"),
2440
+ value: lead.createdAt ? /* @__PURE__ */ jsxs("span", { className: "inline-flex flex-wrap items-baseline gap-x-1.5", children: [
2441
+ /* @__PURE__ */ jsx("span", { children: formatDateTime(lead.createdAt, locale) }),
2442
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
2443
+ "(",
2444
+ formatRelativeTime(lead.createdAt, locale),
2445
+ ")"
2446
+ ] })
2447
+ ] }) : null
2448
+ }
2449
+ ) }),
2450
+ /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(
2451
+ FieldRow,
2452
+ {
2453
+ label: t2("crm.leadDetail.updated"),
2454
+ value: lead.updatedAt ? /* @__PURE__ */ jsxs("span", { className: "inline-flex flex-wrap items-baseline gap-x-1.5", children: [
2455
+ /* @__PURE__ */ jsx("span", { children: formatDateTime(lead.updatedAt, locale) }),
2456
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
2457
+ "(",
2458
+ formatRelativeTime(lead.updatedAt, locale),
2459
+ ")"
2460
+ ] })
2461
+ ] }) : null
2462
+ }
2463
+ ) })
2266
2464
  ] }) })
2267
2465
  ] }),
2268
2466
  lead.tags && lead.tags.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
@@ -2333,6 +2531,7 @@ function ActivitySkeleton() {
2333
2531
  function ActivityListView({ onOpenLead, onOpenQuote } = {}) {
2334
2532
  const t2 = useTranslation();
2335
2533
  const provider = useCrmProvider();
2534
+ const { currency } = useCrmConfig();
2336
2535
  const [selectedDealId, setSelectedDealId] = useState(null);
2337
2536
  const activities = useCrmStore((s) => s.activities);
2338
2537
  const activitiesLoading = useCrmStore((s) => s.activitiesLoading);
@@ -2476,10 +2675,20 @@ function ActivityListView({ onOpenLead, onOpenQuote } = {}) {
2476
2675
  ] })
2477
2676
  ] })
2478
2677
  ] }),
2479
- /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5 text-[10px] text-muted-foreground shrink-0 pt-1", children: [
2480
- new Date(a.createdAt).toLocaleDateString(),
2481
- openRecord && /* @__PURE__ */ jsx(ArrowRight, { className: "h-3 w-3 opacity-0 transition-opacity group-hover:opacity-60" })
2482
- ] })
2678
+ /* @__PURE__ */ jsxs(
2679
+ "span",
2680
+ {
2681
+ className: "flex items-center gap-1.5 text-[10px] text-muted-foreground shrink-0 pt-1",
2682
+ title: formatDateTime(a.createdAt, currency.locale),
2683
+ children: [
2684
+ /* @__PURE__ */ jsxs("span", { className: "text-right leading-tight", children: [
2685
+ /* @__PURE__ */ jsx("span", { className: "block", children: formatRelativeTime(a.createdAt, currency.locale) }),
2686
+ /* @__PURE__ */ jsx("span", { className: "block opacity-70", children: formatDateTime(a.createdAt, currency.locale) })
2687
+ ] }),
2688
+ openRecord && /* @__PURE__ */ jsx(ArrowRight, { className: "h-3 w-3 opacity-0 transition-opacity group-hover:opacity-60" })
2689
+ ]
2690
+ }
2691
+ )
2483
2692
  ]
2484
2693
  },
2485
2694
  a.id
@@ -3541,7 +3750,10 @@ function createSupabaseCrmProvider(options) {
3541
3750
  metadata: {
3542
3751
  formId: r.form_id ?? void 0,
3543
3752
  fields: r.custom_fields ?? {},
3544
- utm: r.utm ?? {}
3753
+ utm: r.utm ?? {},
3754
+ // Ponteiros para o Storage (015). Sem esta linha o anexo é write-only:
3755
+ // chega no banco e nenhuma tela consegue mostrar.
3756
+ attachments: r.attachments ?? []
3545
3757
  },
3546
3758
  tenantId: r.tenant_id,
3547
3759
  createdAt: r.created_at,
@@ -4835,6 +5047,7 @@ var en = {
4835
5047
  "crm.leadDetail.archive": "Archive",
4836
5048
  "crm.leadDetail.backToList": "Back to list",
4837
5049
  "crm.leadDetail.formAnswers": "Form answers",
5050
+ "crm.leadDetail.attachments": "Attachments",
4838
5051
  "crm.leadDetail.company": "Company",
4839
5052
  "crm.leadDetail.contactInfo": "Contact Information",
4840
5053
  "crm.leadDetail.createQuote": "Create Quote",
@@ -5142,6 +5355,7 @@ var ptBR = {
5142
5355
  "crm.leadDetail.archive": "Arquivar",
5143
5356
  "crm.leadDetail.backToList": "Voltar \xE0 lista",
5144
5357
  "crm.leadDetail.formAnswers": "Dados do formul\xE1rio",
5358
+ "crm.leadDetail.attachments": "Anexos",
5145
5359
  "crm.leadDetail.company": "Empresa",
5146
5360
  "crm.leadDetail.contactInfo": "Informa\xE7\xF5es de Contato",
5147
5361
  "crm.leadDetail.createQuote": "Criar Or\xE7amento",