mirror of
https://github.com/langgenius/dify.git
synced 2026-05-12 07:37:09 +08:00
feat: add role duplication functionality with copy role hook
This commit is contained in:
parent
a409a0c3a1
commit
3aa8abbe14
@ -10,7 +10,7 @@ import {
|
||||
import { toast } from '@langgenius/dify-ui/toast'
|
||||
import { useCallback, useState } from 'react'
|
||||
import ActionButton from '@/app/components/base/action-button'
|
||||
import { useDeleteWorkspaceRole } from '@/service/access-control/use-workspace-roles'
|
||||
import { useCopyWorkspaceRole, useDeleteWorkspaceRole } from '@/service/access-control/use-workspace-roles'
|
||||
|
||||
type RowMenuProps = {
|
||||
roleCategory: RoleCategory
|
||||
@ -27,15 +27,22 @@ const RowMenu = ({
|
||||
}: RowMenuProps) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const { mutateAsync: deleteRole } = useDeleteWorkspaceRole()
|
||||
|
||||
const handleView = useCallback(() => onView?.(role), [onView, role])
|
||||
|
||||
const handleEdit = useCallback(() => onEdit?.(role), [onEdit, role])
|
||||
|
||||
const { mutateAsync: copyRole } = useCopyWorkspaceRole()
|
||||
|
||||
const handleDuplicate = useCallback(() => {
|
||||
// TODO: wire up to API when backend is ready
|
||||
}, [])
|
||||
copyRole(role.id, {
|
||||
onSuccess: () => {
|
||||
toast.success('Role duplicated successfully')
|
||||
setOpen(false)
|
||||
},
|
||||
})
|
||||
}, [copyRole, role.id])
|
||||
|
||||
const { mutateAsync: deleteRole } = useDeleteWorkspaceRole()
|
||||
|
||||
const handleDelete = useCallback(() => {
|
||||
deleteRole(role.id, {
|
||||
|
||||
@ -59,3 +59,16 @@ export const useDeleteWorkspaceRole = () => {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useCopyWorkspaceRole = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'copy-workspace-role'],
|
||||
mutationFn: (id: string) =>
|
||||
post<Role>(`/workspaces/current/rbac/roles/${id}/copy`),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: [NAME_SPACE, 'workspace-role-list'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user