Track preschool planning days, partner invites and real vacation forfeiture

Three strands of work that grew together across the same settings screen and
API client, so they land as one change.

Per-year preschool planning days ("studiedagar"): new table, repository
(SQLite + Postgres), service, router and migration 007, plus the hooks and
Settings UI to plan and record them per child and year. Allocation now
reserves the recorded figure for a year where one exists and only falls back
to the child-level estimate otherwise, marking that fallback as assumed.

Partner invitations: workspaces issue and list invitations, registration
accepts an invite token to join the inviter's workspace instead of creating a
personal one, and a /join/:token page plus the settings invite panel drive it.

Vacation forfeiture: tips and the dashboard now distinguish days a parent
genuinely loses from days that merely age, so the warning stops firing on
balances that were never at risk.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 11:22:07 +02:00
parent 6904961bb4
commit 0e9b20ec37
88 changed files with 5301 additions and 348 deletions
+129
View File
@@ -23,6 +23,9 @@ import type {
WorkspaceUpdateRequest,
WorkspaceOverview,
PlanSyncResponse,
PreschoolPlanningDaysPlannedRequest,
PreschoolPlanningDaysTakenRequest,
CreateInvitationResponse,
} from '@/types'
import type {
Workspace,
@@ -42,6 +45,8 @@ import type {
ParentalLeaveYearBalance,
ParentYearBalance,
YearTotals,
PreschoolPlanningDays,
Invitation,
} from '@/types'
const BASE = '/api'
@@ -121,6 +126,8 @@ export interface RawVacationYearBalance {
left: number
carried_out: number
expiring: number
expiring_age: number
expiring_over_cap: number
}
function toVacationYearBalance(raw: RawVacationYearBalance): VacationYearBalance {
@@ -133,6 +140,8 @@ function toVacationYearBalance(raw: RawVacationYearBalance): VacationYearBalance
left: raw.left,
carriedOut: raw.carried_out,
expiring: raw.expiring,
expiringAge: raw.expiring_age,
expiringOverCap: raw.expiring_over_cap,
}
}
@@ -762,6 +771,9 @@ export async function register(req: RegisterRequest): Promise<TokenResponse> {
email: req.email,
password: req.password,
display_name: req.displayName,
// Omitted (rather than sent as `undefined`) so the backend's
// "no invite" default (`None`) applies untouched.
...(req.inviteToken !== undefined ? { invite_token: req.inviteToken } : {}),
}),
})
}
@@ -1403,3 +1415,120 @@ export async function cancelScraperSession(sessionId: string): Promise<void> {
body: JSON.stringify({ session_id: sessionId }),
})
}
// ---------------------------------------------------------------------------
// Preschool planning days ("studiedagar") — /api/preschool-planning-days
// ---------------------------------------------------------------------------
interface RawPreschoolPlanningDays {
id: string | null
child_id: string
year: number
planned_days: number
taken_days: number | null
is_default: boolean
created_at: string | null
updated_at: string | null
}
function toPreschoolPlanningDays(raw: RawPreschoolPlanningDays): PreschoolPlanningDays {
return {
id: raw.id,
childId: raw.child_id,
year: raw.year,
plannedDays: raw.planned_days,
takenDays: raw.taken_days,
isDefault: raw.is_default,
createdAt: raw.created_at,
updatedAt: raw.updated_at,
}
}
export async function upsertPreschoolPlanningDaysPlanned(
childId: string,
year: number,
req: PreschoolPlanningDaysPlannedRequest,
): Promise<PreschoolPlanningDays> {
const raw = (await apiFetch(`/preschool-planning-days/${childId}/${year}/planned`, {
method: 'PUT',
body: JSON.stringify({ planned_days: req.plannedDays }),
})) as RawPreschoolPlanningDays
return toPreschoolPlanningDays(raw)
}
export async function recordPreschoolPlanningDaysTaken(
childId: string,
year: number,
req: PreschoolPlanningDaysTakenRequest,
): Promise<PreschoolPlanningDays> {
const raw = (await apiFetch(`/preschool-planning-days/${childId}/${year}/taken`, {
method: 'PUT',
body: JSON.stringify({ taken_days: req.takenDays }),
})) as RawPreschoolPlanningDays
return toPreschoolPlanningDays(raw)
}
export async function getPreschoolPlanningDaysYear(
childId: string,
year: number,
): Promise<PreschoolPlanningDays> {
const raw = (await apiFetch(
`/preschool-planning-days/${childId}/${year}`,
)) as RawPreschoolPlanningDays
return toPreschoolPlanningDays(raw)
}
export async function listPreschoolPlanningDays(childId: string): Promise<PreschoolPlanningDays[]> {
const raw = (await apiFetch(`/preschool-planning-days/${childId}`)) as RawPreschoolPlanningDays[]
return raw.map(toPreschoolPlanningDays)
}
// ---------------------------------------------------------------------------
// Invitations — /api/workspace/{id}/invitations, /api/invitations/*
// ---------------------------------------------------------------------------
interface RawInvitation {
id: string
workspace_id: string
status: 'pending' | 'accepted' | 'revoked' | 'expired'
expires_at: string
created_at: string
}
function toInvitation(raw: RawInvitation): Invitation {
return {
id: raw.id,
workspaceId: raw.workspace_id,
status: raw.status,
expiresAt: raw.expires_at,
createdAt: raw.created_at,
}
}
/** Creates a one-time invite for `workspaceId`; the raw `token` is returned
* once and never stored server-side — share it out-of-band (the backend
* only ever persists its hash). */
export async function createInvitation(workspaceId: string): Promise<CreateInvitationResponse> {
return apiFetch(`/workspace/${workspaceId}/invitations`, { method: 'POST' })
}
/** Lists this workspace's invitations. Never includes `token_hash` — the
* backend omits it from the wire response entirely. */
export async function listInvitations(workspaceId: string): Promise<Invitation[]> {
const raw = (await apiFetch(`/workspace/${workspaceId}/invitations`)) as RawInvitation[]
return raw.map(toInvitation)
}
export async function redeemInvitation(token: string): Promise<Invitation> {
const raw = (await apiFetch('/invitations/redeem', {
method: 'POST',
body: JSON.stringify({ token }),
})) as RawInvitation
return toInvitation(raw)
}
/** The caller's own workspace is inferred server-side from their session —
* no workspace id is sent. */
export async function revokeInvitation(invitationId: string): Promise<void> {
return apiFetch(`/invitations/${invitationId}`, { method: 'DELETE' })
}