import { Avatar, Divider, Modal, Stack, Text, Title, UnstyledButton, useMantineTheme, } from "@mantine/core"; import "./Sidebar.css"; import { IconDevicesPc, IconFileDescription, IconFlaskFilled, IconLogout, IconSettings2, IconUsers, type Icon, type IconProps, } from "@tabler/icons-react"; import { Link, useLocation, useNavigate, type NavigateFunction, } from "react-router"; import { useEffect, useState, type ForwardRefExoticComponent } from "react"; import { routes } from "Routes/Routes"; import keycloak from "Api/Keycloak/Keycloak"; import { useAuthenticationStore } from "Stores/AuthenticationStore"; import CustomButton from "Components/CustomButton/CustomButton"; interface SubtleLinkButtonProps { link: string; Icon: ForwardRefExoticComponent>; text: string; color: string; selected?: boolean; nav: NavigateFunction; } function SubtleLinkButton(props: SubtleLinkButtonProps) { return ( } style="subtle" color={props.selected ? props.color : "contrast"} text={props.text} textAlign="left" onClick={() => { props.nav(props.link); }} /> ); } function Sidebar() { const { profile, set_profile_picture_path, profile_picture_path } = useAuthenticationStore(); const [open, set_open] = useState(false); const theme = useMantineTheme(); const location = useLocation(); // get current URL const navigate = useNavigate(); useEffect(() => { if (!profile) return; const fetchAvatar = async () => { try { const response = await fetch( `${import.meta.env.VITE_QUANTUM_BACKEND_URL}/user/serve/${profile.id}`, { headers: { Authorization: `Bearer ${keycloak.token}`, }, }, ); if (response.ok) { const blob = await response.blob(); const url = URL.createObjectURL(blob); set_profile_picture_path(url); } } catch (error) { console.error("Failed to load avatar:", error); } }; fetchAvatar(); }, [profile]); return (
set_open(false)} title=Выйти? centered withCloseButton={false} size="auto" >
keycloak.logout({ redirectUri: window.location.origin, }) } textSize="lg" color="contrast" > set_open(false)} text="Отменить" textSize="lg" style="outline" color="contrast" >
{keycloak.authenticated && ( <>
{profile?.username} {profile?.email}
} text="Настройки" color="contrast" textSize="lg" onClick={() => { navigate(routes.SettingsPage.path); }} /> } text="Выйти" textSize="lg" color="contrast" onClick={() => { set_open(true); }} />
)} {!keycloak.authenticated && ( keycloak.login()}> Войти / Зарегестрироваться )}
); } export default Sidebar;