@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
|
@@ -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(
|
|
42
|
-
[w, setWidth] = useState(
|
|
41
|
+
[h, setHeight] = useState(),
|
|
42
|
+
[w, setWidth] = useState(),
|
|
43
43
|
[onOk, setOnOk] = useState(),
|
|
44
|
-
[okBtnLabel, setOkBtnLabel] = useState(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
176
|
+
includeReset: true,
|
|
185
177
|
includeCancel: true,
|
|
186
|
-
|
|
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
|
-
|
|
191
|
+
submitBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
|
|
200
192
|
w: 530, // 510 so it's over the stack threshold
|
|
201
193
|
h: 800,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
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
|
-
|
|
235
|
+
submitBtnLabel: 'Email PDF',
|
|
245
236
|
w: 510, // 510 so it's over the stack threshold
|
|
246
|
-
h:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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 = [
|