Free days, vacation forfeiture, and global auto-replanning
Free days (Sat/Sun/red days, subject to DayOverride) can never be vacation, and can only be parental leave when the workspace opts in via take_pl_on_red_days. The allocator already honoured this; the hand-pin path bypassed it entirely. - PlanningService gains optional workspace_repo/day_override_repo deps and _reject_illegal_free_day, enforced in add_planned_day and update. Reuses allocation_service.is_free_day rather than re-deriving it, and no-ops when the deps are unset so existing callers are unaffected. - update_planned_day had no ValidationError handler at all, so a validation failure there 500'd instead of 422'ing. Fixed. - Calendar filters the pin write loop by the day's isFree; the modal explains free days stay off, and that pinning opts a day out of automatic re-planning. Vacation days at risk of forfeiture were computed and sent over the wire but never rendered: an at-risk column with the age-out/over-cap split, and a dashboard key figure. PlanProposal.warnings was likewise parsed but rendered nowhere, for all three kinds. Adds PlanWarningCard in a Risks section above the tips, with parent names resolved and dates formatted. POST /api/plan/sync now fires from the workspace layer on every plan-input change rather than only from Calendar, so a Settings edit or a pinned-day save re-plans day types instead of merely refetching. Overlapping bumps coalesce into one trailing run; a rejection cannot wedge the in-flight guard. eviction_preview was silently dropped by the frontend despite always being on the wire, and is now surfaced through context. Verified: backend 890 passed (91.49% coverage), frontend 1297 passed, ruff/eslint/tsc clean. Browser-checked in Swedish and English. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JVQx4NUvPbJhn6UcvRd2QY
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
useWorkspaceMembers,
|
||||
usePreschoolPlanningDays,
|
||||
useDebouncedCallback,
|
||||
useAnalytics,
|
||||
} from '@/hooks'
|
||||
import * as api from '@/services/api'
|
||||
import { isApiError } from '@/services/errors'
|
||||
@@ -221,7 +222,7 @@ function PreschoolPlanningYearRow({
|
||||
|
||||
export function Settings(): ReactNode {
|
||||
const { t, explicitLocale, setLocale } = useTranslation()
|
||||
const { workspace, isLoading: wsLoading, selectedChildId, children, personalDataUuid, refreshContext } = useWorkspace()
|
||||
const { workspace, isLoading: wsLoading, selectedChildId, children, personalDataUuid, refreshContext, bumpPlanVersion } = useWorkspace()
|
||||
const { data: vacDays, isLoading: vacLoading, upsert: upsertVacationDays } = useVacationDays(workspace?.id ?? '')
|
||||
const {
|
||||
data: members,
|
||||
@@ -268,6 +269,14 @@ export function Settings(): ReactNode {
|
||||
// a child is chosen/created elsewhere in the app.
|
||||
const balanceChildId = selectedChildId ?? children[0]?.id ?? null
|
||||
|
||||
// Supplies the vacation-days table's "at risk" column (already computed by
|
||||
// the same analytics endpoint Dashboard.tsx uses — see
|
||||
// `AnalyticsService._vacation_year_series`). Deliberately not folded into
|
||||
// `isLoading` below: it's an annotation on the editable table, not data
|
||||
// the table needs to render at all, and a new/unselected-child workspace
|
||||
// (no `balanceChildId` yet) must not block the rest of the page on it.
|
||||
const { data: analytics } = useAnalytics(workspace?.id ?? null, balanceChildId ?? undefined)
|
||||
|
||||
const isLoading = wsLoading || vacLoading || childDetailsLoading || dayOverridesLoading
|
||||
|
||||
useEffect(() => {
|
||||
@@ -303,9 +312,14 @@ export function Settings(): ReactNode {
|
||||
// `vacDays`, showing (and letting you overwrite) the wrong parent's data.
|
||||
const vacationRowsByMember: VacationDaysTableRow[][] = useMemo(
|
||||
() =>
|
||||
orderedMembers.map((member) =>
|
||||
vacationYears.map((year) => {
|
||||
orderedMembers.map((member) => {
|
||||
const projection = analytics?.parentProjections.find((p) => p.personalDataUuid === member.uuid)
|
||||
return vacationYears.map((year) => {
|
||||
const existing = vacDays.find((v: VacationDays) => v.personalDataUuid === member.uuid && v.year === year)
|
||||
// Analytics may not have loaded yet (or there's no child selected)
|
||||
// — the at-risk figures then default to 0 rather than block the
|
||||
// rest of this editable row on a supplementary fetch.
|
||||
const vacationBalance = projection?.yearBalances.find((b) => b.year === year)?.vacation
|
||||
return {
|
||||
year,
|
||||
totalDays: existing?.totalDays ?? DEFAULT_VACATION_DAYS,
|
||||
@@ -314,10 +328,13 @@ export function Settings(): ReactNode {
|
||||
// default is shown, not an entered value. Mirrors the backend's
|
||||
// `VacationBalanceResponse.is_assumed` for the propose-time table.
|
||||
isAssumed: existing === undefined,
|
||||
expiring: vacationBalance?.expiring ?? 0,
|
||||
expiringAge: vacationBalance?.expiringAge ?? 0,
|
||||
expiringOverCap: vacationBalance?.expiringOverCap ?? 0,
|
||||
}
|
||||
}),
|
||||
),
|
||||
[orderedMembers, vacationYears, vacDays],
|
||||
})
|
||||
}),
|
||||
[orderedMembers, vacationYears, vacDays, analytics],
|
||||
)
|
||||
|
||||
if (isLoading) {
|
||||
@@ -354,6 +371,11 @@ export function Settings(): ReactNode {
|
||||
salary_type: parentData.salaryType,
|
||||
employment_status: parentData.employmentStatus,
|
||||
})
|
||||
// Salary type feeds the allocator's cost calculations (sjukpenning
|
||||
// vs lägstanivå tradeoffs) — re-type the rest of the plan's
|
||||
// unpinned days. See `WorkspaceContext.planVersion`. (Child-details
|
||||
// saves above already bump via `useChildSettings.update`.)
|
||||
bumpPlanVersion()
|
||||
}
|
||||
showMessage('success', t('settings.saveFamilySuccess'))
|
||||
} catch (err) {
|
||||
@@ -499,6 +521,10 @@ export function Settings(): ReactNode {
|
||||
setIsSavingRedDayPref(true)
|
||||
await api.updateWorkspace(workspace.id, { takePlOnRedDays: checked })
|
||||
await refreshContext()
|
||||
// Whether PL may be taken on red days changes which dates the
|
||||
// allocator can place leave on — re-type the rest of the plan's
|
||||
// unpinned days. See `WorkspaceContext.planVersion`.
|
||||
bumpPlanVersion()
|
||||
} catch (err) {
|
||||
showMessage('error', err instanceof Error ? err.message : t('settings.takePlOnRedDaysError'))
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user