@subiz/widget-v4 4.1.185 → 4.1.187

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 (117) hide show
  1. package/assets/less/chatbox.less +1 -0
  2. package/assets/less/message.less +20 -0
  3. package/assets/less/widget.less +50 -13
  4. package/compiled_src/bot.js +1 -1
  5. package/compiled_src/chatbox/ChatButton.js +15 -9
  6. package/compiled_src/chatbox/TextMessage.js +3 -0
  7. package/compiled_src/chatbox/block.js +1 -0
  8. package/compiled_src/chatbox/main.js +2 -0
  9. package/compiled_src/store/store.js +8 -1
  10. package/compiled_src/util/common.js +1 -0
  11. package/compiled_src/util/index.js +1 -0
  12. package/compiled_src/util/op.js +9 -0
  13. package/dist/127.js +273 -0
  14. package/dist/132.js +2802 -0
  15. package/dist/185.js +1827 -0
  16. package/dist/19a00a03cb8.127.js +1 -0
  17. package/dist/19a00a03cb8.132.js +1 -0
  18. package/dist/19a00a03cb8.185.js +1 -0
  19. package/dist/19a00a03cb8.27.js +1 -0
  20. package/dist/19a00a03cb8.278.js +1 -0
  21. package/dist/19a00a03cb8.339.js +1 -0
  22. package/dist/19a00a03cb8.459.js +1 -0
  23. package/dist/19a00a03cb8.490.js +1 -0
  24. package/dist/19a00a03cb8.74.js +1 -0
  25. package/dist/19a00a03cb8.997.js +1 -0
  26. package/dist/19a00a03cb8.app.js +1 -0
  27. package/dist/19a00a03cb8.chat.html +1 -0
  28. package/dist/19a00a03cb8.chat.js +1 -0
  29. package/dist/19a00a03cb8.form.html +1 -0
  30. package/dist/19a00a03cb8.form.js +1 -0
  31. package/dist/19a00a03cb8.index.html +72 -0
  32. package/dist/19a00a03cb8.library.html +72 -0
  33. package/dist/19a00a03cb8.library.js +1 -0
  34. package/dist/19a00a03cb8.preview.html +759 -0
  35. package/dist/19a00a03cb8.preview.js +1 -0
  36. package/dist/19a00a03cb8.webview.js +1 -0
  37. package/dist/27.js +35 -0
  38. package/dist/459.js +35 -0
  39. package/dist/490.js +305 -0
  40. package/dist/74.js +372 -0
  41. package/dist/997.js +35 -0
  42. package/dist/HASH +1 -0
  43. package/dist/assets/img/Facebook.64607ec.png +0 -0
  44. package/dist/assets/img/Zalo.6845707.png +0 -0
  45. package/dist/assets/img/award1a.1a58e10.png +0 -0
  46. package/dist/assets/img/award3a.3b74423.png +0 -0
  47. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  48. package/dist/assets/img/award5.39eb7ae.png +0 -0
  49. package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
  50. package/dist/assets/img/caret.998eb8f.svg +1 -0
  51. package/dist/assets/img/convos_empty.2353007.svg +72 -0
  52. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  53. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  54. package/dist/assets/img/done_gray.d7e8203.svg +4 -0
  55. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  56. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  57. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  58. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  59. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  60. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  61. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  62. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  63. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  64. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  65. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  66. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  67. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  68. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  69. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  70. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  71. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  72. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  73. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  74. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  75. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  76. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  77. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  78. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  79. package/dist/assets/img/empty.29bed2d.svg +23 -0
  80. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  81. package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
  82. package/dist/assets/img/external-link.90577cc.svg +1 -0
  83. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  84. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  85. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  86. package/dist/assets/img/image_default.be0698b.png +0 -0
  87. package/dist/assets/img/info.ebce7ea.svg +1 -0
  88. package/dist/assets/img/loader.37000a7.svg +1 -0
  89. package/dist/assets/img/loading_static.a27f0ac.svg +10 -0
  90. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  91. package/dist/assets/img/main-service2.9b99549.png +0 -0
  92. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  93. package/dist/assets/img/package.8d37d0f.svg +5 -0
  94. package/dist/assets/img/package_fade.763c001.svg +1 -0
  95. package/dist/assets/img/rating--average.1ea492c.svg +12 -0
  96. package/dist/assets/img/rating--great.e3d712e.svg +16 -0
  97. package/dist/assets/img/rating--poor.2938a25.svg +12 -0
  98. package/dist/assets/img/search.f9705ff.svg +1 -0
  99. package/dist/assets/img/send.6db52a9.svg +3 -0
  100. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  101. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  102. package/dist/assets/img/stars_v2.79cf728.png +0 -0
  103. package/dist/assets/img/subiz-mono.8fbc067.svg +3 -0
  104. package/dist/assets/img/x.26fdfa3.svg +5 -0
  105. package/dist/malicious-app.js +17 -0
  106. package/dist/screenshoot.html +7 -0
  107. package/dist/screenshoot.js +12630 -0
  108. package/package.json +2 -2
  109. package/src/bot.js +1 -1
  110. package/src/chatbox/ChatButton.js +16 -8
  111. package/src/chatbox/TextMessage.js +15 -5
  112. package/src/chatbox/block.js +1 -0
  113. package/src/chatbox/main.js +2 -0
  114. package/src/store/store.js +8 -2
  115. package/src/util/common.js +1 -0
  116. package/src/util/index.js +1 -0
  117. package/src/util/op.js +18 -6
