@movalib/movalib-commons 1.59.13 → 1.59.15

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 (46) hide show
  1. package/.env.development +2 -0
  2. package/devIndex.tsx +1 -1
  3. package/dist/devIndex.js +1 -1
  4. package/dist/index.d.ts +6 -3
  5. package/dist/index.js +14 -4
  6. package/dist/src/components/LinkedDocumentDialog.d.ts +11 -0
  7. package/dist/src/components/LinkedDocumentDialog.js +55 -0
  8. package/dist/src/{VehicleFullCard.d.ts → components/vehicle/VehicleFullCard.d.ts} +5 -2
  9. package/dist/src/{VehicleFullCard.js → components/vehicle/VehicleFullCard.js} +44 -22
  10. package/dist/src/components/vehicle/VehiclePlateField.d.ts +8 -0
  11. package/dist/src/components/vehicle/VehiclePlateField.js +122 -0
  12. package/dist/src/helpers/CookieUtils.js +2 -1
  13. package/dist/src/helpers/Enums.d.ts +10 -1
  14. package/dist/src/helpers/Enums.js +10 -1
  15. package/dist/src/helpers/Tools.d.ts +1 -0
  16. package/dist/src/helpers/Tools.js +10 -1
  17. package/dist/src/models/Garage.d.ts +2 -0
  18. package/dist/src/services/AuthenticationService.js +2 -0
  19. package/dist/src/services/GarageService.d.ts +8 -4
  20. package/dist/src/services/GarageService.js +75 -45
  21. package/dist/src/services/UserConnected.d.ts +9 -0
  22. package/dist/src/services/UserConnected.js +59 -0
  23. package/dist/src/services/UserService.d.ts +1 -1
  24. package/dist/src/services/VehicleService.d.ts +3 -0
  25. package/dist/src/services/VehicleService.js +22 -0
  26. package/dist/src/style/styled.d.ts +17 -0
  27. package/dist/src/style/styled.js +68 -0
  28. package/dist/src/style/styled.ts +70 -0
  29. package/index.ts +8 -3
  30. package/package.json +3 -2
  31. package/src/VehiclePlateField.tsx +1 -0
  32. package/src/components/LinkedDocumentDialog.tsx +200 -0
  33. package/src/components/vehicle/VehicleFullCard.tsx +549 -0
  34. package/src/components/vehicle/VehiclePlateField.tsx +164 -0
  35. package/src/helpers/CookieUtils.ts +2 -1
  36. package/src/helpers/Enums.ts +12 -1
  37. package/src/helpers/Tools.ts +5 -0
  38. package/src/models/Event.ts +1 -1
  39. package/src/models/Garage.ts +2 -0
  40. package/src/services/AuthenticationService.ts +2 -1
  41. package/src/services/GarageService.ts +557 -390
  42. package/src/services/UserConnected.ts +56 -0
  43. package/src/services/UserService.ts +1 -1
  44. package/src/services/VehicleService.ts +25 -0
  45. package/src/style/styled.ts +70 -0
  46. package/src/VehicleFullCard.tsx +0 -503
