@subiz/widget-v4 4.1.107 → 4.1.109

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 (101) hide show
  1. package/compiled_src/chatbox/TextMessage.js +4 -2
  2. package/compiled_src/chatbox/Widget.js +1 -0
  3. package/compiled_src/chatbox/block.js +27 -1
  4. package/compiled_src/store/store.js +10 -6
  5. package/compiled_src/util/common.js +33 -1
  6. package/package.json +10 -10
  7. package/src/chatbox/TextMessage.js +2 -2
  8. package/src/chatbox/Widget.js +1 -0
  9. package/src/chatbox/block.js +29 -2
  10. package/src/store/store.js +7 -3
  11. package/src/util/common.js +36 -1
  12. package/dist/127.js +0 -273
  13. package/dist/132.js +0 -2802
  14. package/dist/185.js +0 -1885
  15. package/dist/1927039db4c.127.js +0 -1
  16. package/dist/1927039db4c.132.js +0 -1
  17. package/dist/1927039db4c.185.js +0 -1
  18. package/dist/1927039db4c.27.js +0 -1
  19. package/dist/1927039db4c.278.js +0 -1
  20. package/dist/1927039db4c.459.js +0 -1
  21. package/dist/1927039db4c.490.js +0 -1
  22. package/dist/1927039db4c.74.js +0 -1
  23. package/dist/1927039db4c.997.js +0 -1
  24. package/dist/1927039db4c.app.js +0 -1
  25. package/dist/1927039db4c.index.html +0 -57
  26. package/dist/1927039db4c.library.html +0 -57
  27. package/dist/1927039db4c.library.js +0 -1
  28. package/dist/1927039db4c.preview.html +0 -759
  29. package/dist/1927039db4c.preview.js +0 -1
  30. package/dist/1927039db4c.webview.js +0 -1
  31. package/dist/27.js +0 -107
  32. package/dist/278.js +0 -406
  33. package/dist/459.js +0 -107
  34. package/dist/490.js +0 -305
  35. package/dist/74.js +0 -372
  36. package/dist/997.js +0 -107
  37. package/dist/HASH +0 -1
  38. package/dist/assets/img/Facebook.64607ec.png +0 -0
  39. package/dist/assets/img/Zalo.6845707.png +0 -0
  40. package/dist/assets/img/award1a.1a58e10.png +0 -0
  41. package/dist/assets/img/award3a.3b74423.png +0 -0
  42. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  43. package/dist/assets/img/award5.39eb7ae.png +0 -0
  44. package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
  45. package/dist/assets/img/caret.998eb8f.svg +0 -1
  46. package/dist/assets/img/convos_empty.2353007.svg +0 -72
  47. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  48. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  49. package/dist/assets/img/done_gray.d7e8203.svg +0 -4
  50. package/dist/assets/img/done_green.b817fd4.svg +0 -4
  51. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  52. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  53. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  54. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  55. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  56. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  57. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  58. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  59. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  60. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  61. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  62. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  63. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  64. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  65. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  66. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  67. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  68. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  69. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  70. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  71. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  72. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  73. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  74. package/dist/assets/img/empty.29bed2d.svg +0 -23
  75. package/dist/assets/img/empty_1.0b98af0.svg +0 -11
  76. package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
  77. package/dist/assets/img/external-link.90577cc.svg +0 -1
  78. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  79. package/dist/assets/img/ghn.070f8e3.svg +0 -17
  80. package/dist/assets/img/ghtk.326eac1.svg +0 -18
  81. package/dist/assets/img/image_default.be0698b.png +0 -0
  82. package/dist/assets/img/info.ebce7ea.svg +0 -1
  83. package/dist/assets/img/loader.37000a7.svg +0 -1
  84. package/dist/assets/img/loading_static.a27f0ac.svg +0 -10
  85. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  86. package/dist/assets/img/main-service2.9b99549.png +0 -0
  87. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  88. package/dist/assets/img/package.8d37d0f.svg +0 -5
  89. package/dist/assets/img/package_fade.763c001.svg +0 -1
  90. package/dist/assets/img/rating--average.1ea492c.svg +0 -12
  91. package/dist/assets/img/rating--great.e3d712e.svg +0 -16
  92. package/dist/assets/img/rating--poor.2938a25.svg +0 -12
  93. package/dist/assets/img/search.f9705ff.svg +0 -1
  94. package/dist/assets/img/send.6db52a9.svg +0 -3
  95. package/dist/assets/img/shop.f7dc7d8.svg +0 -1
  96. package/dist/assets/img/shop_faded.df7845a.svg +0 -1
  97. package/dist/assets/img/subiz-mono.8fbc067.svg +0 -3
  98. package/dist/assets/img/x.26fdfa3.svg +0 -5
  99. package/dist/malicious-app.js +0 -15
  100. package/dist/screenshoot.html +0 -7
  101. package/dist/screenshoot.js +0 -10688
