Complete NextSteps roadmap: planning engine UI, calendar cluster, flexible wishes
Works through every numbered item in NextSteps260913.md section 3, plus the three known verification issues in section 4.1. Surface what the backend already computed: - 3.1 render surplus_advice in PlanResults, mirroring the shortfall remedies - 3.2 surface VacationBalance.is_assumed so assumed statutory years are visible - 3.3 age-4 expiry given the proposed plan, via a new Age4Projection reusing the existing _age4_projections arithmetic (Dashboard stat verified, not rebuilt) Calendar cluster (one pass over the holiday data): - new GET /api/calendar/days exposing roda dagar, klamdagar and day overrides, paginated four years at a time - 3.4 shade roda dagar/klamdagar, with R/K badges so colour is not the only signal - 3.6 click-to-override behind an explicit mode toggle, leaving drag multi-select intact - 3.7 click month/year to advance - 3.8 per-year red-days list in Settings, statutory days plus overrides i18n: - 3.5 five backend-generated Swedish surfaces converted to message_key + data, following the tips_service pattern; old string fields replaced, not kept Flexible wishes (3.9): - PLANNING_ENGINE_SPEC section 10: window_mode, candidate search, cost function, deterministic tie-break, two-pass ordering, test matrix rows 15-24 - backend: entity, migration 006, _FULL_SCHEMA sync, repository, allocator - frontend: season-preset toggle in WishEditor, unplaced outcome rendering Fixes (4.1): - pin typecheck to the local tsc rather than npx resolving a newer TypeScript - ignore generated coverage/ and dist/ in the ESLint flat config - fix the flaky usePlanApply test properly, with waitFor rather than a retry Tests: backend 361 -> 404, frontend 540 -> 704. Coverage 89.47% -> 96.52% lines. Not yet verified in a browser. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { ReactNode, useState } from 'react'
|
||||
import { useWorkspace } from '@/context'
|
||||
import { useAnalytics, usePlannedDays, useBreakPeriods, useScraperFetch, useParentalLeave } from '@/hooks'
|
||||
import type { PlannedLeaveDay, BreakPeriod } from '@/types'
|
||||
import { useAnalytics, usePlannedDays, useScraperFetch, useParentalLeave } from '@/hooks'
|
||||
import type { PlannedLeaveDay } from '@/types'
|
||||
import * as api from '@/services/api'
|
||||
import { getLabelForType } from '@/utils/leaveTypes'
|
||||
import { useTranslation } from '@/i18n'
|
||||
import { Layout } from '@/components/layout/Layout'
|
||||
import { LoadingSpinner } from '@/components/common/LoadingSpinner'
|
||||
import { OverviewMetrics } from '@/components/dashboard/OverviewMetrics'
|
||||
@@ -14,13 +16,13 @@ import { QRCodeModal } from '@/components/modals/QRCodeModal'
|
||||
import { ManualFetchModal } from '@/components/modals/ManualFetchModal'
|
||||
|
||||
export function Dashboard(): ReactNode {
|
||||
const { t } = useTranslation()
|
||||
const { workspace, isLoading: wsLoading, selectedChildId, children, personalDataUuid, refreshContext } = useWorkspace()
|
||||
const { data: analytics, isLoading: analyticsLoading, error: analyticsError, refresh: refreshAnalytics } = useAnalytics(
|
||||
workspace?.id ?? null,
|
||||
selectedChildId ?? ''
|
||||
)
|
||||
const { data: plannedDays, isLoading: pdLoading } = usePlannedDays(selectedChildId ?? undefined)
|
||||
const { data: breakPeriods, isLoading: bpLoading } = useBreakPeriods(workspace?.id ?? null)
|
||||
const { data: parentalLeave, refresh: refreshParentalLeave } = useParentalLeave(personalDataUuid, selectedChildId ?? null)
|
||||
const scraper = useScraperFetch()
|
||||
|
||||
@@ -33,17 +35,17 @@ export function Dashboard(): ReactNode {
|
||||
const [isManualFetchSaving, setIsManualFetchSaving] = useState(false)
|
||||
const [manualFetchError, setManualFetchError] = useState<string | null>(null)
|
||||
|
||||
const isLoading = wsLoading || analyticsLoading || pdLoading || bpLoading
|
||||
const isLoading = wsLoading || analyticsLoading || pdLoading
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingSpinner message="Loading dashboard..." />
|
||||
return <LoadingSpinner message={t('dashboard.loading')} />
|
||||
}
|
||||
|
||||
const handleAddChild = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setSubmitError(null)
|
||||
if (!workspace || !childName || !childBirthDate) {
|
||||
setSubmitError('Please fill in all fields')
|
||||
setSubmitError(t('dashboard.fillAllFields'))
|
||||
return
|
||||
}
|
||||
setIsSubmitting(true)
|
||||
@@ -57,7 +59,7 @@ export function Dashboard(): ReactNode {
|
||||
setChildBirthDate('')
|
||||
await refreshContext()
|
||||
} catch (err: unknown) {
|
||||
setSubmitError(err instanceof Error ? err.message : 'Failed to create child')
|
||||
setSubmitError(err instanceof Error ? err.message : t('dashboard.createChildError'))
|
||||
} finally {
|
||||
setIsSubmitting(false)
|
||||
}
|
||||
@@ -100,7 +102,7 @@ export function Dashboard(): ReactNode {
|
||||
await refreshAnalytics()
|
||||
setShowManualFetchModal(false)
|
||||
} catch (err) {
|
||||
setManualFetchError(err instanceof Error ? err.message : 'Failed to save manual data')
|
||||
setManualFetchError(err instanceof Error ? err.message : t('dashboard.saveManualFetchError'))
|
||||
} finally {
|
||||
setIsManualFetchSaving(false)
|
||||
}
|
||||
@@ -117,9 +119,9 @@ export function Dashboard(): ReactNode {
|
||||
}
|
||||
|
||||
const breakdown = [
|
||||
{ type: 'Vacation', count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'vacation').length ?? 0 },
|
||||
{ type: 'Sick Leave', count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'sjukpenning').length ?? 0 },
|
||||
{ type: 'Parental', count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'lagsta').length ?? 0 },
|
||||
{ type: getLabelForType('vacation', t), count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'vacation').length ?? 0 },
|
||||
{ type: getLabelForType('sjukpenning', t), count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'sjukpenning').length ?? 0 },
|
||||
{ type: getLabelForType('lagsta', t), count: plannedDays?.filter((d: PlannedLeaveDay) => d.dayType === 'lagsta').length ?? 0 },
|
||||
]
|
||||
|
||||
const currentWeeks = Math.floor((analytics?.combinedDaysUsed ?? 0) / 5)
|
||||
@@ -130,15 +132,15 @@ export function Dashboard(): ReactNode {
|
||||
<Layout>
|
||||
<div data-testid="dashboard" className="dashboard">
|
||||
<section className="dashboard__section">
|
||||
<h2>Lägg till barn</h2>
|
||||
<p>Du har inga barn registrerade ännu. Lägg till ditt första barn för att börja.</p>
|
||||
<h2>{t('dashboard.addChildTitle')}</h2>
|
||||
<p>{t('dashboard.addChildIntro')}</p>
|
||||
<form onSubmit={(e) => void handleAddChild(e)}>
|
||||
<div className="form-group">
|
||||
<label htmlFor="child-name">Barnets namn</label>
|
||||
<label htmlFor="child-name">{t('dashboard.childNameLabel')}</label>
|
||||
<input
|
||||
id="child-name"
|
||||
type="text"
|
||||
placeholder="Namn"
|
||||
placeholder={t('dashboard.namePlaceholder')}
|
||||
value={childName}
|
||||
onChange={(e) => setChildName(e.target.value)}
|
||||
disabled={isSubmitting}
|
||||
@@ -149,7 +151,7 @@ export function Dashboard(): ReactNode {
|
||||
<ChildBirthdayInput
|
||||
birthDate={childBirthDate}
|
||||
onBirthDateChange={setChildBirthDate}
|
||||
label="Födelsedag"
|
||||
label={t('dashboard.birthdayLabel')}
|
||||
/>
|
||||
</div>
|
||||
{submitError && (
|
||||
@@ -158,7 +160,7 @@ export function Dashboard(): ReactNode {
|
||||
</div>
|
||||
)}
|
||||
<button type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Lägger till...' : 'Lägg till barn'}
|
||||
{isSubmitting ? t('dashboard.addingChild') : t('dashboard.addChildButton')}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
@@ -183,14 +185,14 @@ export function Dashboard(): ReactNode {
|
||||
disabled={!selectedChildId}
|
||||
style={{ padding: '0.5rem 1rem', cursor: selectedChildId ? 'pointer' : 'not-allowed' }}
|
||||
>
|
||||
Hämta från Försäkringskassan
|
||||
{t('dashboard.fetchFromFk')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowManualFetchModal(true)}
|
||||
disabled={!selectedChildId}
|
||||
style={{ padding: '0.5rem 1rem', cursor: selectedChildId ? 'pointer' : 'not-allowed' }}
|
||||
>
|
||||
Ange uppgifter manuellt
|
||||
{t('dashboard.enterManually')}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
@@ -198,11 +200,11 @@ export function Dashboard(): ReactNode {
|
||||
<section className="dashboard__section">
|
||||
{analytics && (
|
||||
<OverviewMetrics
|
||||
title="Översikt"
|
||||
title={t('dashboard.overviewTitle')}
|
||||
metrics={[
|
||||
{ label: 'Days Used', value: analytics.combinedDaysUsed },
|
||||
{ label: 'Days Left', value: analytics.combinedDaysLeft },
|
||||
{ label: 'Expiring at Age 4', value: analytics.combinedExpiringAtB4 },
|
||||
{ label: t('dashboard.usedDays'), value: analytics.combinedDaysUsed },
|
||||
{ label: t('dashboard.daysLeft'), value: analytics.combinedDaysLeft },
|
||||
{ label: t('dashboard.expiringAtB4'), value: analytics.combinedExpiringAtB4 },
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
@@ -210,34 +212,18 @@ export function Dashboard(): ReactNode {
|
||||
</section>
|
||||
|
||||
<section className="dashboard__section">
|
||||
<h2>Planerade dagar</h2>
|
||||
<h2>{t('dashboard.plannedDaysTitle')}</h2>
|
||||
<DaysBreakdown breakdown={breakdown} />
|
||||
</section>
|
||||
|
||||
<section className="dashboard__section">
|
||||
<h2>Återstående till 4 års ålder</h2>
|
||||
<h2>{t('dashboard.remainingUntilB4Title')}</h2>
|
||||
<ProgressChart
|
||||
currentWeeks={currentWeeks}
|
||||
targetWeeks={targetWeeks}
|
||||
/>
|
||||
</section>
|
||||
|
||||
{breakPeriods && breakPeriods.length > 0 && (
|
||||
<section className="dashboard__section">
|
||||
<h2>Break Periods ({breakPeriods.length})</h2>
|
||||
<ul className="dashboard__break-list">
|
||||
{breakPeriods.map((period: BreakPeriod) => (
|
||||
<li key={period.id} className="dashboard__break-item">
|
||||
<strong>{period.name}</strong>
|
||||
<small>
|
||||
{period.startDate} to {period.endDate}
|
||||
</small>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<QRCodeModal
|
||||
isOpen={showModal}
|
||||
onClose={handleModalClose}
|
||||
|
||||
Reference in New Issue
Block a user