@subiz/widget-v4 4.1.129 → 4.1.131

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.
@@ -145,18 +145,18 @@ body div#sbz92 {
145
145
  .text-muted {
146
146
  .color(@text-muted);
147
147
  }
148
- .text-lg {
149
- font-size: 18px;
150
- }
151
- .text-xl {
152
- font-size: 20px;
153
- }
154
- .text-center {
155
- text-align: center;
156
- }
157
- .text-danger {
158
- color: #ea3d2f;
159
- }
148
+ .text-lg {
149
+ font-size: 18px;
150
+ }
151
+ .text-xl {
152
+ font-size: 20px;
153
+ }
154
+ .text-center {
155
+ text-align: center;
156
+ }
157
+ .text-danger {
158
+ color: #ea3d2f;
159
+ }
160
160
 
161
161
  .text-italic {
162
162
  font-style: italic;
@@ -227,6 +227,9 @@ body div#sbz92 {
227
227
  .mb-2 {
228
228
  margin-bottom: @spacer2;
229
229
  }
230
+ .mb-1 {
231
+ margin-bottom: @spacer1;
232
+ }
230
233
 
231
234
  .muted {
232
235
  .color(@text-muted);
@@ -431,9 +431,9 @@ select {
431
431
  margin-bottom: 0;
432
432
  }
433
433
 
434
- &.submitted {
435
- margin-bottom: 8px;
436
- }
434
+ &.submitted {
435
+ margin-bottom: 8px;
436
+ }
437
437
  }
438
438
 
439
439
  .form-wrapper.form {
@@ -457,13 +457,14 @@ select {
457
457
  .form-wrapper.form-wrapper-attachment.form {
458
458
  padding: 12px 15px;
459
459
  margin-top: 5px;
460
+ box-shadow: 0 0 0 1px #eeeeee;
460
461
 
461
462
  input[type='text'].form-control,
462
463
  input[type='number'].form-control,
463
464
  input[type='date'].form-control,
464
465
  select.form-control,
465
466
  textarea.form-control {
466
- padding: 6px 15px;
467
+ padding: 6px 10px;
467
468
  }
468
469
 
469
470
  .form-component {
@@ -15,6 +15,21 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
15
15
  class FormAttachment extends _common.Com {
16
16
  constructor(props) {
17
17
  super(props);
18
+ _defineProperty(this, "fetchFormSetting", () => {
19
+ let attachments = _index.default.get(this.props.ev, 'data.message.attachments') || [];
20
+ let formAttachment = _index.default.find(attachments, att => att.type === 'form');
21
+ if (!formAttachment) return;
22
+ let url = formAttachment.url;
23
+ this.token = getUrlParameter(url, 'token');
24
+ let formSetting = formAttachment.form || {};
25
+ let submission = formAttachment.form_submission || {};
26
+ let isSubmited = _index.default.size(submission) > 0;
27
+ this.setState({
28
+ formSetting,
29
+ submission,
30
+ isSubmited
31
+ });
32
+ });
18
33
  _defineProperty(this, "onChangeFormValues", values => {
19
34
  this.setState({
20
35
  submission: {
@@ -30,7 +45,7 @@ class FormAttachment extends _common.Com {
30
45
  this.setState({
31
46
  submiting: true
32
47
  });
33
- let res = await this.props.store.submitForm2(this.props.token, this.state.submission);
48
+ let res = await this.props.store.submitForm2(this.props.store.matchAccount().id, this.token, this.state.submission);
34
49
  if (res.error) {
35
50
  this.setState({
36
51
  submiting: false,
@@ -45,22 +60,26 @@ class FormAttachment extends _common.Com {
45
60
  });
46
61
  this.state = {
47
62
  submission: {},
63
+ formSetting: {},
48
64
  submiting: false,
49
65
  errorMessage: '',
50
66
  isSubmited: false
51
67
  };
52
68
  }
69
+ componentDidMount() {
70
+ this.fetchFormSetting();
71
+ }
53
72
  render() {
54
73
  let attachments = _index.default.get(this.props.ev, 'data.message.attachments') || [];
55
74
  let formAttachment = _index.default.find(attachments, att => att.type === 'form');
56
75
  if (!formAttachment) return;
57
76
  const {
58
77
  submission,
78
+ formSetting,
59
79
  errorMessage,
60
80
  isSubmited,
61
81
  submiting
62
82
  } = this.state;
63
- let formSetting = formAttachment.form || {};
64
83
  return (0, _preact.h)("div", {
65
84
  onClick: e => e.stopPropagation()
66
85
  }, (0, _preact.h)(_Form.default, {
@@ -77,4 +96,10 @@ class FormAttachment extends _common.Com {
77
96
  }));
78
97
  }
79
98
  }
80
- exports.default = FormAttachment;
99
+ exports.default = FormAttachment;
100
+ function getUrlParameter(url, name) {
101
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
102
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
103
+ var results = regex.exec(url);
104
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
105
+ }
@@ -33,8 +33,8 @@ class Form2 extends _common.Com {
33
33
  if (this.props.isSubmited) return;
34
34
  return (0, _preact.h)("div", {
35
35
  class: "form-component form-component-submit-button"
36
- }, (0, _preact.h)("div", {
37
- class: "form-control--valid-input--error"
36
+ }, this.props.errorMessage && (0, _preact.h)("div", {
37
+ class: "form-control--valid-input--error mb-1"
38
38
  }, this.props.errorMessage), (0, _preact.h)("div", null, (0, _preact.h)("button", {
39
39
  class: "btn--start-convo",
40
40
  disabled: this.props.submiting
@@ -89,9 +89,11 @@ class Form2 extends _common.Com {
89
89
  let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
90
90
  val = val.value || '""';
91
91
  val = _index.default.parseJSON(val);
92
+ let cls = 'form-control';
93
+ if (this.state.errorFields[com.key]) cls = 'form-control input--error';
92
94
  return (0, _preact.h)("input", {
93
95
  ref: this[`${com.key}_input`],
94
- class: "form-control",
96
+ class: cls,
95
97
  type: "date",
96
98
  value: val,
97
99
  onInput: e => {
@@ -20,7 +20,7 @@ class FormPage extends _common.Com {
20
20
  this.setState({
21
21
  loading: true
22
22
  });
23
- let res = await this.props.store.checkFormToken(this.props.token);
23
+ let res = await this.props.store.checkFormToken(this.props.store.matchAccount().id, this.props.token);
24
24
  if (res.error) {
25
25
  this.setState({
26
26
  loading: false,
@@ -29,7 +29,7 @@ class FormPage extends _common.Com {
29
29
  return;
30
30
  }
31
31
  let formSetting = _index.default.get(res, 'body.form') || {};
32
- let submission = _index.default.get(res, 'body.submission') || {};
32
+ let submission = _index.default.get(res, 'body.form_submission') || {};
33
33
  let isSubmited = _index.default.size(submission) > 0;
34
34
  this.setState({
35
35
  loading: false,
@@ -54,11 +54,11 @@ class FormPage extends _common.Com {
54
54
  this.setState({
55
55
  submiting: true
56
56
  });
57
- let res = await this.props.store.submitForm2(this.props.token, this.state.submission);
57
+ let res = await this.props.store.submitForm2(this.props.store.matchAccount().id, this.props.token, this.state.submission);
58
58
  if (res.error) {
59
59
  this.setState({
60
60
  submiting: false,
61
- errorMessage: _index.default.get(res, 'error.code')
61
+ errorMessage: this.props.t('form_submission_error')
62
62
  });
63
63
  return;
64
64
  }
@@ -33,10 +33,10 @@ _index.default.preloadWebfonts(['Inter'], [400, 500]);
33
33
  async function load() {
34
34
  let store = new _store.default(config.ApiURL, config.FileURL, config.RealtimeURL, true);
35
35
  window.store = store;
36
- let accid = getUrlParameter('id') || getUrlParameter('acc_id') || getUrlParameter('account_id') || 'acqsulrowbxiugvginhw';
36
+ let accid = getUrlParameter('id') || getUrlParameter('accid') || getUrlParameter('account-id') || 'acqsulrowbxiugvginhw';
37
37
  let mask = accid + '@' + 'abcd';
38
38
  let token = getUrlParameter('token');
39
- await store.init(accid, mask);
39
+ await store.init(accid);
40
40
  let acc = store.matchAccount() || {};
41
41
  let plugin = findChatbox(store) || {};
42
42
  let css = (await promiseMainCSS).default.default.toString();
@@ -110,8 +110,8 @@ class _default {
110
110
  _defineProperty(this, "list_provinces", () => this.apireq.get(`/accounts/${this.accid}/provinces`));
111
111
  _defineProperty(this, "list_districts", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`));
112
112
  _defineProperty(this, "list_wards", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`));
113
- _defineProperty(this, "checkFormToken", token => this.api41.get(`/submissions/${token}`));
114
- _defineProperty(this, "submitForm2", (token, data) => this.api41.post(`/submissions/${token}`, data));
113
+ _defineProperty(this, "checkFormToken", (accid, token) => this.api41.addQuery('account-id', accid).get(`/submissions/${token}`));
114
+ _defineProperty(this, "submitForm2", (accid, token, data) => this.api41.addQuery('account-id', accid).post(`/submissions/${token}`, data));
115
115
  _defineProperty(this, "suggest_address", keyword => this.apireq.setQuery({
116
116
  keyword: keyword
117
117
  }).get(`/accounts/${this.accid}/addresses`));
@@ -135,8 +135,8 @@ class Store {
135
135
  _defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
136
136
  _defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
137
137
  _defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
138
- _defineProperty(this, "checkFormToken", token => this.api.checkFormToken(token));
139
- _defineProperty(this, "submitForm2", (token, data) => this.api.submitForm2(token, data));
138
+ _defineProperty(this, "checkFormToken", (accid, token) => this.api.checkFormToken(accid, token));
139
+ _defineProperty(this, "submitForm2", (accid, token, data) => this.api.submitForm2(accid, token, data));
140
140
  _defineProperty(this, "sendPresence", _index.default.throttle(async () => {
141
141
  if (this._die) return dieErr;
142
142
  await this.readyGate.entry();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.129",
3
+ "version": "4.1.131",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -10,12 +10,30 @@ export default class FormAttachment extends Com {
10
10
  super(props)
11
11
  this.state = {
12
12
  submission: {},
13
+ formSetting: {},
13
14
  submiting: false,
14
15
  errorMessage: '',
15
16
  isSubmited: false,
16
17
  }
17
18
  }
18
19
 
20
+ componentDidMount() {
21
+ this.fetchFormSetting()
22
+ }
23
+
24
+ fetchFormSetting = () => {
25
+ let attachments = sb.get(this.props.ev, 'data.message.attachments') || []
26
+ let formAttachment = sb.find(attachments, (att) => att.type === 'form')
27
+ if (!formAttachment) return
28
+
29
+ let url = formAttachment.url
30
+ this.token = getUrlParameter(url, 'token')
31
+ let formSetting = formAttachment.form || {}
32
+ let submission = formAttachment.form_submission || {}
33
+ let isSubmited = sb.size(submission) > 0
34
+ this.setState({formSetting, submission, isSubmited})
35
+ }
36
+
19
37
  onChangeFormValues = (values) => {
20
38
  this.setState({submission: {values}})
21
39
  }
@@ -24,7 +42,7 @@ export default class FormAttachment extends Com {
24
42
  this.setState({errorMessage: ''})
25
43
  if (this.state.submiting) return
26
44
  this.setState({submiting: true})
27
- let res = await this.props.store.submitForm2(this.props.token, this.state.submission)
45
+ let res = await this.props.store.submitForm2(this.props.store.matchAccount().id, this.token, this.state.submission)
28
46
  if (res.error) {
29
47
  this.setState({submiting: false, errorMessage: sb.get(res, 'error.code')})
30
48
  return
@@ -36,8 +54,7 @@ export default class FormAttachment extends Com {
36
54
  let attachments = sb.get(this.props.ev, 'data.message.attachments') || []
37
55
  let formAttachment = sb.find(attachments, (att) => att.type === 'form')
38
56
  if (!formAttachment) return
39
- const {submission, errorMessage, isSubmited, submiting} = this.state
40
- let formSetting = formAttachment.form || {}
57
+ const {submission, formSetting, errorMessage, isSubmited, submiting} = this.state
41
58
  return (
42
59
  <div onClick={(e) => e.stopPropagation()}>
43
60
  <Form
@@ -56,3 +73,10 @@ export default class FormAttachment extends Com {
56
73
  )
57
74
  }
58
75
  }
76
+
77
+ function getUrlParameter(url, name) {
78
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]')
79
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)')
80
+ var results = regex.exec(url)
81
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '))
82
+ }
package/src/form/Form.js CHANGED
@@ -35,7 +35,7 @@ export default class Form2 extends Com {
35
35
  if (this.props.isSubmited) return
36
36
  return (
37
37
  <div class='form-component form-component-submit-button'>
38
- <div class='form-control--valid-input--error'>{this.props.errorMessage}</div>
38
+ {this.props.errorMessage && <div class='form-control--valid-input--error mb-1'>{this.props.errorMessage}</div>}
39
39
  <div>
40
40
  <button class='btn--start-convo' disabled={this.props.submiting}>
41
41
  {com.label}
@@ -101,10 +101,12 @@ export default class Form2 extends Com {
101
101
  let val = sb.find(this.props.submission.values, (f) => f.key === com.key) || {}
102
102
  val = val.value || '""'
103
103
  val = sb.parseJSON(val)
104
+ let cls = 'form-control'
105
+ if (this.state.errorFields[com.key]) cls = 'form-control input--error'
104
106
  return (
105
107
  <input
106
108
  ref={this[`${com.key}_input`]}
107
- class='form-control'
109
+ class={cls}
108
110
  type='date'
109
111
  value={val}
110
112
  onInput={(e) => {
@@ -26,13 +26,13 @@ export default class FormPage extends Com {
26
26
  fetchFormSetting = async () => {
27
27
  if (this.state.loading) return
28
28
  this.setState({loading: true})
29
- let res = await this.props.store.checkFormToken(this.props.token)
29
+ let res = await this.props.store.checkFormToken(this.props.store.matchAccount().id, this.props.token)
30
30
  if (res.error) {
31
31
  this.setState({loading: false, loadError: true})
32
32
  return
33
33
  }
34
34
  let formSetting = sb.get(res, 'body.form') || {}
35
- let submission = sb.get(res, 'body.submission') || {}
35
+ let submission = sb.get(res, 'body.form_submission') || {}
36
36
  let isSubmited = sb.size(submission) > 0
37
37
  this.setState({loading: false, loadError: false, formSetting, submission, isSubmited})
38
38
  }
@@ -45,9 +45,13 @@ export default class FormPage extends Com {
45
45
  this.setState({errorMessage: ''})
46
46
  if (this.state.submiting) return
47
47
  this.setState({submiting: true})
48
- let res = await this.props.store.submitForm2(this.props.token, this.state.submission)
48
+ let res = await this.props.store.submitForm2(
49
+ this.props.store.matchAccount().id,
50
+ this.props.token,
51
+ this.state.submission,
52
+ )
49
53
  if (res.error) {
50
- this.setState({submiting: false, errorMessage: sb.get(res, 'error.code')})
54
+ this.setState({submiting: false, errorMessage: this.props.t('form_submission_error')})
51
55
  return
52
56
  }
53
57
  this.setState({submiting: false, isSubmited: true})
package/src/form/index.js CHANGED
@@ -35,10 +35,10 @@ async function load() {
35
35
  let store = new Store(config.ApiURL, config.FileURL, config.RealtimeURL, true)
36
36
  window.store = store
37
37
  let accid =
38
- getUrlParameter('id') || getUrlParameter('acc_id') || getUrlParameter('account_id') || 'acqsulrowbxiugvginhw'
38
+ getUrlParameter('id') || getUrlParameter('accid') || getUrlParameter('account-id') || 'acqsulrowbxiugvginhw'
39
39
  let mask = accid + '@' + 'abcd'
40
40
  let token = getUrlParameter('token')
41
- await store.init(accid, mask)
41
+ await store.init(accid)
42
42
 
43
43
  let acc = store.matchAccount() || {}
44
44
  let plugin = findChatbox(store) || {}
package/src/store/api.js CHANGED
@@ -322,8 +322,8 @@ export default class {
322
322
  list_districts = (p) => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`)
323
323
  list_wards = (p) => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`)
324
324
 
325
- checkFormToken = (token) => this.api41.get(`/submissions/${token}`)
326
- submitForm2 = (token, data) => this.api41.post(`/submissions/${token}`, data)
325
+ checkFormToken = (accid, token) => this.api41.addQuery('account-id', accid).get(`/submissions/${token}`)
326
+ submitForm2 = (accid, token, data) => this.api41.addQuery('account-id', accid).post(`/submissions/${token}`, data)
327
327
  suggest_address = (keyword) => this.apireq.setQuery({keyword: keyword}).get(`/accounts/${this.accid}/addresses`)
328
328
  create_ticket = (ticket) => this.apireq.post(`/accounts/${this.accid}/tickets`, ticket)
329
329
  }
@@ -434,8 +434,8 @@ export default class Store {
434
434
  matchHasManuallyClosed = () => !!this.kv.match('hasManuallyClosed') // true if user has ever closed the widget
435
435
  matchClosePreviewAt = () => this.kv.match('close_preview_at') || 0
436
436
 
437
- checkFormToken = (token) => this.api.checkFormToken(token)
438
- submitForm2 = (token, data) => this.api.submitForm2(token, data)
437
+ checkFormToken = (accid, token) => this.api.checkFormToken(accid, token)
438
+ submitForm2 = (accid, token, data) => this.api.submitForm2(accid, token, data)
439
439
  sendPresence = sb.throttle(
440
440
  async () => {
441
441
  if (this._die) return dieErr