ublo-lib 1.17.7 → 1.18.0

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 (38) hide show
  1. package/es/common/components/editable-calendar/calendar.js +3 -2
  2. package/es/esf/components/{instructors-book-v2 → instructors-book}/api.js +12 -8
  3. package/es/esf/components/{instructors-book-v2 → instructors-book}/book.js +1 -1
  4. package/es/esf/components/{instructors-book-v2 → instructors-book}/filters.js +2 -2
  5. package/es/esf/components/instructors-book/index.js +6 -3
  6. package/es/esf/components/{instructors-book-v2 → instructors-book}/instructor.js +6 -6
  7. package/es/esf/components/instructors-book/list.js +39 -170
  8. package/es/esf/components/instructors-book/messages.js +36 -37
  9. package/es/esf/components/{instructors-book-v2 → instructors-book}/sheet.js +17 -17
  10. package/es/esf/components/instructors-book/utils.js +48 -2
  11. package/package.json +1 -1
  12. package/es/esf/components/instructor-suggestions/fetcher.js +0 -16
  13. package/es/esf/components/instructor-suggestions/icons.js +0 -266
  14. package/es/esf/components/instructor-suggestions/index.js +0 -2
  15. package/es/esf/components/instructor-suggestions/instructor-suggestions.js +0 -180
  16. package/es/esf/components/instructor-suggestions/loader.js +0 -8
  17. package/es/esf/components/instructor-suggestions/messages.js +0 -16
  18. package/es/esf/components/instructors-book/container.js +0 -18
  19. package/es/esf/components/instructors-book/details.js +0 -117
  20. package/es/esf/components/instructors-book/icons.js +0 -266
  21. package/es/esf/components/instructors-book/inner.js +0 -15
  22. package/es/esf/components/instructors-book/instructors-book.js +0 -111
  23. package/es/esf/components/instructors-book/link.js +0 -17
  24. package/es/esf/components/instructors-book/list-utils.js +0 -18
  25. package/es/esf/components/instructors-book/loader.js +0 -8
  26. package/es/esf/components/instructors-book-v2/index.js +0 -6
  27. package/es/esf/components/instructors-book-v2/list.js +0 -47
  28. package/es/esf/components/instructors-book-v2/messages.js +0 -41
  29. package/es/esf/components/instructors-book-v2/utils.js +0 -51
  30. /package/es/esf/components/{instructors-book-v2 → instructors-book}/book.module.css +0 -0
  31. /package/es/esf/components/{instructors-book-v2 → instructors-book}/filters.module.css +0 -0
  32. /package/es/esf/components/{instructors-book-v2 → instructors-book}/flags.js +0 -0
  33. /package/es/esf/components/{instructors-book-v2 → instructors-book}/instructor.module.css +0 -0
  34. /package/es/esf/components/{instructors-book-v2 → instructors-book}/list.module.css +0 -0
  35. /package/es/esf/components/{instructors-book-v2 → instructors-book}/prefixes.js +0 -0
  36. /package/es/esf/components/{instructors-book-v2 → instructors-book}/sheet.module.css +0 -0
  37. /package/es/esf/components/{instructors-book-v2 → instructors-book}/suggestions.js +0 -0
  38. /package/es/esf/components/{instructors-book-v2 → instructors-book}/suggestions.module.css +0 -0