@@ -0,0 +1,164 @@
1
+ import React, { FunctionComponent, ReactNode, useEffect, useState } from 'react';
2
+ import TextField from '@mui/material/TextField';
3
+ import { IconButton, InputAdornment } from '@mui/material';
4
+ import SearchIcon from '@mui/icons-material/SearchRounded';
5
+ import { VehiclePlateFormat } from '../../helpers/Enums';
6
+ import Logger from '../../helpers/Logger';
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
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
53
+
54
+ let inputValue = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, ''); // Convertir en majuscules et supprimer les caractères non valides
55
+
56
+ // Si la saisie commence par une lettre, on contrôle l'ancien format, sinon le nouveau
57
+ switch(getPlateFormat(inputValue)){
58
+
59
+ case VehiclePlateFormat.FRENCH_NEW :{
60
+ setHelperText(<>Format détecté : <b>AA-111-AA</b></>);
61
+ handleChangeFrenchNew(inputValue);
62
+ break;
63
+ }
64
+
65
+ case VehiclePlateFormat.FRENCH_OLD: {
66
+ setHelperText(
67
+ <>
68
+ Format détecté (ancien) : <b>1111 AAAA 1111</b>
69
+ <br />
70
+ Pour lancer la recherche, cliquez sur <SearchIcon />
71
+ </>
72
+ );
73
+ handleChangeFrenchOld(inputValue);
74
+ break;
75
+ }
76
+
77
+ case undefined: {
78
+ setHelperText('');
79
+ setValue('');
80
+ }
81
+ }
82
+
83
+ };
84
+
85
+ const validatePlate = () => {
86
+
87
+ if(oldRegexPlate.test(value)){
88
+ onValidVehiclePlate(value);
89
+ }
90
+
91
+ setError(!oldRegexPlate.test(value));
92
+ }
93
+
94
+ const handleChangeFrenchOld = (inputValue: string) => {
95
+
96
+ // ON bloque la saisie à 12 caractères max (limite des anciennes plaques)
97
+ if(!(inputValue.length > 12)){
98
+ setValue(inputValue);
99
+ }
100
+
101
+ setLastLength(inputValue.length); // Mettre à jour la longueur précédente
102
+ }
103
+
104
+ const handleChangeFrenchNew = (inputValue: string) => {
105
+
106
+ // Vérifier si l'utilisateur est en train de supprimer un caractère
107
+ const isDeleting = inputValue.length < lastLength;
108
+
109
+ // Supprimer les tirets pour avoir une chaîne propre
110
+ const cleanInput = inputValue.replace(/-/g, '');
111
+
112
+ // Ajouter des tirets aux positions appropriées
113
+ if (cleanInput.length > 1 && !(cleanInput.length == 2 && isDeleting)) {
114
+ inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2)}`;
115
+ }
116
+
117
+ if (cleanInput.length > 4 && !(cleanInput.length == 5 && isDeleting)) {
118
+ inputValue = `${cleanInput.slice(0, 2)}-${cleanInput.slice(2, 5)}-${cleanInput.slice(5, 7)}`;
119
+ }
120
+
121
+ setValue(inputValue);
122
+
123
+ // On teste la plaque une fois la saisie terminée
124
+ if(inputValue.length == 9){
125
+ setError(!regexPlate.test(inputValue));
126
+ } else {
127
+ setError(false);
128
+ }
129
+
130
+ setLastLength(inputValue.length); // Mettre à jour la longueur précédente
131
+ }
132
+
133
+ return (
134
+ <TextField
135
+ label="Plaque d'immatriculation"
136
+ variant="outlined"
137
+ value={value}
138
+ onChange={handleChange}
139
+ error={error}
140
+ autoFocus
141
+ sx={{
142
+ width: '100%',
143
+ '& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
144
+ }}
145
+ helperText={lastLength > 0 ? helperText : ''}
146
+ InputProps={{
147
+ endAdornment: (
148
+
149
+ <InputAdornment position="end" sx={{ mr: 1, display: getPlateFormat(value) === VehiclePlateFormat.FRENCH_OLD ? 'inherit' : 'none' }} >
150
+ <IconButton
151
+ edge="end"
152
+ onClick={validatePlate}
153
+ >
154
+ <SearchIcon />
155
+ </IconButton>
156
+ </InputAdornment>
157
+
158
+ ),
159
+ }}
160
+ />
161
+ );
162
+ };
163
+
164
+ export default VehiclePlateField;
@@ -5,8 +5,9 @@ export const COOKIE_INDIVIDUAL_TOKEN: string = 'movalibIndividualToken';
5
5
  export const COOKIE_DEFAULT_EXPIRES: number = 7;
6
6
 
7
7
  export const createCookie = (name:string, value:string) => {
8
+ console.log('from lib', name, value);
8
9
  if(name && value){
9
- Cookies.set(name, value, { expires: COOKIE_DEFAULT_EXPIRES, sameSite: 'None', secure: true });
10
+ Cookies.set(name, value, { expires: COOKIE_DEFAULT_EXPIRES, sameSite: 'Lax' });
10
11
  }
11
12
  }
12
13
 
@@ -171,6 +171,10 @@ export enum DigitalPassportIndex {
171
171
  }
172
172
 
173
173
  export enum EventState {
174
+ /**
175
+ * Demande d'empreinte bancaire (pour validation de la demande de RDV)
176
+ */
177
+ REQUIRES_PAYMENT_AUTHORIZATION = "REQUIRES_PAYMENT_AUTHORIZATION",
174
178
  /**
175
179
  * Nouvelle demande de rendez-vous (origine client OU centre)
176
180
  */
@@ -231,8 +235,15 @@ export enum DocumentType {
231
235
  USER_BANK_DETAILS = "USER_BANK_DETAILS",
232
236
  USER_APPOINTMENT_QUOTE = "USER_APPOINTMENT_QUOTE",
233
237
  VEHICLE_MAINTENANCE_INVOICE = 'VEHICLE_MAINTENANCE_INVOICE',
238
+ GARAGE_LOGO = "GARAGE_LOGO",
239
+
234
240
  VEHICLE_TIRE_PHOTO = 'VEHICLE_TIRE_PHOTO',
235
- GARAGE_LOGO = "GARAGE_LOGO"
241
+ VEHICLE_INSPECTION = 'VEHICLE_INSPECTION',
242
+ VEHICLE_OTHER = 'VEHICLE_OTHER',
243
+
244
+ EVENT_OTHER = 'EVENT_OTHER',
245
+ EVENT_VISUAL_PROOFS = 'EVENT_VISUAL_PROOFS',
246
+ EVENT_MAINTENANCE = 'EVENT_MAINTENANCE',
236
247
  }
237
248
 
238
249
  export enum MovaAppType {
@@ -4,6 +4,7 @@ import { MovaFormField, MovaInterval } from "./Types";
4
4
  import { CSSProperties } from "react";
5
5
  import { DayOfWeek, PartsApplicationType, VehiclePlateFormat } from "./Enums";
6
6
  import Schedule from "../models/Schedule";
7
+ import UserConnected from "../services/UserConnected";
7
8
 
8
9
  export const getApplicationsShortLabels = (applications: PartsApplicationType[] | undefined): string => {
9
10
  if(!applications) {
@@ -46,6 +47,10 @@ export const getDayOfWeekIndex = (day: DayOfWeek) => {
46
47
  return -1;
47
48
  }
48
49
 
50
+ export const iAmOwner = (ownreId: number): boolean => {
51
+ return ownreId === UserConnected.getInstance().me?.id;
52
+ }
53
+
49
54
  export const formatPhoneNumber = (phoneNumber: string): string => {
50
55
  let formattedNumber = "";
51
56
 
@@ -108,4 +108,4 @@ export default class Event {
108
108
 
109
109
  return [];
110
110
  }
111
- }
111
+ }
@@ -51,6 +51,8 @@ export default class Garage {
51
51
  defaultView?: string;
52
52
  loanerVehicleActive?: boolean;
53
53
  loanerVehicleRequestActive?: boolean;
54
+ paymentAuthorizationActive?: boolean;
55
+ paymentAuthorizationMinDowntime?: number;
54
56
 
55
57
  constructor(
56
58
  id:string,
@@ -3,6 +3,7 @@ import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, createCookie } from "../help
3
3
  import { APIMethod, MovaAppType } from "../helpers/Enums";
4
4
  import Logger from "../helpers/Logger";
5
5
  import User from "../models/User";
6
+ import UserConnected from "./UserConnected";
6
7
  import UserService from "./UserService";
7
8
 
8
9
  export default class AuthenticationService {
@@ -68,7 +69,7 @@ export default class AuthenticationService {
68
69
  Logger.error(errorMsg);
69
70
  return { success: false, error: errorMsg };
70
71
  }
71
-
72
+ UserConnected.getInstance().me = userResponse.data;
72
73
  return { success: true, data: userResponse.data };
73
74
 
74
75
  } else {