move utils files

This commit is contained in:
Giovanni committed 2025-12-17 14:16:08 +01:00
1 parent 883b9b6c4b
commit 0aaafed26a
13 files changed
+58 -9

No files matched your search

+25 -2
View File
@@ -1,8 +1,9 @@
import styles from "./Header.module.css" import styles from "./Header.module.css"
import { Link, NavLink } from "react-router"; import { Link, NavLink } from "react-router";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import getUserNotifications from "../../utils/getUserNotifications.js"; import getUserNotifications from "../../utils/notifications/getUserNotifications.js";
import getUser from "../../utils/getUser.js"; import getUser from "../../utils/getUser.js";
import deleteNotificationUser from "../../utils/notifications/deleteNotificationUser.js";
function Header() { function Header() {
const [notificationMenu, setnotificationMenu] = useState(false); const [notificationMenu, setnotificationMenu] = useState(false);
@@ -37,6 +38,28 @@ function Header() {
}; };
}, []); }, []);
async function deleteNotification(notificationId) {
try {
const user = await getUser();
const result = await deleteNotificationUser(user.id, notificationId);
console.log(result);
if (result) {
setNotifications(prev => prev.filter(n => n.id !== notificationId));
}
} catch (err) {
console.error('Erreur suppression notification :', err);
}
}
return ( return (
<div className={styles.headerContainer}> <div className={styles.headerContainer}>
<header className={`${styles.header} glassCard`}> <header className={`${styles.header} glassCard`}>
@@ -114,7 +137,7 @@ function Header() {
<p>{notification.content}</p> <p>{notification.content}</p>
<button <button
className={styles.closeBtn} className={styles.closeBtn}
onClick={() => setNotifications(prev => prev.filter((_, i) => i !== index))} onClick={() => deleteNotification(notification.id)}
> >
<img src="close.svg" alt="supprimer la notification"/> <img src="close.svg" alt="supprimer la notification"/>
</button> </button>
+2 -2
View File
@@ -1,8 +1,8 @@
import styles from "./SearchBar.module.css" import styles from "./SearchBar.module.css"
import {Link} from "react-router"; import {Link} from "react-router";
import {useEffect, useState} from "react"; import {useEffect, useState} from "react";
import searchEvents from "../../utils/searchEvents.js"; import searchEvents from "../../utils/events/searchEvents.js";
import searchUsers from "../../utils/searchUsers.js"; import searchUsers from "../../utils/users/searchUsers.js";
import { useLocation } from "react-router"; import { useLocation } from "react-router";
+1 -1
View File
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react"; import React, {useEffect, useState} from "react";
import getEventById from "../../utils/event/getEventById.js"; import getEventById from "../../utils/events/getEventById.js";
import styles from "./Task.module.css"; import styles from "./Task.module.css";
import formatDate from "../../utils/date/formatDate.js"; import formatDate from "../../utils/date/formatDate.js";
@@ -3,7 +3,7 @@ import { useState } from "react";
import Modal from "../ui/modal/modal.jsx"; import Modal from "../ui/modal/modal.jsx";
import Button from "../ui/button/button.jsx"; import Button from "../ui/button/button.jsx";
import TextInput from "../ui/input/input.jsx"; import TextInput from "../ui/input/input.jsx";
import createEvent from "../../utils/event/createEvent.js" import createEvent from "../../utils/events/createEvent.js"
export default function CreateEventBtn() { export default function CreateEventBtn() {
+1 -1
View File
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import Event from "../../components/Event/Event.jsx"; import Event from "../../components/Event/Event.jsx";
import styles from "./EventsPage.module.css"; import styles from "./EventsPage.module.css";
import ToolBar from "../../components/ToolBar/ToolBar.jsx"; import ToolBar from "../../components/ToolBar/ToolBar.jsx";
import getAllEvents from "../../utils/event/getAllEvents.js"; import getAllEvents from "../../utils/events/getAllEvents.js";
import filter from "../../utils/filter.js"; import filter from "../../utils/filter.js";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2 -2
View File
@@ -4,9 +4,9 @@ function filter(elements, filters, type) {
const dB = new Date(dateB); const dB = new Date(dateB);
if (filters.yearOrder === "asc") { if (filters.yearOrder === "asc") {
return dA - dB; // plus ancien -> plus récent return dA - dB;
} else { } else {
return dB - dA; // plus récent -> plus ancien return dB - dA;
} }
}; };
@@ -0,0 +1,26 @@
import getXSRFToken from "../getXSRF.js";
export default async function deleteNotificationUser(userId, notificationId) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/${userId}/delete/notification/${notificationId}`, {
method: 'DELETE',
credentials: 'include',
headers: {
'Accept': 'application/json',
'X-XSRF-TOKEN': csrfToken
}
});
if (!res.ok) {
throw new Error(`Erreur serveur : ${res.status}`);
}
const data = await res.json();
return data;
} catch (err) {
console.error('Erreur :', err);
return null;
}
}
File renamed without changes.