Compare commits
2 commits
67407a1426
...
aa88fbda44
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa88fbda44 | ||
|
|
2e12b2cec7 |
1 changed files with 13 additions and 5 deletions
|
|
@ -98,7 +98,10 @@ export default function NotificationSettings() {
|
|||
try {
|
||||
const result = await registerNotification();
|
||||
if ("error" in result && result.error) {
|
||||
console.error("Failed to unregister previous notifications:", result.error);
|
||||
console.error(
|
||||
"Failed to unregister previous notifications:",
|
||||
result.error
|
||||
);
|
||||
} else {
|
||||
setPushEnabled(true);
|
||||
}
|
||||
|
|
@ -129,10 +132,15 @@ export default function NotificationSettings() {
|
|||
|
||||
const currentSubscriptionId = localStorage.getItem(STORAGE_KEY);
|
||||
const currentSubscription = notifications.find(
|
||||
(sub) => sub.id === currentSubscriptionId
|
||||
(sub) => sub.id.toString() === currentSubscriptionId
|
||||
);
|
||||
useEffect(() => {
|
||||
setEvents(currentSubscription?.events || []);
|
||||
// Remove pushEnabled if no current subscription (i.e., user unsubscribed)
|
||||
if (!isLoading && !isError && pushEnabled && !currentSubscription) {
|
||||
setPushEnabled(false);
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
}, [currentSubscription]);
|
||||
|
||||
async function handleDelete(subscriptionId: string) {
|
||||
|
|
@ -221,9 +229,9 @@ export default function NotificationSettings() {
|
|||
{currentSubscription && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Select Notification Events</CardTitle>
|
||||
<CardTitle>Configurer vos notifications</CardTitle>
|
||||
<CardDescription>
|
||||
Choose which events you want to receive notifications for
|
||||
Choisissez les événements qui déclencheront une notification.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
|
|
@ -257,7 +265,7 @@ export default function NotificationSettings() {
|
|||
onClick={() =>
|
||||
updateSubscription(
|
||||
currentSubscription.id,
|
||||
events.map((event) => event.id)
|
||||
events.filter((e) => e.enabled).map((e) => e.id)
|
||||
)
|
||||
.then(() => {
|
||||
toast.success(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue