@subiz/widget-v4 4.1.190 → 4.1.195

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 (120) hide show
  1. package/assets/less/chatbox.less +0 -1
  2. package/assets/less/message.less +71 -4
  3. package/compiled_src/chatbox/Event.js +38 -8
  4. package/compiled_src/chatbox/Events.js +20 -0
  5. package/compiled_src/chatbox/FileAttachments.js +36 -4
  6. package/compiled_src/chatbox/ImageAttachments.js +31 -4
  7. package/compiled_src/chatbox/QuoteMessage.js +99 -0
  8. package/compiled_src/chatbox/Rating.js +4 -0
  9. package/compiled_src/chatbox/TextMessage.js +49 -4
  10. package/compiled_src/chatbox/Widget.js +43 -1
  11. package/compiled_src/store/api.js +2 -0
  12. package/compiled_src/store/store.js +44 -2
  13. package/compiled_src/util/common.js +13 -1
  14. package/dist/127.js +273 -0
  15. package/dist/132.js +2802 -0
  16. package/dist/185.js +1827 -0
  17. package/dist/19b74edd3c9.127.js +1 -0
  18. package/dist/19b74edd3c9.132.js +1 -0
  19. package/dist/19b74edd3c9.185.js +1 -0
  20. package/dist/19b74edd3c9.27.js +1 -0
  21. package/dist/19b74edd3c9.278.js +1 -0
  22. package/dist/19b74edd3c9.339.js +1 -0
  23. package/dist/19b74edd3c9.459.js +1 -0
  24. package/dist/19b74edd3c9.490.js +1 -0
  25. package/dist/19b74edd3c9.74.js +1 -0
  26. package/dist/19b74edd3c9.997.js +1 -0
  27. package/dist/19b74edd3c9.app.js +1 -0
  28. package/dist/19b74edd3c9.chat.html +1 -0
  29. package/dist/19b74edd3c9.chat.js +1 -0
  30. package/dist/19b74edd3c9.form.html +1 -0
  31. package/dist/19b74edd3c9.form.js +1 -0
  32. package/dist/19b74edd3c9.index.html +72 -0
  33. package/dist/19b74edd3c9.library.html +72 -0
  34. package/dist/19b74edd3c9.library.js +1 -0
  35. package/dist/19b74edd3c9.preview.html +759 -0
  36. package/dist/19b74edd3c9.preview.js +1 -0
  37. package/dist/19b74edd3c9.webview.js +1 -0
  38. package/dist/27.js +35 -0
  39. package/dist/459.js +35 -0
  40. package/dist/490.js +305 -0
  41. package/dist/74.js +372 -0
  42. package/dist/997.js +35 -0
  43. package/dist/HASH +1 -0
  44. package/dist/assets/img/Facebook.64607ec.png +0 -0
  45. package/dist/assets/img/Zalo.6845707.png +0 -0
  46. package/dist/assets/img/award1a.1a58e10.png +0 -0
  47. package/dist/assets/img/award3a.3b74423.png +0 -0
  48. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  49. package/dist/assets/img/award5.39eb7ae.png +0 -0
  50. package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
  51. package/dist/assets/img/caret.998eb8f.svg +1 -0
  52. package/dist/assets/img/convos_empty.2353007.svg +72 -0
  53. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  54. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  55. package/dist/assets/img/done_gray.d7e8203.svg +4 -0
  56. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  57. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  58. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  59. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  60. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  61. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  62. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  63. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  64. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  65. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  66. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  67. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  68. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  69. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  70. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  71. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  72. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  73. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  74. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  75. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  76. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  77. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  78. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  79. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  80. package/dist/assets/img/empty.29bed2d.svg +23 -0
  81. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  82. package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
  83. package/dist/assets/img/external-link.90577cc.svg +1 -0
  84. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  85. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  86. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  87. package/dist/assets/img/image_default.be0698b.png +0 -0
  88. package/dist/assets/img/info.ebce7ea.svg +1 -0
  89. package/dist/assets/img/loader.37000a7.svg +1 -0
  90. package/dist/assets/img/loading_static.a27f0ac.svg +10 -0
  91. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  92. package/dist/assets/img/main-service2.9b99549.png +0 -0
  93. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  94. package/dist/assets/img/package.8d37d0f.svg +5 -0
  95. package/dist/assets/img/package_fade.763c001.svg +1 -0
  96. package/dist/assets/img/rating--average.1ea492c.svg +12 -0
  97. package/dist/assets/img/rating--great.e3d712e.svg +16 -0
  98. package/dist/assets/img/rating--poor.2938a25.svg +12 -0
  99. package/dist/assets/img/search.f9705ff.svg +1 -0
  100. package/dist/assets/img/send.6db52a9.svg +3 -0
  101. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  102. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  103. package/dist/assets/img/stars_v2.79cf728.png +0 -0
  104. package/dist/assets/img/subiz-mono.8fbc067.svg +3 -0
  105. package/dist/assets/img/x.26fdfa3.svg +5 -0
  106. package/dist/malicious-app.js +17 -0
  107. package/dist/screenshoot.html +7 -0
  108. package/dist/screenshoot.js +13015 -0
  109. package/package.json +8 -8
  110. package/src/chatbox/Event.js +49 -9
  111. package/src/chatbox/Events.js +21 -1
  112. package/src/chatbox/FileAttachments.js +31 -4
  113. package/src/chatbox/ImageAttachments.js +26 -3
  114. package/src/chatbox/QuoteMessage.js +94 -0
  115. package/src/chatbox/Rating.js +5 -0
  116. package/src/chatbox/TextMessage.js +50 -2
  117. package/src/chatbox/Widget.js +52 -0
  118. package/src/store/api.js +3 -0
  119. package/src/store/store.js +50 -1
  120. package/src/util/common.js +19 -1
