Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Fixed notification bell integration by:
- Updated API client to match backend's wrapped response format
- Changed notification types to match database enums
- Adjusted notification interface to include all backend fields
- Backend notifications API already exists, no changes needed
Backend endpoint: GET /api/v1/notifications returns:
{ success: true, data: { notifications: [...] } }
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { apiClient } from './client';
|
|
|
|
export interface Notification {
|
|
id: string;
|
|
userId: string;
|
|
childId?: string;
|
|
type: 'feeding_reminder' | 'sleep_reminder' | 'diaper_reminder' | 'medication_reminder' | 'milestone_alert' | 'growth_tracking' | 'appointment_reminder' | 'pattern_anomaly';
|
|
status: 'pending' | 'sent' | 'failed' | 'read' | 'dismissed';
|
|
priority: 'low' | 'medium' | 'high' | 'urgent';
|
|
title: string;
|
|
message: string;
|
|
metadata?: Record<string, any>;
|
|
scheduledFor?: string;
|
|
sentAt?: string | null;
|
|
readAt?: string | null;
|
|
dismissedAt?: string | null;
|
|
deviceToken?: string;
|
|
errorMessage?: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface GetNotificationsParams {
|
|
limit?: number;
|
|
status?: Notification['status'];
|
|
includeRead?: boolean;
|
|
}
|
|
|
|
export interface GetNotificationsResponse {
|
|
notifications: Notification[];
|
|
total: number;
|
|
unreadCount: number;
|
|
}
|
|
|
|
// Backend response is wrapped in { success, data }
|
|
interface BackendResponse<T> {
|
|
success: boolean;
|
|
data: T;
|
|
message?: string;
|
|
}
|
|
|
|
export const notificationsApi = {
|
|
/**
|
|
* Get user notifications with optional filters
|
|
*/
|
|
async getNotifications(params?: GetNotificationsParams): Promise<GetNotificationsResponse> {
|
|
const { data } = await apiClient.get<BackendResponse<{ notifications: Notification[] }>>('/notifications', { params });
|
|
|
|
const notifications = data.data.notifications;
|
|
const unreadCount = notifications.filter(n => !n.readAt && !n.dismissedAt).length;
|
|
|
|
return {
|
|
notifications,
|
|
total: notifications.length,
|
|
unreadCount,
|
|
};
|
|
},
|
|
|
|
/**
|
|
* Mark a notification as read
|
|
*/
|
|
async markAsRead(notificationId: string): Promise<Notification> {
|
|
const { data } = await apiClient.patch<BackendResponse<any>>(`/notifications/${notificationId}/read`);
|
|
// Backend returns success message, not the notification, so we return empty object
|
|
return {} as Notification;
|
|
},
|
|
|
|
/**
|
|
* Mark all notifications as read
|
|
*/
|
|
async markAllAsRead(): Promise<{ count: number }> {
|
|
await apiClient.patch<BackendResponse<any>>('/notifications/mark-all-read');
|
|
return { count: 0 }; // Backend doesn't return count
|
|
},
|
|
|
|
/**
|
|
* Dismiss a notification
|
|
*/
|
|
async dismiss(notificationId: string): Promise<Notification> {
|
|
await apiClient.patch<BackendResponse<any>>(`/notifications/${notificationId}/dismiss`);
|
|
return {} as Notification;
|
|
},
|
|
|
|
/**
|
|
* Get unread notification count
|
|
*/
|
|
async getUnreadCount(): Promise<number> {
|
|
const response = await this.getNotifications({ limit: 100, includeRead: false });
|
|
return response.unreadCount;
|
|
},
|
|
};
|