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 {
|
try {
|
||||||
const result = await registerNotification();
|
const result = await registerNotification();
|
||||||
if ("error" in result && result.error) {
|
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 {
|
} else {
|
||||||
setPushEnabled(true);
|
setPushEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
@ -129,10 +132,15 @@ export default function NotificationSettings() {
|
||||||
|
|
||||||
const currentSubscriptionId = localStorage.getItem(STORAGE_KEY);
|
const currentSubscriptionId = localStorage.getItem(STORAGE_KEY);
|
||||||
const currentSubscription = notifications.find(
|
const currentSubscription = notifications.find(
|
||||||
(sub) => sub.id === currentSubscriptionId
|
(sub) => sub.id.toString() === currentSubscriptionId
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEvents(currentSubscription?.events || []);
|
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]);
|
}, [currentSubscription]);
|
||||||
|
|
||||||
async function handleDelete(subscriptionId: string) {
|
async function handleDelete(subscriptionId: string) {
|
||||||
|
|
@ -221,9 +229,9 @@ export default function NotificationSettings() {
|
||||||
{currentSubscription && (
|
{currentSubscription && (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Select Notification Events</CardTitle>
|
<CardTitle>Configurer vos notifications</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Choose which events you want to receive notifications for
|
Choisissez les événements qui déclencheront une notification.
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
|
|
@ -257,7 +265,7 @@ export default function NotificationSettings() {
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
updateSubscription(
|
updateSubscription(
|
||||||
currentSubscription.id,
|
currentSubscription.id,
|
||||||
events.map((event) => event.id)
|
events.filter((e) => e.enabled).map((e) => e.id)
|
||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success(
|
toast.success(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue