add read notifications route and update notifications behavior
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import Echo from "laravel-echo";
|
||||
import Pusher from "pusher-js";
|
||||
|
||||
window.Pusher = Pusher;
|
||||
|
||||
export default function initEcho() {
|
||||
const echoInstance = new Echo({
|
||||
broadcaster: import.meta.env.VITE_BROADCASTER,
|
||||
key: import.meta.env.VITE_REVERB_KEY,
|
||||
wsHost: import.meta.env.VITE_REVERB_HOST,
|
||||
wsPort: Number(import.meta.env.VITE_REVERB_PORT),
|
||||
forceTLS: import.meta.env.VITE_FORCE_TLS === 'true',
|
||||
disableStats: import.meta.env.VITE_DISABLE_STATS === 'true',
|
||||
encrypted: import.meta.env.VITE_ENCRYPTED === 'true',
|
||||
cluster: import.meta.env.VITE_CLUSTER,
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
});
|
||||
|
||||
window.Echo = echoInstance;
|
||||
return echoInstance;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
|
||||
export default async function readNotifications() {
|
||||
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
try {
|
||||
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/notifications/read`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-XSRF-TOKEN': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Erreur serveur : ${res.status}`);
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (err) {
|
||||
console.error('Erreur :', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user