@subiz/widget-v4 4.1.142 → 4.1.143

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 (43) hide show
  1. package/compiled_src/chatbox/Widget.js +2 -2
  2. package/compiled_src/store/store.js +1257 -0
  3. package/compiled_src/util/campaign.js +88 -0
  4. package/compiled_src/util/common.js +1294 -0
  5. package/compiled_src/util/common.test.js +496 -0
  6. package/compiled_src/util/extractor.test.js +299 -0
  7. package/compiled_src/util/gate.js +38 -0
  8. package/compiled_src/util/gate.test.js +18 -0
  9. package/compiled_src/util/index.js +20 -0
  10. package/compiled_src/util/mutex.js +31 -0
  11. package/compiled_src/util/op.js +55 -0
  12. package/compiled_src/util/pubsub.js +29 -0
  13. package/compiled_src/util/pubsub.test.js +35 -0
  14. package/dist/19680dc0775.278.js +1 -0
  15. package/dist/19680dc0775.app.js +1 -0
  16. package/dist/19680dc0775.form.html +1 -0
  17. package/dist/19680dc0775.form.js +1 -0
  18. package/dist/{1967c022bc1.index.html → 19680dc0775.index.html} +1 -1
  19. package/dist/{1967c022bc1.library.html → 19680dc0775.library.html} +1 -1
  20. package/dist/19680dc0775.library.js +1 -0
  21. package/dist/{1967c022bc1.preview.html → 19680dc0775.preview.html} +1 -1
  22. package/dist/19680dc0775.preview.js +1 -0
  23. package/dist/19680dc0775.webview.js +1 -0
  24. package/dist/278.js +1 -1
  25. package/dist/HASH +1 -1
  26. package/dist/screenshoot.js +79 -90
  27. package/package.json +1 -1
  28. package/src/chatbox/Widget.js +2 -2
  29. package/dist/1967c022bc1.278.js +0 -1
  30. package/dist/1967c022bc1.app.js +0 -1
  31. package/dist/1967c022bc1.form.html +0 -1
  32. package/dist/1967c022bc1.form.js +0 -1
  33. package/dist/1967c022bc1.library.js +0 -1
  34. package/dist/1967c022bc1.preview.js +0 -1
  35. package/dist/1967c022bc1.webview.js +0 -1
  36. /package/dist/{1967c022bc1.127.js → 19680dc0775.127.js} +0 -0
  37. /package/dist/{1967c022bc1.132.js → 19680dc0775.132.js} +0 -0
  38. /package/dist/{1967c022bc1.185.js → 19680dc0775.185.js} +0 -0
  39. /package/dist/{1967c022bc1.27.js → 19680dc0775.27.js} +0 -0
  40. /package/dist/{1967c022bc1.459.js → 19680dc0775.459.js} +0 -0
  41. /package/dist/{1967c022bc1.490.js → 19680dc0775.490.js} +0 -0
  42. /package/dist/{1967c022bc1.74.js → 19680dc0775.74.js} +0 -0
  43. /package/dist/{1967c022bc1.997.js → 19680dc0775.997.js} +0 -0
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 1967c022bc1
1
+ 19680dc0775
@@ -3793,8 +3793,8 @@ function jsonifyTextPlain(param, done) {
3793
3793
  _defineProperty(this, "list_provinces", () => this.apireq.get(`/accounts/${this.accid}/provinces`));
3794
3794
  _defineProperty(this, "list_districts", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`));
3795
3795
  _defineProperty(this, "list_wards", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`));
3796
- _defineProperty(this, "checkFormToken", token => this.api41.get(`/submissions/${token}`));
3797
- _defineProperty(this, "submitForm2", (token, data) => this.api41.post(`/submissions/${token}`, data));
3796
+ _defineProperty(this, "checkFormToken", (accid, token) => this.api41.addQuery('account-id', accid).get(`/submissions/${token}`));
3797
+ _defineProperty(this, "submitForm2", (accid, token, data) => this.api41.addQuery('account-id', accid).post(`/submissions/${token}`, data));
3798
3798
  _defineProperty(this, "suggest_address", keyword => this.apireq.setQuery({
3799
3799
  keyword: keyword
3800
3800
  }).get(`/accounts/${this.accid}/addresses`));
