@movalib/movalib-commons 1.1.16 → 1.1.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 +11 -3
- package/dist/devIndex.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/src/VehiclePlateField.js +73 -3
- package/dist/src/helpers/Enums.d.ts +4 -0
- package/dist/src/helpers/Enums.js +6 -1
- package/index.ts +1 -1
- package/package.json +1 -1
- package/src/VehiclePlateField.tsx +100 -16
- package/src/helpers/Enums.ts +8 -3
package/devIndex.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
|
12
12
|
import DatePicker from '@mui/lab/DatePicker';
|
|
13
13
|
import frLocale from 'date-fns/locale/fr';
|
|
14
14
|
import QRCode from './src/QRCode';
|
|
15
|
-
import { Box, Button, Typography } from '@mui/material';
|
|
15
|
+
import { Box, Button, Container, Typography } from '@mui/material';
|
|
16
16
|
import GarageService from './src/services/GarageService';
|
|
17
17
|
import AuthenticationService from './src/services/AuthenticationService';
|
|
18
18
|
import Logger from './src/helpers/Logger';
|
|
@@ -21,6 +21,7 @@ import ScheduleFields, { DaySchedule } from './src/ScheduleFields';
|
|
|
21
21
|
import Schedule from './src/models/Schedule';
|
|
22
22
|
import { flexCenter } from './src/helpers/Tools';
|
|
23
23
|
import AccountValidation from './src/AccountValidation';
|
|
24
|
+
import VehiclePlateField from './src/VehiclePlateField';
|
|
24
25
|
|
|
25
26
|
const App = () => {
|
|
26
27
|
|
|
@@ -106,8 +107,15 @@ const App = () => {
|
|
|
106
107
|
<ThemeProvider theme={theme}>
|
|
107
108
|
<Box sx={{ mb: 4}}>
|
|
108
109
|
|
|
110
|
+
<Container style={flexCenter} sx={{ width: '400px', mt: 2}}>
|
|
111
|
+
<VehiclePlateField onValidVehiclePlate={function (vehiclePlate: string): void {
|
|
112
|
+
alert('plaque valide');
|
|
113
|
+
} } />
|
|
114
|
+
</Container>
|
|
115
|
+
|
|
116
|
+
|
|
109
117
|
<MovaLogin
|
|
110
|
-
darkMode={
|
|
118
|
+
darkMode={false}
|
|
111
119
|
movaAppType={MovaAppType.GARAGE}
|
|
112
120
|
version="0.1.3"
|
|
113
121
|
onSubmit={function (form: MovaLoginForm): void {
|
|
@@ -117,7 +125,7 @@ const App = () => {
|
|
|
117
125
|
} } />
|
|
118
126
|
|
|
119
127
|
<MovaSignUp
|
|
120
|
-
darkMode={
|
|
128
|
+
darkMode={false}
|
|
121
129
|
movaAppType={MovaAppType.INDIVIDUAL} onSubmit={function (form: MovaLoginForm): void {
|
|
122
130
|
alert('Form Submitted !');
|
|
123
131
|
} } />
|
package/dist/devIndex.js
CHANGED
|
@@ -58,6 +58,7 @@ var ScheduleFields_1 = __importDefault(require("./src/ScheduleFields"));
|
|
|
58
58
|
var Schedule_1 = __importDefault(require("./src/models/Schedule"));
|
|
59
59
|
var Tools_1 = require("./src/helpers/Tools");
|
|
60
60
|
var AccountValidation_1 = __importDefault(require("./src/AccountValidation"));
|
|
61
|
+
var VehiclePlateField_1 = __importDefault(require("./src/VehiclePlateField"));
|
|
61
62
|
var App = function () {
|
|
62
63
|
Logger_1.default.enableLogging();
|
|
63
64
|
// Chargement de données garage de test
|
|
@@ -118,11 +119,13 @@ var App = function () {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(LocalizationProvider_1.LocalizationProvider, __assign({ dateAdapter: AdapterDateFns_1.AdapterDateFns, adapterLocale: fr_1.default }, { children: (0, jsx_runtime_1.jsxs)(styles_1.ThemeProvider, __assign({ theme: theme_1.default }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { mb: 4 } }, { children: [(0, jsx_runtime_1.jsx)(
|
|
122
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(LocalizationProvider_1.LocalizationProvider, __assign({ dateAdapter: AdapterDateFns_1.AdapterDateFns, adapterLocale: fr_1.default }, { children: (0, jsx_runtime_1.jsxs)(styles_1.ThemeProvider, __assign({ theme: theme_1.default }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: { mb: 4 } }, { children: [(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) {
|
|
123
|
+
alert('plaque valide');
|
|
124
|
+
} }) })), (0, jsx_runtime_1.jsx)(MovaLogin_1.default, { darkMode: false, movaAppType: Enums_1.MovaAppType.GARAGE, version: "0.1.3", onSubmit: function (form) {
|
|
122
125
|
alert('Form Submitted !');
|
|
123
126
|
}, onSubmitForgotPassword: function (email) {
|
|
124
127
|
throw new Error('Function not implemented.');
|
|
125
|
-
} }), (0, jsx_runtime_1.jsx)(MovaSignUp_1.default, { darkMode:
|
|
128
|
+
} }), (0, jsx_runtime_1.jsx)(MovaSignUp_1.default, { darkMode: false, movaAppType: Enums_1.MovaAppType.INDIVIDUAL, onSubmit: function (form) {
|
|
126
129
|
alert('Form Submitted !');
|
|
127
130
|
} }), (0, jsx_runtime_1.jsx)(QRCode_1.default, { data: getQRCodeData(), showDownload: true }), (0, jsx_runtime_1.jsx)("div", { style: { marginTop: '40px' } }), (0, jsx_runtime_1.jsx)("div", __assign({ style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)(ScheduleFields_1.default, { schedules: garage === null || garage === void 0 ? void 0 : garage.schedules, size: "small", timePickerStep: 30, onChange: handleScheduleChange }) }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ onClick: function () { return setOpenAccountValidation(!openAccountValidation); } }, { children: "Validation de compte" })) })), openAccountValidation && (0, jsx_runtime_1.jsx)(AccountValidation_1.default, { movaAppType: Enums_1.MovaAppType.GARAGE, onSubmit: function (success, message) {
|
|
128
131
|
throw new Error('Function not implemented.');
|
package/dist/index.d.ts
CHANGED
|
@@ -40,4 +40,4 @@ export { readCookie, deleteCookie } from './src/helpers/CookieUtils';
|
|
|
40
40
|
export { validateField, formatVehicleTire, formatFrenchVehiclePlate, isEmpty, getApplicationShortLabel } from './src/helpers/Tools';
|
|
41
41
|
export { validatePhoneNumber, validateText, validateEmail } from './src/helpers/Validator';
|
|
42
42
|
export { formatDateByCountryCode, getLongFormattedDateTime, capitalizeFirstLetter } from './src/helpers/DateUtils';
|
|
43
|
-
export { RoleType, MovaAppType, DayOfWeek, EventState, EventType, DocumentType, DigitalPassportIndex, DocumentState, Gender, DateFormatTypes, PartsApplicationType, ProductType, OrderPreference, OrderState, SlotAlgorithm } from './src/helpers/Enums';
|
|
43
|
+
export { RoleType, MovaAppType, DayOfWeek, EventState, EventType, DocumentType, DigitalPassportIndex, DocumentState, Gender, DateFormatTypes, PartsApplicationType, ProductType, OrderPreference, OrderState, SlotAlgorithm, VehiclePlateFormat as VehiclePlateType } from './src/helpers/Enums';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.MovaAppType = exports.RoleType = exports.capitalizeFirstLetter = exports.getLongFormattedDateTime = exports.formatDateByCountryCode = exports.validateEmail = exports.validateText = exports.validatePhoneNumber = exports.getApplicationShortLabel = exports.isEmpty = exports.formatFrenchVehiclePlate = exports.formatVehicleTire = exports.validateField = exports.deleteCookie = exports.readCookie = exports.VehicleTire = exports.Event = exports.Schedule = exports.Garage = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.Customer = exports.Logger = exports.Operation = exports.Prestation = exports.Product = exports.Supplier = exports.GenderSelector = exports.ConfirmationDialog = exports.MovaVehicleTireField = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = exports.VehiclePlateField = exports.QRCode = exports.MovaDialog = exports.Loader = exports.MovaDigitalPassport = exports.VehicleFullCard = exports.ScheduleFields = exports.AddressFields = exports.AccountValidation = exports.UserService = exports.GarageService = exports.AuthenticationService = void 0;
|
|
8
|
-
exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = void 0;
|
|
8
|
+
exports.VehiclePlateType = exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = void 0;
|
|
9
9
|
// Export des services
|
|
10
10
|
var AuthenticationService_1 = require("./src/services/AuthenticationService");
|
|
11
11
|
Object.defineProperty(exports, "AuthenticationService", { enumerable: true, get: function () { return __importDefault(AuthenticationService_1).default; } });
|
|
@@ -114,3 +114,4 @@ Object.defineProperty(exports, "ProductType", { enumerable: true, get: function
|
|
|
114
114
|
Object.defineProperty(exports, "OrderPreference", { enumerable: true, get: function () { return Enums_1.OrderPreference; } });
|
|
115
115
|
Object.defineProperty(exports, "OrderState", { enumerable: true, get: function () { return Enums_1.OrderState; } });
|
|
116
116
|
Object.defineProperty(exports, "SlotAlgorithm", { enumerable: true, get: function () { return Enums_1.SlotAlgorithm; } });
|
|
117
|
+
Object.defineProperty(exports, "VehiclePlateType", { enumerable: true, get: function () { return Enums_1.VehiclePlateFormat; } });
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -6,20 +17,71 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
18
|
var react_1 = require("react");
|
|
8
19
|
var TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
9
|
-
|
|
20
|
+
var Enums_1 = require("./helpers/Enums");
|
|
21
|
+
var Logger_1 = __importDefault(require("./helpers/Logger"));
|
|
22
|
+
var material_1 = require("@mui/material");
|
|
23
|
+
var SearchRounded_1 = __importDefault(require("@mui/icons-material/SearchRounded"));
|
|
24
|
+
// Regex pour une plaque d'immatriculation française (nouveau format SIV)
|
|
10
25
|
var regex = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
|
|
26
|
+
// Regex pour une plaque d'immatriculation française (ancien format FNI)
|
|
27
|
+
var oldRegex = /^\d{1,4}[ -]?[A-Z]{1,4}[ -]?\d{1,4}$/;
|
|
11
28
|
var VehiclePlateField = function (_a) {
|
|
12
29
|
var onValidVehiclePlate = _a.onValidVehiclePlate;
|
|
13
30
|
var _b = (0, react_1.useState)(''), value = _b[0], setValue = _b[1];
|
|
14
31
|
var _c = (0, react_1.useState)(false), error = _c[0], setError = _c[1];
|
|
15
32
|
var _d = (0, react_1.useState)(0), lastLength = _d[0], setLastLength = _d[1]; // Ajout d'un état pour stocker la longueur précédente
|
|
33
|
+
var _e = (0, react_1.useState)(''), helperText = _e[0], setHelperText = _e[1];
|
|
34
|
+
// Hook de validation de la plaque
|
|
16
35
|
(0, react_1.useEffect)(function () {
|
|
17
36
|
if (!error && value !== '' && value.match(regex)) {
|
|
18
37
|
onValidVehiclePlate(value);
|
|
19
38
|
}
|
|
20
39
|
}, [error, value, onValidVehiclePlate]);
|
|
40
|
+
var getPlateFormat = function (plate) {
|
|
41
|
+
if (/^[A-Za-z]/.test(plate)) {
|
|
42
|
+
// Commence par une lettre => nouveau format
|
|
43
|
+
return Enums_1.VehiclePlateFormat.FRENCH_NEW;
|
|
44
|
+
}
|
|
45
|
+
else if (/^\d/.test(plate)) {
|
|
46
|
+
// Commence par un chiffre => ancien format
|
|
47
|
+
return Enums_1.VehiclePlateFormat.FRENCH_OLD;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
Logger_1.default.error("Format de plaque inconnu");
|
|
51
|
+
// On retourne le nouveau format par défaut
|
|
52
|
+
return Enums_1.VehiclePlateFormat.FRENCH_NEW;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
21
55
|
var handleChange = function (e) {
|
|
22
56
|
var inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
|
|
57
|
+
// Si la saisie commence par une lettre, on contrôle l'ancien format, sinon le nouveau
|
|
58
|
+
switch (getPlateFormat(inputValue)) {
|
|
59
|
+
case Enums_1.VehiclePlateFormat.FRENCH_NEW: {
|
|
60
|
+
setHelperText((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Format d\u00E9tect\u00E9 : ", (0, jsx_runtime_1.jsx)("b", { children: "AA-111-AA" })] }));
|
|
61
|
+
handleChangeFrenchNew(inputValue);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case Enums_1.VehiclePlateFormat.FRENCH_OLD: {
|
|
65
|
+
setHelperText((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Format d\u00E9tect\u00E9 (ancien) : ", (0, jsx_runtime_1.jsx)("b", { children: "1111 AAAA 1111" })] }));
|
|
66
|
+
handleChangeFrenchOld(inputValue);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var validatePlate = function () {
|
|
72
|
+
if (oldRegex.test(value)) {
|
|
73
|
+
onValidVehiclePlate(value);
|
|
74
|
+
}
|
|
75
|
+
setError(!oldRegex.test(value));
|
|
76
|
+
};
|
|
77
|
+
var handleChangeFrenchOld = function (inputValue) {
|
|
78
|
+
// ON bloque la saisie à 12 caractères max (limite des anciennes plaques)
|
|
79
|
+
if (!(inputValue.length > 12)) {
|
|
80
|
+
setValue(inputValue);
|
|
81
|
+
}
|
|
82
|
+
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
83
|
+
};
|
|
84
|
+
var handleChangeFrenchNew = function (inputValue) {
|
|
23
85
|
// Vérifier si l'utilisateur est en train de supprimer un caractère
|
|
24
86
|
var isDeleting = inputValue.length < lastLength;
|
|
25
87
|
// Supprimer les tirets pour avoir une chaîne propre
|
|
@@ -32,12 +94,20 @@ var VehiclePlateField = function (_a) {
|
|
|
32
94
|
inputValue = "".concat(cleanInput.slice(0, 2), "-").concat(cleanInput.slice(2, 5), "-").concat(cleanInput.slice(5, 7));
|
|
33
95
|
}
|
|
34
96
|
setValue(inputValue);
|
|
35
|
-
|
|
97
|
+
// On teste la plaque une fois la saisie terminée
|
|
98
|
+
if (inputValue.length == 9) {
|
|
99
|
+
setError(!regex.test(inputValue));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
setError(false);
|
|
103
|
+
}
|
|
36
104
|
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
37
105
|
};
|
|
38
106
|
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
107
|
width: '100%',
|
|
40
108
|
'& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
|
|
41
|
-
}, helperText:
|
|
109
|
+
}, helperText: lastLength > 0 ? helperText : '', InputProps: {
|
|
110
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, __assign({ position: "end", sx: { mr: 1, display: getPlateFormat(value) === Enums_1.VehiclePlateFormat.FRENCH_OLD ? 'inherit' : 'none' } }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ edge: "end", onClick: validatePlate }, { children: (0, jsx_runtime_1.jsx)(SearchRounded_1.default, {}) })) }))),
|
|
111
|
+
} }));
|
|
42
112
|
};
|
|
43
113
|
exports.default = VehiclePlateField;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoleType = exports.MovaAppType = exports.DocumentType = exports.DocumentState = exports.DayOfWeek = exports.EventType = exports.EventState = exports.DigitalPassportIndex = exports.Gender = exports.DateFormatTypes = exports.APIMethod = exports.PartsApplicationType = exports.ProductType = exports.OrderPreference = exports.OrderState = exports.SlotAlgorithm = void 0;
|
|
3
|
+
exports.RoleType = exports.MovaAppType = exports.DocumentType = exports.DocumentState = exports.DayOfWeek = exports.EventType = exports.EventState = exports.DigitalPassportIndex = exports.Gender = exports.DateFormatTypes = exports.APIMethod = exports.PartsApplicationType = exports.ProductType = exports.OrderPreference = exports.OrderState = exports.SlotAlgorithm = exports.VehiclePlateFormat = void 0;
|
|
4
|
+
var VehiclePlateFormat;
|
|
5
|
+
(function (VehiclePlateFormat) {
|
|
6
|
+
VehiclePlateFormat["FRENCH_NEW"] = "FRENCH_NEW";
|
|
7
|
+
VehiclePlateFormat["FRENCH_OLD"] = "FRENCH_OLD";
|
|
8
|
+
})(VehiclePlateFormat = exports.VehiclePlateFormat || (exports.VehiclePlateFormat = {}));
|
|
4
9
|
var SlotAlgorithm;
|
|
5
10
|
(function (SlotAlgorithm) {
|
|
6
11
|
/**
|
package/index.ts
CHANGED
|
@@ -56,5 +56,5 @@ export { formatDateByCountryCode, getLongFormattedDateTime, capitalizeFirstLette
|
|
|
56
56
|
// Export des enums
|
|
57
57
|
export { RoleType, MovaAppType, DayOfWeek, EventState, EventType, DocumentType,
|
|
58
58
|
DigitalPassportIndex, DocumentState, Gender, DateFormatTypes, PartsApplicationType,
|
|
59
|
-
ProductType, OrderPreference, OrderState, SlotAlgorithm } from './src/helpers/Enums';
|
|
59
|
+
ProductType, OrderPreference, OrderState, SlotAlgorithm, VehiclePlateFormat as VehiclePlateType } from './src/helpers/Enums';
|
|
60
60
|
|
package/package.json
CHANGED
|
@@ -1,48 +1,118 @@
|
|
|
1
|
-
import React, { FunctionComponent, useEffect, useState } from 'react';
|
|
1
|
+
import React, { FunctionComponent, ReactNode, useEffect, useState } from 'react';
|
|
2
2
|
import TextField from '@mui/material/TextField';
|
|
3
|
+
import { VehiclePlateFormat } from './helpers/Enums';
|
|
4
|
+
import Logger from './helpers/Logger';
|
|
5
|
+
import { IconButton, InputAdornment } from '@mui/material';
|
|
6
|
+
import SearchIcon from '@mui/icons-material/SearchRounded';
|
|
3
7
|
|
|
4
8
|
interface VehiclePlateFieldProps {
|
|
5
9
|
onValidVehiclePlate: (vehiclePlate: string) => void;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
// Regex pour une plaque d'immatriculation française
|
|
12
|
+
// Regex pour une plaque d'immatriculation française (nouveau format SIV)
|
|
9
13
|
const regex = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
|
|
14
|
+
// Regex pour une plaque d'immatriculation française (ancien format FNI)
|
|
15
|
+
const oldRegex = /^\d{1,4}[ -]?[A-Z]{1,4}[ -]?\d{1,4}$/;
|
|
16
|
+
|
|
10
17
|
|
|
11
18
|
const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps> = ({ onValidVehiclePlate }) => {
|
|
12
19
|
|
|
13
20
|
const [value, setValue] = useState<string>('');
|
|
14
21
|
const [error, setError] = useState<boolean>(false);
|
|
15
22
|
const [lastLength, setLastLength] = useState<number>(0); // Ajout d'un état pour stocker la longueur précédente
|
|
23
|
+
const [helperText, setHelperText] = useState<ReactNode>('');
|
|
16
24
|
|
|
25
|
+
// Hook de validation de la plaque
|
|
17
26
|
useEffect(() => {
|
|
18
27
|
if (!error && value !== '' && value.match(regex)) {
|
|
19
28
|
onValidVehiclePlate(value);
|
|
20
29
|
}
|
|
30
|
+
|
|
21
31
|
}, [error, value, onValidVehiclePlate]);
|
|
22
32
|
|
|
33
|
+
const getPlateFormat = (plate: string): VehiclePlateFormat => {
|
|
34
|
+
if (/^[A-Za-z]/.test(plate)) {
|
|
35
|
+
// Commence par une lettre => nouveau format
|
|
36
|
+
return VehiclePlateFormat.FRENCH_NEW;
|
|
37
|
+
} else if (/^\d/.test(plate)) {
|
|
38
|
+
// Commence par un chiffre => ancien format
|
|
39
|
+
return VehiclePlateFormat.FRENCH_OLD;
|
|
40
|
+
} else {
|
|
41
|
+
Logger.error("Format de plaque inconnu");
|
|
42
|
+
// On retourne le nouveau format par défaut
|
|
43
|
+
return VehiclePlateFormat.FRENCH_NEW;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
23
47
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
24
48
|
|
|
25
49
|
let inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
|
|
26
50
|
|
|
27
|
-
|
|
28
|
-
|
|
51
|
+
// Si la saisie commence par une lettre, on contrôle l'ancien format, sinon le nouveau
|
|
52
|
+
switch(getPlateFormat(inputValue)){
|
|
29
53
|
|
|
30
|
-
|
|
31
|
-
|
|
54
|
+
case VehiclePlateFormat.FRENCH_NEW :{
|
|
55
|
+
setHelperText(<>Format détecté : <b>AA-111-AA</b></>);
|
|
56
|
+
handleChangeFrenchNew(inputValue);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
32
59
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
60
|
+
case VehiclePlateFormat.FRENCH_OLD: {
|
|
61
|
+
setHelperText(<>Format détecté (ancien) : <b>1111 AAAA 1111</b></>);
|
|
62
|
+
handleChangeFrenchOld(inputValue);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
36
65
|
}
|
|
37
66
|
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const validatePlate = () => {
|
|
70
|
+
|
|
71
|
+
if(oldRegex.test(value)){
|
|
72
|
+
onValidVehiclePlate(value);
|
|
40
73
|
}
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
75
|
+
setError(!oldRegex.test(value));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const handleChangeFrenchOld = (inputValue: string) => {
|
|
79
|
+
|
|
80
|
+
// ON bloque la saisie à 12 caractères max (limite des anciennes plaques)
|
|
81
|
+
if(!(inputValue.length > 12)){
|
|
82
|
+
setValue(inputValue);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const handleChangeFrenchNew = (inputValue: string) => {
|
|
89
|
+
|
|
90
|
+
// Vérifier si l'utilisateur est en train de supprimer un caractère
|
|
91
|
+
const isDeleting = inputValue.length < lastLength;
|
|
92
|
+
|
|
93
|
+
// Supprimer les tirets pour avoir une chaîne propre
|
|
94
|
+
const cleanInput = inputValue.replace(/-/g, '');
|
|
95
|
+
|
|
96
|
+
// Ajouter des tirets aux positions appropriées
|
|
97
|
+
if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
|
|
98
|
+
inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2)}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
|
|
102
|
+
inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2, 5)}-${cleanInput.slice(5, 7)}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setValue(inputValue);
|
|
106
|
+
|
|
107
|
+
// On teste la plaque une fois la saisie terminée
|
|
108
|
+
if(inputValue.length == 9){
|
|
109
|
+
setError(!regex.test(inputValue));
|
|
110
|
+
} else {
|
|
111
|
+
setError(false);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
115
|
+
}
|
|
46
116
|
|
|
47
117
|
return (
|
|
48
118
|
<TextField
|
|
@@ -56,7 +126,21 @@ const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps> = ({ onValidV
|
|
|
56
126
|
width: '100%',
|
|
57
127
|
'& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
|
|
58
128
|
}}
|
|
59
|
-
helperText={
|
|
129
|
+
helperText={lastLength > 0 ? helperText : ''}
|
|
130
|
+
InputProps={{
|
|
131
|
+
endAdornment: (
|
|
132
|
+
|
|
133
|
+
<InputAdornment position="end" sx={{ mr: 1, display: getPlateFormat(value) === VehiclePlateFormat.FRENCH_OLD ? 'inherit' : 'none' }} >
|
|
134
|
+
<IconButton
|
|
135
|
+
edge="end"
|
|
136
|
+
onClick={validatePlate}
|
|
137
|
+
>
|
|
138
|
+
<SearchIcon />
|
|
139
|
+
</IconButton>
|
|
140
|
+
</InputAdornment>
|
|
141
|
+
|
|
142
|
+
),
|
|
143
|
+
}}
|
|
60
144
|
/>
|
|
61
145
|
);
|
|
62
146
|
};
|
package/src/helpers/Enums.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
export enum VehiclePlateFormat {
|
|
2
|
+
FRENCH_NEW = "FRENCH_NEW",
|
|
3
|
+
FRENCH_OLD ="FRENCH_OLD"
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
export enum SlotAlgorithm {
|
|
2
7
|
/**
|
|
3
8
|
* Calcul des créneaux à l'heure
|
|
4
9
|
*/
|
|
5
|
-
HOUR ="HOUR",
|
|
10
|
+
HOUR = "HOUR",
|
|
6
11
|
/**
|
|
7
12
|
* Calcul des créneaux à demi-heure
|
|
8
13
|
*/
|
|
9
|
-
HALF_HOUR ="HALF_HOUR",
|
|
14
|
+
HALF_HOUR = "HALF_HOUR",
|
|
10
15
|
/**
|
|
11
16
|
* Calcul des créneaux à la période du jour (AM/PM)
|
|
12
17
|
*/
|
|
13
|
-
DAY_PERIOD ="DAY_PERIOD"
|
|
18
|
+
DAY_PERIOD = "DAY_PERIOD"
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export enum OrderState {
|