@controleonline/ui-common 1.2.134 → 1.2.135
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 +12 -5
- package/package.json +6 -2
- package/src/react/components/CategoryForm.js +539 -539
- package/src/react/components/DefaultProvider.native.js +2 -2
- package/src/react/components/DefaultProvider.web.js +2 -2
- package/src/react/components/LinkedOrderProductsTab.js +17 -8
- package/src/react/components/LinkedOrderProductsTab.styles.js +15 -0
- package/src/react/components/documentDetails/DocumentDetailsShell.js +147 -0
- package/src/react/components/documentDetails/DocumentDetailsShell.styles.js +163 -0
- package/src/react/components/documentDetails/DocumentSheet.js +87 -0
- package/src/react/components/integrations/IntegrationHero/index.js +1 -1
- package/src/react/components/integrations/IntegrationHero/styles.js +2 -2
- package/src/react/components/integrations/IntegrationTabs/index.js +1 -1
- package/src/react/components/integrations/IntegrationTabs/styles.js +1 -1
- package/src/react/hooks/useLinkedOrderSummary.js +41 -0
- package/src/react/pages/Connections.styles.js +72 -72
- package/src/react/pages/Devices/detail/DeviceDetailHeader.js +1 -1
- package/src/react/pages/Devices/detail/DeviceDetailMovementSections.js +1 -1
- package/src/react/pages/Devices/detail/useDeviceDetailStateA.js +2 -2
- package/src/react/pages/Devices/detail/useDeviceDetailStateB.js +2 -2
- package/src/react/pages/Devices/deviceTypes/DeviceGroupCard.js +1 -1
- package/src/react/pages/Devices/deviceTypes/shared.js +2 -2
- package/src/react/pages/Devices.js +2 -2
- package/src/react/pages/Devices.styles.js +353 -353
- package/src/react/pages/Food99IntegrationPage/components/Food99CatalogTab.js +219 -219
- package/src/react/pages/Food99IntegrationPage/components/Food99OverviewTab.js +134 -134
- package/src/react/pages/Food99IntegrationPage/components/Food99PreviewModal.js +173 -173
- package/src/react/pages/Food99IntegrationPage/components/Food99QuickWalletModal.js +1 -1
- package/src/react/pages/Food99IntegrationPage/components/Food99SettingsTab.js +306 -306
- package/src/react/pages/Food99IntegrationPage/components/Food99StoreTab.js +417 -417
- package/src/react/pages/Food99IntegrationPage/index.js +1530 -1530
- package/src/react/pages/Food99IntegrationPage/styles.js +792 -792
- package/src/react/pages/IFoodIntegrationPage/components/IFoodOperationsTab.js +267 -267
- package/src/react/pages/IFoodIntegrationPage/components/IFoodOverviewTab.js +118 -118
- package/src/react/pages/IFoodIntegrationPage/components/IFoodPreviewModal.js +101 -101
- package/src/react/pages/IFoodIntegrationPage/components/IFoodStoreTab.js +150 -150
- package/src/react/pages/IFoodIntegrationPage/index.js +1298 -1298
- package/src/react/pages/Imports.js +1 -1
- package/src/react/pages/Imports.styles.js +223 -223
- package/src/react/pages/IntegrationConfigPage.js +2 -2
- package/src/react/pages/Integrations.js +2 -15
- package/src/react/pages/Integrations.styles.js +130 -130
- package/src/react/pages/LinkedInIntegrationPage.js +2 -2
- package/src/react/pages/ManagerOrderNotificationsPage.js +642 -642
- package/src/react/pages/MarketplaceIntegrationPage/components/MarketplaceProductCard.js +205 -205
- package/src/react/pages/MercadoLivreIntegrationPage.js +2 -2
- package/src/react/pages/PrinterDeviceDetailPage.js +1915 -1915
- package/src/react/pages/PrinterDeviceFormPage.js +2 -2
- package/src/react/pages/WhatsAppConnectionPage.styles.js +315 -279
- package/src/react/pages/WhatsAppProviderForm.js +1 -1
- package/src/react/pages/whatsAppConnectionHelpers.js +38 -10
- package/src/react/router/__tests__/publicRoutes.test.js +12 -0
- package/src/react/router/publicRoutes.js +3 -0
- package/src/react/utils/clientPortfolioParams.js +42 -0
- package/src/react/utils/commercialDocumentOrders.js +13 -20
- package/src/react/utils/documentFileContent.js +61 -0
- package/src/react/utils/fileUrl.js +1 -1
- package/src/react/utils/linkedOrderPayload.js +43 -0
- package/src/react/utils/orderProductsSummary.js +28 -0
- package/src/react/utils/peopleDisplay.js +8 -13
- package/src/store/connections/customActions.js +16 -14
- package/src/store/connections/index.js +109 -105
- package/src/tests/react/utils/clientPortfolioParams.test.js +30 -0
- package/src/tests/react/utils/documentFileContent.test.js +29 -0
- package/src/tests/react/utils/linkedOrderPayload.test.js +46 -0
- package/src/tests/react/utils/orderProductsSummary.test.js +24 -0
|
@@ -19,6 +19,29 @@ export const formatPhoneLabel = phone => {
|
|
|
19
19
|
return ddd ? `(${ddd}) ${firstPart}-${lastFour}` : `${firstPart}-${lastFour}`;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const resolveStatusIri = status => {
|
|
23
|
+
if (!status) return null;
|
|
24
|
+
if (typeof status === 'string') {
|
|
25
|
+
if (status.startsWith('/') || status.startsWith('http')) return status;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (typeof status === 'object') {
|
|
29
|
+
const iri = status['@id'] || status.id;
|
|
30
|
+
if (iri == null) return null;
|
|
31
|
+
const asString = String(iri);
|
|
32
|
+
if (asString.startsWith('/') || asString.startsWith('http')) return asString;
|
|
33
|
+
return `/statuses/${asString}`;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const resolveNumericId = item => {
|
|
39
|
+
const raw = item?.id ?? item?.['@id'];
|
|
40
|
+
if (raw == null) return null;
|
|
41
|
+
const digits = String(raw).replace(/\D/g, '');
|
|
42
|
+
return digits ? Number(digits) : null;
|
|
43
|
+
};
|
|
44
|
+
|
|
22
45
|
export const normalizeConnection = item => {
|
|
23
46
|
const channel =
|
|
24
47
|
item?.channel === CHANNEL_WHATSAPP_OFFICIAL
|
|
@@ -26,15 +49,18 @@ export const normalizeConnection = item => {
|
|
|
26
49
|
: CHANNEL_WHATSAPP;
|
|
27
50
|
return {
|
|
28
51
|
id: item?.id || item?.['@id'] || `connection-${Math.random()}`,
|
|
52
|
+
numericId: resolveNumericId(item),
|
|
29
53
|
name: item?.name || 'Sem nome',
|
|
30
|
-
status:
|
|
54
|
+
status:
|
|
55
|
+
(typeof item?.status === 'object'
|
|
56
|
+
? item?.status?.status || item?.status?.name
|
|
57
|
+
: item?.status) || 'Pendente',
|
|
58
|
+
statusIri: resolveStatusIri(item?.status),
|
|
31
59
|
type: item?.type || 'Nenhum',
|
|
32
60
|
channel,
|
|
33
|
-
|
|
34
|
-
provider: channel === CHANNEL_WHATSAPP_OFFICIAL ? CHANNEL_WHATSAPP_OFFICIAL : CHANNEL_WHATSAPP,
|
|
61
|
+
provider: channel,
|
|
35
62
|
phone: item?.phone || {},
|
|
36
63
|
phoneLabel: formatPhoneLabel(item?.phone),
|
|
37
|
-
channelConfig: item?.channelConfig || item?.channel_config || null,
|
|
38
64
|
};
|
|
39
65
|
};
|
|
40
66
|
|
|
@@ -48,10 +74,18 @@ export const toArray = response => {
|
|
|
48
74
|
export const formatApiError = error => {
|
|
49
75
|
if (!error) return 'Nao foi possivel concluir a operacao.';
|
|
50
76
|
if (typeof error === 'string') return error;
|
|
77
|
+
const violations = error?.violations || error?.data?.violations;
|
|
78
|
+
if (Array.isArray(violations) && violations.length) {
|
|
79
|
+
return violations
|
|
80
|
+
.map(v => v?.message || v?.propertyPath)
|
|
81
|
+
.filter(Boolean)
|
|
82
|
+
.join(' · ');
|
|
83
|
+
}
|
|
51
84
|
return (
|
|
52
85
|
error?.message ||
|
|
53
86
|
error?.description ||
|
|
54
87
|
error?.errmsg ||
|
|
88
|
+
error?.hydra?.description ||
|
|
55
89
|
'Nao foi possivel concluir a operacao.'
|
|
56
90
|
);
|
|
57
91
|
};
|
|
@@ -69,9 +103,3 @@ export const buildOfficialChannelConfig = ({
|
|
|
69
103
|
if (version) config.api_version = version;
|
|
70
104
|
return config;
|
|
71
105
|
};
|
|
72
|
-
|
|
73
|
-
export const maskToken = token => {
|
|
74
|
-
const value = String(token || '');
|
|
75
|
-
if (value.length <= 8) return value ? '••••••••' : '';
|
|
76
|
-
return `${value.slice(0, 4)}…${value.slice(-4)}`;
|
|
77
|
-
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {isPublicRoute, PUBLIC_ROUTES} from '../publicRoutes'
|
|
2
|
+
|
|
3
|
+
describe('publicRoutes', () => {
|
|
4
|
+
it('treats MCP OAuth consent as public (ManagerLayout gate)', () => {
|
|
5
|
+
expect(PUBLIC_ROUTES.has('McpOAuthConsentPage')).toBe(true)
|
|
6
|
+
expect(isPublicRoute('McpOAuthConsentPage')).toBe(true)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('keeps SignIn public', () => {
|
|
10
|
+
expect(isPublicRoute('SignInPage')).toBe(true)
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Which clients a user may pick when creating proposals/contracts.
|
|
2
|
+
// Mirrors the backend contract security filter (ContractService::securityFilter):
|
|
3
|
+
// owners/managers of the company see every client; a seller only sees the
|
|
4
|
+
// clients of his own portfolio (PeopleLink linkType "sellers-client", whose
|
|
5
|
+
// company is the seller). Offering other clients would create a document the
|
|
6
|
+
// seller cannot open afterwards.
|
|
7
|
+
|
|
8
|
+
const MANAGEMENT_PERMISSIONS = ['owner', 'manager'];
|
|
9
|
+
|
|
10
|
+
const normalizeEntityId = value => String(value ?? '').replace(/\D/g, '');
|
|
11
|
+
|
|
12
|
+
const normalizePermissions = permissions =>
|
|
13
|
+
(Array.isArray(permissions) ? permissions : [permissions])
|
|
14
|
+
.map(permission => String(permission || '').trim().toLowerCase())
|
|
15
|
+
.filter(Boolean);
|
|
16
|
+
|
|
17
|
+
const resolveClientPortfolioParams = ({ currentCompanyId, permissions, sellerPeopleId } = {}) => {
|
|
18
|
+
const companyId = normalizeEntityId(currentCompanyId);
|
|
19
|
+
if (!companyId) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const normalized = normalizePermissions(permissions);
|
|
24
|
+
const manages = normalized.some(permission => MANAGEMENT_PERMISSIONS.includes(permission));
|
|
25
|
+
const sellerId = normalizeEntityId(sellerPeopleId);
|
|
26
|
+
|
|
27
|
+
if (!manages && normalized.includes('salesman') && sellerId) {
|
|
28
|
+
return {
|
|
29
|
+
'link.company': `/people/${sellerId}`,
|
|
30
|
+
'link.linkType': 'sellers-client',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
'link.company': `/people/${companyId}`,
|
|
36
|
+
'link.linkType': 'client',
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
resolveClientPortfolioParams,
|
|
42
|
+
};
|
|
@@ -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,61 @@
|
|
|
1
|
+
// File.content comes base64 encoded from the API (File::getContent()). Contract
|
|
2
|
+
// and proposal documents are generated from Twig models (HTML or plain text;
|
|
3
|
+
// plain text must be rendered as native text, not through RenderHTML),
|
|
4
|
+
// while signed documents may be PDFs. Decode before deciding how to render.
|
|
5
|
+
|
|
6
|
+
const BASE64_PATTERN = /^[A-Za-z0-9+/=\r\n]+$/;
|
|
7
|
+
|
|
8
|
+
const decodeBase64Binary = value => {
|
|
9
|
+
if (typeof globalThis.atob === 'function') {
|
|
10
|
+
return globalThis.atob(value);
|
|
11
|
+
}
|
|
12
|
+
if (typeof Buffer !== 'undefined') {
|
|
13
|
+
return Buffer.from(value, 'base64').toString('binary');
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const binaryToUtf8 = binary =>
|
|
19
|
+
decodeURIComponent(
|
|
20
|
+
Array.from(binary)
|
|
21
|
+
.map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`)
|
|
22
|
+
.join(''),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const looksLikeHtml = value => String(value || '').trim().startsWith('<');
|
|
26
|
+
|
|
27
|
+
const resolveDocumentFileContent = content => {
|
|
28
|
+
const raw = String(content || '');
|
|
29
|
+
if (!raw.trim()) {
|
|
30
|
+
return { kind: 'empty', content: '' };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (looksLikeHtml(raw)) {
|
|
34
|
+
return { kind: 'html', content: raw };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const compact = raw.trim();
|
|
38
|
+
if (BASE64_PATTERN.test(compact)) {
|
|
39
|
+
const binary = decodeBase64Binary(compact.replace(/[\r\n]/g, ''));
|
|
40
|
+
if (binary !== null) {
|
|
41
|
+
if (binary.startsWith('%PDF')) {
|
|
42
|
+
return { kind: 'pdf', content: compact };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const decoded = binaryToUtf8(binary);
|
|
46
|
+
return looksLikeHtml(decoded)
|
|
47
|
+
? { kind: 'html', content: decoded }
|
|
48
|
+
: { kind: 'text', content: decoded };
|
|
49
|
+
} catch {
|
|
50
|
+
// Not UTF-8 text: keep the binary payload for a viewer.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { kind: 'pdf', content: compact };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { kind: 'text', content: raw };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
resolveDocumentFileContent,
|
|
61
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {env as APP_ENV} from '@env';
|
|
2
2
|
import {filterApiHeaders, isTrustedApiUrl} from '../../utils/trustedApiUrl';
|
|
3
|
-
import {buildAssetUrl} from '@controleonline
|
|
3
|
+
import {buildAssetUrl} from '@controleonline/ui-layout/src/styles/branding';
|
|
4
4
|
import {
|
|
5
5
|
resolveAppDomain,
|
|
6
6
|
resolveCompanyDomain,
|
|
@@ -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
|
+
// Summary shown in proposal/contract headers: only top-level lines count;
|
|
2
|
+
// component/addition rows are already priced inside their parent line.
|
|
3
|
+
|
|
4
|
+
const isTopLevelOrderProduct = item => !item?.orderProduct && !item?.parentProduct;
|
|
5
|
+
|
|
6
|
+
const summarizeOrderProducts = items => {
|
|
7
|
+
const lines = (Array.isArray(items) ? items : []).filter(isTopLevelOrderProduct);
|
|
8
|
+
const total = lines.reduce((sum, item) => {
|
|
9
|
+
const lineTotal = Number(item?.total);
|
|
10
|
+
if (Number.isFinite(lineTotal)) {
|
|
11
|
+
return sum + lineTotal;
|
|
12
|
+
}
|
|
13
|
+
return sum + Number(item?.price || 0) * Number(item?.quantity || 0);
|
|
14
|
+
}, 0);
|
|
15
|
+
|
|
16
|
+
return { count: lines.length, total: Math.round(total * 100) / 100 };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const formatBRL = value =>
|
|
20
|
+
`R$ ${Number(value || 0)
|
|
21
|
+
.toFixed(2)
|
|
22
|
+
.replace('.', ',')
|
|
23
|
+
.replace(/\B(?=(\d{3})+(?!\d))/g, '.')}`;
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
formatBRL,
|
|
27
|
+
summarizeOrderProducts,
|
|
28
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveClientPortfolioParams } from '@controleonline/ui-common/src/react/utils/clientPortfolioParams';
|
|
2
|
+
|
|
1
3
|
const normalizeText = value => String(value || '').trim();
|
|
2
4
|
|
|
3
5
|
const normalizeEntityId = value => String(value || '').replace(/\D/g, '');
|
|
@@ -24,16 +26,9 @@ export const getPeopleDisplayName = person => {
|
|
|
24
26
|
return responsibleLabel || companyLabel;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
'link.company': `/people/${ownerId}`,
|
|
37
|
-
'link.linkType': 'client',
|
|
38
|
-
};
|
|
39
|
-
};
|
|
29
|
+
// Sellers only get their own portfolio; see clientPortfolioParams.js.
|
|
30
|
+
export const buildOwnedClientsParams = ({
|
|
31
|
+
currentCompanyId,
|
|
32
|
+
permissions,
|
|
33
|
+
sellerPeopleId,
|
|
34
|
+
}) => resolveClientPortfolioParams({ currentCompanyId, permissions, sellerPeopleId });
|
|
@@ -4,19 +4,18 @@ import * as types from "@controleonline/ui-default/src/store/default/mutation_ty
|
|
|
4
4
|
export const createWhatsappConnection = ({ commit, getters }, params = {}) => {
|
|
5
5
|
commit(types.SET_ISLOADING, true);
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const options = {
|
|
8
8
|
method: "POST",
|
|
9
9
|
body: params,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
return api
|
|
13
|
-
.fetch("/whatsapp/create-session"
|
|
14
|
-
.then(
|
|
13
|
+
.fetch("/whatsapp/create-session", options)
|
|
14
|
+
.then(data => {
|
|
15
15
|
commit(types.SET_ITEM, data);
|
|
16
|
-
|
|
17
16
|
return data;
|
|
18
17
|
})
|
|
19
|
-
.catch(
|
|
18
|
+
.catch(e => {
|
|
20
19
|
commit(types.SET_ERROR, e.message);
|
|
21
20
|
throw e;
|
|
22
21
|
})
|
|
@@ -26,34 +25,37 @@ export const createWhatsappConnection = ({ commit, getters }, params = {}) => {
|
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
* Persist
|
|
30
|
-
*
|
|
28
|
+
* Persist official Meta Cloud API WhatsApp connection.
|
|
29
|
+
* channel=whatsapp_official + channelConfig JSON (write-only on API).
|
|
31
30
|
*/
|
|
32
|
-
export const saveOfficialWhatsappConnection = ({ commit
|
|
31
|
+
export const saveOfficialWhatsappConnection = ({ commit }, params = {}) => {
|
|
33
32
|
commit(types.SET_ISLOADING, true);
|
|
34
33
|
|
|
35
34
|
const body = {
|
|
36
|
-
name: params.name || `
|
|
37
|
-
channel:
|
|
38
|
-
type: params.type ||
|
|
35
|
+
name: params.name || `WA Oficial ${params.phoneNumberId || ""}`.trim().slice(0, 50),
|
|
36
|
+
channel: "whatsapp_official",
|
|
37
|
+
type: params.type || "relationship",
|
|
39
38
|
people: params.people,
|
|
40
39
|
channelConfig: JSON.stringify({
|
|
41
40
|
access_token: params.accessToken,
|
|
42
41
|
phone_number_id: params.phoneNumberId,
|
|
43
|
-
api_version: params.apiVersion ||
|
|
42
|
+
api_version: params.apiVersion || "v22.0",
|
|
44
43
|
}),
|
|
45
44
|
};
|
|
46
45
|
|
|
46
|
+
if (params.status) {
|
|
47
|
+
body.status = params.status;
|
|
48
|
+
}
|
|
47
49
|
if (params.phone) {
|
|
48
50
|
body.phone = params.phone;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
const options = {
|
|
52
|
-
method: params.id ?
|
|
54
|
+
method: params.id ? "PUT" : "POST",
|
|
53
55
|
body,
|
|
54
56
|
};
|
|
55
57
|
|
|
56
|
-
const endpoint = params.id ? `/connections/${params.id}` :
|
|
58
|
+
const endpoint = params.id ? `/connections/${params.id}` : "/connections";
|
|
57
59
|
|
|
58
60
|
return api
|
|
59
61
|
.fetch(endpoint, options)
|
|
@@ -1,101 +1,105 @@
|
|
|
1
|
-
import * as actions from "@controleonline/ui-default/src/store/default/actions";
|
|
2
|
-
import * as getters from "@controleonline/ui-default/src/store/default/getters";
|
|
3
|
-
import mutations from "@controleonline/ui-default/src/store/default/mutations";
|
|
4
|
-
import * as customActions from "./customActions";
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
namespaced: true,
|
|
8
|
-
state: {
|
|
9
|
-
item: {},
|
|
10
|
-
items: [],
|
|
11
|
-
resourceEndpoint: "connections",
|
|
12
|
-
isLoading: false,
|
|
13
|
-
reload: false,
|
|
14
|
-
error: "",
|
|
15
|
-
totalItems: 0,
|
|
16
|
-
summary: {},
|
|
17
|
-
messages: [],
|
|
18
|
-
message: {},
|
|
19
|
-
filters: {},
|
|
20
|
-
columns: [
|
|
21
|
-
{
|
|
22
|
-
editable: false,
|
|
23
|
-
isIdentity: true,
|
|
24
|
-
sortable: true,
|
|
25
|
-
name: "id",
|
|
26
|
-
align: "left",
|
|
27
|
-
label: "id",
|
|
28
|
-
sum: false,
|
|
29
|
-
format: function (value) {
|
|
30
|
-
return "#" + value;
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
externalFilter: false,
|
|
35
|
-
sortable: true,
|
|
36
|
-
name: "name",
|
|
37
|
-
align: "left",
|
|
38
|
-
label: "name",
|
|
39
|
-
format: function (value) {
|
|
40
|
-
return value;
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
externalFilter: false,
|
|
45
|
-
sortable: true,
|
|
46
|
-
editable: false,
|
|
47
|
-
name: "phone",
|
|
48
|
-
align: "left",
|
|
49
|
-
label: "phone",
|
|
50
|
-
format: function (value, row, column) {
|
|
51
|
-
const phone = String(value.phone);
|
|
52
|
-
const lastFour = phone.slice(-4);
|
|
53
|
-
const firstPart = phone.slice(0, -4);
|
|
54
|
-
return `(${value?.ddd}) ${firstPart}-${lastFour}`;
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
|
|
1
|
+
import * as actions from "@controleonline/ui-default/src/store/default/actions";
|
|
2
|
+
import * as getters from "@controleonline/ui-default/src/store/default/getters";
|
|
3
|
+
import mutations from "@controleonline/ui-default/src/store/default/mutations";
|
|
4
|
+
import * as customActions from "./customActions";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
namespaced: true,
|
|
8
|
+
state: {
|
|
9
|
+
item: {},
|
|
10
|
+
items: [],
|
|
11
|
+
resourceEndpoint: "connections",
|
|
12
|
+
isLoading: false,
|
|
13
|
+
reload: false,
|
|
14
|
+
error: "",
|
|
15
|
+
totalItems: 0,
|
|
16
|
+
summary: {},
|
|
17
|
+
messages: [],
|
|
18
|
+
message: {},
|
|
19
|
+
filters: {},
|
|
20
|
+
columns: [
|
|
21
|
+
{
|
|
22
|
+
editable: false,
|
|
23
|
+
isIdentity: true,
|
|
24
|
+
sortable: true,
|
|
25
|
+
name: "id",
|
|
26
|
+
align: "left",
|
|
27
|
+
label: "id",
|
|
28
|
+
sum: false,
|
|
29
|
+
format: function (value) {
|
|
30
|
+
return "#" + value;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
externalFilter: false,
|
|
35
|
+
sortable: true,
|
|
36
|
+
name: "name",
|
|
37
|
+
align: "left",
|
|
38
|
+
label: "name",
|
|
39
|
+
format: function (value) {
|
|
40
|
+
return value;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
externalFilter: false,
|
|
45
|
+
sortable: true,
|
|
46
|
+
editable: false,
|
|
47
|
+
name: "phone",
|
|
48
|
+
align: "left",
|
|
49
|
+
label: "phone",
|
|
50
|
+
format: function (value, row, column) {
|
|
51
|
+
const phone = String(value.phone);
|
|
52
|
+
const lastFour = phone.slice(-4);
|
|
53
|
+
const firstPart = phone.slice(0, -4);
|
|
54
|
+
return `(${value?.ddd}) ${firstPart}-${lastFour}`;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
58
|
{
|
|
59
59
|
externalFilter: false,
|
|
60
60
|
sortable: true,
|
|
61
61
|
name: "type",
|
|
62
62
|
align: "left",
|
|
63
63
|
label: "type",
|
|
64
|
-
list: [
|
|
65
|
-
{
|
|
66
|
-
value: "crm",
|
|
67
|
-
label: "CRM",
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
value: "support",
|
|
71
|
-
label: "Suporte",
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
value: null,
|
|
75
|
-
label: "Nenhum",
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
format: function (value) {
|
|
79
|
-
return value;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
|
|
64
|
+
list: [
|
|
65
|
+
{
|
|
66
|
+
value: "crm",
|
|
67
|
+
label: "CRM",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
value: "support",
|
|
71
|
+
label: "Suporte",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
value: null,
|
|
75
|
+
label: "Nenhum",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
format: function (value) {
|
|
79
|
+
return value;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
|
|
83
83
|
{
|
|
84
84
|
sortable: true,
|
|
85
85
|
editable: false,
|
|
86
86
|
name: "channel",
|
|
87
87
|
align: "left",
|
|
88
88
|
label: "channel",
|
|
89
|
-
list: [
|
|
90
|
-
{
|
|
91
|
-
value: "whatsapp",
|
|
92
|
-
label: "
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
list: [
|
|
90
|
+
{
|
|
91
|
+
value: "whatsapp",
|
|
92
|
+
label: "WhatsApp",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
value: "whatsapp_official",
|
|
96
|
+
label: "WhatsApp Oficial",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
format: function (value) {
|
|
100
|
+
return value;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
99
103
|
{
|
|
100
104
|
editable: false,
|
|
101
105
|
externalFilter: false,
|
|
@@ -103,22 +107,22 @@ export default {
|
|
|
103
107
|
name: "status",
|
|
104
108
|
align: "left",
|
|
105
109
|
label: "status",
|
|
106
|
-
list: "status/getItems",
|
|
107
|
-
searchParam: "status",
|
|
108
|
-
format: function (value) {
|
|
109
|
-
return value?.status;
|
|
110
|
-
},
|
|
111
|
-
saveFormat: function (value) {
|
|
112
|
-
return value ? "/statuses/" + (value.value || value) : null;
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
name: "connection",
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
print: [],
|
|
120
|
-
},
|
|
121
|
-
actions: { ...actions, ...customActions },
|
|
122
|
-
getters,
|
|
123
|
-
mutations,
|
|
124
|
-
};
|
|
110
|
+
list: "status/getItems",
|
|
111
|
+
searchParam: "status",
|
|
112
|
+
format: function (value) {
|
|
113
|
+
return value?.status;
|
|
114
|
+
},
|
|
115
|
+
saveFormat: function (value) {
|
|
116
|
+
return value ? "/statuses/" + (value.value || value) : null;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "connection",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
print: [],
|
|
124
|
+
},
|
|
125
|
+
actions: { ...actions, ...customActions },
|
|
126
|
+
getters,
|
|
127
|
+
mutations,
|
|
128
|
+
};
|