@@ -23,8 +23,9 @@ function Calendar({
23
23
  const now = new Date();
24
24
  const minDate = now;
25
25
  if (minDate) minDate.setHours(0, 0, 0, 0);
26
- const defaultMonth = Date.THIS_MONTH;
27
- const currentMonth = getMonthFromPresets(presets?.dates);
26
+ const currentMonth = Data.THIS_MONTH;
27
+ const presetMonth = getMonthFromPresets(presets?.dates);
28
+ const defaultMonth = currentMonth > presetMonth ? currentMonth : presetMonth;
28
29
  const currentYear = Data.THIS_YEAR;
29
30
  const [month, setMonth] = React.useState(currentMonth);
30
31
  const [year, setYear] = React.useState(currentYear);
@@ -5,15 +5,16 @@ const {
5
5
  const {
6
6
  resort
7
7
  } = publicRuntimeConfig;
8
- const host = "https://instructors-book-server.carnet-rouge-esf.com";
9
- const authorization = "00q2qa545018261l252gg3414t3qa2";
8
+ const carnetRougeApi = "https://services.carnet-rouge-esf.app/api";
9
+ const authorizationCarnetRouge = "6bdecf9053927dcc7e10923a2cc603a4";
10
10
  const fetcher = async (url, body) => {
11
11
  const res = await fetch(url, {
12
12
  method: "POST",
13
13
  headers: {
14
- "content-type": "application/json;charset=utf-8",
15
- Authorization: authorization,
16
- schoolcode: resort
14
+ ...(body ? {
15
+ "content-type": "application/json;charset=utf-8"
16
+ } : {}),
17
+ Authorization: authorizationCarnetRouge
17
18
  },
18
19
  body: body ? JSON.stringify(body) : undefined
19
20
  });
@@ -21,7 +22,8 @@ const fetcher = async (url, body) => {
21
22
  };
22
23
  export async function fetchInstructors(lang, body = {}) {
23
24
  try {
24
- return fetcher(`${host}/api/instructors-book/${resort}/${lang}`, {
25
+ const url = `${carnetRougeApi}/annuaire/public/moniteurs/${resort}/${lang}`;
26
+ return fetcher(url, {
25
27
  ...body,
26
28
  project: true
27
29
  });
@@ -32,7 +34,8 @@ export async function fetchInstructors(lang, body = {}) {
32
34
  }
33
35
  export async function fetchInstructor(lang, uri) {
34
36
  try {
35
- return fetcher(`${host}/api/instructors-book/${resort}/${lang}/${uri}`);
37
+ const url = `${carnetRougeApi}/annuaire/public/moniteur/${resort}/${lang}/${uri}`;
38
+ return fetcher(url);
36
39
  } catch (e) {
37
40
  console.warn(e);
38
41
  return {};
@@ -40,7 +43,8 @@ export async function fetchInstructor(lang, uri) {
40
43
  }
41
44
  export const fetchRandomInstructors = async (lang, tags, nbInstructor) => {
42
45
  try {
43
- return fetcher(`${host}/api/instructors-book/${resort}/${lang}/byTags`, {
46
+ const url = `${carnetRougeApi}/annuaire/public/moniteurs/${resort}/${lang}/by-tags`;
47
+ return fetcher(url, {
44
48
  tags,
45
49
  size: nbInstructor
46
50
  });
@@ -76,7 +76,7 @@ export default function Book({
76
76
  loading: loading
77
77
  }), _jsx(List, {
78
78
  search: search,
79
- instructors: context.instructors,
79
+ instructors: context.moniteurs,
80
80
  trombi: isTrombi
81
81
  })]
82
82
  });
@@ -18,8 +18,8 @@ export default function Filters({
18
18
  lang
19
19
  } = useUbloContext();
20
20
  const {
21
- activities,
22
- languages
21
+ disciplines: activities,
22
+ langues: languages
23
23
  } = context;
24
24
  const formatedActivities = ["", ...activities.map(({
25
25
  code,
@@ -1,3 +1,6 @@
1
- import instructorsBook from "./instructors-book";
2
- export { fetchInstructor, fetchInstructorsContext } from "./instructors-book";
3
- export default instructorsBook;
1
+ import * as API from "./api";
2
+ import Book from "./book";
3
+ import Sheet from "./sheet";
4
+ import Suggestions from "./suggestions";
5
+ import prefixes from "./prefixes";
6
+ export { Book, Sheet, Suggestions, API, prefixes };
@@ -22,8 +22,8 @@ export default function Instructor({
22
22
  lang
23
23
  } = useUbloContext();
24
24
  const {
25
- firstname,
26
- lastname,
25
+ prenom,
26
+ nom,
27
27
  photo,
28
28
  uri
29
29
  } = instructor;
@@ -66,7 +66,7 @@ export default function Instructor({
66
66
  loading: "lazy",
67
67
  src: picture,
68
68
  className: css.imageBackground,
69
- alt: `${firstname} ${lastname}`,
69
+ alt: `${prenom} ${nom}`,
70
70
  width: "170",
71
71
  height: "220"
72
72
  }), picture ? _jsxs(_Fragment, {
@@ -76,7 +76,7 @@ export default function Instructor({
76
76
  loading: "lazy",
77
77
  src: picture,
78
78
  className: css.image,
79
- alt: `${firstname} ${lastname}`,
79
+ alt: `${prenom} ${nom}`,
80
80
  onLoad: stopLoading,
81
81
  onError: setFallbackPicture,
82
82
  width: "170",
@@ -94,10 +94,10 @@ export default function Instructor({
94
94
  className: css.name,
95
95
  children: [_jsxs("span", {
96
96
  className: css.firstName,
97
- children: [Utils.formatNames(firstname), " "]
97
+ children: [Utils.formatNames(prenom), " "]
98
98
  }), _jsx("span", {
99
99
  className: css.lastName,
100
- children: Utils.formatNames(lastname)
100
+ children: Utils.formatNames(nom)
101
101
  })]
102
102
  })
103
103
  })]
@@ -1,178 +1,47 @@
1
1
  import * as React from "react";
2
- import { useEffect, useState } from "react";
3
- import Container from "./container";
4
- import Loader from "./loader";
5
- import { flags, PersonIcon, OverlayIcon } from "./icons";
6
- import getMessage from "./messages";
7
- import { formatNames } from "./utils";
8
- import { filter } from "./list-utils";
2
+ import classNames from "classnames";
3
+ import { useUbloContext } from "ublo/with-ublo";
4
+ import * as Utils from "./utils";
5
+ import Instructor from "./instructor";
6
+ import { message } from "./messages";
7
+ import css from "./list.module.css";
9
8
  import { jsx as _jsx } from "react/jsx-runtime";
10
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
11
- import { Fragment as _Fragment } from "react/jsx-runtime";
12
- const List = ({
10
+ export default function List({
11
+ search = "",
13
12
  instructors,
14
- activities,
15
- languages,
13
+ fromSuggestions,
14
+ formSendFunction,
15
+ formFields,
16
16
  trombi,
17
- lang,
18
- activity,
19
- language,
20
- selectInstructor,
21
- selectFilter
22
- }) => {
23
- const [search, setSearch] = useState("");
24
- const [displayedInstructors, setDisplayedInstructors] = useState(filter(instructors));
25
- const texts = getMessage(lang);
26
- useEffect(() => {
27
- const displayedInstructors = filter(instructors, search);
28
- setDisplayedInstructors(displayedInstructors);
29
- }, [instructors, search]);
30
- const changeFilter = filter => e => {
31
- if (selectFilter !== undefined) {
32
- selectFilter(filter, e.target.value);
33
- }
34
- };
35
- const renderHeader = () => {
36
- return _jsxs("div", {
37
- className: "instructors-book-list__top",
38
- children: [_jsxs("div", {
39
- className: "instructors-book-list__top-left",
40
- children: [_jsx("h2", {
41
- className: "instructors-book-list__title",
42
- children: texts["instructors-book-title-1"]
43
- }), _jsx("div", {
44
- className: "instructors-book-list__tagline",
45
- children: texts["instructors-book-title-2"]
46
- }), _jsx("div", {
47
- className: "instructors-book-list__helper",
48
- children: texts["instructors-book-intro"]
49
- })]
50
- }), _jsxs("div", {
51
- className: "instructors-book-list__filters",
52
- children: [_jsxs("div", {
53
- className: "instructors-book-list__filters-title",
54
- children: [texts["instructors-book-search-1"], " ", _jsx("span", {
55
- className: "instructors-book-list__filters-title-span",
56
- children: texts["instructors-book-search-2"]
57
- })]
58
- }), _jsx("div", {
59
- className: "instructors-book-list__input-filler",
60
- children: _jsx("input", {
61
- value: search,
62
- className: "instructors-book-list__input",
63
- placeholder: texts["instructors-book-placeholder-search"],
64
- onChange: e => setSearch(e.target.value.toLowerCase())
65
- })
66
- }), _jsx("label", {
67
- htmlFor: "instructors-book-practice-filter",
68
- className: "instructors-book-list__label",
69
- children: texts["instructors-book-filter-activity"]
70
- }), _jsx("div", {
71
- className: "instructors-book-list__input-filler instructors-book-list__input-filler--select",
72
- children: _jsxs("select", {
73
- value: activity,
74
- id: "instructors-book-practice-filter",
75
- className: "instructors-book-list__input instructors-book-list__input--select",
76
- onChange: changeFilter("activity"),
77
- children: [_jsx("option", {
78
- value: "",
79
- children: texts["instructors-book-placeholder-activity"]
80
- }), activities && activities.map(({
81
- code,
82
- label
83
- }) => _jsx("option", {
84
- value: code,
85
- children: label
86
- }, code))]
87
- })
88
- }), _jsx("label", {
89
- htmlFor: "instructors-book-language-filter",
90
- className: "instructors-book-list__label",
91
- children: texts["instructors-book-filter-language"]
92
- }), _jsx("div", {
93
- className: "instructors-book-list__input-filler instructors-book-list__input-filler--select",
94
- children: _jsxs("select", {
95
- value: language,
96
- id: "instructors-book-language-filter",
97
- className: "instructors-book-list__input instructors-book-list__input--select",
98
- onChange: changeFilter("language"),
99
- children: [_jsx("option", {
100
- value: "",
101
- children: texts["instructors-book-placeholder-language"]
102
- }), languages && languages.map(({
103
- code,
104
- label
105
- }) => _jsx("option", {
106
- value: code,
107
- children: label
108
- }, code))]
109
- })
110
- })]
111
- })]
112
- });
113
- };
114
- const renderInstructor = (instructor, index) => {
115
- const {
116
- firstname,
117
- lastname,
118
- photo,
119
- activities,
120
- languages,
121
- uri
122
- } = instructor;
123
- return _jsxs(Container, {
124
- trombi: trombi,
125
- className: "instructors-book-list__instructor",
126
- ...selectInstructor(uri),
127
- children: [_jsxs("div", {
128
- className: "instructors-book-list__instructor-image-container",
129
- children: [!trombi && _jsx("div", {
130
- className: "instructors-book-list__instructor-overlay",
131
- children: _jsx(OverlayIcon, {
132
- className: "instructors-book-list__instructor-overlay-icon"
133
- })
134
- }), photo ? _jsx("img", {
135
- loading: "lazy",
136
- src: photo,
137
- className: "instructors-book-list__instructor-image",
138
- alt: `${firstname} ${lastname}`
139
- }) : _jsx(PersonIcon, {
140
- className: "instructors-book-list__instructor-imageplaceholder"
141
- })]
142
- }), _jsxs("div", {
143
- className: "instructors-book-list__instructor-name",
144
- children: [formatNames(firstname), " ", _jsx("span", {
145
- className: "instructors-book-list__instructor-lastname",
146
- children: formatNames(lastname)
147
- })]
148
- }), trombi && _jsxs(_Fragment, {
149
- children: [_jsx("div", {
150
- className: "instructors-book-list__instructor-practices",
151
- children: activities && activities.map(({
152
- label
153
- }) => label).join(" - ")
154
- }), _jsx("div", {
155
- className: "instructors-book-list__instructor-langs",
156
- children: languages && languages.map(({
157
- code,
158
- label
159
- }) => {
160
- const Flag = flags[code];
161
- return _jsx(Flag, {
162
- className: "instructors-book-list__instructor-lang",
163
- title: label
164
- }, code);
165
- })
166
- })]
167
- })]
168
- }, uri || `instructor-${index}`);
169
- };
17
+ popup
18
+ }) {
19
+ const {
20
+ lang
21
+ } = useUbloContext();
22
+ const displayedInstructors = fromSuggestions ? instructors : Utils.filter(instructors, search);
23
+ const listCountMessageCode = displayedInstructors?.length > 1 ? "instructors" : "instructor";
24
+ const classes = classNames(css.container, {
25
+ [css.containerSuggestions]: fromSuggestions
26
+ });
170
27
  return _jsxs("div", {
171
- className: "instructors-book-list",
172
- children: [renderHeader(), _jsx("div", {
173
- className: "instructors-book-list__inner",
174
- children: displayedInstructors ? displayedInstructors.map((instructor, index) => renderInstructor(instructor, index)) : _jsx(Loader, {})
28
+ className: classes,
29
+ children: [!fromSuggestions && _jsxs("div", {
30
+ className: css.listCount,
31
+ children: [_jsx("b", {
32
+ children: displayedInstructors.length
33
+ }), " ", message(lang, listCountMessageCode)]
34
+ }), _jsx("div", {
35
+ className: css.inner,
36
+ children: displayedInstructors?.map(instructor => {
37
+ return _jsx(Instructor, {
38
+ instructor: instructor,
39
+ trombi: trombi,
40
+ formFields: formFields,
41
+ formSendFunction: formSendFunction,
42
+ popup: popup
43
+ }, instructor.uri);
44
+ })
175
45
  })]
176
46
  });
177
- };
178
- export default List;
47
+ }
@@ -1,42 +1,41 @@
1
- const messages = {
1
+ const locales = {
2
2
  fr: {
3
- "instructors-book-title-1": "le book",
4
- "instructors-book-title-2": "des moniteurs",
5
- "instructors-book-intro": "Cliquez sur un moniteur pour afficher ses informations",
6
- "instructors-book-search-1": "recherchez",
7
- "instructors-book-search-2": "votre moniteur",
8
- "instructors-book-filter-activity": "Filtrer par pratique",
9
- "instructors-book-filter-language": "Filtrer par langue",
10
- "instructors-book-placeholder-search": "Nom, prénom...",
11
- "instructors-book-placeholder-activity": "Sélectionnez une pratique",
12
- "instructors-book-placeholder-language": "Sélectionnez une langue",
13
- "instructors-book-activities": "Mes spécialités sont : ",
14
- "instructors-book-about": "À propos",
15
- "instructors-book-and": " et ",
16
- "instructors-book-back-to-list": "Retour"
3
+ "search-label": "Chercher un moniteur",
4
+ "search-placeholder": "Nom, prénom...",
5
+ "activity-label": "Quelle pratique ?",
6
+ "language-label": "Quelle langue ?",
7
+ instructors: "moniteurs trouvés",
8
+ instructor: "moniteur trouvé",
9
+ activities: "Activités pratiquées",
10
+ and: "et",
11
+ languages: "Langues parlées",
12
+ about: "À propos",
13
+ contact: "Quand souhaitez-vous skier avec moi ?",
14
+ "suggestions-title": "Les moniteurs qui vous proposent ce cours",
15
+ "suggestions-button": "Voir tous les moniteurs",
16
+ "see-more": "Voir plus",
17
+ "go-back": "Retour"
17
18
  },
18
19
  en: {
19
- "instructors-book-title-1": "ski instructors'",
20
- "instructors-book-title-2": "book",
21
- "instructors-book-intro": "Click an instructor bellow to display his informations",
22
- "instructors-book-search-1": "search",
23
- "instructors-book-search-2": "your instructor",
24
- "instructors-book-filter-activity": "Filter by discipline",
25
- "instructors-book-filter-language": "Filter by spoken language",
26
- "instructors-book-placeholder-search": "Lastname, firstname...",
27
- "instructors-book-placeholder-activity": "Select a discipline",
28
- "instructors-book-placeholder-language": "Select a language",
29
- "instructors-book-activities": "My disciplines are : ",
30
- "instructors-book-about": "About",
31
- "instructors-book-and": " and ",
32
- "instructors-book-back-to-list": "Go back"
20
+ "search-label": "Search an instructor",
21
+ "search-placeholder": "Lastname, firstname...",
22
+ "activity-label": "Which activity?",
23
+ "language-label": "Which language?",
24
+ instructors: "instructors found",
25
+ instructor: "instructor found",
26
+ activities: "Activities",
27
+ and: "and",
28
+ languages: "Spoken languages",
29
+ about: "About",
30
+ contact: "When would you like to ski with me?",
31
+ "suggestions-title": "The instructors who offer you this course",
32
+ "suggestions-button": "See all instructors",
33
+ "see-more": "See more",
34
+ "go-back": "Go back"
33
35
  }
34
36
  };
35
- const getMessage = lang => {
36
- if (messages[lang] !== undefined) {
37
- return messages[lang];
38
- } else {
39
- return messages.en;
40
- }
41
- };
42
- export default getMessage;
37
+ export const message = (lang, id) => {
38
+ const locale = lang === "fr" ? "fr" : "en";
39
+ const messages = locales[locale];
40
+ return messages[id] || `??${id}??`;
41
+ };
@@ -21,11 +21,11 @@ export default function Sheet({
21
21
  bookUrl
22
22
  }) {
23
23
  const {
24
- firstname,
25
- lastname,
24
+ prenom,
25
+ nom,
26
26
  photo,
27
- languages,
28
- activities,
27
+ langues,
28
+ disciplines,
29
29
  introduction,
30
30
  description,
31
31
  uri
@@ -65,7 +65,7 @@ export default function Sheet({
65
65
  loading: "lazy",
66
66
  src: picture,
67
67
  className: css.imageBackground,
68
- alt: `${firstname} ${lastname}`,
68
+ alt: `${prenom} ${nom}`,
69
69
  width: "170",
70
70
  height: "220"
71
71
  }), picture ? _jsxs(_Fragment, {
@@ -75,7 +75,7 @@ export default function Sheet({
75
75
  loading: "lazy",
76
76
  src: picture,
77
77
  className: css.image,
78
- alt: `${firstname} ${lastname}`,
78
+ alt: `${prenom} ${nom}`,
79
79
  onLoad: stopLoading,
80
80
  onError: setFallbackPicture,
81
81
  width: "190",
@@ -93,24 +93,24 @@ export default function Sheet({
93
93
  className: css.name,
94
94
  children: [_jsxs("span", {
95
95
  className: css.firstName,
96
- children: [Utils.formatNames(firstname), " "]
96
+ children: [Utils.formatNames(prenom), " "]
97
97
  }), _jsx("span", {
98
98
  className: css.lastName,
99
- children: Utils.formatNames(lastname)
99
+ children: Utils.formatNames(nom)
100
100
  })]
101
- }), activities && _jsxs("div", {
101
+ }), disciplines && _jsxs("div", {
102
102
  className: css.activities,
103
103
  children: [_jsx("div", {
104
104
  className: css.activitiesTitle,
105
105
  children: message(lang, "activities")
106
106
  }), _jsx("div", {
107
107
  className: css.activitiesList,
108
- children: activities.map((activity, i) => {
108
+ children: disciplines.map((discipline, i) => {
109
109
  const {
110
110
  code,
111
111
  label
112
- } = activity;
113
- const length = activities.length;
112
+ } = discipline;
113
+ const length = disciplines.length;
114
114
  return _jsxs("span", {
115
115
  className: css.activity,
116
116
  children: [_jsx("span", {
@@ -119,19 +119,19 @@ export default function Sheet({
119
119
  }, code);
120
120
  })
121
121
  })]
122
- }), languages && _jsxs("div", {
122
+ }), langues && _jsxs("div", {
123
123
  className: css.languages,
124
124
  children: [_jsx("div", {
125
125
  className: css.languagesTitle,
126
126
  children: message(lang, "languages")
127
127
  }), _jsx("div", {
128
128
  className: css.languagesList,
129
- children: languages.map((language, i) => {
129
+ children: langues.map((langue, i) => {
130
130
  const {
131
131
  code,
132
132
  label
133
- } = language;
134
- const length = languages.length;
133
+ } = langue;
134
+ const length = langues.length;
135
135
  return _jsxs("span", {
136
136
  className: css.language,
137
137
  children: [label, " ", i < length - 1 ? " - " : ""]
@@ -171,7 +171,7 @@ export default function Sheet({
171
171
  fields: formFields,
172
172
  className: css.form,
173
173
  innerClassName: css.formInner,
174
- customSend: formSendFunction(firstname, lastname)
174
+ customSend: formSendFunction(prenom, nom)
175
175
  })]
176
176
  })]
177
177
  });
@@ -1,5 +1,51 @@
1
+ const SLASH = "/";
2
+ export function truncate(input, lenght = 140) {
3
+ return input.length > lenght ? `${input.substring(0, lenght)}...` : input;
4
+ }
5
+ export function sanitizeHTML(text) {
6
+ const element = document.createElement("div");
7
+ element.innerHTML = text;
8
+ return element.textContent;
9
+ }
10
+ export function propsFromQueryString() {
11
+ if (typeof window === "undefined") return {};
12
+ const params = new URLSearchParams(document.location.search);
13
+ const activity = params.get("activity") || undefined;
14
+ const language = params.get("language") || undefined;
15
+ return {
16
+ activity,
17
+ language
18
+ };
19
+ }
20
+ export function hasTrailingSlash(path) {
21
+ return path.length > 1 && path.endsWith(SLASH);
22
+ }
1
23
  export const formatNames = name => {
2
24
  const lowercasedName = name && name.toLowerCase();
3
- return lowercasedName.charAt(0).toUpperCase() + lowercasedName.slice(1);
25
+ return lowercasedName ? lowercasedName.charAt(0).toUpperCase() + lowercasedName.slice(1) : "";
4
26
  };
5
- export const includesString = (source, included) => source.toLowerCase().includes(included.toLowerCase());
27
+ export function includesString(source, included) {
28
+ source.toLowerCase().includes(included.toLowerCase());
29
+ }
30
+ function strStartWith(str1, str2) {
31
+ return str1.toLowerCase().trim().startsWith(str2.toLowerCase().trim());
32
+ }
33
+ function strEquals(str1, str2) {
34
+ return str1.toLowerCase().trim() === str2.toLowerCase().trim();
35
+ }
36
+ function match(searchingArray, entries) {
37
+ return searchingArray.reduce((acc, str, index) => {
38
+ const matched = index === searchingArray.length - 1 ? strStartWith : strEquals;
39
+ return acc && entries.some(entry => matched(entry, str));
40
+ }, true);
41
+ }
42
+ export function filter(array, search = "") {
43
+ const searchingArray = search.split(" ");
44
+ const filtered = array.all ? array.all.filter(uri => {
45
+ const instructor = array.byUri[uri];
46
+ const firstnameWords = instructor.prenom.split(" ");
47
+ const lastnameWords = instructor.nom.split(" ");
48
+ return match(searchingArray, [...firstnameWords, ...lastnameWords]);
49
+ }) : [];
50
+ return filtered.reduce((acc, uri) => [...acc, array.byUri[uri]], []);
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.17.7",
3
+ "version": "1.18.0",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.9.0",
6
6
  "leaflet": "^1.9.1",
@@ -1,16 +0,0 @@
1
- const buildHost = env => env === "dev" ? "http://localhost:9002" : env === "uat" ? "https://instructors-book-server-uat.carnet-rouge-esf.com" : "https://instructors-book-server.carnet-rouge-esf.com";
2
- export const fetchRandomInstructors = async (school, lang, tags, nbInstructor, env) => {
3
- const res = await fetch(`${buildHost(env)}/api/instructors-book/${school}/${lang}/byTags`, {
4
- method: "POST",
5
- headers: {
6
- "content-type": "application/json;charset=utf-8",
7
- Authorization: "00q2qa545018261l252gg3414t3qa2",
8
- schoolcode: school
9
- },
10
- body: JSON.stringify({
11
- tags,
12
- size: nbInstructor
13
- })
14
- });
15
- return res.json();
16
- };