+ profil details

This commit is contained in:
AntoninoP 2024-07-05 14:46:31 +02:00
parent 71745d6e19
commit 1a6672f0c3
2 changed files with 63 additions and 32 deletions

View File

@ -1,21 +1,52 @@
import React from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { auth } from '../../service/firebase';
import styles from './Navbar.module.scss';
const Navbar = ({ user }) => {
const [dropdownOpen, setDropdownOpen] = useState(false);
const dropdownRef = useRef(null);
const handleLogout = () => {
auth.signOut();
};
const toggleDropdown = (event) => {
if (dropdownRef.current && dropdownRef.current.contains(event.target)) {
setDropdownOpen(false);
} else {
setDropdownOpen(!dropdownOpen);
}
};
const handleClickOutside = (event) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
setDropdownOpen(false);
}
};
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);
return (
<div className={styles.navbar}>
<div className={styles.userInfo}>
<img src={user.photoURL} alt="Profile" className={styles.profilePic} />
<div className={styles.userDetails}>
<span className={styles.userName}>{user.displayName}</span>
<button onClick={handleLogout} className={styles.logoutButton}>Déconnexion</button>
</div>
<div className={styles.profileSection} onClick={toggleDropdown}>
{user.photoURL ? (
<img src={user.photoURL} alt="Profile" className={styles.profilePic} />
) : (
<h1>hello</h1>
)}
</div>
{dropdownOpen && (
<div className={styles.dropdownMenu} ref={dropdownRef}>
<div className={styles.menuItem} onClick={toggleDropdown}>Informations</div>
<div className={styles.menuItem} onClick={toggleDropdown}>Paramètres</div>
<div className={styles.menuItem} onClick={handleLogout}>Se déconnecter</div>
</div>
)}
</div>
);
};

View File

@ -2,10 +2,10 @@
display: flex;
justify-content: flex-end;
align-items: center;
padding: 10px 20px;
padding: 0.833rem 1.667rem;
background-color: var(--navbar-background-color);
color: var(--navbar-color);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
box-shadow: 0 0.167rem 0.333rem rgba(0, 0, 0, 0.1);
position: fixed;
top: 0;
width: 100%;
@ -13,39 +13,39 @@
height: var(--navbar-height);
}
.userInfo {
display: flex;
align-items: center;
.profileSection {
position: relative;
cursor: pointer;
}
.profilePic {
width: var(--profile-pic-size);
height: var(--profile-pic-size);
border-radius: 50%;
margin-right: 1rem;
border-radius: 100%;
margin-right: 3rem;
}
.userDetails {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-right: 4rem;
.dropdownMenu {
position: absolute;
top: 4rem;
right: 4rem;
background-color: black;
box-shadow: 0 0.167rem 0.833rem rgba(0, 0, 0, 0.15);
border-radius: 0.8rem;
overflow: hidden;
z-index: 1001;
width: 20rem;
border: .1rem solid red;
}
.userName {
.menuItem {
padding: 1.25rem 2rem;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
font-weight: bold;
}
.logoutButton {
margin-top: 5px;
padding: 5px 10px;
background-color: var(--logout-button-bg);
color: var(--navbar-color);
border: none;
border-radius: 5px;
cursor: pointer;
}
.logoutButton:hover {
background-color: var(--logout-button-bg-hover);
.menuItem:hover {
background-color: rgba(0, 0, 0, 0.1);
color: var(--primary-color);
}