-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace useDispatch w. useQuery/request: Notifications (src/Component…
…s/Notifications/**) #6392 (#6543) * Add only imports. other functionality and changes in code to be complited later * ShowPushNotification - change useDispatch with useQuery, old code is on the comments, add model.tsx in to folder notifications and add references into api.tsx * Complete ShowPushNotification.tsx and NoticeBoard.tsx - change useDispatch with useQuery * Complete ShowPushNotification.tsx and NoticeBoard.tsx - change useDispatch with useQuery, delete all commnets of old code * Complete NotificationsList.tsx - change useDispatch with useQuery, delete all commnets of old code * deleting all comments * code modification according to requests * back the original content of package-lock.json from origin branch --------- Co-authored-by: Adrián Sliva <[email protected]>
- Loading branch information
1 parent
e8091bf
commit bf932d5
Showing
6 changed files
with
106 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
import { useDispatch } from "react-redux"; | ||
import { getNotificationData } from "../../Redux/actions"; | ||
import { useEffect } from "react"; | ||
import { DetailRoute } from "../../Routers/types"; | ||
import useQuery from "../../Utils/request/useQuery"; | ||
import routes from "../../Redux/api"; | ||
import { NotificationData } from "./models"; | ||
|
||
export default function ShowPushNotification({ id }: DetailRoute) { | ||
const dispatch: any = useDispatch(); | ||
useQuery(routes.getNotificationData, { | ||
pathParams: { id }, | ||
onResponse(res) { | ||
if (res.data) { | ||
window.location.href = resultUrl(res.data); | ||
} | ||
}, | ||
}); | ||
|
||
const resultUrl = async () => { | ||
const res = await dispatch(getNotificationData({ id })); | ||
const data = res.data.caused_objects; | ||
switch (res.data.event) { | ||
const resultUrl = ({ caused_objects, event }: NotificationData) => { | ||
switch (event) { | ||
case "PATIENT_CREATED": | ||
return `/facility/${data.facility}/patient/${data.patient}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}`; | ||
case "PATIENT_UPDATED": | ||
return `/facility/${data.facility}/patient/${data.patient}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}`; | ||
case "PATIENT_CONSULTATION_CREATED": | ||
return `/facility/${data.facility}/patient/${data.patient}/consultation/${data.consultation}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}/consultation/${caused_objects?.consultation}`; | ||
case "PATIENT_CONSULTATION_UPDATED": | ||
return `/facility/${data.facility}/patient/${data.patient}/consultation/${data.consultation}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}/consultation/${caused_objects?.consultation}`; | ||
case "PATIENT_CONSULTATION_UPDATE_CREATED": | ||
return `/facility/${data.facility}/patient/${data.patient}/consultation/${data.consultation}/daily-rounds/${data.daily_round}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}/consultation/${caused_objects?.consultation}/daily-rounds/${caused_objects?.daily_round}`; | ||
case "PATIENT_CONSULTATION_UPDATE_UPDATED": | ||
return `/facility/${data.facility}/patient/${data.patient}/consultation/${data.consultation}/daily-rounds/${data.daily_round}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}/consultation/${caused_objects?.consultation}/daily-rounds/${caused_objects?.daily_round}`; | ||
case "INVESTIGATION_SESSION_CREATED": | ||
return `/facility/${data.facility}/patient/${data.patient}/consultation/${data.consultation}/investigation/${data.session}`; | ||
return `/facility/${caused_objects?.facility}/patient/${caused_objects?.patient}/consultation/${caused_objects?.consultation}/investigation/${caused_objects?.session}`; | ||
case "MESSAGE": | ||
return "/notice_board/"; | ||
default: | ||
return "#"; | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
resultUrl() | ||
.then((url) => { | ||
window.location.href = url; | ||
}) | ||
.catch((err) => console.log(err)); | ||
}, []); | ||
|
||
return <></>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export interface NotificationData { | ||
id: string; | ||
title: string; | ||
caused_objects: cause_object; | ||
caused_by: any; | ||
content: string; | ||
offset: number; | ||
event: string; | ||
event_type: string; | ||
medium_sent: string; | ||
created_date: string; | ||
read_at: string; | ||
message: string; | ||
public_key: string; | ||
} | ||
|
||
export interface cause_object { | ||
facility: string; | ||
patient: string; | ||
consultation: string; | ||
daily_round: string; | ||
session: string; | ||
} | ||
|
||
export interface PNconfigData { | ||
pf_auth: string; | ||
pf_endpoint: string; | ||
pf_p256dh: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters