feat(settings): every date picker starts its week on the day you pick

Settings > General > Language & region gets "Week starts on" (Monday,
Sunday or Saturday), and Admin > User Defaults a default for everyone who
has not picked one. Monday stays the built-in value, so nothing changes
for anyone who leaves it alone.

Both calendar implementations follow it: CustomDatePicker, used by trip
dates, bookings, costs, to-dos and the admin school holidays on desktop
and phone, and the journey date picker, whose weekday headers were
hardcoded English and now speak the app language. The grid math and the
header row live in one helper (utils/calendarWeek.ts). The day names on
the options come from Intl, so only the label and a hint needed
translating. Vacay keeps its own per-plan week start.

The value is validated like the other regional settings: VALID_VALUES for
admin defaults, the display-settings MCP tool, and the managed key list.

Addresses discussion #2029.
This commit is contained in:
Maurice
2026-09-24 21:56:10 +02:00
parent 196dc12762
commit 7ce31756a3
84 changed files with 511 additions and 106 deletions
@@ -1,4 +1,4 @@
// FE-COMP-DISPLAY-001 to FE-COMP-DISPLAY-052
// FE-COMP-DISPLAY-001 to FE-COMP-DISPLAY-054
import { render, screen, within, fireEvent } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
@@ -444,3 +444,32 @@ describe('DisplaySettingsTab – startup destination', () => {
expect(await screen.findByText('Start locked')).toBeInTheDocument();
});
});
// ── Week start (053, 054) ─────────────────────────────────────────────────────
describe('DisplaySettingsTab week start (#2029)', () => {
it('FE-COMP-DISPLAY-053: shows Monday when unset and saves the day picked', async () => {
const user = userEvent.setup();
const updateSetting = vi.fn().mockResolvedValue(undefined);
seedStore(useSettingsStore, { settings: buildSettings({ week_start: undefined }), updateSetting });
render(<DisplaySettingsTab />);
expect(screen.getByText('Week starts on')).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: /Monday/ }));
await user.click(await screen.findByText('Sunday'));
expect(updateSetting).toHaveBeenCalledWith('week_start', 'sunday');
});
it('FE-COMP-DISPLAY-054: a rejected change surfaces the error', async () => {
const user = userEvent.setup();
const updateSetting = vi.fn().mockRejectedValue(new Error('Save failed'));
seedStore(useSettingsStore, { settings: buildSettings({ week_start: 'sunday' }), updateSetting });
render(<><ToastContainer /><DisplaySettingsTab /></>);
await user.click(screen.getByRole('button', { name: /Sunday/ }));
await user.click(await screen.findByText('Saturday'));
expect(await screen.findByText('Save failed')).toBeInTheDocument();
});
});
@@ -9,10 +9,12 @@ import Section from './Section'
import { TRIP_TAB_IDS, TRIP_TAB_LABEL_KEYS } from '../../constants/tripTabs'
import { DEFAULT_START_PAGE, DEFAULT_START_TRIP_TAB } from '../../utils/startDestination'
import type { DistanceUnit } from '../../types'
import { DEFAULT_WEEK_START } from '@trek/shared'
import { weekStartOptions } from '../../utils/calendarWeek'
export default function DisplaySettingsTab(): React.ReactElement {
const { settings, updateSetting } = useSettingsStore()
const { t } = useTranslation()
const { t, locale } = useTranslation()
const toast = useToast()
const [tempUnit, setTempUnit] = useState<string>(settings.temperature_unit || DEFAULT_SETTINGS.temperature_unit)
const [distanceUnit, setDistanceUnit] = useState<DistanceUnit>(settings.distance_unit || DEFAULT_SETTINGS.distance_unit)
@@ -285,6 +287,20 @@ export default function DisplaySettingsTab(): React.ReactElement {
))}
</div>
</div>
{/* Week start: the first column of every date picker (#2029) */}
<div>
<label className="block text-sm font-medium mb-2 text-content-secondary">{t('settings.weekStart')}</label>
<CustomSelect
value={settings.week_start || DEFAULT_WEEK_START}
onChange={async v => {
try { await updateSetting('week_start', String(v)) }
catch (e: unknown) { toast.error(e instanceof Error ? e.message : t('common.error')) }
}}
options={weekStartOptions(locale)}
/>
<p className="text-xs text-content-faint mt-2">{t('settings.weekStartHint')}</p>
</div>
</Section>
<Section title={t('settings.general.travelMap')} icon={Map}>