@@ -19,6 +19,7 @@
19
19
  @desktop-chat-button-margin-x: '@desktop_button.margin_x'; //20px;
20
20
  @desktop-chat-button-margin-y: '@desktop_button.margin_y'; // 20px;
21
21
  @desktop-widget-max-height: '@desktop_widget_max_height'; // calc(100% - desktop_buttom.margin_y)
22
+ @preview-max-width: '@preview_max_width';
22
23
 
23
24
  @form-page-background-color: '@form_background_color';
24
25
  @form-page-header-font-size: '@form_header_font_size';
@@ -963,3 +963,23 @@ a.product_attachment__title {
963
963
  .text-message-li {
964
964
  display: list-item;
965
965
  }
966
+
967
+ .agent-message .text-message-link {
968
+ .color(@link);
969
+ font-weight: 400;
970
+
971
+ &:hover {
972
+ .color(@link-hover);
973
+ }
974
+ }
975
+
976
+ .user-message .text-message-link {
977
+ text-decoration: underline;
978
+ text-decoration-color: rgba(255, 255, 255, 0.6);
979
+ text-underline-offset: 4px;
980
+
981
+ &:hover {
982
+ text-decoration-color: #fff;
983
+ background-color: rgba(255, 255, 255, 0.08);
984
+ }
985
+ }
@@ -645,6 +645,34 @@
645
645
  &.right {
646
646
  align-items: flex-end;
647
647
  }
648
+
649
+ &.horizontal {
650
+ flex-direction: row;
651
+ flex-wrap: wrap;
652
+ align-items: center;
653
+ gap: 10px;
654
+
655
+ &.right {
656
+ justify-content: flex-end;
657
+ }
658
+
659
+ &.left {
660
+ justify-content: flex-start;
661
+ }
662
+ }
663
+ }
664
+
665
+ .widget-preview-quick-reply-wrapper.horizontal .widget-preview-quick-reply-item {
666
+ margin: 0;
667
+ max-width: 200px;
668
+ overflow: hidden;
669
+ text-overflow: ellipsis;
670
+ white-space: nowrap;
671
+ padding: 6px 15px;
672
+
673
+ &:last-child {
674
+ margin-bottom: 0;
675
+ }
648
676
  }
649
677
 