@@ -63,13 +63,15 @@ class TextMessage extends _common.Com {
63
63
  return (0, _preact.h)("div", {
64
64
  class: "message-agent message-text--agent"
65
65
  }, (0, _preact.h)(_block.default, {
66
- block: block
66
+ block: block,
67
+ onLink: this.props.onLink
67
68
  }));
68
69
  }
69
70
  return (0, _preact.h)("div", {
70
71
  class: "message-user message-text--user"
71
72
  }, (0, _preact.h)(_block.default, {
72
- block: block
73
+ block: block,
74
+ onLink: this.props.onLink
73
75
  }));
74
76
  }
75
77
  }
@@ -949,6 +949,7 @@ class Widget extends _common.Com {
949
949
  return joined;
950
950
  }
951
951
  hasSentMessage(cid) {
952
+ if (this.userSent[cid]) return true;
952
953
  let convo = this.props.store.matchConvo(cid) || {};
953
954
  let joined = _index.default.find(convo.members, mem => {
954
955
  if (mem.type === 'bot') return true;
@@ -100,7 +100,33 @@ class Block extends _common.Com {
100
100
  return null;
101
101
  }
102
102
  let $body = null;
103
- if (_index.default.size(block.content)) $body = _index.default.map(block.content, block => this.renderBlock(block));else $body = ele.text;
103
+ if (_index.default.size(block.content)) {
104
+ $body = _index.default.map(block.content, block => this.renderBlock(block));
105
+ } else if (block.type === 'text') {
106
+ let $tags = _index.default.extractText(ele.text).map(tag => {
107
+ if (tag.type === 'link') {
108
+ let url = tag.text || '';
109
+ if (!url.startsWith('//') && !url.startsWith('https://') && !url.startsWith('http://') && !url.startsWith('data:')) {
110
+ url = '//' + url;
111
+ }
112
+ return (0, _preact.h)("a", {
113
+ href: url,
114
+ target: "_blank",
115
+ onClick: e => this.props.onLink(e, url)
116
+ }, tag.text);
117
+ }
118
+ if (tag.type === 'phone') return (0, _preact.h)("a", {
119
+ href: 'tel:' + tag.text
120
+ }, tag.text);
121
+ if (tag.type === 'email') return (0, _preact.h)("a", {
122
+ href: 'mailto:' + tag.text
123
+ }, tag.text);
124
+ return tag.text;
125
+ });
126
+ $body = $tags;
127
+ } else {
128
+ $body = ele.text;
129
+ }
104
130
  switch (ele.tag) {
105
131
  case 'div':
106
132
  return (0, _preact.h)("div", null, $body);
@@ -1109,6 +1109,16 @@ function sendToFBPixel(category, action, label) {
1109
1109
  });
1110
1110
  }
1111
1111
  function sendToGA(category, action, label) {
1112
+ if (window.sbz_no_gtag) {
1113
+ console.log('SKIPSENT.', category, action, label);
1114
+ return;
1115
+ }
1116
+ let dataLayer = window.dataLayer || [];
1117
+ dataLayer.push({
1118
+ event: category,
1119
+ event_action: action,
1120
+ event_label: label
1121
+ });
1112
1122
  if (window.gtag) window.gtag('event', category, {
1113
1123
  Action: action,
1114
1124
  Label: label
@@ -1131,12 +1141,6 @@ function sendEventToThirdParty(category, action, label) {
1131
1141
  }));
1132
1142
  sendToGA(category, action, label);
1133
1143
  sendToFBPixel(category, action, label);
1134
- let dataLayer = window.dataLayer || [];
1135
- dataLayer.push({
1136
- event: category,
1137
- event_action: action,
1138
- event_label: label
1139
- });
1140
1144
  }
1141
1145
  let cleanLocalStorage = () => {
1142
1146
  try {
@@ -191,7 +191,7 @@ function extractText(text) {
191
191
  phone.type = 'phone';
192
192
  var emoji = extractEmojis;
193
193
  emoji.type = 'emoji';
194
- return pipeExtracts(text, [email, link, phone, emoji]);
194
+ return pipeExtracts(text, [link, email, phone, emoji]);
195
195
  }
196
196
  function parseJSON(str) {
197
197
  try {
@@ -733,6 +733,38 @@ function checkRunConditions(freq, conds, lastrun, store) {
733
733
  if (!found) return false;
734
734
  }
735
735
  break;
736
+ case 'url_path':
737
+ let excludePaths = filter(cond.exclude_url_paths, url => norm(url));
738
+ if (size(excludePaths) > 0) {
739
+ let urlObj = new URL(window.location.href);
740
+ let pathname = urlObj.pathname || '';
741
+ if (typeof pathname === 'string' && pathname.endsWith('/')) {
742
+ pathname = pathname.substring(0, pathname.length - 1);
743
+ }
744
+ let found = find(excludePaths, url => {
745
+ if (typeof url === 'string' && url.endsWith('/')) {
746
+ url = url.substring(0, url.length - 1);
747
+ }
748
+ return pathname === url;
749
+ });
750
+ if (found) return false;
751
+ }
752
+ let paths = filter(cond.url_paths, url => norm(url));
753
+ if (size(paths) > 0) {
754
+ let urlObj = new URL(window.location.href);
755
+ let pathname = urlObj.pathname || '';
756
+ if (typeof pathname === 'string' && pathname.endsWith('/')) {
757
+ pathname = pathname.substring(0, pathname.length - 1);
758
+ }
759
+ let found = find(paths, url => {
760
+ if (typeof url === 'string' && url.endsWith('/')) {
761
+ url = url.substring(0, url.length - 1);
762
+ }
763
+ return pathname === url;
764
+ });
765
+ if (!found) return false;
766
+ }
767
+ break;
736
768
  case 'browser':
737
769
  if (size(cond.browsers) > 0) {
738
770
  var browsername = browserName();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.107",
3
+ "version": "4.1.109",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -14,24 +14,24 @@
14
14
  "@subiz/storage": "0.0.8",
15
15
  "@subiz/wsclient": "^4.0.27",
16
16
  "cookie_js": "1.4.2",
17
- "core-js": "^3.38.1",
17
+ "core-js": "^3.39.0",
18
18
  "css-loader": "5.2.7",
19
19
  "file-loader": "^6.2.0",
20
- "less": "^4.2.0",
20
+ "less": "^4.2.1",
21
21
  "less-loader": "^12.2.0",
22
22
  "preact": "10.19.3"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/cli": "^7.25.7",
26
- "@babel/core": "^7.25.7",
25
+ "@babel/cli": "^7.26.4",
26
+ "@babel/core": "^7.26.0",
27
27
  "@babel/plugin-proposal-class-properties": "^7.18.6",
28
- "@babel/plugin-transform-react-jsx": "^7.25.7",
29
- "@babel/preset-env": "^7.25.7",
28
+ "@babel/plugin-transform-react-jsx": "^7.25.9",
29
+ "@babel/preset-env": "^7.26.0",
30
30
  "babel-loader": "^9.2.1",
31
31
  "babel-plugin-syntax-jsx": "^6.18.0",
32
- "html-webpack-plugin": "^5.6.0",
33
- "puppeteer": "^23.5.0",
34
- "webpack": "^5.95.0",
32
+ "html-webpack-plugin": "^5.6.3",
33
+ "puppeteer": "^23.10.2",
34
+ "webpack": "^5.97.1",
35
35
  "webpack-bundle-analyzer": "^4.10.2",
36
36
  "webpack-cli": "^5.1.4",
37
37
  "webpack-dev-server": "^5.1.0"
@@ -55,13 +55,13 @@ export default class TextMessage extends Com {
55
55
  if (byType === 'agent') {
56
56
  return (
57
57
  <div class='message-agent message-text--agent'>
58
- <Block block={block} />
58
+ <Block block={block} onLink={this.props.onLink} />
59
59
  </div>
60
60
  )
61
61
  }
62
62
  return (
63
63
  <div class='message-user message-text--user'>
64
- <Block block={block} />
64
+ <Block block={block} onLink={this.props.onLink} />
65
65
  </div>
66
66
  )
67
67
  }
@@ -1029,6 +1029,7 @@ export default class Widget extends Com {
1029
1029
  }
1030
1030
 
1031
1031
  hasSentMessage(cid) {
1032
+ if (this.userSent[cid]) return true
1032
1033
  let convo = this.props.store.matchConvo(cid) || {}
1033
1034
  let joined = sb.find(convo.members, (mem) => {
1034
1035
  // sometime bot didnt update last_sent
@@ -108,8 +108,35 @@ export default class Block extends Com {
108
108
  }
109
109
 
110
110
  let $body = null
111
- if (sb.size(block.content)) $body = sb.map(block.content, (block) => this.renderBlock(block))
112
- else $body = ele.text
111
+ if (sb.size(block.content)) {
112
+ $body = sb.map(block.content, (block) => this.renderBlock(block))
113
+ } else if (block.type === 'text') {
114
+ let $tags = sb.extractText(ele.text).map((tag) => {
115
+ if (tag.type === 'link') {
116
+ let url = tag.text || ''
117
+ if (
118
+ !url.startsWith('//') &&
119
+ !url.startsWith('https://') &&
120
+ !url.startsWith('http://') &&
121
+ !url.startsWith('data:')
122
+ ) {
123
+ url = '//' + url
124
+ }
125
+
126
+ return (
127
+ <a href={url} target='_blank' onClick={(e) => this.props.onLink(e, url)}>
128
+ {tag.text}
129
+ </a>
130
+ )
131
+ }
132
+ if (tag.type === 'phone') return <a href={'tel:' + tag.text}>{tag.text}</a>
133
+ if (tag.type === 'email') return <a href={'mailto:' + tag.text}>{tag.text}</a>
134
+ return tag.text
135
+ })
136
+ $body = $tags
137
+ } else {
138
+ $body = ele.text
139
+ }
113
140
  switch (ele.tag) {
114
141
  case 'div':
115
142
  return <div>{$body}</div>
@@ -1306,7 +1306,13 @@ function sendToFBPixel(category, action, label) {
1306
1306
  }
1307
1307
 
1308
1308
  function sendToGA(category, action, label) {
1309
- // console.log('SENT.', category, action, label)
1309
+ if (window.sbz_no_gtag) {
1310
+ console.log('SKIPSENT.', category, action, label)
1311
+ return
1312
+ }
1313
+ let dataLayer = window.dataLayer || []
1314
+ dataLayer.push({event: category, event_action: action, event_label: label})
1315
+
1310
1316
  if (window.gtag) window.gtag('event', category, {Action: action, Label: label})
1311
1317
  if (window.ga && window.ga.getAll) {
1312
1318
  // only send gtag when ga is not available
@@ -1322,8 +1328,6 @@ function sendEventToThirdParty(category, action, label) {
1322
1328
  document.dispatchEvent(new CustomEvent('subiz', {detail: {category, action, label}}))
1323
1329
  sendToGA(category, action, label)
1324
1330
  sendToFBPixel(category, action, label)
1325
- let dataLayer = window.dataLayer || []
1326
- dataLayer.push({event: category, event_action: action, event_label: label})
1327
1331
  }
1328
1332
 
1329
1333
  let cleanLocalStorage = () => {
@@ -124,7 +124,8 @@ export function extractText(text) {
124
124
  var emoji = extractEmojis
125
125
  emoji.type = 'emoji'
126
126
 
127
- return pipeExtracts(text, [email, link, phone, emoji])
127
+ // extractLinks prefered over extractEmails becase some link is https://example.com/@something.vn would detect this is email over link
128
+ return pipeExtracts(text, [link, email, phone, emoji])
128
129
  }
129
130
 
130
131
  export function parseJSON(str) {
@@ -822,6 +823,40 @@ export function checkRunConditions(freq, conds, lastrun, store) {
822
823
  if (!found) return false
823
824
  }
824
825
  break
826
+ case 'url_path':
827
+ let excludePaths = filter(cond.exclude_url_paths, (url) => norm(url))
828
+ if (size(excludePaths) > 0) {
829
+ let urlObj = new URL(window.location.href)
830
+ let pathname = urlObj.pathname || ''
831
+ if (typeof pathname === 'string' && pathname.endsWith('/')) {
832
+ pathname = pathname.substring(0, pathname.length - 1)
833
+ }
834
+ let found = find(excludePaths, (url) => {
835
+ if (typeof url === 'string' && url.endsWith('/')) {
836
+ url = url.substring(0, url.length - 1)
837
+ }
838
+ return pathname === url
839
+ })
840
+ if (found) return false
841
+ }
842
+
843
+ // ignore empty url
844
+ let paths = filter(cond.url_paths, (url) => norm(url))
845
+ if (size(paths) > 0) {
846
+ let urlObj = new URL(window.location.href)
847
+ let pathname = urlObj.pathname || ''
848
+ if (typeof pathname === 'string' && pathname.endsWith('/')) {
849
+ pathname = pathname.substring(0, pathname.length - 1)
850
+ }
851
+ let found = find(paths, (url) => {
852
+ if (typeof url === 'string' && url.endsWith('/')) {
853
+ url = url.substring(0, url.length - 1)
854
+ }
855
+ return pathname === url
856
+ })
857
+ if (!found) return false
858
+ }
859
+ break
825
860
  case 'browser':
826
861
  if (size(cond.browsers) > 0) {
827
862
  var browsername = browserName()
package/dist/127.js DELETED
@@ -1,273 +0,0 @@
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
- }]);