Merge branch 'dev' into features/admin-assign
This commit is contained in:
@@ -11,14 +11,14 @@ interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
}
|
||||
|
||||
const TextInput = ({
|
||||
placeholder,
|
||||
onChange,
|
||||
value,
|
||||
borderStyle = "square",
|
||||
password,
|
||||
className = "",
|
||||
...props
|
||||
}: TextInputProps) => {
|
||||
placeholder = "",
|
||||
onChange,
|
||||
value = "",
|
||||
borderStyle = "square",
|
||||
password = false,
|
||||
className = "",
|
||||
...props
|
||||
}: TextInputProps) => {
|
||||
const [showPassword, setShowPassword] = useState<boolean>(false);
|
||||
|
||||
let inputBorderStyle = styles.square;
|
||||
@@ -28,15 +28,16 @@ const TextInput = ({
|
||||
setShowPassword((prev) => !prev);
|
||||
};
|
||||
|
||||
if (password)
|
||||
if (password) {
|
||||
return (
|
||||
<div className={styles.passwordContainer}>
|
||||
<TextInput
|
||||
<input
|
||||
type={showPassword ? "text" : "password"}
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
onChange={onChange}
|
||||
className={styles.passwordInput}
|
||||
className={`${styles.input} ${styles.passwordInput} ${inputBorderStyle} ${className}`}
|
||||
{...props}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
@@ -47,6 +48,7 @@ const TextInput = ({
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<input
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface User {
|
||||
|
||||
export interface AuthContextType {
|
||||
user: User | null;
|
||||
loading: boolean;
|
||||
update: () => void;
|
||||
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";
|
||||
|
||||
export type Task = {
|
||||
|
||||
+4
-1
@@ -5,13 +5,16 @@ import Background from "./components/Background/Background.jsx";
|
||||
import { Navigate } from "react-router";
|
||||
import { useContext} from "react";
|
||||
import { AuthContext } from "./contexts/Auth/AuthContext.js";
|
||||
import Loading from "./components/ui/Loading/Loading.tsx";
|
||||
|
||||
|
||||
function Layout(){
|
||||
|
||||
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 && user.validate === 0) return <Navigate to="/error/validation" />;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useContext } from "react";
|
||||
import styles from "./AdminPage.module.css";
|
||||
import IncompleteEvents from "./components/IncompleteEvent/IncompleteEvent.jsx";
|
||||
import PendingMembers from "./components/PendingMembers/PendingMembers.jsx";
|
||||
import { AuthContext } from "../../contexts/Auth/AuthContext.js";
|
||||
import IncompleteEvents from "./components/IncompleteEvent/IncompleteEvent";
|
||||
import PendingMembers from "./components/PendingMembers/PendingMembers";
|
||||
import { AuthContext } from "../../contexts/Auth/AuthContext";
|
||||
import { useNavigate } from "react-router";
|
||||
import RegisterMember from "./components/RegisterMember/RegisterMember";
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ import deleteOtherUser from "../../../../utils/users/deleteOtherUser.js";
|
||||
import { PendingMembersContext } from "../../../../contexts/PendingMembers/PendingMembersContext";
|
||||
|
||||
function PendingMembers() {
|
||||
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [message, setMessage] = 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 styles from "./EventList.module.css";
|
||||
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 {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
@@ -113,7 +112,6 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Conteneur des informations principales */
|
||||
.topDescription {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -122,14 +120,12 @@
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Bloc d'informations */
|
||||
.infoBlock {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Conteneur pour les paramètres */
|
||||
.settingImage {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
@@ -137,7 +133,6 @@
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
/* Adaptation pour tablette et PC */
|
||||
@media (min-width: 768px) {
|
||||
.contentWrapper {
|
||||
flex-direction: row;
|
||||
|
||||
+137
-161
@@ -1,6 +1,7 @@
|
||||
import getXSRFToken from "../../utils/getXSRF.js";
|
||||
import {useContext, useEffect, useState} from "react";
|
||||
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 Task from "../../components/Task/Task";
|
||||
import SettingsModal from "./components/SettingsModal/SettingsModal";
|
||||
@@ -9,26 +10,24 @@ import {useNavigate} from "react-router";
|
||||
import {useRef} from "react";
|
||||
import getUserById from "../../utils/users/getUserById.js";
|
||||
import ManageMember from "./components/ManageMember/ManageMember.jsx";
|
||||
|
||||
import uploadProfilePhoto from "../../utils/users/uploadProfilePhoto";
|
||||
import deleteProfilePhoto from "../../utils/users/deleteProfilePhoto.js";
|
||||
|
||||
|
||||
interface TaskType {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
location: string;
|
||||
start: string;
|
||||
end: string;
|
||||
max_participants: number;
|
||||
events_id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
pivot: {
|
||||
user_id: number;
|
||||
task_id: number;
|
||||
};
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
location: string;
|
||||
start: string;
|
||||
end: string;
|
||||
max_participants: number;
|
||||
events_id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
pivot: {
|
||||
user_id: number;
|
||||
task_id: number;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -51,162 +50,139 @@ interface AuthContextType {
|
||||
}
|
||||
|
||||
function ProfilePage() {
|
||||
const navigate = useNavigate();
|
||||
const {id} = useParams();
|
||||
const {user, update} = useContext(AuthContext) as AuthContextType;
|
||||
const [profileUser, setProfileUser] = useState<User | 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 navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const { user, update } = useContext(AuthContext) as AuthContextType;
|
||||
const [profileUser, setProfileUser] = useState<User | null>(null);
|
||||
const [profilePicture, setProfilePicture] = useState<string | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const isOwnProfile = !id || user?.id.toString() === id;
|
||||
const isOwnProfile = !id || user?.id.toString() === id;
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!isOwnProfile && id) {
|
||||
const res = await getUserById(id);
|
||||
if (res.status === 404) {
|
||||
navigate("/404");
|
||||
return;
|
||||
}
|
||||
if (res.status !== 200) {
|
||||
console.error("Erreur lors du chargement du profil", res);
|
||||
return;
|
||||
}
|
||||
setProfileUser(res.data);
|
||||
} else {
|
||||
update();
|
||||
setProfileUser(user);
|
||||
if (user?.profile_photo_path) {
|
||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${user.profile_photo_path}`);
|
||||
}
|
||||
}
|
||||
})();
|
||||
}, [user, id]);
|
||||
|
||||
const handleEditPictureClick = () => {
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.click();
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
console.log(JSON.stringify(import.meta.env.VITE_API_URL));
|
||||
if (!isOwnProfile && id) {
|
||||
const res = await getUserById(id);
|
||||
if (res.status === 404) {
|
||||
navigate("/404");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Remplacé : handleFileChange extrait vers utils/users/uploadProfilePhoto
|
||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
try {
|
||||
const res = await uploadProfilePhoto(file);
|
||||
if (res.ok) {
|
||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${res.data.profile_photo_path}`);
|
||||
setSuccess("Photo mise à jour !");
|
||||
setError(null);
|
||||
await update();
|
||||
} else {
|
||||
setError(res.data?.message || res.error || "Erreur lors de l'upload.");
|
||||
setSuccess(null);
|
||||
}
|
||||
} catch (err) {
|
||||
setError("Erreur réseau.");
|
||||
setSuccess(null);
|
||||
if (res.status !== 200) {
|
||||
console.log("Erreur lors du chargement du profil", res);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Remplacé : handleDeletePicture extrait vers utils/users/deleteProfilePhoto
|
||||
const handleDeletePicture = async () => {
|
||||
try {
|
||||
const res = await deleteProfilePhoto();
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
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);
|
||||
setProfileUser(res.data);
|
||||
} else {
|
||||
setProfileUser(user);
|
||||
if (user?.profile_photo_path) {
|
||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${user.profile_photo_path}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
})();
|
||||
}, [user, id]);
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={`${styles.profileboard} glassCard`}>
|
||||
<div className={styles.contentWrapper}>
|
||||
<div className={styles.profilePictureContainer}>
|
||||
<img
|
||||
src={isOwnProfile ? (profilePicture || "/react.svg") : "/react.svg"}
|
||||
alt="Photo de profil"
|
||||
className={styles.profilePicture}
|
||||
/>
|
||||
</div>
|
||||
const handleEditPictureClick = () => {
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.click();
|
||||
}
|
||||
};
|
||||
|
||||
{isOwnProfile && (
|
||||
<div className={styles.pictureButtons}>
|
||||
<button onClick={handleEditPictureClick} className={styles.editPictureButton}>
|
||||
Modifier la photo
|
||||
</button>
|
||||
{user?.profile_photo_path && (
|
||||
<button onClick={handleDeletePicture} className={styles.deletePictureButton}>
|
||||
Supprimer
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
onChange={handleFileChange}
|
||||
accept="image/*"
|
||||
style={{display: "none"}}
|
||||
/>
|
||||
{error && <p className={styles.errorMessage}>{error}</p>}
|
||||
{success && <p className={styles.successMessage}>{success}</p>}
|
||||
try {
|
||||
const res = await uploadProfilePhoto(file);
|
||||
if (res.ok) {
|
||||
setProfilePicture(`${import.meta.env.VITE_API_URL}/storage/${res.data.profile_photo_path}`);
|
||||
console.log("Photo mise à jour")
|
||||
await update();
|
||||
} else {
|
||||
console.log(res.data?.message || res.error || "Erreur lors de l'upload.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Erreur réseau.");
|
||||
}
|
||||
};
|
||||
const handleDeletePicture = async () => {
|
||||
|
||||
deleteProfilePhoto();
|
||||
setProfilePicture(null);
|
||||
};
|
||||
|
||||
<div className={styles.description}>
|
||||
<div className={styles.headerProfile}>
|
||||
<h2>
|
||||
{profileUser?.name} {profileUser?.lastname}
|
||||
</h2>
|
||||
{user?.isAdmin && profileUser && !isOwnProfile && (
|
||||
<ManageMember userToManage={profileUser}/>
|
||||
)}
|
||||
</div>
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={`${styles.profileboard} glassCard`}>
|
||||
<div className={styles.contentWrapper}>
|
||||
<div className={styles.profilePictureContainer}>
|
||||
<img
|
||||
src={isOwnProfile ? (profilePicture || "/react.svg") : "/react.svg"}
|
||||
alt="Photo de profil"
|
||||
className={styles.profilePicture}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.topDescription}>
|
||||
<div className={`${styles.infoBlock} glassBorder`}>
|
||||
<p><strong>Role :</strong> {profileUser?.role}</p>
|
||||
<p><strong>Membre depuis :</strong> {profileUser && formatDate(profileUser.created_at)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className={`${styles.infoBlock} glassBorder`}>
|
||||
<p><strong>Mail :</strong> {profileUser?.email}</p>
|
||||
<p><strong>Téléphone :</strong> {profileUser?.phone ?? "Non renseigné"}</p>
|
||||
</div>
|
||||
|
||||
{isOwnProfile && (
|
||||
<div className={styles.settingImage}>
|
||||
<SettingsModal/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2>Tâches :</h2>
|
||||
{profileUser?.tasks.length ? (
|
||||
profileUser.tasks.map((task) =><Task key={task.id} task={task}/>)
|
||||
) : (
|
||||
<p>Aucune tâche.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{isOwnProfile && (
|
||||
<div className={styles.pictureButtons}>
|
||||
<button onClick={handleEditPictureClick} className={styles.editPictureButton}>
|
||||
Modifier la photo
|
||||
</button>
|
||||
{user?.profile_photo_path && (
|
||||
<button onClick={handleDeletePicture} className={styles.editPictureButton}>
|
||||
Supprimer
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
onChange={handleFileChange}
|
||||
accept="image/*"
|
||||
style={{ display: "none" }}
|
||||
/>
|
||||
|
||||
<div className={styles.description}>
|
||||
<div className={styles.headerProfile}>
|
||||
<h2>
|
||||
{profileUser?.name} {profileUser?.lastname}
|
||||
</h2>
|
||||
{user?.isAdmin && profileUser && !isOwnProfile && (
|
||||
<ManageMember userToManage={profileUser} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className={styles.topDescription}>
|
||||
<div className={`${styles.infoBlock} glassBorder`}>
|
||||
<p><strong>Role :</strong> {profileUser?.role}</p>
|
||||
<p><strong>Membre depuis :</strong> {profileUser && formatDate(profileUser.created_at)}</p>
|
||||
</div>
|
||||
|
||||
<div className={`${styles.infoBlock} glassBorder`}>
|
||||
<p><strong>Mail :</strong> {profileUser?.email}</p>
|
||||
<p><strong>Téléphone :</strong> {profileUser?.phone ?? "Non renseigné"}</p>
|
||||
</div>
|
||||
|
||||
{isOwnProfile && (
|
||||
<div className={styles.settingImage}>
|
||||
<SettingsModal />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2>Tâches :</h2>
|
||||
{profileUser?.tasks.length ? (
|
||||
profileUser.tasks.map((task) => <Task key={task.id} task={task} />)
|
||||
) : (
|
||||
<p>Aucune tâche.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProfilePage;
|
||||
@@ -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 }
|
||||
);
|
||||
}
|
||||
@@ -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 {
|
||||
if (!d) return "Date inconnue";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
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();
|
||||
|
||||
return fetchWrapper(
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function deleteEvent(eventId) {
|
||||
export default async function deleteEvent(eventId:number) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
return fetchWrapper(
|
||||
@@ -1,4 +1,4 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
|
||||
export default async function getAllEvents() {
|
||||
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) {
|
||||
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> {
|
||||
status: number;
|
||||
data: T | null;
|
||||
@@ -79,7 +38,7 @@ export default async function fetchWrapper(
|
||||
};
|
||||
|
||||
} catch (err) {
|
||||
console.error("❌ Erreur réseau :", err);
|
||||
console.error("Erreur réseau :", err);
|
||||
|
||||
return {
|
||||
status: 0,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fetchWrapper from "./fetchWrapper.js";
|
||||
import fetchWrapper from "./fetchWrapper";
|
||||
|
||||
export default async function getRoles() {
|
||||
return fetchWrapper("/api/roles", null, "GET");
|
||||
@@ -1,5 +1,5 @@
|
||||
import fetchWrapper from "./fetchWrapper.js";
|
||||
import fetchWrapper from "./fetchWrapper";
|
||||
|
||||
export default async function getUser() {
|
||||
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> {
|
||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/sanctum/csrf-cookie`, {
|
||||
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();
|
||||
|
||||
try {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function readNotifications() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "./fetchWrapper.js";
|
||||
import getXSRFToken from "./getXSRF.js";
|
||||
import fetchWrapper from "./fetchWrapper";
|
||||
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();
|
||||
|
||||
return fetchWrapper(
|
||||
@@ -1,8 +1,8 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
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();
|
||||
|
||||
return fetchWrapper(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function deactivateUser(userId) {
|
||||
export default async function deactivateUser(userId:number) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
return fetchWrapper(
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function deleteOtherUser(userId) {
|
||||
export default async function deleteOtherUser(userId:number) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
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 }> {
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
|
||||
export default async function getAllUser() {
|
||||
return fetchWrapper("/api/users");
|
||||
@@ -1,4 +1,4 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
|
||||
export default async function getUserById(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() {
|
||||
return fetchWrapper("/api/users/invalid");
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function modifyRole(role, userId) {
|
||||
export default async function modifyRole(role:number, userId:number) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
return fetchWrapper(
|
||||
@@ -1,33 +1,12 @@
|
||||
/*import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
|
||||
export default async function updateUser(name, lastname, phone) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
return fetchWrapper(
|
||||
"/api/users/update",
|
||||
{ name, lastname, phone },
|
||||
"POST",
|
||||
{ "X-XSRF-TOKEN": csrfToken }
|
||||
);
|
||||
}*/
|
||||
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
interface UserUpdateData {
|
||||
name: string;
|
||||
lastname: string;
|
||||
phone: string | null;
|
||||
export default async function updateUser(name: string, lastname: string, phone: string | null) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
return fetchWrapper(
|
||||
"/api/users/update",
|
||||
{ name, lastname, phone },
|
||||
"POST",
|
||||
{ "X-XSRF-TOKEN": csrfToken }
|
||||
);
|
||||
}
|
||||
|
||||
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 }> {
|
||||
const formData = new FormData();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
import fetchWrapper from "../fetchWrapper";
|
||||
import getXSRFToken from "../getXSRF";
|
||||
|
||||
export default async function validateUser(userId) {
|
||||
export default async function validateUser(userId:number) {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
return fetchWrapper(
|
||||
Reference in New Issue
Block a user