Skip to content

Commit 146b394

Browse files
committed
refactor: enhance error handling in NotificationSettings for push notifications
1 parent c34d1d8 commit 146b394

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/components/notification-settings.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ const NotificationSettingsContent = ({
121121
valuePropName: "checked",
122122
})(
123123
<Checkbox
124-
onChange={(e) => {
125-
if (e.target.checked) askPermission();
124+
onChange={async (e) => {
125+
if (e.target.checked) {
126+
try {
127+
await askPermission();
128+
} catch (err) {
129+
form.setFieldsValue({ pushNotifications: false });
130+
}
131+
}
126132
}}
127133
placeholder="PushNotifications"
128134
>
@@ -199,7 +205,12 @@ const NotificationSettings = Form.create()(({ form, settings: { key: settingsKey
199205
const { email, fullName, phone, pushNotifications, ...rest } = values;
200206
let pushNotificationsData;
201207
if (pushNotifications) {
202-
pushNotificationsData = await subscribeUserToPush();
208+
try {
209+
pushNotificationsData = await subscribeUserToPush();
210+
} catch (e) {
211+
setUserSettingsPatchState({ error: e?.message || "Failed to enable push notifications." });
212+
return;
213+
}
203214
}
204215
setLoadingUserSettingsPatch(true);
205216
try {

0 commit comments

Comments
 (0)