@movalib/movalib-commons 1.0.23 → 1.0.25

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { default as VehiclePlateField } from './src/VehiclePlateField';
1
2
  export { default as TestButton } from './src/TestButton';
2
3
  export { default as MovaSnackbar } from './src/MovaSnackbar';
3
4
  export { default as MovaLogin } from './src/MovaLogin';
package/dist/index.js CHANGED
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MovaAppType = exports.RoleType = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = void 0;
7
+ exports.MovaAppType = exports.RoleType = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = exports.VehiclePlateField = void 0;
8
8
  // Export des composants
9
+ var VehiclePlateField_1 = require("./src/VehiclePlateField");
10
+ Object.defineProperty(exports, "VehiclePlateField", { enumerable: true, get: function () { return __importDefault(VehiclePlateField_1).default; } });
9
11
  var TestButton_1 = require("./src/TestButton");
10
12
  Object.defineProperty(exports, "TestButton", { enumerable: true, get: function () { return __importDefault(TestButton_1).default; } });
11
13
  var MovaSnackbar_1 = require("./src/MovaSnackbar");
@@ -112,7 +112,7 @@ var MovaLogin = function (_a) {
112
112
  // Validator pour l'email
113
113
  newForm.email = (0, Tools_1.validateField)(form.email, Validator_1.validateEmail, 'Adresse email invalide');
114
114
  // Validator pour le mot de passe
115
- newForm.password = (0, Tools_1.validateField)(form.password, function (value) { return value.length >= 10 && /[a-z]/.test(value) && /[A-Z]/.test(value); }, 'Votre mot de passe doit faire au moins 8 caractères de long');
115
+ newForm.password = (0, Tools_1.validateField)(form.password, function (value) { return value.length >= 10 && /[a-z]/.test(value) && /[A-Z]/.test(value); }, 'Mot de passe invalide');
116
116
  setForm(newForm);
117
117
  return newForm.email.isValid && newForm.password.isValid;
118
118
  };
@@ -67,8 +67,7 @@ var Tools_1 = require("./helpers/Tools");
67
67
  var styles = {
68
68
  display: 'flex',
69
69
  justifyContent: 'center',
70
- alignItems: 'center',
71
- height: '100vh', // Ajustez la hauteur en fonction de vos besoins
70
+ alignItems: 'center'
72
71
  };
73
72
  var initialUserFormState = {
74
73
  firstname: { value: '', isValid: true },
@@ -0,0 +1,6 @@
1
+ import { FunctionComponent } from 'react';
2
+ interface VehiclePlateFieldProps {
3
+ onValidVehiclePlate: (vehiclePlate: string) => void;
4
+ }
5
+ declare const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps>;
6
+ export default VehiclePlateField;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
+ var react_1 = require("react");
8
+ var TextField_1 = __importDefault(require("@mui/material/TextField"));
9
+ // Regex pour une plaque d'immatriculation française
10
+ var regex = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
11
+ var VehiclePlateField = function (_a) {
12
+ var onValidVehiclePlate = _a.onValidVehiclePlate;
13
+ var _b = (0, react_1.useState)(''), value = _b[0], setValue = _b[1];
14
+ var _c = (0, react_1.useState)(false), error = _c[0], setError = _c[1];
15
+ var _d = (0, react_1.useState)(0), lastLength = _d[0], setLastLength = _d[1]; // Ajout d'un état pour stocker la longueur précédente
16
+ (0, react_1.useEffect)(function () {
17
+ if (!error && value !== '' && value.match(regex)) {
18
+ onValidVehiclePlate(value);
19
+ }
20
+ }, [error, value, onValidVehiclePlate]);
21
+ var handleChange = function (e) {
22
+ var inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
23
+ // Vérifier si l'utilisateur est en train de supprimer un caractère
24
+ var isDeleting = inputValue.length < lastLength;
25
+ // Supprimer les tirets pour avoir une chaîne propre
26
+ var cleanInput = inputValue.replace(/-/g, '');
27
+ // Ajouter des tirets aux positions appropriées
28
+ if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
29
+ inputValue = "".concat(cleanInput.slice(0, 2), "-").concat(cleanInput.slice(2));
30
+ }
31
+ if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
32
+ inputValue = "".concat(cleanInput.slice(0, 2), "-").concat(cleanInput.slice(2, 5), "-").concat(cleanInput.slice(5, 7));
33
+ }
34
+ setValue(inputValue);
35
+ setError(!regex.test(inputValue));
36
+ setLastLength(inputValue.length); // Mettre à jour la longueur précédente
37
+ };
38
+ return ((0, jsx_runtime_1.jsx)(TextField_1.default, { label: "Plaque d'immatriculation", variant: "outlined", value: value, onChange: handleChange, error: error, autoFocus: true, sx: {
39
+ width: '100%',
40
+ '& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
41
+ }, helperText: error ? "Utilisez le format 'XX-123-XX'" : '' }));
42
+ };
43
+ exports.default = VehiclePlateField;
package/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
 
