fix: notification click navigates to related page, report interpretation notifies patient
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { PageHeader } from '@/components/layout/PageHeader';
|
||||
import { Card } from '@/components/common/Card';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useNotificationStore } from '@/stores/notification.store';
|
||||
import { formatRelative } from '@/utils/format';
|
||||
import type { NotificationType } from '@/types';
|
||||
import type { NotificationType, Notification } from '@/types';
|
||||
import styles from './NotificationListPage.module.css';
|
||||
|
||||
const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [
|
||||
@@ -15,7 +16,23 @@ const TYPE_TABS: { key: NotificationType | 'all'; label: string }[] = [
|
||||
{ key: 'system', label: '系统' },
|
||||
];
|
||||
|
||||
function getNavPath(n: Notification): string | null {
|
||||
switch (n.type) {
|
||||
case 'consultation':
|
||||
return '/services/consultation';
|
||||
case 'medication':
|
||||
return '/health/medications';
|
||||
case 'followup':
|
||||
return '/services/follow-ups';
|
||||
case 'report':
|
||||
return n.relatedId ? `/services/reports/${n.relatedId}` : '/services/reports';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function NotificationListPage() {
|
||||
const navigate = useNavigate();
|
||||
const { notifications, unreadCount, fetchNotifications, markRead, markAllRead } = useNotificationStore();
|
||||
const [tab, setTab] = useState<NotificationType | 'all'>('all');
|
||||
|
||||
@@ -27,6 +44,12 @@ export function NotificationListPage() {
|
||||
? notifications
|
||||
: notifications.filter((n) => n.type === tab);
|
||||
|
||||
const handleClick = (n: Notification) => {
|
||||
if (!n.isRead) markRead(n.id);
|
||||
const path = getNavPath(n);
|
||||
if (path) navigate(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="page--no-tab">
|
||||
<PageHeader
|
||||
@@ -59,7 +82,7 @@ export function NotificationListPage() {
|
||||
<Card
|
||||
key={n.id}
|
||||
className={`${styles.notifCard} ${!n.isRead ? styles.unread : ''}`}
|
||||
onClick={() => { if (!n.isRead) markRead(n.id); }}
|
||||
onClick={() => handleClick(n)}
|
||||
>
|
||||
<div className={styles.notifHeader}>
|
||||
<span className={styles.notifTitle}>{n.title}</span>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type NotificationType = 'medication' | 'followup' | 'consultation' | 'system';
|
||||
export type NotificationType = 'medication' | 'followup' | 'consultation' | 'report' | 'system';
|
||||
|
||||
export interface Notification {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user