pref: member/group/org (#4316)
* feat: change group owner api * pref: member/org/group * fix: member modal select clb * fix: search member when change owner
This commit is contained in:
@@ -10,8 +10,8 @@ import { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/t
|
||||
import { TeamMemberItemType } from '@fastgpt/global/support/user/team/type';
|
||||
import { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||
|
||||
export const getOrgList = (parentId: ParentIdType) =>
|
||||
GET<OrgListItemType[]>(`/proApi/support/user/team/org/list`, { parentId });
|
||||
export const getOrgList = (params: { orgPath: string; getPermission?: boolean }) =>
|
||||
GET<OrgListItemType[]>(`/proApi/support/user/team/org/list`, params);
|
||||
|
||||
export const postCreateOrg = (data: postCreateOrgData) =>
|
||||
POST('/proApi/support/user/team/org/create', data);
|
||||
@@ -19,19 +19,17 @@ export const postCreateOrg = (data: postCreateOrgData) =>
|
||||
export const deleteOrg = (orgId: string) =>
|
||||
DELETE('/proApi/support/user/team/org/delete', { orgId });
|
||||
|
||||
export const deleteOrgMember = (orgId: string, tmbId: string) =>
|
||||
DELETE('/proApi/support/user/team/org/deleteMember', { orgId, tmbId });
|
||||
|
||||
export const putMoveOrg = (data: putMoveOrgType) => PUT('/proApi/support/user/team/org/move', data);
|
||||
|
||||
export const putUpdateOrg = (data: putUpdateOrgData) =>
|
||||
PUT('/proApi/support/user/team/org/update', data);
|
||||
|
||||
// org members
|
||||
export const putUpdateOrgMembers = (data: putUpdateOrgMembersData) =>
|
||||
PUT('/proApi/support/user/team/org/updateMembers', data);
|
||||
|
||||
// export const putChnageOrgOwner = (data: putChnageOrgOwnerData) =>
|
||||
// PUT('/proApi/support/user/team/org/changeOwner', data);
|
||||
|
||||
export const getOrgMembers = (data: PaginationProps<{ orgId: string }>) =>
|
||||
export const getOrgMembers = (data: PaginationProps<{ orgPath?: string }>) =>
|
||||
GET<PaginationResponse<TeamMemberItemType>>(`/proApi/support/user/team/org/members`, data);
|
||||
|
||||
export const deleteOrgMember = (orgId: string, tmbId: string) =>
|
||||
DELETE('/proApi/support/user/team/org/deleteMember', { orgId, tmbId });
|
||||
|
||||
108
projects/app/src/web/support/user/team/org/hooks/useOrg.tsx
Normal file
108
projects/app/src/web/support/user/team/org/hooks/useOrg.tsx
Normal file
@@ -0,0 +1,108 @@
|
||||
import { getOrgChildrenPath } from '@fastgpt/global/support/user/team/org/constant';
|
||||
import { OrgListItemType } from '@fastgpt/global/support/user/team/org/type';
|
||||
import { memo, useMemo, useState } from 'react';
|
||||
import { useUserStore } from '../../../useUserStore';
|
||||
import { ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { getOrgList, getOrgMembers } from '../api';
|
||||
import { useScrollPagination } from '@fastgpt/web/hooks/useScrollPagination';
|
||||
|
||||
function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
const [orgStack, setOrgStack] = useState<OrgListItemType[]>([]);
|
||||
|
||||
const { userInfo } = useUserStore();
|
||||
|
||||
const path = useMemo(
|
||||
() => (orgStack.length ? getOrgChildrenPath(orgStack[orgStack.length - 1]) : ''),
|
||||
[orgStack]
|
||||
);
|
||||
|
||||
const currentOrg = useMemo(() => {
|
||||
return (
|
||||
orgStack.at(-1) ??
|
||||
({
|
||||
_id: '',
|
||||
path: '',
|
||||
pathId: '',
|
||||
avatar: userInfo?.team.avatar,
|
||||
name: userInfo?.team.teamName
|
||||
} as OrgListItemType) // root org
|
||||
);
|
||||
}, [orgStack, userInfo?.team.avatar, userInfo?.team.teamName]);
|
||||
|
||||
const {
|
||||
data: orgs = [],
|
||||
loading: isLoadingOrgs,
|
||||
refresh: refetchOrgs
|
||||
} = useRequest2(() => getOrgList({ orgPath: path, getPermission }), {
|
||||
manual: false,
|
||||
refreshDeps: [userInfo?.team?.teamId, path]
|
||||
});
|
||||
|
||||
const paths = useMemo(() => {
|
||||
if (!currentOrg) return [];
|
||||
return orgStack
|
||||
.map((org) => {
|
||||
return {
|
||||
parentId: getOrgChildrenPath(org),
|
||||
parentName: org.name
|
||||
};
|
||||
})
|
||||
.filter(Boolean) as ParentTreePathItemType[];
|
||||
}, [currentOrg, orgStack]);
|
||||
|
||||
const onClickOrg = (org: OrgListItemType) => {
|
||||
setOrgStack([...orgStack, org]);
|
||||
};
|
||||
|
||||
const {
|
||||
data: members = [],
|
||||
ScrollData: MemberScrollData,
|
||||
refreshList: refetchMembers
|
||||
} = useScrollPagination(getOrgMembers, {
|
||||
pageSize: 20,
|
||||
params: {
|
||||
orgPath: path
|
||||
},
|
||||
refreshDeps: [path]
|
||||
});
|
||||
|
||||
const onPathClick = (path: string) => {
|
||||
const pathIds = path.split('/');
|
||||
setOrgStack(orgStack.filter((org) => pathIds.includes(org.pathId)));
|
||||
};
|
||||
|
||||
const refresh = () => {
|
||||
refetchOrgs();
|
||||
refetchMembers();
|
||||
};
|
||||
|
||||
const updateCurrentOrg = (data: { name?: string; description?: string; avatar?: string }) => {
|
||||
if (currentOrg.path === '') return;
|
||||
setOrgStack([
|
||||
...orgStack.slice(0, -1),
|
||||
{
|
||||
...currentOrg,
|
||||
name: data.name || currentOrg.name,
|
||||
description: data.description || currentOrg.description,
|
||||
avatar: data.avatar || currentOrg.avatar
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
return {
|
||||
orgStack,
|
||||
currentOrg,
|
||||
orgs,
|
||||
isLoadingOrgs,
|
||||
paths,
|
||||
onClickOrg,
|
||||
members,
|
||||
MemberScrollData,
|
||||
onPathClick,
|
||||
refresh,
|
||||
updateCurrentOrg
|
||||
};
|
||||
}
|
||||
|
||||
export default useOrg;
|
||||
Reference in New Issue
Block a user