@movalib/movalib-commons 1.59.16 → 1.59.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/devIndex.tsx CHANGED
@@ -19,7 +19,7 @@ import Logger from './src/helpers/Logger';
19
19
  import Garage from './src/models/Garage';
20
20
  import ScheduleFields, { DaySchedule } from './src/ScheduleFields';
21
21
  import Schedule from './src/models/Schedule';
22
- import { flexCenter } from './src/helpers/Tools';
22
+ import { flexCenter, formatVehicleTire } from './src/helpers/Tools';
23
23
  import AccountValidation from './src/AccountValidation';
24
24
  import VehiclePlateField from './src/components/vehicle/VehiclePlateField';
25
25
  import GaragePLV from './src/GaragePLV';
@@ -127,7 +127,7 @@ const App = () => {
127
127
  </Container>
128
128
  <Container style={flexCenter} sx={{ width: '400px', mt: 2}}>
129
129
  <MovaVehicleTireField onChangeVehicleTire={(vehicleTire) => {
130
- console.log(vehicleTire);
130
+ console.log('formatVehicleTire', formatVehicleTire(vehicleTire));
131
131
  }}/>
132
132
  </Container>
133
133
 
package/dist/devIndex.js CHANGED
@@ -133,7 +133,7 @@ var App = function () {
133
133
  } }), (0, jsx_runtime_1.jsx)(material_1.Container, __assign({ style: Tools_1.flexCenter, sx: { width: '400px', mt: 2 } }, { children: (0, jsx_runtime_1.jsx)(VehiclePlateField_1.default, { onValidVehiclePlate: function (vehiclePlate) {
134
134
  alert('plaque valide');
135
135
  } }) })), (0, jsx_runtime_1.jsx)(material_1.Container, __assign({ style: Tools_1.flexCenter, sx: { width: '400px', mt: 2 } }, { children: (0, jsx_runtime_1.jsx)(MovaVehicleTireField_1.default, { onChangeVehicleTire: function (vehicleTire) {
136
- console.log(vehicleTire);
136
+ console.log('formatVehicleTire', (0, Tools_1.formatVehicleTire)(vehicleTire));
137
137
  } }) })), (0, jsx_runtime_1.jsx)(MovaLogin_1.default, { darkMode: false, movaAppType: Enums_1.MovaAppType.INDIVIDUAL, version: "0.1.3", onSubmit: function (form) {
138
138
  alert('Form Submitted !');
139
139
  }, onSubmitForgotPassword: function (email) {
@@ -9,7 +9,7 @@ var react_1 = require("react");
9
9
  var VehicleTire_1 = __importDefault(require("./models/VehicleTire"));
10
10
  var Tools_1 = require("./helpers/Tools");
11
11
  // Regex pour une taille de pneumatique Française
12
- var regex = /^\d{9,10}[A-Za-z]$/;
12
+ var regex = /^[A-Za-z0-9]{7}/;
13
13
  var MovaVehicleTireField = function (_a) {
14
14
  var vehicleTire = _a.vehicleTire, onChangeVehicleTire = _a.onChangeVehicleTire;
15
15
  var _b = (0, react_1.useState)(''), tireInfo = _b[0], setTireInfo = _b[1];
@@ -25,12 +25,13 @@ var MovaVehicleTireField = function (_a) {
25
25
  var rawValue = e.target.value;
26
26
  // Cette expression régulière supprimera tous les caractères qui ne sont pas des chiffres ou des lettres alphabétiques, à l'exception de "R" et "r".
27
27
  // On ne peut saisir que 10 caractères maximum (ex : 245551791V)
28
- var value = rawValue.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 11);
28
+ var value = rawValue.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 15);
29
29
  // On valide la saisie (le champ n'est pas obligatoire)
30
30
  var isValid = value.length == 0 || (value.length > 0 && regex.test(value));
31
31
  setError(!regex.test(value));
32
32
  // Vérifier si l'utilisateur est en train de supprimer un caractère
33
- var isDeleting = value.length < lastLength;
33
+ var isDeleting = rawValue.length < lastLength;
34
+ console.log(isDeleting);
34
35
  // Ajout du " / "
35
36
  if (value.length >= 3 && !(rawValue.length == 5 && isDeleting)) {
36
37
  value = "".concat(value.substring(0, 3), " / ").concat(value.substring(3));
@@ -39,19 +40,46 @@ var MovaVehicleTireField = function (_a) {
39
40
  if (value.length >= 8 && !(rawValue.length == 9 && isDeleting)) {
40
41
  value = "".concat(value.substring(0, 8), " R").concat(value.substring(8));
41
42
  }
43
+ var additonalChar = false;
44
+ if (value[12] && /^[A-Z]$/.test(value[12])) {
45
+ if (rawValue.length === 14 && isDeleting) {
46
+ value = "".concat(value.substring(0, 12));
47
+ }
48
+ else {
49
+ additonalChar = true;
50
+ value = "".concat(value.substring(0, 13), " ").concat(value.substring(13));
51
+ }
52
+ }
42
53
  // Ajout d'un espace après la saisie du diamètre des pneus
43
54
  if (value.length >= 12 && !(rawValue.length <= 12 && isDeleting)) {
44
55
  value = "".concat(value.substring(0, 12), " ").concat(value.substring(12));
45
56
  }
46
- setTireInfo(value);
57
+ //console.log('2 valeu',JSON.stringify(value));
58
+ if (additonalChar) {
59
+ var endString = rawValue.substring(15);
60
+ value = value.substring(0, 15) + (endString !== undefined ? endString : '');
61
+ console.log(rawValue.split(' ')[5]);
62
+ }
63
+ else {
64
+ var endString = rawValue.substring(12);
65
+ if (endString && endString.length > 1) {
66
+ value = value.substring(0, 13) + endString.trimStart();
67
+ }
68
+ }
47
69
  var parts = value.split(" ");
48
- if (value.length >= 16 && !(rawValue.length == 18 && isDeleting) && parts.length === 5) {
70
+ setTireInfo(value);
71
+ console.log(parts);
72
+ if (value.length >= 16) {
49
73
  var width = parts[0], _separator = parts[1], height = parts[2], diameter = parts[3], speedIndex = parts[4];
74
+ speedIndex = value.substring(13);
75
+ console.log('YYY', width, height, diameter, speedIndex, _separator);
50
76
  var vehicleTire_1 = new VehicleTire_1.default(width, height, diameter, speedIndex);
51
77
  onChangeVehicleTire(vehicleTire_1, isValid);
52
78
  }
53
79
  else {
54
80
  var width = parts[0], _separator = parts[1], height = parts[2], diameter = parts[3], speedIndex = parts[4];
81
+ speedIndex = value.substring(13);
82
+ console.log('XXX', width, height, diameter, speedIndex, _separator);
55
83
  var vehicleTire_2 = new VehicleTire_1.default(width !== null && width !== void 0 ? width : '', height !== null && height !== void 0 ? height : '', diameter !== null && diameter !== void 0 ? diameter : '', speedIndex !== null && speedIndex !== void 0 ? speedIndex : '');
56
84
  onChangeVehicleTire(vehicleTire_2, isValid);
57
85
  }
@@ -218,20 +218,18 @@ var formatVehicleTire = function (vehicleTire) {
218
218
  };
219
219
  exports.formatVehicleTire = formatVehicleTire;
220
220
  var formatVehicleTireStr = function (input) {
221
- var formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 10);
222
- if (formatted.length >= 3) {
221
+ var formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 7);
222
+ if (formatted.length > 3) {
223
223
  formatted = "".concat(formatted.substring(0, 3), " / ").concat(formatted.substring(3));
224
224
  }
225
- var indexOfR = formatted.indexOf(" R");
226
- if (formatted.length >= 8 && indexOfR === -1) {
227
- formatted = "".concat(formatted.substring(0, 8), " R").concat(formatted.substring(8));
228
- if (formatted.length >= 12 && indexOfR === -1)
229
- formatted = "".concat(formatted.substring(0, 12), " ").concat(formatted.substring(12));
225
+ var indexOfRraw = input.indexOf("R");
226
+ var toAdd = indexOfRraw !== -1 ? input.substring(indexOfRraw + 3) : '';
227
+ if (toAdd.length > 0) {
228
+ toAdd = ' ' + toAdd;
230
229
  }
231
- else if (indexOfR !== -1 && formatted.length > indexOfR + 2) {
232
- formatted = "".concat(formatted.substring(0, indexOfR + 2), " ").concat(formatted.substring(indexOfR + 2));
230
+ if (formatted.length > 8) {
231
+ formatted = "".concat(formatted.substring(0, 8), " R").concat(formatted.substring(8)).concat(toAdd);
233
232
  }
234
- console.log(formatted);
235
233
  return formatted;
236
234
  };
237
235
  exports.formatVehicleTireStr = formatVehicleTireStr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.59.16",
3
+ "version": "1.59.17",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,7 @@ interface MovaVehicleTireFieldProps {
9
9
  }
10
10
 
11
11
  // Regex pour une taille de pneumatique Française
12
- const regex = /^\d{9,10}[A-Za-z]$/;
12
+ const regex = /^[A-Za-z0-9]{7}/;
13
13
 
14
14
  const MovaVehicleTireField: FC<MovaVehicleTireFieldProps> = ({ vehicleTire, onChangeVehicleTire }) => {
15
15
 
@@ -27,46 +27,67 @@ const MovaVehicleTireField: FC<MovaVehicleTireFieldProps> = ({ vehicleTire, onCh
27
27
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
28
28
  e.preventDefault();
29
29
  const rawValue = e.target.value;
30
-
31
30
  // Cette expression régulière supprimera tous les caractères qui ne sont pas des chiffres ou des lettres alphabétiques, à l'exception de "R" et "r".
32
31
  // On ne peut saisir que 10 caractères maximum (ex : 245551791V)
33
- let value = rawValue.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 11);
32
+ let value = rawValue.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 15);
34
33
 
35
34
  // On valide la saisie (le champ n'est pas obligatoire)
36
35
  let isValid = value.length == 0 || (value.length > 0 && regex.test(value));
37
36
  setError(!regex.test(value));
38
37
 
39
38
  // Vérifier si l'utilisateur est en train de supprimer un caractère
40
- const isDeleting = value.length < lastLength;
41
-
39
+ const isDeleting = rawValue.length < lastLength;
42
40
  // Ajout du " / "
43
41
  if (value.length >= 3 && !(rawValue.length == 5 && isDeleting)) {
44
42
  value = `${value.substring(0, 3)} / ${value.substring(3)}`;
45
43
  }
46
-
44
+
47
45
  // Ajout du " R"
48
46
  if (value.length >= 8 && !(rawValue.length == 9 && isDeleting)) {
49
47
  value = `${value.substring(0, 8)} R${value.substring(8)}`;
50
48
  }
51
49
 
50
+ let additonalChar = false;
51
+
52
+ if (value[12] && /^[A-Z]$/.test(value[12])) {
53
+ if(rawValue.length === 14 && isDeleting) {
54
+ value = `${value.substring(0, 12)}`;
55
+ } else {
56
+ additonalChar = true;
57
+ value = `${value.substring(0, 13)} ${value.substring(13)}`;
58
+ }
59
+ }
60
+
52
61
 
53
62
  // Ajout d'un espace après la saisie du diamètre des pneus
54
63
  if (value.length >= 12 && !(rawValue.length <= 12 && isDeleting)) {
55
64
  value = `${value.substring(0, 12)} ${value.substring(12)}`;
56
65
  }
66
+ //console.log('2 valeu',JSON.stringify(value));
67
+ if (additonalChar) {
68
+ let endString = rawValue.substring(15);
69
+ value = value.substring(0,15) + (endString !== undefined ? endString :'');
70
+ console.log(rawValue.split(' ')[5]);
71
+ } else {
72
+ let endString = rawValue.substring(12);
73
+ if(endString && endString.length > 1) {
74
+ value = value.substring(0,13) + endString.trimStart();
75
+ }
76
+ }
57
77
 
58
- setTireInfo(value);
59
78
 
60
79
  const parts = value.split(" ");
61
80
 
62
- if (value.length >= 16 && !(rawValue.length == 18 && isDeleting) && parts.length === 5) {
63
- const [width, _separator, height, diameter, speedIndex] = parts;
81
+ setTireInfo(value);
82
+ if (value.length >= 16) {
83
+ let [width, _separator, height, diameter, speedIndex] = parts;
84
+ speedIndex = value.substring(13);
64
85
  const vehicleTire = new VehicleTire(width, height, diameter, speedIndex);
65
86
  onChangeVehicleTire(vehicleTire, isValid);
66
87
  } else {
67
- const [width, _separator, height, diameter, speedIndex] = parts;
88
+ let [width, _separator, height, diameter, speedIndex] = parts;
89
+ speedIndex = value.substring(13);
68
90
  const vehicleTire = new VehicleTire(width ?? '', height ?? '', diameter ?? '', speedIndex ?? '');
69
-
70
91
  onChangeVehicleTire(vehicleTire, isValid);
71
92
  }
72
93
 
@@ -239,26 +239,18 @@ export const formatVehicleTire = (vehicleTire: VehicleTire) => {
239
239
  }
240
240
 
241
241
  export const formatVehicleTireStr = (input: string) => {
242
-
243
- let formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 10);
244
-
245
- if (formatted.length >= 3) {
242
+ let formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 7);
243
+ if (formatted.length > 3) {
246
244
  formatted = `${formatted.substring(0, 3)} / ${formatted.substring(3)}`;
247
245
  }
248
-
249
- const indexOfR = formatted.indexOf(" R");
250
-
251
- if (formatted.length >= 8 && indexOfR === -1) {
252
- formatted = `${formatted.substring(0, 8)} R${formatted.substring(8)}`;
253
-
254
- if (formatted.length >= 12 && indexOfR === -1)
255
- formatted = `${formatted.substring(0, 12)} ${formatted.substring(12)}`;
256
-
257
- } else if (indexOfR !== -1 && formatted.length > indexOfR + 2) {
258
- formatted = `${formatted.substring(0, indexOfR + 2)} ${formatted.substring(indexOfR + 2)}`;
246
+ const indexOfRraw = input.indexOf("R");
247
+ let toAdd = indexOfRraw !== -1 ? input.substring(indexOfRraw + 3) : '';
248
+ if(toAdd.length > 0) {
249
+ toAdd = ' ' + toAdd;
250
+ }
251
+ if(formatted.length > 8) {
252
+ formatted = `${formatted.substring(0, 8)} R${formatted.substring(8)}${toAdd}`;
259
253
  }
260
-
261
- console.log(formatted);
262
254
  return formatted;
263
255
  };
264
256