@@ -4849,8 +4849,8 @@ class Store {
4849
4849
  store_defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
4850
4850
  store_defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
4851
4851
  store_defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
4852
- store_defineProperty(this, "checkFormToken", token => this.api.checkFormToken(token));
4853
- store_defineProperty(this, "submitForm2", (token, data) => this.api.submitForm2(token, data));
4852
+ store_defineProperty(this, "checkFormToken", (accid, token) => this.api.checkFormToken(accid, token));
4853
+ store_defineProperty(this, "submitForm2", (accid, token, data) => this.api.submitForm2(accid, token, data));
4854
4854
  store_defineProperty(this, "sendPresence", util/* default */.A.throttle(async () => {
4855
4855
  if (this._die) return dieErr;
4856
4856
  await this.readyGate.entry();
@@ -7412,7 +7412,7 @@ class Form2 extends common/* Com */.Mw {
7412
7412
  });
7413
7413
  Form_defineProperty(this, "renderFormComponent", (com, idx) => {
7414
7414
  if (com.type === 'input') return this.renderField(com, idx);
7415
- if (com.type === 'submit_button') return this.renderSubmitButton(com, idx);
7415
+ if (com.type === 'button') return this.renderSubmitButton(com, idx);
7416
7416
  if (this.props.isSubmited) return;
7417
7417
  return (0,preact_module.h)("div", {
7418
7418
  class: "form-component form-component-block"
@@ -7424,8 +7424,8 @@ class Form2 extends common/* Com */.Mw {
7424
7424
  if (this.props.isSubmited) return;
7425
7425
  return (0,preact_module.h)("div", {
7426
7426
  class: "form-component form-component-submit-button"
7427
- }, (0,preact_module.h)("div", {
7428
- class: "form-control--valid-input--error"
7427
+ }, this.props.errorMessage && (0,preact_module.h)("div", {
7428
+ class: "form-control--valid-input--error mb-1"
7429
7429
  }, this.props.errorMessage), (0,preact_module.h)("div", null, (0,preact_module.h)("button", {
7430
7430
  class: "btn--start-convo",
7431
7431
  disabled: this.props.submiting
@@ -7434,7 +7434,7 @@ class Form2 extends common/* Com */.Mw {
7434
7434
  Form_defineProperty(this, "renderField", (com, idx) => {
7435
7435
  let errorMsg = this.state.errorFields[com.key];
7436
7436
  if (this.props.isSubmited) {
7437
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7437
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7438
7438
  val = val.value || '""';
7439
7439
  val = util/* default */.A.parseJSON(val);
7440
7440
  if (Array.isArray(val)) val = val.join(', ');
@@ -7461,7 +7461,7 @@ class Form2 extends common/* Com */.Mw {
7461
7461
  Form_defineProperty(this, "renderFieldTextInput", (com, idx) => {
7462
7462
  let cls = 'form-control';
7463
7463
  if (this.state.errorFields[com.key]) cls = 'form-control input--error';
7464
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7464
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7465
7465
  val = val.value || '""';
7466
7466
  val = util/* default */.A.parseJSON(val);
7467
7467
  return (0,preact_module.h)("input", {
@@ -7477,12 +7477,14 @@ class Form2 extends common/* Com */.Mw {
7477
7477
  });
7478
7478
  });
7479
7479
  Form_defineProperty(this, "renderFieldDateInput", (com, idx) => {
7480
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7480
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7481
7481
  val = val.value || '""';
7482
7482
  val = util/* default */.A.parseJSON(val);
7483
+ let cls = 'form-control';
7484
+ if (this.state.errorFields[com.key]) cls = 'form-control input--error';
7483
7485
  return (0,preact_module.h)("input", {
7484
7486
  ref: this[`${com.key}_input`],
7485
- class: "form-control",
7487
+ class: cls,
7486
7488
  type: "date",
7487
7489
  value: val,
7488
7490
  onInput: e => {
@@ -7492,7 +7494,7 @@ class Form2 extends common/* Com */.Mw {
7492
7494
  });
7493
7495
  });
7494
7496
  Form_defineProperty(this, "renderFieldRadioInput", (com, idx) => {
7495
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7497
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7496
7498
  val = val.value || '""';
7497
7499
  val = util/* default */.A.parseJSON(val);
7498
7500
  return util/* default */.A.map(com.input_options, (option, oidx) => {
@@ -7514,7 +7516,7 @@ class Form2 extends common/* Com */.Mw {
7514
7516
  });
7515
7517
  });
7516
7518
  Form_defineProperty(this, "renderFieldCheckboxInput", (com, idx) => {
7517
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7519
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7518
7520
  val = val.value || '[]';
7519
7521
  val = util/* default */.A.parseJSON(val);
7520
7522
  return util/* default */.A.map(com.input_options, (option, oidx) => {
@@ -7536,7 +7538,7 @@ class Form2 extends common/* Com */.Mw {
7536
7538
  });
7537
7539
  });
7538
7540
  Form_defineProperty(this, "renderFieldDropdownInput", (com, idx) => {
7539
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7541
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7540
7542
  val = val.value || '""';
7541
7543
  val = util/* default */.A.parseJSON(val);
7542
7544
  return (0,preact_module.h)("select", {
@@ -7553,7 +7555,7 @@ class Form2 extends common/* Com */.Mw {
7553
7555
  }));
7554
7556
  });
7555
7557
  Form_defineProperty(this, "renderFieldTextareaInput", (com, idx) => {
7556
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7558
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7557
7559
  val = val.value || '""';
7558
7560
  val = util/* default */.A.parseJSON(val);
7559
7561
  return (0,preact_module.h)("textarea", {
@@ -7580,7 +7582,7 @@ class Form2 extends common/* Com */.Mw {
7580
7582
  util/* default */.A.each(components, com => {
7581
7583
  if (com.type === 'input') {
7582
7584
  if (com.is_required) {
7583
- let val = util/* default */.A.find(this.props.formValues, f => f.key === com.key) || {};
7585
+ let val = util/* default */.A.find(this.props.submission.values, f => f.key === com.key) || {};
7584
7586
  val = val.value || '""';
7585
7587
  val = util/* default */.A.parseJSON(val);
7586
7588
  if (typeof val === 'string' && !val.trim()) {
@@ -7604,7 +7606,7 @@ class Form2 extends common/* Com */.Mw {
7604
7606
  return result;
7605
7607
  });
7606
7608
  Form_defineProperty(this, "onChangeValue", (key, v) => {
7607
- let formValues = this.props.formValues;
7609
+ let formValues = util/* default */.A.get(this.props.submission, 'values') || [];
7608
7610
  let f = util/* default */.A.find(formValues, field => field.key === key);
7609
7611
  if (!f) {
7610
7612
  formValues.push({
@@ -7635,7 +7637,7 @@ class Form2 extends common/* Com */.Mw {
7635
7637
  this.onChangeValue(key, v);
7636
7638
  }
7637
7639
  toggleCheckboxField(key, v) {
7638
- let currentValues = util/* default */.A.find(this.props.formValues, f => f.key === key) || {};
7640
+ let currentValues = util/* default */.A.find(this.props.submission.values, f => f.key === key) || {};
7639
7641
  currentValues = currentValues.value || '[]';
7640
7642
  currentValues = util/* default */.A.parseJSON(currentValues);
7641
7643
  if (currentValues.includes(v)) {
@@ -7648,6 +7650,7 @@ class Form2 extends common/* Com */.Mw {
7648
7650
  }
7649
7651
  render() {
7650
7652
  let components = util/* default */.A.get(this.props.formSetting, 'components') || [];
7653
+ let title = util/* default */.A.get(this.props.formSetting, 'title') || '';
7651
7654
  let cls = 'form-wrapper form';
7652
7655
  if (this.props.mode === 'attachment') cls += ' form-wrapper-attachment';
7653
7656
  return (0,preact_module.h)("div", {
@@ -7656,7 +7659,9 @@ class Form2 extends common/* Com */.Mw {
7656
7659
  class: "form-component"
7657
7660
  }, this.props.t('you_have_submitted_info_successfully')), (0,preact_module.h)("form", {
7658
7661
  onSubmit: this.onSubmit
7659
- }, util/* default */.A.map(components, this.renderFormComponent)));
7662
+ }, (0,preact_module.h)("div", {
7663
+ class: "form-component form-component-block"
7664
+ }, title), util/* default */.A.map(components, this.renderFormComponent)));
7660
7665
  }
7661
7666
  }
7662
7667
  ;// ./src/chatbox/FormAttachment2.js
@@ -7670,20 +7675,29 @@ function FormAttachment2_toPrimitive(t, r) { if ("object" != typeof t || !t) ret
7670
7675
  class FormAttachment extends common/* Com */.Mw {
7671
7676
  constructor(props) {
7672
7677
  super(props);
7673
- FormAttachment2_defineProperty(this, "state", {
7674
- formValues: [],
7675
- submiting: false,
7676
- isSubmited: false,
7677
- errorMessage: '',
7678
- step: 1
7678
+ FormAttachment2_defineProperty(this, "fetchFormSetting", () => {
7679
+ let attachments = util/* default */.A.get(this.props.ev, 'data.message.attachments') || [];
7680
+ let formAttachment = util/* default */.A.find(attachments, att => att.type === 'form');
7681
+ if (!formAttachment) return;
7682
+ let url = formAttachment.url;
7683
+ this.token = getUrlParameter(url, 'token');
7684
+ let formSetting = formAttachment.form || {};
7685
+ let submission = formAttachment.form_submission || {};
7686
+ let isSubmited = util/* default */.A.size(submission) > 0;
7687
+ this.setState({
7688
+ formSetting,
7689
+ submission,
7690
+ isSubmited
7691
+ });
7679
7692
  });
7680
7693
  FormAttachment2_defineProperty(this, "onChangeFormValues", values => {
7681
7694
  this.setState({
7682
- formValues: values
7695
+ submission: {
7696
+ values
7697
+ }
7683
7698
  });
7684
7699
  });
7685
7700
  FormAttachment2_defineProperty(this, "onSubmit", async () => {
7686
- console.log('submittttttt', this.state.formValues);
7687
7701
  this.setState({
7688
7702
  errorMessage: ''
7689
7703
  });
@@ -7691,72 +7705,41 @@ class FormAttachment extends common/* Com */.Mw {
7691
7705
  this.setState({
7692
7706
  submiting: true
7693
7707
  });
7694
- await util/* default */.A.sleep(1_500);
7708
+ let res = await this.props.store.submitForm2(this.props.store.matchAccount().id, this.token, this.state.submission);
7709
+ if (res.error) {
7710
+ this.setState({
7711
+ submiting: false,
7712
+ errorMessage: util/* default */.A.get(res, 'error.code')
7713
+ });
7714
+ return;
7715
+ }
7695
7716
  this.setState({
7696
7717
  submiting: false,
7697
7718
  isSubmited: true
7698
7719
  });
7699
7720
  });
7721
+ this.state = {
7722
+ submission: {},
7723
+ formSetting: {},
7724
+ submiting: false,
7725
+ errorMessage: '',
7726
+ isSubmited: false
7727
+ };
7728
+ }
7729
+ componentDidMount() {
7730
+ this.fetchFormSetting();
7700
7731
  }
7701
7732
  render() {
7702
- if (this.props.ev.id !== 'evshpgaeetsplfqprzmynrvrl') return;
7703
- const formSetting = {
7704
- components: [{
7705
- type: 'text',
7706
- text: 'Đặt lịch khám'
7707
- }, {
7708
- type: 'input',
7709
- key: 'fullname',
7710
- default_value: '234',
7711
- link_attribute: 'email',
7712
- placeholder: 'Nguyen Van A',
7713
- label: 'Họ và tên',
7714
- input_type: 'text',
7715
- is_required: true
7716
- }, {
7717
- type: 'input',
7718
- key: 'phone',
7719
- validation: 'phone',
7720
- label: 'SĐT',
7721
- input_type: 'text',
7722
- is_required: true
7723
- }, {
7724
- type: 'input',
7725
- label: 'Chọn ca',
7726
- is_required: true,
7727
- input_type: 'radio',
7728
- key: 'shift',
7729
- input_options: [{
7730
- value: 'Buổi sáng',
7731
- label: 'Buổi sáng'
7732
- }, {
7733
- value: 'Buổi chiều',
7734
- label: 'Buổi chiều'
7735
- }]
7736
- }, {
7737
- type: 'input',
7738
- label: 'Chọn ca 2',
7739
- is_required: true,
7740
- input_type: 'checkbox',
7741
- key: 'shift_2',
7742
- input_options: [{
7743
- value: 'Buổi sáng',
7744
- label: 'Buổi sáng'
7745
- }, {
7746
- value: 'Buổi chiều',
7747
- label: 'Buổi chiều'
7748
- }]
7749
- }, {
7750
- type: 'input',
7751
- key: 'schedule',
7752
- label: 'Chọn ngày',
7753
- is_required: true,
7754
- input_type: 'date'
7755
- }, {
7756
- type: 'submit_button',
7757
- label: 'Submit'
7758
- }]
7759
- };
7733
+ let attachments = util/* default */.A.get(this.props.ev, 'data.message.attachments') || [];
7734
+ let formAttachment = util/* default */.A.find(attachments, att => att.type === 'form');
7735
+ if (!formAttachment) return;
7736
+ const {
7737
+ submission,
7738
+ formSetting,
7739
+ errorMessage,
7740
+ isSubmited,
7741
+ submiting
7742
+ } = this.state;
7760
7743
  return (0,preact_module.h)("div", {
7761
7744
  onClick: e => e.stopPropagation()
7762
7745
  }, (0,preact_module.h)(Form2, {
@@ -7764,15 +7747,21 @@ class FormAttachment extends common/* Com */.Mw {
7764
7747
  formSetting: formSetting,
7765
7748
  mode: "attachment",
7766
7749
  t: this.props.t,
7767
- formValues: this.state.formValues,
7768
- errorMessage: this.state.errorMessage,
7769
- isSubmited: this.state.isSubmited,
7770
- submiting: this.state.submiting,
7750
+ submission: submission,
7751
+ errorMessage: errorMessage,
7752
+ isSubmited: isSubmited,
7753
+ submiting: submiting,
7771
7754
  onChangeFormValues: this.onChangeFormValues,
7772
7755
  onSubmit: this.onSubmit
7773
7756
  }));
7774
7757
  }
7775
7758
  }
7759
+ function getUrlParameter(url, name) {
7760
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
7761
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
7762
+ var results = regex.exec(url);
7763
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
7764
+ }
7776
7765
  ;// ./src/chatbox/FormSubmitAttachments.js
7777
7766
 
7778
7767
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.142",
3
+ "version": "4.1.143",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -501,9 +501,9 @@ export default class Widget extends Com {
501
501
  )
502
502
  } else if (sb.get(field, 'def.select') === 'checkbox') {
503
503
  $field = this.renderCheckboxField(field)
504
- } else if (sb.get(field, 'def.select') === 'radio') {
504
+ } else if (sb.get(field, 'def.select') === 'radio' && sb.size(sb.get(field, 'def.items', [])) < 5) {
505
505
  $field = this.renderRadioField(field)
506
- } else if (sb.get(field, 'def.select') === 'dropdown') {
506
+ } else if (sb.get(field, 'def.select') === 'dropdown' || sb.size(sb.get(field, 'def.items', [])) >= 5) {
507
507
  $field = this.renderDropdownField(field)
508
508
  } else {
509
509
  $field = (