@controleonline/ui-crm 1.0.44 → 1.0.46

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 (44) hide show
  1. package/.github/workflows/integration-source-gate.yml +1 -15
  2. package/.github/workflows/manager-worker.yml +155 -7
  3. package/.github/workflows/publish-npm.yml +22 -73
  4. package/.release/rc-manifest.json +13 -0
  5. package/AGENTS.md +0 -2
  6. package/package.json +2 -2
  7. package/src/react/pages/crm/hooks/useCrmData.js +17 -23
  8. package/src/react/pages/mcp/McpPage.js +301 -0
  9. package/src/react/pages/mcp/McpPage.styles.js +116 -0
  10. package/src/react/pages/proposals/CreateProposalsModal.js +0 -1
  11. package/src/react/pages/proposals/index.js +33 -14
  12. package/src/react/pages/settings/GeneralSettings.js +17 -9
  13. package/src/react/pages/settings/GeneralSettings.shared.js +20 -20
  14. package/src/react/pages/settings/GeneralSettings.styles.js +0 -2
  15. package/src/react/pages/settings/sections/AiProvidersSection.js +263 -0
  16. package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +11 -11
  17. package/src/react/pages/settings/sections/IntegrationsSection.js +17 -17
  18. package/src/react/pages/settings/sections/LogSection.js +10 -10
  19. package/src/react/pages/settings/sections/LoginSection.js +13 -13
  20. package/src/react/pages/settings/sections/LoyaltyProductPicker.js +145 -58
  21. package/src/react/pages/settings/sections/LoyaltySection.js +9 -35
  22. package/src/react/pages/settings/sections/MaintenanceSection.js +16 -16
  23. package/src/react/pages/settings/sections/MapsSection.js +257 -81
  24. package/src/react/pages/settings/sections/ShopSection.js +2 -2
  25. package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +28 -7
  26. package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +8 -54
  27. package/src/react/pages/settings/sections/shop/shopSettingsShared.js +11 -32
  28. package/src/react/router/routes.js +14 -0
  29. package/src/react/utils/proposalProductSelection.js +13 -103
  30. package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +0 -25
  31. package/src/tests/browser/manager/general-settings-maps.spec.js +347 -173
  32. package/src/tests/react/utils/proposalProductSelection.test.js +1 -57
  33. package/src/react/pages/settings/sections/MapsFranchisePreview.js +0 -102
  34. package/src/react/pages/settings/sections/MapsMapasControls.js +0 -262
  35. package/src/react/pages/settings/sections/loyaltyProductCompany.js +0 -57
  36. package/src/react/pages/settings/sections/mapsSectionHelpers.js +0 -137
  37. package/src/react/utils/clientDetailsNavigation.js +0 -56
  38. package/src/react/utils/clientSellerVisibility.js +0 -60
  39. package/src/react/utils/proposalStatus.js +0 -160
  40. package/src/tests/react/pages/settings/sections/loyaltyProductCompany.test.js +0 -41
  41. package/src/tests/react/pages/settings/sections/mapsSectionHelpers.test.js +0 -38
  42. package/src/tests/react/utils/clientDetailsNavigation.test.js +0 -98
  43. package/src/tests/react/utils/clientSellerVisibility.test.js +0 -74
  44. package/src/tests/react/utils/proposalStatus.test.mjs +0 -77
