From 4d661996b41c3ee2f5d2eabf4a8e317a9f4f9a72 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Fri, 29 Mar 2024 19:30:28 +0800 Subject: [PATCH] feat(next/web): allow customer service agent to create user --- next/web/src/App/Admin/Settings/index.tsx | 55 +++++++++++++++---- next/web/src/App/Admin/Sidebar/index.tsx | 12 ++-- .../web/src/components/Page/SubMenu/index.tsx | 2 +- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/next/web/src/App/Admin/Settings/index.tsx b/next/web/src/App/Admin/Settings/index.tsx index 1d972228d..f4a268b2a 100644 --- a/next/web/src/App/Admin/Settings/index.tsx +++ b/next/web/src/App/Admin/Settings/index.tsx @@ -1,6 +1,7 @@ +import { useMemo } from 'react'; import { Route, Routes } from 'react-router-dom'; -import { SubMenu, MenuDataItem } from '@/components/Page'; +import { SubMenu } from '@/components/Page'; import { NewUser } from './Users'; import { Members } from './Members'; @@ -35,12 +36,19 @@ import { NewTicketFormNoteTranslation } from './TicketFormNotes/NewTicketFormNot import { EditTicketFormNoteTranslation } from './TicketFormNotes/EditTranslation'; import { EditSupportEmail, NewSupportEmail, SupportEmailList } from './SupportEmails'; import { useCurrentUserIsAdmin } from '@/leancloud'; -import { Result } from '@/components/antd'; import { EvaluationConfig } from './Evaluation'; import { MergeUser } from './Users/MergeUser'; import { ExportTicketTask } from './ExportTicket/Tasks'; const SettingRoutes = () => ( + + + } /> + + +); + +const AdminSettingRoutes = () => ( @@ -146,14 +154,24 @@ const SettingRoutes = () => ( ); -const routeGroups: MenuDataItem[] = [ +interface MenuItem { + name: string; + path?: string; + key?: string; + children?: Omit[]; + adminOnly?: boolean; +} + +const routeGroups: MenuItem[] = [ { name: '用户', key: 'users', + adminOnly: false, children: [ { name: '创建用户', path: 'users/new', + adminOnly: false, }, { name: '合并用户', @@ -267,14 +285,29 @@ const routeGroups: MenuDataItem[] = [ }, ]; +function filterDeep( + items: T[], + predicate: (item: T) => boolean +): T[] { + return items + .map((item) => { + if (item.children) { + return { + ...item, + children: filterDeep(item.children, predicate), + }; + } + return item; + }) + .filter(predicate); +} + export default function Setting() { const isAdmin = useCurrentUserIsAdmin(); - if (!isAdmin) { - return ; - } - return ( - - - - ); + const menus = useMemo(() => { + if (isAdmin) return routeGroups; + return filterDeep(routeGroups, (menu) => menu.adminOnly === false); + }, [isAdmin]); + + return {isAdmin ? : }; } diff --git a/next/web/src/App/Admin/Sidebar/index.tsx b/next/web/src/App/Admin/Sidebar/index.tsx index e770543c6..7c90d952e 100644 --- a/next/web/src/App/Admin/Sidebar/index.tsx +++ b/next/web/src/App/Admin/Sidebar/index.tsx @@ -3,11 +3,10 @@ import { NavLink } from 'react-router-dom'; import { AiOutlineContainer, AiOutlineSetting } from 'react-icons/ai'; import { HiOutlinePlus, HiOutlineTicket } from 'react-icons/hi'; import { MdOutlineAnalytics } from 'react-icons/md'; -import { BsChatSquareDots } from 'react-icons/bs'; import cx from 'classnames'; import { Tooltip } from '@/components/antd'; -import { useCurrentUserIsAdmin, useCurrentUserIsCustomerService } from '@/leancloud'; +import { useCurrentUserIsCustomerService } from '@/leancloud'; import { Feedback } from '../Feedback'; import { CurrentUserSection } from '../CurrentUserSection'; import { RequirePermission } from '@/components/RequirePermission'; @@ -36,7 +35,6 @@ function Path({ to, children, title }: { to: string; children: ReactNode; title? export function Sidebar(props: ComponentPropsWithoutRef<'aside'>) { const isCustomerService = useCurrentUserIsCustomerService(); - const isAdmin = useCurrentUserIsAdmin(); return (