@onehat/ui 0.3.337 → 0.3.338

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.337",
3
+ "version": "0.3.338",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -38,10 +38,10 @@ export default function withModal(WrappedComponent) {
38
38
  [isModalShown, setIsModalShown] = useState(false),
39
39
  [isValid, setIsValid] = useState(false),
40
40
  [isDirty, setIsDirty] = useState(false),
41
- [h, setHeight] = useState(250),
42
- [w, setWidth] = useState(400),
41
+ [h, setHeight] = useState(),
42
+ [w, setWidth] = useState(),
43
43
  [onOk, setOnOk] = useState(),
44
- [okBtnLabel, setOkBtnLabel] = useState('OK'),
44
+ [okBtnLabel, setOkBtnLabel] = useState(),
45
45
  [onYes, setOnYes] = useState(),
46
46
  [onNo, setOnNo] = useState(),
47
47
  [onSubmit, setOnSubmit] = useState(),
@@ -49,7 +49,7 @@ export default function withModal(WrappedComponent) {
49
49
  [customButtons, setCustomButtons] = useState(),
50
50
  [formProps, setFormProps] = useState(),
51
51
  [self, setSelf] = useState(),
52
- [color, setColor] = useState('#000'),
52
+ [color, setColor] = useState(),
53
53
  [body, setBody] = useState(),
54
54
  useForm = !!formProps, // convenience flag
55
55
  autoFocusRef = useRef(null),
@@ -65,28 +65,31 @@ export default function withModal(WrappedComponent) {
65
65
  self?.children?.ModalForm?.reset();
66
66
  },
67
67
  onCancel = () => {
68
+ hideModal();
69
+ },
70
+ hideModal = () => {
68
71
  setIsModalShown(false);
69
72
  },
70
73
  showModal = (args) => {
71
- const {
72
- title = '',
73
- message = '',
74
- body,
74
+ let {
75
+ title = null,
76
+ message = null,
77
+ body = null,
75
78
  canClose = true,
76
79
  includeCancel = false,
77
- onOk,
78
- okBtnLabel,
79
- onYes,
80
- onNo,
81
- onSubmit,
82
- submitBtnLabel,
83
- customButtons,
80
+ onOk = null,
81
+ okBtnLabel = null,
82
+ onYes = null,
83
+ onNo = null,
84
+ onSubmit = null,
85
+ submitBtnLabel = null,
86
+ customButtons = null,
84
87
  includeReset = false,
85
- formProps,
86
- self,
87
- color,
88
- h,
89
- w,
88
+ formProps = null,
89
+ self = null,
90
+ color = null,
91
+ h = null,
92
+ w = null,
90
93
  } = args;
91
94
 
92
95
  if (!message && !body && !formProps) {
@@ -95,54 +98,25 @@ export default function withModal(WrappedComponent) {
95
98
  if (includeReset && !self) {
96
99
  throw new Error('self is required when using includeReset');
97
100
  }
98
- if (title) {
99
- setTitle(title);
100
- }
101
- if (message) {
102
- setMessage(message);
103
- }
104
- if (body) {
105
- setBody(body);
106
- }
101
+
102
+ setTitle(title);
103
+ setMessage(message);
104
+ setBody(body);
107
105
  setCanClose(canClose);
108
106
  setIncludeCancel(includeCancel);
109
- if (onOk) {
110
- setOnOk(() => onOk);
111
- }
112
- if (okBtnLabel) {
113
- setOkBtnLabel(okBtnLabel);
114
- }
115
- if (onYes) {
116
- setOnYes(() => onYes);
117
- }
118
- if (onNo) {
119
- setOnNo(() => onNo);
120
- }
121
- if (onSubmit) {
122
- setOnSubmit(() => onSubmit);
123
- }
124
- if (submitBtnLabel) {
125
- setSubmitBtnLabel(submitBtnLabel);
126
- }
127
- if (customButtons) {
128
- setCustomButtons(customButtons);
129
- }
107
+ setOnOk(onOk ? () => onOk : null);
108
+ setOkBtnLabel(okBtnLabel || 'OK');
109
+ setOnYes(onYes ? () => onYes : null);
110
+ setOnNo(onNo ? () => onNo : null);
111
+ setOnSubmit(onSubmit ? () => onSubmit : null);
112
+ setSubmitBtnLabel(submitBtnLabel);
113
+ setCustomButtons(customButtons);
130
114
  setIncludeReset(includeReset);
131
- if (formProps) {
132
- setFormProps(formProps);
133
- }
134
- if (self) {
135
- setSelf(self);
136
- }
137
- if (color) {
138
- setColor(color);
139
- }
140
- if (h) {
141
- setHeight(h);
142
- }
143
- if (w) {
144
- setWidth(w);
145
- }
115
+ setFormProps(formProps);
116
+ setSelf(self);
117
+ setColor(color || '#000');
118
+ setHeight(h || 250);
119
+ setWidth(w || 400);
146
120
 
147
121
  setIsModalShown(true);
148
122
  };
@@ -218,7 +192,8 @@ export default function withModal(WrappedComponent) {
218
192
  let modalBody = null;
219
193
  if (useForm) {
220
194
  modalBody = <Form
221
- {...formProps}
195
+ {...formProps}
196
+ parent={self}
222
197
  reference="ModalForm"
223
198
  onValidityChange={onValidityChange}
224
199
  onDirtyChange={onDirtyChange}
@@ -181,9 +181,9 @@ export default function withPdfButtons(WrappedComponent) {
181
181
 
182
182
  showModal({
183
183
  title: 'PDF Fields to Show',
184
- message: 'Please select which fields to show in the PDF. (1)',
184
+ includeReset: true,
185
185
  includeCancel: true,
186
- onOk: () => {
186
+ onSubmit: () => {
187
187
  hideModal();
188
188
 
189
189
  const
@@ -196,97 +196,104 @@ export default function withPdfButtons(WrappedComponent) {
196
196
  getPdf(data);
197
197
  }
198
198
  },
199
- okBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
199
+ submitBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
200
200
  w: 530, // 510 so it's over the stack threshold
201
201
  h: 800,
202
- body: <Column w="100%">
203
- <Row px={10}>
204
- <Column w="40px" mr={5} justifyContent="flex-start">
205
- <Icon as={TriangleExclamation} size={10} color="#000" />
206
- </Column>
207
- <Text flex={1}>Please select which fields to show in the PDF. (2)</Text>
208
- </Row>
209
- <Form
210
- parent={self}
211
- reference="ModalForm"
212
- editorType={EDITOR_TYPE__PLAIN}
213
- useAdditionalEditButtons={false}
214
- flex={1}
215
- Repository={Repository}
216
- items={modalItems}
217
- startingValues={startingValues}
218
- validator={validator}
219
- checkIsEditingDisabled={false}
220
- disableFooter={true}
221
- columnDefaults={{
222
- labelWidth: '100%',
223
- }}
224
- />
225
- </Column>,
202
+ self,
203
+ formProps: {
204
+ editorType: EDITOR_TYPE__PLAIN,
205
+ disableFooter: true,
206
+ columnDefaults: {
207
+ labelWidth: '100%',
208
+ },
209
+ items: [
210
+ {
211
+ name: 'instructions',
212
+ type: 'DisplayField',
213
+ text: 'Please select which fields to show in the PDF.',
214
+ mb: 10,
215
+ },
216
+ ...modalItems,
217
+ ],
218
+ Repository,
219
+ startingValues,
220
+ validator,
221
+ },
226
222
  });
227
223
  },
228
224
  onChooseEmailAddress = (data) => {
229
225
  showModal({
230
226
  title: 'Email To',
227
+ includeReset: true,
231
228
  includeCancel: true,
232
- onOk: () => {
229
+ onSubmit: () => {
233
230
  hideModal();
234
231
 
235
232
  const
236
233
  fv = self.children.ModalForm.formGetValues(),
237
- email = fv.email;
234
+ email = fv.email,
235
+ message = fv.message;
238
236
 
239
237
  sendEmail({
240
238
  ...data,
241
239
  email,
240
+ message,
242
241
  });
243
242
  },
244
- okBtnLabel: 'Email PDF',
243
+ submitBtnLabel: 'Email PDF',
245
244
  w: 510, // 510 so it's over the stack threshold
246
- h: 300,
247
- body: <Column w="100%">
248
- <Row>
249
- <Column w="40px" mr={5} justifyContent="flex-start">
250
- <Icon as={TriangleExclamation} size={10} color="#000" />
251
- </Column>
252
- <Text flex={1}>Please enter one more more email addresses{"\n"}
253
- (separated by a comma) to send the PDF to.</Text>
254
- </Row>
255
- <Form
256
- parent={self}
257
- reference="ModalForm"
258
- editorType={EDITOR_TYPE__PLAIN}
259
- disableFooter={true}
260
- columnDefaults={{
261
- labelWidth: '100%',
262
- }}
263
- items={[
264
- {
265
- name: 'email',
266
- label: 'Email Address',
267
- type: 'Input',
268
- required: true,
269
- },
270
- ]}
271
- validator={yup.object({
272
- email: yup.string().required().test({
273
- name: 'csvEmails',
274
- test: function(value) {
275
- const firstInvalidEmail = value.split(",")
276
- .map(email => email.trim())
277
- .filter(v => !_.isEmpty(v))
278
- .find(v => !yup.string().email().isValidSync(v));
279
- if (firstInvalidEmail) {
280
- return this.createError({
281
- message: `The email address '${firstInvalidEmail}' is invalid.`
282
- });
283
- }
284
- return true;
285
- },
286
- }),
287
- })}
288
- />
289
- </Column>,
245
+ h: 500,
246
+ self,
247
+ formProps: {
248
+ editorType: EDITOR_TYPE__PLAIN,
249
+ disableFooter: true,
250
+ columnDefaults: {
251
+ labelWidth: '100%',
252
+ },
253
+ items: [
254
+ {
255
+ name: 'instructions',
256
+ type: 'DisplayField',
257
+ text: 'Please enter one or more email addresses, separated by a comma.',
258
+ },
259
+ {
260
+ name: 'email',
261
+ label: 'Email Address',
262
+ type: 'Input',
263
+ tooltip: 'Separate multiple email addresses with a comma.',
264
+ },
265
+ {
266
+ name: 'message',
267
+ label: 'Message',
268
+ placeholder: 'Please see attached PDF.',
269
+ type: 'TextArea',
270
+ totalLines: 6,
271
+ },
272
+ ],
273
+ validator: yup.object({
274
+ email: yup.string().required('Email is required').test({
275
+ name: 'csvEmails',
276
+ test: function(value) {
277
+ if (!value) {
278
+ return this.createError({
279
+ message: 'Email is required',
280
+ });
281
+ }
282
+ const firstInvalidEmail = value.split(",")
283
+ .map(email => email.trim())
284
+ .filter(v => !_.isEmpty(v))
285
+ .find(v => !yup.string().email().isValidSync(v));
286
+ if (firstInvalidEmail) {
287
+ return this.createError({
288
+ message: `The email address '${firstInvalidEmail}' is invalid.`
289
+ });
290
+ }
291
+ return true;
292
+ },
293
+ }),
294
+ message: yup.string().notRequired(),
295
+ }),
296
+ },
290
297
  });
291
298
  },
292
299
  getPdf = (data) => {