Phase 1: Fix TypeScript compilation — add missing API functions and fix hook signatures

- Add 8 missing API client functions (getBreakPeriods, createBreakPeriod, deleteBreakPeriod, getTips, getParentalLeave, getPlannedDays, createPlannedDay, deletePlannedDay)
- Fix useAnalytics to accept optional childId parameter
- Fix ApiError strict optional properties handling
- Export HeaderProps from Header component
- Update hook tests to use correct data structures and optional parameters

npx tsc --noEmit now passes with zero errors.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 17:47:17 +02:00
parent 53d157535a
commit fbb7a04580
15 changed files with 1092 additions and 62 deletions
+18 -9
View File
@@ -18,28 +18,29 @@ describe('useAnalytics', () => {
it('fetches analytics data on mount', async () => {
const mockData = {
workspace_id: 'ws1',
total_days: 25,
days_used: 10,
days_left: 15,
projected_left_at_age_4: 50,
workspaceId: 'ws1',
childId: 'child1',
parentProjections: [],
combinedDaysUsed: 10,
combinedDaysLeft: 15,
combinedExpiringAtB4: 50,
}
vi.mocked(api.getWorkspaceOverview).mockResolvedValue(mockData as any)
const { result } = renderHook(() => useAnalytics('ws1'))
renderHook(() => useAnalytics('ws1', 'child1'))
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0))
})
expect(api.getWorkspaceOverview).toHaveBeenCalledWith('ws1')
expect(api.getWorkspaceOverview).toHaveBeenCalledWith('ws1', 'child1')
})
it('handles fetch errors', async () => {
vi.mocked(api.getWorkspaceOverview).mockRejectedValue(new Error('API error'))
const { result } = renderHook(() => useAnalytics('ws1'))
const { result } = renderHook(() => useAnalytics('ws1', 'child1'))
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0))
@@ -56,10 +57,18 @@ describe('useAnalytics', () => {
expect(api.getWorkspaceOverview).not.toHaveBeenCalled()
})
it('does not fetch when childId is missing', () => {
vi.mocked(api.getWorkspaceOverview).mockResolvedValue({} as any)
renderHook(() => useAnalytics('ws1'))
expect(api.getWorkspaceOverview).not.toHaveBeenCalled()
})
it('provides refresh function', async () => {
vi.mocked(api.getWorkspaceOverview).mockResolvedValue({} as any)
const { result } = renderHook(() => useAnalytics('ws1'))
const { result } = renderHook(() => useAnalytics('ws1', 'child1'))
await act(async () => {
await result.current.refresh()