@onehat/ui 0.3.337 → 0.3.339

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.339",
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}
@@ -1,19 +1,11 @@
1
- import {
2
- Column,
3
- Icon,
4
- Row,
5
- Text,
6
- } from 'native-base';
7
1
  import {
8
2
  VIEW,
9
3
  } from '../../Constants/Commands.js';
10
4
  import * as yup from 'yup'; // https://github.com/jquense/yup#string
11
5
  import Inflector from 'inflector-js';
12
6
  import qs from 'qs';
13
- import Form from '../Form/Form.js';
14
7
  import inArray from '../../Functions/inArray.js';
15
8
  import Pdf from '../Icons/Pdf.js';
16
- import TriangleExclamation from '../Icons/TriangleExclamation.js';
17
9
  import withModal from './withModal.js';
18
10
  import { EDITOR_TYPE__PLAIN } from '../../Constants/Editor.js';
19
11
  import UiGlobals from '../../UiGlobals.js';
@@ -181,9 +173,9 @@ export default function withPdfButtons(WrappedComponent) {
181
173
 
182
174
  showModal({
183
175
  title: 'PDF Fields to Show',
184
- message: 'Please select which fields to show in the PDF. (1)',
176
+ includeReset: true,
185
177
  includeCancel: true,
186
- onOk: () => {
178
+ onSubmit: () => {
187
179
  hideModal();
188
180
 
189
181
  const
@@ -196,97 +188,104 @@ export default function withPdfButtons(WrappedComponent) {
196
188
  getPdf(data);
197
189
  }
198
190
  },
199
- okBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
191
+ submitBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
200
192
  w: 530, // 510 so it's over the stack threshold
201
193
  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>,
194
+ self,
195
+ formProps: {
196
+ editorType: EDITOR_TYPE__PLAIN,
197
+ disableFooter: true,
198
+ columnDefaults: {
199
+ labelWidth: '100%',
200
+ },
201
+ items: [
202
+ {
203
+ name: 'instructions',
204
+ type: 'DisplayField',
205
+ text: 'Please select which fields to show in the PDF.',
206
+ mb: 10,
207
+ },
208
+ ...modalItems,
209
+ ],
210
+ Repository,
211
+ startingValues,
212
+ validator,
213
+ },
226
214
  });
227
215
  },
228
216
  onChooseEmailAddress = (data) => {
229
217
  showModal({
230
218
  title: 'Email To',
219
+ includeReset: true,
231
220
  includeCancel: true,
232
- onOk: () => {
221
+ onSubmit: () => {
233
222
  hideModal();
234
223
 
235
224
  const
236
225
  fv = self.children.ModalForm.formGetValues(),
237
- email = fv.email;
226
+ email = fv.email,
227
+ message = fv.message;
238
228
 
239
229
  sendEmail({
240
230
  ...data,
241
231
  email,
232
+ message,
242
233
  });
243
234
  },
244
- okBtnLabel: 'Email PDF',
235
+ submitBtnLabel: 'Email PDF',
245
236
  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>,
237
+ h: 500,
238
+ self,
239
+ formProps: {
240
+ editorType: EDITOR_TYPE__PLAIN,
241
+ disableFooter: true,
242
+ columnDefaults: {
243
+ labelWidth: '100%',
244
+ },
245
+ items: [
246
+ {
247
+ name: 'instructions',
248
+ type: 'DisplayField',
249
+ text: 'Please enter one or more email addresses, separated by a comma.',
250
+ },
251
+ {
252
+ name: 'email',
253
+ label: 'Email Address',
254
+ type: 'Input',
255
+ tooltip: 'Separate multiple email addresses with a comma.',
256
+ },
257
+ {
258
+ name: 'message',
259
+ label: 'Message',
260
+ placeholder: 'Please see attached PDF.',
261
+ type: 'TextArea',
262
+ totalLines: 6,
263
+ },
264
+ ],
265
+ validator: yup.object({
266
+ email: yup.string().required('Email is required').test({
267
+ name: 'csvEmails',
268
+ test: function(value) {
269
+ if (!value) {
270
+ return this.createError({
271
+ message: 'Email is required',
272
+ });
273
+ }
274
+ const firstInvalidEmail = value.split(",")
275
+ .map(email => email.trim())
276
+ .filter(v => !_.isEmpty(v))
277
+ .find(v => !yup.string().email().isValidSync(v));
278
+ if (firstInvalidEmail) {
279
+ return this.createError({
280
+ message: `The email address '${firstInvalidEmail}' is invalid.`
281
+ });
282
+ }
283
+ return true;
284
+ },
285
+ }),
286
+ message: yup.string().notRequired(),
287
+ }),
288
+ },
290
289
  });
291
290
  },
292
291
  getPdf = (data) => {
@@ -300,8 +299,13 @@ export default function withPdfButtons(WrappedComponent) {
300
299
  },
301
300
  sendEmail = async (data) => {
302
301
 
302
+ const
303
+ dispatch = UiGlobals.redux.dispatch,
304
+ setIsWaitModalShownAction = UiGlobals.debugReducer.setIsWaitModalShownAction;
305
+
306
+ dispatch(setIsWaitModalShownAction(true));
307
+
303
308
  data.id = selection[0].id;
304
-
305
309
  const result = await Repository._send('POST', model + '/emailModelPdf', data);
306
310
 
307
311
  const {
@@ -311,13 +315,13 @@ export default function withPdfButtons(WrappedComponent) {
311
315
  message
312
316
  } = Repository._processServerResponse(result);
313
317
 
318
+ dispatch(setIsWaitModalShownAction(false));
319
+
314
320
  if (!success) {
315
321
  alert('Email could not be sent.');
316
322
  return;
317
323
  }
318
-
319
324
  showInfo('Email sent successfully.');
320
-
321
325
  };
322
326
 
323
327
  const buttons = [