From 59a205f0805ed45b1fc1c3bc58dae8a17bc6ecaf Mon Sep 17 00:00:00 2001 From: Bhavik Agarwal <73033511+Bhavik-ag@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:29:49 +0530 Subject: [PATCH] added warning on doctor notes usage if not subscribed (#7224) * added warning on doctor notes usage if not subscribed * removing unnecessary console logs --- .../Facility/PatientNotesSlideover.tsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Components/Facility/PatientNotesSlideover.tsx b/src/Components/Facility/PatientNotesSlideover.tsx index 8943d7fe21a..2e04312d277 100644 --- a/src/Components/Facility/PatientNotesSlideover.tsx +++ b/src/Components/Facility/PatientNotesSlideover.tsx @@ -12,6 +12,8 @@ import routes from "../../Redux/api"; import { PatientNoteStateType } from "./models"; import useKeyboardShortcut from "use-keyboard-shortcut"; import AutoExpandingTextInputFormField from "../Form/FormFields/AutoExpandingTextInputFormField.js"; +import * as Sentry from "@sentry/browser"; +import useAuthUser from "../../Common/hooks/useAuthUser"; interface PatientNotesProps { patientId: string; @@ -26,6 +28,33 @@ export default function PatientNotesSlideover(props: PatientNotesProps) { const [reload, setReload] = useState(false); const [focused, setFocused] = useState(false); + const { username } = useAuthUser(); + + const intialSubscriptionState = async () => { + try { + const res = await request(routes.getUserPnconfig, { + pathParams: { username }, + }); + const reg = await navigator.serviceWorker.ready; + const subscription = await reg.pushManager.getSubscription(); + if (!subscription && !res.data?.pf_endpoint) { + Notification.Warn({ + msg: "Please subscribe to notifications to get live updates on doctor notes.", + }); + } else if (subscription?.endpoint !== res.data?.pf_endpoint) { + Notification.Warn({ + msg: "Please subscribe to notifications on this device to get live updates on doctor notes.", + }); + } + } catch (error) { + Sentry.captureException(error); + } + }; + + useEffect(() => { + intialSubscriptionState(); + }, []); + const initialData: PatientNoteStateType = { notes: [], cPage: 1,