@controleonline/ui-crm 1.0.42 → 1.0.44
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/.github/workflows/integration-source-gate.yml +82 -0
- package/.github/workflows/manager-worker.yml +7 -155
- package/.github/workflows/publish-npm.yml +73 -22
- package/AGENTS.md +2 -0
- package/package.json +2 -2
- package/src/react/pages/crm/hooks/useCrmData.js +23 -17
- package/src/react/pages/proposals/CreateProposalsModal.js +1 -0
- package/src/react/pages/proposals/index.js +14 -33
- package/src/react/pages/settings/GeneralSettings.styles.js +2 -0
- package/src/react/pages/settings/sections/LoyaltyProductPicker.js +58 -145
- package/src/react/pages/settings/sections/LoyaltySection.js +35 -9
- package/src/react/pages/settings/sections/MapsFranchisePreview.js +102 -0
- package/src/react/pages/settings/sections/MapsMapasControls.js +262 -0
- package/src/react/pages/settings/sections/MapsSection.js +71 -247
- package/src/react/pages/settings/sections/loyaltyProductCompany.js +57 -0
- package/src/react/pages/settings/sections/mapsSectionHelpers.js +137 -0
- package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +7 -28
- package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +54 -8
- package/src/react/pages/settings/sections/shop/shopSettingsShared.js +32 -11
- package/src/react/utils/clientDetailsNavigation.js +56 -0
- package/src/react/utils/clientSellerVisibility.js +60 -0
- package/src/react/utils/proposalProductSelection.js +103 -13
- package/src/react/utils/proposalStatus.js +160 -0
- package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +25 -0
- package/src/tests/browser/manager/general-settings-maps.spec.js +173 -347
- package/src/tests/react/pages/settings/sections/loyaltyProductCompany.test.js +41 -0
- package/src/tests/react/pages/settings/sections/mapsSectionHelpers.test.js +38 -0
- package/src/tests/react/utils/clientDetailsNavigation.test.js +98 -0
- package/src/tests/react/utils/clientSellerVisibility.test.js +74 -0
- package/src/tests/react/utils/proposalProductSelection.test.js +57 -1
- package/src/tests/react/utils/proposalStatus.test.mjs +77 -0
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
});
|
|
@@ -2,11 +2,13 @@ const test = require('node:test');
|
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
|
+
collectProductCategoryIds,
|
|
5
6
|
filterProductsByModelCategory,
|
|
6
7
|
getProposalModelCategoryId,
|
|
7
8
|
getProposalModelCategoryName,
|
|
8
9
|
keepCompatibleSelectedProducts,
|
|
9
10
|
normalizeCategoryId,
|
|
11
|
+
productMatchesModelCategory,
|
|
10
12
|
} = require('../../../react/utils/proposalProductSelection');
|
|
11
13
|
|
|
12
14
|
test('normalizeCategoryId resolves nested category references', () => {
|
|
@@ -32,7 +34,19 @@ test('getProposalModelCategoryName returns human label when present', () => {
|
|
|
32
34
|
assert.equal(getProposalModelCategoryName({ category: {} }), '');
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
test('
|
|
37
|
+
test('collectProductCategoryIds reads productCategory join collection', () => {
|
|
38
|
+
const product = {
|
|
39
|
+
'@id': '/products/1',
|
|
40
|
+
productCategory: [
|
|
41
|
+
{ category: { '@id': '/categories/4' } },
|
|
42
|
+
{ category: '/categories/9' },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
assert.deepEqual([...collectProductCategoryIds(product)].sort(), ['4', '9']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('filterProductsByModelCategory keeps matching products via product.category', () => {
|
|
36
50
|
const products = [
|
|
37
51
|
{ '@id': '/products/1', category: { '@id': '/categories/4' } },
|
|
38
52
|
{ '@id': '/products/2', category: { '@id': '/categories/7' } },
|
|
@@ -48,6 +62,40 @@ test('filterProductsByModelCategory keeps only matching products when a category
|
|
|
48
62
|
);
|
|
49
63
|
});
|
|
50
64
|
|
|
65
|
+
test('filterProductsByModelCategory keeps matching products via productCategory join', () => {
|
|
66
|
+
const products = [
|
|
67
|
+
{
|
|
68
|
+
'@id': '/products/10',
|
|
69
|
+
productCategory: [{ category: { '@id': '/categories/4', name: 'Serviços' } }],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
'@id': '/products/11',
|
|
73
|
+
productCategory: [{ category: { '@id': '/categories/8' } }],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
assert.deepEqual(
|
|
78
|
+
filterProductsByModelCategory({
|
|
79
|
+
products,
|
|
80
|
+
selectedModelCategoryId: '4',
|
|
81
|
+
}),
|
|
82
|
+
[products[0]],
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('filterProductsByModelCategory keeps sparse products when categories are not embedded', () => {
|
|
87
|
+
// product:read often omits productCategory; API filter is the source of truth.
|
|
88
|
+
const products = [{ '@id': '/products/1' }, { '@id': '/products/2' }];
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(
|
|
91
|
+
filterProductsByModelCategory({
|
|
92
|
+
products,
|
|
93
|
+
selectedModelCategoryId: '4',
|
|
94
|
+
}),
|
|
95
|
+
products,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
51
99
|
test('filterProductsByModelCategory preserves the original list when the model has no category', () => {
|
|
52
100
|
const products = [{ '@id': '/products/1' }, { '@id': '/products/2' }];
|
|
53
101
|
|
|
@@ -74,3 +122,11 @@ test('keepCompatibleSelectedProducts drops selections outside the model category
|
|
|
74
122
|
[selectedProducts[0]],
|
|
75
123
|
);
|
|
76
124
|
});
|
|
125
|
+
|
|
126
|
+
test('productMatchesModelCategory accepts join-based membership', () => {
|
|
127
|
+
const product = {
|
|
128
|
+
productCategory: [{ category: '/categories/15' }],
|
|
129
|
+
};
|
|
130
|
+
assert.equal(productMatchesModelCategory(product, '15'), true);
|
|
131
|
+
assert.equal(productMatchesModelCategory(product, '99'), false);
|
|
132
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
});
|