ublo-lib 1.23.6 → 1.24.1

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.
Files changed (39) hide show
  1. package/es/common/components/custom-contact-form/custom-contact-form.d.ts +1 -0
  2. package/es/common/components/custom-contact-form/custom-contact-form.d.ts.map +1 -1
  3. package/es/common/components/custom-contact-form/custom-contact-form.js +2 -2
  4. package/es/common/components/custom-contact-form/messages.js +1 -1
  5. package/es/common/components/gesco-contact-form/data/phone-prefixes.json +251 -0
  6. package/es/common/components/gesco-contact-form/gesco-contact-form.d.ts +17 -0
  7. package/es/common/components/gesco-contact-form/gesco-contact-form.d.ts.map +1 -0
  8. package/es/common/components/gesco-contact-form/gesco-contact-form.js +85 -281
  9. package/es/common/components/gesco-contact-form/gesco-contact-form.module.css +31 -14
  10. package/es/common/components/gesco-contact-form/hooks/use-params.d.ts +15 -0
  11. package/es/common/components/gesco-contact-form/hooks/use-params.d.ts.map +1 -0
  12. package/es/common/components/gesco-contact-form/hooks/use-params.js +24 -0
  13. package/es/common/components/gesco-contact-form/index.d.ts +3 -0
  14. package/es/common/components/gesco-contact-form/index.d.ts.map +1 -0
  15. package/es/common/components/gesco-contact-form/index.js +1 -1
  16. package/es/common/components/gesco-contact-form/phone-code-select.d.ts +8 -0
  17. package/es/common/components/gesco-contact-form/phone-code-select.d.ts.map +1 -0
  18. package/es/common/components/gesco-contact-form/phone-code-select.js +48 -0
  19. package/es/common/components/gesco-contact-form/phone-code-select.module.css +21 -0
  20. package/es/common/components/gesco-contact-form/services/api.d.ts +30 -0
  21. package/es/common/components/gesco-contact-form/services/api.d.ts.map +1 -0
  22. package/es/common/components/gesco-contact-form/services/api.js +12 -0
  23. package/es/common/components/gesco-contact-form/services/form.d.ts +31 -0
  24. package/es/common/components/gesco-contact-form/services/form.d.ts.map +1 -0
  25. package/es/common/components/gesco-contact-form/services/form.js +28 -0
  26. package/es/common/components/gesco-contact-form/services/messages.d.ts +33 -0
  27. package/es/common/components/gesco-contact-form/services/messages.d.ts.map +1 -0
  28. package/es/common/components/gesco-contact-form/services/messages.js +70 -0
  29. package/es/common/components/gesco-contact-form/services/plausible.d.ts +3 -0
  30. package/es/common/components/gesco-contact-form/services/plausible.d.ts.map +1 -0
  31. package/es/common/components/gesco-contact-form/services/plausible.js +11 -0
  32. package/es/common/components/gesco-contact-form/types.d.ts +33 -0
  33. package/es/common/components/gesco-contact-form/types.d.ts.map +1 -0
  34. package/es/common/components/gesco-contact-form/types.js +1 -0
  35. package/package.json +23 -23
  36. package/es/common/components/gesco-contact-form/api.js +0 -37
  37. package/es/common/components/gesco-contact-form/data.js +0 -53
  38. package/es/common/components/gesco-contact-form/messages.js +0 -74
  39. package/es/common/components/gesco-contact-form/validation.js +0 -65
