@controleonline/ui-common 1.2.131 → 1.2.132
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/.release/rc-manifest.json +6 -5
- package/package.json +4 -2
- package/src/react/components/LinkedOrderProductsTab.js +11 -4
- package/src/react/utils/commercialDocumentOrders.js +13 -20
- package/src/react/utils/documentFileContent.js +55 -0
- package/src/react/utils/linkedOrderPayload.js +43 -0
- package/src/tests/react/utils/documentFileContent.test.js +28 -0
- package/src/tests/react/utils/linkedOrderPayload.test.js +46 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.132",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.2.132-rc.1",
|
|
5
|
+
"baseMaster": "6ca50f9716ba2ff370dce15669b68777271b7e99",
|
|
6
|
+
"baseTag": "v1.2.131",
|
|
6
7
|
"tasks": [
|
|
7
|
-
|
|
8
|
+
98
|
|
8
9
|
],
|
|
9
10
|
"frozen": true,
|
|
10
11
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-common": "
|
|
12
|
+
"ControleOnline/ui-common": "07ca4291f5553015f8cc898f015b4f3df68057cc"
|
|
12
13
|
}
|
|
13
14
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@controleonline/ui-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.132",
|
|
4
4
|
"author": "ControleOnline",
|
|
5
5
|
"description": "ControleOnline Common Quasar UI Component",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/react/index.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary",
|
|
9
|
+
"test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary && npm run test:linked-order-payload && npm run test:document-file-content",
|
|
10
10
|
"test:receita-federal": "node --test src/tests/react/pages/receitaFederalIntegrationContract.test.mjs",
|
|
11
11
|
"test:imports-status": "mkdir -p node_modules/@controleonline && rm -rf node_modules/@controleonline/ui-common && ln -s ../.. node_modules/@controleonline/ui-common && node --test src/tests/react/utils/importStatus.test.js",
|
|
12
12
|
"test:cash-register-summary": "node --test src/tests/react/utils/cashRegisterSummary.test.js",
|
|
13
|
+
"test:linked-order-payload": "node --test src/tests/react/utils/linkedOrderPayload.test.js",
|
|
14
|
+
"test:document-file-content": "node --test src/tests/react/utils/documentFileContent.test.js",
|
|
13
15
|
"test:runtime-language": "node --test src/tests/react/utils/runtimeLanguage.test.js",
|
|
14
16
|
"test:runtime-footer": "node --test src/tests/react/utils/runtimeFooter.test.js src/tests/react/utils/runtimeFooterText.test.js",
|
|
15
17
|
"test:invoice-presentation": "node --test src/tests/react/utils/invoicePresentation.test.mjs",
|
|
@@ -62,6 +62,8 @@ const LinkedOrderProductsTab = ({
|
|
|
62
62
|
emptyTitle = 'Nenhum produto adicionado.',
|
|
63
63
|
emptySubtitle = 'Você pode vincular produtos a este documento quando precisar.',
|
|
64
64
|
searchPlaceholder = 'Buscar produto para adicionar...',
|
|
65
|
+
// Called after products change so the parent can regenerate/reload the document.
|
|
66
|
+
onProductsChanged,
|
|
65
67
|
}) => {
|
|
66
68
|
const peopleStore = useStore('people');
|
|
67
69
|
const { currentCompany } = peopleStore.getters;
|
|
@@ -82,6 +84,9 @@ const LinkedOrderProductsTab = ({
|
|
|
82
84
|
);
|
|
83
85
|
|
|
84
86
|
const canEditProducts = !!canEdit && !!contract?.['@id'] && (!order || isOpenCommercialOrder(order));
|
|
87
|
+
// The backend only accepts products linked to the contract model category
|
|
88
|
+
// (ProposalProductCategoryGuard), so the search must use the same filter.
|
|
89
|
+
const modelCategoryId = normalizeEntityId(contract?.contractModel?.category);
|
|
85
90
|
|
|
86
91
|
const loadLinkedOrderProducts = useCallback(async () => {
|
|
87
92
|
if (!contract?.['@id']) {
|
|
@@ -128,6 +133,7 @@ const LinkedOrderProductsTab = ({
|
|
|
128
133
|
const results = await searchCompanyProducts({
|
|
129
134
|
companyId: currentCompany.id,
|
|
130
135
|
query: trimmedQuery,
|
|
136
|
+
categoryId: modelCategoryId,
|
|
131
137
|
});
|
|
132
138
|
|
|
133
139
|
if (!cancelled) {
|
|
@@ -148,7 +154,7 @@ const LinkedOrderProductsTab = ({
|
|
|
148
154
|
cancelled = true;
|
|
149
155
|
clearTimeout(timeoutId);
|
|
150
156
|
};
|
|
151
|
-
}, [canEditProducts, currentCompany?.id, searchQuery]);
|
|
157
|
+
}, [canEditProducts, currentCompany?.id, modelCategoryId, searchQuery]);
|
|
152
158
|
|
|
153
159
|
const ensureCurrentOrder = useCallback(async () => {
|
|
154
160
|
if (order) {
|
|
@@ -161,7 +167,6 @@ const LinkedOrderProductsTab = ({
|
|
|
161
167
|
client: contract?.client,
|
|
162
168
|
payer: contract?.client,
|
|
163
169
|
app: 'CRM',
|
|
164
|
-
orderType: 'sale',
|
|
165
170
|
});
|
|
166
171
|
|
|
167
172
|
setOrder(createdOrder);
|
|
@@ -188,12 +193,13 @@ const LinkedOrderProductsTab = ({
|
|
|
188
193
|
setSearchQuery('');
|
|
189
194
|
setSearchResults([]);
|
|
190
195
|
await loadLinkedOrderProducts();
|
|
196
|
+
await onProductsChanged?.();
|
|
191
197
|
} catch (error) {
|
|
192
198
|
showError?.(formatApiError(error));
|
|
193
199
|
} finally {
|
|
194
200
|
setAddingProductId(null);
|
|
195
201
|
}
|
|
196
|
-
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, showError]);
|
|
202
|
+
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, onProductsChanged, showError]);
|
|
197
203
|
|
|
198
204
|
const handleChangeQuantity = useCallback(async (orderProduct, nextQuantity) => {
|
|
199
205
|
if (updatingOrderProductId) {
|
|
@@ -217,12 +223,13 @@ const LinkedOrderProductsTab = ({
|
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
await loadLinkedOrderProducts();
|
|
226
|
+
await onProductsChanged?.();
|
|
220
227
|
} catch (error) {
|
|
221
228
|
showError?.(formatApiError(error));
|
|
222
229
|
} finally {
|
|
223
230
|
setUpdatingOrderProductId(null);
|
|
224
231
|
}
|
|
225
|
-
}, [loadLinkedOrderProducts, showError, updatingOrderProductId]);
|
|
232
|
+
}, [loadLinkedOrderProducts, onProductsChanged, showError, updatingOrderProductId]);
|
|
226
233
|
|
|
227
234
|
const visibleSearchResults = useMemo(() => {
|
|
228
235
|
const existingProductIds = new Set(
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { api } from '@controleonline/ui-common/src/api';
|
|
2
|
+
import {
|
|
3
|
+
LINKED_ORDER_TYPE,
|
|
4
|
+
buildLinkedOrderPayload,
|
|
5
|
+
} from '@controleonline/ui-common/src/react/utils/linkedOrderPayload';
|
|
2
6
|
|
|
3
7
|
const normalizeStatusKey = value => String(value || '').trim().toLowerCase();
|
|
4
8
|
|
|
@@ -158,30 +162,19 @@ export const createLinkedOrder = async ({
|
|
|
158
162
|
client,
|
|
159
163
|
payer,
|
|
160
164
|
app = 'CRM',
|
|
161
|
-
orderType =
|
|
165
|
+
orderType = LINKED_ORDER_TYPE,
|
|
162
166
|
fallbackStatusId = null,
|
|
163
167
|
}) => {
|
|
164
168
|
const status = await resolveOpenOrderStatusIri(fallbackStatusId);
|
|
165
|
-
const payload = {
|
|
169
|
+
const payload = buildLinkedOrderPayload({
|
|
166
170
|
app,
|
|
167
171
|
orderType,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const clientIri = toEntityIri(client, 'people');
|
|
177
|
-
if (clientIri) {
|
|
178
|
-
payload.client = clientIri;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const payerIri = toEntityIri(payer || client, 'people');
|
|
182
|
-
if (payerIri) {
|
|
183
|
-
payload.payer = payerIri;
|
|
184
|
-
}
|
|
172
|
+
contractIri: toEntityIri(contractRef, 'contracts'),
|
|
173
|
+
providerIri: toEntityIri(provider, 'people'),
|
|
174
|
+
statusIri: status,
|
|
175
|
+
clientIri: toEntityIri(client, 'people'),
|
|
176
|
+
payerIri: toEntityIri(payer, 'people'),
|
|
177
|
+
});
|
|
185
178
|
|
|
186
179
|
return api.fetch('orders', {
|
|
187
180
|
method: 'POST',
|
|
@@ -195,7 +188,7 @@ export const ensureLinkedOrder = async ({
|
|
|
195
188
|
client,
|
|
196
189
|
payer,
|
|
197
190
|
app = 'CRM',
|
|
198
|
-
orderType =
|
|
191
|
+
orderType = LINKED_ORDER_TYPE,
|
|
199
192
|
fallbackStatusId = null,
|
|
200
193
|
}) => {
|
|
201
194
|
const existingOrder = await fetchLinkedOrder(contractRef);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// File.content comes base64 encoded from the API (File::getContent()). Contract
|
|
2
|
+
// and proposal documents are HTML generated from Twig models, while signed
|
|
3
|
+
// documents may be PDFs. Decode before deciding how to render.
|
|
4
|
+
|
|
5
|
+
const BASE64_PATTERN = /^[A-Za-z0-9+/=\r\n]+$/;
|
|
6
|
+
|
|
7
|
+
const decodeBase64Utf8 = value => {
|
|
8
|
+
const binary =
|
|
9
|
+
typeof globalThis.atob === 'function'
|
|
10
|
+
? globalThis.atob(value)
|
|
11
|
+
: typeof Buffer !== 'undefined'
|
|
12
|
+
? Buffer.from(value, 'base64').toString('binary')
|
|
13
|
+
: null;
|
|
14
|
+
if (binary === null) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const percentEncoded = Array.from(binary)
|
|
19
|
+
.map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`)
|
|
20
|
+
.join('');
|
|
21
|
+
return decodeURIComponent(percentEncoded);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const looksLikeHtml = value => String(value || '').trim().startsWith('<');
|
|
25
|
+
|
|
26
|
+
const resolveDocumentFileContent = content => {
|
|
27
|
+
const raw = String(content || '');
|
|
28
|
+
if (!raw.trim()) {
|
|
29
|
+
return { kind: 'empty', content: '' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (looksLikeHtml(raw)) {
|
|
33
|
+
return { kind: 'html', content: raw };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const compact = raw.trim();
|
|
37
|
+
if (BASE64_PATTERN.test(compact)) {
|
|
38
|
+
try {
|
|
39
|
+
const decoded = decodeBase64Utf8(compact.replace(/[\r\n]/g, ''));
|
|
40
|
+
if (decoded !== null && looksLikeHtml(decoded)) {
|
|
41
|
+
return { kind: 'html', content: decoded };
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
// Not UTF-8 text: binary payload such as a PDF.
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { kind: 'pdf', content: compact };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { kind: 'text', content: raw };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
resolveDocumentFileContent,
|
|
55
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Orders linked to proposals/contracts are commercial drafts: the backend only
|
|
2
|
+
// accepts add/remove of products while the order is a `cart`
|
|
3
|
+
// (api-platform-orders OrderProductServiceHelpers::isMutableCartOrder) and never
|
|
4
|
+
// lets a `sale` go back to `cart`. They must start as `cart` and be promoted to
|
|
5
|
+
// `sale` (PUT /orders/{id} with orderType=sale) only when the deal is confirmed.
|
|
6
|
+
const LINKED_ORDER_TYPE = 'cart';
|
|
7
|
+
|
|
8
|
+
const buildLinkedOrderPayload = ({
|
|
9
|
+
app = 'CRM',
|
|
10
|
+
orderType = LINKED_ORDER_TYPE,
|
|
11
|
+
contractIri = null,
|
|
12
|
+
providerIri = null,
|
|
13
|
+
statusIri = null,
|
|
14
|
+
clientIri = null,
|
|
15
|
+
payerIri = null,
|
|
16
|
+
} = {}) => {
|
|
17
|
+
const payload = {
|
|
18
|
+
app,
|
|
19
|
+
orderType: orderType || LINKED_ORDER_TYPE,
|
|
20
|
+
contract: contractIri,
|
|
21
|
+
provider: providerIri,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (statusIri) {
|
|
25
|
+
payload.status = statusIri;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (clientIri) {
|
|
29
|
+
payload.client = clientIri;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const resolvedPayerIri = payerIri || clientIri;
|
|
33
|
+
if (resolvedPayerIri) {
|
|
34
|
+
payload.payer = resolvedPayerIri;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return payload;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
LINKED_ORDER_TYPE,
|
|
42
|
+
buildLinkedOrderPayload,
|
|
43
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { resolveDocumentFileContent } = require('../../../react/utils/documentFileContent');
|
|
4
|
+
|
|
5
|
+
const toBase64 = text => Buffer.from(text, 'utf8').toString('base64');
|
|
6
|
+
|
|
7
|
+
test('decodes base64 HTML documents returned by the files API', () => {
|
|
8
|
+
const html = '<h1>Proposta</h1><p>Codex — R$ 260,00 (ação)</p>';
|
|
9
|
+
assert.deepEqual(resolveDocumentFileContent(toBase64(html)), { kind: 'html', content: html });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('keeps plain HTML as is', () => {
|
|
13
|
+
assert.deepEqual(resolveDocumentFileContent(' <p>ok</p>'), { kind: 'html', content: ' <p>ok</p>' });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('treats non-HTML base64 payloads as PDF', () => {
|
|
17
|
+
const pdf = Buffer.from([0x25, 0x50, 0x44, 0x46, 0x2d, 0xff, 0xfe, 0x00]).toString('base64');
|
|
18
|
+
assert.deepEqual(resolveDocumentFileContent(pdf), { kind: 'pdf', content: pdf });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('empty and plain text contents', () => {
|
|
22
|
+
assert.deepEqual(resolveDocumentFileContent(''), { kind: 'empty', content: '' });
|
|
23
|
+
assert.deepEqual(resolveDocumentFileContent(null), { kind: 'empty', content: '' });
|
|
24
|
+
assert.deepEqual(resolveDocumentFileContent('Contrato simples, sem HTML.'), {
|
|
25
|
+
kind: 'text',
|
|
26
|
+
content: 'Contrato simples, sem HTML.',
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const {
|
|
4
|
+
LINKED_ORDER_TYPE,
|
|
5
|
+
buildLinkedOrderPayload,
|
|
6
|
+
} = require('../../../react/utils/linkedOrderPayload');
|
|
7
|
+
|
|
8
|
+
test('linked commercial orders start as cart so products can be edited', () => {
|
|
9
|
+
assert.equal(LINKED_ORDER_TYPE, 'cart');
|
|
10
|
+
const payload = buildLinkedOrderPayload({
|
|
11
|
+
contractIri: '/contracts/27',
|
|
12
|
+
providerIri: '/people/1',
|
|
13
|
+
statusIri: '/statuses/119',
|
|
14
|
+
clientIri: '/people/105792',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
assert.deepEqual(payload, {
|
|
18
|
+
app: 'CRM',
|
|
19
|
+
orderType: 'cart',
|
|
20
|
+
contract: '/contracts/27',
|
|
21
|
+
provider: '/people/1',
|
|
22
|
+
status: '/statuses/119',
|
|
23
|
+
client: '/people/105792',
|
|
24
|
+
payer: '/people/105792',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('empty orderType falls back to cart instead of being sent blank', () => {
|
|
29
|
+
assert.equal(buildLinkedOrderPayload({orderType: ''}).orderType, 'cart');
|
|
30
|
+
assert.equal(buildLinkedOrderPayload({orderType: null}).orderType, 'cart');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('explicit payer wins over client and optional refs are omitted', () => {
|
|
34
|
+
const payload = buildLinkedOrderPayload({
|
|
35
|
+
contractIri: '/contracts/1',
|
|
36
|
+
providerIri: '/people/1',
|
|
37
|
+
clientIri: '/people/2',
|
|
38
|
+
payerIri: '/people/3',
|
|
39
|
+
});
|
|
40
|
+
assert.equal(payload.payer, '/people/3');
|
|
41
|
+
assert.equal('status' in payload, false);
|
|
42
|
+
|
|
43
|
+
const withoutParties = buildLinkedOrderPayload({contractIri: '/contracts/1'});
|
|
44
|
+
assert.equal('client' in withoutParties, false);
|
|
45
|
+
assert.equal('payer' in withoutParties, false);
|
|
46
|
+
});
|