ublo-lib 1.10.16 → 1.10.17
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/es/common/components/gesco-contact-form/api.js +4 -4
- package/es/common/components/gesco-contact-form/gesco-contact-form.js +13 -12
- package/es/common/components/gesco-contact-form/validation.js +35 -31
- package/es/common/utils/cms.d.ts.map +1 -1
- package/es/common/utils/cms.js +6 -3
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Data from "./data";
|
|
2
|
-
export
|
|
2
|
+
export async function fetchParams(lang, resort, merchant, channel, categories, integration = false, uat = false) {
|
|
3
3
|
const host = integration ? Data.HOSTS.TEST : uat ? Data.HOSTS.UAT : Data.HOSTS.PROD;
|
|
4
4
|
const res = await fetch(`${host}/api/gesco/contact/parameters`, {
|
|
5
5
|
method: "POST",
|
|
@@ -15,8 +15,8 @@ export const fetchParams = async (lang, resort, merchant, channel, categories, i
|
|
|
15
15
|
})
|
|
16
16
|
});
|
|
17
17
|
return res.json();
|
|
18
|
-
}
|
|
19
|
-
export
|
|
18
|
+
}
|
|
19
|
+
export async function postMessage(payload, integration = false, uat = false) {
|
|
20
20
|
const host = integration ? Data.HOSTS.TEST : uat ? Data.HOSTS.UAT : Data.HOSTS.PROD;
|
|
21
21
|
const {
|
|
22
22
|
userAgent,
|
|
@@ -34,4 +34,4 @@ export const postMessage = async (payload, integration = false, uat = false) =>
|
|
|
34
34
|
})
|
|
35
35
|
});
|
|
36
36
|
return res.json();
|
|
37
|
-
}
|
|
37
|
+
}
|
|
@@ -20,7 +20,8 @@ const ContactFormWithSnackbar = props => {
|
|
|
20
20
|
})
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
export default React.memo(ContactFormWithSnackbar);
|
|
24
|
+
function ContactForm({
|
|
24
25
|
lang,
|
|
25
26
|
resort,
|
|
26
27
|
channel = "ESF",
|
|
@@ -29,7 +30,7 @@ const ContactForm = ({
|
|
|
29
30
|
integration = false,
|
|
30
31
|
uat = false,
|
|
31
32
|
onSubmit
|
|
32
|
-
})
|
|
33
|
+
}) {
|
|
33
34
|
const [submiting, setSubmiting] = React.useState(false);
|
|
34
35
|
const [params, setParams] = React.useState(Data.DEFAULT_PARAMS);
|
|
35
36
|
const [fields, setFields] = React.useState(Data.DEFAULT_FIELDS);
|
|
@@ -65,7 +66,7 @@ const ContactForm = ({
|
|
|
65
66
|
if (params === undefined || params.error !== undefined) {
|
|
66
67
|
setHasError(true);
|
|
67
68
|
} else {
|
|
68
|
-
const needCategory = params
|
|
69
|
+
const needCategory = params?.categories?.length > 1;
|
|
69
70
|
setParams(params);
|
|
70
71
|
setNeedCategory(needCategory);
|
|
71
72
|
if (!needCategory) {
|
|
@@ -80,10 +81,8 @@ const ContactForm = ({
|
|
|
80
81
|
getParams();
|
|
81
82
|
}, [categories, channel, integration, merchant, resort, uat, update, widgetLang]);
|
|
82
83
|
const validateAll = () => {
|
|
83
|
-
const stayValidators = [];
|
|
84
|
-
const categoryValidators = needCategory ? undefined : [];
|
|
85
84
|
Object.keys(fields).forEach(key => {
|
|
86
|
-
update(true, key, undefined,
|
|
85
|
+
update(true, key, undefined, !needCategory && key === "category" ? undefined : fields[key].validators);
|
|
87
86
|
});
|
|
88
87
|
};
|
|
89
88
|
const isValidated = () => {
|
|
@@ -148,10 +147,13 @@ const ContactForm = ({
|
|
|
148
147
|
setSubmiting(false);
|
|
149
148
|
setTimeout(() => setSubmiting(false), 2000);
|
|
150
149
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
if (hasError) {
|
|
151
|
+
return _jsx("div", {
|
|
152
|
+
className: css.error,
|
|
153
|
+
children: Messages.get(widgetLang, "parametersError")
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return _jsxs("form", {
|
|
155
157
|
className: css.form,
|
|
156
158
|
onSubmit: submit,
|
|
157
159
|
children: [_jsx(Select, {
|
|
@@ -280,5 +282,4 @@ const ContactForm = ({
|
|
|
280
282
|
})
|
|
281
283
|
})]
|
|
282
284
|
});
|
|
283
|
-
}
|
|
284
|
-
export default React.memo(ContactFormWithSnackbar);
|
|
285
|
+
}
|
|
@@ -1,61 +1,65 @@
|
|
|
1
1
|
import * as Messages from "./messages";
|
|
2
|
-
export
|
|
2
|
+
export function validate(lang, name, value = "", validators, fields) {
|
|
3
3
|
return validators.reduce((acc, validator) => {
|
|
4
4
|
const label = Messages.get(lang, name);
|
|
5
5
|
return acc === undefined ? validator(lang, label, value, fields) : acc;
|
|
6
6
|
}, undefined);
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
const mailCheck = /^\w+([.\-+]?\w+)*@\w+([.-]?\w+)*(.\w{2,})+$/;
|
|
9
|
-
export
|
|
9
|
+
export function email(lang, label, value) {
|
|
10
10
|
if (mailCheck.exec(value) === null) {
|
|
11
11
|
return Messages.getFormated(lang, "errorMail", {
|
|
12
12
|
label
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
const phoneCheck = /^\+?[0-9,(,),.,\-, ]{6,19}[0-9]$/;
|
|
17
|
-
export
|
|
17
|
+
export function phone(lang, label, value) {
|
|
18
18
|
if (phoneCheck.exec(value) === null) {
|
|
19
19
|
return Messages.getFormated(lang, "errorPhone", {
|
|
20
20
|
label
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
23
|
+
}
|
|
24
|
+
export function min(length) {
|
|
25
|
+
return (lang, label, value) => {
|
|
26
|
+
if (value.length < length) {
|
|
27
|
+
return Messages.getFormated(lang, "errorMin", {
|
|
28
|
+
label,
|
|
29
|
+
length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
32
34
|
const dateCheck = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
|
|
33
|
-
export
|
|
35
|
+
export function date(lang, label, value) {
|
|
34
36
|
const date = new Date(value);
|
|
35
37
|
const strValid = dateCheck.exec(value) !== null;
|
|
36
38
|
const isValid = strValid && date instanceof Date && !isNaN(date);
|
|
37
39
|
return isValid ? undefined : Messages.getFormated(lang, "errorDate", {
|
|
38
40
|
label
|
|
39
41
|
});
|
|
40
|
-
}
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
42
|
+
}
|
|
43
|
+
export function afterDate(other) {
|
|
44
|
+
return (lang, label, value, fields) => {
|
|
45
|
+
const otherDate = fields[other].value;
|
|
46
|
+
const a = new Date(otherDate);
|
|
47
|
+
const b = new Date(value);
|
|
48
|
+
if (a.getTime() > b.getTime()) {
|
|
49
|
+
const f = new Intl.DateTimeFormat(lang);
|
|
50
|
+
const otherDate = f.format(a);
|
|
51
|
+
return Messages.getFormated(lang, "errorDateAfter", {
|
|
52
|
+
label,
|
|
53
|
+
otherDate
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function mandatory(lang, label, val) {
|
|
55
59
|
const value = val.trim();
|
|
56
60
|
if (value === undefined || value.length === 0) {
|
|
57
61
|
return Messages.getFormated(lang, "errorMandatory", {
|
|
58
62
|
label
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
|
-
}
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../../src/common/utils/cms.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../../src/common/utils/cms.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,YAE1B;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,iBAO5C;AAED,wBAAsB,aAAa,kBAOlC"}
|
package/es/common/utils/cms.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
function getToken() {
|
|
2
|
+
return window.sessionStorage.getItem("cms_token");
|
|
3
|
+
}
|
|
1
4
|
export function isConnected() {
|
|
2
|
-
return Boolean(
|
|
5
|
+
return Boolean(getToken());
|
|
3
6
|
}
|
|
4
7
|
export async function revalidate(path) {
|
|
5
8
|
try {
|
|
6
|
-
const token =
|
|
9
|
+
const token = getToken();
|
|
7
10
|
await fetch(`/api/revalidate?token=${token}&path=${path}`);
|
|
8
11
|
}
|
|
9
12
|
catch (e) {
|
|
@@ -12,7 +15,7 @@ export async function revalidate(path) {
|
|
|
12
15
|
}
|
|
13
16
|
export async function revalidateAll() {
|
|
14
17
|
try {
|
|
15
|
-
const token =
|
|
18
|
+
const token = getToken();
|
|
16
19
|
await fetch(`/api/revalidate?token=${token}&all=true`);
|
|
17
20
|
}
|
|
18
21
|
catch (e) {
|