@@ -0,0 +1,31 @@
1
+ import type { FormFields } from "../types";
2
+ export declare function extractValues(elements: HTMLFormControlsCollection): FormFields;
3
+ type Params = {
4
+ lang: "fr" | "en";
5
+ channel: string;
6
+ resort?: number;
7
+ merchant?: string;
8
+ facet: "WINTER" | "SUMMER";
9
+ };
10
+ export declare function buildPayload(params: Params, values: FormFields): {
11
+ userAgent: string;
12
+ browserLang: string;
13
+ subject: string;
14
+ firstname: string;
15
+ lastname: string;
16
+ email: string;
17
+ phone: string;
18
+ phoneCode?: string | undefined;
19
+ country: string;
20
+ category?: string | undefined;
21
+ stayFrom: string;
22
+ stayTo: string;
23
+ message: string;
24
+ lang: "fr" | "en";
25
+ channel: string;
26
+ resort?: number | undefined;
27
+ merchant?: string | undefined;
28
+ facet: "WINTER" | "SUMMER";
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../src/common/components/gesco-contact-form/services/form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,UAAU,CAAC;AAExD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,0BAA0B,cAuBjE;AAED,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC5B,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;EAG9D"}
@@ -0,0 +1,28 @@
1
+ export function extractValues(elements) {
2
+ return Array.from(elements).reduce((acc, element) => {
3
+ // exclude submit button
4
+ if (element instanceof HTMLButtonElement) {
5
+ return acc;
6
+ }
7
+ const { name, value } = element;
8
+ // ignore hidden inputs
9
+ if (!name) {
10
+ return acc;
11
+ }
12
+ // merge phone code and phone number + cleanup
13
+ if (name === "phone") {
14
+ const phoneWithoutZero = value.replace(/\b0+/g, "");
15
+ const phoneWithoutSpacesAndDots = phoneWithoutZero.replace(/[\s.]+/g, "");
16
+ const phoneCode = acc.phoneCode || "";
17
+ const [, code] = phoneCode.split("|");
18
+ const phoneWithCode = `+${code}${phoneWithoutSpacesAndDots}`;
19
+ delete acc.phoneCode;
20
+ return { ...acc, phone: phoneWithCode };
21
+ }
22
+ return { ...acc, [name]: value };
23
+ }, {});
24
+ }
25
+ export function buildPayload(params, values) {
26
+ const { userAgent, language: browserLang } = navigator || {};
27
+ return { ...params, ...values, userAgent, browserLang };
28
+ }
@@ -0,0 +1,33 @@
1
+ declare const fr: {
2
+ subject: string;
3
+ firstname: string;
4
+ lastname: string;
5
+ email: string;
6
+ phoneCode: string;
7
+ phone: string;
8
+ country: string;
9
+ category: string;
10
+ stay: string;
11
+ stayFrom: string;
12
+ stayFromDate: string;
13
+ stayTo: string;
14
+ stayToDate: string;
15
+ dateFormat: string;
16
+ from: string;
17
+ to: string;
18
+ message: string;
19
+ submit: string;
20
+ defaultCountry: string;
21
+ defaultCategory: string;
22
+ defaultSubject: string;
23
+ sendSucesss: string;
24
+ sendError: string;
25
+ parametersError: string;
26
+ emailError: string;
27
+ phoneError: string;
28
+ lengthError: string;
29
+ };
30
+ export declare function get(lang: "fr" | "en", overrides?: {}): Record<keyof typeof fr, string>;
31
+ export declare function format(value: string, params: Record<string, string>): string;
32
+ export {};
33
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../../src/common/components/gesco-contact-form/services/messages.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BP,CAAC;AAmCF,wBAAgB,GAAG,CACjB,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,SAAS,KAAK,GACb,MAAM,CAAC,MAAM,OAAO,EAAE,EAAE,MAAM,CAAC,CAKjC;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAKnE"}
@@ -0,0 +1,70 @@
1
+ const fr = {
2
+ subject: "Objet",
3
+ firstname: "Prénom",
4
+ lastname: "Nom",
5
+ email: "E-mail",
6
+ phoneCode: "Indicatif",
7
+ phone: "Téléphone",
8
+ country: "Pays",
9
+ category: "Destinataire",
10
+ stay: "Dates de séjour",
11
+ stayFrom: "Date de début",
12
+ stayFromDate: "Date de début de séjour",
13
+ stayTo: "Date de fin",
14
+ stayToDate: "Date de fin de séjour",
15
+ dateFormat: "Choisissez une date",
16
+ from: "Du",
17
+ to: "au",
18
+ message: "Message",
19
+ submit: "Envoyer le message",
20
+ defaultCountry: "Indiquez votre pays...",
21
+ defaultCategory: "Sélectionnez...",
22
+ defaultSubject: "Sélectionnez...",
23
+ sendSucesss: "Votre message à bien été envoyé !",
24
+ sendError: "Une erreur est survenue pendant l'envoi du message. Veuillez réessayer ultérieurement.",
25
+ parametersError: "Une erreur est survenue pendant la génération du formulaire. Veuillez réessayer ultérieurement.",
26
+ emailError: 'L\'email doit être au format "john.doe@domaine.com"',
27
+ phoneError: 'Le téléphone doit être au format "0612345678"',
28
+ lengthError: '"{label}" doit contenir au moins {length} caractères',
29
+ };
30
+ const en = {
31
+ subject: "Subject",
32
+ firstname: "Firstname",
33
+ lastname: "Lastname",
34
+ email: "E-mail",
35
+ phoneCode: "Phone code",
36
+ phone: "Phone number",
37
+ country: "Country",
38
+ category: "Addressee",
39
+ stay: "Stay dates",
40
+ stayFromDate: "Stay from date",
41
+ stayToDate: "Stay to date",
42
+ stayFrom: "From date",
43
+ stayTo: "End date",
44
+ dateFormat: "Choose a date",
45
+ from: "From",
46
+ to: "to",
47
+ message: "Message",
48
+ submit: "Send message",
49
+ defaultCountry: "Select your country...",
50
+ defaultCategory: "Select...",
51
+ defaultSubject: "Select...",
52
+ sendSucesss: "Your message was just sent !",
53
+ sendError: "An error occured during the sending of the message. Please try again later.",
54
+ parametersError: "An error occured during the creation of the form. Please try again later.",
55
+ emailError: 'The email must be in the format "john.doe@domain.com"',
56
+ phoneError: 'The phone number must be in the following formats: "0612345678" or "555 555 555',
57
+ lengthError: '"{label}" must contain at least {length} characters',
58
+ };
59
+ export function get(lang, overrides = {}) {
60
+ const locale = lang === "fr" ? fr : en;
61
+ const override = overrides[lang] || {};
62
+ const locales = { ...locale, ...override };
63
+ return locales;
64
+ }
65
+ export function format(value, params) {
66
+ return Object.keys(params).reduce((acc, param) => {
67
+ const search = `{${param}}`;
68
+ return acc.replace(search, params[param]);
69
+ }, value);
70
+ }
@@ -0,0 +1,3 @@
1
+ import type { FormFields, Params } from "../types";
2
+ export declare function sendEvent(values: FormFields, params?: Params): void;
3
+ //# sourceMappingURL=plausible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plausible.d.ts","sourceRoot":"","sources":["../../../../../src/common/components/gesco-contact-form/services/plausible.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEnD,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,QAY5D"}
@@ -0,0 +1,11 @@
1
+ import * as Plausible from "../../plausible";
2
+ export function sendEvent(values, params) {
3
+ if (!params)
4
+ return;
5
+ const country = params.countries.find((country) => country.code === values.country);
6
+ const subject = params.subjects.find((subject) => subject.id === values.subject);
7
+ Plausible.sendGoal("Contact-us", {
8
+ Country: country?.name,
9
+ Subject: subject?.label,
10
+ });
11
+ }
@@ -0,0 +1,33 @@
1
+ export type FormFields = {
2
+ subject: string;
3
+ firstname: string;
4
+ lastname: string;
5
+ email: string;
6
+ phone: string;
7
+ phoneCode?: string;
8
+ country: string;
9
+ category?: string;
10
+ stayFrom: string;
11
+ stayTo: string;
12
+ message: string;
13
+ };
14
+ export type FormElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
15
+ type Country = {
16
+ code: string;
17
+ name: string;
18
+ };
19
+ type Category = {
20
+ code: string;
21
+ label: string;
22
+ };
23
+ type Subject = {
24
+ id: string;
25
+ label: string;
26
+ };
27
+ export type Params = {
28
+ countries: Country[];
29
+ categories: Category[];
30
+ subjects: Subject[];
31
+ };
32
+ export {};
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/common/components/gesco-contact-form/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB,gBAAgB,GAChB,iBAAiB,GACjB,mBAAmB,CAAC;AAExB,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.23.6",
3
+ "version": "1.24.1",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^3.1.5",
6
6
  "leaflet": "^1.9.1",
@@ -24,42 +24,42 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "awesome-debounce-promise": "2.1.0",
27
- "classnames": "2.3.2",
28
- "framer-motion": "10.16.5",
27
+ "classnames": "2.5.1",
28
+ "framer-motion": "11.0.3",
29
29
  "react-async-hook": "4.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@babel/cli": "7.22.6",
33
- "@babel/core": "7.22.6",
34
- "@babel/eslint-parser": "7.22.6",
35
- "@babel/eslint-plugin": "^7.22.5",
32
+ "@babel/cli": "7.23.4",
33
+ "@babel/core": "7.23.7",
34
+ "@babel/eslint-parser": "7.23.3",
35
+ "@babel/eslint-plugin": "^7.23.5",
36
36
  "@babel/plugin-proposal-class-properties": "7.18.6",
37
- "@babel/preset-react": "7.22.5",
38
- "@babel/preset-typescript": "7.22.5",
39
- "@types/css-modules": "1.0.2",
40
- "@types/react": "18.2.14",
41
- "@types/react-dom": "18.2.6",
42
- "classnames": "2.3.2",
37
+ "@babel/preset-react": "7.23.3",
38
+ "@babel/preset-typescript": "7.23.3",
39
+ "@types/css-modules": "1.0.5",
40
+ "@types/react": "18.2.48",
41
+ "@types/react-dom": "18.2.18",
42
+ "classnames": "2.5.1",
43
43
  "cors": "2.8.5",
44
44
  "cpx2": "4.2.3",
45
- "dt-design-system": "3.1.5",
46
- "eslint": "8.44.0",
47
- "eslint-config-prettier": "8.8.0",
45
+ "dt-design-system": "3.6.19",
46
+ "eslint": "8.56.0",
47
+ "eslint-config-prettier": "9.1.0",
48
48
  "eslint-config-standard": "17.1.0",
49
- "eslint-plugin-import": "^2.27.5",
50
- "eslint-plugin-jsx-a11y": "6.7.1",
51
- "eslint-plugin-n": "16.0.1",
49
+ "eslint-plugin-import": "2.29.1",
50
+ "eslint-plugin-jsx-a11y": "6.8.0",
51
+ "eslint-plugin-n": "16.6.2",
52
52
  "eslint-plugin-node": "11.1.0",
53
53
  "eslint-plugin-promise": "6.1.1",
54
- "eslint-plugin-react": "7.32.2",
54
+ "eslint-plugin-react": "7.33.2",
55
55
  "eslint-plugin-react-hooks": "4.6.0",
56
56
  "mv": "2.1.1",
57
- "next": "13.4.8",
57
+ "next": "14.1.0",
58
58
  "react": "18.2.0",
59
59
  "react-dom": "18.2.0",
60
60
  "react-scripts": "5.0.1",
61
- "typescript": "5.2.2",
62
- "ublo": "3.14.5"
61
+ "typescript": "5.3.3",
62
+ "ublo": "3.16.0"
63
63
  },
