@crystaldesign/widget-contact-form 25.3.0-beta.39 → 25.3.0-beta.42
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/build/esm/index.js +16 -82
- package/build/types/widget-contact-form/src/index.d.ts.map +1 -1
- package/build/types/widget-contact-form/src/types/index.d.ts +3 -3
- package/build/types/widget-contact-form/src/types/index.d.ts.map +1 -1
- package/build/types/widget-contact-form/src/useContactForm.d.ts +2 -1
- package/build/types/widget-contact-form/src/useContactForm.d.ts.map +1 -1
- package/package.json +5 -2
- package/build/types/widget-contact-form/src/utils/updateCssInDom.d.ts +0 -7
- package/build/types/widget-contact-form/src/utils/updateCssInDom.d.ts.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { useState
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useCss, useConfiguration } from '@crystaldesign/widget-library';
|
|
3
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
5
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
6
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
@@ -117,38 +118,11 @@ function _sendMail() {
|
|
|
117
118
|
return _sendMail.apply(this, arguments);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
/**
|
|
121
|
-
* Make sure that the CSS is in the dome and that it has the current content
|
|
122
|
-
*
|
|
123
|
-
* @param url an url to a css file
|
|
124
|
-
*/
|
|
125
|
-
function updateCssInDom (url) {
|
|
126
|
-
var element = document.getElementById('CONTACT-FORM-STYLE-URL');
|
|
127
|
-
if (element) {
|
|
128
|
-
var _element$parentNode;
|
|
129
|
-
(_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || _element$parentNode.removeChild(element);
|
|
130
|
-
}
|
|
131
|
-
element = document.createElement('link');
|
|
132
|
-
element.rel = 'stylesheet';
|
|
133
|
-
element.type = 'text/css';
|
|
134
|
-
element.id = 'CONTACT-FORM-STYLE-URL';
|
|
135
|
-
element.href = url;
|
|
136
|
-
document.head.appendChild(element);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
140
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
141
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
142
121
|
function useContactForm(settings) {
|
|
143
|
-
var _useState = useState(settings),
|
|
144
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
145
|
-
contactFormSettings = _useState2[0],
|
|
146
|
-
setContactFormSettings = _useState2[1];
|
|
147
122
|
var _useDivaCore = useDivaCore(),
|
|
148
123
|
_useDivaCore$state = _useDivaCore.state,
|
|
149
124
|
apiConfig = _useDivaCore$state.apiConfig,
|
|
150
125
|
jwt = _useDivaCore$state.jwt,
|
|
151
|
-
currentComponent = _useDivaCore$state.currentComponent,
|
|
152
126
|
organization = _useDivaCore$state.organization,
|
|
153
127
|
navigationConfiguration = _useDivaCore$state.navigationConfiguration,
|
|
154
128
|
_useDivaCore$actions = _useDivaCore.actions,
|
|
@@ -157,22 +131,7 @@ function useContactForm(settings) {
|
|
|
157
131
|
var _useTranslation = useTranslation(),
|
|
158
132
|
t = _useTranslation.t,
|
|
159
133
|
i18n = _useTranslation.i18n;
|
|
160
|
-
|
|
161
|
-
if (!settings) {
|
|
162
|
-
var contactFormConfig = findContactForm(currentComponent);
|
|
163
|
-
if (contactFormConfig) {
|
|
164
|
-
setContactFormSettings(contactFormConfig.settings);
|
|
165
|
-
if (contactFormConfig.settings.cssUrl) {
|
|
166
|
-
updateCssInDom(contactFormConfig.settings.cssUrl);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}, []);
|
|
171
|
-
useEffect(function () {
|
|
172
|
-
if (settings !== null && settings !== void 0 && settings.cssUrl) {
|
|
173
|
-
updateCssInDom(settings === null || settings === void 0 ? void 0 : settings.cssUrl);
|
|
174
|
-
}
|
|
175
|
-
}, [settings === null || settings === void 0 ? void 0 : settings.cssUrl]);
|
|
134
|
+
useCss(settings);
|
|
176
135
|
function sendEMail(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
177
136
|
return _sendEMail.apply(this, arguments);
|
|
178
137
|
}
|
|
@@ -183,12 +142,6 @@ function useContactForm(settings) {
|
|
|
183
142
|
while (1) switch (_context.prev = _context.next) {
|
|
184
143
|
case 0:
|
|
185
144
|
_context.prev = 0;
|
|
186
|
-
if (contactFormSettings) {
|
|
187
|
-
_context.next = 3;
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
throw new Error('No contact form settings found');
|
|
191
|
-
case 3:
|
|
192
145
|
data = {
|
|
193
146
|
name: name,
|
|
194
147
|
email: variant !== 'CLIENT' ? email : undefined,
|
|
@@ -196,18 +149,18 @@ function useContactForm(settings) {
|
|
|
196
149
|
divaNr: divaNr
|
|
197
150
|
};
|
|
198
151
|
toggleLoading('sendMail');
|
|
199
|
-
_context.next =
|
|
200
|
-
return sendMail(apiConfig.messageService, jwt, organization._id, variant === 'CLIENT' ? email :
|
|
201
|
-
case
|
|
152
|
+
_context.next = 5;
|
|
153
|
+
return sendMail(apiConfig.messageService, jwt, organization._id, variant === 'CLIENT' ? email : settings.mailTo, variant, data, attachments, (_ref = i18n.language.toUpperCase()) !== null && _ref !== void 0 ? _ref : 'DE');
|
|
154
|
+
case 5:
|
|
202
155
|
toggleLoading('sendMail');
|
|
203
156
|
openModal({
|
|
204
157
|
content: t('modal.success.sendingcontactform'),
|
|
205
158
|
accept: true
|
|
206
159
|
});
|
|
207
|
-
_context.next =
|
|
160
|
+
_context.next = 13;
|
|
208
161
|
break;
|
|
209
|
-
case
|
|
210
|
-
_context.prev =
|
|
162
|
+
case 9:
|
|
163
|
+
_context.prev = 9;
|
|
211
164
|
_context.t0 = _context["catch"](0);
|
|
212
165
|
toggleLoading('sendMail');
|
|
213
166
|
openModal({
|
|
@@ -215,36 +168,14 @@ function useContactForm(settings) {
|
|
|
215
168
|
content: t('modal.error.sendingcontactform') + _context.t0,
|
|
216
169
|
accept: true
|
|
217
170
|
});
|
|
218
|
-
case
|
|
171
|
+
case 13:
|
|
219
172
|
case "end":
|
|
220
173
|
return _context.stop();
|
|
221
174
|
}
|
|
222
|
-
}, _callee, null, [[0,
|
|
175
|
+
}, _callee, null, [[0, 9]]);
|
|
223
176
|
}));
|
|
224
177
|
return _sendEMail.apply(this, arguments);
|
|
225
178
|
}
|
|
226
|
-
function findContactForm(component) {
|
|
227
|
-
var _component$settings;
|
|
228
|
-
if ((component === null || component === void 0 ? void 0 : component.type) === 'CONTACTFORM') {
|
|
229
|
-
return component;
|
|
230
|
-
}
|
|
231
|
-
if (component !== null && component !== void 0 && (_component$settings = component.settings) !== null && _component$settings !== void 0 && _component$settings.subComponents) {
|
|
232
|
-
var _iterator = _createForOfIteratorHelper(component.settings.subComponents),
|
|
233
|
-
_step;
|
|
234
|
-
try {
|
|
235
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
236
|
-
var subComponent = _step.value;
|
|
237
|
-
var found = findContactForm(subComponent);
|
|
238
|
-
if (found) return found;
|
|
239
|
-
}
|
|
240
|
-
} catch (err) {
|
|
241
|
-
_iterator.e(err);
|
|
242
|
-
} finally {
|
|
243
|
-
_iterator.f();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
179
|
var validateEmail = function validateEmail(email) {
|
|
249
180
|
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
250
181
|
return regex.test(email);
|
|
@@ -425,12 +356,15 @@ var Main = function Main(_ref) {
|
|
|
425
356
|
var settings = _ref.settings;
|
|
426
357
|
_ref.parameters;
|
|
427
358
|
_ref.internal;
|
|
428
|
-
return /*#__PURE__*/jsx(
|
|
359
|
+
return /*#__PURE__*/jsx(ContactFormComponent, {
|
|
429
360
|
settings: settings
|
|
430
361
|
});
|
|
431
362
|
};
|
|
432
363
|
var ContactFormComponent = function ContactFormComponent(props) {
|
|
433
|
-
|
|
364
|
+
var settings = useConfiguration(ContactForm.name, props.settings);
|
|
365
|
+
return /*#__PURE__*/jsx(MainComponent, _objectSpread(_objectSpread({}, props), {}, {
|
|
366
|
+
settings: settings
|
|
367
|
+
}));
|
|
434
368
|
};
|
|
435
369
|
var ContactForm = {
|
|
436
370
|
name: 'CONTACTFORM',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAkB,MAAM,0BAA0B,CAAC;AAG/E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAM1D,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAG3D,CAAC;AAEF,QAAA,MAAM,WAAW,EAAE,mBAAmB,CAAC,aAAa,CAGnD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BasketData } from '@crystaldesign/diva-core';
|
|
2
|
+
import { BaseConfiguration } from '@crystaldesign/widget-library';
|
|
2
3
|
export interface ContactFormProps {
|
|
3
|
-
settings
|
|
4
|
+
settings: Configuration;
|
|
4
5
|
title?: string;
|
|
5
6
|
submitButtonText?: string;
|
|
6
7
|
onSubmit?: (data: {
|
|
@@ -11,8 +12,7 @@ export interface ContactFormProps {
|
|
|
11
12
|
action?: 'SEND_MAIL';
|
|
12
13
|
basket?: BasketData;
|
|
13
14
|
}
|
|
14
|
-
export interface Configuration {
|
|
15
|
+
export interface Configuration extends BaseConfiguration {
|
|
15
16
|
mailTo: string;
|
|
16
|
-
cssUrl?: string;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/types/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/types/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { Configuration } from './types';
|
|
2
|
+
export default function useContactForm(settings: Configuration): {
|
|
2
3
|
sendEMail: (name: string, email: string, message: string, variant: string, attachments?: string[], divaNr?: string) => Promise<void>;
|
|
3
4
|
navigationConfiguration: import("packages/core/src/types").NavigationConfiguration;
|
|
4
5
|
validateEmail: (email: string) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContactForm.d.ts","sourceRoot":"","sources":["../../../../src/useContactForm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useContactForm.d.ts","sourceRoot":"","sources":["../../../../src/useContactForm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,QAAQ,EAAE,aAAa;sBAS7B,MAAM,SAAS,MAAM,WAAW,MAAM,WAAW,MAAM,gBAAgB,MAAM,EAAE,WAAW,MAAM;;2BA2BjG,MAAM;EAMrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystaldesign/widget-contact-form",
|
|
3
|
-
"version": "25.3.0-beta.
|
|
3
|
+
"version": "25.3.0-beta.42",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"storybook": "storybook dev -p 6006",
|
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
"react": "^18.3.1",
|
|
26
26
|
"react-dom": "^18.3.1"
|
|
27
27
|
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@crystaldesign/widget-library": "25.3.0-beta.42"
|
|
30
|
+
},
|
|
28
31
|
"module": "build/esm/index.js",
|
|
29
32
|
"types": "./build/types/widget-contact-form/src/index.d.ts",
|
|
30
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "ac1ee04802272364e173c8ab0eea41892d5ebef9"
|
|
31
34
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateCssInDom.d.ts","sourceRoot":"","sources":["../../../../../src/utils/updateCssInDom.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,GAAG,EAAE,MAAM,QAWnC"}
|