@fayz-ai/plugin-crm 0.29.2 → 0.29.3

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.
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ /**
3
+ * A empresa que alguém DIGITOU, mas que não é empresa nenhuma ainda.
4
+ *
5
+ * Um lead de feira chega com o nome da casa escrito à mão num campo de texto —
6
+ * `people.metadata.company`. É o dado mais importante do card e o único que o
7
+ * sistema não sabia usar: sem uma linha em `plg_crm_companies` e sem o vínculo
8
+ * em `plg_crm_company_people`, o negócio nasce sem `company_id`, a manchete do
9
+ * funil cai no nome da PESSOA e o painel Empresa não aparece — o nome fica na
10
+ * tela como texto morto, sem levar a lugar nenhum.
11
+ *
12
+ * Medido em 2026-09-28 nesta base: 27 leads assim, 26 negócios abertos por
13
+ * baixo deles. Não é um caso de borda, é um quarto do funil.
14
+ *
15
+ * O gesto é UM clique porque o dado já está lá. Quem escreveu "AELA BURGER" no
16
+ * crachá já decidiu o nome; pedir um formulário aqui é pedir que digite de novo
17
+ * o que acabou de ler na tela. Se já existir uma casa com esse nome a gente
18
+ * VINCULA em vez de criar uma segunda — duplicata de empresa é o defeito que
19
+ * este botão existiria para causar se fosse ingênuo.
20
+ *
21
+ * Some assim que o vínculo existe. O `trg_plg_crm_deals_stamp_company` carimba
22
+ * o negócio a partir do vínculo, então não há nada a fazer do lado do card.
23
+ */
24
+ export declare function LinkCompanyPrompt({ personId, companyText, onLinked }: {
25
+ /** A pessoa a ligar — o lead ou o contato do card. */
26
+ personId: string;
27
+ /** O que está escrito no cadastro. Sem isto não há o que oferecer. */
28
+ companyText?: string | null;
29
+ onLinked?: (companyId: string) => void;
30
+ }): React.JSX.Element | null;
31
+ //# sourceMappingURL=LinkCompanyPrompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkCompanyPrompt.d.ts","sourceRoot":"","sources":["../../src/components/LinkCompanyPrompt.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAMlD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;IACrE,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAA;IAChB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;CACvC,4BAgEA"}
package/dist/index.js CHANGED
@@ -3762,6 +3762,68 @@ function buildCrmRegistries(activityTypes) {
3762
3762
  } : registry
3763
3763
  );
3764
3764
  }
3765
+ function LinkCompanyPrompt({ personId, companyText, onLinked }) {
3766
+ const t2 = useTranslation();
3767
+ const provider = useCrmProvider();
3768
+ const saveCompany = useCrmStore((s) => s.saveCompany);
3769
+ const [existente, setExistente] = useState(null);
3770
+ const [ligando, setLigando] = useState(false);
3771
+ const nome = companyText?.trim();
3772
+ useEffect(() => {
3773
+ if (!nome) {
3774
+ setExistente(null);
3775
+ return;
3776
+ }
3777
+ let vivo = true;
3778
+ provider.searchCompanies(nome, 5).then((rs) => {
3779
+ if (!vivo) return;
3780
+ const exato = rs.find((r) => r.name.trim().toLowerCase() === nome.toLowerCase());
3781
+ setExistente(exato ? { id: exato.id, name: exato.name } : null);
3782
+ }).catch(() => {
3783
+ if (vivo) setExistente(null);
3784
+ });
3785
+ return () => {
3786
+ vivo = false;
3787
+ };
3788
+ }, [provider, nome]);
3789
+ if (!nome) return null;
3790
+ async function vincular() {
3791
+ if (!nome || ligando) return;
3792
+ setLigando(true);
3793
+ try {
3794
+ const companyId = existente?.id ?? (await saveCompany({ name: nome })).id;
3795
+ await provider.linkCompanyPerson({ companyId, personId, isPrimary: true });
3796
+ toast.success(t2("crm.linkCompany.done", { name: nome }));
3797
+ onLinked?.(companyId);
3798
+ } catch (err) {
3799
+ toast.error(t2("crm.linkCompany.failed"), { description: err?.message });
3800
+ } finally {
3801
+ setLigando(false);
3802
+ }
3803
+ }
3804
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-card border border-dashed bg-muted/20 px-3 py-3", children: [
3805
+ /* @__PURE__ */ jsx(Building2, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
3806
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
3807
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: nome }),
3808
+ /* @__PURE__ */ jsx("span", { className: "block text-[11px] text-muted-foreground", children: t2(existente ? "crm.linkCompany.hintExisting" : "crm.linkCompany.hintNew") })
3809
+ ] }),
3810
+ /* @__PURE__ */ jsxs(
3811
+ "button",
3812
+ {
3813
+ type: "button",
3814
+ onClick: () => {
3815
+ void vincular();
3816
+ },
3817
+ disabled: ligando,
3818
+ className: "inline-flex shrink-0 items-center gap-1.5 rounded-button bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-button transition-opacity hover:opacity-90 disabled:opacity-60",
3819
+ children: [
3820
+ ligando ? /* @__PURE__ */ jsx(Loader2, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
3821
+ t2(existente ? "crm.linkCompany.link" : "crm.linkCompany.create")
3822
+ ]
3823
+ }
3824
+ )
3825
+ ] });
3826
+ }
3765
3827
  var STYLE = {
3766
3828
  hot: { icon: Flame, cls: "bg-destructive-soft text-destructive-soft-foreground" },
3767
3829
  warm: { icon: Sun, cls: "bg-warning-soft text-warning-soft-foreground" },
@@ -4625,6 +4687,16 @@ function DealCardModal({ dealId, open, onClose, onViewLead, onViewQuote, onViewC
4625
4687
  deal.groupCompanies ? /* @__PURE__ */ jsx("span", { className: "block truncate text-[11px] text-muted-foreground", children: t2("crm.card.groupCompanies", { count: String(deal.groupCompanies) }) }) : null
4626
4688
  ] })
