@movalib/movalib-commons 1.62.3 → 1.63.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.
- package/devIndex.tsx +15 -4
- package/dist/devIndex.js +10 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -4
- package/dist/src/components/MovaTableBack/MovaTableBack.d.ts +25 -0
- package/dist/src/components/MovaTableBack/MovaTableBack.js +95 -0
- package/dist/src/components/vehicle/VehicleFullCard.js +5 -3
- package/dist/src/components/vehicle/VehiclePlateField.d.ts +5 -1
- package/dist/src/components/vehicle/VehiclePlateField.js +74 -16
- package/dist/src/helpers/Enums.d.ts +4 -2
- package/dist/src/helpers/Enums.js +2 -0
- package/dist/src/helpers/Tools.d.ts +1 -1
- package/dist/src/helpers/Tools.js +18 -9
- package/dist/src/models/Customer.d.ts +3 -1
- package/dist/src/models/Customer.js +9 -5
- package/dist/src/models/Document.d.ts +4 -1
- package/dist/src/models/Document.js +10 -2
- package/dist/src/models/Garage.d.ts +11 -7
- package/dist/src/models/Garage.js +5 -1
- package/dist/src/models/Vehicle.d.ts +2 -1
- package/dist/src/models/Vehicle.js +2 -1
- package/dist/src/services/GarageService.types.d.ts +2 -0
- package/index.ts +2 -1
- package/package.json +1 -1
- package/src/components/MovaTableBack/MovaTableBack.tsx +249 -0
- package/src/components/vehicle/VehicleFullCard.tsx +47 -43
- package/src/components/vehicle/VehiclePlateField.tsx +112 -28
- package/src/helpers/Enums.ts +2 -0
- package/src/helpers/Tools.ts +18 -8
- package/src/models/Customer.ts +49 -45
- package/src/models/Document.ts +20 -2
- package/src/models/Garage.ts +121 -104
- package/src/models/Vehicle.ts +4 -1
- package/src/services/GarageService.types.ts +2 -0
- package/dist/src/VehiclePlateField.d.ts +0 -8
- package/dist/src/VehiclePlateField.js +0 -122
- package/src/VehiclePlateField.tsx +0 -165
package/src/models/Vehicle.ts
CHANGED
|
@@ -36,6 +36,7 @@ export default class Vehicle {
|
|
|
36
36
|
tireSize: VehicleTire;
|
|
37
37
|
lastInspectionDate: Date;
|
|
38
38
|
lastMaintenanceDate: Date;
|
|
39
|
+
foreignPlate: boolean;
|
|
39
40
|
|
|
40
41
|
constructor(
|
|
41
42
|
id: number,
|
|
@@ -57,7 +58,8 @@ export default class Vehicle {
|
|
|
57
58
|
documents: Document[],
|
|
58
59
|
tireSize: VehicleTire,
|
|
59
60
|
lastInspectionDate: Date,
|
|
60
|
-
lastMaintenanceDate: Date
|
|
61
|
+
lastMaintenanceDate: Date,
|
|
62
|
+
foreignPlate: boolean
|
|
61
63
|
) {
|
|
62
64
|
this.id = id;
|
|
63
65
|
this.ownerId = ownerId;
|
|
@@ -79,6 +81,7 @@ export default class Vehicle {
|
|
|
79
81
|
this.tireSize = tireSize;
|
|
80
82
|
this.lastInspectionDate = lastInspectionDate;
|
|
81
83
|
this.lastMaintenanceDate = lastMaintenanceDate;
|
|
84
|
+
this.foreignPlate = foreignPlate
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
getVehicleLabel() {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent } from 'react';
|
|
2
|
-
interface VehiclePlateFieldProps {
|
|
3
|
-
onValidVehiclePlate: (vehiclePlate: string) => void;
|
|
4
|
-
}
|
|
5
|
-
export declare const regexPlate: RegExp;
|
|
6
|
-
export declare const oldRegexPlate: RegExp;
|
|
7
|
-
declare const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps>;
|
|
8
|
-
export default VehiclePlateField;
|
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.oldRegexPlate = exports.regexPlate = void 0;
|
|
18
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
-
var react_1 = require("react");
|
|
20
|
-
var TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
21
|
-
var Enums_1 = require("./helpers/Enums");
|
|
22
|
-
var Logger_1 = __importDefault(require("./helpers/Logger"));
|
|
23
|
-
var material_1 = require("@mui/material");
|
|
24
|
-
var SearchRounded_1 = __importDefault(require("@mui/icons-material/SearchRounded"));
|
|
25
|
-
// Regex pour une plaque d'immatriculation française (nouveau format SIV)
|
|
26
|
-
exports.regexPlate = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
|
|
27
|
-
// Regex pour une plaque d'immatriculation française (ancien format FNI)
|
|
28
|
-
exports.oldRegexPlate = /^\d{1,4}[ -]?[A-Z]{1,4}[ -]?\d{1,4}$/;
|
|
29
|
-
var VehiclePlateField = function (_a) {
|
|
30
|
-
var onValidVehiclePlate = _a.onValidVehiclePlate;
|
|
31
|
-
var _b = (0, react_1.useState)(''), value = _b[0], setValue = _b[1];
|
|
32
|
-
var _c = (0, react_1.useState)(false), error = _c[0], setError = _c[1];
|
|
33
|
-
var _d = (0, react_1.useState)(0), lastLength = _d[0], setLastLength = _d[1]; // Ajout d'un état pour stocker la longueur précédente
|
|
34
|
-
var _e = (0, react_1.useState)(''), helperText = _e[0], setHelperText = _e[1];
|
|
35
|
-
// Hook de validation de la plaque
|
|
36
|
-
(0, react_1.useEffect)(function () {
|
|
37
|
-
if (!error && value !== '' && value.match(exports.regexPlate)) {
|
|
38
|
-
onValidVehiclePlate(value);
|
|
39
|
-
}
|
|
40
|
-
}, [error, value, onValidVehiclePlate]);
|
|
41
|
-
var getPlateFormat = function (plate) {
|
|
42
|
-
if (plate === '') {
|
|
43
|
-
// Si la saisie est vide, retournez un format par défaut (nouveau format, par exemple)
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
if (/^[A-Za-z]/.test(plate)) {
|
|
47
|
-
// Commence par une lettre => nouveau format
|
|
48
|
-
return Enums_1.VehiclePlateFormat.FRENCH_NEW;
|
|
49
|
-
}
|
|
50
|
-
else if (/^\d/.test(plate)) {
|
|
51
|
-
// Commence par un chiffre => ancien format
|
|
52
|
-
return Enums_1.VehiclePlateFormat.FRENCH_OLD;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
Logger_1.default.error("Format de plaque inconnu");
|
|
56
|
-
// On retourne le nouveau format par défaut
|
|
57
|
-
return Enums_1.VehiclePlateFormat.FRENCH_NEW;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var handleChange = function (e) {
|
|
61
|
-
var inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
|
|
62
|
-
// Si la saisie commence par une lettre, on contrôle l'ancien format, sinon le nouveau
|
|
63
|
-
switch (getPlateFormat(inputValue)) {
|
|
64
|
-
case Enums_1.VehiclePlateFormat.FRENCH_NEW: {
|
|
65
|
-
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" })] }));
|
|
66
|
-
handleChangeFrenchNew(inputValue);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case Enums_1.VehiclePlateFormat.FRENCH_OLD: {
|
|
70
|
-
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" }), (0, jsx_runtime_1.jsx)("br", {}), "Pour lancer la recherche, cliquez sur ", (0, jsx_runtime_1.jsx)(SearchRounded_1.default, {})] }));
|
|
71
|
-
handleChangeFrenchOld(inputValue);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case undefined: {
|
|
75
|
-
setHelperText('');
|
|
76
|
-
setValue('');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var validatePlate = function () {
|
|
81
|
-
if (exports.oldRegexPlate.test(value)) {
|
|
82
|
-
onValidVehiclePlate(value);
|
|
83
|
-
}
|
|
84
|
-
setError(!exports.oldRegexPlate.test(value));
|
|
85
|
-
};
|
|
86
|
-
var handleChangeFrenchOld = function (inputValue) {
|
|
87
|
-
// ON bloque la saisie à 12 caractères max (limite des anciennes plaques)
|
|
88
|
-
if (!(inputValue.length > 12)) {
|
|
89
|
-
setValue(inputValue);
|
|
90
|
-
}
|
|
91
|
-
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
92
|
-
};
|
|
93
|
-
var handleChangeFrenchNew = function (inputValue) {
|
|
94
|
-
// Vérifier si l'utilisateur est en train de supprimer un caractère
|
|
95
|
-
var isDeleting = inputValue.length < lastLength;
|
|
96
|
-
// Supprimer les tirets pour avoir une chaîne propre
|
|
97
|
-
var cleanInput = inputValue.replace(/-/g, '');
|
|
98
|
-
// Ajouter des tirets aux positions appropriées
|
|
99
|
-
if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
|
|
100
|
-
inputValue = "".concat(cleanInput.slice(0, 2), "-").concat(cleanInput.slice(2));
|
|
101
|
-
}
|
|
102
|
-
if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
|
|
103
|
-
inputValue = "".concat(cleanInput.slice(0, 2), "-").concat(cleanInput.slice(2, 5), "-").concat(cleanInput.slice(5, 7));
|
|
104
|
-
}
|
|
105
|
-
setValue(inputValue);
|
|
106
|
-
// On teste la plaque une fois la saisie terminée
|
|
107
|
-
if (inputValue.length == 9) {
|
|
108
|
-
setError(!exports.regexPlate.test(inputValue));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
setError(false);
|
|
112
|
-
}
|
|
113
|
-
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
114
|
-
};
|
|
115
|
-
return ((0, jsx_runtime_1.jsx)(TextField_1.default, { label: "Plaque d'immatriculation", variant: "outlined", value: value, onChange: handleChange, error: error, autoFocus: true, sx: {
|
|
116
|
-
width: '100%',
|
|
117
|
-
'& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
|
|
118
|
-
}, helperText: lastLength > 0 ? helperText : '', InputProps: {
|
|
119
|
-
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, {}) })) }))),
|
|
120
|
-
} }));
|
|
121
|
-
};
|
|
122
|
-
exports.default = VehiclePlateField;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import React, { FunctionComponent, ReactNode, useEffect, useState } from 'react';
|
|
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';
|
|
7
|
-
|
|
8
|
-
interface VehiclePlateFieldProps {
|
|
9
|
-
onValidVehiclePlate: (vehiclePlate: string) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Regex pour une plaque d'immatriculation française (nouveau format SIV)
|
|
13
|
-
export const regexPlate = /^[A-Z]{2}-\d{3}-[A-Z]{2}$/;
|
|
14
|
-
// Regex pour une plaque d'immatriculation française (ancien format FNI)
|
|
15
|
-
export const oldRegexPlate = /^\d{1,4}[ -]?[A-Z]{1,4}[ -]?\d{1,4}$/;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const VehiclePlateField: FunctionComponent<VehiclePlateFieldProps> = ({ onValidVehiclePlate }) => {
|
|
19
|
-
|
|
20
|
-
const [value, setValue] = useState<string>('');
|
|
21
|
-
const [error, setError] = useState<boolean>(false);
|
|
22
|
-
const [lastLength, setLastLength] = useState<number>(0); // Ajout d'un état pour stocker la longueur précédente
|
|
23
|
-
const [helperText, setHelperText] = useState<ReactNode>('');
|
|
24
|
-
|
|
25
|
-
// Hook de validation de la plaque
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (!error && value !== '' && value.match(regexPlate)) {
|
|
28
|
-
onValidVehiclePlate(value);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
}, [error, value, onValidVehiclePlate]);
|
|
32
|
-
|
|
33
|
-
const getPlateFormat = (plate: string): VehiclePlateFormat | undefined => {
|
|
34
|
-
if (plate === '') {
|
|
35
|
-
// Si la saisie est vide, retournez un format par défaut (nouveau format, par exemple)
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (/^[A-Za-z]/.test(plate)) {
|
|
40
|
-
// Commence par une lettre => nouveau format
|
|
41
|
-
return VehiclePlateFormat.FRENCH_NEW;
|
|
42
|
-
} else if (/^\d/.test(plate)) {
|
|
43
|
-
// Commence par un chiffre => ancien format
|
|
44
|
-
return VehiclePlateFormat.FRENCH_OLD;
|
|
45
|
-
} else {
|
|
46
|
-
Logger.error("Format de plaque inconnu");
|
|
47
|
-
// On retourne le nouveau format par défaut
|
|
48
|
-
return VehiclePlateFormat.FRENCH_NEW;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
54
|
-
|
|
55
|
-
let inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
|
|
56
|
-
|
|
57
|
-
// Si la saisie commence par une lettre, on contrôle l'ancien format, sinon le nouveau
|
|
58
|
-
switch(getPlateFormat(inputValue)){
|
|
59
|
-
|
|
60
|
-
case VehiclePlateFormat.FRENCH_NEW :{
|
|
61
|
-
setHelperText(<>Format détecté : <b>AA-111-AA</b></>);
|
|
62
|
-
handleChangeFrenchNew(inputValue);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
case VehiclePlateFormat.FRENCH_OLD: {
|
|
67
|
-
setHelperText(
|
|
68
|
-
<>
|
|
69
|
-
Format détecté (ancien) : <b>1111 AAAA 1111</b>
|
|
70
|
-
<br />
|
|
71
|
-
Pour lancer la recherche, cliquez sur <SearchIcon />
|
|
72
|
-
</>
|
|
73
|
-
);
|
|
74
|
-
handleChangeFrenchOld(inputValue);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
case undefined: {
|
|
79
|
-
setHelperText('');
|
|
80
|
-
setValue('');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const validatePlate = () => {
|
|
87
|
-
|
|
88
|
-
if(oldRegexPlate.test(value)){
|
|
89
|
-
onValidVehiclePlate(value);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
setError(!oldRegexPlate.test(value));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const handleChangeFrenchOld = (inputValue: string) => {
|
|
96
|
-
|
|
97
|
-
// ON bloque la saisie à 12 caractères max (limite des anciennes plaques)
|
|
98
|
-
if(!(inputValue.length > 12)){
|
|
99
|
-
setValue(inputValue);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const handleChangeFrenchNew = (inputValue: string) => {
|
|
106
|
-
|
|
107
|
-
// Vérifier si l'utilisateur est en train de supprimer un caractère
|
|
108
|
-
const isDeleting = inputValue.length < lastLength;
|
|
109
|
-
|
|
110
|
-
// Supprimer les tirets pour avoir une chaîne propre
|
|
111
|
-
const cleanInput = inputValue.replace(/-/g, '');
|
|
112
|
-
|
|
113
|
-
// Ajouter des tirets aux positions appropriées
|
|
114
|
-
if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
|
|
115
|
-
inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2)}`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
|
|
119
|
-
inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2, 5)}-${cleanInput.slice(5, 7)}`;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
setValue(inputValue);
|
|
123
|
-
|
|
124
|
-
// On teste la plaque une fois la saisie terminée
|
|
125
|
-
if(inputValue.length == 9){
|
|
126
|
-
setError(!regexPlate.test(inputValue));
|
|
127
|
-
} else {
|
|
128
|
-
setError(false);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setLastLength(inputValue.length); // Mettre à jour la longueur précédente
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
<TextField
|
|
136
|
-
label="Plaque d'immatriculation"
|
|
137
|
-
variant="outlined"
|
|
138
|
-
value={value}
|
|
139
|
-
onChange={handleChange}
|
|
140
|
-
error={error}
|
|
141
|
-
autoFocus
|
|
142
|
-
sx={{
|
|
143
|
-
width: '100%',
|
|
144
|
-
'& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
|
|
145
|
-
}}
|
|
146
|
-
helperText={lastLength > 0 ? helperText : ''}
|
|
147
|
-
InputProps={{
|
|
148
|
-
endAdornment: (
|
|
149
|
-
|
|
150
|
-
<InputAdornment position="end" sx={{ mr: 1, display: getPlateFormat(value) === VehiclePlateFormat.FRENCH_OLD ? 'inherit' : 'none' }} >
|
|
151
|
-
<IconButton
|
|
152
|
-
edge="end"
|
|
153
|
-
onClick={validatePlate}
|
|
154
|
-
>
|
|
155
|
-
<SearchIcon />
|
|
156
|
-
</IconButton>
|
|
157
|
-
</InputAdornment>
|
|
158
|
-
|
|
159
|
-
),
|
|
160
|
-
}}
|
|
161
|
-
/>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export default VehiclePlateField;
|