fix: Add mock children data to Redux store for development

Added Alice and Bob as mock children in development mode to allow
tracking pages and UI to work without requiring authentication.

Changes:
- Updated childrenSlice to use childrenApi for consistent backend calls
- Pre-populated Redux store with 2 mock children (Alice, Bob)
- Set selectedChildId to first child by default
- Added mock token to localStorage for API client

This allows all tracking forms and ChildSelector components to work
in development without needing real login/auth flow.

TODO: Remove mocks and implement real authentication in production.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-05 06:48:05 +00:00
parent cb22d92796
commit 52144ca4a9
3 changed files with 51 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@@ -15,7 +15,7 @@ export interface AuthState {
loading: boolean;
}
// Mock user for development (TODO: Remove in production and implement real auth)
// Mock user and token for development (TODO: Remove in production and implement real auth)
const MOCK_USER: User = {
id: 'user_test123',
email: 'test@maternal.app',
@@ -23,10 +23,18 @@ const MOCK_USER: User = {
familyId: 'fam_test123',
};
// Mock JWT token for development - this is just for testing, real auth needed in production
const MOCK_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJ1c2VyX3Rlc3QxMjMiLCJmYW1pbHlJZCI6ImZhbV90ZXN0MTIzIiwiaWF0IjoxNjAwMDAwMDAwfQ.mock_signature_for_development';
// Set mock token in localStorage for development
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
localStorage.setItem('accessToken', MOCK_TOKEN);
}
const initialState: AuthState = {
// Use mock user in development if no real user is stored
user: process.env.NODE_ENV === 'development' ? MOCK_USER : null,
token: null,
token: process.env.NODE_ENV === 'development' ? MOCK_TOKEN : null,
isAuthenticated: process.env.NODE_ENV === 'development',
loading: false,
};

View File

@@ -1,5 +1,6 @@
import { createSlice, createAsyncThunk, createEntityAdapter, PayloadAction } from '@reduxjs/toolkit';
import { RootState } from '../store';
import { childrenApi } from '@/lib/api/children';
export interface Child {
id: string;
@@ -32,12 +33,8 @@ const childrenAdapter = createEntityAdapter<Child>({
export const fetchChildren = createAsyncThunk(
'children/fetch',
async (familyId: string) => {
const response = await fetch(`/api/v1/children?familyId=${familyId}`);
if (!response.ok) {
throw new Error('Failed to fetch children');
}
const data = await response.json();
return data.data;
const children = await childrenApi.getChildren(familyId);
return children;
}
);
@@ -94,18 +91,45 @@ interface ChildrenState {
lastSyncTime: string | null;
}
// Mock children for development (matches real data from andrei@cloudz.ro)
const MOCK_CHILDREN: Child[] = process.env.NODE_ENV === 'development' ? [
{
id: 'child_alice123',
familyId: 'fam_test123',
name: 'Alice',
birthDate: '2023-03-15',
gender: 'female',
displayColor: '#FF6B9D',
sortOrder: 1,
createdAt: new Date().toISOString(),
},
{
id: 'child_bob456',
familyId: 'fam_test123',
name: 'Bob',
birthDate: '2024-06-20',
gender: 'male',
displayColor: '#4A90E2',
sortOrder: 2,
createdAt: new Date().toISOString(),
},
] : [];
const childrenSlice = createSlice({
name: 'children',
initialState: childrenAdapter.getInitialState<ChildrenState>({
loading: false,
error: null,
selectedChildId: null,
selectedChildIds: [],
defaultChildId: null,
viewMode: 'auto',
lastSelectedPerScreen: {},
lastSyncTime: null,
}),
initialState: childrenAdapter.getInitialState<ChildrenState>(
{
loading: false,
error: null,
selectedChildId: MOCK_CHILDREN.length > 0 ? MOCK_CHILDREN[0].id : null,
selectedChildIds: MOCK_CHILDREN.length > 0 ? [MOCK_CHILDREN[0].id] : [],
defaultChildId: MOCK_CHILDREN.length > 0 ? MOCK_CHILDREN[0].id : null,
viewMode: 'auto',
lastSelectedPerScreen: {},
lastSyncTime: null,
},
MOCK_CHILDREN
),
reducers: {
// Optimistic operations
optimisticCreate: (state, action: PayloadAction<Child>) => {