Skip to content

Commit

Permalink
Merge pull request #1040 from The-Commit-Company/push-notification-pr…
Browse files Browse the repository at this point in the history
…omise-toast

fix: show loading toast when enabling push notifications
  • Loading branch information
nikkothari22 authored Aug 31, 2024
2 parents 5172c99 + 23c3247 commit d77e527
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ const PushNotificationToggle = (props: Props) => {
}

const enablePushNotifications = async () => {
// @ts-expect-error
window.frappePushNotification
.enableNotification()
.then((data: any) => {
if (data.permission_granted) {
setPushNotificationsEnabled(true)
toast.success("Push notifications enabled")
} else {
toast.error("Permission denied for push notifications")


toast.promise(
// @ts-expect-error
window.frappePushNotification
.enableNotification()
.then((data: any) => {
if (data.permission_granted) {
setPushNotificationsEnabled(true)
} else {
setPushNotificationsEnabled(false)
throw new Error("Permission denied for push notifications")
}
})
.catch((error: any) => {
setPushNotificationsEnabled(false)
}
})
.catch((error: any) => {
toast.error("Error enabling push notifications", {
description: getErrorMessage(error)
throw error
})
setPushNotificationsEnabled(false)
, {
success: "Push notifications enabled",
loading: "Enabling...",
error: (e: Error) => e.message
})
}

Expand Down

0 comments on commit d77e527

Please sign in to comment.