Files
maternal-app/maternal-web/lib/api/children.ts
andupetcu 6894fa8edf Add backend API integration for Children, Family, and Tracking
API Services Created:
- lib/api/children.ts: Full CRUD operations for children management
- lib/api/families.ts: Family member management and invitations
- lib/api/tracking.ts: Activity tracking (feeding, sleep, diaper, etc.)

Children Page Implementation:
- Fetch and display children from backend API
- Add/Edit child with modal dialog (ChildDialog component)
- Delete child with confirmation (DeleteConfirmDialog component)
- Age calculation from birthDate
- Loading states and error handling
- Responsive card grid layout
- Gender-based avatar colors
- Empty state for no children

AuthContext Updates:
- Added families array to User interface
- Includes familyId for API calls

Components:
- components/children/ChildDialog.tsx: Form for add/edit child
- components/children/DeleteConfirmDialog.tsx: Delete confirmation

All components use Material-UI theme and include proper TypeScript types

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-30 22:10:00 +03:00

61 lines
1.8 KiB
TypeScript

import apiClient from './client';
export interface Child {
id: string;
familyId: string;
name: string;
birthDate: string;
gender: 'male' | 'female' | 'other';
photoUrl?: string;
medicalInfo?: any;
createdAt: string;
}
export interface CreateChildData {
name: string;
birthDate: string;
gender: 'male' | 'female' | 'other';
photoUrl?: string;
medicalInfo?: any;
}
export interface UpdateChildData extends Partial<CreateChildData> {}
export const childrenApi = {
// Get all children for the authenticated user
getChildren: async (familyId?: string): Promise<Child[]> => {
const params = familyId ? { familyId } : {};
const response = await apiClient.get('/api/v1/children', { params });
return response.data.data.children;
},
// Get a specific child
getChild: async (id: string): Promise<Child> => {
const response = await apiClient.get(`/api/v1/children/${id}`);
return response.data.data.child;
},
// Create a new child
createChild: async (familyId: string, data: CreateChildData): Promise<Child> => {
const response = await apiClient.post(`/api/v1/children?familyId=${familyId}`, data);
return response.data.data.child;
},
// Update a child
updateChild: async (id: string, data: UpdateChildData): Promise<Child> => {
const response = await apiClient.patch(`/api/v1/children/${id}`, data);
return response.data.data.child;
},
// Delete a child
deleteChild: async (id: string): Promise<void> => {
await apiClient.delete(`/api/v1/children/${id}`);
},
// Get child's age
getChildAge: async (id: string): Promise<{ ageInMonths: number; ageInYears: number; remainingMonths: number }> => {
const response = await apiClient.get(`/api/v1/children/${id}/age`);
return response.data.data;
},
};