From 89cf479f1675b1e4a23d82abae9e2eb3a431b5c4 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Mon, 25 Dec 2023 14:52:07 +0800 Subject: [PATCH] feat: remove leanchat navigation --- next/api/src/controller/leanchat.ts | 39 ----------------------- next/web/src/App/Admin/LeanChat/index.tsx | 39 ----------------------- next/web/src/App/Admin/Sidebar/index.tsx | 3 -- next/web/src/App/Admin/index.tsx | 2 -- 4 files changed, 83 deletions(-) delete mode 100644 next/api/src/controller/leanchat.ts delete mode 100644 next/web/src/App/Admin/LeanChat/index.tsx diff --git a/next/api/src/controller/leanchat.ts b/next/api/src/controller/leanchat.ts deleted file mode 100644 index d3187de2a..000000000 --- a/next/api/src/controller/leanchat.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { sign } from 'jsonwebtoken'; - -import { Controller, CurrentUser, HttpError, Post, UseMiddlewares } from '@/common/http'; -import { auth, customerServiceOnly } from '@/middleware'; -import { User } from '@/model/User'; -import { roleService } from '@/service/role'; - -@Controller('leanchat') -@UseMiddlewares(auth, customerServiceOnly) -export class LeanChatController { - private jwtSecret?: string; - - constructor() { - this.jwtSecret = process.env.LEANCHAT_LOGIN_JWT_SECRET; - } - - @Post('login-token') - async createLoginToken(@CurrentUser() user: User) { - if (!this.jwtSecret) { - throw new HttpError(400, 'LeanChat JWT token is not configured'); - } - - const roles = await roleService.getSystemRolesForUser(user.id); - const chatRole = roles.includes('admin') ? 2 : 1; - const chatName = `客服${user.id.slice(-4)}`; - const token = sign( - { - role: chatRole, - username: `${user.username}_ticket`, - externalName: chatName, - internalName: user.name ?? chatName, - concurrency: 5, - }, - this.jwtSecret - ); - - return { token }; - } -} diff --git a/next/web/src/App/Admin/LeanChat/index.tsx b/next/web/src/App/Admin/LeanChat/index.tsx deleted file mode 100644 index 0a65413f9..000000000 --- a/next/web/src/App/Admin/LeanChat/index.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { Button } from 'antd'; -import { AiOutlineLink } from 'react-icons/ai'; -import { useMutation } from 'react-query'; - -import { http } from '@/leancloud'; - -export default function LeanChat() { - const leanchatUrl = import.meta.env.VITE_LEANCHAT_URL; - - const { mutate: toLeanChat, isLoading } = useMutation({ - mutationFn: async () => { - const res = await http.post<{ token: string }>('/api/2/leanchat/login-token'); - return res.data.token; - }, - onSuccess: (token) => { - if (leanchatUrl) { - const url = new URL(leanchatUrl); - url.pathname = '/login'; - url.searchParams.set('token', token); - window.open(url, '_blank'); - } - }, - }); - - return ( -
- {leanchatUrl ? ( - - ) : ( - '暂未开启' - )} -
- ); -} diff --git a/next/web/src/App/Admin/Sidebar/index.tsx b/next/web/src/App/Admin/Sidebar/index.tsx index 72019965c..e770543c6 100644 --- a/next/web/src/App/Admin/Sidebar/index.tsx +++ b/next/web/src/App/Admin/Sidebar/index.tsx @@ -65,9 +65,6 @@ export function Sidebar(props: ComponentPropsWithoutRef<'aside'>) { } - - - {isAdmin && ( diff --git a/next/web/src/App/Admin/index.tsx b/next/web/src/App/Admin/index.tsx index a53672fdb..0542924da 100644 --- a/next/web/src/App/Admin/index.tsx +++ b/next/web/src/App/Admin/index.tsx @@ -15,7 +15,6 @@ import Settings from './Settings'; import Stats from './Stats'; import { NewTicket } from '../Tickets/New'; import { Verification } from './Verification'; -import LeanChat from './LeanChat'; const NavigateToAvailablePage = () => { const isCustomerService = useCurrentUserIsCustomerService(); @@ -89,7 +88,6 @@ export default function AdminPage() { } /> } /> - } /> } />