@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
|
@@ -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}
|
|
@@ -181,9 +181,9 @@ export default function withPdfButtons(WrappedComponent) {
|
|
|
181
181
|
|
|
182
182
|
showModal({
|
|
183
183
|
title: 'PDF Fields to Show',
|
|
184
|
-
|
|
184
|
+
includeReset: true,
|
|
185
185
|
includeCancel: true,
|
|
186
|
-
|
|
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
|
-
|
|
199
|
+
submitBtnLabel: userWantsToEmail ? 'Choose Email' : 'Get PDF',
|
|
200
200
|
w: 530, // 510 so it's over the stack threshold
|
|
201
201
|
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>,
|
|
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
|
-
|
|
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
|
-
|
|
243
|
+
submitBtnLabel: 'Email PDF',
|
|
245
244
|
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
|
-
|
|
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) => {
|