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:
69
maternal-web/lib/api/families.ts
Normal file
69
maternal-web/lib/api/families.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import apiClient from './client';
|
||||
|
||||
export interface Family {
|
||||
id: string;
|
||||
name: string;
|
||||
shareCode: string;
|
||||
createdBy: string;
|
||||
subscriptionTier: string;
|
||||
members?: FamilyMember[];
|
||||
}
|
||||
|
||||
export interface FamilyMember {
|
||||
id: string;
|
||||
userId: string;
|
||||
familyId: string;
|
||||
role: 'parent' | 'caregiver' | 'viewer';
|
||||
permissions: any;
|
||||
user?: {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface InviteMemberData {
|
||||
email: string;
|
||||
role: 'parent' | 'caregiver' | 'viewer';
|
||||
}
|
||||
|
||||
export interface JoinFamilyData {
|
||||
shareCode: string;
|
||||
}
|
||||
|
||||
export const familiesApi = {
|
||||
// Get a specific family
|
||||
getFamily: async (familyId: string): Promise<Family> => {
|
||||
const response = await apiClient.get(`/api/v1/families/${familyId}`);
|
||||
return response.data.data.family;
|
||||
},
|
||||
|
||||
// Get family members
|
||||
getFamilyMembers: async (familyId: string): Promise<FamilyMember[]> => {
|
||||
const response = await apiClient.get(`/api/v1/families/${familyId}/members`);
|
||||
return response.data.data.members;
|
||||
},
|
||||
|
||||
// Invite a family member
|
||||
inviteMember: async (familyId: string, data: InviteMemberData): Promise<any> => {
|
||||
const response = await apiClient.post(`/api/v1/families/invite?familyId=${familyId}`, data);
|
||||
return response.data.data.invitation;
|
||||
},
|
||||
|
||||
// Join a family using share code
|
||||
joinFamily: async (data: JoinFamilyData): Promise<FamilyMember> => {
|
||||
const response = await apiClient.post('/api/v1/families/join', data);
|
||||
return response.data.data.member;
|
||||
},
|
||||
|
||||
// Update member role
|
||||
updateMemberRole: async (familyId: string, userId: string, role: string): Promise<FamilyMember> => {
|
||||
const response = await apiClient.patch(`/api/v1/families/${familyId}/members/${userId}/role`, { role });
|
||||
return response.data.data.member;
|
||||
},
|
||||
|
||||
// Remove a family member
|
||||
removeMember: async (familyId: string, userId: string): Promise<void> => {
|
||||
await apiClient.delete(`/api/v1/families/${familyId}/members/${userId}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user