64
64
  "scripts": {
65
65
  "clean": "rm -rf es",
@@ -1,37 +0,0 @@
1
- import * as Data from "./data";
2
- export async function fetchParams(lang, resort, merchant, channel, categories, integration = false, uat = false) {
3
- const host = integration ? Data.HOSTS.TEST : uat ? Data.HOSTS.UAT : Data.HOSTS.PROD;
4
- const res = await fetch(`${host}/api/gesco/contact/parameters`, {
5
- method: "POST",
6
- headers: {
7
- "content-type": "application/json;charset=utf-8"
8
- },
9
- body: JSON.stringify({
10
- lang,
11
- resort,
12
- merchant,
13
- channel,
14
- categories
15
- })
16
- });
17
- return res.json();
18
- }
19
- export async function postMessage(payload, integration = false, uat = false) {
20
- const host = integration ? Data.HOSTS.TEST : uat ? Data.HOSTS.UAT : Data.HOSTS.PROD;
21
- const {
22
- userAgent,
23
- language: browserLang
24
- } = navigator || {};
25
- const res = await fetch(`${host}/api/gesco/contact/send`, {
26
- method: "POST",
27
- headers: {
28
- "content-type": "application/json;charset=utf-8"
29
- },
30
- body: JSON.stringify({
31
- ...payload,
32
- userAgent,
33
- browserLang
34
- })
35
- });
36
- return res.json();
37
- }
@@ -1,53 +0,0 @@
1
- import * as Validation from "./validation";
2
- export const HOSTS = {
3
- PROD: "https://admin.mon-sejour-en-montagne.com",
4
- TEST: "https://admin-integration.mon-sejour-en-montagne.com",
5
- UAT: "https://admin-uat.mon-sejour-en-montagne.com"
6
- };
7
- export const DEFAULT_PARAMS = {
8
- countries: [],
9
- categories: [],
10
- subjects: []
11
- };
12
- export const DEFAULT_FIELDS = {
13
- firstname: {
14
- value: "",
15
- validators: [Validation.min(2), Validation.mandatory]
16
- },
17
- lastname: {
18
- value: "",
19
- validators: [Validation.min(2), Validation.mandatory]
20
- },
21
- email: {
22
- value: "",
23
- validators: [Validation.email, Validation.mandatory]
24
- },
25
- phone: {
26
- value: "",
27
- validators: [Validation.phone, Validation.mandatory]
28
- },
29
- message: {
30
- value: "",
31
- validators: [Validation.min(10), Validation.mandatory]
32
- },
33
- country: {
34
- value: "",
35
- validators: [Validation.mandatory]
36
- },
37
- stayFrom: {
38
- value: "",
39
- validators: [Validation.date, Validation.mandatory]
40
- },
41
- stayTo: {
42
- value: "",
43
- validators: [Validation.date, Validation.mandatory, Validation.afterDate("stayFrom")]
44
- },
45
- category: {
46
- value: "",
47
- validators: [Validation.mandatory]
48
- },
49
- subject: {
50
- value: "",
51
- validators: [Validation.mandatory]
52
- }
53
- };
@@ -1,74 +0,0 @@
1
- const messages = {
2
- fr: {
3
- subject: "Objet",
4
- firstname: "Votre prénom",
5
- lastname: "Votre nom",
6
- email: "Votre email",
7
- phone: "Votre téléphone",
8
- country: "Votre pays",
9
- category: "Destinataire",
10
- stay: "Dates de séjour",
11
- stayFrom: "Date de début",
12
- stayFromDate: "Date de début de séjour",
13
- stayTo: "Date de fin",
14
- stayToDate: "Date de fin de séjour",
15
- dateFormat: "aaaa-mm-jj",
16
- from: "Du",
17
- to: "au",
18
- message: "Message",
19
- submit: "Envoyer le message",
20
- defaultCountry: "Indiquez votre pays...",
21
- defaultCategory: "Sélectionnez...",
22
- defaultSubject: "Précisez l'objet de votre demande...",
23
- errorMail: '"{label}" n\'est pas une adresse valide',
24
- errorPhone: '"{label}" n\'est pas un numéro valide',
25
- errorMax: '"{label}" ne peut pas dépasser {length} caractères',
26
- errorMin: '"{label}" doit faire au moins {length} caractères',
27
- errorMandatory: '"{label}" est obligatoire',
28
- errorDate: '"{label}" doit être une date',
29
- errorDateAfter: '"{label}" doit être postérieure au {otherDate}',
30
- messageSent: "Votre message à bien été envoyé !",
31
- parametersError: "Une erreur est survenue pendant la génération du formulaire. Veuillez réessayer ultérieurement."
32
- },
33
- en: {
34
- subject: "Subject",
35
- firstname: "Your firstname",
36
- lastname: "Your lastname",
37
- email: "Your email",
38
- phone: "Your phone number",
39
- country: "Country",
40
- category: "Addressee",
41
- stay: "Stay dates",
42
- stayFromDate: "Stay from date",
43
- stayToDate: "Stay to date",
44
- stayFrom: "From date",
45
- stayTo: "End date",
46
- dateFormat: "yyyy-mm-dd",
47
- from: "From",
48
- to: "to",
49
- message: "Message",
50
- submit: "Send message",
51
- defaultCountry: "Select your country...",
52
- defaultCategory: "Select...",
53
- defaultSubject: "Select the type of request...",
54
- errorMail: '"{label}" is not a valid adress',
55
- errorPhone: '"{label}" is not a valid number',
56
- errorMax: '"{label}" cannot be longer than {length} characters',
57
- errorMin: '"{label}" should be at least {length} characters long',
58
- errorMandatory: '"{label}" is mandatory',
59
- errorDate: '"{label}" must be a date',
60
- errorDateAfter: '"{label}" must be after {otherDate}',
61
- messageSent: "Your message was just sent !",
62
- parametersError: "An error occured during the creation of the form. Please try again later."
63
- }
64
- };
65
- export const get = (lang, message) => {
66
- const _lang = messages[lang] === undefined ? "en" : lang;
67
- return messages[_lang][message];
68
- };
69
- export const getFormated = (lang, message, params) => {
70
- return Object.keys(params).reduce((acc, param) => {
71
- const search = `{${param}}`;
72
- return acc.replace(search, params[param]);
73
- }, get(lang, message));
74
- };
@@ -1,65 +0,0 @@
1
- import * as Messages from "./messages";
2
- export function validate(lang, name, value = "", validators, fields) {
3
- return validators.reduce((acc, validator) => {
4
- const label = Messages.get(lang, name);
5
- return acc === undefined ? validator(lang, label, value, fields) : acc;
6
- }, undefined);
7
- }
8
- const mailCheck = /^\w+([.\-+]?\w+)*@\w+([.-]?\w+)*(.\w{2,})+$/;
9
- export function email(lang, label, value) {
10
- if (mailCheck.exec(value) === null) {
11
- return Messages.getFormated(lang, "errorMail", {
12
- label
13
- });
14
- }
15
- }
16
- const phoneCheck = /^\+?[0-9,(,),.,\-, ]{6,19}[0-9]$/;
17
- export function phone(lang, label, value) {
18
- if (phoneCheck.exec(value) === null) {
19
- return Messages.getFormated(lang, "errorPhone", {
20
- label
21
- });
22
- }
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
- }
34
- const dateCheck = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
35
- export function date(lang, label, value) {
36
- const date = new Date(value);
37
- const strValid = dateCheck.exec(value) !== null;
38
- const isValid = strValid && date instanceof Date && !isNaN(date);
39
- return isValid ? undefined : Messages.getFormated(lang, "errorDate", {
40
- label
41
- });
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) {
59
- const value = val.trim();
60
- if (value === undefined || value.length === 0) {
61
- return Messages.getFormated(lang, "errorMandatory", {
62
- label
63
- });
64
- }
65
- }