added security and fix edit profile
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import LogoIcon from "./icons/LogoIcon";
|
||||
import React, { useState } from "react";
|
||||
import {NAV_BOTTOM, NAV_ITEMS} from "../config/feedConstants";
|
||||
import {NavIcons} from "./icons/NavIcons";
|
||||
import Profile from "./profile/Profile";
|
||||
|
||||
export default function Sidebar({ open, activeNav, onClose, onNavClick, onEditProfile }) {
|
||||
const [profileData] = useState({
|
||||
firstName: "Иван",
|
||||
lastName: "Иванов",
|
||||
email: "ivan@example.com",
|
||||
phone: "+7 (999) 123-45-67",
|
||||
});
|
||||
|
||||
export default function Sidebar({
|
||||
open,
|
||||
activeNav,
|
||||
onClose,
|
||||
onNavClick,
|
||||
onEditProfile,
|
||||
profileData = {},
|
||||
isAuthenticated,
|
||||
onLogout,
|
||||
onLoginClick,
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className={`f-overlay${open ? " show" : ""}`} onClick={onClose} />
|
||||
@@ -23,11 +25,20 @@ export default function Sidebar({ open, activeNav, onClose, onNavClick, onEditPr
|
||||
<nav className="f-sb-nav">
|
||||
{NAV_ITEMS.map(({ icon, label }) => {
|
||||
const Ic = NavIcons[icon];
|
||||
const handleClick = () => {
|
||||
// «Мои объявления» и «Чат» требуют авторизации
|
||||
if (!isAuthenticated && (label === "Мои объявления" || label === "Чат")) {
|
||||
onLoginClick();
|
||||
} else {
|
||||
onNavClick(label);
|
||||
}
|
||||
onClose();
|
||||
};
|
||||
return (
|
||||
<div
|
||||
key={label}
|
||||
className={`f-sb-item${activeNav === label ? " active" : ""}`}
|
||||
onClick={() => { onNavClick(label); onClose(); }}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<Ic /> {label}
|
||||
</div>
|
||||
@@ -48,7 +59,27 @@ export default function Sidebar({ open, activeNav, onClose, onNavClick, onEditPr
|
||||
);
|
||||
})}
|
||||
<div className="f-sb-divider" />
|
||||
<Profile data={profileData} onEdit={onEditProfile} />
|
||||
|
||||
{isAuthenticated ? (
|
||||
<>
|
||||
<Profile data={profileData} onEdit={onEditProfile} />
|
||||
<div
|
||||
className="f-sb-item"
|
||||
onClick={() => { onLogout(); onClose(); }}
|
||||
style={{ color: "rgba(255,107,107,.7)", marginTop: 8 }}
|
||||
>
|
||||
<span style={{ fontSize: "1.1rem" }}>🚪</span> Выйти
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div
|
||||
className="f-sb-item"
|
||||
onClick={() => { onLoginClick(); onClose(); }}
|
||||
style={{ color: "#2de0c8" }}
|
||||
>
|
||||
<span style={{ fontSize: "1.1rem" }}>🔑</span> Войти
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user