From e4e973ee0b7be06fd5fed41a1b71fcc13c434178 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Mon, 25 Dec 2023 14:13:46 +0800 Subject: [PATCH] feat(next/web): collaborator privileges --- .../Settings/Collaborators/Privileges.tsx | 54 +++++++++++++++++++ .../Admin/Settings/Collaborators/index.tsx | 6 +-- next/web/src/api/collaborator.ts | 39 +++++++++++++- 3 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 next/web/src/App/Admin/Settings/Collaborators/Privileges.tsx diff --git a/next/web/src/App/Admin/Settings/Collaborators/Privileges.tsx b/next/web/src/App/Admin/Settings/Collaborators/Privileges.tsx new file mode 100644 index 000000000..8687cf8ae --- /dev/null +++ b/next/web/src/App/Admin/Settings/Collaborators/Privileges.tsx @@ -0,0 +1,54 @@ +import { Checkbox, Spin } from 'antd'; + +import { + CollaboratorPrivileges, + useCollaboratorPrivileges, + useSetCollaboratorPrivileges, +} from '@/api/collaborator'; + +interface PrivilegeItem { + key?: keyof CollaboratorPrivileges; + title: string; +} + +export function Privileges() { + const { data: privileges } = useCollaboratorPrivileges(); + const { mutate, isLoading: isMutating } = useSetCollaboratorPrivileges(); + + const privilegeItems: PrivilegeItem[] = [ + { + title: '查看分配给其的工单', + }, + { + title: '创建内部回复', + }, + { + key: 'createPublicReply', + title: '创建公开回复', + }, + ]; + + if (!privileges) { + return ; + } + + return ( + + ); +} diff --git a/next/web/src/App/Admin/Settings/Collaborators/index.tsx b/next/web/src/App/Admin/Settings/Collaborators/index.tsx index e0439db40..8a499b1f4 100644 --- a/next/web/src/App/Admin/Settings/Collaborators/index.tsx +++ b/next/web/src/App/Admin/Settings/Collaborators/index.tsx @@ -6,6 +6,7 @@ import { useCollaborators, useCreateCollaborator, useDeleteCollaborator } from ' import { Button, Modal, Table, Typography } from '@/components/antd'; import { UserSelect } from '@/components/common'; import { UserLabel } from '@/App/Admin/components'; +import { Privileges } from './Privileges'; const { Column } = Table; const { Title, Paragraph } = Typography; @@ -77,10 +78,7 @@ export function Collaborators() { 协作者 协作者可以: -
    -
  • 查看分配给其的工单
  • -
  • 创建内部回复
  • -
+
diff --git a/next/web/src/api/collaborator.ts b/next/web/src/api/collaborator.ts index 2e647cbe8..afdb9b9a7 100644 --- a/next/web/src/api/collaborator.ts +++ b/next/web/src/api/collaborator.ts @@ -1,4 +1,10 @@ -import { useMutation, UseMutationOptions, useQuery, UseQueryOptions } from 'react-query'; +import { + useMutation, + UseMutationOptions, + useQuery, + useQueryClient, + UseQueryOptions, +} from 'react-query'; import { http } from '@/leancloud'; import { UserSchema } from './user'; @@ -16,6 +22,20 @@ async function deleteCollaborator(userId: string) { await http.delete(`/api/2/collaborators/${userId}`); } +export interface CollaboratorPrivileges { + createPublicReply?: boolean; +} + +async function getCollaboratorPrivileges() { + const res = await http.get('/api/2/collaborators/privileges'); + return res.data; +} + +async function setCollaboratorPrivileges(value: CollaboratorPrivileges) { + const res = await http.put('/api/2/collaborators/privileges', value); + return res.data; +} + export function useCollaborators(options?: UseQueryOptions) { return useQuery({ queryKey: ['collaborators'], @@ -39,3 +59,20 @@ export function useDeleteCollaborator(options?: UseMutationOptions { + queryClient.setQueryData(['CollaboratorPrivileges'], data); + }, + }); +}