@movalib/movalib-commons 1.59.35 → 1.59.37

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.
@@ -1,508 +1,748 @@
1
+ import { AttachFile } from "@mui/icons-material";
1
2
  import {
2
- Alert, Box, Button, Card, CardActions, CardContent, FormControl, FormHelperText, Grid, IconButton, InputLabel,
3
- Link, MenuItem, Select, SelectChangeEvent, TextField, Tooltip, Typography, darken, useTheme
4
- } from '@mui/material';
5
- import { useState, type FC, useEffect, useRef } from 'react';
6
- import CarFigure from "../../assets/images/car_figure.png";
7
- import { MovaFormField, MovaVehicleForm } from '../../helpers/Types';
8
- import Vehicle from '../../models/Vehicle';
9
- import Document from '../../models/Document';
10
- import VehicleTire from '../../models/VehicleTire';
11
- import MovaVehicleTireField from '../../MovaVehicleTireField';
12
- import ConfirmationDialog from '../../ConfirmationDialog';
13
- import { DocumentType, DateFormatTypes, MovaAppType } from '../../helpers/Enums';
14
- import { validateField, formatVehicleTire, formatFrenchVehiclePlate } from '../../helpers/Tools';
15
- import MovaDigitalPassport from '../../MovaDigitalPassport';
16
- import Loader from '../../Loader';
17
- import { formatDateByTimezone } from '../../helpers/DateUtils';
18
- import CancelIcon from '@mui/icons-material/CloseRounded';
19
- import EditIcon from '@mui/icons-material/EditRounded';
20
- import CloseIcon from '@mui/icons-material/CloseRounded';
21
- import Logger from '../../helpers/Logger';
22
- import { AttachFile } from '@mui/icons-material';
23
- import { LinkedDocumentDialog } from '../LinkedDocumentDialog';
24
- import User from '../../models/User';
25
- import CatPlateBg from '../../assets/images/car_plate_bg.png';
26
- import { DatePicker } from '@mui/x-date-pickers';
3
+ default as CancelIcon,
4
+ default as CloseIcon,
5
+ } from "@mui/icons-material/CloseRounded";
6
+ import EditIcon from "@mui/icons-material/EditRounded";
7
+ import {
8
+ Alert,
9
+ Box,
10
+ Button,
11
+ Card,
12
+ CardActions,
13
+ CardContent,
14
+ FormControl,
15
+ FormHelperText,
16
+ Grid,
17
+ IconButton,
18
+ InputLabel,
19
+ Link,
20
+ MenuItem,
21
+ Select,
22
+ SelectChangeEvent,
23
+ TextField,
24
+ Tooltip,
25
+ Typography,
26
+ darken,
27
+ useTheme,
28
+ } from "@mui/material";
29
+ import { DatePicker } from "@mui/x-date-pickers";
30
+ import { useEffect, useRef, useState, type FC } from "react";
31
+ import CatPlateBg from "../../assets/images/car_plate_bg.png";
32
+ import ConfirmationDialog from "../../ConfirmationDialog";
33
+ import { formatDateByTimezone } from "../../helpers/DateUtils";
34
+ import {
35
+ DateFormatTypes,
36
+ DocumentType,
37
+ MovaAppType,
38
+ } from "../../helpers/Enums";
39
+ import Logger from "../../helpers/Logger";
40
+ import {
41
+ formatFrenchVehiclePlate,
42
+ formatVehicleTire,
43
+ } from "../../helpers/Tools";
44
+ import { MovaFormField, MovaVehicleForm } from "../../helpers/Types";
45
+ import User from "../../models/User";
46
+ import Vehicle from "../../models/Vehicle";
47
+ import VehicleTire from "../../models/VehicleTire";
48
+ import MovaVehicleTireField from "../../MovaVehicleTireField";
49
+ import { LinkedDocumentDialog } from "../LinkedDocumentDialog";
27
50
 
28
51
  interface VehicleFullCardProps {
29
- currentUser: User,
30
- vehicle: Vehicle,
31
- onError: (message: string) => void,
32
- onUploadDocument: (data: FormData) => void,
33
- onDeleteDocument: (documentId: string) => void,
34
- editMode: boolean,
35
- appType: MovaAppType;
36
- fullwidth?: boolean,
37
- focused?: boolean,
38
- onUpdate?: (form: MovaVehicleForm) => void,
39
- onDelete?: () => void;
40
- currentUpload: boolean;
52
+ currentUser: User;
53
+ vehicle: Vehicle;
54
+ onError: (message: string) => void;
55
+ onUploadDocument: (data: FormData) => void;
56
+ onDeleteDocument: (documentId: string) => void;
57
+ editMode: boolean;
58
+ appType: MovaAppType;
59
+ fullwidth?: boolean;
60
+ focused?: boolean;
61
+ onUpdate?: (form: MovaVehicleForm) => void;
62
+ onDelete?: () => void;
63
+ currentUpload: boolean;
41
64
  }
42
65
 
43
66
  const initialUserFormState = {
44
- currentMileage: { value: null, isValid: true },
45
- averageMileagePerYear: { value: null, isValid: true },
46
- tireSize: { value: null, isValid: true },
47
- tireWidth: { value: '', isValid: true },
48
- tireHeight: { value: '', isValid: true },
49
- tireDiameter: { value: '', isValid: true },
50
- tireSpeedIndex: { value: '', isValid: true },
51
- lastInspectionDate: { value: null, isValid: true },
52
- lastMaintenanceDate: { value: null, isValid: true }
53
- }
54
-
55
- const VehicleFullCard: FC<VehicleFullCardProps> = ({ vehicle, fullwidth, onError, onUploadDocument, onDeleteDocument, appType, editMode = false, focused = false, onUpdate, onDelete, currentUpload, currentUser }) => {
56
-
57
- const theme = useTheme();
58
- const [localEditMode, setLocalEditMode] = useState(editMode);
59
- const [openConfirmDocumentDelete, setOpenConfirmDocumentDelete] = useState(false);
60
- const [openConfirmVehicleDelete, setOpenConfirmVehicleDelete] = useState(false);
61
- const [documentToDelete, setDocumentToDelete] = useState('');
62
- const [sizeLimit, setSizeLimit] = useState(false);
63
- // Formulaire utilisé pour les modifications d'informations sur le véhicule
64
- const [form, setForm] = useState<MovaVehicleForm>(initialUserFormState);
65
- // Références aux éventuels documents uploadés depuis la fiche
66
- const invoiceInputRef = useRef<HTMLInputElement>(null);
67
- const tirePictureInputRef = useRef(null);
68
- const [isShowLinkedDocument, setShowLinkedDocument] = useState(false);
69
- const docTypeCurrent = useRef<DocumentType>();
70
-
71
- const messageRGPD = appType === MovaAppType.INDIVIDUAL ? <Box></Box> : <Box sx={{ mt: 2 }}><Alert severity='warning'>
72
- Vous êtes responsable des documents que vous importez, en ajoutant un document vous reconnaissez
73
- disposer du consentement explicite du client pour le stockage de ses données conformément à la
74
- réglementation RGPD.
75
- </Alert></Box>;
76
-
77
- useEffect(() => {
78
- setLocalEditMode(editMode);
79
- }, [editMode]);
80
-
81
- useEffect(() => {
82
- initForm();
83
- }, [vehicle]);
84
-
85
- const initForm = () => {
86
- if (vehicle)
87
- {
88
-
89
- setForm(prevForm => (
90
- { ...prevForm, ['currentMileage']: { ...prevForm['currentMileage'], value: vehicle.currentMileage } }));
91
- setForm(prevForm => (
92
- { ...prevForm, ['averageMileagePerYear']: { ...prevForm['averageMileagePerYear'], value: vehicle.averageMileagePerYear } }));
93
- setForm(prevForm => (
94
- { ...prevForm, ['tireWidth']: { ...prevForm['tireWidth'], value: vehicle.tireWidth } }));
95
- setForm(prevForm => (
96
- { ...prevForm, ['tireHeight']: { ...prevForm['tireHeight'], value: vehicle.tireHeight } }));
97
- setForm(prevForm => (
98
- { ...prevForm, ['tireDiameter']: { ...prevForm['tireDiameter'], value: vehicle.tireDiameter } }));
99
- setForm(prevForm => (
100
- { ...prevForm, ['tireSpeedIndex']: { ...prevForm['tireSpeedIndex'], value: vehicle.tireSpeedIndex } }));
101
- setForm(prevForm => (
102
- { ...prevForm, ['lastInspectionDate']: { ...prevForm['lastInspectionDate'], value: vehicle.lastInspectionDate ? new Date(vehicle.lastInspectionDate) : null } }));
103
- setForm(prevForm => (
104
- { ...prevForm, ['lastMaintenanceDate']: { ...prevForm['lastMaintenanceDate'], value: vehicle.lastMaintenanceDate ? new Date(vehicle.lastMaintenanceDate) : null } }));
105
-
106
- if (isVehicleTireSizeDefined(vehicle))
107
- {
108
- setForm(prevForm => (
109
- { ...prevForm, ['tireSize']: { ...prevForm['tireSize'], value: vehicle.tireSize } }));
110
- }
111
-
112
- Logger.info(form);
113
- }
114
- }
115
-
116
- const toggleShowLinkedDocument = (docType: DocumentType | null) => {
117
- setShowLinkedDocument(!isShowLinkedDocument);
118
- if (docType && invoiceInputRef.current)
119
- {
120
- docTypeCurrent.current = docType;
121
- invoiceInputRef.current.click();
122
- } else
123
- {
124
- docTypeCurrent.current = undefined;
125
- }
126
- }
127
-
128
- const isVehicleTireSizeDefined = (vehicle: Vehicle) => {
129
- return vehicle.tireSize && vehicle.tireSize.diameter && vehicle.tireSize.height && vehicle.tireSize.speedIndex && vehicle.tireSize.width;
130
- }
131
-
132
- const validateForm = () => {
133
- let newForm: MovaVehicleForm = { ...form };
134
-
135
- // Validator pour les champs obligatoires
136
- newForm.currentMileage = validateField(form.currentMileage, value => !!value, 'Champ obligatoire');
137
- newForm.averageMileagePerYear = validateField(form.averageMileagePerYear, value => !!value, 'Champ obligatoire');
138
-
139
- // La validation de la saisie des pneumatiques se fait dans le composant "MovaVehicleTireField", traitée dans le callback "handleOnChangeVehicleTire"
140
-
141
- setForm(newForm);
142
-
143
- return newForm.currentMileage.isValid && newForm.averageMileagePerYear.isValid && newForm.tireSize.isValid;
144
- }
67
+ currentMileage: { value: null, isValid: true },
68
+ averageMileagePerYear: { value: null, isValid: true },
69
+ tireSize: { value: null, isValid: true },
70
+ tireWidth: { value: "", isValid: true },
71
+ tireHeight: { value: "", isValid: true },
72
+ tireDiameter: { value: "", isValid: true },
73
+ tireSpeedIndex: { value: "", isValid: true },
74
+ lastInspectionDate: { value: null, isValid: true },
75
+ lastMaintenanceDate: { value: null, isValid: true },
76
+ };
77
+
78
+ const VehicleFullCard: FC<VehicleFullCardProps> = ({
79
+ vehicle,
80
+ fullwidth,
81
+ onError,
82
+ onUploadDocument,
83
+ onDeleteDocument,
84
+ appType,
85
+ editMode = false,
86
+ focused = false,
87
+ onUpdate,
88
+ onDelete,
89
+ currentUpload,
90
+ currentUser,
91
+ }) => {
92
+ const theme = useTheme();
93
+ const [localEditMode, setLocalEditMode] = useState(editMode);
94
+ const [openConfirmDocumentDelete, setOpenConfirmDocumentDelete] =
95
+ useState(false);
96
+ const [openConfirmVehicleDelete, setOpenConfirmVehicleDelete] =
97
+ useState(false);
98
+ const [documentToDelete, setDocumentToDelete] = useState("");
99
+ const [sizeLimit, setSizeLimit] = useState(false);
100
+ // Formulaire utilisé pour les modifications d'informations sur le véhicule
101
+ const [form, setForm] = useState<MovaVehicleForm>(initialUserFormState);
102
+ // Références aux éventuels documents uploadés depuis la fiche
103
+ const invoiceInputRef = useRef<HTMLInputElement>(null);
104
+ const tirePictureInputRef = useRef(null);
105
+ const [isShowLinkedDocument, setShowLinkedDocument] = useState(false);
106
+ const docTypeCurrent = useRef<DocumentType>();
107
+
108
+ const messageRGPD =
109
+ appType === MovaAppType.INDIVIDUAL ? (
110
+ <Box></Box>
111
+ ) : (
112
+ <Box sx={{ mt: 2 }}>
113
+ <Alert severity="warning">
114
+ Vous êtes responsable des documents que vous importez, en ajoutant un
115
+ document vous reconnaissez disposer du consentement explicite du
116
+ client pour le stockage de ses données conformément à la
117
+ réglementation RGPD.
118
+ </Alert>
119
+ </Box>
120
+ );
145
121
 
146
- const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {
147
- handleChange(e.target.name, e.target.value);
122
+ useEffect(() => {
123
+ setLocalEditMode(editMode);
124
+ }, [editMode]);
125
+
126
+ useEffect(() => {
127
+ initForm();
128
+ }, [vehicle]);
129
+
130
+ const initForm = () => {
131
+ if (vehicle) {
132
+ setForm((prevForm) => ({
133
+ ...prevForm,
134
+ currentMileage: {
135
+ ...prevForm["currentMileage"],
136
+ value: vehicle.currentMileage,
137
+ },
138
+ }));
139
+ setForm((prevForm) => ({
140
+ ...prevForm,
141
+ averageMileagePerYear: {
142
+ ...prevForm["averageMileagePerYear"],
143
+ value: vehicle.averageMileagePerYear,
144
+ },
145
+ }));
146
+ setForm((prevForm) => ({
147
+ ...prevForm,
148
+ tireWidth: { ...prevForm["tireWidth"], value: vehicle.tireWidth },
149
+ }));
150
+ setForm((prevForm) => ({
151
+ ...prevForm,
152
+ tireHeight: { ...prevForm["tireHeight"], value: vehicle.tireHeight },
153
+ }));
154
+ setForm((prevForm) => ({
155
+ ...prevForm,
156
+ tireDiameter: {
157
+ ...prevForm["tireDiameter"],
158
+ value: vehicle.tireDiameter,
159
+ },
160
+ }));
161
+ setForm((prevForm) => ({
162
+ ...prevForm,
163
+ tireSpeedIndex: {
164
+ ...prevForm["tireSpeedIndex"],
165
+ value: vehicle.tireSpeedIndex,
166
+ },
167
+ }));
168
+ setForm((prevForm) => ({
169
+ ...prevForm,
170
+ lastInspectionDate: {
171
+ ...prevForm["lastInspectionDate"],
172
+ value: vehicle.lastInspectionDate
173
+ ? new Date(vehicle.lastInspectionDate)
174
+ : null,
175
+ },
176
+ }));
177
+ setForm((prevForm) => ({
178
+ ...prevForm,
179
+ lastMaintenanceDate: {
180
+ ...prevForm["lastMaintenanceDate"],
181
+ value: vehicle.lastMaintenanceDate
182
+ ? new Date(vehicle.lastMaintenanceDate)
183
+ : null,
184
+ },
185
+ }));
186
+
187
+ if (isVehicleTireSizeDefined(vehicle)) {
188
+ setForm((prevForm) => ({
189
+ ...prevForm,
190
+ tireSize: { ...prevForm["tireSize"], value: vehicle.tireSize },
191
+ }));
192
+ }
193
+
194
+ Logger.info(form);
148
195
  }
149
-
150
- const handleSelectChange = (e: SelectChangeEvent<string>): void => {
151
- handleChange(e.target.name, e.target.value);
196
+ };
197
+
198
+ const toggleShowLinkedDocument = (docType: DocumentType | null) => {
199
+ setShowLinkedDocument(!isShowLinkedDocument);
200
+ if (docType && invoiceInputRef.current) {
201
+ docTypeCurrent.current = docType;
202
+ invoiceInputRef.current.click();
203
+ } else {
204
+ docTypeCurrent.current = undefined;
152
205
  }
206
+ };
153
207
 
154
- const handleChange = (fieldName: string, fieldValue: string): void => {
155
- console.log(fieldName, fieldValue);
156
- const newField: MovaFormField = { [fieldName]: { value: fieldValue, isValid: true } };
208
+ const isVehicleTireSizeDefined = (vehicle: Vehicle) => {
209
+ return (
210
+ vehicle.tireSize &&
211
+ vehicle.tireSize.diameter &&
212
+ vehicle.tireSize.height &&
213
+ vehicle.tireSize.speedIndex &&
214
+ vehicle.tireSize.width
215
+ );
216
+ };
157
217
 
158
- setForm({ ...form, ...newField });
159
- }
218
+ const validateForm = () => {
219
+ let newForm: MovaVehicleForm = { ...form };
160
220
 
161
- const uploadVehicleDocument = (document: File, documentType: DocumentType) => {
162
- if (document.size > 10000000)
163
- {
164
- setSizeLimit(true);
165
- return;
166
- }
167
-
168
- if (vehicle && document && documentType)
169
- {
170
-
171
- // Utilisation d'un formData pour permettre le trasnfert de fichier vers l'API
172
- let formData = new FormData();
173
- formData.append("documentType", documentType);
174
- // Ajouter la facture à FormData
175
- formData.append('file', document);
176
-
177
- // Appel du callback correspondant
178
- if (onUploadDocument)
179
- onUploadDocument(formData);
180
- }
181
- }
221
+ // Validator pour les champs obligatoires
222
+ // newForm.currentMileage = validateField(form.currentMileage, value => !!value, 'Champ obligatoire');
223
+ // newForm.averageMileagePerYear = validateField(form.averageMileagePerYear, value => !!value, 'Champ obligatoire');
182
224
 
183
- /**
184
- *
185
- * @param event L'upload des documents se fait directement lors du téléchargement
186
- * @param docType
187
- */
188
- const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>, docType: DocumentType) => {
189
- event.preventDefault();
225
+ // La validation de la saisie des pneumatiques se fait dans le composant "MovaVehicleTireField", traitée dans le callback "handleOnChangeVehicleTire"
190
226
 
191
- if (event && event.target.files && event.target.files.length > 0 && docType)
192
- {
193
- uploadVehicleDocument(event.target.files[0], docType);
194
- }
227
+ setForm(newForm);
195
228
 
229
+ return (
230
+ newForm.currentMileage.isValid &&
231
+ newForm.averageMileagePerYear.isValid &&
232
+ newForm.tireSize.isValid
233
+ );
234
+ };
235
+
236
+ const handleInputChange = (
237
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
238
+ ): void => {
239
+ handleChange(e.target.name, e.target.value);
240
+ };
241
+
242
+ const handleSelectChange = (e: SelectChangeEvent<string>): void => {
243
+ handleChange(e.target.name, e.target.value);
244
+ };
245
+
246
+ const handleChange = (fieldName: string, fieldValue: string): void => {
247
+ console.log(fieldName, fieldValue);
248
+ const newField: MovaFormField = {
249
+ [fieldName]: { value: fieldValue, isValid: true },
196
250
  };
197
251
 
198
- const handleOnClickEdit = () => {
199
-
200
- // On passe la fiche véhicule en mode édition
201
- setLocalEditMode(true);
202
- }
203
-
204
- const handleOnChangeVehicleTire = (vehicleTire: VehicleTire, isValid: boolean) => {
205
- setForm(prevForm => (
206
- { ...prevForm, ['tireSize']: { ...prevForm['tireSize'], value: vehicleTire, isValid: isValid } }));
207
- }
208
-
209
-
210
- const handleOnClickDeleteVehicle = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
211
- e.preventDefault();
212
- setOpenConfirmVehicleDelete(true);
213
- }
252
+ setForm({ ...form, ...newField });
253
+ };
214
254
 
215
- const handleDeleteDocument = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, documentId: string) => {
216
- e.preventDefault();
217
- setDocumentToDelete(documentId);
218
- setOpenConfirmDocumentDelete(true);
255
+ const uploadVehicleDocument = (
256
+ document: File,
257
+ documentType: DocumentType
258
+ ) => {
259
+ if (document.size > 10000000) {
260
+ setSizeLimit(true);
261
+ return;
219
262
  }
220
263
 
221
- const handleOnClickValidate = () => {
222
-
223
- if (validateForm())
224
- {
225
-
226
- Logger.info(form.tireSize.value);
227
-
228
- let query = {
229
- currentMileage: form.currentMileage.value,
230
- averageMileagePerYear: form.averageMileagePerYear.value,
231
- tireWidth: form.tireSize.isValid && form.tireSize.value ? (form.tireSize.value as VehicleTire).width : undefined,
232
- tireHeight: form.tireSize.isValid && form.tireSize.value ? (form.tireSize.value as VehicleTire).height : undefined,
233
- tireDiameter: form.tireSize.isValid && form.tireSize.value ? (form.tireSize.value as VehicleTire).diameter : undefined,
234
- tireSpeedIndex: form.tireSize.isValid && form.tireSize.value ? (form.tireSize.value as VehicleTire).speedIndex : undefined,
235
- lastInspectionDate: form.lastInspectionDate.value,
236
- lastMaintenanceDate: form.lastMaintenanceDate.value,
237
- }
238
- Logger.info(query)
239
-
240
- // Appel du callback correspondant
241
- if (onUpdate)
242
- onUpdate(form);
243
- }
244
- }
264
+ if (vehicle && document && documentType) {
265
+ // Utilisation d'un formData pour permettre le trasnfert de fichier vers l'API
266
+ let formData = new FormData();
267
+ formData.append("documentType", documentType);
268
+ // Ajouter la facture à FormData
269
+ formData.append("file", document);
245
270
 
246
- const handleOnClickCancel = () => {
247
- initForm();
248
- setLocalEditMode(false);
271
+ // Appel du callback correspondant
272
+ if (onUploadDocument) onUploadDocument(formData);
249
273
  }
250
-
251
- const handleCloseConfirmDocumentDelete = () => {
252
- setOpenConfirmDocumentDelete(false);
253
- setDocumentToDelete('');
274
+ };
275
+
276
+ /**
277
+ *
278
+ * @param event L'upload des documents se fait directement lors du téléchargement
279
+ * @param docType
280
+ */
281
+ const handleFileChange = (
282
+ event: React.ChangeEvent<HTMLInputElement>,
283
+ docType: DocumentType
284
+ ) => {
285
+ event.preventDefault();
286
+
287
+ if (
288
+ event &&
289
+ event.target.files &&
290
+ event.target.files.length > 0 &&
291
+ docType
292
+ ) {
293
+ uploadVehicleDocument(event.target.files[0], docType);
254
294
  }
255
-
256
- const handleCloseConfirmVehicleDelete = () => {
257
- setOpenConfirmVehicleDelete(false);
295
+ };
296
+
297
+ const handleOnClickEdit = () => {
298
+ // On passe la fiche véhicule en mode édition
299
+ setLocalEditMode(true);
300
+ };
301
+
302
+ const handleOnChangeVehicleTire = (
303
+ vehicleTire: VehicleTire,
304
+ isValid: boolean
305
+ ) => {
306
+ setForm((prevForm) => ({
307
+ ...prevForm,
308
+ tireSize: {
309
+ ...prevForm["tireSize"],
310
+ value: vehicleTire,
311
+ isValid: isValid,
312
+ },
313
+ }));
314
+ };
315
+
316
+ const handleOnClickDeleteVehicle = (
317
+ e: React.MouseEvent<HTMLButtonElement, MouseEvent>
318
+ ) => {
319
+ e.preventDefault();
320
+ setOpenConfirmVehicleDelete(true);
321
+ };
322
+
323
+ const handleDeleteDocument = (
324
+ e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
325
+ documentId: string
326
+ ) => {
327
+ e.preventDefault();
328
+ setDocumentToDelete(documentId);
329
+ setOpenConfirmDocumentDelete(true);
330
+ };
331
+
332
+ const handleOnClickValidate = () => {
333
+ if (validateForm()) {
334
+ Logger.info(form.tireSize.value);
335
+
336
+ let query = {
337
+ currentMileage: form.currentMileage.value,
338
+ averageMileagePerYear: form.averageMileagePerYear.value,
339
+ tireWidth:
340
+ form.tireSize.isValid && form.tireSize.value
341
+ ? (form.tireSize.value as VehicleTire).width
342
+ : undefined,
343
+ tireHeight:
344
+ form.tireSize.isValid && form.tireSize.value
345
+ ? (form.tireSize.value as VehicleTire).height
346
+ : undefined,
347
+ tireDiameter:
348
+ form.tireSize.isValid && form.tireSize.value
349
+ ? (form.tireSize.value as VehicleTire).diameter
350
+ : undefined,
351
+ tireSpeedIndex:
352
+ form.tireSize.isValid && form.tireSize.value
353
+ ? (form.tireSize.value as VehicleTire).speedIndex
354
+ : undefined,
355
+ lastInspectionDate: form.lastInspectionDate.value,
356
+ lastMaintenanceDate: form.lastMaintenanceDate.value,
357
+ };
358
+ Logger.info(query);
359
+
360
+ // Appel du callback correspondant
361
+ if (onUpdate) onUpdate(form);
258
362
  }
259
-
260
- /**
261
- *
262
- */
263
- const handleConfirmDocumentDelete = () => {
264
- setOpenConfirmDocumentDelete(false);
265
-
266
- if (vehicle && documentToDelete)
267
- {
268
-
269
- // Appel du callback correspondant
270
- if (onDeleteDocument)
271
- onDeleteDocument(documentToDelete);
272
- }
363
+ };
364
+
365
+ const handleOnClickCancel = () => {
366
+ initForm();
367
+ setLocalEditMode(false);
368
+ };
369
+
370
+ const handleCloseConfirmDocumentDelete = () => {
371
+ setOpenConfirmDocumentDelete(false);
372
+ setDocumentToDelete("");
373
+ };
374
+
375
+ const handleCloseConfirmVehicleDelete = () => {
376
+ setOpenConfirmVehicleDelete(false);
377
+ };
378
+
379
+ /**
380
+ *
381
+ */
382
+ const handleConfirmDocumentDelete = () => {
383
+ setOpenConfirmDocumentDelete(false);
384
+
385
+ if (vehicle && documentToDelete) {
386
+ // Appel du callback correspondant
387
+ if (onDeleteDocument) onDeleteDocument(documentToDelete);
273
388
  }
389
+ };
274
390
 
275
- const handleConfirmVehicleDelete = () => {
276
- setOpenConfirmVehicleDelete(false);
391
+ const handleConfirmVehicleDelete = () => {
392
+ setOpenConfirmVehicleDelete(false);
277
393
 
278
- if (vehicle && onDelete)
279
- {
280
-
281
- // Appel du callback correspondant
282
- onDelete();
283
- }
394
+ if (vehicle && onDelete) {
395
+ // Appel du callback correspondant
396
+ onDelete();
284
397
  }
285
-
286
- return (
287
- <>
288
- {vehicle &&
289
- <Card variant='outlined' sx={{
290
- maxWidth: fullwidth ? '80%' : 500,
291
- backgroundColor: focused ? theme.palette.primary.light : 'white',
292
- overflow: 'visible', mt: 4, pb: 1
293
- }}
398
+ };
399
+
400
+ return (
401
+ <>
402
+ {vehicle && (
403
+ <Card
404
+ variant="outlined"
405
+ sx={{
406
+ maxWidth: fullwidth ? "80%" : 500,
407
+ backgroundColor: focused ? theme.palette.primary.light : "white",
408
+ overflow: "visible",
409
+ mt: 4,
410
+ pb: 1,
411
+ }}
412
+ >
413
+ <CardContent sx={{ pt: 0, pb: 0 }}>
414
+ <Typography
415
+ variant="h6"
416
+ component="div"
417
+ align="center"
418
+ sx={{ mb: 1 }}
419
+ color={darken(theme.palette.primary.main, 0.2)}
420
+ >
421
+ {vehicle.brand && `${vehicle.brand} `}
422
+ {vehicle.model && `${vehicle.model} `}
423
+ {vehicle.version && `${vehicle.version}`}
424
+ </Typography>
425
+ <Grid container justifyContent="space-between">
426
+ <Grid
427
+ container
428
+ sx={{ mb: 1, alignItems: "center", justifyContent: "center" }}
429
+ >
430
+ <Grid
431
+ item
432
+ xs={6}
433
+ sx={{ position: "relative", minWidth: "234px" }}
294
434
  >
295
- <CardContent sx={{ pt: 0, pb: 0 }}>
296
- <Typography variant="h6" component="div" align="center" sx={{ mb: 1 }} color={darken(theme.palette.primary.main, 0.2)}>
297
- {vehicle.brand && `${vehicle.brand} `}
298
- {vehicle.model && `${vehicle.model} `}
299
- {vehicle.version && `${vehicle.version}`}
300
- </Typography>
301
- <Grid container justifyContent="space-between">
302
-
303
- <Grid container sx={{ mb: 1, alignItems: 'center', justifyContent: 'center' }}>
304
- <Grid item xs={6} sx={{ position: 'relative', minWidth: '234px' }}>
305
- <img
306
- src={CatPlateBg}
307
- alt="Plaque d'immatriculation"
308
- style={{ height: '50px', position: 'relative', }}
309
- />
310
- <Typography
311
- variant='h6'
312
- color={theme.palette.text.primary}
313
- sx={{ position: 'absolute', top: '8px', left: '76px' }}
314
- >
315
- <b>{formatFrenchVehiclePlate(vehicle.plate)}</b>
316
- </Typography>
317
- </Grid>
318
- {onDelete && <Grid item xs={6} style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
319
- <Button variant='contained' color='error' onClick={(e) => handleOnClickDeleteVehicle(e)}>
320
- Supprimer
321
- </Button>
322
- </Grid>}
323
- </Grid>
324
-
325
- {!localEditMode && <Grid container textAlign='justify' sx={{ pt: 2 }}>
326
- <Grid item xs={8} >
327
- <Typography variant="body1" color="text.secondary">
328
- Km actuel :
329
- </Typography>
330
- </Grid>
331
- <Grid item xs={4} sx={{ textAlign: 'right' }}>
332
- <Typography variant="body1" color="text.secondary">
333
- <b>{vehicle.currentMileage} km</b>
334
- </Typography>
335
- </Grid>
336
- </Grid>}
337
-
338
- {localEditMode && <Grid item xs={12}>
339
- <TextField
340
- label="Kilométrage actuel"
341
- name="currentMileage"
342
- variant="outlined"
343
- type="number"
344
- required
345
- value={form.currentMileage.value}
346
- onChange={(e) => handleInputChange(e)}
347
- error={(Boolean(form.currentMileage.error))}
348
- sx={{
349
- width: '100%',
350
- mt: 2,
351
- '& input': { textTransform: 'uppercase' } // CSS pour forcer les majuscules dans l'input
352
- }}
353
- helperText={Boolean(form.currentMileage.error && form.currentMileage.value > 0)
354
- ? form.currentMileage.error : "Sur votre tableau de bord 😉"}
355
- />
356
- </Grid>}
357
-
358
- {!localEditMode && <Grid container textAlign='justify' sx={{ pt: 2 }}>
359
- <Grid item xs={8} >
360
- <Typography variant="body1" color="text.secondary">
361
- Km moyen annuel :
362
- </Typography>
363
- </Grid>
364
- <Grid item xs={4} sx={{ textAlign: 'right' }}>
365
- <Typography variant="body1" color="text.secondary">
366
- <b>{vehicle.averageMileagePerYear} km</b>
367
- </Typography>
368
- </Grid>
369
- </Grid>}
370
-
371
- {localEditMode && <Grid item xs={12}>
372
- <FormControl fullWidth margin="normal" error={Boolean(form.averageMileagePerYear.error)}>
373
- <InputLabel id="averageMileagePerYear-label">Kilométrage moyen annuel</InputLabel>
374
- <Select
375
- labelId="averageMileagePerYear-label"
376
- id="averageMileagePerYear"
377
- name="averageMileagePerYear"
378
- value={form.averageMileagePerYear.value ?
379
- String(form.averageMileagePerYear.value) : ''}
380
- onChange={e => handleSelectChange(e)}
381
- label="Kilométrage moyen annuel"
382
- >
383
- <MenuItem value={5000}>5 000</MenuItem>
384
- <MenuItem value={10000}>10 000</MenuItem>
385
- <MenuItem value={15000}>15 000</MenuItem>
386
- <MenuItem value={20000}>20 000</MenuItem>
387
- <MenuItem value={25000}>25 000</MenuItem>
388
- <MenuItem value={30000}>30 000</MenuItem>
389
- <MenuItem value={50000}>50 000</MenuItem>
390
- <MenuItem value={75000}>75 000</MenuItem>
391
- <MenuItem value={100000}>100 000</MenuItem>
392
- <MenuItem value={999999}>+100 000</MenuItem>
393
- </Select>
394
- <FormHelperText>{form.averageMileagePerYear.error}</FormHelperText>
395
- </FormControl>
396
- </Grid>}
397
-
398
- {!localEditMode && <Grid container textAlign='justify' sx={{ pt: 2 }}>
399
- <Grid item xs={6}>
400
- <Typography variant="body1" color="text.secondary">
401
- Pneumatiques :
402
- </Typography>
403
- </Grid>
404
- <Grid item xs={6} sx={{ textAlign: 'right' }}>
405
- <Typography variant="body1" color="text.secondary">
406
- {isVehicleTireSizeDefined(vehicle) ? <b>{formatVehicleTire(vehicle.tireSize)}</b> : '-'}
407
- </Typography>
408
- </Grid>
409
- </Grid>}
410
-
411
- {localEditMode && <Grid item xs={12} sx={{ mt: 1 }}>
412
- <MovaVehicleTireField
413
- vehicleTire={form.tireSize.value}
414
- onChangeVehicleTire={handleOnChangeVehicleTire}
415
- />
416
- </Grid>}
417
-
418
- {!localEditMode && <Grid container textAlign='justify' sx={{ pt: 2 }}>
419
- <Grid item xs={8} >
420
- <Typography variant="body1" color="text.secondary">
421
- Dernier contrôle technique :
422
- </Typography>
423
- </Grid>
424
- <Grid item xs={4} sx={{ textAlign: 'right' }}>
425
- <Typography variant="body1" color="text.secondary">
426
- <b>{formatDateByTimezone(vehicle.lastInspectionDate, 'Europe/Paris', DateFormatTypes.SHORT_FORMAT_DATE) !== '' ? formatDateByTimezone(vehicle.lastInspectionDate, 'Europe/Paris', DateFormatTypes.SHORT_FORMAT_DATE) : '-'}</b>
427
- </Typography>
428
- </Grid>
429
- </Grid>}
430
-
431
- {localEditMode && <Grid item xs={12}>
432
- <FormControl fullWidth sx={{marginTop: 2}}>
433
- <DatePicker
434
- label={"Dernier contrôle technique"}
435
- name={'lastInspectionDate'}
436
- value={form.lastInspectionDate.value}
437
- format='dd/MM/yyyy'
438
- formatDensity='dense'
439
- views={['day']}
440
- displayWeekNumber
441
- onChange={(e)=>handleChange('lastInspectionDate',e)}
442
- />
443
- </FormControl>
444
- </Grid>}
445
-
446
- {!localEditMode && <Grid container textAlign='justify' sx={{ pt: 2 }}>
447
- <Grid item xs={8} >
448
- <Typography variant="body1" color="text.secondary">
449
- Dernier entretien :
450
- </Typography>
451
- </Grid>
452
- <Grid item xs={4} sx={{ textAlign: 'right' }}>
453
- <Typography variant="body1" color="text.secondary">
454
- <b>{formatDateByTimezone(vehicle.lastMaintenanceDate, 'Europe/Paris', DateFormatTypes.SHORT_FORMAT_DATE) !== '' ? formatDateByTimezone(vehicle.lastMaintenanceDate, 'Europe/Paris', DateFormatTypes.SHORT_FORMAT_DATE) : '-'}</b>
455
- </Typography>
456
- </Grid>
457
- </Grid>}
458
-
459
- {localEditMode && <Grid item xs={12}>
460
- <FormControl fullWidth sx={{marginTop: 2}}>
461
- <DatePicker
462
- label={"Dernier entretien"}
463
- name={'lastMaintenanceDate'}
464
- value={form.lastMaintenanceDate.value}
465
- format='dd/MM/yyyy'
466
- formatDensity='dense'
467
- views={['day']}
468
- displayWeekNumber
469
- onChange={(e)=>handleChange('lastMaintenanceDate',e)}
470
- />
471
- </FormControl>
472
- </Grid>}
473
-
474
-
475
-
476
- </Grid>
477
-
478
- {!localEditMode && <>
479
-
480
- <Grid item xs={12}>
481
- <Typography variant="h6" component="div" align="center" sx={{ mt: 3, mb: 1 }} color={darken(theme.palette.primary.main, 0.2)}>
482
- CARNET DU VÉHICULE
483
- </Typography>
484
- </Grid>
485
-
486
- {vehicle.documents && vehicle.documents?.map((invoice, index) => (
487
- <Grid container sx={{ justifyContent: 'space-between', alignItems: 'center' }} key={index + 1}>
488
- <Grid item xs={11} key={(index + 1) * 50} sx={{ textAlign: 'left' }} >
489
- <Tooltip title={invoice.originalFileName}>
490
- <Link color={darken('#F29ABA', 0.2)} href={invoice.fileSignedUrl} target="_blank" rel="noopener">
491
- <Typography variant="body1">
492
- {invoice.fileName}
493
- </Typography>
494
- </Link>
495
- </Tooltip>
496
- </Grid>
497
- <Grid item xs={1} key={(index + 1) * 100} sx={{ textAlign: 'right' }}>
498
- <IconButton disabled={!(invoice.ownerId.toString() == currentUser.id)} onClick={(e) => handleDeleteDocument(e, invoice?.id)}>
499
- <CloseIcon />
500
- </IconButton>
501
- </Grid>
502
- </Grid>
503
- ))}
504
-
505
- {/* * Les FACTURES du véhicule
435
+ <img
436
+ src={CatPlateBg}
437
+ alt="Plaque d'immatriculation"
438
+ style={{ height: "50px", position: "relative" }}
439
+ />
440
+ <Typography
441
+ variant="h6"
442
+ color={theme.palette.text.primary}
443
+ sx={{ position: "absolute", top: "8px", left: "76px" }}
444
+ >
445
+ <b>{formatFrenchVehiclePlate(vehicle.plate)}</b>
446
+ </Typography>
447
+ </Grid>
448
+ {onDelete && (
449
+ <Grid
450
+ item
451
+ xs={6}
452
+ style={{
453
+ display: "flex",
454
+ alignItems: "center",
455
+ justifyContent: "center",
456
+ }}
457
+ >
458
+ <Button
459
+ variant="contained"
460
+ color="error"
461
+ onClick={(e) => handleOnClickDeleteVehicle(e)}
462
+ >
463
+ Supprimer
464
+ </Button>
465
+ </Grid>
466
+ )}
467
+ </Grid>
468
+
469
+ {!localEditMode && (
470
+ <Grid container textAlign="justify" sx={{ pt: 2 }}>
471
+ <Grid item xs={8}>
472
+ <Typography variant="body1" color="text.secondary">
473
+ Km actuel :
474
+ </Typography>
475
+ </Grid>
476
+ <Grid item xs={4} sx={{ textAlign: "right" }}>
477
+ <Typography variant="body1" color="text.secondary">
478
+ <b>{vehicle.currentMileage} km</b>
479
+ </Typography>
480
+ </Grid>
481
+ </Grid>
482
+ )}
483
+
484
+ {localEditMode && (
485
+ <Grid item xs={12}>
486
+ <TextField
487
+ label="Kilométrage actuel"
488
+ name="currentMileage"
489
+ variant="outlined"
490
+ type="number"
491
+ required
492
+ value={form.currentMileage.value}
493
+ onChange={(e) => handleInputChange(e)}
494
+ error={Boolean(form.currentMileage.error)}
495
+ sx={{
496
+ width: "100%",
497
+ mt: 2,
498
+ "& input": { textTransform: "uppercase" }, // CSS pour forcer les majuscules dans l'input
499
+ }}
500
+ helperText={
501
+ Boolean(
502
+ form.currentMileage.error &&
503
+ form.currentMileage.value > 0
504
+ )
505
+ ? form.currentMileage.error
506
+ : "Sur votre tableau de bord 😉"
507
+ }
508
+ />
509
+ </Grid>
510
+ )}
511
+
512
+ {!localEditMode && (
513
+ <Grid container textAlign="justify" sx={{ pt: 2 }}>
514
+ <Grid item xs={8}>
515
+ <Typography variant="body1" color="text.secondary">
516
+ Km moyen annuel :
517
+ </Typography>
518
+ </Grid>
519
+ <Grid item xs={4} sx={{ textAlign: "right" }}>
520
+ <Typography variant="body1" color="text.secondary">
521
+ <b>{vehicle.averageMileagePerYear} km</b>
522
+ </Typography>
523
+ </Grid>
524
+ </Grid>
525
+ )}
526
+
527
+ {localEditMode && (
528
+ <Grid item xs={12}>
529
+ <FormControl
530
+ fullWidth
531
+ margin="normal"
532
+ error={Boolean(form.averageMileagePerYear.error)}
533
+ >
534
+ <InputLabel id="averageMileagePerYear-label">
535
+ Kilométrage moyen annuel
536
+ </InputLabel>
537
+ <Select
538
+ labelId="averageMileagePerYear-label"
539
+ id="averageMileagePerYear"
540
+ name="averageMileagePerYear"
541
+ value={
542
+ form.averageMileagePerYear.value
543
+ ? String(form.averageMileagePerYear.value)
544
+ : ""
545
+ }
546
+ onChange={(e) => handleSelectChange(e)}
547
+ label="Kilométrage moyen annuel"
548
+ >
549
+ <MenuItem value={5000}>5 000</MenuItem>
550
+ <MenuItem value={10000}>10 000</MenuItem>
551
+ <MenuItem value={15000}>15 000</MenuItem>
552
+ <MenuItem value={20000}>20 000</MenuItem>
553
+ <MenuItem value={25000}>25 000</MenuItem>
554
+ <MenuItem value={30000}>30 000</MenuItem>
555
+ <MenuItem value={50000}>50 000</MenuItem>
556
+ <MenuItem value={75000}>75 000</MenuItem>
557
+ <MenuItem value={100000}>100 000</MenuItem>
558
+ <MenuItem value={999999}>+100 000</MenuItem>
559
+ </Select>
560
+ <FormHelperText>
561
+ {form.averageMileagePerYear.error}
562
+ </FormHelperText>
563
+ </FormControl>
564
+ </Grid>
565
+ )}
566
+
567
+ {!localEditMode && (
568
+ <Grid container textAlign="justify" sx={{ pt: 2 }}>
569
+ <Grid item xs={6}>
570
+ <Typography variant="body1" color="text.secondary">
571
+ Pneumatiques :
572
+ </Typography>
573
+ </Grid>
574
+ <Grid item xs={6} sx={{ textAlign: "right" }}>
575
+ <Typography variant="body1" color="text.secondary">
576
+ {isVehicleTireSizeDefined(vehicle) ? (
577
+ <b>{formatVehicleTire(vehicle.tireSize)}</b>
578
+ ) : (
579
+ "-"
580
+ )}
581
+ </Typography>
582
+ </Grid>
583
+ </Grid>
584
+ )}
585
+
586
+ {localEditMode && (
587
+ <Grid item xs={12} sx={{ mt: 1 }}>
588
+ <MovaVehicleTireField
589
+ vehicleTire={form.tireSize.value}
590
+ onChangeVehicleTire={handleOnChangeVehicleTire}
591
+ />
592
+ </Grid>
593
+ )}
594
+
595
+ {!localEditMode && (
596
+ <Grid container textAlign="justify" sx={{ pt: 2 }}>
597
+ <Grid item xs={8}>
598
+ <Typography variant="body1" color="text.secondary">
599
+ Dernier contrôle technique :
600
+ </Typography>
601
+ </Grid>
602
+ <Grid item xs={4} sx={{ textAlign: "right" }}>
603
+ <Typography variant="body1" color="text.secondary">
604
+ <b>
605
+ {formatDateByTimezone(
606
+ vehicle.lastInspectionDate,
607
+ "Europe/Paris",
608
+ DateFormatTypes.SHORT_FORMAT_DATE
609
+ ) !== ""
610
+ ? formatDateByTimezone(
611
+ vehicle.lastInspectionDate,
612
+ "Europe/Paris",
613
+ DateFormatTypes.SHORT_FORMAT_DATE
614
+ )
615
+ : "-"}
616
+ </b>
617
+ </Typography>
618
+ </Grid>
619
+ </Grid>
620
+ )}
621
+
622
+ {localEditMode && (
623
+ <Grid item xs={12}>
624
+ <FormControl fullWidth sx={{ marginTop: 2 }}>
625
+ <DatePicker
626
+ label={"Dernier contrôle technique"}
627
+ name={"lastInspectionDate"}
628
+ value={form.lastInspectionDate.value}
629
+ format="dd/MM/yyyy"
630
+ formatDensity="dense"
631
+ views={["day"]}
632
+ displayWeekNumber
633
+ onChange={(e) => handleChange("lastInspectionDate", e)}
634
+ />
635
+ </FormControl>
636
+ </Grid>
637
+ )}
638
+
639
+ {!localEditMode && (
640
+ <Grid container textAlign="justify" sx={{ pt: 2 }}>
641
+ <Grid item xs={8}>
642
+ <Typography variant="body1" color="text.secondary">
643
+ Dernier entretien :
644
+ </Typography>
645
+ </Grid>
646
+ <Grid item xs={4} sx={{ textAlign: "right" }}>
647
+ <Typography variant="body1" color="text.secondary">
648
+ <b>
649
+ {formatDateByTimezone(
650
+ vehicle.lastMaintenanceDate,
651
+ "Europe/Paris",
652
+ DateFormatTypes.SHORT_FORMAT_DATE
653
+ ) !== ""
654
+ ? formatDateByTimezone(
655
+ vehicle.lastMaintenanceDate,
656
+ "Europe/Paris",
657
+ DateFormatTypes.SHORT_FORMAT_DATE
658
+ )
659
+ : "-"}
660
+ </b>
661
+ </Typography>
662
+ </Grid>
663
+ </Grid>
664
+ )}
665
+
666
+ {localEditMode && (
667
+ <Grid item xs={12}>
668
+ <FormControl fullWidth sx={{ marginTop: 2 }}>
669
+ <DatePicker
670
+ label={"Dernier entretien"}
671
+ name={"lastMaintenanceDate"}
672
+ value={form.lastMaintenanceDate.value}
673
+ format="dd/MM/yyyy"
674
+ formatDensity="dense"
675
+ views={["day"]}
676
+ displayWeekNumber
677
+ onChange={(e) => handleChange("lastMaintenanceDate", e)}
678
+ />
679
+ </FormControl>
680
+ </Grid>
681
+ )}
682
+ </Grid>
683
+
684
+ {!localEditMode && (
685
+ <>
686
+ <Grid item xs={12}>
687
+ <Typography
688
+ variant="h6"
689
+ component="div"
690
+ align="center"
691
+ sx={{ mt: 3, mb: 1 }}
692
+ color={darken(theme.palette.primary.main, 0.2)}
693
+ >
694
+ CARNET DU VÉHICULE
695
+ </Typography>
696
+ </Grid>
697
+
698
+ {vehicle.documents &&
699
+ vehicle.documents?.map((invoice, index) => (
700
+ <Grid
701
+ container
702
+ sx={{
703
+ justifyContent: "space-between",
704
+ alignItems: "center",
705
+ }}
706
+ key={index + 1}
707
+ >
708
+ <Grid
709
+ item
710
+ xs={11}
711
+ key={(index + 1) * 50}
712
+ sx={{ textAlign: "left" }}
713
+ >
714
+ <Tooltip title={invoice.originalFileName}>
715
+ <Link
716
+ color={darken("#F29ABA", 0.2)}
717
+ href={invoice.fileSignedUrl}
718
+ target="_blank"
719
+ rel="noopener"
720
+ >
721
+ <Typography variant="body1">
722
+ {invoice.fileName}
723
+ </Typography>
724
+ </Link>
725
+ </Tooltip>
726
+ </Grid>
727
+ <Grid
728
+ item
729
+ xs={1}
730
+ key={(index + 1) * 100}
731
+ sx={{ textAlign: "right" }}
732
+ >
733
+ <IconButton
734
+ disabled={
735
+ !(invoice.ownerId.toString() == currentUser.id)
736
+ }
737
+ onClick={(e) => handleDeleteDocument(e, invoice?.id)}
738
+ >
739
+ <CloseIcon />
740
+ </IconButton>
741
+ </Grid>
742
+ </Grid>
743
+ ))}
744
+
745
+ {/* * Les FACTURES du véhicule
506
746
  {vehicle.documents && vehicle.documents?.filter(doc => doc.type === DocumentType.VEHICLE_MAINTENANCE_INVOICE)
507
747
  .map((invoice, index) => (
508
748
  <Grid container sx={{ justifyContent: 'space-between', alignItems: 'center' }} key={index+1}>
@@ -539,89 +779,137 @@ const VehicleFullCard: FC<VehicleFullCardProps> = ({ vehicle, fullwidth, onError
539
779
  </Grid>
540
780
  ))} */}
541
781
 
542
- <Grid container >
543
- <Grid item xs={12} sx={{ mt: 2, textAlign: 'center' }} >
544
- <div>
545
- <input
546
- accept="image/*, application/pdf"
547
- type="file"
548
- style={{ display: 'none' }}
549
- ref={invoiceInputRef}
550
- id="raised-button-invoice"
551
- onChange={(e) => handleFileChange(e, docTypeCurrent.current!)}
552
- />
553
- <Button size='large' disabled={currentUpload} onClick={() => setShowLinkedDocument(true)} component="span" variant="outlined" startIcon={<AttachFile />}
554
- sx={{ alignItems: 'center', width: '90%', mt: 2, mb: 1, height: '50px', p: 1, color: darken(theme.palette.primary.main, 0.2) }}>
555
-
556
- Ajouter un document
557
-
558
- </Button>
559
- {currentUpload && <Typography variant='body2' sx={{ animation: 'blink 1.5s infinite' }}>
560
- Document en cours d'importation...
561
- </Typography>}
562
- {sizeLimit && <Typography
563
- variant='body1'
564
- sx={{ animation: 'blink 1.5s infinite' }}
565
- color={theme.palette.warning.dark}
566
- >Echec de l'importation car la taille du fichier dépasse 10Mo</Typography>}
567
- {!sizeLimit && <Typography variant='body2'>
568
- Taille maximale du fichier : 10Mo
569
- </Typography>}
570
- </div>
571
- </Grid>
572
- </Grid>
573
- </>
574
- }
575
-
576
- </CardContent>
577
-
578
- <CardActions sx={{ mt: 3, justifyContent: localEditMode ? 'center' : 'end' }}>
579
- {!localEditMode &&
580
- <>
581
- <Button onClick={handleOnClickEdit} color="inherit" sx={{ width: '45%' }} variant='text'>
582
- <EditIcon sx={{ mr: 1 }} />MODIFIER
583
- </Button>
584
- </>
782
+ <Grid container>
783
+ <Grid item xs={12} sx={{ mt: 2, textAlign: "center" }}>
784
+ <div>
785
+ <input
786
+ accept="image/*, application/pdf"
787
+ type="file"
788
+ style={{ display: "none" }}
789
+ ref={invoiceInputRef}
790
+ id="raised-button-invoice"
791
+ onChange={(e) =>
792
+ handleFileChange(e, docTypeCurrent.current!)
585
793
  }
586
-
587
- {localEditMode &&
588
- <>
589
- <Button onClick={handleOnClickCancel} sx={{ width: '45%', color: theme.palette.text.secondary }} variant='text'>
590
- <CancelIcon sx={{ mr: 1 }} />ANNULER
591
- </Button>
592
-
593
- <Button onClick={handleOnClickValidate} sx={{ width: '45%', color: darken(theme.palette.primary.main, 0.2) }} variant='text'>
594
- <EditIcon sx={{ mr: 1 }} />VALIDER
595
- </Button>
596
- </>
597
- }
598
- </CardActions>
599
-
600
- </Card>
601
- }
602
- {isShowLinkedDocument && <LinkedDocumentDialog
603
- isVehicle={true}
604
- isShowLinkedDocument={isShowLinkedDocument}
605
- appType={appType}
606
- toggleShowLinkedDocument={toggleShowLinkedDocument}
607
- message={messageRGPD}
608
- />}
609
-
610
- <ConfirmationDialog
611
- open={openConfirmDocumentDelete}
612
- onClose={handleCloseConfirmDocumentDelete}
613
- onConfirm={handleConfirmDocumentDelete}
614
- message="Êtes-vous sûr de vouloir supprimer ce document ?"
615
- />
616
-
617
- <ConfirmationDialog
618
- open={openConfirmVehicleDelete}
619
- onClose={handleCloseConfirmVehicleDelete}
620
- onConfirm={handleConfirmVehicleDelete}
621
- message="Êtes-vous sûr de vouloir supprimer ce véhicule ?"
622
- />
623
- </>
624
- );
625
- }
794
+ />
795
+ <Button
796
+ size="large"
797
+ disabled={currentUpload}
798
+ onClick={() => setShowLinkedDocument(true)}
799
+ component="span"
800
+ variant="outlined"
801
+ startIcon={<AttachFile />}
802
+ sx={{
803
+ alignItems: "center",
804
+ width: "90%",
805
+ mt: 2,
806
+ mb: 1,
807
+ height: "50px",
808
+ p: 1,
809
+ color: darken(theme.palette.primary.main, 0.2),
810
+ }}
811
+ >
812
+ Ajouter un document
813
+ </Button>
814
+ {currentUpload && (
815
+ <Typography
816
+ variant="body2"
817
+ sx={{ animation: "blink 1.5s infinite" }}
818
+ >
819
+ Document en cours d'importation...
820
+ </Typography>
821
+ )}
822
+ {sizeLimit && (
823
+ <Typography
824
+ variant="body1"
825
+ sx={{ animation: "blink 1.5s infinite" }}
826
+ color={theme.palette.warning.dark}
827
+ >
828
+ Echec de l'importation car la taille du fichier
829
+ dépasse 10Mo
830
+ </Typography>
831
+ )}
832
+ {!sizeLimit && (
833
+ <Typography variant="body2">
834
+ Taille maximale du fichier : 10Mo
835
+ </Typography>
836
+ )}
837
+ </div>
838
+ </Grid>
839
+ </Grid>
840
+ </>
841
+ )}
842
+ </CardContent>
843
+
844
+ <CardActions
845
+ sx={{ mt: 3, justifyContent: localEditMode ? "center" : "end" }}
846
+ >
847
+ {!localEditMode && (
848
+ <>
849
+ <Button
850
+ onClick={handleOnClickEdit}
851
+ color="inherit"
852
+ sx={{ width: "45%" }}
853
+ variant="text"
854
+ >
855
+ <EditIcon sx={{ mr: 1 }} />
856
+ MODIFIER
857
+ </Button>
858
+ </>
859
+ )}
860
+
861
+ {localEditMode && (
862
+ <>
863
+ <Button
864
+ onClick={handleOnClickCancel}
865
+ sx={{ width: "45%", color: theme.palette.text.secondary }}
866
+ variant="text"
867
+ >
868
+ <CancelIcon sx={{ mr: 1 }} />
869
+ ANNULER
870
+ </Button>
871
+
872
+ <Button
873
+ onClick={handleOnClickValidate}
874
+ sx={{
875
+ width: "45%",
876
+ color: darken(theme.palette.primary.main, 0.2),
877
+ }}
878
+ variant="text"
879
+ >
880
+ <EditIcon sx={{ mr: 1 }} />
881
+ VALIDER
882
+ </Button>
883
+ </>
884
+ )}
885
+ </CardActions>
886
+ </Card>
887
+ )}
888
+ {isShowLinkedDocument && (
889
+ <LinkedDocumentDialog
890
+ isVehicle={true}
891
+ isShowLinkedDocument={isShowLinkedDocument}
892
+ appType={appType}
893
+ toggleShowLinkedDocument={toggleShowLinkedDocument}
894
+ message={messageRGPD}
895
+ />
896
+ )}
897
+
898
+ <ConfirmationDialog
899
+ open={openConfirmDocumentDelete}
900
+ onClose={handleCloseConfirmDocumentDelete}
901
+ onConfirm={handleConfirmDocumentDelete}
902
+ message="Êtes-vous sûr de vouloir supprimer ce document ?"
903
+ />
904
+
905
+ <ConfirmationDialog
906
+ open={openConfirmVehicleDelete}
907
+ onClose={handleCloseConfirmVehicleDelete}
908
+ onConfirm={handleConfirmVehicleDelete}
909
+ message="Êtes-vous sûr de vouloir supprimer ce véhicule ?"
910
+ />
911
+ </>
912
+ );
913
+ };
626
914
 
627
915
  export default VehicleFullCard;