pcm-shared-components 2.1.384 → 2.1.386
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,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { TextField, Icon, IconButton, Button, Paper, Typography, InputAdornment, MenuItem, ToggleButton, ToggleButtonGroup, Checkbox, ListItemText, Chip, Alert } from '@mui/material';
|
|
3
|
+
import { TextField, Icon, IconButton, Button, Paper, Typography, InputAdornment, MenuItem, ToggleButton, ToggleButtonGroup, Checkbox, ListItemText, Chip, Alert, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions } from '@mui/material';
|
|
4
4
|
import { ThemeProvider } from '@mui/system';
|
|
5
5
|
import { createTheme, useTheme, alpha } from '@mui/material/styles';
|
|
6
6
|
import AddIcon from '@mui/icons-material/Add';
|
|
@@ -23,7 +23,9 @@ const KEYS = {
|
|
|
23
23
|
requiredInformation: 'animal.required_information',
|
|
24
24
|
missingCount: 'animal.missing_count',
|
|
25
25
|
needsInformation: 'animal.needs_information',
|
|
26
|
-
maxReached: 'occupant_vehicle.max_animal'
|
|
26
|
+
maxReached: 'occupant_vehicle.max_animal',
|
|
27
|
+
removeConfirmTitle: 'animal.remove_confirm_title',
|
|
28
|
+
removeConfirmMessage: 'animal.remove_confirm_message'
|
|
27
29
|
},
|
|
28
30
|
vehicle: {
|
|
29
31
|
sectionTitle: 'client_vehicle.client_vehicle_title',
|
|
@@ -33,7 +35,9 @@ const KEYS = {
|
|
|
33
35
|
requiredInformation: 'client_vehicle.required_information',
|
|
34
36
|
missingCount: 'client_vehicle.missing_count',
|
|
35
37
|
needsInformation: 'client_vehicle.needs_information',
|
|
36
|
-
maxReached: 'occupant_vehicle.max_vehicle'
|
|
38
|
+
maxReached: 'occupant_vehicle.max_vehicle',
|
|
39
|
+
removeConfirmTitle: 'client_vehicle.remove_confirm_title',
|
|
40
|
+
removeConfirmMessage: 'client_vehicle.remove_confirm_message'
|
|
37
41
|
}
|
|
38
42
|
};
|
|
39
43
|
|
|
@@ -88,6 +92,26 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
88
92
|
const keys = KEYS[itemType] || KEYS.animal;
|
|
89
93
|
const requiredErrorText = fieldType => i18next.t(REQUIRED_ERROR_KEY_BY_TYPE[fieldType] || 'animal.required_error');
|
|
90
94
|
const missingRequiredFields = item => fieldConfig.filter(f => f.required).filter(f => !isFieldAnswered(f.type, item.values?.[f.key] ?? (f.type === 'select_multiple' ? [] : '')));
|
|
95
|
+
|
|
96
|
+
// Any field answered (not just required ones) -- an optional field someone bothered to fill in
|
|
97
|
+
// is still real data that'd be silently thrown away by a bare-click delete.
|
|
98
|
+
const hasAnyData = item => fieldConfig.some(f => isFieldAnswered(f.type, item.values?.[f.key] ?? (f.type === 'select_multiple' ? [] : '')));
|
|
99
|
+
|
|
100
|
+
// Removing an item that actually has data goes through a confirmation step first; an empty one
|
|
101
|
+
// (nothing entered yet) is removed immediately, same as before -- no point prompting when
|
|
102
|
+
// there's nothing to lose.
|
|
103
|
+
const [pendingRemoveId, setPendingRemoveId] = useState(null);
|
|
104
|
+
const requestRemove = item => {
|
|
105
|
+
if (hasAnyData(item)) {
|
|
106
|
+
setPendingRemoveId(item.id);
|
|
107
|
+
} else {
|
|
108
|
+
onRemoveItem(item.id);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const confirmRemove = () => {
|
|
112
|
+
onRemoveItem(pendingRemoveId);
|
|
113
|
+
setPendingRemoveId(null);
|
|
114
|
+
};
|
|
91
115
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
92
116
|
// Growing the list (Add) jumps to the newly-added last item, since that's the one the host just
|
|
93
117
|
// asked for and the one that needs filling in. Shrinking it (Remove) just clamps the current
|
|
@@ -140,9 +164,13 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
140
164
|
gap: 6
|
|
141
165
|
}
|
|
142
166
|
}, itemType === 'vehicle' ? /*#__PURE__*/React.createElement(Icon, {
|
|
143
|
-
|
|
167
|
+
sx: {
|
|
168
|
+
color: 'info.main'
|
|
169
|
+
}
|
|
144
170
|
}, "drive_eta") : /*#__PURE__*/React.createElement(Icon, {
|
|
145
|
-
|
|
171
|
+
sx: {
|
|
172
|
+
color: 'success.main'
|
|
173
|
+
}
|
|
146
174
|
}, "pets"), /*#__PURE__*/React.createElement(Typography, {
|
|
147
175
|
sx: {
|
|
148
176
|
fontWeight: 700
|
|
@@ -220,7 +248,7 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
220
248
|
}, i18next.t(keys.requiredInformation))), /*#__PURE__*/React.createElement(IconButton, {
|
|
221
249
|
size: "small",
|
|
222
250
|
color: "error",
|
|
223
|
-
onClick: () =>
|
|
251
|
+
onClick: () => requestRemove(selectedItem)
|
|
224
252
|
}, /*#__PURE__*/React.createElement(DeleteOutlineIcon, {
|
|
225
253
|
fontSize: "small"
|
|
226
254
|
}))), /*#__PURE__*/React.createElement("div", {
|
|
@@ -228,7 +256,8 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
228
256
|
className: "grid grid-cols-2",
|
|
229
257
|
style: {
|
|
230
258
|
columnGap: 12,
|
|
231
|
-
rowGap: 16
|
|
259
|
+
rowGap: 16,
|
|
260
|
+
gridAutoFlow: 'row dense'
|
|
232
261
|
}
|
|
233
262
|
}, fieldConfig.map(field => {
|
|
234
263
|
const value = selectedItem.values?.[field.key] ?? '';
|
|
@@ -422,7 +451,18 @@ export const AnimalVehicleDetailsEditor = props => {
|
|
|
422
451
|
}, i18next.t(keys.needsInformation, {
|
|
423
452
|
count: incompleteCount
|
|
424
453
|
}));
|
|
425
|
-
})()
|
|
454
|
+
})(), /*#__PURE__*/React.createElement(Dialog, {
|
|
455
|
+
open: pendingRemoveId !== null,
|
|
456
|
+
onClose: () => setPendingRemoveId(null),
|
|
457
|
+
maxWidth: "xs",
|
|
458
|
+
fullWidth: true
|
|
459
|
+
}, /*#__PURE__*/React.createElement(DialogTitle, null, i18next.t(keys.removeConfirmTitle)), /*#__PURE__*/React.createElement(DialogContent, null, /*#__PURE__*/React.createElement(DialogContentText, null, i18next.t(keys.removeConfirmMessage))), /*#__PURE__*/React.createElement(DialogActions, null, /*#__PURE__*/React.createElement(Button, {
|
|
460
|
+
onClick: () => setPendingRemoveId(null)
|
|
461
|
+
}, i18next.t('common.app.cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
462
|
+
color: "error",
|
|
463
|
+
variant: "contained",
|
|
464
|
+
onClick: confirmRemove
|
|
465
|
+
}, i18next.t('common.app.remove'))))));
|
|
426
466
|
};
|
|
427
467
|
AnimalVehicleDetailsEditor.defaultProps = {
|
|
428
468
|
items: [],
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"needs_information": "{{count}} animal needs information",
|
|
35
35
|
"needs_information_plural": "{{count}} animals need information",
|
|
36
36
|
"complete_required_fields": "Complete {{count}} required field",
|
|
37
|
-
"complete_required_fields_plural": "Complete {{count}} required fields"
|
|
37
|
+
"complete_required_fields_plural": "Complete {{count}} required fields",
|
|
38
|
+
"remove_confirm_title": "Remove this animal?",
|
|
39
|
+
"remove_confirm_message": "All information entered for this animal will be lost. This can't be undone."
|
|
38
40
|
},
|
|
39
41
|
"app": {
|
|
40
42
|
"common": {
|
|
@@ -572,7 +574,9 @@
|
|
|
572
574
|
"needs_information": "{{count}} vehicle needs information",
|
|
573
575
|
"needs_information_plural": "{{count}} vehicles need information",
|
|
574
576
|
"complete_required_fields": "Complete {{count}} required field",
|
|
575
|
-
"complete_required_fields_plural": "Complete {{count}} required fields"
|
|
577
|
+
"complete_required_fields_plural": "Complete {{count}} required fields",
|
|
578
|
+
"remove_confirm_title": "Remove this vehicle?",
|
|
579
|
+
"remove_confirm_message": "All information entered for this vehicle will be lost. This can't be undone."
|
|
576
580
|
},
|
|
577
581
|
"common": {
|
|
578
582
|
"app": {
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"needs_information": "{{count}} animal necesita información",
|
|
35
35
|
"needs_information_plural": "{{count}} animales necesitan información",
|
|
36
36
|
"complete_required_fields": "Complete {{count}} campo requerido",
|
|
37
|
-
"complete_required_fields_plural": "Complete {{count}} campos requeridos"
|
|
37
|
+
"complete_required_fields_plural": "Complete {{count}} campos requeridos",
|
|
38
|
+
"remove_confirm_title": "¿Eliminar este animal?",
|
|
39
|
+
"remove_confirm_message": "Toda la información ingresada para este animal se perderá. Esto no se puede deshacer."
|
|
38
40
|
},
|
|
39
41
|
"app": {
|
|
40
42
|
"common": {
|
|
@@ -572,7 +574,9 @@
|
|
|
572
574
|
"needs_information": "{{count}} vehículo necesita información",
|
|
573
575
|
"needs_information_plural": "{{count}} vehículos necesitan información",
|
|
574
576
|
"complete_required_fields": "Complete {{count}} campo requerido",
|
|
575
|
-
"complete_required_fields_plural": "Complete {{count}} campos requeridos"
|
|
577
|
+
"complete_required_fields_plural": "Complete {{count}} campos requeridos",
|
|
578
|
+
"remove_confirm_title": "¿Eliminar este vehículo?",
|
|
579
|
+
"remove_confirm_message": "Toda la información ingresada para este vehículo se perderá. Esto no se puede deshacer."
|
|
576
580
|
},
|
|
577
581
|
"common": {
|
|
578
582
|
"app": {
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"needs_information": "{{count}} animal nécessite des informations",
|
|
35
35
|
"needs_information_plural": "{{count}} animaux nécessitent des informations",
|
|
36
36
|
"complete_required_fields": "Complétez {{count}} champ requis",
|
|
37
|
-
"complete_required_fields_plural": "Complétez {{count}} champs requis"
|
|
37
|
+
"complete_required_fields_plural": "Complétez {{count}} champs requis",
|
|
38
|
+
"remove_confirm_title": "Supprimer cet animal ?",
|
|
39
|
+
"remove_confirm_message": "Toutes les informations saisies pour cet animal seront perdues. Cela ne peut pas être annulé."
|
|
38
40
|
},
|
|
39
41
|
"app": {
|
|
40
42
|
"common": {
|
|
@@ -572,7 +574,9 @@
|
|
|
572
574
|
"needs_information": "{{count}} véhicule nécessite des informations",
|
|
573
575
|
"needs_information_plural": "{{count}} véhicules nécessitent des informations",
|
|
574
576
|
"complete_required_fields": "Complétez {{count}} champ requis",
|
|
575
|
-
"complete_required_fields_plural": "Complétez {{count}} champs requis"
|
|
577
|
+
"complete_required_fields_plural": "Complétez {{count}} champs requis",
|
|
578
|
+
"remove_confirm_title": "Supprimer ce véhicule ?",
|
|
579
|
+
"remove_confirm_message": "Toutes les informations saisies pour ce véhicule seront perdues. Cela ne peut pas être annulé."
|
|
576
580
|
},
|
|
577
581
|
"common": {
|
|
578
582
|
"app": {
|