Phase 7 Implementation: - Add lazy loading for AI Assistant and Insights pages - Create LoadingFallback component with skeleton screens (page, card, list, chart, chat variants) - Create OptimizedImage component with Next.js Image optimization - Create PerformanceMonitor component with web-vitals v5 integration - Add performance monitoring library tracking Core Web Vitals (CLS, INP, FCP, LCP, TTFB) - Install web-vitals v5.1.0 dependency - Extract AI chat interface and insights dashboard to lazy-loaded components Tracking System Fixes: - Fix API data transformation between frontend (timestamp/data) and backend (startedAt/metadata) - Update createActivity, getActivities, and getActivity to properly transform data structures - Fix diaper, feeding, and sleep tracking pages to work with backend API Homepage Improvements: - Connect Today's Summary to backend daily summary API - Load real-time data for feeding count, sleep hours, and diaper count - Add loading states and empty states for better UX - Format sleep duration as "Xh Ym" for better readability - Display child name in summary section 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
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 });
|
|
// Transform backend response to frontend format
|
|
const activities = response.data.data.activities.map((activity: any) => ({
|
|
...activity,
|
|
timestamp: activity.startedAt, // Frontend expects timestamp
|
|
data: activity.metadata, // Frontend expects data
|
|
}));
|
|
return activities;
|
|
},
|
|
|
|
// Get a specific activity
|
|
getActivity: async (id: string): Promise<Activity> => {
|
|
const response = await apiClient.get(`/api/v1/activities/${id}`);
|
|
const activity = response.data.data.activity;
|
|
// Transform backend response to frontend format
|
|
return {
|
|
...activity,
|
|
timestamp: activity.startedAt,
|
|
data: activity.metadata,
|
|
};
|
|
},
|
|
|
|
// Create a new activity
|
|
createActivity: async (childId: string, data: CreateActivityData): Promise<Activity> => {
|
|
// Transform frontend data structure to backend DTO format
|
|
const payload = {
|
|
type: data.type,
|
|
startedAt: data.timestamp, // Backend expects startedAt, not timestamp
|
|
metadata: data.data, // Backend expects metadata, not data
|
|
notes: data.notes,
|
|
};
|
|
const response = await apiClient.post(`/api/v1/activities?childId=${childId}`, payload);
|
|
const activity = response.data.data.activity;
|
|
// Transform backend response to frontend format
|
|
return {
|
|
...activity,
|
|
timestamp: activity.startedAt,
|
|
data: activity.metadata,
|
|
};
|
|
},
|
|
|
|
// 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;
|
|
},
|
|
};
|