Skip to content

Commit

Permalink
Fix: TypeError in notification list (ohcnetwork#8935)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 authored and Rishith25 committed Nov 25, 2024
1 parent 71c9f9b commit f665dbc
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions src/components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ export default function NotificationsList({

const handleSubscribeClick = () => {
const status = isSubscribed;
if (status === "NotSubscribed" || status === "SubscribedOnAnotherDevice") {
if (!navigator.serviceWorker) {
return;
}
if (["NotSubscribed", "SubscribedOnAnotherDevice"].includes(status)) {
if (Notification.permission === "denied") {
Warn({
msg: t("notification_permission_denied"),
Expand Down Expand Up @@ -286,49 +289,47 @@ export default function NotificationsList({

let manageResults: any = null;

const unsubscribe = () => {
navigator.serviceWorker.ready
.then(function (reg) {
setIsSubscribing(true);
reg.pushManager
.getSubscription()
.then(function (subscription) {
subscription
?.unsubscribe()
.then(async function (_successful) {
const data = {
pf_endpoint: "",
pf_p256dh: "",
pf_auth: "",
};

await request(routes.updateUserPnconfig, {
pathParams: { username: username },
body: data,
});

Warn({
msg: t("unsubscribed_successfully"),
});

setIsSubscribed("NotSubscribed");
setIsSubscribing(false);
})
.catch(function (_e) {
Error({
msg: t("unsubscribe_failed"),
});
});
})
.catch(function (_e) {
Error({ msg: t("subscription_error") });
const unsubscribe = async () => {
try {
const reg = await navigator.serviceWorker.ready;

if (!reg.pushManager) {
Error({ msg: t("unsubscribe_failed") });
return;
}

setIsSubscribing(true);

const subscription = await reg.pushManager.getSubscription();

if (subscription) {
try {
await subscription.unsubscribe();

await request(routes.updateUserPnconfig, {
pathParams: { username },
body: {
pf_endpoint: "",
pf_p256dh: "",
pf_auth: "",
},
});
})
.catch(function (_e) {
Sentry.captureException(_e);
});
};

setIsSubscribed("NotSubscribed");
Warn({
msg: t("unsubscribed_successfully"),
});
} catch (e) {
Error({ msg: t("unsubscribe_failed") });
}
}
} catch (e) {
Sentry.captureException(e);
Error({ msg: t("subscription_error") });
} finally {
setIsSubscribing(false);
}
};
async function subscribe() {
setIsSubscribing(true);
try {
Expand Down

0 comments on commit f665dbc

Please sign in to comment.