mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(tours): say why a tour over a day cannot be saved
A tour whose walking time and breaks came to more than 24 hours a stage only greyed out Save, with nothing saying why. The planner now marks the planned total and says what to do: make it a multi-day tour by ending a stage at a stop, or enter a shorter planned total. The details section opens by itself so the reason is in sight. Closes #2869
This commit is contained in:
@@ -212,7 +212,7 @@ function TourTimeFields({ planner, locked }: TourFieldProps) {
|
||||
id="tour-planner-planned-duration"
|
||||
label={t('tours.planner.plannedTotalDuration')}
|
||||
value={planner.plannedDurationMinutes ?? planner.plannedTotalMinutes}
|
||||
invalid={planner.plannedDurationInvalid}
|
||||
invalid={planner.plannedDurationInvalid || planner.plannedTotalInvalid}
|
||||
errorId="tour-planner-planned-duration-error"
|
||||
locked={locked}
|
||||
onCommit={planner.setPlannedDurationMinutes}
|
||||
@@ -220,6 +220,10 @@ function TourTimeFields({ planner, locked }: TourFieldProps) {
|
||||
{planner.plannedDurationInvalid && (
|
||||
<FieldError id="tour-planner-planned-duration-error">{t('tours.planner.timeValueInvalid')}</FieldError>
|
||||
)}
|
||||
{/* #2869: over a day a stage Save waits, and says why rather than only greying out. */}
|
||||
{!planner.plannedDurationInvalid && planner.plannedTotalInvalid && (
|
||||
<FieldError id="tour-planner-planned-duration-error">{t('tours.planner.plannedTotalOverDay')}</FieldError>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -337,7 +341,11 @@ export function TourDetailsSection({
|
||||
}: TourFieldProps & { onDifficultyChange: (value: Difficulty) => void }) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(readDetailsOpen);
|
||||
const forcedOpen = planner.websiteInvalid || planner.plannedDurationInvalid || planner.breakAdditionalInvalid;
|
||||
const forcedOpen =
|
||||
planner.websiteInvalid ||
|
||||
planner.plannedDurationInvalid ||
|
||||
planner.breakAdditionalInvalid ||
|
||||
planner.plannedTotalInvalid;
|
||||
const expanded = open || forcedOpen;
|
||||
const toggle = () => {
|
||||
const next = !expanded;
|
||||
|
||||
@@ -526,6 +526,18 @@ describe('TourPlannerRail', () => {
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Enter a whole value from 0 to 1,440 minutes.')
|
||||
})
|
||||
|
||||
it('says why Save waits on a tour over a day a stage, and opens the details to say it (#2869)', () => {
|
||||
window.localStorage.clear()
|
||||
render(<TourPlannerRail planner={planner({
|
||||
mode: { type: 'new-draft' }, hasUnsavedChanges: true, canSave: false,
|
||||
walkingDurationMinutes: 1500, plannedTotalMinutes: 1500, plannedTotalInvalid: true,
|
||||
})} />)
|
||||
expect(screen.getByLabelText(/Planned total duration/)).toHaveAttribute('aria-invalid', 'true')
|
||||
expect(screen.getByRole('alert')).toHaveTextContent(
|
||||
'Walking time and breaks add up to more than 24 hours a day. Make it a multi-day tour with “End stage here” at a stop, or enter a shorter planned total.',
|
||||
)
|
||||
})
|
||||
|
||||
it('RS-02: Info controls are keyboard focusable and explain themselves only through the shared tooltip', async () => {
|
||||
render(<TourPlannerRail planner={planner({
|
||||
mode: { type: 'new-draft' }, hasUnsavedChanges: true, walkingDurationMinutes: 80,
|
||||
|
||||
Reference in New Issue
Block a user