@controleonline/ui-common 1.2.70 → 1.2.71

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.
Files changed (61) hide show
  1. package/package.json +31 -28
  2. package/src/api/index.js +237 -37
  3. package/src/react/components/AddImportModal.js +1 -1
  4. package/src/react/components/AnimatedModal.js +171 -0
  5. package/src/react/components/AnimatedModal.styles.js +21 -0
  6. package/src/react/components/AppTypeSwitcher.js +164 -0
  7. package/src/react/components/AppTypeSwitcher.styles.js +109 -0
  8. package/src/react/components/BackgroundRuntimeBridge.js +5 -4
  9. package/src/react/components/BottomNavigationBar.js +86 -31
  10. package/src/react/components/BottomNavigationBar.styles.js +118 -110
  11. package/src/react/components/DefaultProvider.native.js +68 -66
  12. package/src/react/components/DefaultProvider.web.js +44 -42
  13. package/src/react/components/DeliveryPushBridge.native.js +2 -2
  14. package/src/react/components/DeviceAlertSoundService.js +3 -3
  15. package/src/react/components/KioskModeBridge.js +2 -2
  16. package/src/react/components/LauncherModeBridge.js +2 -2
  17. package/src/react/components/ManagerPushBridge.native.js +2 -2
  18. package/src/react/components/RemoteCheckoutService.js +28 -20
  19. package/src/react/components/RuntimeBottomNavigationBar.js +146 -119
  20. package/src/react/components/RuntimeInfoFooter.js +37 -9
  21. package/src/react/components/StateStore.js +258 -0
  22. package/src/react/components/WebsocketListener.native.js +11 -11
  23. package/src/react/config/deviceConfigBootstrap.js +66 -27
  24. package/src/react/css/orders.js +72 -0
  25. package/src/react/pages/SettingsPage/PaymentTypesByWalletTab.js +484 -454
  26. package/src/react/pages/SettingsPage/index.js +1266 -1167
  27. package/src/react/print/providers/local.js +1 -1
  28. package/src/react/router/publicRoutes.js +25 -0
  29. package/src/react/services/Cielo/Checkout.js +39 -0
  30. package/src/react/services/Cielo/Cielo.js +193 -0
  31. package/src/react/services/Cielo/Print.js +7 -0
  32. package/src/react/services/InfinitePay/Checkout.js +33 -0
  33. package/src/react/services/InfinitePay/InfinitePay.js +24 -0
  34. package/src/react/{utils → services}/paymentGatewayExecution.js +91 -91
  35. package/src/react/styles/global.js +115 -0
  36. package/src/react/utils/fileUrl.js +182 -16
  37. package/src/react/utils/menuNavigation.js +31 -0
  38. package/src/react/utils/orderIdentity.js +277 -0
  39. package/src/react/utils/remotePayment.js +115 -61
  40. package/src/react/utils/runtimeMenu.js +35 -3
  41. package/src/react/utils/shopConfig.js +50 -24
  42. package/src/react/utils/shopFranchises.js +56 -22
  43. package/src/react/utils/socketRuntimePipeline.js +14 -14
  44. package/src/store/configs/index.js +2 -2
  45. package/src/tests/react/api/loadSmokeIndex.test.js +75 -0
  46. package/src/tests/react/config/deviceConfigBootstrap.test.js +47 -0
  47. package/src/tests/react/print/localPrintProvider.test.js +1 -1
  48. package/src/tests/react/services/Cielo.test.js +190 -0
  49. package/src/tests/react/utils/fileUrl.test.js +62 -0
  50. package/src/tests/react/utils/importStatus.test.js +2 -2
  51. package/src/tests/react/utils/orderIdentity.test.js +139 -0
  52. package/src/tests/react/utils/remotePayment.test.js +62 -0
  53. package/src/tests/react/utils/runtimeFooter.test.js +4 -6
  54. package/src/tests/react/utils/runtimeLanguage.test.js +2 -2
  55. package/src/tests/react/utils/runtimeMenu.test.js +23 -3
  56. package/src/tests/react/utils/shopConfig.test.js +74 -0
  57. package/src/tests/react/utils/shopFranchises.test.js +79 -12
  58. package/src/tests/react/utils/translate.test.mjs +166 -102
  59. package/src/utils/formatter.js +18 -0
  60. package/src/utils/integrationConfigs.js +80 -79
  61. package/src/utils/translate.js +125 -30
