@subiz/widget-v4 4.1.130 → 4.1.132

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.
@@ -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 {
@@ -19,8 +19,10 @@ class FormAttachment extends _common.Com {
19
19
  let attachments = _index.default.get(this.props.ev, 'data.message.attachments') || [];
20
20
  let formAttachment = _index.default.find(attachments, att => att.type === 'form');
21
21
  if (!formAttachment) return;
22
+ let url = formAttachment.url;
23
+ this.token = getUrlParameter(url, 'token');
22
24
  let formSetting = formAttachment.form || {};
23
- let submission = formAttachment.submission || {};
25
+ let submission = formAttachment.form_submission || {};
24
26
  let isSubmited = _index.default.size(submission) > 0;
25
27
  this.setState({
26
28
  formSetting,
@@ -43,7 +45,7 @@ class FormAttachment extends _common.Com {
43
45
  this.setState({
44
46
  submiting: true
45
47
  });
46
- 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);
47
49
  if (res.error) {
48
50
  this.setState({
49
51
  submiting: false,
@@ -94,4 +96,10 @@ class FormAttachment extends _common.Com {
94
96
  }));
95
97
  }
96
98
  }
97
- 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
+ }
@@ -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,7 +54,7 @@ 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,
@@ -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();
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renderForm = renderForm;
7
+ var _preact = require("preact");
8
+ var _Form = _interopRequireDefault(require("./form/Form.js"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function renderForm(form, $div) {
11
+ (0, _preact.render)((0, _preact.h)(_Form.default, {
12
+ mode: "attachment",
13
+ formSetting: plugin,
14
+ submission: {
15
+ values: []
16
+ },
17
+ t: () => ''
18
+ }), $div);
19
+ }
@@ -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.130",
3
+ "version": "4.1.132",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -26,8 +26,10 @@ export default class FormAttachment extends Com {
26
26
  let formAttachment = sb.find(attachments, (att) => att.type === 'form')
27
27
  if (!formAttachment) return
28
28
 
29
+ let url = formAttachment.url
30
+ this.token = getUrlParameter(url, 'token')
29
31
  let formSetting = formAttachment.form || {}
30
- let submission = formAttachment.submission || {}
32
+ let submission = formAttachment.form_submission || {}
31
33
  let isSubmited = sb.size(submission) > 0
32
34
  this.setState({formSetting, submission, isSubmited})
33
35
  }
@@ -40,7 +42,7 @@ export default class FormAttachment extends Com {
40
42
  this.setState({errorMessage: ''})
41
43
  if (this.state.submiting) return
42
44
  this.setState({submiting: true})
43
- 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)
44
46
  if (res.error) {
45
47
  this.setState({submiting: false, errorMessage: sb.get(res, 'error.code')})
46
48
  return
@@ -71,3 +73,10 @@ export default class FormAttachment extends Com {
71
73
  )
72
74
  }
73
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
+ }
@@ -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,7 +45,11 @@ 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
54
  this.setState({submiting: false, errorMessage: this.props.t('form_submission_error')})
51
55
  return
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/form.js ADDED
@@ -0,0 +1,6 @@
1
+ import {h, render, createRef} from 'preact'
2
+ import Form from './form/Form.js'
3
+
4
+ export function renderForm(form, $div) {
5
+ render(<Form mode='attachment' formSetting={plugin} submission={{values: []}} t={() => ''} />, $div)
6
+ }
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