From 85d9e60025fa0f63d92770c9f716f9eb2472b2b0 Mon Sep 17 00:00:00 2001 From: p2405951 Date: Fri, 6 Feb 2026 15:21:05 +0100 Subject: [PATCH] add TS + implement upload profilePicture --- src/config/appConfig.js | 4 -- .../Home/components/EventList/eventList.jsx | 31 +++++----- src/pages/Profile/ProfilePage.tsx | 60 ++++++++++++++----- tsconfig.json | 59 +++--------------- 4 files changed, 68 insertions(+), 86 deletions(-) delete mode 100644 src/config/appConfig.js diff --git a/src/config/appConfig.js b/src/config/appConfig.js deleted file mode 100644 index 12764ab..0000000 --- a/src/config/appConfig.js +++ /dev/null @@ -1,4 +0,0 @@ -export const APP_CONFIG = { - contactEmail: "contact@example.com", - contactPhone: "+33 01 02 03 04 05" -} \ No newline at end of file diff --git a/src/pages/Home/components/EventList/eventList.jsx b/src/pages/Home/components/EventList/eventList.jsx index 975adf9..9ab2321 100644 --- a/src/pages/Home/components/EventList/eventList.jsx +++ b/src/pages/Home/components/EventList/eventList.jsx @@ -4,33 +4,32 @@ import EventItem from "./eventItem.jsx"; import { EventContext } from "../../../../contexts/events/EventContext.js"; import { useContext } from "react"; - function EventList() { - - const { events } = useContext(EventContext); + // 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 (
-

Liste des événements à venir

- {sortedEvents.length > 0 ? ( -
- {sortedEvents.map((eventGroup, index) => ( - - ))} -
- ) : ( -

Aucun événement planifié pour l'instant.

- )} +

Liste des événements à venir

+ {sortedEvents.length > 0 ? ( +
+ {sortedEvents.map((eventGroup, index) => ( + + ))} +
+ ) : ( +

Aucun événement planifié pour l'instant.

+ )}
- ); } -export default EventList; \ No newline at end of file +export default EventList; diff --git a/src/pages/Profile/ProfilePage.tsx b/src/pages/Profile/ProfilePage.tsx index 84c2211..0733f40 100644 --- a/src/pages/Profile/ProfilePage.tsx +++ b/src/pages/Profile/ProfilePage.tsx @@ -1,12 +1,8 @@ -import { useContext, useEffect } from "react"; -import styles from "./ProfilePage.module.css"; - +import { useContext, useEffect, useState, useRef } from "react"; +import styles from "../Profile/ProfilePage.module.css"; import { AuthContext } from "../../contexts/auth/AuthContext"; import formatDate from "../../utils/date/formatDate"; -//import Task from "../../components/Task/Task"; -//import SettingsModal from "./components/SettingsModal/SettingsModal"; - interface TaskType { id: number; title?: string; @@ -22,6 +18,7 @@ interface User { phone: string | null; created_at: string; tasks: TaskType[]; + profilePicture?: string | null; } interface AuthContextType { @@ -29,10 +26,32 @@ interface AuthContextType { update: () => void; } - - -function ProfilePage(){ +function ProfilePage() { const { user, update } = useContext(AuthContext) as AuthContextType; + const [profilePicture, setProfilePicture] = useState(user?.profilePicture || null); + const fileInputRef = useRef(null); + + // Fonction pour déclencher l'input file + const handleEditPictureClick = () => { + if (fileInputRef.current) { + fileInputRef.current.click(); + } + }; + + // Fonction pour gérer le changement de fichier + const handleFileChange = async (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (!file) return; + + // Logique pour uploader la photo (à adapter selon ton backend) + const formData = new FormData(); + formData.append("profilePicture", file); + + // Appelle la fonction pour uploader la photo (exemple) + // const response = await uploadProfilePicture(formData); + // setProfilePicture(response.url); // Met à jour l'URL de la photo + // update(); // Met à jour le contexte utilisateur + }; useEffect(() => { update(); @@ -44,10 +63,23 @@ function ProfilePage(){
Photo de profil + +
@@ -79,19 +111,18 @@ function ProfilePage(){
- {/* */} + {/* */}

Tâches :

- - {/* {user && user.tasks.length > 0 ? ( + {/* {user && user.tasks.length > 0 ? ( user.tasks.map((task) => ( )) ) : (

Aucune tâche pour le moment.

- )}*/} + )} */} @@ -101,7 +132,6 @@ function ProfilePage(){ export default ProfilePage; - /*import React, { useContext, useEffect } from "react"; import styles from "./ProfilePage.module.css"; import { AuthContext } from "../../contexts/auth/AuthContext.js"; diff --git a/tsconfig.json b/tsconfig.json index f5783f0..b3a52d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,49 +1,4 @@ { - // Visit https://aka.ms/tsconfig to read more about this file - /*"compilerOptions": {*/ - // File Layout - // "rootDir": "./src", - // "outDir": "./dist", - - // Environment Settings - // See also https://aka.ms/tsconfig/module - /*"module": "nodenext", - "target": "esnext", - "types": [],*/ - // For nodejs: - // "lib": ["esnext"], - // "types": ["node"], - // and npm install -D @types/node - - // Other Outputs - /*"sourceMap": true, - "declaration": true, - "declarationMap": true,*/ - - // Stricter Typechecking Options - /*"noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": true,*/ - - // Style Options - // "noImplicitReturns": true, - // "noImplicitOverride": true, - // "noUnusedLocals": true, - // "noUnusedParameters": true, - // "noFallthroughCasesInSwitch": true, - // "noPropertyAccessFromIndexSignature": true, - - // Recommended Options - /* "strict": true, - "jsx": "react-jsx", - "verbatimModuleSyntax": true, - "isolatedModules": true, - "noUncheckedSideEffectImports": true, - "moduleDetection": "force", - "skipLibCheck": true, - } -} - -{*/ "compilerOptions": { "target": "ESNext", "lib": ["DOM", "DOM.Iterable", "ESNext"], @@ -52,11 +7,13 @@ "jsx": "react-jsx", "strict": true, "isolatedModules": true, - - "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": false, - + "noUncheckedIndexedAccess": false, + "exactOptionalPropertyTypes": true, "resolveJsonModule": true, - "skipLibCheck": true - } + "skipLibCheck": true, + "allowJs": true, + "esModuleInterop": true + }, + "include": ["src"], + "exclude": ["**/*.js"] }