@subiz/widget-v4 4.1.129 → 4.1.130

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);
@@ -15,6 +15,19 @@ 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 formSetting = formAttachment.form || {};
23
+ let submission = formAttachment.submission || {};
24
+ let isSubmited = _index.default.size(submission) > 0;
25
+ this.setState({
26
+ formSetting,
27
+ submission,
28
+ isSubmited
29
+ });
30
+ });
18
31
  _defineProperty(this, "onChangeFormValues", values => {
19
32
  this.setState({
20
33
  submission: {
@@ -45,22 +58,26 @@ class FormAttachment extends _common.Com {
45
58
  });
46
59
  this.state = {
47
60
  submission: {},
61
+ formSetting: {},
48
62
  submiting: false,
49
63
  errorMessage: '',
50
64
  isSubmited: false
51
65
  };
52
66
  }
67
+ componentDidMount() {
68
+ this.fetchFormSetting();
69
+ }
53
70
  render() {
54
71
  let attachments = _index.default.get(this.props.ev, 'data.message.attachments') || [];
55
72
  let formAttachment = _index.default.find(attachments, att => att.type === 'form');
56
73
  if (!formAttachment) return;
57
74
  const {
58
75
  submission,
76
+ formSetting,
59
77
  errorMessage,
60
78
  isSubmited,
61
79
  submiting
62
80
  } = this.state;
63
- let formSetting = formAttachment.form || {};
64
81
  return (0, _preact.h)("div", {
65
82
  onClick: e => e.stopPropagation()
66
83
  }, (0, _preact.h)(_Form.default, {
@@ -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 => {
@@ -58,7 +58,7 @@ class FormPage extends _common.Com {
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
  }
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.130",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -10,12 +10,28 @@ 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 formSetting = formAttachment.form || {}
30
+ let submission = formAttachment.submission || {}
31
+ let isSubmited = sb.size(submission) > 0
32
+ this.setState({formSetting, submission, isSubmited})
33
+ }
34
+
19
35
  onChangeFormValues = (values) => {
20
36
  this.setState({submission: {values}})
21
37
  }
@@ -36,8 +52,7 @@ export default class FormAttachment extends Com {
36
52
  let attachments = sb.get(this.props.ev, 'data.message.attachments') || []
37
53
  let formAttachment = sb.find(attachments, (att) => att.type === 'form')
38
54
  if (!formAttachment) return
39
- const {submission, errorMessage, isSubmited, submiting} = this.state
40
- let formSetting = formAttachment.form || {}
55
+ const {submission, formSetting, errorMessage, isSubmited, submiting} = this.state
41
56
  return (
42
57
  <div onClick={(e) => e.stopPropagation()}>
43
58
  <Form
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) => {
@@ -47,7 +47,7 @@ export default class FormPage extends Com {
47
47
  this.setState({submiting: true})
48
48
  let res = await this.props.store.submitForm2(this.props.token, this.state.submission)
49
49
  if (res.error) {
50
- this.setState({submiting: false, errorMessage: sb.get(res, 'error.code')})
50
+ this.setState({submiting: false, errorMessage: this.props.t('form_submission_error')})
51
51
  return
52
52
  }
53
53
  this.setState({submiting: false, isSubmited: true})