Skip to content

Commit

Permalink
fix(profil-modal): fix profil in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Oct 24, 2024
1 parent 537b01c commit 02d8bd2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions client/src/api/send-mail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ function EmailSender({ contribution, refetch }: EmailSenderProps) {
</Container>
<ProfileModal
isOpen={showProfileModal}
selectedProfile={selectedProfile}
onClose={() => setShowProfileModal(false)}
onSelectProfile={handleProfileSelect}
onSelectProfile={handleProfileSelect} // Passer la fonction pour sélectionner le profil
selectedProfile={selectedProfile}
/>
<Modal isOpen={showPreviewModal} hide={() => setShowPreviewModal(false)}>
<ModalTitle>Prévisualisation du mail</ModalTitle>
Expand Down
28 changes: 15 additions & 13 deletions client/src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditModalProps> = ({
isOpen,
Expand All @@ -24,7 +24,9 @@ const EditModal: React.FC<EditModalProps> = ({
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<Inputs>({
Expand All @@ -36,7 +38,6 @@ const EditModal: React.FC<EditModalProps> = ({
});
const [filteredTags, setFilteredTags] = useState<string[]>([]);
const [tagInput, setTagInput] = useState("");

let basePath = "contacts";

if (window.location.pathname.includes("contributionPage")) {
Expand Down Expand Up @@ -105,7 +106,6 @@ const EditModal: React.FC<EditModalProps> = ({
setShowProfileModal(true);
return;
}

try {
const extraEntries = inputs.extra.split("\n").reduce((acc, line) => {
const [key, value] = line.split(":").map((part) => part.trim());
Expand Down Expand Up @@ -164,7 +164,7 @@ const EditModal: React.FC<EditModalProps> = ({
return (
<>
<Modal isOpen={isOpen} hide={onClose}>
<ModalTitle>Modifier la contribution</ModalTitle>
<ModalTitle>Édition</ModalTitle>
<ModalContent>
<Col className="fr-mb-1w">
<label htmlFor="statusInput">Statut</label>
Expand Down Expand Up @@ -248,14 +248,16 @@ const EditModal: React.FC<EditModalProps> = ({
</Row>
</ModalContent>
</Modal>
{showProfileModal && (
<ProfileModal
isOpen={showProfileModal}
selectedProfile={selectedProfile}
onClose={() => setShowProfileModal(false)}
onSelectProfile={(profile) => handleInputChange("team", [profile])}
/>
)}
<ProfileModal
isOpen={showProfileModal}
onClose={() => setShowProfileModal(false)}
onSelectProfile={(profile) => {
setSelectedProfile(profile);
localStorage.setItem("selectedProfile", profile);
setShowProfileModal(false);
}}
selectedProfile={selectedProfile}
/>
<TagSelectionModal
isOpen={showTagModal}
allTags={filteredTags}
Expand Down
7 changes: 5 additions & 2 deletions client/src/components/profil-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ const ProfileModal: React.FC<ProfileModalProps> = ({
}) => {
return (
<Modal isOpen={isOpen} hide={onClose}>
<ModalTitle>Hello ! Selectionne ton profil</ModalTitle>
<ModalTitle>Hello ! Sélectionne ton profil</ModalTitle>
<ModalContent className="profile-modal-content">
<div className="profile-buttons">
{profiles.map((profile, index) => (
<button
key={index}
className={`profile-button profile${index + 1}`}
onClick={() => onSelectProfile(profile)}
onClick={() => {
onSelectProfile(profile);
onClose();
}}
>
{profile}
</button>
Expand Down
11 changes: 10 additions & 1 deletion client/src/layout/header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import {
Header as HeaderWrapper,
Expand Down Expand Up @@ -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 (
<>
<HeaderWrapper>
Expand Down Expand Up @@ -89,6 +97,7 @@ const Header: React.FC = () => {
>
{selectedProfile ? `Salut ${selectedProfile} !` : "Mon profil"}
</Button>

<ProfileModal
isOpen={showModal}
selectedProfile={selectedProfile}
Expand Down

0 comments on commit 02d8bd2

Please sign in to comment.