650
678
  .widget-preview-quick-reply-item {
@@ -719,7 +747,7 @@
719
747
  }
720
748
 
721
749
  .widget-preview-new-wrapper {
722
- max-width: 340px;
750
+ max-width: @preview-max-width;
723
751
  position: relative;
724
752
  opacity: 1;
725
753
  transition:
@@ -740,18 +768,6 @@
740
768
  display: flex;
741
769
  }
742
770
  }
743
-
744
- .widget-preview--btn-close {
745
- width: 32px;
746
- height: 32px;
747
- background-color: #00000040;
748
- background-size: 16px 16px;
749
- background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXIteCI+PGxpbmUgeDE9IjE4IiB5MT0iNiIgeDI9IjYiIHkyPSIxOCI+PC9saW5lPjxsaW5lIHgxPSI2IiB5MT0iNiIgeDI9IjE4IiB5Mj0iMTgiPjwvbGluZT48L3N2Zz4K');
750
-
751
- &:hover {
752
- background-color: #00000066;
753
- }
754
- }
755
771
  }
756
772
 
757
773
  .widget-preview-x-wrapper {
@@ -763,9 +779,30 @@
763
779
  left: -20px;
764
780
  bottom: 100%;
765
781
 
782
+ &.mobile {
783
+ display: flex;
784
+ }
785
+
766
786
  &.right {
767
787
  justify-content: flex-end;
768
788
  left: unset;
769
789
  right: -20px;
770
790
  }
791
+
792
+ .widget-preview--btn-close {
793
+ opacity: 1;
794
+ width: 32px;
795
+ height: 32px;
796
+ border: 1px solid #ececec;
797
+ box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.15);
798
+ background-color: #00000040;
799
+ background-size: 16px 16px;
800
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNlY2VjZWMiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXIteCI+PGxpbmUgeDE9IjE4IiB5MT0iNiIgeDI9IjYiIHkyPSIxOCI+PC9saW5lPjxsaW5lIHgxPSI2IiB5MT0iNiIgeDI9IjE4IiB5Mj0iMTgiPjwvbGluZT48L3N2Zz4K');
801
+
802
+ &:hover {
803
+ border-color: #fff;
804
+ background-color: #00000066;
805
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS13aWR0aD0iMi4yIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXIteCI+PGxpbmUgeDE9IjE4IiB5MT0iNiIgeDI9IjYiIHkyPSIxOCI+PC9saW5lPjxsaW5lIHgxPSI2IiB5MT0iNiIgeDI9IjE4IiB5Mj0iMTgiPjwvbGluZT48L3N2Zz4K');
806
+ }
807
+ }
771
808
  }
@@ -21,7 +21,7 @@ function _default(store) {
21
21
  if (!bot.welcome_message) return;
22
22
  let {
23
23
  error
24
- } = await store.startLightConvo(bot.id, bot.welcome_message, common.getLocale(bot, _index.default.detectLang()), true);
24
+ } = await store.startLightConvo(bot.id, bot.welcome_message, common.getLocale(bot, _index.default.detectLang()), false);
25
25
  if (error) return console.error(error);
26
26
  store.logBotRun(bot.id);
27
27
  return;
