@controleonline/ui-common 1.2.133 → 1.2.134
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 +5 -6
- package/package.json +2 -6
- package/src/react/components/LinkedOrderProductsTab.js +8 -17
- package/src/react/components/LinkedOrderProductsTab.styles.js +0 -15
- package/src/react/pages/WhatsAppConnectionPage.js +51 -0
- package/src/react/pages/WhatsAppProviderForm.js +38 -0
- package/src/react/pages/whatsAppEmbeddedSignup.js +133 -0
- package/src/react/utils/commercialDocumentOrders.js +20 -13
- package/src/react/utils/peopleDisplay.js +13 -8
- package/src/store/connections/customActions.js +35 -0
- package/src/react/components/documentDetails/DocumentDetailsShell.js +0 -147
- package/src/react/components/documentDetails/DocumentDetailsShell.styles.js +0 -163
- package/src/react/components/documentDetails/DocumentSheet.js +0 -87
- package/src/react/hooks/useLinkedOrderSummary.js +0 -41
- package/src/react/utils/clientPortfolioParams.js +0 -42
- package/src/react/utils/documentFileContent.js +0 -61
- package/src/react/utils/linkedOrderPayload.js +0 -43
- package/src/react/utils/orderProductsSummary.js +0 -28
- package/src/tests/react/utils/clientPortfolioParams.test.js +0 -30
- package/src/tests/react/utils/documentFileContent.test.js +0 -29
- package/src/tests/react/utils/linkedOrderPayload.test.js +0 -46
- package/src/tests/react/utils/orderProductsSummary.test.js +0 -24
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.131",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
6
|
-
"baseTag": "v1.2.132",
|
|
4
|
+
"branch": "rc/1.2.131-rc.1",
|
|
5
|
+
"baseMaster": "3aeaced0835b88b82621be16259985080203eee1",
|
|
7
6
|
"tasks": [
|
|
8
|
-
|
|
7
|
+
159
|
|
9
8
|
],
|
|
10
9
|
"frozen": true,
|
|
11
10
|
"repositories": {
|
|
12
|
-
"ControleOnline/ui-common": "
|
|
11
|
+
"ControleOnline/ui-common": "96efe92a8b5fd573c7688b21713f75fe7a0b57c2"
|
|
13
12
|
}
|
|
14
13
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@controleonline/ui-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.134",
|
|
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",
|
|
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:order-products-summary": "node --test src/tests/react/utils/orderProductsSummary.test.js",
|
|
15
|
-
"test:client-portfolio": "node --test src/tests/react/utils/clientPortfolioParams.test.js",
|
|
16
|
-
"test:document-file-content": "node --test src/tests/react/utils/documentFileContent.test.js",
|
|
17
13
|
"test:runtime-language": "node --test src/tests/react/utils/runtimeLanguage.test.js",
|
|
18
14
|
"test:runtime-footer": "node --test src/tests/react/utils/runtimeFooter.test.js src/tests/react/utils/runtimeFooterText.test.js",
|
|
19
15
|
"test:invoice-presentation": "node --test src/tests/react/utils/invoicePresentation.test.mjs",
|
|
@@ -62,10 +62,6 @@ 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,
|
|
67
|
-
// Rendered inside a sheet that already has its own title.
|
|
68
|
-
embedded = false,
|
|
69
65
|
}) => {
|
|
70
66
|
const peopleStore = useStore('people');
|
|
71
67
|
const { currentCompany } = peopleStore.getters;
|
|
@@ -86,9 +82,6 @@ const LinkedOrderProductsTab = ({
|
|
|
86
82
|
);
|
|
87
83
|
|
|
88
84
|
const canEditProducts = !!canEdit && !!contract?.['@id'] && (!order || isOpenCommercialOrder(order));
|
|
89
|
-
// The backend only accepts products linked to the contract model category
|
|
90
|
-
// (ProposalProductCategoryGuard), so the search must use the same filter.
|
|
91
|
-
const modelCategoryId = normalizeEntityId(contract?.contractModel?.category);
|
|
92
85
|
|
|
93
86
|
const loadLinkedOrderProducts = useCallback(async () => {
|
|
94
87
|
if (!contract?.['@id']) {
|
|
@@ -135,7 +128,6 @@ const LinkedOrderProductsTab = ({
|
|
|
135
128
|
const results = await searchCompanyProducts({
|
|
136
129
|
companyId: currentCompany.id,
|
|
137
130
|
query: trimmedQuery,
|
|
138
|
-
categoryId: modelCategoryId,
|
|
139
131
|
});
|
|
140
132
|
|
|
141
133
|
if (!cancelled) {
|
|
@@ -156,7 +148,7 @@ const LinkedOrderProductsTab = ({
|
|
|
156
148
|
cancelled = true;
|
|
157
149
|
clearTimeout(timeoutId);
|
|
158
150
|
};
|
|
159
|
-
}, [canEditProducts, currentCompany?.id,
|
|
151
|
+
}, [canEditProducts, currentCompany?.id, searchQuery]);
|
|
160
152
|
|
|
161
153
|
const ensureCurrentOrder = useCallback(async () => {
|
|
162
154
|
if (order) {
|
|
@@ -169,6 +161,7 @@ const LinkedOrderProductsTab = ({
|
|
|
169
161
|
client: contract?.client,
|
|
170
162
|
payer: contract?.client,
|
|
171
163
|
app: 'CRM',
|
|
164
|
+
orderType: 'sale',
|
|
172
165
|
});
|
|
173
166
|
|
|
174
167
|
setOrder(createdOrder);
|
|
@@ -195,13 +188,12 @@ const LinkedOrderProductsTab = ({
|
|
|
195
188
|
setSearchQuery('');
|
|
196
189
|
setSearchResults([]);
|
|
197
190
|
await loadLinkedOrderProducts();
|
|
198
|
-
await onProductsChanged?.();
|
|
199
191
|
} catch (error) {
|
|
200
192
|
showError?.(formatApiError(error));
|
|
201
193
|
} finally {
|
|
202
194
|
setAddingProductId(null);
|
|
203
195
|
}
|
|
204
|
-
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts,
|
|
196
|
+
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, showError]);
|
|
205
197
|
|
|
206
198
|
const handleChangeQuantity = useCallback(async (orderProduct, nextQuantity) => {
|
|
207
199
|
if (updatingOrderProductId) {
|
|
@@ -225,13 +217,12 @@ const LinkedOrderProductsTab = ({
|
|
|
225
217
|
}
|
|
226
218
|
|
|
227
219
|
await loadLinkedOrderProducts();
|
|
228
|
-
await onProductsChanged?.();
|
|
229
220
|
} catch (error) {
|
|
230
221
|
showError?.(formatApiError(error));
|
|
231
222
|
} finally {
|
|
232
223
|
setUpdatingOrderProductId(null);
|
|
233
224
|
}
|
|
234
|
-
}, [loadLinkedOrderProducts,
|
|
225
|
+
}, [loadLinkedOrderProducts, showError, updatingOrderProductId]);
|
|
235
226
|
|
|
236
227
|
const visibleSearchResults = useMemo(() => {
|
|
237
228
|
const existingProductIds = new Set(
|
|
@@ -248,11 +239,11 @@ const LinkedOrderProductsTab = ({
|
|
|
248
239
|
return (
|
|
249
240
|
<ScrollView
|
|
250
241
|
style={styles.container}
|
|
251
|
-
contentContainerStyle={
|
|
242
|
+
contentContainerStyle={styles.content}
|
|
252
243
|
keyboardShouldPersistTaps="handled">
|
|
253
|
-
<View style={
|
|
254
|
-
<View style={
|
|
255
|
-
<View
|
|
244
|
+
<View style={styles.section}>
|
|
245
|
+
<View style={styles.headerRow}>
|
|
246
|
+
<View>
|
|
256
247
|
<Text style={styles.title}>Produtos</Text>
|
|
257
248
|
<Text style={styles.subtitle}>
|
|
258
249
|
{orderId
|
|
@@ -8,21 +8,6 @@ const styles = StyleSheet.create({
|
|
|
8
8
|
padding: 16,
|
|
9
9
|
paddingBottom: 36,
|
|
10
10
|
},
|
|
11
|
-
contentEmbedded: {
|
|
12
|
-
paddingHorizontal: 20,
|
|
13
|
-
paddingTop: 12,
|
|
14
|
-
paddingBottom: 24,
|
|
15
|
-
},
|
|
16
|
-
sectionEmbedded: {
|
|
17
|
-
backgroundColor: 'transparent',
|
|
18
|
-
},
|
|
19
|
-
headerRowEmbedded: {
|
|
20
|
-
marginBottom: 0,
|
|
21
|
-
minHeight: 0,
|
|
22
|
-
},
|
|
23
|
-
hidden: {
|
|
24
|
-
display: 'none',
|
|
25
|
-
},
|
|
26
11
|
section: {
|
|
27
12
|
backgroundColor: '#FFFFFF',
|
|
28
13
|
borderRadius: 14,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
buildOfficialProviderConfig,
|
|
21
21
|
} from './whatsAppConnectionHelpers';
|
|
22
22
|
import WhatsAppProviderForm from './WhatsAppProviderForm';
|
|
23
|
+
import { isEmbeddedSignupSupported, launchEmbeddedSignup } from './whatsAppEmbeddedSignup';
|
|
23
24
|
import {
|
|
24
25
|
resolveThemePalette,
|
|
25
26
|
withOpacity,
|
|
@@ -77,6 +78,7 @@ export default function WhatsAppConnectionPage() {
|
|
|
77
78
|
const [qrValue, setQrValue] = useState('');
|
|
78
79
|
const [connectionStatus, setConnectionStatus] = useState('');
|
|
79
80
|
const [lastRequestedPhone, setLastRequestedPhone] = useState('');
|
|
81
|
+
const [embeddedSignupConfig, setEmbeddedSignupConfig] = useState(null);
|
|
80
82
|
|
|
81
83
|
const pollingRef = useRef(null);
|
|
82
84
|
const providerId = currentCompany?.id;
|
|
@@ -207,6 +209,53 @@ export default function WhatsAppConnectionPage() {
|
|
|
207
209
|
}
|
|
208
210
|
}, [accessToken, phoneNumberId, apiVersion, connectionType, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
|
|
209
211
|
|
|
212
|
+
// Meta Embedded Signup only runs in the browser (Facebook JS SDK popup).
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (Platform.OS !== 'web' || !isEmbeddedSignupSupported()) return;
|
|
215
|
+
let active = true;
|
|
216
|
+
Promise.resolve(connectionsActions.getWhatsappEmbeddedSignupConfig())
|
|
217
|
+
.then(config => {
|
|
218
|
+
if (active && config?.app_id && config?.config_id) setEmbeddedSignupConfig(config);
|
|
219
|
+
})
|
|
220
|
+
.catch(() => {});
|
|
221
|
+
return () => {
|
|
222
|
+
active = false;
|
|
223
|
+
};
|
|
224
|
+
}, [connectionsActions]);
|
|
225
|
+
|
|
226
|
+
const handleEmbeddedSignup = useCallback(async coexistence => {
|
|
227
|
+
if (!embeddedSignupConfig) return;
|
|
228
|
+
setSubmitting(true);
|
|
229
|
+
try {
|
|
230
|
+
const session = await launchEmbeddedSignup({
|
|
231
|
+
appId: embeddedSignupConfig.app_id,
|
|
232
|
+
configId: embeddedSignupConfig.config_id,
|
|
233
|
+
graphVersion: embeddedSignupConfig.graph_version,
|
|
234
|
+
coexistence,
|
|
235
|
+
});
|
|
236
|
+
const response = await connectionsActions.completeWhatsappEmbeddedSignup({
|
|
237
|
+
...session,
|
|
238
|
+
coexistence,
|
|
239
|
+
type: connectionType,
|
|
240
|
+
people: peopleIri,
|
|
241
|
+
});
|
|
242
|
+
showSuccess(
|
|
243
|
+
coexistence
|
|
244
|
+
? 'Numero conectado. Ele continua no app do celular e agora tambem recebe pela API.'
|
|
245
|
+
: 'Numero conectado a API oficial do WhatsApp.',
|
|
246
|
+
);
|
|
247
|
+
setConnectionStatus('CONNECTED');
|
|
248
|
+
setQrValue('');
|
|
249
|
+
await loadConnections();
|
|
250
|
+
return response;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
showError(formatApiError(error));
|
|
253
|
+
return null;
|
|
254
|
+
} finally {
|
|
255
|
+
setSubmitting(false);
|
|
256
|
+
}
|
|
257
|
+
}, [embeddedSignupConfig, connectionsActions, connectionType, peopleIri, loadConnections, showError, showSuccess]);
|
|
258
|
+
|
|
210
259
|
const handlePrimaryAction = useCallback(async () => {
|
|
211
260
|
if (providerMode === PROVIDER_OFFICIAL) {
|
|
212
261
|
return saveOfficialConnection();
|
|
@@ -366,6 +415,8 @@ export default function WhatsAppConnectionPage() {
|
|
|
366
415
|
setApiVersion={setApiVersion}
|
|
367
416
|
submitting={submitting}
|
|
368
417
|
onPrimaryAction={() => handlePrimaryAction()}
|
|
418
|
+
embeddedSignupAvailable={!!embeddedSignupConfig}
|
|
419
|
+
onEmbeddedSignup={handleEmbeddedSignup}
|
|
369
420
|
/>
|
|
370
421
|
|
|
371
422
|
<View style={{ flexDirection: 'row', gap: 8, marginTop: 8 }}>
|
|
@@ -17,6 +17,8 @@ export default function WhatsAppProviderForm({
|
|
|
17
17
|
setApiVersion,
|
|
18
18
|
submitting,
|
|
19
19
|
onPrimaryAction,
|
|
20
|
+
embeddedSignupAvailable,
|
|
21
|
+
onEmbeddedSignup,
|
|
20
22
|
}) {
|
|
21
23
|
return (
|
|
22
24
|
<>
|
|
@@ -50,6 +52,42 @@ export default function WhatsAppProviderForm({
|
|
|
50
52
|
</TouchableOpacity>
|
|
51
53
|
</View>
|
|
52
54
|
|
|
55
|
+
{providerMode === PROVIDER_OFFICIAL && embeddedSignupAvailable ? (
|
|
56
|
+
<View style={{ marginBottom: 12 }}>
|
|
57
|
+
<Text style={styles.inputLabel}>Conectar pelo Facebook</Text>
|
|
58
|
+
{[
|
|
59
|
+
[true, 'Numero do app WhatsApp Business', 'smartphone', 'Continua no celular; autorize pelo QR Code no app.'],
|
|
60
|
+
[false, 'Numero novo', 'plus-circle', 'O Meta verifica o numero por SMS ou ligacao.'],
|
|
61
|
+
].map(([coexistence, label, icon, hint]) => (
|
|
62
|
+
<TouchableOpacity
|
|
63
|
+
key={label}
|
|
64
|
+
activeOpacity={0.9}
|
|
65
|
+
disabled={submitting}
|
|
66
|
+
onPress={() => onEmbeddedSignup(coexistence)}
|
|
67
|
+
style={{
|
|
68
|
+
flexDirection: 'row',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
gap: 10,
|
|
71
|
+
borderWidth: 1,
|
|
72
|
+
borderColor: withOpacity('#1877F2', 0.35),
|
|
73
|
+
backgroundColor: withOpacity('#1877F2', 0.06),
|
|
74
|
+
borderRadius: 12,
|
|
75
|
+
padding: 12,
|
|
76
|
+
marginTop: 8,
|
|
77
|
+
opacity: submitting ? 0.6 : 1,
|
|
78
|
+
}}>
|
|
79
|
+
<Icon name={icon} size={18} color="#1877F2" />
|
|
80
|
+
<View style={{ flex: 1 }}>
|
|
81
|
+
<Text style={{ color: '#0F172A', fontWeight: '600' }}>{label}</Text>
|
|
82
|
+
<Text style={{ color: '#64748B', fontSize: 12 }}>{hint}</Text>
|
|
83
|
+
</View>
|
|
84
|
+
<Icon name="chevron-right" size={18} color="#1877F2" />
|
|
85
|
+
</TouchableOpacity>
|
|
86
|
+
))}
|
|
87
|
+
<Text style={[styles.inputLabel, { marginTop: 16 }]}>Ou informe manualmente</Text>
|
|
88
|
+
</View>
|
|
89
|
+
) : null}
|
|
90
|
+
|
|
53
91
|
{providerMode === PROVIDER_OFFICIAL ? (
|
|
54
92
|
<View style={{ marginBottom: 12 }}>
|
|
55
93
|
<Text style={styles.inputLabel}>Access token (Meta)</Text>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Meta WhatsApp Embedded Signup (web only): opens the Facebook login popup with the
|
|
2
|
+
// Embedded Signup configuration and resolves with the code + WABA / phone number ids.
|
|
3
|
+
// The code is exchanged for the token by the API (POST /whatsapp/embedded-signup).
|
|
4
|
+
|
|
5
|
+
const SDK_ID = 'facebook-jssdk';
|
|
6
|
+
const SIGNUP_EVENT = 'WA_EMBEDDED_SIGNUP';
|
|
7
|
+
|
|
8
|
+
let sdkPromise = null;
|
|
9
|
+
|
|
10
|
+
// Only messages posted by the Facebook popup itself (exact host or a facebook.com subdomain).
|
|
11
|
+
const isFacebookOrigin = origin => {
|
|
12
|
+
try {
|
|
13
|
+
const { protocol, hostname } = new URL(origin);
|
|
14
|
+
return protocol === 'https:' && (hostname === 'facebook.com' || hostname.endsWith('.facebook.com'));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isEmbeddedSignupSupported = () =>
|
|
21
|
+
typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
22
|
+
|
|
23
|
+
const loadFacebookSdk = ({ appId, graphVersion }) => {
|
|
24
|
+
if (window.FB) {
|
|
25
|
+
window.FB.init({ appId, autoLogAppEvents: true, xfbml: false, version: graphVersion });
|
|
26
|
+
return Promise.resolve(window.FB);
|
|
27
|
+
}
|
|
28
|
+
if (sdkPromise) return sdkPromise;
|
|
29
|
+
|
|
30
|
+
sdkPromise = new Promise((resolve, reject) => {
|
|
31
|
+
window.fbAsyncInit = () => {
|
|
32
|
+
window.FB.init({ appId, autoLogAppEvents: true, xfbml: false, version: graphVersion });
|
|
33
|
+
resolve(window.FB);
|
|
34
|
+
};
|
|
35
|
+
const script = document.createElement('script');
|
|
36
|
+
script.id = SDK_ID;
|
|
37
|
+
script.async = true;
|
|
38
|
+
script.defer = true;
|
|
39
|
+
script.crossOrigin = 'anonymous';
|
|
40
|
+
script.src = 'https://connect.facebook.net/pt_BR/sdk.js';
|
|
41
|
+
script.onerror = () => {
|
|
42
|
+
sdkPromise = null;
|
|
43
|
+
reject(new Error('Nao foi possivel carregar o SDK do Facebook.'));
|
|
44
|
+
};
|
|
45
|
+
document.body.appendChild(script);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return sdkPromise;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {{appId: string, configId: string, graphVersion: string, coexistence: boolean}} options
|
|
53
|
+
* @returns {Promise<{code: string, wabaId: string, phoneNumberId: string}>}
|
|
54
|
+
*/
|
|
55
|
+
export const launchEmbeddedSignup = async ({ appId, configId, graphVersion, coexistence }) => {
|
|
56
|
+
if (!appId || !configId) {
|
|
57
|
+
throw new Error('Cadastro incorporado do Meta nao configurado na API.');
|
|
58
|
+
}
|
|
59
|
+
const FB = await loadFacebookSdk({ appId, graphVersion });
|
|
60
|
+
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const session = {};
|
|
63
|
+
let code = '';
|
|
64
|
+
let settled = false;
|
|
65
|
+
|
|
66
|
+
const finish = (error, value) => {
|
|
67
|
+
if (settled) return;
|
|
68
|
+
settled = true;
|
|
69
|
+
window.removeEventListener('message', onMessage);
|
|
70
|
+
if (error) reject(error);
|
|
71
|
+
else resolve(value);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const tryResolve = () => {
|
|
75
|
+
if (code && session.wabaId && session.phoneNumberId) {
|
|
76
|
+
finish(null, { code, ...session });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Meta posts the selected WABA / number from the popup; the login callback brings the code.
|
|
81
|
+
const onMessage = event => {
|
|
82
|
+
if (!isFacebookOrigin(event.origin)) return;
|
|
83
|
+
let data = event.data;
|
|
84
|
+
try {
|
|
85
|
+
data = typeof data === 'string' ? JSON.parse(data) : data;
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (data?.type !== SIGNUP_EVENT) return;
|
|
90
|
+
|
|
91
|
+
if (String(data.event || '').startsWith('FINISH')) {
|
|
92
|
+
session.wabaId = String(data.data?.waba_id || '');
|
|
93
|
+
session.phoneNumberId = String(data.data?.phone_number_id || '');
|
|
94
|
+
tryResolve();
|
|
95
|
+
} else if (data.event === 'CANCEL') {
|
|
96
|
+
const step = data.data?.current_step ? ` (etapa ${data.data.current_step})` : '';
|
|
97
|
+
finish(new Error(data.data?.error_message || `Conexao cancelada no Facebook${step}.`));
|
|
98
|
+
} else if (data.event === 'ERROR') {
|
|
99
|
+
finish(new Error(data.data?.error_message || 'O Facebook retornou um erro.'));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
window.addEventListener('message', onMessage);
|
|
103
|
+
|
|
104
|
+
const extras = { setup: {}, sessionInfoVersion: '3' };
|
|
105
|
+
if (coexistence) {
|
|
106
|
+
extras.featureType = 'whatsapp_business_app_onboarding';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// FB.login requires a plain (non-async) callback.
|
|
110
|
+
FB.login(
|
|
111
|
+
response => {
|
|
112
|
+
code = response?.authResponse?.code || '';
|
|
113
|
+
if (!code) {
|
|
114
|
+
finish(new Error('Login no Facebook nao concluido.'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
tryResolve();
|
|
118
|
+
// The session message may arrive a little after the callback.
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
if (!settled) {
|
|
121
|
+
finish(new Error('O Facebook nao informou a conta e o numero do WhatsApp. Tente novamente.'));
|
|
122
|
+
}
|
|
123
|
+
}, 15000);
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
config_id: configId,
|
|
127
|
+
response_type: 'code',
|
|
128
|
+
override_default_response_type: true,
|
|
129
|
+
extras,
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
@@ -1,8 +1,4 @@
|
|
|
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';
|
|
6
2
|
|
|
7
3
|
const normalizeStatusKey = value => String(value || '').trim().toLowerCase();
|
|
8
4
|
|
|
@@ -162,19 +158,30 @@ export const createLinkedOrder = async ({
|
|
|
162
158
|
client,
|
|
163
159
|
payer,
|
|
164
160
|
app = 'CRM',
|
|
165
|
-
orderType =
|
|
161
|
+
orderType = 'sale',
|
|
166
162
|
fallbackStatusId = null,
|
|
167
163
|
}) => {
|
|
168
164
|
const status = await resolveOpenOrderStatusIri(fallbackStatusId);
|
|
169
|
-
const payload =
|
|
165
|
+
const payload = {
|
|
170
166
|
app,
|
|
171
167
|
orderType,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
contract: toEntityIri(contractRef, 'contracts'),
|
|
169
|
+
provider: toEntityIri(provider, 'people'),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (status) {
|
|
173
|
+
payload.status = status;
|
|
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
|
+
}
|
|
178
185
|
|
|
179
186
|
return api.fetch('orders', {
|
|
180
187
|
method: 'POST',
|
|
@@ -188,7 +195,7 @@ export const ensureLinkedOrder = async ({
|
|
|
188
195
|
client,
|
|
189
196
|
payer,
|
|
190
197
|
app = 'CRM',
|
|
191
|
-
orderType =
|
|
198
|
+
orderType = 'sale',
|
|
192
199
|
fallbackStatusId = null,
|
|
193
200
|
}) => {
|
|
194
201
|
const existingOrder = await fetchLinkedOrder(contractRef);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { resolveClientPortfolioParams } from '@controleonline/ui-common/src/react/utils/clientPortfolioParams';
|
|
2
|
-
|
|
3
1
|
const normalizeText = value => String(value || '').trim();
|
|
4
2
|
|
|
5
3
|
const normalizeEntityId = value => String(value || '').replace(/\D/g, '');
|
|
@@ -26,9 +24,16 @@ export const getPeopleDisplayName = person => {
|
|
|
26
24
|
return responsibleLabel || companyLabel;
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
export const buildOwnedClientsParams = ({
|
|
28
|
+
currentCompanyId,
|
|
29
|
+
}) => {
|
|
30
|
+
const ownerId = normalizeEntityId(currentCompanyId);
|
|
31
|
+
if (!ownerId) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
'link.company': `/people/${ownerId}`,
|
|
37
|
+
'link.linkType': 'client',
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -109,3 +109,38 @@ export const saveEmailConnection = ({ commit }, params = {}) => {
|
|
|
109
109
|
commit(types.SET_ISLOADING, false);
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Meta Embedded Signup: public data to open the Facebook popup (app id + configuration id).
|
|
115
|
+
*/
|
|
116
|
+
export const getWhatsappEmbeddedSignupConfig = () =>
|
|
117
|
+
api.fetch('/whatsapp/embedded-signup/config', { method: 'GET' });
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Meta Embedded Signup: the API exchanges the code for the token, subscribes the webhook
|
|
121
|
+
* and creates/updates the whatsapp_official connection of the company.
|
|
122
|
+
*/
|
|
123
|
+
export const completeWhatsappEmbeddedSignup = ({ commit }, params = {}) => {
|
|
124
|
+
commit(types.SET_ISLOADING, true);
|
|
125
|
+
|
|
126
|
+
return api
|
|
127
|
+
.fetch('/whatsapp/embedded-signup', {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: {
|
|
130
|
+
people: params.people,
|
|
131
|
+
code: params.code,
|
|
132
|
+
waba_id: params.wabaId,
|
|
133
|
+
phone_number_id: params.phoneNumberId,
|
|
134
|
+
coexistence: !!params.coexistence,
|
|
135
|
+
type: params.type || null,
|
|
136
|
+
connection: params.connection || null,
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
.catch(e => {
|
|
140
|
+
commit(types.SET_ERROR, e.message);
|
|
141
|
+
throw e;
|
|
142
|
+
})
|
|
143
|
+
.finally(() => {
|
|
144
|
+
commit(types.SET_ISLOADING, false);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
ActivityIndicator,
|
|
4
|
-
ScrollView,
|
|
5
|
-
Text,
|
|
6
|
-
TouchableOpacity,
|
|
7
|
-
useWindowDimensions,
|
|
8
|
-
View,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
11
|
-
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
12
|
-
import { createDocumentDetailsStyles, resolveDocumentDetailsTheme } from './DocumentDetailsShell.styles';
|
|
13
|
-
|
|
14
|
-
const WIDE_BREAKPOINT = 768;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Shared layout for proposal/contract details.
|
|
18
|
-
* The header and the action bar stay fixed so the seller always sees who the
|
|
19
|
-
* document is for, its value and the main action, while the document itself
|
|
20
|
-
* gets the rest of the screen. Secondary data (products, signers) open in sheets.
|
|
21
|
-
*/
|
|
22
|
-
const DocumentDetailsShell = ({
|
|
23
|
-
theme,
|
|
24
|
-
title,
|
|
25
|
-
clientName,
|
|
26
|
-
meta,
|
|
27
|
-
totalLabel,
|
|
28
|
-
statusLabel,
|
|
29
|
-
statusColor,
|
|
30
|
-
onBack,
|
|
31
|
-
loading,
|
|
32
|
-
children,
|
|
33
|
-
secondaryActions = [],
|
|
34
|
-
primaryAction,
|
|
35
|
-
footerNote,
|
|
36
|
-
}) => {
|
|
37
|
-
const { width } = useWindowDimensions();
|
|
38
|
-
const isWide = width >= WIDE_BREAKPOINT;
|
|
39
|
-
const colors = resolveDocumentDetailsTheme(theme);
|
|
40
|
-
const styles = createDocumentDetailsStyles(colors, isWide);
|
|
41
|
-
const chipColor = statusColor || colors.muted;
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<SafeAreaView style={styles.container} edges={['top', 'left', 'right']}>
|
|
45
|
-
<View style={styles.header}>
|
|
46
|
-
<View style={styles.headerInner}>
|
|
47
|
-
{onBack ? (
|
|
48
|
-
<TouchableOpacity
|
|
49
|
-
accessibilityRole="button"
|
|
50
|
-
accessibilityLabel="Voltar"
|
|
51
|
-
onPress={onBack}
|
|
52
|
-
style={styles.backButton}>
|
|
53
|
-
<Icon name="arrow-back" size={20} color={colors.text} />
|
|
54
|
-
</TouchableOpacity>
|
|
55
|
-
) : null}
|
|
56
|
-
|
|
57
|
-
<View style={styles.headerText}>
|
|
58
|
-
<View style={styles.titleRow}>
|
|
59
|
-
<Text style={styles.title} numberOfLines={1}>
|
|
60
|
-
{title}
|
|
61
|
-
</Text>
|
|
62
|
-
{statusLabel ? (
|
|
63
|
-
<View style={[styles.statusChip, { borderColor: `${chipColor}55`, backgroundColor: `${chipColor}14` }]}>
|
|
64
|
-
<View style={[styles.statusDot, { backgroundColor: chipColor }]} />
|
|
65
|
-
<Text style={[styles.statusText, { color: chipColor }]} numberOfLines={1}>
|
|
66
|
-
{statusLabel}
|
|
67
|
-
</Text>
|
|
68
|
-
</View>
|
|
69
|
-
) : null}
|
|
70
|
-
</View>
|
|
71
|
-
<Text style={styles.subtitle} numberOfLines={1}>
|
|
72
|
-
{[clientName, meta].filter(Boolean).join(' · ')}
|
|
73
|
-
</Text>
|
|
74
|
-
</View>
|
|
75
|
-
|
|
76
|
-
{totalLabel ? (
|
|
77
|
-
<View style={styles.totalBox}>
|
|
78
|
-
<Text style={styles.totalCaption}>Total</Text>
|
|
79
|
-
<Text style={styles.totalValue} numberOfLines={1}>
|
|
80
|
-
{totalLabel}
|
|
81
|
-
</Text>
|
|
82
|
-
</View>
|
|
83
|
-
) : null}
|
|
84
|
-
</View>
|
|
85
|
-
</View>
|
|
86
|
-
|
|
87
|
-
<ScrollView style={styles.body} contentContainerStyle={styles.bodyContent}>
|
|
88
|
-
<View style={styles.paper}>
|
|
89
|
-
{loading ? (
|
|
90
|
-
<View style={styles.loading}>
|
|
91
|
-
<ActivityIndicator color={colors.primary} />
|
|
92
|
-
</View>
|
|
93
|
-
) : (
|
|
94
|
-
children
|
|
95
|
-
)}
|
|
96
|
-
</View>
|
|
97
|
-
</ScrollView>
|
|
98
|
-
|
|
99
|
-
<View style={styles.footer}>
|
|
100
|
-
<View style={styles.footerInner}>
|
|
101
|
-
<View style={styles.secondaryActions}>
|
|
102
|
-
{secondaryActions.map(action => (
|
|
103
|
-
<TouchableOpacity
|
|
104
|
-
key={action.key}
|
|
105
|
-
accessibilityRole="button"
|
|
106
|
-
accessibilityLabel={action.label}
|
|
107
|
-
onPress={action.onPress}
|
|
108
|
-
style={styles.secondaryButton}>
|
|
109
|
-
<Icon name={action.icon} size={18} color={colors.text} />
|
|
110
|
-
{isWide ? <Text style={styles.secondaryLabel}>{action.label}</Text> : null}
|
|
111
|
-
{Number.isFinite(action.count) ? (
|
|
112
|
-
<View style={styles.countBadge}>
|
|
113
|
-
<Text style={styles.countText}>{action.count}</Text>
|
|
114
|
-
</View>
|
|
115
|
-
) : null}
|
|
116
|
-
</TouchableOpacity>
|
|
117
|
-
))}
|
|
118
|
-
</View>
|
|
119
|
-
|
|
120
|
-
{primaryAction ? (
|
|
121
|
-
<TouchableOpacity
|
|
122
|
-
accessibilityRole="button"
|
|
123
|
-
accessibilityLabel={primaryAction.label}
|
|
124
|
-
disabled={primaryAction.disabled || primaryAction.loading}
|
|
125
|
-
onPress={primaryAction.onPress}
|
|
126
|
-
style={[
|
|
127
|
-
styles.primaryButton,
|
|
128
|
-
(primaryAction.disabled || primaryAction.loading) && styles.primaryButtonDisabled,
|
|
129
|
-
]}>
|
|
130
|
-
{primaryAction.loading ? (
|
|
131
|
-
<ActivityIndicator color={colors.onPrimary} size="small" />
|
|
132
|
-
) : (
|
|
133
|
-
<Icon name={primaryAction.icon || 'check'} size={18} color={colors.onPrimary} />
|
|
134
|
-
)}
|
|
135
|
-
<Text style={styles.primaryLabel} numberOfLines={1}>
|
|
136
|
-
{primaryAction.label}
|
|
137
|
-
</Text>
|
|
138
|
-
</TouchableOpacity>
|
|
139
|
-
) : null}
|
|
140
|
-
</View>
|
|
141
|
-
{footerNote ? <Text style={styles.footerNote}>{footerNote}</Text> : null}
|
|
142
|
-
</View>
|
|
143
|
-
</SafeAreaView>
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export default DocumentDetailsShell;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Platform, StyleSheet } from 'react-native';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_THEME = {
|
|
4
|
-
primary: '#1f6feb',
|
|
5
|
-
onPrimary: '#ffffff',
|
|
6
|
-
background: '#f3f5f8',
|
|
7
|
-
surface: '#ffffff',
|
|
8
|
-
text: '#0f172a',
|
|
9
|
-
muted: '#64748b',
|
|
10
|
-
border: '#e5e9f0',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const resolveDocumentDetailsTheme = theme => ({ ...DEFAULT_THEME, ...(theme || {}) });
|
|
14
|
-
|
|
15
|
-
const softShadow = Platform.select({
|
|
16
|
-
web: { boxShadow: '0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06)' },
|
|
17
|
-
default: {
|
|
18
|
-
shadowColor: '#0f172a',
|
|
19
|
-
shadowOpacity: 0.08,
|
|
20
|
-
shadowRadius: 12,
|
|
21
|
-
shadowOffset: { width: 0, height: 4 },
|
|
22
|
-
elevation: 2,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const MAX_CONTENT_WIDTH = 920;
|
|
27
|
-
|
|
28
|
-
export const createDocumentDetailsStyles = (colors, isWide) =>
|
|
29
|
-
StyleSheet.create({
|
|
30
|
-
container: { flex: 1, backgroundColor: colors.background },
|
|
31
|
-
|
|
32
|
-
header: {
|
|
33
|
-
backgroundColor: colors.surface,
|
|
34
|
-
borderBottomWidth: 1,
|
|
35
|
-
borderBottomColor: colors.border,
|
|
36
|
-
paddingHorizontal: isWide ? 24 : 12,
|
|
37
|
-
paddingVertical: isWide ? 12 : 10,
|
|
38
|
-
},
|
|
39
|
-
headerInner: {
|
|
40
|
-
flexDirection: 'row',
|
|
41
|
-
alignItems: 'center',
|
|
42
|
-
width: '100%',
|
|
43
|
-
maxWidth: MAX_CONTENT_WIDTH,
|
|
44
|
-
alignSelf: 'center',
|
|
45
|
-
},
|
|
46
|
-
backButton: {
|
|
47
|
-
width: 36,
|
|
48
|
-
height: 36,
|
|
49
|
-
borderRadius: 18,
|
|
50
|
-
alignItems: 'center',
|
|
51
|
-
justifyContent: 'center',
|
|
52
|
-
backgroundColor: colors.background,
|
|
53
|
-
marginRight: 12,
|
|
54
|
-
},
|
|
55
|
-
headerText: { flex: 1, minWidth: 0 },
|
|
56
|
-
titleRow: { flexDirection: 'row', alignItems: 'center' },
|
|
57
|
-
title: {
|
|
58
|
-
flexShrink: 1,
|
|
59
|
-
fontSize: isWide ? 17 : 15,
|
|
60
|
-
fontWeight: '700',
|
|
61
|
-
color: colors.text,
|
|
62
|
-
letterSpacing: -0.2,
|
|
63
|
-
},
|
|
64
|
-
subtitle: { marginTop: 2, fontSize: 12.5, color: colors.muted },
|
|
65
|
-
statusChip: {
|
|
66
|
-
flexDirection: 'row',
|
|
67
|
-
alignItems: 'center',
|
|
68
|
-
marginLeft: 8,
|
|
69
|
-
paddingHorizontal: 8,
|
|
70
|
-
paddingVertical: 2,
|
|
71
|
-
borderRadius: 999,
|
|
72
|
-
borderWidth: 1,
|
|
73
|
-
},
|
|
74
|
-
statusDot: { width: 6, height: 6, borderRadius: 3, marginRight: 5 },
|
|
75
|
-
statusText: { fontSize: 11.5, fontWeight: '700' },
|
|
76
|
-
totalBox: { marginLeft: 12, alignItems: 'flex-end' },
|
|
77
|
-
totalCaption: {
|
|
78
|
-
fontSize: 10.5,
|
|
79
|
-
fontWeight: '600',
|
|
80
|
-
color: colors.muted,
|
|
81
|
-
textTransform: 'uppercase',
|
|
82
|
-
letterSpacing: 0.6,
|
|
83
|
-
},
|
|
84
|
-
totalValue: { fontSize: isWide ? 18 : 15, fontWeight: '800', color: colors.text },
|
|
85
|
-
|
|
86
|
-
body: { flex: 1 },
|
|
87
|
-
bodyContent: {
|
|
88
|
-
paddingHorizontal: isWide ? 24 : 0,
|
|
89
|
-
paddingVertical: isWide ? 24 : 0,
|
|
90
|
-
paddingBottom: isWide ? 32 : 16,
|
|
91
|
-
},
|
|
92
|
-
paper: {
|
|
93
|
-
width: '100%',
|
|
94
|
-
maxWidth: MAX_CONTENT_WIDTH,
|
|
95
|
-
alignSelf: 'center',
|
|
96
|
-
backgroundColor: colors.surface,
|
|
97
|
-
borderRadius: isWide ? 14 : 0,
|
|
98
|
-
paddingHorizontal: isWide ? 40 : 16,
|
|
99
|
-
paddingVertical: isWide ? 36 : 16,
|
|
100
|
-
minHeight: 240,
|
|
101
|
-
...(isWide ? softShadow : {}),
|
|
102
|
-
},
|
|
103
|
-
loading: { paddingVertical: 48, alignItems: 'center' },
|
|
104
|
-
|
|
105
|
-
footer: {
|
|
106
|
-
backgroundColor: colors.surface,
|
|
107
|
-
borderTopWidth: 1,
|
|
108
|
-
borderTopColor: colors.border,
|
|
109
|
-
paddingHorizontal: isWide ? 24 : 12,
|
|
110
|
-
paddingTop: 10,
|
|
111
|
-
paddingBottom: Platform.OS === 'ios' ? 28 : 10,
|
|
112
|
-
},
|
|
113
|
-
footerInner: {
|
|
114
|
-
flexDirection: 'row',
|
|
115
|
-
alignItems: 'center',
|
|
116
|
-
width: '100%',
|
|
117
|
-
maxWidth: MAX_CONTENT_WIDTH,
|
|
118
|
-
alignSelf: 'center',
|
|
119
|
-
},
|
|
120
|
-
secondaryActions: { flexDirection: 'row', alignItems: 'center', flexShrink: 0 },
|
|
121
|
-
secondaryButton: {
|
|
122
|
-
flexDirection: 'row',
|
|
123
|
-
alignItems: 'center',
|
|
124
|
-
height: 42,
|
|
125
|
-
paddingHorizontal: isWide ? 14 : 12,
|
|
126
|
-
marginRight: 8,
|
|
127
|
-
borderRadius: 10,
|
|
128
|
-
borderWidth: 1,
|
|
129
|
-
borderColor: colors.border,
|
|
130
|
-
backgroundColor: colors.surface,
|
|
131
|
-
},
|
|
132
|
-
secondaryLabel: { marginLeft: 6, fontSize: 14, fontWeight: '600', color: colors.text },
|
|
133
|
-
countBadge: {
|
|
134
|
-
minWidth: 20,
|
|
135
|
-
height: 20,
|
|
136
|
-
paddingHorizontal: 6,
|
|
137
|
-
marginLeft: 6,
|
|
138
|
-
borderRadius: 10,
|
|
139
|
-
alignItems: 'center',
|
|
140
|
-
justifyContent: 'center',
|
|
141
|
-
backgroundColor: colors.background,
|
|
142
|
-
},
|
|
143
|
-
countText: { fontSize: 11.5, fontWeight: '700', color: colors.text },
|
|
144
|
-
primaryButton: {
|
|
145
|
-
flex: 1,
|
|
146
|
-
flexDirection: 'row',
|
|
147
|
-
alignItems: 'center',
|
|
148
|
-
justifyContent: 'center',
|
|
149
|
-
height: 44,
|
|
150
|
-
paddingHorizontal: 18,
|
|
151
|
-
borderRadius: 10,
|
|
152
|
-
backgroundColor: colors.primary,
|
|
153
|
-
...(isWide ? { flex: 0, minWidth: 220, marginLeft: 'auto' } : {}),
|
|
154
|
-
},
|
|
155
|
-
primaryButtonDisabled: { opacity: 0.5 },
|
|
156
|
-
primaryLabel: { marginLeft: 8, fontSize: 15, fontWeight: '700', color: colors.onPrimary },
|
|
157
|
-
footerNote: {
|
|
158
|
-
marginTop: 6,
|
|
159
|
-
fontSize: 12,
|
|
160
|
-
color: colors.muted,
|
|
161
|
-
textAlign: 'center',
|
|
162
|
-
},
|
|
163
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Platform, Pressable, StyleSheet, Text, TouchableOpacity, useWindowDimensions, View } from 'react-native';
|
|
3
|
-
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
4
|
-
import AnimatedModal from '@controleonline/ui-common/src/react/components/AnimatedModal';
|
|
5
|
-
import { resolveDocumentDetailsTheme } from './DocumentDetailsShell.styles';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Bottom sheet (centered panel on wide screens) for secondary document data,
|
|
9
|
-
* such as products and signers, so they don't take space from the document.
|
|
10
|
-
*/
|
|
11
|
-
const DocumentSheet = ({ visible, onClose, title, subtitle, theme, children }) => {
|
|
12
|
-
const { width, height } = useWindowDimensions();
|
|
13
|
-
const isWide = width >= 768;
|
|
14
|
-
const colors = resolveDocumentDetailsTheme(theme);
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<AnimatedModal visible={visible} onRequestClose={onClose}>
|
|
18
|
-
<Pressable style={styles.backdrop} onPress={onClose} accessibilityLabel="Fechar" />
|
|
19
|
-
<View
|
|
20
|
-
style={[
|
|
21
|
-
styles.sheet,
|
|
22
|
-
{
|
|
23
|
-
backgroundColor: colors.surface,
|
|
24
|
-
maxHeight: Math.round(height * (isWide ? 0.8 : 0.86)),
|
|
25
|
-
},
|
|
26
|
-
isWide ? styles.sheetWide : null,
|
|
27
|
-
]}>
|
|
28
|
-
<View style={styles.handleWrap}>
|
|
29
|
-
<View style={[styles.handle, { backgroundColor: colors.border }]} />
|
|
30
|
-
</View>
|
|
31
|
-
<View style={[styles.header, { borderBottomColor: colors.border }]}>
|
|
32
|
-
<View style={styles.headerText}>
|
|
33
|
-
<Text style={[styles.title, { color: colors.text }]} numberOfLines={1}>
|
|
34
|
-
{title}
|
|
35
|
-
</Text>
|
|
36
|
-
{subtitle ? (
|
|
37
|
-
<Text style={[styles.subtitle, { color: colors.muted }]} numberOfLines={1}>
|
|
38
|
-
{subtitle}
|
|
39
|
-
</Text>
|
|
40
|
-
) : null}
|
|
41
|
-
</View>
|
|
42
|
-
<TouchableOpacity
|
|
43
|
-
accessibilityRole="button"
|
|
44
|
-
accessibilityLabel="Fechar"
|
|
45
|
-
onPress={onClose}
|
|
46
|
-
style={[styles.close, { backgroundColor: colors.background }]}>
|
|
47
|
-
<Icon name="close" size={20} color={colors.text} />
|
|
48
|
-
</TouchableOpacity>
|
|
49
|
-
</View>
|
|
50
|
-
<View style={styles.body}>{children}</View>
|
|
51
|
-
</View>
|
|
52
|
-
</AnimatedModal>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const styles = StyleSheet.create({
|
|
57
|
-
backdrop: { flex: 1 },
|
|
58
|
-
sheet: {
|
|
59
|
-
width: '100%',
|
|
60
|
-
borderTopLeftRadius: 18,
|
|
61
|
-
borderTopRightRadius: 18,
|
|
62
|
-
overflow: 'hidden',
|
|
63
|
-
paddingBottom: Platform.OS === 'ios' ? 24 : 8,
|
|
64
|
-
},
|
|
65
|
-
sheetWide: {
|
|
66
|
-
maxWidth: 760,
|
|
67
|
-
alignSelf: 'center',
|
|
68
|
-
borderRadius: 18,
|
|
69
|
-
marginBottom: 32,
|
|
70
|
-
},
|
|
71
|
-
handleWrap: { alignItems: 'center', paddingTop: 8 },
|
|
72
|
-
handle: { width: 40, height: 4, borderRadius: 2 },
|
|
73
|
-
header: {
|
|
74
|
-
flexDirection: 'row',
|
|
75
|
-
alignItems: 'center',
|
|
76
|
-
paddingHorizontal: 20,
|
|
77
|
-
paddingVertical: 12,
|
|
78
|
-
borderBottomWidth: 1,
|
|
79
|
-
},
|
|
80
|
-
headerText: { flex: 1, minWidth: 0 },
|
|
81
|
-
title: { fontSize: 17, fontWeight: '700', letterSpacing: -0.2 },
|
|
82
|
-
subtitle: { fontSize: 12.5, marginTop: 2 },
|
|
83
|
-
close: { width: 34, height: 34, borderRadius: 17, alignItems: 'center', justifyContent: 'center' },
|
|
84
|
-
body: { flexShrink: 1 },
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export default DocumentSheet;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
fetchLinkedOrder,
|
|
4
|
-
fetchOrderProducts,
|
|
5
|
-
} from '@controleonline/ui-common/src/react/utils/commercialDocumentOrders';
|
|
6
|
-
import { formatBRL, summarizeOrderProducts } from '@controleonline/ui-common/src/react/utils/orderProductsSummary';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Product count and total of the order linked to a proposal/contract, for the
|
|
10
|
-
* fixed document header. Call `reload` after products change.
|
|
11
|
-
*/
|
|
12
|
-
const useLinkedOrderSummary = contractRef => {
|
|
13
|
-
const [summary, setSummary] = useState({ count: 0, total: 0, loaded: false });
|
|
14
|
-
|
|
15
|
-
const reload = useCallback(async () => {
|
|
16
|
-
if (!contractRef) {
|
|
17
|
-
setSummary({ count: 0, total: 0, loaded: true });
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const order = await fetchLinkedOrder(contractRef);
|
|
23
|
-
const items = order ? await fetchOrderProducts(order['@id'] || order.id) : [];
|
|
24
|
-
setSummary({ ...summarizeOrderProducts(items), loaded: true });
|
|
25
|
-
} catch {
|
|
26
|
-
setSummary(current => ({ ...current, loaded: true }));
|
|
27
|
-
}
|
|
28
|
-
}, [contractRef]);
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
reload();
|
|
32
|
-
}, [reload]);
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
...summary,
|
|
36
|
-
totalLabel: summary.loaded && summary.count > 0 ? formatBRL(summary.total) : null,
|
|
37
|
-
reload,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default useLinkedOrderSummary;
|
|
@@ -1,42 +0,0 @@
|
|
|
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,61 +0,0 @@
|
|
|
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,43 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
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,30 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const { resolveClientPortfolioParams } = require('../../../react/utils/clientPortfolioParams');
|
|
4
|
-
|
|
5
|
-
test('seller only sees his own portfolio', () => {
|
|
6
|
-
assert.deepEqual(
|
|
7
|
-
resolveClientPortfolioParams({ currentCompanyId: 1, permissions: ['salesman'], sellerPeopleId: 31487 }),
|
|
8
|
-
{ 'link.company': '/people/31487', 'link.linkType': 'sellers-client' },
|
|
9
|
-
);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('owners and managers see every company client', () => {
|
|
13
|
-
const expected = { 'link.company': '/people/1', 'link.linkType': 'client' };
|
|
14
|
-
assert.deepEqual(
|
|
15
|
-
resolveClientPortfolioParams({ currentCompanyId: 1, permissions: ['salesman', 'owner'], sellerPeopleId: 7 }),
|
|
16
|
-
expected,
|
|
17
|
-
);
|
|
18
|
-
assert.deepEqual(
|
|
19
|
-
resolveClientPortfolioParams({ currentCompanyId: '/people/1', permissions: 'manager', sellerPeopleId: 7 }),
|
|
20
|
-
expected,
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('without seller data falls back to company clients, without company returns null', () => {
|
|
25
|
-
assert.deepEqual(
|
|
26
|
-
resolveClientPortfolioParams({ currentCompanyId: 1, permissions: ['salesman'] }),
|
|
27
|
-
{ 'link.company': '/people/1', 'link.linkType': 'client' },
|
|
28
|
-
);
|
|
29
|
-
assert.equal(resolveClientPortfolioParams({ permissions: ['salesman'], sellerPeopleId: 1 }), null);
|
|
30
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
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('plain-text models are returned decoded as text', () => {
|
|
17
|
-
const text = 'CONTRATO PADRÃO\nCláusula 1 – <nome_contratante> & mais';
|
|
18
|
-
assert.deepEqual(resolveDocumentFileContent(toBase64(text)), { kind: 'text', content: text });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('PDF payloads stay base64 for the viewer', () => {
|
|
22
|
-
const pdf = Buffer.from('%PDF-1.7\n\xff\xfe binary', 'binary').toString('base64');
|
|
23
|
-
assert.deepEqual(resolveDocumentFileContent(pdf), { kind: 'pdf', content: pdf });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('empty contents', () => {
|
|
27
|
-
assert.deepEqual(resolveDocumentFileContent(''), { kind: 'empty', content: '' });
|
|
28
|
-
assert.deepEqual(resolveDocumentFileContent(null), { kind: 'empty', content: '' });
|
|
29
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const { formatBRL, summarizeOrderProducts } = require('../../../react/utils/orderProductsSummary');
|
|
4
|
-
|
|
5
|
-
test('sums only top-level lines', () => {
|
|
6
|
-
const items = [
|
|
7
|
-
{ id: 1, quantity: 2, price: 130, total: 260 },
|
|
8
|
-
{ id: 2, quantity: 1, price: 0.01, total: 0.01 },
|
|
9
|
-
{ id: 3, quantity: 1, price: 10, total: 10, orderProduct: '/order_products/1' },
|
|
10
|
-
];
|
|
11
|
-
assert.deepEqual(summarizeOrderProducts(items), { count: 2, total: 260.01 });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('falls back to price x quantity and handles empty input', () => {
|
|
15
|
-
assert.deepEqual(summarizeOrderProducts([{ quantity: 3, price: 2.5 }]), { count: 1, total: 7.5 });
|
|
16
|
-
assert.deepEqual(summarizeOrderProducts(null), { count: 0, total: 0 });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('formats Brazilian currency', () => {
|
|
20
|
-
assert.equal(formatBRL(1260), 'R$ 1.260,00');
|
|
21
|
-
assert.equal(formatBRL(260.01), 'R$ 260,01');
|
|
22
|
-
assert.equal(formatBRL(0), 'R$ 0,00');
|
|
23
|
-
assert.equal(formatBRL(1234567.8), 'R$ 1.234.567,80');
|
|
24
|
-
});
|