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>
This commit is contained in:
80
maternal-web/lib/api/tracking.ts
Normal file
80
maternal-web/lib/api/tracking.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import apiClient from './client';
|
||||
|
||||
export type ActivityType = 'feeding' | 'sleep' | 'diaper' | 'medication' | 'milestone' | 'note';
|
||||
|
||||
export interface Activity {
|
||||
id: string;
|
||||
childId: string;
|
||||
type: ActivityType;
|
||||
timestamp: string;
|
||||
data: any;
|
||||
notes?: string;
|
||||
loggedBy: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface CreateActivityData {
|
||||
type: ActivityType;
|
||||
timestamp: string;
|
||||
data: any;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface UpdateActivityData extends Partial<CreateActivityData> {}
|
||||
|
||||
export interface DailySummary {
|
||||
date: string;
|
||||
feedingCount: number;
|
||||
sleepTotalMinutes: number;
|
||||
diaperCount: number;
|
||||
activities: Activity[];
|
||||
}
|
||||
|
||||
export const trackingApi = {
|
||||
// Get all activities for a child
|
||||
getActivities: async (
|
||||
childId: string,
|
||||
type?: ActivityType,
|
||||
startDate?: string,
|
||||
endDate?: string
|
||||
): Promise<Activity[]> => {
|
||||
const params: any = { childId };
|
||||
if (type) params.type = type;
|
||||
if (startDate) params.startDate = startDate;
|
||||
if (endDate) params.endDate = endDate;
|
||||
|
||||
const response = await apiClient.get('/api/v1/activities', { params });
|
||||
return response.data.data.activities;
|
||||
},
|
||||
|
||||
// Get a specific activity
|
||||
getActivity: async (id: string): Promise<Activity> => {
|
||||
const response = await apiClient.get(`/api/v1/activities/${id}`);
|
||||
return response.data.data.activity;
|
||||
},
|
||||
|
||||
// Create a new activity
|
||||
createActivity: async (childId: string, data: CreateActivityData): Promise<Activity> => {
|
||||
const response = await apiClient.post(`/api/v1/activities?childId=${childId}`, data);
|
||||
return response.data.data.activity;
|
||||
},
|
||||
|
||||
// Update an activity
|
||||
updateActivity: async (id: string, data: UpdateActivityData): Promise<Activity> => {
|
||||
const response = await apiClient.patch(`/api/v1/activities/${id}`, data);
|
||||
return response.data.data.activity;
|
||||
},
|
||||
|
||||
// Delete an activity
|
||||
deleteActivity: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/api/v1/activities/${id}`);
|
||||
},
|
||||
|
||||
// Get daily summary
|
||||
getDailySummary: async (childId: string, date: string): Promise<DailySummary> => {
|
||||
const response = await apiClient.get('/api/v1/activities/daily-summary', {
|
||||
params: { childId, date },
|
||||
});
|
||||
return response.data.data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user