From 02d8bd25e0486c959f11abfb23860e0f0175c886 Mon Sep 17 00:00:00 2001 From: Mihoub Date: Thu, 24 Oct 2024 12:34:00 +0200 Subject: [PATCH] fix(profil-modal): fix profil in storage --- client/src/api/send-mail/index.tsx | 4 +-- client/src/components/edit-modal/index.tsx | 28 +++++++++++--------- client/src/components/profil-modal/index.tsx | 7 +++-- client/src/layout/header.tsx | 11 +++++++- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/client/src/api/send-mail/index.tsx b/client/src/api/send-mail/index.tsx index 7565808..7d45e29 100644 --- a/client/src/api/send-mail/index.tsx +++ b/client/src/api/send-mail/index.tsx @@ -108,9 +108,9 @@ function EmailSender({ contribution, refetch }: EmailSenderProps) { setShowProfileModal(false)} - onSelectProfile={handleProfileSelect} + onSelectProfile={handleProfileSelect} // Passer la fonction pour sélectionner le profil + selectedProfile={selectedProfile} /> setShowPreviewModal(false)}> Prévisualisation du mail diff --git a/client/src/components/edit-modal/index.tsx b/client/src/components/edit-modal/index.tsx index be94d22..b84c728 100644 --- a/client/src/components/edit-modal/index.tsx +++ b/client/src/components/edit-modal/index.tsx @@ -13,8 +13,8 @@ import { import { EditModalProps, Inputs } from "../../types"; import { postHeaders } from "../../config/api"; import { toast } from "react-toastify"; -import ProfileModal from "../profil-modal"; import TagSelectionModal from "./modal-select-tags"; +import ProfileModal from "../profil-modal"; const EditModal: React.FC = ({ isOpen, @@ -24,7 +24,9 @@ const EditModal: React.FC = ({ allTags, }) => { const [showProfileModal, setShowProfileModal] = useState(false); - const [selectedProfile] = useState(localStorage.getItem("selectedProfile")); + const [selectedProfile, setSelectedProfile] = useState( + localStorage.getItem("selectedProfile") + ); const [showTagModal, setShowTagModal] = useState(false); const [inputs, setInputs] = useState({ @@ -36,7 +38,6 @@ const EditModal: React.FC = ({ }); const [filteredTags, setFilteredTags] = useState([]); const [tagInput, setTagInput] = useState(""); - let basePath = "contacts"; if (window.location.pathname.includes("contributionPage")) { @@ -105,7 +106,6 @@ const EditModal: React.FC = ({ setShowProfileModal(true); return; } - try { const extraEntries = inputs.extra.split("\n").reduce((acc, line) => { const [key, value] = line.split(":").map((part) => part.trim()); @@ -164,7 +164,7 @@ const EditModal: React.FC = ({ return ( <> - Modifier la contribution + Édition @@ -248,14 +248,16 @@ const EditModal: React.FC = ({ - {showProfileModal && ( - setShowProfileModal(false)} - onSelectProfile={(profile) => handleInputChange("team", [profile])} - /> - )} + setShowProfileModal(false)} + onSelectProfile={(profile) => { + setSelectedProfile(profile); + localStorage.setItem("selectedProfile", profile); + setShowProfileModal(false); + }} + selectedProfile={selectedProfile} + /> = ({ }) => { return ( - Hello ! Selectionne ton profil + Hello ! Sélectionne ton profil
{profiles.map((profile, index) => ( diff --git a/client/src/layout/header.tsx b/client/src/layout/header.tsx index 7d144e4..a87a504 100644 --- a/client/src/layout/header.tsx +++ b/client/src/layout/header.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useLocation } from "react-router-dom"; import { Header as HeaderWrapper, @@ -56,11 +56,19 @@ const Header: React.FC = () => { const handleProfileSelect = (profile: string) => { setSelectedProfile(profile); + localStorage.setItem("selectedProfile", profile); setShowModal(false); }; const handleCloseModal = () => setShowModal(false); + useEffect(() => { + const profileFromStorage = localStorage.getItem("selectedProfile"); + if (profileFromStorage) { + setSelectedProfile(profileFromStorage); + } + }, []); + return ( <> @@ -89,6 +97,7 @@ const Header: React.FC = () => { > {selectedProfile ? `Salut ${selectedProfile} !` : "Mon profil"} +