@@ -17,6 +17,7 @@ export default class Translate {
17
17
  this.bootstrapStores = new Set(this.getStoreList());
18
18
  this.discoveredStores = new Set();
19
19
  this.pendingStoreDiscoveries = new Map();
20
+ this.pendingTranslateResolutionPromise = null;
20
21
  this.pendingPersistRequests = new Map();
21
22
  this.t = this.t.bind(this);
22
23
  if (typeof this.translateActions?.setPendingMessages === "function") {
@@ -223,7 +224,17 @@ export default class Translate {
223
224
  hasDiscoveredStore(store) {
224
225
  if (!store) return false;
225
226
 
226
- return this.discoveredStores.has(this.getStoreDiscoveryToken(store));
227
+ const token = this.getStoreDiscoveryToken(store);
228
+ if (this.discoveredStores.has(token)) {
229
+ return true;
230
+ }
231
+
232
+ if (this.hasCachedBootstrapStore(store)) {
233
+ this.markStoreDiscovered(store);
234
+ return true;
235
+ }
236
+
237
+ return false;
227
238
  }
228
239
 
229
240
  markStoreDiscovered(store) {
@@ -339,7 +350,7 @@ export default class Translate {
339
350
  persistMissingTranslate(store, type, key, translate) {
340
351
  if (!store || !type || !key || !this.defaultCompany?.id) return;
341
352
 
342
- // verifica se tenho acesso ao defaultCompany
353
+ // Skip writes when the default company is not available in the current access scope.
343
354
  const defaultCompanyId = this.normalizeId(this.defaultCompany?.id);
344
355
  if (
345
356
  !Array.isArray(this.companies) ||
@@ -351,15 +362,7 @@ export default class Translate {
351
362
  return;
352
363
  }
353
364
 
354
- const requestToken = this.getPersistRequestToken(store, type, key);
355
- if (this.pendingPersistRequests.has(requestToken)) {
356
- return;
357
- }
358
-
359
- if (
360
- typeof this.translateActions?.queueMissingTranslate !== "function" ||
361
- typeof this.translateActions?.save !== "function"
362
- ) {
365
+ if (typeof this.translateActions?.queueMissingTranslate !== "function") {
363
366
  return;
364
367
  }
365
368
 
@@ -372,6 +375,19 @@ export default class Translate {
372
375
  translate,
373
376
  });
374
377
 
378
+ if (typeof this.translateActions?.resolveQueuedMessages === "function") {
379
+ return this.scheduleQueuedTranslateResolution();
380
+ }
381
+
382
+ const requestToken = this.getPersistRequestToken(store, type, key);
383
+ if (this.pendingPersistRequests.has(requestToken)) {
384
+ return this.pendingPersistRequests.get(requestToken);
385
+ }
386
+
387
+ if (typeof this.translateActions?.save !== "function") {
388
+ return;
389
+ }
390
+
375
391
  const request = Promise.resolve(
376
392
  this.translateActions.save({
377
393
  people: "/people/" + defaultCompanyId,
@@ -398,6 +414,7 @@ export default class Translate {
398
414
  });
399
415
 
400
416
  this.pendingPersistRequests.set(requestToken, request);
417
+ return request;
401
418
  }
402
419
 
403
420
  removePendingTranslate(store, type, key) {
@@ -415,31 +432,108 @@ export default class Translate {
415
432
  key,
416
433
  });
417
434
  }
418
-
419
- t(store, type, key) {
420
- const translate = this.getMessageFromBuckets(store, type, key);
421
- const fallbackTranslate = this.formatMessage(key);
422
- const shouldDiscoverStore =
423
- this.canDiscoverStore() && !this.hasDiscoveredStore(store);
424
435
 
425
- if (shouldDiscoverStore) {
426
- this.ensureStoreDiscovered(store)
427
- .then(() => {
428
- const discoveredTranslate = this.getMessageFromBuckets(store, type, key);
436
+ getQueuedTranslateGroups() {
437
+ const defaultCompanyId = this.normalizeId(this.defaultCompany?.id);
438
+ if (!defaultCompanyId) {
439
+ return [];
440
+ }
441
+
442
+ const companyBucket = this.getPendingCompanyBucket(defaultCompanyId, this.language);
443
+ if (!companyBucket) {
444
+ return [];
445
+ }
446
+
447
+ const requests = [];
448
+ Object.entries(companyBucket).forEach(([store, storeBucket]) => {
449
+ if (!storeBucket || typeof storeBucket !== "object") {
450
+ return;
451
+ }
452
+
453
+ Object.entries(storeBucket).forEach(([type, typeBucket]) => {
454
+ if (!typeBucket || typeof typeBucket !== "object") {
455
+ return;
456
+ }
457
+
458
+ const keys = Object.keys(typeBucket)
459
+ .map((value) => String(value).trim())
460
+ .filter(Boolean);
461
+
462
+ if (keys.length === 0) {
463
+ return;
464
+ }
465
+
466
+ requests.push({
467
+ store,
468
+ type,
469
+ keys,
470
+ });
471
+ });
472
+ });
473
+
474
+ return requests;
475
+ }
476
+
477
+ scheduleQueuedTranslateResolution() {
478
+ if (this.pendingTranslateResolutionPromise) {
479
+ return this.pendingTranslateResolutionPromise;
480
+ }
429
481
 
430
- if (discoveredTranslate) {
431
- return;
432
- }
482
+ this.pendingTranslateResolutionPromise = Promise.resolve()
483
+ .then(() => this.resolveQueuedTranslations())
484
+ .catch(() => this.translates)
485
+ .finally(() => {
486
+ this.pendingTranslateResolutionPromise = null;
487
+ });
433
488
 
434
- this.persistMissingTranslate(store, type, key, fallbackTranslate);
435
- })
436
- .catch(() => {});
489
+ return this.pendingTranslateResolutionPromise;
490
+ }
491
+
492
+ async resolveQueuedTranslations() {
493
+ if (typeof this.translateActions?.resolveQueuedMessages !== "function") {
494
+ return this.translates;
495
+ }
496
+
497
+ const requests = this.getQueuedTranslateGroups();
498
+ if (requests.length === 0) {
499
+ return this.translates;
500
+ }
501
+
502
+ const currentCompanyId = this.normalizeId(this.currentCompany?.id || this.defaultCompany?.id);
503
+ if (!currentCompanyId) {
504
+ return this.translates;
437
505
  }
438
506
 
507
+ const response = await this.translateActions.resolveQueuedMessages({
508
+ people: "/people/" + currentCompanyId,
509
+ language: this.language,
510
+ requests,
511
+ });
512
+
513
+ const resolvedItems = Array.isArray(response)
514
+ ? response
515
+ : response?.member || response?.["hydra:member"] || [];
516
+
517
+ let changed = false;
518
+ resolvedItems.forEach((item) => {
519
+ changed = this.cacheTranslateRecord(item, currentCompanyId, this.language) || changed;
520
+ this.removePendingTranslate(item.store, item.type, item.key);
521
+ });
522
+
523
+ if (changed) {
524
+ this.persist();
525
+ this.notifyTranslationsUpdated();
526
+ }
527
+
528
+ return resolvedItems;
529
+ }
530
+
531
+ t(store, type, key) {
532
+ const translate = this.getMessageFromBuckets(store, type, key);
533
+ const fallbackTranslate = this.formatMessage(key);
534
+
439
535
  if (!translate) {
440
- if (!shouldDiscoverStore) {
441
- this.persistMissingTranslate(store, type, key, fallbackTranslate);
442
- }
536
+ this.persistMissingTranslate(store, type, key, fallbackTranslate);
443
537
 
444
538
  return fallbackTranslate;
445
539
  }
@@ -456,6 +550,7 @@ export default class Translate {
456
550
  this.translates = {};
457
551
  this.discoveredStores.clear();
458
552
  this.pendingStoreDiscoveries.clear();
553
+ this.pendingTranslateResolutionPromise = null;
459
554
  this.pendingPersistRequests.clear();
460
555
  if (typeof this.translateActions?.setPendingMessages === "function") {
461
556
  this.translateActions.setPendingMessages({});