@@ -1,160 +0,0 @@
1
- export const normalizeProposalStatusKey = value =>
2
- String(value || '')
3
- .trim()
4
- .toLowerCase()
5
- .replace(/[_-]+/g, ' ')
6
- .replace(/\s+/g, ' ');
7
-
8
- export const getProposalStatusColor = status => {
9
- const normalized = normalizeProposalStatusKey(status);
10
-
11
- switch (normalized) {
12
- case 'ativo':
13
- case 'active':
14
- case 'assinado':
15
- case 'signed':
16
- return '#10B981';
17
- case 'inativo':
18
- case 'inactive':
19
- case 'cancelado':
20
- case 'canceled':
21
- return '#EF4444';
22
- case 'pendente':
23
- case 'pending':
24
- return '#F59E0B';
25
- case 'open':
26
- case 'aberto':
27
- return '#3B82F6';
28
- default:
29
- return '#64748B';
30
- }
31
- };
32
-
33
- export const getProposalStatusTranslationKey = status => {
34
- const normalized = normalizeProposalStatusKey(status);
35
- const map = {
36
- ativo: 'active',
37
- active: 'active',
38
- inativo: 'inactive',
39
- inactive: 'inactive',
40
- pendente: 'pending',
41
- pending: 'pending',
42
- open: 'open',
43
- aberto: 'open',
44
- closed: 'closed',
45
- fechado: 'closed',
46
- cancelado: 'canceled',
47
- canceled: 'canceled',
48
- 'waiting signature': 'waitingSignature',
49
- 'awaiting signature': 'waitingSignature',
50
- 'signature pending': 'waitingSignature',
51
- assinado: 'signed',
52
- signed: 'signed',
53
- draft: 'draft',
54
- rascunho: 'draft',
55
- };
56
-
57
- return map[normalized] || '';
58
- };
59
-
60
- export const getProposalStatusLabel = (status, translate) => {
61
- const translationKey = getProposalStatusTranslationKey(status);
62
- if (translationKey) {
63
- return translate?.('contract', 'status', translationKey);
64
- }
65
-
66
- return translate?.('contract', 'label', 'na') || '';
67
- };
68
-
69
- export const getProposalStatusFilterKey = item => {
70
- if (!item) {
71
- return '';
72
- }
73
-
74
- if (item['@id']) {
75
- return item['@id'];
76
- }
77
-
78
- if (item.id != null) {
79
- return `/statuses/${item.id}`;
80
- }
81
-
82
- const normalized = normalizeProposalStatusKey(item.realStatus || item.status);
83
- return normalized ? `realStatus:${normalized}` : '';
84
- };
85
-
86
- export const buildProposalStatusFilterOptions = ({ contracts = [], translate } = {}) => {
87
- const options = [
88
- {
89
- key: 'realStatus:open',
90
- label: translate?.('contract', 'status', 'open'),
91
- color: getProposalStatusColor('open'),
92
- normalizedStatus: 'open',
93
- },
94
- {
95
- key: 'realStatus:pending',
96
- label: translate?.('contract', 'status', 'pending'),
97
- color: getProposalStatusColor('pending'),
98
- normalizedStatus: 'pending',
99
- },
100
- {
101
- key: 'realStatus:closed',
102
- label: translate?.('contract', 'status', 'closed'),
103
- color: getProposalStatusColor('closed'),
104
- normalizedStatus: 'closed',
105
- },
106
- ];
107
-
108
- contracts.forEach(contract => {
109
- const statusObj = contract?.status || {};
110
- const key = getProposalStatusFilterKey(statusObj);
111
- if (!key || options.some(item => item.key === key)) {
112
- return;
113
- }
114
-
115
- const normalizedStatus = normalizeProposalStatusKey(statusObj.realStatus || statusObj.status);
116
- options.push({
117
- key,
118
- label: getProposalStatusLabel(statusObj.status || statusObj.realStatus, translate),
119
- color: statusObj.color || getProposalStatusColor(normalizedStatus),
120
- normalizedStatus,
121
- });
122
- });
123
-
124
- return options;
125
- };
126
-
127
- export const proposalMatchesStatusFilter = (contract, filterKey, statusFilterOptions = []) => {
128
- if (!filterKey) {
129
- return true;
130
- }
131
-
132
- const statusObj = contract?.status || {};
133
- const statusIri = statusObj['@id']
134
- ? statusObj['@id']
135
- : statusObj.id != null
136
- ? `/statuses/${statusObj.id}`
137
- : '';
138
-
139
- const normalizedStatus = normalizeProposalStatusKey(
140
- statusObj.realStatus || statusObj.status,
141
- );
142
- const normalizedFilter = normalizeProposalStatusKey(
143
- String(filterKey || '').replace('realStatus:', ''),
144
- );
145
-
146
- if (filterKey.startsWith('/statuses/')) {
147
- if (statusIri === filterKey) {
148
- return true;
149
- }
150
-
151
- const selectedOption = statusFilterOptions.find(item => item.key === filterKey);
152
- if (selectedOption?.normalizedStatus) {
153
- return normalizedStatus === selectedOption.normalizedStatus;
154
- }
155
-
156
- return false;
157
- }
158
-
159
- return normalizedStatus === normalizedFilter;
160
- };
@@ -1,41 +0,0 @@
1
- const {
2
- normalizeLoyaltyCompanyId,
3
- productBelongsToCompany,
4
- filterProductsByCompany,
5
- } = require('../../../../../react/pages/settings/sections/loyaltyProductCompany');
6
-
7
- describe('loyaltyProductCompany', () => {
8
- test('normalizes IRI, object and digits', () => {
9
- expect(normalizeLoyaltyCompanyId('/people/42')).toBe('42');
10
- expect(normalizeLoyaltyCompanyId({id: 7})).toBe('7');
11
- expect(normalizeLoyaltyCompanyId({['@id']: '/people/9'})).toBe('9');
12
- expect(normalizeLoyaltyCompanyId('')).toBe('');
13
- });
14
-
15
- test('keeps products without company field when company is selected', () => {
16
- expect(productBelongsToCompany({id: 1, product: 'X'}, 10)).toBe(true);
17
- });
18
-
19
- test('drops products owned by another company', () => {
20
- expect(
21
- productBelongsToCompany({id: 1, company: '/people/99'}, 10),
22
- ).toBe(false);
23
- expect(
24
- productBelongsToCompany({id: 2, company: {id: 10}}, '10'),
25
- ).toBe(true);
26
- });
27
-
28
- test('filterProductsByCompany returns empty without company', () => {
29
- expect(filterProductsByCompany([{id: 1}], '')).toEqual([]);
30
- });
31
-
32
- test('filterProductsByCompany keeps only matching company', () => {
33
- const items = [
34
- {id: 1, company: 10},
35
- {id: 2, company: 11},
36
- {id: 3},
37
- ];
38
- const filtered = filterProductsByCompany(items, 10);
39
- expect(filtered.map(item => item.id)).toEqual([1, 3]);
40
- });
41
- });
@@ -1,38 +0,0 @@
1
- const {describe, it} = require('node:test');
2
- const assert = require('node:assert/strict');
3
-
4
- describe('mapsSectionHelpers', () => {
5
- it('parses coordinates and builds a static map URL', async () => {
6
- const mod = await import(
7
- '../../../../../react/pages/settings/sections/mapsSectionHelpers.js'
8
- );
9
- const {parseCoord, resolveAddressCoords, buildStaticMapUrl, PRIMARY_ENTRY_LABELS} =
10
- mod;
11
-
12
- assert.equal(parseCoord(''), null);
13
- assert.equal(parseCoord(undefined), null);
14
- assert.equal(parseCoord('0'), null);
15
- assert.equal(parseCoord('-23.5614'), -23.5614);
16
-
17
- assert.equal(resolveAddressCoords({latitude: 0, longitude: 0}), null);
18
- assert.deepEqual(resolveAddressCoords({latitude: -23.56, longitude: -46.65}), {
19
- lat: -23.56,
20
- lng: -46.65,
21
- });
22
- assert.deepEqual(resolveAddressCoords({lat: -10.1, lon: -20.2}), {
23
- lat: -10.1,
24
- lng: -20.2,
25
- });
26
-
27
- assert.equal(buildStaticMapUrl({apiKey: '', markers: [{lat: 1, lng: 2}]}), null);
28
- const url = buildStaticMapUrl({
29
- apiKey: 'abc',
30
- markers: [{lat: -23.56, lng: -46.65}],
31
- });
32
- assert.ok(String(url).includes('maps.googleapis.com'));
33
- assert.ok(String(url).includes('abc'));
34
-
35
- assert.equal(typeof PRIMARY_ENTRY_LABELS, 'object');
36
- assert.ok(Object.keys(PRIMARY_ENTRY_LABELS).length >= 2);
37
- });
38
- });
@@ -1,98 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert/strict');
3
-
4
- const {
5
- resolveClientDetailsNavigation,
6
- extractId,
7
- } = require('../../../react/utils/clientDetailsNavigation');
8
-
9
- test('extractId strips non-digits', () => {
10
- assert.equal(extractId('/people/42'), '42');
11
- assert.equal(extractId('abc'), '');
12
- assert.equal(extractId(null), '');
13
- });
14
-
15
- test('returns null when the client reference is missing', () => {
16
- assert.equal(resolveClientDetailsNavigation({ reference: '' }), null);
17
- assert.equal(resolveClientDetailsNavigation({}), null);
18
- });
19
-
20
- test('returns null when reference has no numeric id', () => {
21
- assert.equal(
22
- resolveClientDetailsNavigation({ reference: '/people/' }),
23
- null,
24
- );
25
- });
26
-
27
- test('opens legal entities in the sellers tab with client context', () => {
28
- const result = resolveClientDetailsNavigation({
29
- reference: '/people/42',
30
- opportunityClient: {
31
- '@id': '/people/42',
32
- peopleType: 'J',
33
- name: 'ACME Ltda',
34
- },
35
- fallbackName: 'Cliente',
36
- });
37
-
38
- assert.deepEqual(result, {
39
- selectedClient: {
40
- '@id': '/people/42',
41
- peopleType: 'J',
42
- name: 'ACME Ltda',
43
- },
44
- params: {
45
- clientId: '42',
46
- contextKey: 'client',
47
- initialTab: 'sellers',
48
- },
49
- });
50
- });
51
-
52
- test('opens non-legal-entity clients in the general tab', () => {
53
- const result = resolveClientDetailsNavigation({
54
- reference: '/people/13',
55
- opportunityClient: {
56
- '@id': '/people/13',
57
- peopleType: 'F',
58
- name: 'Maria',
59
- },
60
- fallbackName: 'Cliente',
61
- });
62
-
63
- assert.equal(result.params.initialTab, 'general');
64
- assert.equal(result.params.clientId, '13');
65
- assert.equal(result.params.contextKey, 'client');
66
- });
67
-
68
- test('prefers the matched person and preserves its id for store context', () => {
69
- const matchedPerson = {
70
- '@id': '/people/88',
71
- id: 88,
72
- peopleType: 'J',
73
- name: 'Matched Co',
74
- };
75
-
76
- const result = resolveClientDetailsNavigation({
77
- reference: '/people/88',
78
- matchedPerson,
79
- opportunityClient: { peopleType: 'F', name: 'Ignored' },
80
- fallbackName: 'Fallback',
81
- });
82
-
83
- assert.equal(result.selectedClient, matchedPerson);
84
- assert.equal(result.params.initialTab, 'sellers');
85
- assert.equal(result.params.clientId, '88');
86
- });
87
-
88
- test('builds a minimal selectedClient when only reference is available', () => {
89
- const result = resolveClientDetailsNavigation({
90
- reference: 'people/7',
91
- fallbackName: 'Orphan',
92
- });
93
-
94
- assert.equal(result.params.clientId, '7');
95
- assert.equal(result.params.initialTab, 'general');
96
- assert.equal(result.selectedClient.name, 'Orphan');
97
- assert.equal(result.selectedClient.id, '7');
98
- });
@@ -1,74 +0,0 @@
1
- const test = require('node:test');
2
- const assert = require('node:assert/strict');
3
-
4
- const {
5
- resolveClientSellerVisibility,
6
- canShowCommissionFields,
7
- canManageSellerLinks,
8
- isManagerApp,
9
- normalizeAppType,
10
- } = require('../../../react/utils/clientSellerVisibility');
11
-
12
- test('normalizeAppType uppercases and trims', () => {
13
- assert.equal(normalizeAppType(' manager '), 'MANAGER');
14
- assert.equal(normalizeAppType(null), '');
15
- });
16
-
17
- test('isManagerApp is true only for MANAGER', () => {
18
- assert.equal(isManagerApp('MANAGER'), true);
19
- assert.equal(isManagerApp('manager'), true);
20
- assert.equal(isManagerApp('CRM'), false);
21
- assert.equal(isManagerApp('POS'), false);
22
- assert.equal(isManagerApp(''), false);
23
- assert.equal(isManagerApp(undefined), false);
24
- });
25
-
26
- test('MANAGER can view and fully manage sellers and commissions', () => {
27
- const v = resolveClientSellerVisibility('MANAGER');
28
- assert.equal(v.canViewSeller, true);
29
- assert.equal(v.canManageSellers, true);
30
- assert.equal(v.canChangeSeller, true);
31
- assert.equal(v.canRemoveSeller, true);
32
- assert.equal(v.canAddMultipleSellers, true);
33
- assert.equal(v.canEditSeller, true);
34
- assert.equal(v.canViewCommissionPercent, true);
35
- assert.equal(v.canViewMinimumCommission, true);
36
- });
37
-
38
- test('CRM can view seller but cannot manage or see commissions', () => {
39
- const v = resolveClientSellerVisibility('CRM');
40
- assert.equal(v.canViewSeller, true);
41
- assert.equal(v.canManageSellers, false);
42
- assert.equal(v.canChangeSeller, false);
43
- assert.equal(v.canRemoveSeller, false);
44
- assert.equal(v.canAddMultipleSellers, false);
45
- assert.equal(v.canEditSeller, false);
46
- assert.equal(v.canViewCommissionPercent, false);
47
- assert.equal(v.canViewMinimumCommission, false);
48
- });
49
-
50
- test('POS and SHOP follow non-MANAGER rules', () => {
51
- for (const app of ['POS', 'SHOP', 'ADMIN', '']) {
52
- const v = resolveClientSellerVisibility(app);
53
- assert.equal(v.canViewSeller, true, app);
54
- assert.equal(v.canManageSellers, false, app);
55
- assert.equal(v.canViewCommissionPercent, false, app);
56
- }
57
- });
58
-
59
- test('canShowCommissionFields mirrors MANAGER only', () => {
60
- assert.equal(canShowCommissionFields('MANAGER'), true);
61
- assert.equal(canShowCommissionFields('CRM'), false);
62
- assert.equal(canShowCommissionFields(null), false);
63
- });
64
-
65
- test('canManageSellerLinks mirrors MANAGER only', () => {
66
- assert.equal(canManageSellerLinks('MANAGER'), true);
67
- assert.equal(canManageSellerLinks('crm'), false);
68
- });
69
-
70
- test('case-insensitive MANAGER still grants full access', () => {
71
- const v = resolveClientSellerVisibility('MaNaGeR');
72
- assert.equal(v.canManageSellers, true);
73
- assert.equal(v.canViewCommissionPercent, true);
74
- });
@@ -1,77 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
-
4
- import {
5
- buildProposalStatusFilterOptions,
6
- getProposalStatusColor,
7
- getProposalStatusFilterKey,
8
- getProposalStatusLabel,
9
- normalizeProposalStatusKey,
10
- proposalMatchesStatusFilter,
11
- } from '../../../react/utils/proposalStatus.js';
12
-
13
- const translate = (store, type, key) => `${store}.${type}.${key}`;
14
-
15
- test('normalizeProposalStatusKey normalizes separators and casing', () => {
16
- assert.equal(normalizeProposalStatusKey(' Waiting_Signature '), 'waiting signature');
17
- });
18
-
19
- test('getProposalStatusLabel translates known backend statuses', () => {
20
- assert.equal(
21
- getProposalStatusLabel('awaiting signature', translate),
22
- 'contract.status.waitingSignature',
23
- );
24
- assert.equal(
25
- getProposalStatusLabel('PENDENTE', translate),
26
- 'contract.status.pending',
27
- );
28
- });
29
-
30
- test('getProposalStatusLabel falls back to the canonical empty-state label', () => {
31
- assert.equal(getProposalStatusLabel('custom approval', translate), 'contract.label.na');
32
- });
33
-
34
- test('buildProposalStatusFilterOptions keeps fixed filters and appends API statuses', () => {
35
- const options = buildProposalStatusFilterOptions({
36
- contracts: [
37
- {
38
- status: {
39
- id: 9,
40
- status: 'Assinado',
41
- realStatus: 'signed',
42
- color: '#123456',
43
- },
44
- },
45
- ],
46
- translate,
47
- });
48
-
49
- assert.deepEqual(
50
- options.slice(0, 3).map(item => item.key),
51
- ['realStatus:open', 'realStatus:pending', 'realStatus:closed'],
52
- );
53
- assert.equal(options[3].key, '/statuses/9');
54
- assert.equal(options[3].label, 'contract.status.signed');
55
- assert.equal(options[3].color, '#123456');
56
- });
57
-
58
- test('proposalMatchesStatusFilter supports fixed and specific status filters', () => {
59
- const contract = {
60
- status: {
61
- id: 9,
62
- '@id': '/statuses/9',
63
- status: 'Assinado',
64
- realStatus: 'signed',
65
- },
66
- };
67
- const options = buildProposalStatusFilterOptions({ contracts: [contract], translate });
68
-
69
- assert.equal(proposalMatchesStatusFilter(contract, '/statuses/9', options), true);
70
- assert.equal(proposalMatchesStatusFilter(contract, 'realStatus:signed', options), true);
71
- assert.equal(proposalMatchesStatusFilter(contract, 'realStatus:open', options), false);
72
- });
73
-
74
- test('helpers expose consistent colors and filter keys', () => {
75
- assert.equal(getProposalStatusColor('aberto'), '#3B82F6');
76
- assert.equal(getProposalStatusFilterKey({ id: 5 }), '/statuses/5');
77
- });