@subiz/widget-v4 4.1.68 → 4.1.69

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.
@@ -142,13 +142,17 @@ class Rating extends _common.Com {
142
142
  var rated;
143
143
  var ended;
144
144
  let user = this.props.store.matchUser();
145
+ let foundUser = false;
145
146
  _index.default.map(this.props.store.listEvents(this.props.cid), ev => {
146
- if (_index.default.get(ev, 'type') === 'conversation_state_updated' && _index.default.get(ev, 'data.conversation.state') === 'ended') {
147
+ if (!ev || !ev.by) return;
148
+ if (ev.by.type == 'user') foundUser = true;
149
+ if (ev.type === 'conversation_state_updated' && _index.default.get(ev, 'data.conversation.state') === 'ended') {
147
150
  ended = ev;
148
151
  }
149
- if (_index.default.get(ev, 'type') === 'conversation_rating_requested') requested = ev;
150
- if (_index.default.get(ev, 'type') === 'conversation_rated' && _index.default.get(ev, 'by.id') === user.id) rated = ev;
152
+ if (ev.type === 'conversation_rating_requested') requested = ev;
153
+ if (ev.type === 'conversation_rated' && ev.by.id === user.id) rated = ev;
151
154
  });
155
+ if (!foundUser) return false;
152
156
  if (rated) return false;
153
157
  let accountSetting = this.props.plugin.chatbox;
154
158
  var auto = accountSetting.auto_request_rating && ended;
@@ -31,6 +31,20 @@ class Widget extends _common.Com {
31
31
  constructor(props) {
32
32
  super(props);
33
33
  _defineProperty(this, "msgInput", (0, _preact.createRef)());
34
+ _defineProperty(this, "formMounted", form => {
35
+ let formData = this.fillForm(form);
36
+ formData['question'] = {
37
+ key: 'question',
38
+ is_required: true,
39
+ label: this.props.t.i18n(_index.default.get(form, `i18n_question_label`, {})) || form.question_label,
40
+ type: 'text',
41
+ value: this.state.quickReplyMessage.text
42
+ };
43
+ this.setState({
44
+ formData
45
+ });
46
+ if (!this.props.store.isMobile()) this.focusInput();
47
+ });
34
48
  _defineProperty(this, "sendMessage", async message => {
35
49
  let hasPostback = _index.default.find(message.attachments, att => att.type === 'postback');
36
50
  if (this.isFormRequired() && hasPostback) {
@@ -308,20 +322,6 @@ class Widget extends _common.Com {
308
322
  });
309
323
  if (!this.props.store.isMobile()) this.focusInput();
310
324
  }
311
- formMounted(form) {
312
- let formData = this.fillForm(form);
313
- formData['question'] = {
314
- key: 'question',
315
- is_required: true,
316
- label: this.props.t.i18n(_index.default.get(form, `i18n_question_label`, {})) || form.question_label,
317
- type: 'text',
318
- value: this.state.quickReplyMessage.text
319
- };
320
- this.setState({
321
- formData
322
- });
323
- if (!this.props.store.isMobile()) this.focusInput();
324
- }
325
325
  onBooleanChange(key, e) {
326
326
  this.wasFormInputed = true;
327
327
  let formData = _index.default.cloneDeep(this.state.formData);
@@ -595,8 +595,9 @@ class Widget extends _common.Com {
595
595
  return (0, _preact.h)("div", {
596
596
  class: "widget-body"
597
597
  }, (0, _preact.h)(FormMounter, {
598
+ key: form._updated,
598
599
  form: form,
599
- onMount: f => this.formMounted(f)
600
+ onMount: this.formMounted
600
601
  }), (0, _preact.h)("div", {
601
602
  class: "widget-body--content flex-grow-1 pl-3 pr-3 d-flex flex-column"
602
603
  }, (0, _preact.h)("div", {
@@ -252,48 +252,39 @@ class PluginMgr {
252
252
  }
253
253
  getCurrentView() {
254
254
  let chatbox = this.findChatbox();
255
- if (!chatbox) return;
256
- return chatbox.call('getCurrentView');
255
+ if (chatbox) return chatbox.call('getCurrentView');
257
256
  }
258
257
  showCurrentChatbox(p) {
259
258
  let chatbox = this.findChatbox();
260
- if (!chatbox) return;
261
- chatbox.call('showWidget', p);
259
+ if (chatbox) return chatbox.call('showWidget', p);
262
260
  }
263
261
  showCurrentGreeting() {
264
262
  let chatbox = this.findChatbox();
265
- if (!chatbox) return;
266
- chatbox.call('showGreeting');
263
+ if (chatbox) return chatbox.call('showGreeting');
267
264
  }
268
265
  hideCurrentGreeting() {
269
266
  let chatbox = this.findChatbox();
270
- if (!chatbox) return;
271
- chatbox.call('hideGreeting');
267
+ if (chatbox) return chatbox.call('hideGreeting');
272
268
  }
273
269
  hideCurrentChatbox() {
274
270
  let chatbox = this.findChatbox();
275
- if (!chatbox) return;
276
- chatbox.call('hideWidget');
271
+ if (chatbox) return chatbox.call('hideWidget');
277
272
  }
278
273
  forceUpdateLang(id) {
279
274
  let plugin = this.pluginM[id];
280
- if (!plugin) return;
281
- plugin.forceDownloadLanguage();
275
+ if (plugin) return plugin.forceDownloadLanguage();
282
276
  }
283
277
  forceRunPopup(id) {
284
278
  let plugin = this.pluginM[id];
285
- if (!plugin) return;
286
- plugin.forceRunPopup(id);
279
+ if (plugin) return plugin.forceRunPopup(id);
287
280
  }
288
281
  setPluginLocale(id, locale) {
289
282
  let plugin = this.pluginM[id];
290
- if (!plugin) return;
291
- return plugin.setLocale(locale);
283
+ if (plugin) return plugin.setLocale(locale);
292
284
  }
293
285
  setCurrentChatboxLocale(locale) {
294
286
  let chatbox = this.findChatbox();
295
- if (!chatbox) return;
296
- chatbox.setLocale(locale);
287
+ if (chatbox) return chatbox.setLocale(locale);
297
288
  }
298
289
  destroy() {
299
290
  _index.default.map(this.pluginM, (conf, id) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.68",
3
+ "version": "4.1.69",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -117,14 +117,18 @@ export default class Rating extends Com {
117
117
  var ended
118
118
 
119
119
  let user = this.props.store.matchUser()
120
+ // user must send message
121
+ let foundUser = false
120
122
  sb.map(this.props.store.listEvents(this.props.cid), (ev) => {
121
- if (sb.get(ev, 'type') === 'conversation_state_updated' && sb.get(ev, 'data.conversation.state') === 'ended') {
123
+ if (!ev || !ev.by) return
124
+ if (ev.by.type == 'user') foundUser = true
125
+ if (ev.type === 'conversation_state_updated' && sb.get(ev, 'data.conversation.state') === 'ended') {
122
126
  ended = ev
123
127
  }
124
- if (sb.get(ev, 'type') === 'conversation_rating_requested') requested = ev
125
- if (sb.get(ev, 'type') === 'conversation_rated' && sb.get(ev, 'by.id') === user.id) rated = ev
128
+ if (ev.type === 'conversation_rating_requested') requested = ev
129
+ if (ev.type === 'conversation_rated' && ev.by.id === user.id) rated = ev
126
130
  })
127
-
131
+ if (!foundUser) return false
128
132
  if (rated) return false
129
133
  let accountSetting = this.props.plugin.chatbox
130
134
  var auto = accountSetting.auto_request_rating && ended
@@ -93,7 +93,6 @@ export default class Widget extends Com {
93
93
  // choose form to display
94
94
  let accountSetting = this.props.plugin.chatbox || {}
95
95
  let acc = this.props.store.matchAccount() || {}
96
-
97
96
  let submitLabel = this.props.t('prechat_form_btn')
98
97
  if (sb.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form
99
98
  let offlineEnabled = sb.get(accountSetting, 'offline_form.enabled')
@@ -247,7 +246,7 @@ export default class Widget extends Com {
247
246
  if (!this.props.store.isMobile()) this.focusInput()
248
247
  }
249
248
 
250
- formMounted(form) {
249
+ formMounted = (form) => {
251
250
  // waiting for element to be created
252
251
  let formData = this.fillForm(form)
253
252
  formData['question'] = {
@@ -578,7 +577,7 @@ export default class Widget extends Com {
578
577
 
579
578
  return (
580
579
  <div class='widget-body'>
581
- <FormMounter form={form} onMount={(f) => this.formMounted(f)} />
580
+ <FormMounter key={form._updated} form={form} onMount={this.formMounted} />
582
581
  <div class='widget-body--content flex-grow-1 pl-3 pr-3 d-flex flex-column'>
583
582
  <div class='flex-grow-1'>
584
583
  <div class='form mt-3 pl-3 pr-3 pt-3 pb-3 d-flex flex-column'>
package/src/plugin.js CHANGED
@@ -284,56 +284,47 @@ export default class PluginMgr {
284
284
 
285
285
  getCurrentView() {
286
286
  let chatbox = this.findChatbox()
287
- if (!chatbox) return
288
- return chatbox.call('getCurrentView')
287
+ if (chatbox) return chatbox.call('getCurrentView')
289
288
  }
290
289
 
291
290
  showCurrentChatbox(p) {
292
291
  let chatbox = this.findChatbox()
293
- if (!chatbox) return
294
- chatbox.call('showWidget', p)
292
+ if (chatbox) return chatbox.call('showWidget', p)
295
293
  }
296
294
 
297
295
  showCurrentGreeting() {
298
296
  let chatbox = this.findChatbox()
299
- if (!chatbox) return
300
- chatbox.call('showGreeting')
297
+ if (chatbox) return chatbox.call('showGreeting')
301
298
  }
302
299
 
303
300
  hideCurrentGreeting() {
304
301
  let chatbox = this.findChatbox()
305
- if (!chatbox) return
306
- chatbox.call('hideGreeting')
302
+ if (chatbox) return chatbox.call('hideGreeting')
307
303
  }
308
304
 
309
305
  hideCurrentChatbox() {
310
306
  let chatbox = this.findChatbox()
311
- if (!chatbox) return
312
- chatbox.call('hideWidget')
307
+ if (chatbox) return chatbox.call('hideWidget')
313
308
  }
314
309
 
315
310
  forceUpdateLang(id) {
316
311
  let plugin = this.pluginM[id]
317
- if (!plugin) return
318
- plugin.forceDownloadLanguage()
312
+ if (plugin) return plugin.forceDownloadLanguage()
319
313
  }
320
314
 
321
315
  forceRunPopup(id) {
322
316
  let plugin = this.pluginM[id]
323
- if (!plugin) return
324
- plugin.forceRunPopup(id)
317
+ if (plugin) return plugin.forceRunPopup(id)
325
318
  }
326
319
 
327
320
  setPluginLocale(id, locale) {
328
321
  let plugin = this.pluginM[id]
329
- if (!plugin) return
330
- return plugin.setLocale(locale)
322
+ if (plugin) return plugin.setLocale(locale)
331
323
  }
332
324
 
333
325
  setCurrentChatboxLocale(locale) {
334
326
  let chatbox = this.findChatbox()
335
- if (!chatbox) return
336
- chatbox.setLocale(locale)
327
+ if (chatbox) return chatbox.setLocale(locale)
337
328
  }
338
329
 
339
330
  destroy() {