Skip to content

Commit 182869d

Browse files
committed
front: add error messages for missing path steps in new itinerary modal
Signed-off-by: Theo Macron <theo.macron0315@gmail.com>
1 parent ad23347 commit 182869d

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

front/public/locales/en/operational-studies.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@
410410
"itineraryModal": {
411411
"addLocationOnMap": "Add a location on the map",
412412
"alertInvalidOP": "At least one of the waypoints could not be recognized",
413+
"alertMissingDestination": "Destination is not defined",
414+
"alertMissingOrigin": "Origin is not defined",
415+
"alertMissingRequestedPoint": "At least two path steps are required to define an itinerary",
413416
"cancel": "Cancel",
414417
"focusLocationOnMap": "Focus the map on this operational point",
415418
"frameAll": "Center on all path steps on map",

front/public/locales/fr/operational-studies.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@
410410
"itineraryModal": {
411411
"addLocationOnMap": "Ajouter un point remarquable sur la carte",
412412
"alertInvalidOP": "Au moins un des points de passage n'a pas été reconnu",
413+
"alertMissingDestination": "La destination n'est pas définie",
414+
"alertMissingOrigin": "L'origine n'est pas définie",
415+
"alertMissingRequestedPoint": "Il faut au minimum deux points de passage pour définir un itinéraire",
413416
"cancel": "Annuler",
414417
"focusLocationOnMap": "Centrer la carte sur ce point remarquable",
415418
"frameAll": "Centrer sur tous les points de passage sur la carte",

front/src/applications/operationalStudies/views/Scenario/components/ManageTimetableItem/Itinerary/ItineraryModal.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const ItineraryModal = ({
8080

8181
const [pathSteps, setPathSteps] = useState<PathStepV2[]>([]);
8282
const [categoryWarning, setCategoryWarning] = useState<string | undefined>(undefined);
83+
const [alertBoxWiggle, setAlertBoxWiggle] = useState(0);
8384

8485
const [hoveredGapIndex, setHoveredGapIndex] = useState<number | null>(null);
8586

@@ -364,10 +365,9 @@ const ItineraryModal = ({
364365

365366
const submitItinerary = () => {
366367
setSubmitAttempted(true);
368+
setAlertBoxWiggle((c) => c + 1);
367369
if (isNameEmpty) return;
368-
if (locatedStepsCount < 2) {
369-
return;
370-
}
370+
if (locatedStepsCount < 2) return;
371371

372372
const filledSteps = pathSteps.filter((step) => !isEmptyStep(step, getInputForStep(step.id)));
373373
if (filledSteps.length < 2) return;
@@ -416,9 +416,29 @@ const ItineraryModal = ({
416416
</div>
417417
<div className="itinerary-modal-form-body">
418418
{categoryWarning && <AlertBox message={categoryWarning} closeable />}
419-
{hasInvalidPathStepDisplay && <AlertBox type="error" message={t('alertInvalidOP')} />}
419+
{hasInvalidPathStepDisplay && (
420+
<div key={`invalid-op-${alertBoxWiggle}`}>
421+
<AlertBox type="error" message={t('alertInvalidOP')} />
422+
</div>
423+
)}
420424
{!hasInvalidPathStepDisplay && pathfindingError && (
421-
<AlertBox type="error" message={pathfindingError} />
425+
<div key={`pathfinding-${alertBoxWiggle}`}>
426+
<AlertBox type="error" message={pathfindingError} />
427+
</div>
428+
)}
429+
{submitAttempted && (!pathSteps[0]?.location || locatedStepsCount < 2) && (
430+
<div key={`missing-step-${alertBoxWiggle}`}>
431+
<AlertBox
432+
type="error"
433+
message={t(
434+
!pathSteps[0]?.location && locatedStepsCount < 2
435+
? 'alertMissingRequestedPoint'
436+
: !pathSteps[0]?.location
437+
? 'alertMissingOrigin'
438+
: 'alertMissingDestination'
439+
)}
440+
/>
441+
</div>
422442
)}
423443
<TypeAndPath rollingStockId={rollingStockId} isInNewModal />
424444
<div className="path-step-list">

front/src/styles/scss/applications/operationalStudies/_itineraryModal.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
@use './scenario';
22

3+
@keyframes wiggle {
4+
0% {
5+
transform: translateX(0);
6+
}
7+
25% {
8+
transform: translateX(5px);
9+
}
10+
50% {
11+
transform: translateX(-5px);
12+
}
13+
75% {
14+
transform: translateX(5px);
15+
}
16+
100% {
17+
transform: translateX(0);
18+
}
19+
}
20+
321
.itinerary-modal {
422
--header-height: 164px;
523
--footer-height: 96px;
@@ -121,6 +139,7 @@
121139

122140
.alert-box {
123141
margin-top: -1px;
142+
animation: wiggle 0.4s ease-in;
124143
}
125144

126145
.path-step-list {

0 commit comments

Comments
 (0)