@@ -48,11 +48,15 @@ class ChatButton extends _common.Com {
48
48
  if (screen === 'widget') return;
49
49
  if (minimized && Date.now() - minimized < Ms30Mins) return;
50
50
  if (this.props.store.isMobile()) {
51
- this.props.store.updateLastview({
52
- previewEvent: ev
53
- });
54
- this.forceUpdate();
55
- return;
51
+ let mobileDisabled = _index.default.get(this.props.plugin, 'chatbox.greeting.mobile_disabled');
52
+ if (mobileDisabled) {
53
+ this.props.store.updateLastview({
54
+ screen: 'button',
55
+ previewEvent: ev
56
+ });
57
+ this.forceUpdate();
58
+ return;
59
+ }
56
60
  }
57
61
  this.props.store.updateLastview({
58
62
  screen: 'preview',
@@ -210,7 +214,8 @@ class ChatButton extends _common.Com {
210
214
  let greeting = _index.default.get(accountSetting, 'greeting', {});
211
215
  let text = this.props.t.i18n(_index.default.get(greeting, 'greeting', {})) || greeting.message;
212
216
  let enabled = greeting.enabled;
213
- if (!text || !enabled) {
217
+ let mobileDisabled = this.props.store.isMobile() && greeting.mobile_disabled;
218
+ if (!text || !enabled || mobileDisabled) {
214
219
  return;
215
220
  }
216
221
  this.ShowGreeting();
@@ -269,7 +274,6 @@ class ChatButton extends _common.Com {
269
274
  return agent;
270
275
  }
271
276
  renderPreview() {
272
- if (this.props.store.isMobile()) return;
273
277
  if (!this.state.hasPreviewDom) return;
274
278
  let previewEvent = this.state.previewEvent;
275
279
  let agent = this.getAgentOfPreviewEvent(previewEvent);
@@ -283,6 +287,7 @@ class ChatButton extends _common.Com {
283
287
  let attachments = _index.default.get(previewEvent, 'data.message.attachments') || [];
284
288
  let quickReplies = _index.default.find(attachments, att => att.type === 'quick_replies');
285
289
  quickReplies = _index.default.get(quickReplies, 'quick_replies') || [];
290
+ quickReplies = _index.default.take(quickReplies, 10);
286
291
  let imgAtt = _index.default.find(attachments, att => _index.default.includes(att.mimetype, 'image') && att.url);
287
292
  let uri = _index.default.get(imgAtt, 'url') || '';
288
293
  if (uri && !uri.startsWith('https://') && !uri.startsWith('http://') && !uri.startsWith('content://') && !uri.startsWith('data:')) {
@@ -291,7 +296,7 @@ class ChatButton extends _common.Com {
291
296
  return (0, _preact.h)("div", {
292
297
  class: `widget-preview-new-wrapper ${this.state.previewExtraCls}`
293
298
  }, (0, _preact.h)("div", {
294
- class: `widget-preview-x-wrapper ${position}`
299
+ class: `widget-preview-x-wrapper ${position} ${this.props.store.isMobile() ? 'mobile' : ''}`
295
300
  }, (0, _preact.h)("div", {
296
301
  class: "widget-preview--btn-close",
297
302
  onClick: e => this.closePreview(e)
@@ -322,10 +327,11 @@ class ChatButton extends _common.Com {
322
327
  }, (0, _preact.h)("img", {
323
328
  src: uri
324
329
  }))), _index.default.size(quickReplies) > 0 && (0, _preact.h)("div", {
325
- class: `widget-preview-quick-reply-wrapper ${position}`
330
+ class: `widget-preview-quick-reply-wrapper ${position} ${_index.default.size(quickReplies) > 4 ? 'horizontal' : ''}`
326
331
  }, _index.default.map(quickReplies, reply => {
327
332
  if (!(reply.title || '').trim()) return;
328
333
  return (0, _preact.h)("div", {
334
+ title: reply.title,
329
335
  class: "widget-preview-quick-reply-item",
330
336
  onClick: () => {
331
337
  this.props.onSelectQuickReply({
@@ -45,15 +45,18 @@ class TextMessage extends _common.Com {
45
45
  url = '//' + url;
46
46
  }
47
47
  return (0, _preact.h)("a", {
48
+ class: "text-message-link",
48
49
  href: url,
49
50
  target: "_blank",
50
51
  onClick: e => this.props.onLink(e, url)
51
52
  }, tag.text);
52
53
  }
53
54
  if (tag.type === 'phone') return (0, _preact.h)("a", {
55
+ class: "text-message-link",
54
56
  href: 'tel:' + tag.text
55
57
  }, tag.text);
56
58
  if (tag.type === 'email') return (0, _preact.h)("a", {
59
+ class: "text-message-link",
57
60
  href: 'mailto:' + tag.text
58
61
  }, tag.text);
59
62
  return tag.text;
@@ -179,6 +179,7 @@ class Block extends _common.Com {
179
179
  return (0, _preact.h)("hr", null);
180
180
  case 'a':
181
181
  return (0, _preact.h)("a", {
182
+ class: this.props.textMessage ? 'message-text-link' : '',
182
183
  href: ele.attrs['href'],
183
184
  target: this.props.textMessage ? '_blank' : ele.attrs['target'],
184
185
  title: ele.attrs['title']
@@ -25,6 +25,8 @@ class Main extends _common.Com {
25
25
  let chatbox = found.chatbox;
26
26
  let margin_y = _index.default.get(chatbox, 'desktop_button.margin_y');
27
27
  chatbox.desktop_widget_max_height = margin_y ? `calc(100% - ${margin_y + 10}px)` : 'calc(100% - 40px)';
28
+ const PREVIEW_MAX_WIDTH = 340;
29
+ chatbox.preview_max_width = Math.min(PREVIEW_MAX_WIDTH, chatbox.width) + 'px';
28
30
  var outcss = _index.default.replaceCssVariable(css, chatbox);
29
31
  _index.default.setCss(this.props.plugin.id, this.$cssStyleDiv, outcss);
30
32
  }
@@ -521,7 +521,14 @@ class Store {
521
521
  lastView.screen = 'widget';
522
522
  }
523
523
  }
524
- if (this.isMobile()) lastView.screen = 'button';
524
+ if (this.isMobile()) {
525
+ lastView.screen = 'preview';
526
+ let plugins = this.matchPlugin() || {};
527
+ let chatbox = _index.default.find(plugins, plugin => plugin.type === 'chatbox') || {};
528
+ if (_index.default.get(chatbox, 'chatbox.greeting.mobile_disabled')) {
529
+ lastView.screen = 'button';
530
+ }
531
+ }
525
532
  this.kv.put('lastview', lastView);
526
533
  }
527
534
  async _initResource(accid, auth, realtimep) {
@@ -628,6 +628,7 @@ function replaceCssVariable(css, setting) {
628
628
  tokens = tokenize(tokens, "'@desktop_button.margin_x'");
629
629
  tokens = tokenize(tokens, "'@desktop_button.margin_y'");
630
630
  tokens = tokenize(tokens, "'@desktop_widget_max_height'");
631
+ tokens = tokenize(tokens, "'@preview_max_width'");
631
632
  tokens = tokenize(tokens, "'@mobile_button.width'");
632
633
  tokens = tokenize(tokens, "'@mobile_button.height'");
633
634
  tokens = tokenize(tokens, "'@mobile_button.background'");
@@ -14,6 +14,7 @@ sb.Mutex = require('./mutex.js').default;
14
14
  var op = require('./op.js');
15
15
  sb.get = op.get;
16
16
  sb.set = op.set;
17
+ sb.take = op.take;
17
18
  sb.Pubsub = require('./pubsub.js').default;
18
19
  sb = Object.assign(sb, campaign);
19
20
  var _default = exports.default = sb;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.get = get;
7
7
  exports.set = set;
8
+ exports.take = take;
8
9
  var toStr = Object.prototype.toString;
9
10
  var isArray = Array.isArray || function (obj) {
10
11
  return toStr.call(obj) === '[object Array]';
@@ -52,4 +53,12 @@ function set(obj, path, value) {
52
53
  obj[currentPath] = typeof path[1] === 'number' ? [] : {};
53
54
  }
54
55
  return set(obj[currentPath], path.slice(1), value);
56
+ }
57
+ function take(arr, n = 1) {
58
+ if (!Array.isArray(arr)) return [];
59
+ let len = arr.length;
60
+ if (typeof len !== 'number' || len <= 0) return [];
61
+ if (n <= 0) return [];
62
+ let end = Math.min(n, len);
63
+ return arr.slice(0, end);
55
64
  }
package/dist/127.js ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ (self["webpackChunk_subiz_widget_v4"] = self["webpackChunk_subiz_widget_v4"] || []).push([[127],{
3
+
4
+ /***/ 6127:
5
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
6
+
7
+ __webpack_require__.r(__webpack_exports__);
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ "default": () => (/* binding */ ProductAttachments)
10
+ /* harmony export */ });
11
+ /* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8150);
12
+ /* harmony import */ var _common_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2840);
13
+ /* harmony import */ var preact__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(172);
14
+
15
+
16
+
17
+ class ProductAttachments extends _common_js__WEBPACK_IMPORTED_MODULE_1__/* .Com */ .Mw {
18
+ render() {
19
+ let byType = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'by.type');
20
+ if (byType === 'user') return null;
21
+ let acc = this.props.store.matchAccount();
22
+ var attachments = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'data.message.attachments', []);
23
+ let orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.filter(attachments, att => att.type === 'order' && att.order).map(att => att.order);
24
+ if (orders.length === 0) return null;
25
+ let $orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(orders, (order, index) => {
26
+ calcOrderTotal(order);
27
+ let $note = null;
28
+ if (order.note) {
29
+ $note = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
30
+ class: "order_attachment__label"
31
+ }, this.props.t('note')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
32
+ class: "order_attachment__note",
33
+ title: order.note
34
+ }, order.note));
35
+ }
36
+ let $products = null;
37
+ if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order.items) > 0) {
38
+ $products = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
39
+ class: "order_attachment__label"
40
+ }, this.props.t('product')), _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(order.items, item => {
41
+ let product = item.product || {};
42
+ return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
43
+ class: "order_attachment__product"
44
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("img", {
45
+ class: "order_attachment__product_img",
46
+ alt: '' + _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'id'),
47
+ src: _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'image', __webpack_require__(2876))
48
+ }), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
49
+ style: "overflow: hidden !important;"
50
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
51
+ class: "order_attachment__product_name",
52
+ title: this.props.t.i18n(product.i18n_name) || product.name
53
+ }, this.props.t.i18n(product.i18n_name) || product.name), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
54
+ class: "order_attachment__product_desc"
55
+ }, getProductPropName(product, ' / ')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
56
+ class: "order_attachment__product_desc"
57
+ }, this.props.t('qty'), " ", item.quantity, "\xA0\xB7\xA0", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(product.price))));
58
+ }));
59
+ }
60
+ let $total = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
61
+ class: "order_attachment__footer"
62
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
63
+ class: "d-flex align-items-center justify-content-between"
64
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, this.props.t('total')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("b", {
65
+ class: "order_attachment__total"
66
+ }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total)))));
67
+ let phoneattr = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.find(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'user.attributes', []), attr => attr.key === 'phones') || {
68
+ key: 'phones',
69
+ text: ''
70
+ };
71
+ let phone = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.address.phone', '').trim();
72
+ phone = phone || _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.trim(phoneattr.text);
73
+ if (phone) phone = this.props.t('phn') + ': ' + phone;
74
+ let $shipto = null;
75
+ if (displayOrderShippingAddress(order) || phone) {
76
+ $shipto = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
77
+ class: "order_attachment__label"
78
+ }, this.props.t('ship_to')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, displayOrderShippingAddress(order)), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
79
+ class: "order_attachment__text_truncate"
80
+ }, phone));
81
+ }
82
+ let $beforeTax = null;
83
+ if (order._discount_before_tax) {
84
+ $beforeTax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
85
+ class: "order_attachment__footer"
86
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
87
+ class: "d-flex align-items-center justify-content-between"
88
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
89
+ class: "order_attachment__label no_margin"
90
+ }, this.props.t('subtotal_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._order_value))), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
91
+ class: "d-flex align-items-center justify-content-between"
92
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
93
+ class: "order_attachment__label no_margin"
94
+ }, this.props.t('discount_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._discount_before_tax))));
95
+ }
96
+ let $subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
97
+ class: "d-flex align-items-center justify-content-between"
98
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
99
+ class: "order_attachment__label no_margin"
100
+ }, this.props.t('subtotal')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
101
+ style: ""
102
+ }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.subtotal)));
103
+ let $tax = null;
104
+ if (order.total_tax) {
105
+ let taxname = '';
106
+ if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order._taxM) === 1) {
107
+ let tax = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order._taxM, '0.tax', {});
108
+ if (tax.name && tax.percentage) taxname = `(${tax.name} ${Math.round(tax.percentage || 0) / 100}%)`;
109
+ }
110
+ $tax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
111
+ class: "d-flex align-items-center justify-content-between"
112
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
113
+ class: "order_attachment__label no_margin"
114
+ }, this.props.t('tax'), " ", taxname), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
115
+ style: ""
116
+ }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total_tax)));
117
+ }
118
+ let $discount = null;
119
+ if (order.discount_type === 'percentage' && order.discount_percentage) {
120
+ $discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
121
+ class: "d-flex align-items-center justify-content-between"
122
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
123
+ class: "order_attachment__label no_margin"
124
+ }, this.props.t('discount_after_tax'), " (", Math.round(order.discount_percentage / 100), "%)"), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
125
+ style: ""
126
+ }, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
127
+ }
128
+ if (order.discount_type === 'amount' && order.discount_amount) {
129
+ $discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
130
+ class: "d-flex align-items-center justify-content-between"
131
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
132
+ class: "order_attachment__label no_margin"
133
+ }, this.props.t('discount_after_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
134
+ class: "no-shrink"
135
+ }, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
136
+ }
137
+ let $shipping = null;
138
+ if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee')) {
139
+ $shipping = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
140
+ class: "d-flex align-items-center justify-content-between"
141
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
142
+ class: "order_attachment__label no_margin"
143
+ }, this.props.t('shipping_fee')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
144
+ style: ""
145
+ }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee', 0))));
146
+ }
147
+ let $adjustment = null;
148
+ if (order.adjustment) {
149
+ $adjustment = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
150
+ class: "d-flex align-items-center justify-content-between"
151
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
152
+ class: "order_attachment__label no_margin"
153
+ }, order.adjustment_description), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
154
+ class: "no-shrink"
155
+ }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.adjustment)));
156
+ }
157
+ $subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
158
+ class: "order_attachment__footer"
159
+ }, $subtotal, $tax, $shipping, $discount, $adjustment);
160
+ if (!$shipping && !$adjustment && !$discount && !$tax) {
161
+ $subtotal = null;
162
+ }
163
+ return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
164
+ class: `order_attachment order_attachment__${byType}`
165
+ }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
166
+ class: "order_attachment__header"
167
+ }, this.props.t('order'), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("span", {
168
+ class: "order_attachment__text_muted order_attachment__text_sm"
169
+ }, getOrderDisplayName(order))), $products, $shipto, $note, $beforeTax, $subtotal, $total);
170
+ });
171
+ return $orders;
172
+ }
173
+ }
174
+ function getProductPropName(product, seperator = ' - ') {
175
+ let options = op.get(product, 'options', []);
176
+ let props = op.get(product, 'props', []);
177
+ let multiPropsOptions = op.filter(options, option => op.size(option.values) > 1);
178
+ let names = [];
179
+ op.each(multiPropsOptions, option => {
180
+ let prop = op.find(props, prop => prop.key === option.key) || {};
181
+ if (prop.value) names.push(prop.value);
182
+ });
183
+ return names.join(seperator);
184
+ }
185
+ function getOrderDisplayName(order = {}) {
186
+ return order.number || order.id || '';
187
+ }
188
+ function displayOrderShippingAddress(order, isShorten) {
189
+ let addr = op.get(order, 'shipping.address', {});
190
+ let fulladdr = [addr.address, addr.ward, addr.district, addr.province].filter(a => a).join(', ').trim();
191
+ if (isShorten) fulladdr = shortenAddr(fulladdr);
192
+ return fulladdr;
193
+ }
194
+ function shortenAddr(str) {
195
+ str = str || '';
196
+ str = str.replace(/Hà Nội/gi, 'HN');
197
+ str = str.replace(/Hồ Chí Minh/gi, 'HCM');
198
+ str = str.replace(/Thành Phố/gi, 'TP');
199
+ return str;
200
+ }
201
+ function calcOrderTotal(order) {
202
+ let subtotal = 0;
203
+ let beforeTaxDiscount = 0;
204
+ let ordervalue = 0;
205
+ op.map(order.items, item => {
206
+ if (!item.product) return 0;
207
+ let price = op.get(item, 'product.price', 0) * (item.quantity || 0);
208
+ ordervalue += price;
209
+ if (item.discount_type == 'percentage') {
210
+ if (item.discount_percentage > 0) {
211
+ beforeTaxDiscount += price * item.discount_percentage / 10000;
212
+ price = price * (1 - (item.discount_percentage || 0) / 10000);
213
+ }
214
+ } else if (item.discount_type == 'amount') {
215
+ if (item.discount_amount > 0) {
216
+ beforeTaxDiscount += item.discount_amount;
217
+ price = price - (item.discount_amount || 0);
218
+ if (price <= 0) price = 0;
219
+ }
220
+ }
221
+ item.total = price;
222
+ subtotal += price;
223
+ });
224
+ let taxM = {};
225
+ op.map(order.items, (item, i) => {
226
+ if (!item.product) return;
227
+ let tax = item.product.tax;
228
+ if (!tax) return;
229
+ if (!tax.id) return;
230
+ let taxprice = item.total * tax.percentage / 10000;
231
+ item.total_tax = taxprice;
232
+ taxM[i] = {
233
+ tax: tax,
234
+ taxprice: taxprice
235
+ };
236
+ });
237
+ let totaltax = 0;
238
+ op.map(taxM, t => totaltax += t.taxprice);
239
+ let computed_discount = 0;
240
+ if (order.discount_type == 'percentage' && order.discount_percentage > 0) {
241
+ computed_discount = (subtotal + totaltax) * order.discount_percentage / 10000;
242
+ } else if (order.discount_type == 'amount') {
243
+ computed_discount = order.discount_amount || 0;
244
+ }
245
+ let shippingfee = op.get(order, 'shipping.nominal_fee', 0);
246
+ if (shippingfee > 0) {
247
+ if (op.get(order, 'shipping.tax.id')) {
248
+ let tax = order.shipping.tax;
249
+ let taxprice = shippingfee * (tax.percentage / 10000);
250
+ taxM['ship'] = {
251
+ tax: tax,
252
+ taxprice: taxprice
253
+ };
254
+ order.shipping.total_tax = taxprice;
255
+ }
256
+ }
257
+ totaltax = 0;
258
+ op.map(taxM, t => totaltax += t.taxprice);
259
+ let total = subtotal + totaltax - computed_discount + shippingfee;
260
+ total += order.adjustment || 0;
261
+ if (total < 0) total = 0;
262
+ order.subtotal = subtotal;
263
+ order._computed_discount = computed_discount;
264
+ order._taxM = taxM;
265
+ order.total = total;
266
+ order.total_tax = totaltax;
267
+ order._discount_before_tax = beforeTaxDiscount;
268
+ order._order_value = ordervalue;
269
+ }
270
+
271
+ /***/ })
272
+
273
+ }]);