mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(vacay): correct weekend toggling and remove redundant labels
This commit is contained in:
@@ -51,7 +51,6 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
|
||||
{/* Weekend days selector */}
|
||||
{plan.block_weekends !== false && (
|
||||
<div data-testid="weekend-days" style={{ paddingInlineStart: 36 }}>
|
||||
<p className="text-xs font-medium mb-2 text-content-muted">{t('vacay.weekendDays')}</p>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{[
|
||||
{ day: 1, label: t('vacay.mon') },
|
||||
|
||||
@@ -110,6 +110,26 @@ describe('useVacaySettings', () => {
|
||||
expect(result.current.weekendDays).toEqual([5, 6]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[6, 0],
|
||||
[0, 6],
|
||||
])('keeps day %i deselected when the last selected day %i is then removed', (first, last) => {
|
||||
const { result } = renderHook(() => useVacaySettings({ language: 'en', loadCountries: false }));
|
||||
|
||||
act(() => result.current.toggleWeekendDay(first));
|
||||
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: String(last) });
|
||||
act(() => useVacayStore.setState({ plan: plan({ weekend_days: String(last) }) }));
|
||||
expect(result.current.weekendDays).toEqual([last]);
|
||||
|
||||
act(() => result.current.toggleWeekendDay(last));
|
||||
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: String(first) });
|
||||
act(() => useVacayStore.setState({ plan: plan({ weekend_days: String(first) }) }));
|
||||
expect(result.current.weekendDays).toEqual([first]);
|
||||
|
||||
act(() => result.current.toggleWeekendDay(last));
|
||||
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: `${first},${last}` });
|
||||
});
|
||||
|
||||
it('FE-COMP-VACAYSET-005: dissolving toasts and then hands over', async () => {
|
||||
const order: string[] = [];
|
||||
toast.success.mockImplementation(() => order.push('toast'));
|
||||
|
||||
@@ -62,6 +62,8 @@ export function useVacaySettings({ language, loadCountries }: { language: string
|
||||
const weekendDays: number[] = plan?.weekend_days ? String(plan.weekend_days).split(',').map(Number) : [0, 6];
|
||||
const toggleWeekendDay = (day: number) => {
|
||||
const next = weekendDays.includes(day) ? weekendDays.filter((d) => d !== day) : [...weekendDays, day];
|
||||
// An empty value restores both default days, including the day just deselected.
|
||||
if (next.length === 0) next.push(...[0, 6].filter((d) => d !== day));
|
||||
updatePlan({ weekend_days: next.join(',') });
|
||||
};
|
||||
|
||||
|
||||
@@ -78,28 +78,23 @@ export default function MVacaySettingsSheet({ open, onClose }: MVacaySettingsShe
|
||||
<MToggle checked={plan.block_weekends !== false} onChange={() => updatePlan({ block_weekends: !plan.block_weekends })} ariaLabel={t('vacay.blockWeekends')} />
|
||||
</div>
|
||||
{plan.block_weekends !== false && (
|
||||
<>
|
||||
<div className="mb-[6px] ms-7 mt-[2px] font-geist text-[0.625rem] font-bold uppercase tracking-[.06em] text-m-faint">
|
||||
{t('vacay.weekendDays')}
|
||||
</div>
|
||||
<div className="mb-[6px] ms-7 flex gap-1">
|
||||
{weekdayChips.map(({ day, label }) => {
|
||||
const active = weekendDays.includes(day)
|
||||
return (
|
||||
<button
|
||||
key={day}
|
||||
type="button"
|
||||
onClick={() => toggleWeekendDay(day)}
|
||||
className={`flex-1 rounded-[10px] py-[7px] text-center text-[0.65625rem] font-semibold ${
|
||||
active ? 'bg-m-act text-m-actfg' : 'border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-ink'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
<div className="mb-[6px] ms-7 flex gap-1">
|
||||
{weekdayChips.map(({ day, label }) => {
|
||||
const active = weekendDays.includes(day)
|
||||
return (
|
||||
<button
|
||||
key={day}
|
||||
type="button"
|
||||
onClick={() => toggleWeekendDay(day)}
|
||||
className={`flex-1 rounded-[10px] py-[7px] text-center text-[0.65625rem] font-semibold ${
|
||||
active ? 'bg-m-act text-m-actfg' : 'border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-ink'
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
<section className={CARD}>
|
||||
|
||||
Reference in New Issue
Block a user