mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-17 23:18:20 +00:00
feat(web): Unified frontend code style (#1923)
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: 谨欣 <echo.cmy@antgroup.com> Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com> Co-authored-by: yanzhiyong <932374019@qq.com>
This commit is contained in:
@@ -1,38 +1,36 @@
|
||||
import { UserInfoResponse } from '@/types/userinfo';
|
||||
import { STORAGE_USERINFO_KEY } from '@/utils/constants/index';
|
||||
import { LogoutOutlined } from '@ant-design/icons';
|
||||
import { Avatar, Dropdown, Space } from 'antd';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Avatar } from 'antd';
|
||||
import cls from 'classnames';
|
||||
function UserBar({ onlyAvatar = false }) {
|
||||
const { t } = useTranslation();
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
function UserBar({ onlyAvatar = false }) {
|
||||
const [userInfo, setUserInfo] = useState<UserInfoResponse>();
|
||||
useEffect(() => {
|
||||
try {
|
||||
const user = JSON.parse(localStorage.getItem(STORAGE_USERINFO_KEY) ?? '');
|
||||
setUserInfo(user);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem(STORAGE_USERINFO_KEY);
|
||||
window.location.href = `${process.env.LOGOUT_URL}&goto=${encodeURIComponent(window.location.href)}`;
|
||||
};
|
||||
// TODO: delete unused function
|
||||
// const logout = () => {
|
||||
// localStorage.removeItem(STORAGE_USERINFO_KEY);
|
||||
// window.location.href = `${process.env.LOGOUT_URL}&goto=${encodeURIComponent(window.location.href)}`;
|
||||
// };
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<div className='flex flex-1 items-center justify-center'>
|
||||
<div
|
||||
className={cls('flex items-center group w-full', {
|
||||
'justify-center': onlyAvatar,
|
||||
'justify-between': !onlyAvatar,
|
||||
})}
|
||||
>
|
||||
<span className="flex gap-2 items-center">
|
||||
<Avatar src={userInfo?.avatar_url} className="bg-gradient-to-tr from-[#31afff] to-[#1677ff] cursor-pointer">
|
||||
<span className='flex gap-2 items-center'>
|
||||
<Avatar src={userInfo?.avatar_url} className='bg-gradient-to-tr from-[#31afff] to-[#1677ff] cursor-pointer'>
|
||||
{userInfo?.nick_name}
|
||||
</Avatar>
|
||||
<span
|
||||
|
Reference in New Issue
Block a user