Merge branch 'dev' into features/admin-assign
This commit is contained in:
commit
1c8332365b
40 files changed
+119
-259
No files matched your search
@@ -11,11 +11,11 @@ interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TextInput = ({
|
const TextInput = ({
|
||||||
placeholder,
|
placeholder = "",
|
||||||
onChange,
|
onChange,
|
||||||
value,
|
value = "",
|
||||||
borderStyle = "square",
|
borderStyle = "square",
|
||||||
password,
|
password = false,
|
||||||
className = "",
|
className = "",
|
||||||
...props
|
...props
|
||||||
}: TextInputProps) => {
|
}: TextInputProps) => {
|
||||||
@@ -28,15 +28,16 @@ const TextInput = ({
|
|||||||
setShowPassword((prev) => !prev);
|
setShowPassword((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (password)
|
if (password) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.passwordContainer}>
|
<div className={styles.passwordContainer}>
|
||||||
<TextInput
|
<input
|
||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
value={value}
|
value={value}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
className={styles.passwordInput}
|
className={`${styles.input} ${styles.passwordInput} ${inputBorderStyle} ${className}`}
|
||||||
|
{...props}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -47,6 +48,7 @@ const TextInput = ({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface User {
|
|||||||
|
|
||||||
export interface AuthContextType {
|
export interface AuthContextType {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
|
loading: boolean;
|
||||||
update: () => void;
|
update: () => void;
|
||||||
login: (email: string, password: string) => Promise<{ status: number }>;
|
login: (email: string, password: string) => Promise<{ status: number }>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
/*import { createContext } from "react";
|
|
||||||
|
|
||||||
export const EventContext = createContext(null);*/
|
|
||||||
|
|
||||||
|
|
||||||
import { createContext } from "react";
|
import { createContext } from "react";
|
||||||
|
|
||||||
export type Task = {
|
export type Task = {
|
||||||
|
|||||||
+4
-1
@@ -5,13 +5,16 @@ import Background from "./components/Background/Background.jsx";
|
|||||||
import { Navigate } from "react-router";
|
import { Navigate } from "react-router";
|
||||||
import { useContext} from "react";
|
import { useContext} from "react";
|
||||||
import { AuthContext } from "./contexts/Auth/AuthContext.js";
|
import { AuthContext } from "./contexts/Auth/AuthContext.js";
|
||||||
|
import Loading from "./components/ui/Loading/Loading.tsx";
|
||||||
|
|
||||||
|
|
||||||
function Layout(){
|
function Layout(){
|
||||||
|
|
||||||
const { user, loading } = useContext(AuthContext);
|
const { user, loading } = useContext(AuthContext);
|
||||||
|
|
||||||
if (loading) return <p>Loading</p>;
|
if (loading) return <Background>
|
||||||
|
<Loading />
|
||||||
|
</Background>;
|
||||||
if (!user) return <Navigate to="/login" />;
|
if (!user) return <Navigate to="/login" />;
|
||||||
if(user && user.validate === 0) return <Navigate to="/error/validation" />;
|
if(user && user.validate === 0) return <Navigate to="/error/validation" />;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import styles from "./AdminPage.module.css";
|
import styles from "./AdminPage.module.css";
|
||||||
import IncompleteEvents from "./components/IncompleteEvent/IncompleteEvent.jsx";
|
import IncompleteEvents from "./components/IncompleteEvent/IncompleteEvent";
|
||||||
import PendingMembers from "./components/PendingMembers/PendingMembers.jsx";
|
import PendingMembers from "./components/PendingMembers/PendingMembers";
|
||||||
import { AuthContext } from "../../contexts/Auth/AuthContext.js";
|
import { AuthContext } from "../../contexts/Auth/AuthContext";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import RegisterMember from "./components/RegisterMember/RegisterMember";
|
import RegisterMember from "./components/RegisterMember/RegisterMember";
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import deleteOtherUser from "../../../../utils/users/deleteOtherUser.js";
|
|||||||
import { PendingMembersContext } from "../../../../contexts/PendingMembers/PendingMembersContext";
|
import { PendingMembersContext } from "../../../../contexts/PendingMembers/PendingMembersContext";
|
||||||
|
|
||||||
function PendingMembers() {
|
function PendingMembers() {
|
||||||
|
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
|
|||||||
@@ -1,38 +1,3 @@
|
|||||||
/*import { useMemo } from "react";
|
|
||||||
import styles from "./eventList.module.css";
|
|
||||||
import EventItem from "./eventItem.jsx";
|
|
||||||
import { EventContext } from "../../../../contexts/events/EventContext.js";
|
|
||||||
import { useContext } from "react";
|
|
||||||
|
|
||||||
function EventList() {
|
|
||||||
// Utilise une valeur par défaut pour `events` si elle est `undefined`
|
|
||||||
const { events = [] } = useContext(EventContext);
|
|
||||||
|
|
||||||
const sortedEvents = useMemo(() => {
|
|
||||||
// Vérifie explicitement que `events` est un tableau avant de trier
|
|
||||||
if (!Array.isArray(events)) return [];
|
|
||||||
return [...events].sort(
|
|
||||||
(a, b) => new Date(a.start) - new Date(b.start)
|
|
||||||
);
|
|
||||||
}, [events]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`${styles.glassCard} glassCard`}>
|
|
||||||
<h2>Liste des événements à venir</h2>
|
|
||||||
{sortedEvents.length > 0 ? (
|
|
||||||
<div className={styles.eventList}>
|
|
||||||
{sortedEvents.map((eventGroup, index) => (
|
|
||||||
<EventItem eventGroup={eventGroup} key={index} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p>Aucun événement planifié pour l'instant.</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EventList;*/
|
|
||||||
import { useMemo, useContext } from "react";
|
import { useMemo, useContext } from "react";
|
||||||
import styles from "./EventList.module.css";
|
import styles from "./EventList.module.css";
|
||||||
import EventItem from "./EventItem";
|
import EventItem from "./EventItem";
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import styles from "./LoginPage.module.css";
|
||||||
|
import LoginForm from "./components/LoginForm/LoginForm";
|
||||||
|
import Background from "../../components/Background/Background.jsx";
|
||||||
|
import { useEffect, useContext } from "react";
|
||||||
|
import { AuthContext, AuthContextType } from "../../../src/contexts/Auth/AuthContext";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
|
||||||
|
function LoginPage() {
|
||||||
|
const { user, loading } = useContext(AuthContext) as AuthContextType;
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!loading && user) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}, [loading, user, navigate]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Background className="">
|
||||||
|
<div className={styles.container}>
|
||||||
|
<h1 className={styles.title}>Connexion</h1>
|
||||||
|
<LoginForm />
|
||||||
|
</div>
|
||||||
|
</Background>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginPage;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
/* Conteneur principal */
|
|
||||||
.container {
|
.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
@@ -113,7 +112,6 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Conteneur des informations principales */
|
|
||||||
.topDescription {
|
.topDescription {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -122,14 +120,12 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bloc d'informations */
|
|
||||||
.infoBlock {
|
.infoBlock {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Conteneur pour les paramètres */
|
|
||||||
.settingImage {
|
.settingImage {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -137,7 +133,6 @@
|
|||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adaptation pour tablette et PC */
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
.contentWrapper {
|
.contentWrapper {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import getXSRFToken from "../../utils/getXSRF.js";
|
||||||
import {useContext, useEffect, useState} from "react";
|
import {useContext, useEffect, useState} from "react";
|
||||||
import styles from "./ProfilePage.module.css";
|
import styles from "./ProfilePage.module.css";
|
||||||
import {AuthContext} from "../../contexts/Auth/AuthContext";
|
import {AuthContext} from "../../../src/contexts/Auth/AuthContext.js";
|
||||||
import formatDate from "../../utils/date/formatDate";
|
import formatDate from "../../utils/date/formatDate";
|
||||||
import Task from "../../components/Task/Task";
|
import Task from "../../components/Task/Task";
|
||||||
import SettingsModal from "./components/SettingsModal/SettingsModal";
|
import SettingsModal from "./components/SettingsModal/SettingsModal";
|
||||||
@@ -9,11 +10,9 @@ import {useNavigate} from "react-router";
|
|||||||
import {useRef} from "react";
|
import {useRef} from "react";
|
||||||
import getUserById from "../../utils/users/getUserById.js";
|
import getUserById from "../../utils/users/getUserById.js";
|
||||||
import ManageMember from "./components/ManageMember/ManageMember.jsx";
|
import ManageMember from "./components/ManageMember/ManageMember.jsx";
|
||||||
|
|
||||||
import uploadProfilePhoto from "../../utils/users/uploadProfilePhoto";
|
import uploadProfilePhoto from "../../utils/users/uploadProfilePhoto";
|
||||||
import deleteProfilePhoto from "../../utils/users/deleteProfilePhoto.js";
|
import deleteProfilePhoto from "../../utils/users/deleteProfilePhoto.js";
|
||||||
|
|
||||||
|
|
||||||
interface TaskType {
|
interface TaskType {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -56,14 +55,13 @@ function ProfilePage() {
|
|||||||
const { user, update } = useContext(AuthContext) as AuthContextType;
|
const { user, update } = useContext(AuthContext) as AuthContextType;
|
||||||
const [profileUser, setProfileUser] = useState<User | null>(null);
|
const [profileUser, setProfileUser] = useState<User | null>(null);
|
||||||
const [profilePicture, setProfilePicture] = useState<string | null>(null);
|
const [profilePicture, setProfilePicture] = useState<string | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [success, setSuccess] = useState<string | null>(null);
|
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const isOwnProfile = !id || user?.id.toString() === id;
|
const isOwnProfile = !id || user?.id.toString() === id;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
console.log(JSON.stringify(import.meta.env.VITE_API_URL));
|
||||||
if (!isOwnProfile && id) {
|
if (!isOwnProfile && id) {
|
||||||
const res = await getUserById(id);
|
const res = await getUserById(id);
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
@@ -71,12 +69,11 @@ function ProfilePage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
console.error("Erreur lors du chargement du profil", res);
|
console.log("Erreur lors du chargement du profil", res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setProfileUser(res.data);
|
setProfileUser(res.data);
|
||||||
} else {
|
} else {
|
||||||
update();
|
|
||||||
setProfileUser(user);
|
setProfileUser(user);
|
||||||
if (user?.profile_photo_path) {
|
if (user?.profile_photo_path) {
|
||||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${user.profile_photo_path}`);
|
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${user.profile_photo_path}`);
|
||||||
@@ -91,7 +88,6 @@ function ProfilePage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remplacé : handleFileChange extrait vers utils/users/uploadProfilePhoto
|
|
||||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
@@ -100,36 +96,19 @@ function ProfilePage() {
|
|||||||
const res = await uploadProfilePhoto(file);
|
const res = await uploadProfilePhoto(file);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${res.data.profile_photo_path}`);
|
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${res.data.profile_photo_path}`);
|
||||||
setSuccess("Photo mise à jour !");
|
console.log("Photo mise à jour")
|
||||||
setError(null);
|
|
||||||
await update();
|
await update();
|
||||||
} else {
|
} else {
|
||||||
setError(res.data?.message || res.error || "Erreur lors de l'upload.");
|
console.log(res.data?.message || res.error || "Erreur lors de l'upload.");
|
||||||
setSuccess(null);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError("Erreur réseau.");
|
console.log("Erreur réseau.");
|
||||||
setSuccess(null);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remplacé : handleDeletePicture extrait vers utils/users/deleteProfilePhoto
|
|
||||||
const handleDeletePicture = async () => {
|
const handleDeletePicture = async () => {
|
||||||
try {
|
|
||||||
const res = await deleteProfilePhoto();
|
deleteProfilePhoto();
|
||||||
if (res.status >= 200 && res.status < 300) {
|
|
||||||
setProfilePicture(null);
|
setProfilePicture(null);
|
||||||
setSuccess("Photo supprimée !");
|
|
||||||
setError(null);
|
|
||||||
await update();
|
|
||||||
} else {
|
|
||||||
setError(res.data?.message || "Erreur lors de la suppression.");
|
|
||||||
setSuccess(null);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError("Erreur réseau.");
|
|
||||||
setSuccess(null);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -150,7 +129,7 @@ function ProfilePage() {
|
|||||||
Modifier la photo
|
Modifier la photo
|
||||||
</button>
|
</button>
|
||||||
{user?.profile_photo_path && (
|
{user?.profile_photo_path && (
|
||||||
<button onClick={handleDeletePicture} className={styles.deletePictureButton}>
|
<button onClick={handleDeletePicture} className={styles.editPictureButton}>
|
||||||
Supprimer
|
Supprimer
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -164,8 +143,6 @@ function ProfilePage() {
|
|||||||
accept="image/*"
|
accept="image/*"
|
||||||
style={{ display: "none" }}
|
style={{ display: "none" }}
|
||||||
/>
|
/>
|
||||||
{error && <p className={styles.errorMessage}>{error}</p>}
|
|
||||||
{success && <p className={styles.successMessage}>{success}</p>}
|
|
||||||
|
|
||||||
<div className={styles.description}>
|
<div className={styles.description}>
|
||||||
<div className={styles.headerProfile}>
|
<div className={styles.headerProfile}>
|
||||||
@@ -180,8 +157,7 @@ function ProfilePage() {
|
|||||||
<div className={styles.topDescription}>
|
<div className={styles.topDescription}>
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
<div className={`${styles.infoBlock} glassBorder`}>
|
||||||
<p><strong>Role :</strong> {profileUser?.role}</p>
|
<p><strong>Role :</strong> {profileUser?.role}</p>
|
||||||
<p><strong>Membre depuis :</strong> {profileUser && formatDate(profileUser.created_at)}
|
<p><strong>Membre depuis :</strong> {profileUser && formatDate(profileUser.created_at)}</p>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
<div className={`${styles.infoBlock} glassBorder`}>
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
|
||||||
import getXSRFToken from "../getXSRF.js";
|
|
||||||
|
|
||||||
export default async function login(email, password) {
|
|
||||||
const csrfToken = await getXSRFToken();
|
|
||||||
|
|
||||||
return fetchWrapper(
|
|
||||||
"/api/users/login",
|
|
||||||
{ email, password },
|
|
||||||
"POST",
|
|
||||||
{ "X-XSRF-TOKEN": csrfToken }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default async function login(email: string, password: string) {
|
||||||
|
const csrfToken: string = await getXSRFToken();
|
||||||
|
return fetchWrapper(
|
||||||
|
"/api/users/login",
|
||||||
|
{ email, password },
|
||||||
|
"POST",
|
||||||
|
{ "X-XSRF-TOKEN": csrfToken }
|
||||||
|
);
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -1,35 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
/*export function formatDateLetter(d) {
|
|
||||||
if (!d) return "Date inconnue";
|
|
||||||
|
|
||||||
const dateObj = new Date(d);
|
|
||||||
if (isNaN(dateObj.getTime())) return "Date invalide";
|
|
||||||
|
|
||||||
const monthNames = [
|
|
||||||
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
|
|
||||||
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
|
|
||||||
];
|
|
||||||
|
|
||||||
const day = dateObj.getDate().toString().padStart(2, "0");
|
|
||||||
const month = monthNames[dateObj.getMonth()];
|
|
||||||
const year = dateObj.getFullYear();
|
|
||||||
const hours = dateObj.getHours().toString().padStart(2, "0");
|
|
||||||
const minutes = dateObj.getMinutes().toString().padStart(2, "0");
|
|
||||||
|
|
||||||
return `${day} ${month} ${year} à ${hours}:${minutes}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function formatDateLetterJS(d) {
|
|
||||||
const monthNames = [
|
|
||||||
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
|
|
||||||
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
|
|
||||||
];
|
|
||||||
const [year, month, day] = d.split('-');
|
|
||||||
return `${day} ${monthNames[parseInt(month) - 1]} ${year}`;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
export function formatDateLetter(d: string | Date | null | undefined): string {
|
export function formatDateLetter(d: string | Date | null | undefined): string {
|
||||||
if (!d) return "Date inconnue";
|
if (!d) return "Date inconnue";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function createEvent(name, description, start, end) {
|
export default async function createEvent(name:string, description:string, start:string, end:string) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function deleteEvent(eventId) {
|
export default async function deleteEvent(eventId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
export default async function getAllEvents() {
|
export default async function getAllEvents() {
|
||||||
return fetchWrapper("/api/events/", null, "GET");
|
return fetchWrapper("/api/events/", null, "GET");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
export default async function GetEventById(id) {
|
export default async function GetEventById(id) {
|
||||||
return fetchWrapper(`/api/events/${id}`, null, "GET");
|
return fetchWrapper(`/api/events/${id}`, null, "GET");
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
|
export default async function GetEventById(id:number) {
|
||||||
|
return fetchWrapper(`/api/events/${id}`, null, "GET");
|
||||||
|
}
|
||||||
@@ -1,44 +1,3 @@
|
|||||||
/*export default async function fetchWrapper(path,data = null,method = "GET",headers = {}) {
|
|
||||||
try {
|
|
||||||
const res = await fetch(
|
|
||||||
`${import.meta.env.VITE_API_URL}${path}`,
|
|
||||||
{
|
|
||||||
method,
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
"Accept": "application/json",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
...headers,
|
|
||||||
},
|
|
||||||
body: data ? JSON.stringify(data) : null,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let responseData = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
responseData = await res.json();
|
|
||||||
} catch (_) {
|
|
||||||
responseData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: res.status,
|
|
||||||
data: responseData,
|
|
||||||
};
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error("❌ Erreur réseau :", err);
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: 0,
|
|
||||||
data: {
|
|
||||||
message: "Network error",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
interface FetchResponse<T = any> {
|
interface FetchResponse<T = any> {
|
||||||
status: number;
|
status: number;
|
||||||
data: T | null;
|
data: T | null;
|
||||||
@@ -79,7 +38,7 @@ export default async function fetchWrapper(
|
|||||||
};
|
};
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ Erreur réseau :", err);
|
console.error("Erreur réseau :", err);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 0,
|
status: 0,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "./fetchWrapper.js";
|
import fetchWrapper from "./fetchWrapper";
|
||||||
|
|
||||||
export default async function getRoles() {
|
export default async function getRoles() {
|
||||||
return fetchWrapper("/api/roles", null, "GET");
|
return fetchWrapper("/api/roles", null, "GET");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "./fetchWrapper.js";
|
import fetchWrapper from "./fetchWrapper";
|
||||||
|
|
||||||
export default async function getUser() {
|
export default async function getUser() {
|
||||||
return fetchWrapper("/api/users/me", null, "GET");
|
return fetchWrapper("/api/users/me", null, "GET");
|
||||||
@@ -1,23 +1,3 @@
|
|||||||
/*export default async function getXSRFToken() {
|
|
||||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/sanctum/csrf-cookie`, {
|
|
||||||
method: 'GET',
|
|
||||||
credentials: 'include'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok && response.status !== 204) {
|
|
||||||
throw new Error(`Error : ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = 'XSRF-TOKEN';
|
|
||||||
const value = `; ${document.cookie}`;
|
|
||||||
const parts = value.split(`; ${name}=`);
|
|
||||||
if (parts.length === 2) {
|
|
||||||
return decodeURIComponent(parts.pop().split(';').shift());
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('Error: Invalid XSRF-TOKEN');
|
|
||||||
}*/
|
|
||||||
|
|
||||||
export default async function getXSRFToken(): Promise<string> {
|
export default async function getXSRFToken(): Promise<string> {
|
||||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/sanctum/csrf-cookie`, {
|
const response = await fetch(`${import.meta.env.VITE_API_URL}/sanctum/csrf-cookie`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function deleteNotificationUser(notificationId) {
|
export default async function deleteNotificationUser(notificationId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function readNotifications() {
|
export default async function readNotifications() {
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "./fetchWrapper.js";
|
import fetchWrapper from "./fetchWrapper";
|
||||||
import getXSRFToken from "./getXSRF.js";
|
import getXSRFToken from "./getXSRF";
|
||||||
|
|
||||||
export default async function register(email, password, name, lastname, phone) {
|
export default async function register(email:string, password:string, name:string, lastname:string, phone:string) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
File renamed without changes.
@@ -1,8 +1,8 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
import Response from "../../interfaces/response.interface";
|
import Response from "../../interfaces/response.interface";
|
||||||
|
|
||||||
export default async function adminCreateUser(email: string, name: string, lastname: string, phone: string): Promise<Response> {
|
export default async function adminCreateUser(email: string, name: string, lastname: string, phone: string) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function deactivateUser(userId) {
|
export default async function deactivateUser(userId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function deleteOtherUser(userId) {
|
export default async function deleteOtherUser(userId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function deleteProfilePhoto(): Promise<{ status: number; ok: boolean; data?: any; error?: string }> {
|
export default async function deleteProfilePhoto(): Promise<{ status: number; ok: boolean; data?: any; error?: string }> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
export default async function getAllUser() {
|
export default async function getAllUser() {
|
||||||
return fetchWrapper("/api/users");
|
return fetchWrapper("/api/users");
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
export default async function getUserById(id) {
|
export default async function getUserById(id) {
|
||||||
return fetchWrapper(`/api/users/${id}`);
|
return fetchWrapper(`/api/users/${id}`);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
|
export default async function getUserById(id:number) {
|
||||||
|
return fetchWrapper(`/api/users/${id}`);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
|
|
||||||
export default async function getUserToValidate() {
|
export default async function getUserToValidate() {
|
||||||
return fetchWrapper("/api/users/invalid");
|
return fetchWrapper("/api/users/invalid");
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function modifyRole(role, userId) {
|
export default async function modifyRole(role:number, userId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
@@ -1,33 +1,12 @@
|
|||||||
/*import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function updateUser(name, lastname, phone) {
|
export default async function updateUser(name: string, lastname: string, phone: string | null) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
"/api/users/update",
|
"/api/users/update",
|
||||||
{ name, lastname, phone },
|
{ name, lastname, phone },
|
||||||
"POST",
|
"POST",
|
||||||
{ "X-XSRF-TOKEN": csrfToken }
|
{ "X-XSRF-TOKEN": csrfToken }
|
||||||
);
|
);
|
||||||
}*/
|
|
||||||
|
|
||||||
import fetchWrapper from "../fetchWrapper";
|
|
||||||
import getXSRFToken from "../getXSRF";
|
|
||||||
|
|
||||||
interface UserUpdateData {
|
|
||||||
name: string;
|
|
||||||
lastname: string;
|
|
||||||
phone: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RequestHeaders {
|
|
||||||
"X-XSRF-TOKEN": string;
|
|
||||||
}
|
|
||||||
export default async function updateUser(name: string,lastname: string,phone: string | null): Promise<Response> {
|
|
||||||
const csrfToken: string = await getXSRFToken();
|
|
||||||
const userData: UserUpdateData = {name,lastname,phone,};
|
|
||||||
const headers: RequestHeaders = {"X-XSRF-TOKEN": csrfToken,};
|
|
||||||
return fetchWrapper("/api/users/update",userData,"POST",headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function uploadProfilePhoto(file: File): Promise<{ status: number; ok: boolean; data?: any; error?: string }> {
|
export default async function uploadProfilePhoto(file: File): Promise<{ status: number; ok: boolean; data?: any; error?: string }> {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fetchWrapper from "../fetchWrapper.js";
|
import fetchWrapper from "../fetchWrapper";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF";
|
||||||
|
|
||||||
export default async function validateUser(userId) {
|
export default async function validateUser(userId:number) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
return fetchWrapper(
|
return fetchWrapper(
|
||||||
Reference in new issue
Block a user