@controleonline/ui-crm 1.0.87 → 1.0.90

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.
@@ -1,12 +1,14 @@
1
1
  {
2
- "version": "1.0.87",
2
+ "version": "1.0.89",
3
3
  "rc": 1,
4
- "branch": "rc/1.0.87-rc.1",
5
- "baseMaster": "e21f04e30423240b1a6294719d11bd2e5ce0e997",
6
- "baseTag": "v1.0.86",
7
- "tasks": [105],
4
+ "branch": "rc/1.0.89-rc.1",
5
+ "baseMaster": "a5c82d3e56a9543b89b56d37b397435f50523c60",
6
+ "baseTag": "v1.0.88",
7
+ "tasks": [
8
+ 98
9
+ ],
8
10
  "frozen": true,
9
11
  "repositories": {
10
- "ControleOnline/ui-crm": "2783818d7c529320fa8584006de36af15afb91d0"
12
+ "ControleOnline/ui-crm": "4d59fd3096e3ae4b192cf4e54d063a21ac6a8bda"
11
13
  }
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controleonline/ui-crm",
3
- "version": "1.0.87",
3
+ "version": "1.0.90",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline CRM Quasar UI Component",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@ const {
25
25
  } = require('../../utils/proposalCreateHelpers');
26
26
 
27
27
  const {
28
- filterProductsByModelCategory,
28
+ tagProductsWithModelCategory,
29
29
  getProposalModelCategoryId,
30
30
  getProposalModelCategoryName,
31
31
  keepCompatibleSelectedProducts,
@@ -106,9 +106,11 @@ const CreateProposalsModal = ({ visible, onClose, onSuccess }) => {
106
106
  const results = await searchCompanyProducts({
107
107
  companyId: currentCompany.id,
108
108
  query: productQuery,
109
+ // Server-side filter matches the backend guard (product_categories).
110
+ categoryId: selectedModelCategoryId,
109
111
  });
110
112
 
111
- const filteredResults = filterProductsByModelCategory({
113
+ const filteredResults = tagProductsWithModelCategory({
112
114
  products: results,
113
115
  selectedModelCategoryId,
114
116
  });
@@ -257,7 +259,6 @@ const CreateProposalsModal = ({ visible, onClose, onSuccess }) => {
257
259
  client: selectedClient,
258
260
  payer: selectedClient,
259
261
  app: 'CRM',
260
- orderType: 'sale',
261
262
  });
262
263
 
263
264
  if (selectedProducts.length > 0) {
@@ -8,6 +8,7 @@ import RenderHTML from 'react-native-render-html';
8
8
  import { colors } from '@controleonline/../../src/styles/colors';
9
9
  import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
10
10
  import LinkedOrderProductsTab from '@controleonline/ui-common/src/react/components/LinkedOrderProductsTab';
11
+ import { resolveDocumentFileContent } from '@controleonline/ui-common/src/react/utils/documentFileContent';
11
12
  import styles from './ProposalDetails.styles';
12
13
  import { getProposalInitialTabIndex } from './proposalNavigation';
13
14
 
@@ -126,7 +127,7 @@ const ProposalDetails = () => {
126
127
  setFileLoading(true);
127
128
  try {
128
129
  const res = await contractActions.getFileContent(data.contractFile['@id']);
129
- setFileContent(res.content || '');
130
+ setFileContent(resolveDocumentFileContent(res?.content).content);
130
131
  } catch {
131
132
  setFileError('Falha ao carregar a proposta');
132
133
  } finally {
@@ -147,13 +148,28 @@ const ProposalDetails = () => {
147
148
  const updated = await contractActions.get(contractId);
148
149
  if (updated?.contractFile) {
149
150
  const res = await contractActions.getFileContent(updated.contractFile['@id']);
150
- setFileContent(res.content || '');
151
+ setFileContent(resolveDocumentFileContent(res?.content).content);
151
152
  }
152
153
  } catch {
153
154
  showError('Erro ao enviar proposta');
154
155
  }
155
156
  };
156
157
 
158
+ // The proposal is rendered from the order products; regenerate it after they change.
159
+ const handleProductsChanged = async () => {
160
+ try {
161
+ await contractActions.generate({ id: contractId });
162
+ const updated = await contractActions.get(contractId);
163
+ if (updated?.contractFile) {
164
+ const res = await contractActions.getFileContent(updated.contractFile['@id']);
165
+ setFileContent(resolveDocumentFileContent(res?.content).content);
166
+ setFileError(null);
167
+ }
168
+ } catch {
169
+ showError('Produtos salvos, mas a proposta nao foi atualizada. Recarregue a tela.');
170
+ }
171
+ };
172
+
157
173
  const handleTabPress = (index) => {
158
174
  setActiveTab(index);
159
175
  scrollRef.current?.scrollTo({ x: index * width, animated: true });
@@ -253,6 +269,7 @@ const ProposalDetails = () => {
253
269
  emptyTitle="Nenhum produto vinculado a esta proposta."
254
270
  emptySubtitle="Adicione os produtos negociados para poder ajustar a proposta ao longo da conversa com o cliente."
255
271
  searchPlaceholder="Buscar produto para adicionar a proposta..."
272
+ onProductsChanged={handleProductsChanged}
256
273
  />
257
274
  </View>
258
275
  </ScrollView>
@@ -38,6 +38,49 @@ const getProposalModelCategoryId = model => normalizeCategoryId(model?.category)
38
38
  const getProposalModelCategoryName = model =>
39
39
  String(model?.category?.name || model?.category?.category || '').trim();
40
40
 
41
+ // Products returned by a search already filtered on the server by
42
+ // `productCategory.category` carry this tag, because the product payload does
43
+ // not always embed its productCategory relation.
44
+ const MODEL_CATEGORY_TAG = 'proposalModelCategoryId';
45
+
46
+ const tagProductsWithModelCategory = ({ products, selectedModelCategoryId }) => {
47
+ const normalizedProducts = Array.isArray(products) ? products : [];
48
+ if (!selectedModelCategoryId) {
49
+ return normalizedProducts;
50
+ }
51
+
52
+ return normalizedProducts.map(product => ({
53
+ ...product,
54
+ [MODEL_CATEGORY_TAG]: String(selectedModelCategoryId),
55
+ }));
56
+ };
57
+
58
+ // Mirrors the backend rule (ProposalProductCategoryGuard): the product belongs
59
+ // to the model category when one of its product_categories points to it.
60
+ const productBelongsToCategory = (product, categoryId) => {
61
+ const expectedId = normalizeEntityId(categoryId);
62
+ if (!expectedId) {
63
+ return true;
64
+ }
65
+
66
+ if (normalizeEntityId(product?.[MODEL_CATEGORY_TAG]) === expectedId) {
67
+ return true;
68
+ }
69
+
70
+ const productCategories = Array.isArray(product?.productCategory)
71
+ ? product.productCategory
72
+ : [];
73
+ if (
74
+ productCategories.some(
75
+ productCategory => normalizeCategoryId(productCategory) === expectedId,
76
+ )
77
+ ) {
78
+ return true;
79
+ }
80
+
81
+ return !!product?.category && normalizeCategoryId(product.category) === expectedId;
82
+ };
83
+
41
84
  const filterProductsByModelCategory = ({ products, selectedModelCategoryId }) => {
42
85
  const normalizedProducts = Array.isArray(products) ? products : [];
43
86
 
@@ -45,8 +88,8 @@ const filterProductsByModelCategory = ({ products, selectedModelCategoryId }) =>
45
88
  return normalizedProducts;
46
89
  }
47
90
 
48
- return normalizedProducts.filter(
49
- product => normalizeCategoryId(product?.category) === selectedModelCategoryId,
91
+ return normalizedProducts.filter(product =>
92
+ productBelongsToCategory(product, selectedModelCategoryId),
50
93
  );
51
94
  };
52
95
 
@@ -62,10 +105,13 @@ const keepCompatibleSelectedProducts = ({ selectedProducts, selectedModelCategor
62
105
  };
63
106
 
64
107
  module.exports = {
108
+ MODEL_CATEGORY_TAG,
65
109
  filterProductsByModelCategory,
66
110
  getProposalModelCategoryId,
67
111
  getProposalModelCategoryName,
68
112
  keepCompatibleSelectedProducts,
69
113
  normalizeCategoryId,
70
114
  normalizeEntityId,
115
+ productBelongsToCategory,
116
+ tagProductsWithModelCategory,
71
117
  };
@@ -7,6 +7,8 @@ const {
7
7
  getProposalModelCategoryName,
8
8
  keepCompatibleSelectedProducts,
9
9
  normalizeCategoryId,
10
+ productBelongsToCategory,
11
+ tagProductsWithModelCategory,
10
12
  } = require('../../../react/utils/proposalProductSelection');
11
13
 
12
14
  test('normalizeCategoryId resolves nested category references', () => {
@@ -74,3 +76,42 @@ test('keepCompatibleSelectedProducts drops selections outside the model category
74
76
  [selectedProducts[0]],
75
77
  );
76
78
  });
79
+
80
+ test('productBelongsToCategory follows the product_categories relation used by the backend guard', () => {
81
+ const product = {
82
+ '@id': '/products/1374',
83
+ productCategory: [
84
+ { category: { '@id': '/categories/2' } },
85
+ { category: '/categories/176' },
86
+ ],
87
+ };
88
+
89
+ assert.equal(productBelongsToCategory(product, '176'), true);
90
+ assert.equal(productBelongsToCategory(product, '/categories/2'), true);
91
+ assert.equal(productBelongsToCategory(product, '9'), false);
92
+ assert.equal(productBelongsToCategory({ '@id': '/products/1' }, '176'), false);
93
+ assert.equal(productBelongsToCategory({ '@id': '/products/1' }, null), true);
94
+ });
95
+
96
+ test('products fetched with the server category filter stay compatible with that model only', () => {
97
+ const tagged = tagProductsWithModelCategory({
98
+ products: [{ '@id': '/products/1374', product: 'Codex' }],
99
+ selectedModelCategoryId: '176',
100
+ });
101
+
102
+ assert.equal(tagged[0].product, 'Codex');
103
+ assert.deepEqual(
104
+ keepCompatibleSelectedProducts({ selectedProducts: tagged, selectedModelCategoryId: '176' }),
105
+ tagged,
106
+ );
107
+ assert.deepEqual(
108
+ keepCompatibleSelectedProducts({ selectedProducts: tagged, selectedModelCategoryId: '172' }),
109
+ [],
110
+ );
111
+ });
112
+
113
+ test('tagProductsWithModelCategory keeps the list untouched when the model has no category', () => {
114
+ const products = [{ '@id': '/products/1' }];
115
+ assert.equal(tagProductsWithModelCategory({ products, selectedModelCategoryId: null }), products);
116
+ assert.deepEqual(tagProductsWithModelCategory({ products: null, selectedModelCategoryId: '1' }), []);
117
+ });