@@ -32,6 +32,43 @@ class Widget extends _common.Com {
32
32
  constructor(props) {
33
33
  super(props);
34
34
  _defineProperty(this, "msgInput", (0, _preact.createRef)());
35
+ _defineProperty(this, "findMissingRTMessage", async started => {
36
+ let messageSentDict = this.props.store.listAgentRealtimeMessageSent();
37
+ let res1 = await this.props.store.sbzListConversations();
38
+ let conversions = _index.default.get(res1, 'body.conversations') || [];
39
+ let cids = _index.default.map(conversions, convo => convo.id);
40
+ let promises = _index.default.map(cids, cid => this.props.store.sbzListMessages(cid));
41
+ let msgReses = await Promise.all(promises);
42
+ _index.default.map(msgReses, msgRes => {
43
+ let messages = _index.default.get(msgRes, 'body') || [];
44
+ _index.default.map(messages, ev => {
45
+ if (ev.created < started) return;
46
+ if (ev.type !== 'message_sent') return;
47
+ if (_index.default.get(ev, 'by.type') === 'user') return;
48
+ console.log('check ev pass condition', ev);
49
+ if (!messageSentDict[ev.id]) {
50
+ this.props.store.sendBugReport('[WIDGET ' + accid + '] Missing agent message sent evid ' + ev.id + ', cid ' + _index.default.convoOfEv(ev));
51
+ }
52
+ });
53
+ });
54
+ });
55
+ _defineProperty(this, "debugRTAgentMessageSent", async () => {
56
+ try {
57
+ let debugAccountIds = this.props.store.matchDebugAccountIds();
58
+ let accid = _index.default.get(this.props.store.matchAccount(), 'id');
59
+ if (!debugAccountIds.includes(accid)) return;
60
+ console.log('START check RT agent message with BE source');
61
+ let started = Date.now();
62
+ this.findMissingRTMessage(started);
63
+ for (let i = 0; i < 100_000; i++) {
64
+ await _index.default.sleep(120_000);
65
+ console.log('LOOP check RT agent message with BE source', i);
66
+ this.findMissingRTMessage(started);
67
+ }
68
+ } catch (err) {
69
+ this.props.store.sendBugReport(`debugRTAgentMessageSent ERROR ${err.stack}`);
70
+ }
71
+ });
35
72
  _defineProperty(this, "formMounted", form => {
36
73
  let formData = this.fillForm(form);
37
74
  if (form.question_required || this.state.quickReplyMessage.text) {
@@ -65,6 +102,9 @@ class Widget extends _common.Com {
65
102
  });
66
103
  let botid = cid.split('_')[0].slice(7);
67
104
  let oldconvo = this.props.store.matchConvo(this.props.cid) || {};
105
+ let greeting_msg = _index.default.find(oldconvo.events, ev => {
106
+ return ev.type == 'message_sent' && ev.by && ev.by.type == 'bot';
107
+ });
68
108
  const {
69
109
  convo,
70
110
  error
@@ -78,7 +118,8 @@ class Widget extends _common.Com {
78
118
  bot_version: oldconvo.bot_version
79
119
  }],
80
120
  initial_by: this.props.store.matchUser().id,
81
- is_testing: oldconvo.is_testing
121
+ is_testing: oldconvo.is_testing,
122
+ greeting_message: greeting_msg
82
123
  });
83
124
  if (_creating != this._creating) return;
84
125
  if (error) {
@@ -184,6 +225,7 @@ class Widget extends _common.Com {
184
225
  componentDidMount() {
185
226
  if (!this.props.store.isMobile()) this.focusInput();
186
227
  this.updateFormDataFields();
228
+ this.debugRTAgentMessageSent();
187
229
  }
188
230
  applyMessage(text) {
189
231
  this.focusInput(text);
@@ -45,6 +45,7 @@ let trackResponseFn = (param, done) => {
45
45
  };
46
46
  class _default {
47
47
  constructor(ApiURL, FileURL) {
48
+ _defineProperty(this, "sendBugReport", str => this.bugReq.post('/bugs', str));
48
49
  _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
49
50
  _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
50
51
  _defineProperty(this, "ajax", ajax);
@@ -199,6 +200,7 @@ class _default {
199
200
  this.refreshLock = new _index.default.Mutex();
200
201
  this.FileURL = FileURL;
201
202
  this.ApiURL = ApiURL;
203
+ this.bugReq = ajax.setBaseUrl('https://api5.subiz.com.vn/4.1').setContentType('text/plain');
202
204
  this.api41 = ajax.setBaseUrl('https://api.sbz.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).beforeHook(trackRequestFn).setParser('json');
203
205
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).setParser('json').beforeHook(trackRequestFn).beforeHook((param, done) => {
204
206
  if (this.token_generator) {
@@ -24,6 +24,7 @@ cookie.defaults.expires = 3650;
24
24
  let memlocalStorage = require('./inmem_localstorage.js');
25
25
  const MAX_CONVO = 20;
26
26
  const page_loaded = _index.default.Date.now();
27
+ const DEBUG_ACCOUNT_IDS = ['acqsulrowbxiugvginhw', 'acryguzgwxmamhzmqlyx'];
27
28
  class Store {
28
29
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi) {
29
30
  _defineProperty(this, "inmem", false);
@@ -132,6 +133,21 @@ class Store {
132
133
  }
133
134
  return this._doFetchMsg(convoid);
134
135
  });
136
+ _defineProperty(this, "reloadConvoEvents", async convoid => {
137
+ await this.chain.reload(convoid, () => {
138
+ return [[], ''];
139
+ });
140
+ let {
141
+ error
142
+ } = await this.chain.fetchMore(convoid, 150, async (type, anchor, limit) => {
143
+ let [events, newanchor, error, outofmsg] = await this.listmessageapi(type, anchor, limit);
144
+ if (outofmsg) this.outofmsgM[convoid] = true;
145
+ return [events, newanchor, error];
146
+ });
147
+ return {
148
+ error
149
+ };
150
+ });
135
151
  _defineProperty(this, "_doFetchMsg", async convoid => {
136
152
  let {
137
153
  error
@@ -174,12 +190,24 @@ class Store {
174
190
  _defineProperty(this, "now", () => _index.default.Date.now() + this.timeDiff);
175
191
  _defineProperty(this, "seenQueue", []);
176
192
  _defineProperty(this, "matchTrafficSource", () => this.kv.match('traffic_source'));
193
+ _defineProperty(this, "sendBugReport", str => this.api.sendBugReport(str));
194
+ _defineProperty(this, "matchDebugAccountIds", () => DEBUG_ACCOUNT_IDS);
195
+ _defineProperty(this, "sbzListConversations", () => {
196
+ return this.api.listConversations();
197
+ });
198
+ _defineProperty(this, "sbzListMessages", cid => {
199
+ return this.api.listMessages(cid, 100, '');
200
+ });
201
+ _defineProperty(this, "listAgentRealtimeMessageSent", () => {
202
+ return this.agent_rt_message_sent_dict;
203
+ });
177
204
  _defineProperty(this, "_alreadyReceived", {});
178
205
  _defineProperty(this, "_typing", _index.default.throttle(convoid => this.api.sendTyping(convoid), 3000, {
179
206
  trailing: false
180
207
  }));
181
208
  _defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
182
209
  _defineProperty(this, "onWidgetClose", (o, cb) => this.pubsub.on2(o, 'sbz_close_widget', cb));
210
+ _defineProperty(this, "onMessageUpdated", (o, cb) => this.pubsub.on2(o, 'message_updated', cb));
183
211
  _defineProperty(this, "seenConvo", id => {
184
212
  if (!id || id === 'create') return;
185
213
  this.seenQueue.push(id);
@@ -208,6 +236,7 @@ class Store {
208
236
  this.CONNECTION_CHECK_INTERVAL = 3000;
209
237
  this.reconnectTimestamp = 0;
210
238
  this.g_sync = {};
239
+ this.agent_rt_message_sent_dict = {};
211
240
  this._die = false;
212
241
  this.forceDevice = null;
213
242
  this.forcePlugins = {};
@@ -533,6 +562,7 @@ class Store {
533
562
  }
534
563
  async _initResource(accid, auth, realtimep) {
535
564
  this.g_sync = {};
565
+ this._current_acc_id = accid;
536
566
  let user = await this.api.setAuth(auth);
537
567
  if (typeof sbz_info != 'undefined') sbz_info.store_7 = true;
538
568
  if (user.error) {
@@ -635,7 +665,7 @@ class Store {
635
665
  }, 1000);
636
666
  }
637
667
  async reconnectWs(accid, userid) {
638
- await this.realtime.subscribe([`conversation_state_updated.account.${accid}.user.${userid}`, `conversation_joined.account.${accid}.user.${userid}`, `conversation_typing.account.${accid}.user.${userid}`, `message_sent.account.${accid}.user.${userid}`, `message_pong.account.${accid}.user.${userid}`, `conversation_rating_requested.account.${accid}.user.${userid}`, `conversation_rated.account.${accid}.user.${userid}`]);
668
+ await this.realtime.subscribe([`conversation_state_updated.account.${accid}.user.${userid}`, `conversation_joined.account.${accid}.user.${userid}`, `conversation_typing.account.${accid}.user.${userid}`, `message_sent.account.${accid}.user.${userid}`, `message_pong.account.${accid}.user.${userid}`, `conversation_rating_requested.account.${accid}.user.${userid}`, `conversation_rated.account.${accid}.user.${userid}`, `conversation_events.account.${accid}.user.${userid}`]);
639
669
  await this.readyGate.entry();
640
670
  }
641
671
  async reconnect(p) {
@@ -769,7 +799,15 @@ class Store {
769
799
  await this._onWs(ev);
770
800
  this.wsGate.open();
771
801
  }
802
+ handleLogCompare(ev) {
803
+ if (!DEBUG_ACCOUNT_IDS.includes(this._current_acc_id)) return;
804
+ if (ev.type !== 'message_sent') return;
805
+ let byType = _index.default.get(ev, 'by.type');
806
+ if (byType === 'user') return;
807
+ this.agent_rt_message_sent_dict[ev.id] = ev;
808
+ }
772
809
  async _onWs(ev) {
810
+ this.handleLogCompare(ev);
773
811
  if (this._die) return;
774
812
  if (!ev || !ev.type) return;
775
813
  ev.created = _index.default.getMs(ev.created);
@@ -781,6 +819,10 @@ class Store {
781
819
  this._setUser(user);
782
820
  return;
783
821
  }
822
+ if (ev.type === 'message_deleted') {
823
+ this.pubsub.publish('message_updated', ev);
824
+ return;
825
+ }
784
826
  let user = this.cache.match('user') || {};
785
827
  let cid = _index.default.convoOfEv(ev);
786
828
  let convo;
@@ -798,7 +840,7 @@ class Store {
798
840
  this._setConvo(convo);
799
841
  }
800
842
  }
801
- if (cid.startsWith('cslight')) {
843
+ if (cid && cid.startsWith('cslight')) {
802
844
  convo = this.lightConvos[cid];
803
845
  if (!convo) return;
804
846
  convo.events.push(ev);
@@ -302,6 +302,7 @@ function convoToEv(convoid, ev) {
302
302
  switch (ev.type) {
303
303
  case 'message_sent':
304
304
  case 'message_updated':
305
+ case 'message_deleted':
305
306
  case 'message_pong':
306
307
  return op.set(ev, 'data.message.conversation_id', convoid);
307
308
  case 'ticket_updated':
@@ -1330,5 +1331,16 @@ function isEmptyBlock(block) {
1330
1331
  }
1331
1332
  function isEmptyMessage(msg) {
1332
1333
  if (!msg) return true;
1333
- if (!msg.text && isEmptyBlock(msg.block) && !size(msg.attachments)) return true;
1334
+ if (!msg.text && isEmptyBlock(msg.block) && isEmptyAttachment(msg)) return true;
1335
+ return false;
1336
+ }
1337
+ function isEmptyAttachment(msg) {
1338
+ if (!msg) return true;
1339
+ if (!size(msg.attachments)) return true;
1340
+ return size(filter(msg.attachments, att => {
1341
+ if (att.type == 'quick_replies') {
1342
+ return size(filter(att.quick_replies, r => size(trim(r)) > 0)) > 0;
1343
+ }
1344
+ return true;
1345
+ })) == 0;
1334
1346
  }
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
+ }]);