3
3
  // Export des composants
4
+ export { default as VehiclePlateField } from './src/VehiclePlateField';
4
5
  export { default as TestButton } from './src/TestButton';
5
6
  export { default as MovaSnackbar } from './src/MovaSnackbar';
6
7
  export { default as MovaLogin } from './src/MovaLogin';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
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",
package/src/MovaLogin.tsx CHANGED
@@ -84,7 +84,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
84
84
  // Validator pour le mot de passe
85
85
  newForm.password = validateField(form.password,
86
86
  value => value.length >= 10 && /[a-z]/.test(value) && /[A-Z]/.test(value),
87
- 'Votre mot de passe doit faire au moins 8 caractères de long');
87
+ 'Mot de passe invalide');
88
88
 
89
89
  setForm(newForm);
90
90
 
@@ -16,8 +16,7 @@ import { validateField } from "./helpers/Tools";
16
16
  const styles: CSSProperties = {
17
17
  display: 'flex',
18
18
  justifyContent: 'center',
19
- alignItems: 'center',
20
- height: '100vh', // Ajustez la hauteur en fonction de vos besoins
19
+ alignItems: 'center'
21
20
  };
22
21
 
23
22
  const initialUserFormState = {
@@ -0,0 +1,64 @@
1
+ import React, { FunctionComponent, useEffect, useState } from 'react';
2
+ import TextField from '@mui/material/TextField';
3
+
4
+ interface VehiclePlateFieldProps {
5
+ onValidVehiclePlate: (vehiclePlate: string) => void;
6
+ }
7
+
8
+ // Regex pour une plaque d'immatriculation française
9
+ const regex = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
10
+
11
+ const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps> = ({ onValidVehiclePlate }) => {
12
+
13
+ const [value, setValue] = useState<string>('');
14
+ const [error, setError] = useState<boolean>(false);
15
+ const [lastLength, setLastLength] = useState<number>(0); // Ajout d'un état pour stocker la longueur précédente
16
+
17
+ useEffect(() => {
18
+ if (!error && value !== '' && value.match(regex)) {
19
+ onValidVehiclePlate(value);
20
+ }
21
+ }, [error, value, onValidVehiclePlate]);
22
+
23
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
24
+
25
+ let inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
26
+
27
+ // Vérifier si l'utilisateur est en train de supprimer un caractère
28
+ const isDeleting = inputValue.length < lastLength;
29
+
30
+ // Supprimer les tirets pour avoir une chaîne propre
31
+ const cleanInput = inputValue.replace(/-/g, '');
32
+
33
+ // Ajouter des tirets aux positions appropriées
34
+ if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
35
+ inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2)}`;
36
+ }
37
+
38
+ if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
39
+ inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2, 5)}-${cleanInput.slice(5, 7)}`;
40
+ }
41
+
42
+ setValue(inputValue);
43
+ setError(!regex.test(inputValue));
44
+ setLastLength(inputValue.length); // Mettre à jour la longueur précédente
45
+ };
46
+
47
+ return (
48
+ <TextField
49
+ label="Plaque d'immatriculation"
50
+ variant="outlined"
51
+ value={value}
52
+ onChange={handleChange}
53
+ error={error}
54
+ autoFocus
55
+ sx={{
56
+ width: '100%',
57
+ '& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
58
+ }}
59
+ helperText={error ? "Utilisez le format 'XX-123-XX'" : ''}
60
+ />
61
+ );
62
+ };
63
+
64
+ export default VehiclePlateField;