Skip to content

Commit

Permalink
Add notifications tab
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszbachorski committed Oct 1, 2024
1 parent 0c08295 commit efd1c8e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions modules/notifications/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ export const parseMessageToLink = (message: UserMessage) => {
}
return null
}

export const getNotificationPatientId = (message: UserMessage) => {
const action = message.action
if (!action) return null
const actionParts = action.split('/')
if (actionParts.at(0) === 'users') {
return actionParts.at(1)
}
return null
}
23 changes: 23 additions & 0 deletions routes/~_dashboard/~patients/~$id/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useQuery } from '@tanstack/react-query'
import { useUser } from '@/modules/firebase/UserProvider'
import { getNotificationPatientId } from '@/modules/notifications/helpers'
import { NotificationsTable } from '@/modules/notifications/NotificationsTable'
import { notificationQueries } from '@/modules/notifications/queries'

interface NotificationsProps {
userId: string
}

export const Notifications = ({ userId }: NotificationsProps) => {
const { auth } = useUser()

const { data: notifications = [] } = useQuery({
...notificationQueries.list({ userId: auth.uid }),
select: (notifications) =>
notifications.filter(
(notification) => getNotificationPatientId(notification) === userId,
),
})

return <NotificationsTable notifications={notifications} />
}
3 changes: 2 additions & 1 deletion routes/~_dashboard/~patients/~$id/~index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { Allergies } from '@/routes/~_dashboard/~patients/~$id/Allergies'
import { Appointments } from '@/routes/~_dashboard/~patients/~$id/Appointments'
import { GenerateHealthSummary } from '@/routes/~_dashboard/~patients/~$id/GenerateHealthSummary'
import { Labs } from '@/routes/~_dashboard/~patients/~$id/Labs'
import { Notifications } from '@/routes/~_dashboard/~patients/~$id/Notifications'
import { DashboardLayout } from '../../DashboardLayout'

const getUserMedications = async (payload: {
Expand Down Expand Up @@ -212,7 +213,7 @@ const PatientPage = () => {
/>
</TabsContent>
<TabsContent value={PatientPageTab.notifications}>
notifications
<Notifications userId={userId} />
</TabsContent>
<TabsContent value={PatientPageTab.medications}>
<Medications
Expand Down

0 comments on commit efd1c8e

Please sign in to comment.