4627
4689
  ] }) }),
4690
+ !company && pessoaDoCard?.id && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsx(
4691
+ LinkCompanyPrompt,
4692
+ {
4693
+ personId: pessoaDoCard.id,
4694
+ companyText: pessoaDoCard.company ?? draft.company,
4695
+ onLinked: () => {
4696
+ void provider.getLiveDealById(dealId).then((d) => d && setDeal(d));
4697
+ }
4698
+ }
4699
+ ) }),
4628
4700
  company && /* @__PURE__ */ jsx(Section, { title: t2("crm.card.companyTitle"), children: /* @__PURE__ */ jsxs(
4629
4701
  "button",
4630
4702
  {
@@ -7071,6 +7143,7 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7071
7143
  const [archiving, setArchiving] = useState(false);
7072
7144
  const [confirmandoArquivo, setConfirmandoArquivo] = useState(false);
7073
7145
  const [lead, setLead] = useState(null);
7146
+ const [recarga, setRecarga] = useState(0);
7074
7147
  useRecordVisit(lead ? {
7075
7148
  id: lead.id,
7076
7149
  kind: "lead",
@@ -7114,7 +7187,7 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7114
7187
  }
7115
7188
  setLoading(false);
7116
7189
  });
7117
- }, [leadId]);
7190
+ }, [leadId, recarga]);
7118
7191
  if (loading) {
7119
7192
  return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
7120
7193
  /* @__PURE__ */ jsx(SubpageHeader, { title: t2("crm.leadDetail.loading"), parentLabel: t2("crm.leads.title"), onBack }),
@@ -7235,12 +7308,21 @@ function LeadDetailView({ leadId, onBack, onCreateQuote, onViewQuote, onOpenComp
7235
7308
  ] })
7236
7309
  ]
7237
7310
  }
7238
- ) : (
7311
+ ) : lead.company ? (
7239
7312
  /* Sem vínculo ainda: mostra o texto livre que veio da
7240
- importação. Trocar um pelo outro apagaria a única coisa
7241
- que 297 leads importados têm. */
7242
- lead.company
7243
- )
7313
+ importação — e OFERECE transformá-lo em cadastro. Trocar
7314
+ um pelo outro apagaria a única coisa que 297 leads
7315
+ importados têm; deixá-lo como texto morto era o que fazia
7316
+ o card do funil cair no nome da pessoa. */
7317
+ /* @__PURE__ */ jsx(
7318
+ LinkCompanyPrompt,
7319
+ {
7320
+ personId: leadId,
7321
+ companyText: lead.company,
7322
+ onLinked: () => setRecarga((n) => n + 1)
7323
+ }
7324
+ )
7325
+ ) : null
7244
7326
  }
7245
7327
  ) }),
7246
7328
  lead.credentialCompany && lead.credentialCompany.trim().toLowerCase() !== (lead.companyName ?? "").trim().toLowerCase() && /* @__PURE__ */ jsx("div", { className: "px-5 md:border-b md:last:border-b-0", children: /* @__PURE__ */ jsx(
@@ -29147,6 +29229,12 @@ var en = {
29147
29229
  "crm.deals.allCampaigns": "All campaigns",
29148
29230
  "crm.deals.allCities": "All cities",
29149
29231
  "crm.card.companyTitle": "Company",
29232
+ "crm.linkCompany.hintNew": "Written on the record, but not a company here yet",
29233
+ "crm.linkCompany.hintExisting": "This company already exists \u2014 this person is not linked to it",
29234
+ "crm.linkCompany.create": "Create",
29235
+ "crm.linkCompany.link": "Link",
29236
+ "crm.linkCompany.done": "{{name}} linked",
29237
+ "crm.linkCompany.failed": "Could not link the company",
29150
29238
  "crm.card.groupTitle": "Economic group",
29151
29239
  "crm.card.groupCompanies": "{{count}} companies",
29152
29240
  "crm.card.takeOver": "Take this lead",
@@ -30000,6 +30088,12 @@ var ptBR = {
30000
30088
  "crm.deals.allCampaigns": "Todas as campanhas",
30001
30089
  "crm.deals.allCities": "Todas as cidades",
30002
30090
  "crm.card.companyTitle": "Empresa",
30091
+ "crm.linkCompany.hintNew": "Escrito no cadastro, mas ainda n\xE3o \xE9 uma empresa aqui",
30092
+ "crm.linkCompany.hintExisting": "Esta empresa j\xE1 existe \u2014 falta ligar esta pessoa a ela",
30093
+ "crm.linkCompany.create": "Cadastrar",
30094
+ "crm.linkCompany.link": "Vincular",
30095
+ "crm.linkCompany.done": "{{name}} vinculada",
30096
+ "crm.linkCompany.failed": "N\xE3o deu para vincular a empresa",
30003
30097
  "crm.card.groupTitle": "Grupo econ\xF4mico",
30004
30098
  "crm.card.groupCompanies": "{{count}} CNPJs",
30005
30099
  "crm.card.takeOver": "Assumir este lead",