@fayz-ai/plugin-crm 0.32.14 → 0.32.15
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.
- package/dist/CrmGeneralSettings-6XPS3L42.js +4 -0
- package/dist/CrmGeneralSettings-6XPS3L42.js.map +1 -0
- package/dist/CrmPage-BHJG2BZV.js +10212 -0
- package/dist/CrmPage-BHJG2BZV.js.map +1 -0
- package/dist/SegmentsView-PHLN2MOW.js +385 -0
- package/dist/SegmentsView-PHLN2MOW.js.map +1 -0
- package/dist/chunk-7V46TYYX.js +13 -0
- package/dist/chunk-7V46TYYX.js.map +1 -0
- package/dist/chunk-BIQL232X.js +809 -0
- package/dist/chunk-BIQL232X.js.map +1 -0
- package/dist/chunk-CA24LK57.js +174 -0
- package/dist/chunk-CA24LK57.js.map +1 -0
- package/dist/chunk-QJOLAGGN.js +129 -0
- package/dist/chunk-QJOLAGGN.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5031 -30820
- package/dist/index.js.map +1 -1
- package/dist/migrations/main.browser.js +69 -0
- package/dist/migrations/main.browser.js.map +1 -0
- package/dist/migrations/main.js +14137 -0
- package/dist/migrations/main.js.map +1 -0
- package/package.json +11 -5
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
import React2, { useState, useEffect } from 'react';
|
|
2
|
+
import { Button, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Badge, Checkbox } from '@fayz-ai/ui';
|
|
3
|
+
import { useUnitBootstrap, useUnitStore } from '@fayz-ai/admin';
|
|
4
|
+
import { useTranslation, getSupabaseClientOptional, getActiveUnitId } from '@fayz-ai/core';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
import { ArrowUp, ArrowDown, X } from 'lucide-react';
|
|
7
|
+
|
|
8
|
+
// src/data/registries.ts
|
|
9
|
+
|
|
10
|
+
// src/data/tables.ts
|
|
11
|
+
var T = {
|
|
12
|
+
activities: "plg_crm_activities",
|
|
13
|
+
tags: "plg_crm_tags",
|
|
14
|
+
activityTypes: "plg_crm_activity_types",
|
|
15
|
+
pipelines: "plg_crm_pipelines",
|
|
16
|
+
dealStatuses: "plg_crm_deal_statuses",
|
|
17
|
+
pipelineStages: "plg_crm_pipeline_stages",
|
|
18
|
+
deals: "plg_crm_deals",
|
|
19
|
+
// Retired in place: the deal left `orders` and took its fields with it. What
|
|
20
|
+
// survives here is the link row to a legacy order, nothing the deal owns.
|
|
21
|
+
// Writing pipeline_id/stage_id/probability here writes where nobody reads.
|
|
22
|
+
dealExtensions: "plg_crm_deal_extensions",
|
|
23
|
+
leadSources: "plg_crm_lead_sources",
|
|
24
|
+
partners: "plg_crm_partners",
|
|
25
|
+
surveys: "plg_crm_surveys",
|
|
26
|
+
surveyQuestions: "plg_crm_survey_questions",
|
|
27
|
+
surveyResponses: "plg_crm_survey_responses",
|
|
28
|
+
surveyAnswers: "plg_crm_survey_answers",
|
|
29
|
+
surveyStats: "v_crm_survey_stats",
|
|
30
|
+
segments: "plg_crm_segments",
|
|
31
|
+
segmentMembers: "plg_crm_segment_members",
|
|
32
|
+
engagementSettings: "plg_crm_engagement_settings",
|
|
33
|
+
personEngagement: "v_crm_person_engagement",
|
|
34
|
+
scorecardWeights: "plg_crm_scorecard_weights",
|
|
35
|
+
repLeads: "plg_crm_rep_leads",
|
|
36
|
+
assignmentRules: "plg_crm_assignment_rules",
|
|
37
|
+
leadOffers: "v_crm_lead_offers",
|
|
38
|
+
leadBacklog: "v_crm_lead_backlog",
|
|
39
|
+
leadScore: "v_crm_lead_score",
|
|
40
|
+
leadScoreWeights: "plg_crm_lead_score_weights",
|
|
41
|
+
// Tabela do espinho, não do plugin: a lápide de um merge continua em
|
|
42
|
+
// `people`, e é de lá que sai o nome do cadastro absorvido.
|
|
43
|
+
people: "people",
|
|
44
|
+
personMerges: "person_merges",
|
|
45
|
+
companies: "plg_crm_companies",
|
|
46
|
+
// The read model: the table plus people_count, open_deals, won_value and how
|
|
47
|
+
// many siblings share the CNPJ root. Reads go here, writes to `companies`.
|
|
48
|
+
// A enriquecida (059). A 013 continua dona de `v_crm_companies`, que não pode
|
|
49
|
+
// crescer sem quebrar o replay da cadeia — o porquê está escrito na 059.
|
|
50
|
+
companiesView: "v_crm_companies_enriched",
|
|
51
|
+
companyPeople: "plg_crm_company_people",
|
|
52
|
+
companyPeopleView: "v_crm_company_people",
|
|
53
|
+
personPhones: "plg_crm_person_phones",
|
|
54
|
+
// `v_leads` plus the person's primary company. The CRM screens read this one;
|
|
55
|
+
// the spine's `v_leads` stays what it was.
|
|
56
|
+
crmLeads: "v_crm_leads",
|
|
57
|
+
companyGroups: "plg_crm_company_groups",
|
|
58
|
+
companyGroupsView: "v_crm_company_groups",
|
|
59
|
+
companyGroupMembers: "plg_crm_company_group_members",
|
|
60
|
+
companyGroupMembersView: "v_crm_company_group_members",
|
|
61
|
+
// Grupos que a raiz do CNPJ revela e ninguém declarou. PROPOSTA — ler daqui
|
|
62
|
+
// e escrever em `companyGroupMembers` é decisão de gente.
|
|
63
|
+
companyGroupCandidates: "v_crm_company_group_candidates",
|
|
64
|
+
// A OUTRA proposta: mesma bandeira, raízes diferentes. Franquia e federação
|
|
65
|
+
// são invisíveis para a raiz do CNPJ, e são metade dos casos reais.
|
|
66
|
+
companyBrandCandidates: "v_crm_company_brand_candidates",
|
|
67
|
+
companyGroupRollup: "v_crm_company_group_rollup",
|
|
68
|
+
leadDuplicates: "v_crm_lead_duplicates",
|
|
69
|
+
// O funil com os vínculos já agregados (060). A tela lê daqui; as duas
|
|
70
|
+
// tabelas abaixo são para ESCREVER o vínculo.
|
|
71
|
+
pipelinesView: "v_crm_pipelines",
|
|
72
|
+
pipelineUnits: "plg_crm_pipeline_units",
|
|
73
|
+
pipelineTeams: "plg_crm_pipeline_teams"
|
|
74
|
+
};
|
|
75
|
+
function PartnerUnitsInput({ value, onChange }) {
|
|
76
|
+
const t = useTranslation();
|
|
77
|
+
useUnitBootstrap();
|
|
78
|
+
const units = useUnitStore((s) => s.units);
|
|
79
|
+
const loading = useUnitStore((s) => s.loading);
|
|
80
|
+
const selected = new Set(value ?? []);
|
|
81
|
+
function toggle(id, on) {
|
|
82
|
+
const next = new Set(selected);
|
|
83
|
+
if (on) next.add(id);
|
|
84
|
+
else next.delete(id);
|
|
85
|
+
onChange([...next]);
|
|
86
|
+
}
|
|
87
|
+
if (loading && units.length === 0) {
|
|
88
|
+
return /* @__PURE__ */ jsx("div", { className: "space-y-1.5", "aria-hidden": true, children: [0, 1, 2].map((i) => /* @__PURE__ */ jsx("div", { className: "h-8 rounded-input bg-muted/40 animate-pulse" }, i)) });
|
|
89
|
+
}
|
|
90
|
+
if (units.length === 0) {
|
|
91
|
+
return /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("crm.partners.noUnits") });
|
|
92
|
+
}
|
|
93
|
+
return /* @__PURE__ */ jsx("div", { className: "space-y-1.5 rounded-input border border-input bg-card p-2", children: units.map((u) => /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2.5 cursor-pointer px-1 py-0.5", children: [
|
|
94
|
+
/* @__PURE__ */ jsx(
|
|
95
|
+
Checkbox,
|
|
96
|
+
{
|
|
97
|
+
checked: selected.has(u.id),
|
|
98
|
+
onChange: (on) => toggle(u.id, on)
|
|
99
|
+
}
|
|
100
|
+
),
|
|
101
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm", children: u.name })
|
|
102
|
+
] }, u.id)) });
|
|
103
|
+
}
|
|
104
|
+
function PartnerUnitsCell({ value }) {
|
|
105
|
+
const t = useTranslation();
|
|
106
|
+
const count = Array.isArray(value) ? value.length : 0;
|
|
107
|
+
if (count === 0) return /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: t("crm.partners.allUnits") });
|
|
108
|
+
return /* @__PURE__ */ jsx("span", { className: "text-sm", children: t("crm.partners.unitCount", { count }) });
|
|
109
|
+
}
|
|
110
|
+
function PartnerOnlineBookingCell({ value }) {
|
|
111
|
+
const t = useTranslation();
|
|
112
|
+
return value ? /* @__PURE__ */ jsx(Badge, { children: t("common.yes") }) : /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: t("common.no") });
|
|
113
|
+
}
|
|
114
|
+
async function loadTeam(opts) {
|
|
115
|
+
const supabase = getSupabaseClientOptional();
|
|
116
|
+
if (!supabase) return [];
|
|
117
|
+
const { data: memberships, error } = await supabase.from("v_authz_memberships").select("user_id, person_id").eq("active", true);
|
|
118
|
+
if (error) throw new Error(error.message);
|
|
119
|
+
let rows = memberships ?? [];
|
|
120
|
+
if (rows.length === 0) return [];
|
|
121
|
+
const unitId = opts?.unitId ?? getActiveUnitId();
|
|
122
|
+
if (unitId) {
|
|
123
|
+
const { data: reach } = await supabase.from("v_authz_user_unit_access").select("user_id").eq("unit_id", unitId);
|
|
124
|
+
const allowed = new Set((reach ?? []).map((r) => r.user_id));
|
|
125
|
+
if (allowed.size > 0) rows = rows.filter((r) => allowed.has(r.user_id));
|
|
126
|
+
}
|
|
127
|
+
const { data: people } = await supabase.from("people").select("id, name").in("id", rows.map((r) => r.person_id));
|
|
128
|
+
const nameById = new Map(
|
|
129
|
+
(people ?? []).map((p) => [p.id, p.name ?? ""])
|
|
130
|
+
);
|
|
131
|
+
const porUsuario = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const r of rows) {
|
|
133
|
+
if (porUsuario.has(r.user_id)) continue;
|
|
134
|
+
porUsuario.set(r.user_id, { userId: r.user_id, name: nameById.get(r.person_id) || r.user_id.slice(0, 8) });
|
|
135
|
+
}
|
|
136
|
+
return [...porUsuario.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
137
|
+
}
|
|
138
|
+
async function loadTeamOrNull(opts) {
|
|
139
|
+
try {
|
|
140
|
+
return await loadTeam(opts);
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function loadMyUserId() {
|
|
146
|
+
const supabase = getSupabaseClientOptional();
|
|
147
|
+
if (!supabase) return null;
|
|
148
|
+
try {
|
|
149
|
+
const { data } = await supabase.auth.getUser();
|
|
150
|
+
return data?.user?.id ?? null;
|
|
151
|
+
} catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
var ROW_ACTION = "rounded p-1 text-muted-foreground hover:bg-muted disabled:opacity-30";
|
|
156
|
+
var loadMembers = loadTeam;
|
|
157
|
+
function AssigneeRotaInput({ value, onChange }) {
|
|
158
|
+
const t = useTranslation();
|
|
159
|
+
const [members, setMembers] = useState(null);
|
|
160
|
+
const [failed, setFailed] = useState(false);
|
|
161
|
+
const rota = value ?? [];
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
void loadMembers().then(setMembers).catch(() => {
|
|
164
|
+
setFailed(true);
|
|
165
|
+
setMembers([]);
|
|
166
|
+
});
|
|
167
|
+
}, []);
|
|
168
|
+
if (members === null) {
|
|
169
|
+
return /* @__PURE__ */ jsx("div", { className: "h-8 animate-pulse rounded-input bg-muted/40", "aria-hidden": true });
|
|
170
|
+
}
|
|
171
|
+
if (failed || members.length === 0 && rota.length === 0) {
|
|
172
|
+
return /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("crm.rota.cannotRead") });
|
|
173
|
+
}
|
|
174
|
+
const nameOf = (id) => members.find((m) => m.userId === id)?.name ?? id.slice(0, 8);
|
|
175
|
+
const available = members.filter((m) => !rota.includes(m.userId));
|
|
176
|
+
function move(i, delta) {
|
|
177
|
+
const j = i + delta;
|
|
178
|
+
if (j < 0 || j >= rota.length) return;
|
|
179
|
+
const next = [...rota];
|
|
180
|
+
[next[i], next[j]] = [next[j], next[i]];
|
|
181
|
+
onChange(next);
|
|
182
|
+
}
|
|
183
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
184
|
+
rota.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("crm.rota.empty") }) : /* @__PURE__ */ jsx("ol", { className: "space-y-1", children: rota.map((id, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 rounded-input border border-input bg-card px-2 py-1.5", children: [
|
|
185
|
+
/* @__PURE__ */ jsx("span", { className: "w-5 text-xs tabular-nums text-muted-foreground", children: i + 1 }),
|
|
186
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm", children: nameOf(id) }),
|
|
187
|
+
/* @__PURE__ */ jsx(
|
|
188
|
+
Button,
|
|
189
|
+
{
|
|
190
|
+
type: "button",
|
|
191
|
+
variant: "bare",
|
|
192
|
+
size: "bare",
|
|
193
|
+
onClick: () => move(i, -1),
|
|
194
|
+
disabled: i === 0,
|
|
195
|
+
className: ROW_ACTION,
|
|
196
|
+
title: t("crm.rota.up"),
|
|
197
|
+
children: /* @__PURE__ */ jsx(ArrowUp, { className: "h-3.5 w-3.5" })
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
/* @__PURE__ */ jsx(
|
|
201
|
+
Button,
|
|
202
|
+
{
|
|
203
|
+
type: "button",
|
|
204
|
+
variant: "bare",
|
|
205
|
+
size: "bare",
|
|
206
|
+
onClick: () => move(i, 1),
|
|
207
|
+
disabled: i === rota.length - 1,
|
|
208
|
+
className: ROW_ACTION,
|
|
209
|
+
title: t("crm.rota.down"),
|
|
210
|
+
children: /* @__PURE__ */ jsx(ArrowDown, { className: "h-3.5 w-3.5" })
|
|
211
|
+
}
|
|
212
|
+
),
|
|
213
|
+
/* @__PURE__ */ jsx(
|
|
214
|
+
Button,
|
|
215
|
+
{
|
|
216
|
+
type: "button",
|
|
217
|
+
variant: "bare",
|
|
218
|
+
size: "bare",
|
|
219
|
+
onClick: () => onChange(rota.filter((x) => x !== id)),
|
|
220
|
+
className: `${ROW_ACTION} hover:text-destructive`,
|
|
221
|
+
title: t("crm.rota.remove"),
|
|
222
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" })
|
|
223
|
+
}
|
|
224
|
+
)
|
|
225
|
+
] }, id)) }),
|
|
226
|
+
available.length > 0 && /* @__PURE__ */ jsxs(Select, { value: "", onValueChange: (v) => onChange([...rota, v]), children: [
|
|
227
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: "h-auto bg-background px-2 py-1.5 shadow-none", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("crm.rota.add") }) }),
|
|
228
|
+
/* @__PURE__ */ jsx(SelectContent, { children: available.map((m) => /* @__PURE__ */ jsx(SelectItem, { value: m.userId, children: m.name }, m.userId)) })
|
|
229
|
+
] })
|
|
230
|
+
] });
|
|
231
|
+
}
|
|
232
|
+
function AssigneeRotaCell({ value }) {
|
|
233
|
+
const t = useTranslation();
|
|
234
|
+
const ids = Array.isArray(value) ? value : [];
|
|
235
|
+
if (ids.length === 0) return /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("crm.rota.empty") });
|
|
236
|
+
return /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("crm.rota.count", { count: String(ids.length) }) });
|
|
237
|
+
}
|
|
238
|
+
function AssigneeName({ userId }) {
|
|
239
|
+
const [name, setName] = useState(null);
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
let alive = true;
|
|
242
|
+
void loadMembers().then((ms) => {
|
|
243
|
+
if (alive) setName(ms.find((m) => m.userId === userId)?.name ?? null);
|
|
244
|
+
}).catch(() => {
|
|
245
|
+
});
|
|
246
|
+
return () => {
|
|
247
|
+
alive = false;
|
|
248
|
+
};
|
|
249
|
+
}, [userId]);
|
|
250
|
+
return /* @__PURE__ */ jsx(Fragment, { children: name ?? userId.slice(0, 8) });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/data/registries.ts
|
|
254
|
+
var leadSourceEntity = {
|
|
255
|
+
name: "Lead Source",
|
|
256
|
+
namePlural: "Lead Sources",
|
|
257
|
+
icon: "Globe",
|
|
258
|
+
displayField: "name",
|
|
259
|
+
defaultSort: "name",
|
|
260
|
+
fields: [
|
|
261
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
262
|
+
// O V1 não tem descrição em nenhuma das nove origens, e o guia registra o
|
|
263
|
+
// preço disso: quem cadastra confunde "Indicação" com "Influenciador". A
|
|
264
|
+
// diferença precisa estar escrita onde a escolha é feita.
|
|
265
|
+
{ key: "description", label: "Description", type: "text", showInTable: true, searchable: true },
|
|
266
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
267
|
+
],
|
|
268
|
+
data: { table: T.leadSources, tenantScoped: true, searchColumns: ["name", "description"] }
|
|
269
|
+
};
|
|
270
|
+
var partnerEntity = {
|
|
271
|
+
name: "Partnership",
|
|
272
|
+
namePlural: "Partnerships",
|
|
273
|
+
icon: "Handshake",
|
|
274
|
+
displayField: "name",
|
|
275
|
+
defaultSort: "name",
|
|
276
|
+
fields: [
|
|
277
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
278
|
+
{ key: "description", label: "Description", type: "text", showInTable: false, searchable: true },
|
|
279
|
+
{
|
|
280
|
+
key: "allUnits",
|
|
281
|
+
label: "Valid in every unit",
|
|
282
|
+
type: "boolean",
|
|
283
|
+
defaultValue: true,
|
|
284
|
+
showInTable: false,
|
|
285
|
+
hint: "Turn off to name the units where the partnership applies."
|
|
286
|
+
},
|
|
287
|
+
// A coluna "Unidades" do V1: "Todas" ou "N unidade(s)". A célula lê a
|
|
288
|
+
// LISTA — o CHECK da tabela faz lista vazia significar a rede inteira e
|
|
289
|
+
// nada mais, e a tela de detalhe entrega o valor sem o resto da linha.
|
|
290
|
+
{
|
|
291
|
+
key: "unitIds",
|
|
292
|
+
label: "Units",
|
|
293
|
+
type: "custom",
|
|
294
|
+
showInTable: true,
|
|
295
|
+
// `[]`, não vazio: o formulário genérico manda o valor mesmo com o campo
|
|
296
|
+
// escondido, e sem isto a coluna NOT NULL recebe null e o save volta 400.
|
|
297
|
+
defaultValue: [],
|
|
298
|
+
visibleWhen: (values) => values.allUnits === false,
|
|
299
|
+
renderInput: ({ value, onChange }) => React2.createElement(PartnerUnitsInput, {
|
|
300
|
+
value,
|
|
301
|
+
onChange
|
|
302
|
+
}),
|
|
303
|
+
renderCell: (value) => React2.createElement(PartnerUnitsCell, { value })
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
key: "allowsOnlineBooking",
|
|
307
|
+
label: "Online booking",
|
|
308
|
+
type: "boolean",
|
|
309
|
+
showInTable: true,
|
|
310
|
+
defaultValue: false,
|
|
311
|
+
hint: "Members can book on their own from the public page.",
|
|
312
|
+
renderCell: (value) => React2.createElement(PartnerOnlineBookingCell, { value })
|
|
313
|
+
},
|
|
314
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
315
|
+
],
|
|
316
|
+
data: { table: T.partners, tenantScoped: true, searchColumns: ["name", "description"] }
|
|
317
|
+
};
|
|
318
|
+
var tagEntity = {
|
|
319
|
+
name: "Tag",
|
|
320
|
+
namePlural: "Tags",
|
|
321
|
+
icon: "Tag",
|
|
322
|
+
displayField: "name",
|
|
323
|
+
defaultSort: "name",
|
|
324
|
+
fields: [
|
|
325
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
326
|
+
// O slug é o que vive em people.tags/orders.tags — renomear a tag NÃO o
|
|
327
|
+
// muda (o trigger só o deriva quando está vazio), e é por isso que renomear
|
|
328
|
+
// não órfã registro. Exposto porque, quando um chip não aparece onde
|
|
329
|
+
// deveria, a resposta está sempre aqui.
|
|
330
|
+
{ key: "slug", label: "Slug", type: "text", showInTable: true },
|
|
331
|
+
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
|
|
332
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
|
|
333
|
+
],
|
|
334
|
+
data: { table: T.tags, tenantScoped: true }
|
|
335
|
+
};
|
|
336
|
+
var pipelineUnitEntity = {
|
|
337
|
+
name: "Unit",
|
|
338
|
+
namePlural: "Units",
|
|
339
|
+
icon: "Building2",
|
|
340
|
+
displayField: "unitId",
|
|
341
|
+
fields: [
|
|
342
|
+
{
|
|
343
|
+
key: "unitId",
|
|
344
|
+
label: "Unit",
|
|
345
|
+
type: "relation",
|
|
346
|
+
required: true,
|
|
347
|
+
showInTable: true,
|
|
348
|
+
relation: { table: "v_units", labelField: "name" }
|
|
349
|
+
},
|
|
350
|
+
{ key: "pipelineId", label: "Pipeline", type: "relation", required: true, relation: { table: T.pipelines, labelField: "name" } }
|
|
351
|
+
],
|
|
352
|
+
data: { table: T.pipelineUnits, tenantScoped: true }
|
|
353
|
+
};
|
|
354
|
+
var pipelineTeamEntity = {
|
|
355
|
+
name: "Team",
|
|
356
|
+
namePlural: "Teams",
|
|
357
|
+
icon: "Users",
|
|
358
|
+
displayField: "teamId",
|
|
359
|
+
fields: [
|
|
360
|
+
{
|
|
361
|
+
key: "teamId",
|
|
362
|
+
label: "Team",
|
|
363
|
+
type: "relation",
|
|
364
|
+
required: true,
|
|
365
|
+
showInTable: true,
|
|
366
|
+
// A equipe é a categoria `staff_team` (139 do espinha) — a mesma que os
|
|
367
|
+
// Cadastros criam na aba Equipes dos Profissionais.
|
|
368
|
+
relation: { table: "categories", labelField: "name", filter: { kind: "staff_team" } }
|
|
369
|
+
},
|
|
370
|
+
{ key: "pipelineId", label: "Pipeline", type: "relation", required: true, relation: { table: T.pipelines, labelField: "name" } }
|
|
371
|
+
],
|
|
372
|
+
data: { table: T.pipelineTeams, tenantScoped: true }
|
|
373
|
+
};
|
|
374
|
+
var pipelineStageEntity = {
|
|
375
|
+
name: "Stage",
|
|
376
|
+
namePlural: "Stages",
|
|
377
|
+
icon: "Workflow",
|
|
378
|
+
displayField: "name",
|
|
379
|
+
defaultSort: "order",
|
|
380
|
+
fields: [
|
|
381
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
382
|
+
{
|
|
383
|
+
key: "pipelineId",
|
|
384
|
+
label: "Pipeline",
|
|
385
|
+
type: "relation",
|
|
386
|
+
relation: { table: T.pipelines, labelField: "name" },
|
|
387
|
+
required: true,
|
|
388
|
+
showInTable: true
|
|
389
|
+
},
|
|
390
|
+
{ key: "order", label: "Order", type: "number", required: true, showInTable: true, defaultValue: 0 },
|
|
391
|
+
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
|
|
392
|
+
{ key: "probability", label: "Probability %", type: "number", min: 0, max: 100, showInTable: true, defaultValue: 0 },
|
|
393
|
+
// O terceiro papel especial, que o V1 tem desde sempre e o V2 não tinha:
|
|
394
|
+
// ONDE O LEAD ENTRA. Antes era inferido no cliente pela menor ordem entre
|
|
395
|
+
// as não-terminais — acerta quase sempre e erra em silêncio quando alguém
|
|
396
|
+
// reordena o funil. O índice único da 005 garante uma por funil.
|
|
397
|
+
{ key: "isInitial", label: "Entry Stage", type: "boolean", showInTable: true, defaultValue: false },
|
|
398
|
+
{ key: "isWon", label: "Won Stage", type: "boolean", showInTable: true, defaultValue: false },
|
|
399
|
+
{ key: "isLost", label: "Lost Stage", type: "boolean", showInTable: true, defaultValue: false },
|
|
400
|
+
// O código fica FORA do formulário: é a identidade estável por onde uma
|
|
401
|
+
// automação aponta para a etapa, e deixá-lo editável ofereceria justamente
|
|
402
|
+
// quebrar o que ele protege. O banco o deriva do nome quando a etapa nasce
|
|
403
|
+
// (gatilho da 005) e nunca mais o toca.
|
|
404
|
+
{ key: "code", label: "Code", type: "text", showInForm: false }
|
|
405
|
+
],
|
|
406
|
+
data: { table: T.pipelineStages, tenantScoped: true }
|
|
407
|
+
};
|
|
408
|
+
var pipelineEntity = {
|
|
409
|
+
name: "Pipeline",
|
|
410
|
+
namePlural: "Pipelines",
|
|
411
|
+
icon: "GitBranch",
|
|
412
|
+
displayField: "name",
|
|
413
|
+
defaultSort: "name",
|
|
414
|
+
fields: [
|
|
415
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
416
|
+
// One default per tenant; the provider clears the flag on the others when
|
|
417
|
+
// this one is set. It is the funnel a lead falls into when nobody chose.
|
|
418
|
+
{ key: "isDefault", label: "Default", type: "boolean", showInTable: true, defaultValue: false },
|
|
419
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
420
|
+
],
|
|
421
|
+
// O funil ABERTO mostra o que é dele: as etapas primeiro, porque são o
|
|
422
|
+
// funil, e depois para quem ele serve. Antes as etapas moravam numa lista
|
|
423
|
+
// irmã com uma coluna "Pipeline" — para saber as etapas DESTE funil era
|
|
424
|
+
// preciso sair dele e filtrar uma lista de todos.
|
|
425
|
+
relatedLists: [
|
|
426
|
+
{ id: "stages", label: "Stages", icon: "Workflow", entity: pipelineStageEntity, foreignKey: "pipelineId" }
|
|
427
|
+
],
|
|
428
|
+
// Unidades e equipes são SEÇÃO, não aba: são duas ou três pastilhas, e para
|
|
429
|
+
// quem o funil serve se lê junto com o nome dele. Numa aba própria seriam
|
|
430
|
+
// dois cliques para descobrir uma linha de configuração — e quem abre o
|
|
431
|
+
// funil para conferir o recorte teria de abrir as duas.
|
|
432
|
+
relatedSections: [
|
|
433
|
+
{
|
|
434
|
+
id: "units",
|
|
435
|
+
label: "Units",
|
|
436
|
+
icon: "Building2",
|
|
437
|
+
entity: pipelineUnitEntity,
|
|
438
|
+
foreignKey: "pipelineId",
|
|
439
|
+
emptyHint: "Sem unidade: este funil serve a conta inteira."
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
id: "teams",
|
|
443
|
+
label: "Teams",
|
|
444
|
+
icon: "Users",
|
|
445
|
+
entity: pipelineTeamEntity,
|
|
446
|
+
foreignKey: "pipelineId",
|
|
447
|
+
emptyHint: "Sem equipe: este funil serve todas as equipes."
|
|
448
|
+
}
|
|
449
|
+
],
|
|
450
|
+
data: { table: T.pipelines, tenantScoped: true }
|
|
451
|
+
};
|
|
452
|
+
var dealStatusEntity = {
|
|
453
|
+
name: "Contact status",
|
|
454
|
+
namePlural: "Contact statuses",
|
|
455
|
+
icon: "SignalHigh",
|
|
456
|
+
displayField: "name",
|
|
457
|
+
defaultSort: "sortOrder",
|
|
458
|
+
fields: [
|
|
459
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true, searchable: true },
|
|
460
|
+
{
|
|
461
|
+
key: "derivedFrom",
|
|
462
|
+
label: "When it applies",
|
|
463
|
+
type: "select",
|
|
464
|
+
required: true,
|
|
465
|
+
showInTable: true,
|
|
466
|
+
options: [
|
|
467
|
+
{ value: "no_activity", label: "Nothing logged yet" },
|
|
468
|
+
{ value: "attempted", label: "Some contact was logged" },
|
|
469
|
+
{ value: "no_answer", label: "Last attempt went unanswered" },
|
|
470
|
+
{ value: "connected", label: "Spoke to the person" },
|
|
471
|
+
{ value: "replied", label: "They replied" },
|
|
472
|
+
{ value: "meeting_scheduled", label: "A meeting is set" },
|
|
473
|
+
{ value: "overdue_task", label: "A follow-up is past due" }
|
|
474
|
+
],
|
|
475
|
+
hint: "The fact that makes this status true. It is computed from the timeline \u2014 nobody sets it by hand."
|
|
476
|
+
},
|
|
477
|
+
// Vazio = vale em toda etapa. A linha específica ganha da universal, que é
|
|
478
|
+
// como uma casa cria "Aguardando assinatura" só na etapa de Proposta.
|
|
479
|
+
{
|
|
480
|
+
key: "stageId",
|
|
481
|
+
label: "Only in stage",
|
|
482
|
+
type: "relation",
|
|
483
|
+
relation: { table: T.pipelineStages, labelField: "name" },
|
|
484
|
+
showInTable: true,
|
|
485
|
+
hint: "Leave empty to use this status in every stage."
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
key: "sortOrder",
|
|
489
|
+
label: "Rank",
|
|
490
|
+
type: "number",
|
|
491
|
+
defaultValue: 100,
|
|
492
|
+
showInTable: true,
|
|
493
|
+
hint: 'When more than one rule is true, the highest rank wins. "They replied" should outrank "contact logged".'
|
|
494
|
+
},
|
|
495
|
+
{ key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#64748b" },
|
|
496
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
497
|
+
],
|
|
498
|
+
data: { table: T.dealStatuses, tenantScoped: true, searchColumns: ["name"] }
|
|
499
|
+
};
|
|
500
|
+
var assignmentRuleEntity = {
|
|
501
|
+
name: "Assignment Rota",
|
|
502
|
+
namePlural: "Assignment Rota",
|
|
503
|
+
icon: "Repeat",
|
|
504
|
+
displayField: "name",
|
|
505
|
+
defaultSort: "name",
|
|
506
|
+
fields: [
|
|
507
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
508
|
+
// Empty means every funnel. A house running new business and renewals wants
|
|
509
|
+
// a rota for each, and the engine prefers an exact funnel match over the
|
|
510
|
+
// general rule.
|
|
511
|
+
{
|
|
512
|
+
key: "pipelineId",
|
|
513
|
+
label: "Funnel",
|
|
514
|
+
type: "relation",
|
|
515
|
+
relation: { table: T.pipelines, labelField: "name" },
|
|
516
|
+
showInTable: true,
|
|
517
|
+
hint: "Leave empty to use this rota for every funnel."
|
|
518
|
+
},
|
|
519
|
+
// How long ONE person holds the lead to themselves before it falls to the
|
|
520
|
+
// next. Short on purpose — speed-to-lead is the entire point of a rota.
|
|
521
|
+
{
|
|
522
|
+
key: "offerMinutes",
|
|
523
|
+
label: "Offer window (min)",
|
|
524
|
+
type: "number",
|
|
525
|
+
min: 1,
|
|
526
|
+
max: 1440,
|
|
527
|
+
defaultValue: 5,
|
|
528
|
+
showInTable: true,
|
|
529
|
+
hint: "How long one person has the lead before it cascades to the next."
|
|
530
|
+
},
|
|
531
|
+
// The rota is an ORDERED list of membership user ids: position IS the
|
|
532
|
+
// rotation, so it is a reorderable list rather than a checkbox grid. Same
|
|
533
|
+
// `custom` escape hatch the partnership's unit picker uses — `[]` and not
|
|
534
|
+
// empty as the default, because the generic form sends the value even when
|
|
535
|
+
// the control is hidden and a NOT NULL uuid[] refuses null.
|
|
536
|
+
{
|
|
537
|
+
key: "assigneeIds",
|
|
538
|
+
label: "Rota",
|
|
539
|
+
type: "custom",
|
|
540
|
+
defaultValue: [],
|
|
541
|
+
showInTable: true,
|
|
542
|
+
hint: "Who is offered a new lead, in order.",
|
|
543
|
+
renderInput: ({ value, onChange }) => React2.createElement(AssigneeRotaInput, {
|
|
544
|
+
value,
|
|
545
|
+
onChange
|
|
546
|
+
}),
|
|
547
|
+
renderCell: (value) => React2.createElement(AssigneeRotaCell, { value })
|
|
548
|
+
},
|
|
549
|
+
// Where the rotation currently is. Read-only: editing it by hand would skew
|
|
550
|
+
// the next offer with nothing recording why.
|
|
551
|
+
{ key: "rotaCursor", label: "Cursor", type: "number", showInTable: true, showInForm: false },
|
|
552
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: false, inlineToggle: true }
|
|
553
|
+
],
|
|
554
|
+
data: { table: T.assignmentRules, tenantScoped: true }
|
|
555
|
+
};
|
|
556
|
+
var activityTypeEntity = {
|
|
557
|
+
name: "Activity Type",
|
|
558
|
+
namePlural: "Activity Types",
|
|
559
|
+
icon: "MessageCircle",
|
|
560
|
+
displayField: "name",
|
|
561
|
+
defaultSort: "name",
|
|
562
|
+
fields: [
|
|
563
|
+
{ key: "name", label: "Name", type: "text", required: true, showInTable: true },
|
|
564
|
+
{ key: "icon", label: "Icon", type: "text", showInTable: true },
|
|
565
|
+
{ key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true, inlineToggle: true }
|
|
566
|
+
],
|
|
567
|
+
data: { table: T.activityTypes, tenantScoped: true }
|
|
568
|
+
};
|
|
569
|
+
var DEFAULT_ACTIVITY_TYPES = [
|
|
570
|
+
{ value: "call", label: "Call", icon: "Phone" },
|
|
571
|
+
{ value: "email", label: "Email", icon: "Mail" },
|
|
572
|
+
{ value: "meeting", label: "Meeting", icon: "Users" },
|
|
573
|
+
{ value: "note", label: "Note", icon: "FileText" },
|
|
574
|
+
{ value: "task", label: "Task", icon: "CheckSquare" },
|
|
575
|
+
{ value: "whatsapp", label: "WhatsApp", icon: "MessageCircle" },
|
|
576
|
+
{ value: "visit", label: "Visit", icon: "MapPin" }
|
|
577
|
+
];
|
|
578
|
+
var crmRegistries = [
|
|
579
|
+
{
|
|
580
|
+
id: "pipelines",
|
|
581
|
+
entity: pipelineEntity,
|
|
582
|
+
icon: "GitBranch",
|
|
583
|
+
description: "Sales funnels \u2014 one per sales motion the house runs",
|
|
584
|
+
display: "table",
|
|
585
|
+
// Mirrors `crm_seed_default_pipeline`: one funnel, marked default. The
|
|
586
|
+
// stage seeds below hang off this id.
|
|
587
|
+
seedData: [
|
|
588
|
+
{ id: "pipe-default", name: "Sales Pipeline", isDefault: true, isActive: true }
|
|
589
|
+
]
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
id: "stages",
|
|
593
|
+
entity: pipelineStageEntity,
|
|
594
|
+
icon: "Workflow",
|
|
595
|
+
description: "Pipeline stages used by CRM deals",
|
|
596
|
+
display: "table",
|
|
597
|
+
seedData: [
|
|
598
|
+
{ id: "stage-new", pipelineId: "pipe-default", name: "New Lead", order: 1, color: "#64748b", probability: 10, isInitial: true, isWon: false, isLost: false },
|
|
599
|
+
{ id: "stage-qualified", pipelineId: "pipe-default", name: "Qualified", order: 2, color: "#3b82f6", probability: 30, isWon: false, isLost: false },
|
|
600
|
+
{ id: "stage-proposal", pipelineId: "pipe-default", name: "Proposal", order: 3, color: "#8b5cf6", probability: 60, isWon: false, isLost: false },
|
|
601
|
+
{ id: "stage-negotiation", pipelineId: "pipe-default", name: "Negotiation", order: 4, color: "#f59e0b", probability: 80, isWon: false, isLost: false },
|
|
602
|
+
{ id: "stage-won", pipelineId: "pipe-default", name: "Won", order: 5, color: "#10b981", probability: 100, isWon: true, isLost: false },
|
|
603
|
+
{ id: "stage-lost", pipelineId: "pipe-default", name: "Lost", order: 6, color: "#ef4444", probability: 0, isWon: false, isLost: true }
|
|
604
|
+
]
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
id: "deal-statuses",
|
|
608
|
+
entity: dealStatusEntity,
|
|
609
|
+
icon: "SignalHigh",
|
|
610
|
+
description: "O que j\xE1 se tentou dentro da etapa \u2014 calculado a partir da linha do tempo",
|
|
611
|
+
display: "table",
|
|
612
|
+
// Sem seed aqui: quem semeia é `crm_seed_deal_statuses` (014), porque os
|
|
613
|
+
// sete degraus precisam existir para o CÁLCULO, e não só para a tela.
|
|
614
|
+
seedData: []
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
id: "assignment-rota",
|
|
618
|
+
entity: assignmentRuleEntity,
|
|
619
|
+
icon: "Repeat",
|
|
620
|
+
description: "Who is offered a new lead, in what order, and for how long",
|
|
621
|
+
display: "table",
|
|
622
|
+
// No seed: a rota names real people, and no tenant is born with one. It
|
|
623
|
+
// also starts INACTIVE, so installing this never silently starts routing.
|
|
624
|
+
seedData: []
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
id: "lead-sources",
|
|
628
|
+
entity: leadSourceEntity,
|
|
629
|
+
icon: "Globe",
|
|
630
|
+
description: "Where your leads come from",
|
|
631
|
+
display: "table",
|
|
632
|
+
// Espelha o que a migration 001 semeia por tenant: contra o banco o
|
|
633
|
+
// `seedData` NÃO é gravado (ele só alimenta o provider mock), e as duas
|
|
634
|
+
// listas divergirem faria a tela do mock ensinar uma coisa e a do banco
|
|
635
|
+
// outra.
|
|
636
|
+
seedData: [
|
|
637
|
+
{ id: "src-email", name: "E-mail", description: "Escreveu para o e-mail da casa.", isActive: true },
|
|
638
|
+
{ id: "src-facebook", name: "Facebook", description: "P\xE1gina ou an\xFAncio no Facebook.", isActive: true },
|
|
639
|
+
{ id: "src-google", name: "Google", description: "Busca ou an\xFAncio no Google.", isActive: true },
|
|
640
|
+
{ id: "src-referral", name: "Indica\xE7\xE3o", description: "Um cliente indicou. A pessoa que indicou \xE9 conhecida.", isActive: true },
|
|
641
|
+
{ id: "src-influencer", name: "Influenciador", description: "Veio por um creator pago ou permutado \u2014 n\xE3o \xE9 indica\xE7\xE3o de cliente.", isActive: true },
|
|
642
|
+
{ id: "src-instagram", name: "Instagram", description: "Perfil, story ou an\xFAncio no Instagram.", isActive: true },
|
|
643
|
+
{ id: "src-walkin", name: "Passante", description: "Entrou porque passou na porta.", isActive: true },
|
|
644
|
+
{ id: "src-website", name: "Site", description: "Formul\xE1rio ou contato pelo site.", isActive: true },
|
|
645
|
+
{ id: "src-whatsapp", name: "WhatsApp", description: "Chamou direto no WhatsApp.", isActive: true }
|
|
646
|
+
]
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
id: "partners",
|
|
650
|
+
entity: partnerEntity,
|
|
651
|
+
icon: "Handshake",
|
|
652
|
+
description: "Conv\xEAnios e clubes de benef\xEDcio que trazem clientes",
|
|
653
|
+
display: "table",
|
|
654
|
+
// Sem semente: uma parceria é um acordo com um terceiro, e nenhum tenant
|
|
655
|
+
// nasce com um.
|
|
656
|
+
seedData: []
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
id: "tags",
|
|
660
|
+
entity: tagEntity,
|
|
661
|
+
icon: "Tag",
|
|
662
|
+
description: "Tags for organizing leads and deals",
|
|
663
|
+
display: "table",
|
|
664
|
+
// Só alimenta o provider MOCK (apps sem Supabase). Contra o banco, o
|
|
665
|
+
// cadastro se alimenta do uso: `crm_register_tags` insere a linha quando
|
|
666
|
+
// uma tag é gravada num lead. Semear vocabulário aqui encheria a tela de
|
|
667
|
+
// tags que nenhum registro carrega.
|
|
668
|
+
seedData: [
|
|
669
|
+
{ id: "tag-vip", name: "VIP", slug: "vip", color: "#f59e0b", isActive: true },
|
|
670
|
+
{ id: "tag-hot", name: "Hot Lead", slug: "hot-lead", color: "#ef4444", isActive: true },
|
|
671
|
+
{ id: "tag-followup", name: "Follow-up", slug: "follow-up", color: "#3b82f6", isActive: true }
|
|
672
|
+
]
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
id: "activity-types",
|
|
676
|
+
entity: activityTypeEntity,
|
|
677
|
+
icon: "MessageCircle",
|
|
678
|
+
description: "Types of activities and interactions",
|
|
679
|
+
display: "table",
|
|
680
|
+
// Tenant-editable (the provider lazily seeds the app's set per tenant);
|
|
681
|
+
// system timeline events (lead_created, stage_changed…) are product-defined
|
|
682
|
+
// and never appear here.
|
|
683
|
+
seedData: [
|
|
684
|
+
...DEFAULT_ACTIVITY_TYPES.map((t) => ({ id: `at-${t.value}`, name: t.label, icon: t.icon, isActive: true }))
|
|
685
|
+
]
|
|
686
|
+
}
|
|
687
|
+
];
|
|
688
|
+
function buildCrmRegistries(activityTypes) {
|
|
689
|
+
if (!activityTypes?.length) return crmRegistries;
|
|
690
|
+
return crmRegistries.map(
|
|
691
|
+
(registry) => registry.id === "activity-types" ? {
|
|
692
|
+
...registry,
|
|
693
|
+
seedData: [
|
|
694
|
+
...activityTypes.map((t) => ({ id: `at-${t.value}`, name: t.label, icon: t.icon, isActive: true }))
|
|
695
|
+
]
|
|
696
|
+
} : registry
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
function humanizeTag(slug) {
|
|
700
|
+
return slug.replace(/^[a-z]+:/, "").replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
701
|
+
}
|
|
702
|
+
function dotColor(color) {
|
|
703
|
+
return color && /^#[0-9a-f]{6}$/i.test(color) ? color : "#94A3B8";
|
|
704
|
+
}
|
|
705
|
+
function DotChip({ color, label, title, className }) {
|
|
706
|
+
return /* @__PURE__ */ jsxs(
|
|
707
|
+
"span",
|
|
708
|
+
{
|
|
709
|
+
title: title ?? label,
|
|
710
|
+
className: `inline-flex h-[18px] max-w-[10rem] items-center gap-1 truncate rounded-full border border-border bg-card px-1.5 text-[9px] font-medium text-foreground/80 ${className ?? ""}`,
|
|
711
|
+
children: [
|
|
712
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: color } }),
|
|
713
|
+
label
|
|
714
|
+
]
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
function TagChips({ tags, defs, max, size = "xs", className }) {
|
|
719
|
+
if (!tags?.length) return null;
|
|
720
|
+
const shown = max ? tags.slice(0, max) : tags;
|
|
721
|
+
const hidden = max ? tags.length - shown.length : 0;
|
|
722
|
+
const text = size === "xs" ? "h-[18px] text-[9px] px-1.5" : "text-[10px] px-2 py-0.5";
|
|
723
|
+
return /* @__PURE__ */ jsxs("div", { className: `flex flex-wrap items-center gap-1 ${className ?? ""}`, children: [
|
|
724
|
+
shown.map((slug) => {
|
|
725
|
+
const def = defs?.get(slug);
|
|
726
|
+
return /* @__PURE__ */ jsxs(
|
|
727
|
+
"span",
|
|
728
|
+
{
|
|
729
|
+
title: def?.name ?? humanizeTag(slug),
|
|
730
|
+
className: `inline-flex max-w-[6.5rem] items-center gap-1 truncate rounded-full border border-border bg-card font-medium text-foreground/80 ${text}`,
|
|
731
|
+
children: [
|
|
732
|
+
/* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 shrink-0 rounded-full", style: { backgroundColor: dotColor(def?.color) } }),
|
|
733
|
+
def?.name ?? humanizeTag(slug)
|
|
734
|
+
]
|
|
735
|
+
},
|
|
736
|
+
slug
|
|
737
|
+
);
|
|
738
|
+
}),
|
|
739
|
+
hidden > 0 && /* @__PURE__ */ jsxs(
|
|
740
|
+
"span",
|
|
741
|
+
{
|
|
742
|
+
title: tags.slice(shown.length).map((s) => defs?.get(s)?.name ?? humanizeTag(s)).join(", "),
|
|
743
|
+
className: `inline-flex items-center rounded-full border border-border bg-muted font-medium text-muted-foreground ${text}`,
|
|
744
|
+
children: [
|
|
745
|
+
"+",
|
|
746
|
+
hidden
|
|
747
|
+
]
|
|
748
|
+
}
|
|
749
|
+
)
|
|
750
|
+
] });
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/lib/identity.ts
|
|
754
|
+
function normalizeDocument(doc) {
|
|
755
|
+
return (doc ?? "").replace(/[^0-9A-Za-z]/g, "").toUpperCase();
|
|
756
|
+
}
|
|
757
|
+
function documentKind(doc) {
|
|
758
|
+
const d = normalizeDocument(doc);
|
|
759
|
+
if (d.length === 14) return "cnpj";
|
|
760
|
+
if (d.length === 11) return "cpf";
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
function isValidDocument(doc) {
|
|
764
|
+
const d = normalizeDocument(doc);
|
|
765
|
+
if (!d) return null;
|
|
766
|
+
const kind = documentKind(d);
|
|
767
|
+
if (!kind) return false;
|
|
768
|
+
if (new Set(d).size === 1) return false;
|
|
769
|
+
if (!/^[0-9]{2}$/.test(d.slice(-2))) return false;
|
|
770
|
+
if (kind === "cpf" && !/^[0-9]{11}$/.test(d)) return false;
|
|
771
|
+
if (kind === "cnpj" && !/^[0-9A-Z]{14}$/.test(d)) return false;
|
|
772
|
+
const bodyLen = d.length - 2;
|
|
773
|
+
for (let round = 1; round <= 2; round++) {
|
|
774
|
+
const span = bodyLen + round - 1;
|
|
775
|
+
let total = 0;
|
|
776
|
+
for (let pos = 1; pos <= span; pos++) {
|
|
777
|
+
const weight = kind === "cpf" ? span + 2 - pos : (span - pos) % 8 + 2;
|
|
778
|
+
total += (d.charCodeAt(pos - 1) - 48) * weight;
|
|
779
|
+
}
|
|
780
|
+
const rest = total % 11;
|
|
781
|
+
const expected = rest < 2 ? 0 : 11 - rest;
|
|
782
|
+
if (expected !== d.charCodeAt(bodyLen + round - 1) - 48) return false;
|
|
783
|
+
}
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
function formatDocument(doc) {
|
|
787
|
+
const d = normalizeDocument(doc);
|
|
788
|
+
if (d.length === 14) return `${d.slice(0, 2)}.${d.slice(2, 5)}.${d.slice(5, 8)}/${d.slice(8, 12)}-${d.slice(12)}`;
|
|
789
|
+
if (d.length === 11) return `${d.slice(0, 3)}.${d.slice(3, 6)}.${d.slice(6, 9)}-${d.slice(9)}`;
|
|
790
|
+
return d;
|
|
791
|
+
}
|
|
792
|
+
function documentRoot(doc) {
|
|
793
|
+
return documentKind(doc) === "cnpj" ? normalizeDocument(doc).slice(0, 8) : null;
|
|
794
|
+
}
|
|
795
|
+
function localPhoneKey(phone) {
|
|
796
|
+
if (!phone) return null;
|
|
797
|
+
let d = phone.replace(/[^0-9]/g, "");
|
|
798
|
+
if ((d.length === 12 || d.length === 13) && d.startsWith("55")) d = d.slice(2);
|
|
799
|
+
if ((d.length === 11 || d.length === 12) && d.startsWith("0")) d = d.slice(1);
|
|
800
|
+
if (d.length < 8 || d.length > 11) return null;
|
|
801
|
+
if (d.length === 10 && ["6", "7", "8", "9"].includes(d[2])) {
|
|
802
|
+
d = `${d.slice(0, 2)}9${d.slice(2)}`;
|
|
803
|
+
}
|
|
804
|
+
return d;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export { AssigneeName, DEFAULT_ACTIVITY_TYPES, DotChip, T, TagChips, buildCrmRegistries, documentKind, documentRoot, formatDocument, humanizeTag, isValidDocument, loadMyUserId, loadTeamOrNull, localPhoneKey, normalizeDocument };
|
|
808
|
+
//# sourceMappingURL=chunk-BIQL232X.js.map
|
|
809
|
+
//# sourceMappingURL=chunk-BIQL232X.js.map
|