pref: member list (#4344)
* chore: search member new api * chore: permission * fix: ts error * fix: member modal
This commit is contained in:
@@ -34,8 +34,16 @@ export const putSwitchTeam = (teamId: string) =>
|
||||
PUT<string>(`/proApi/support/user/team/switch`, { teamId });
|
||||
|
||||
/* --------------- team member ---------------- */
|
||||
export const getTeamMembers = (props: PaginationProps<{ withLeaved?: boolean }>) =>
|
||||
GET<PaginationResponse<TeamMemberItemType>>(`/proApi/support/user/team/member/list`, props);
|
||||
export const getTeamMembers = (
|
||||
props: PaginationProps<{
|
||||
status?: 'active' | 'inactive';
|
||||
withOrgs?: boolean;
|
||||
withPermission?: boolean;
|
||||
searchKey?: string;
|
||||
orgId?: string;
|
||||
groupId?: string;
|
||||
}>
|
||||
) => POST<PaginationResponse<TeamMemberItemType>>(`/proApi/support/user/team/member/list`, props);
|
||||
export const getTeamMemberCount = () =>
|
||||
GET<{ count: number }>(`/proApi/support/user/team/member/count`);
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@ 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 = (params: { orgPath: string; getPermission?: boolean }) =>
|
||||
GET<OrgListItemType[]>(`/proApi/support/user/team/org/list`, params);
|
||||
export const getOrgList = (params: {
|
||||
orgId: string;
|
||||
withPermission?: boolean;
|
||||
searchKey?: string;
|
||||
}) => POST<OrgListItemType[]>(`/proApi/support/user/team/org/list`, params);
|
||||
|
||||
export const postCreateOrg = (data: postCreateOrgData) =>
|
||||
POST('/proApi/support/user/team/org/create', data);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
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 { memo, useEffect, 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';
|
||||
import { getTeamMembers } from '../../api';
|
||||
import _ from 'lodash';
|
||||
|
||||
function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
function useOrg({ withPermission = true }: { withPermission?: boolean } = {}) {
|
||||
const [orgStack, setOrgStack] = useState<OrgListItemType[]>([]);
|
||||
const [searchKey, setSearchKey] = useState('');
|
||||
|
||||
const { userInfo } = useUserStore();
|
||||
|
||||
@@ -34,10 +37,18 @@ function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
data: orgs = [],
|
||||
loading: isLoadingOrgs,
|
||||
refresh: refetchOrgs
|
||||
} = useRequest2(() => getOrgList({ orgPath: path, getPermission }), {
|
||||
manual: false,
|
||||
refreshDeps: [userInfo?.team?.teamId, path]
|
||||
});
|
||||
} = useRequest2(
|
||||
() => getOrgList({ orgId: currentOrg._id, withPermission: withPermission, searchKey }),
|
||||
{
|
||||
manual: false,
|
||||
refreshDeps: [userInfo?.team?.teamId, path, currentOrg._id]
|
||||
}
|
||||
);
|
||||
const search = _.debounce(() => {
|
||||
if (!searchKey) return;
|
||||
refetchOrgs();
|
||||
}, 200);
|
||||
useEffect(() => search, [searchKey]);
|
||||
|
||||
const paths = useMemo(() => {
|
||||
if (!currentOrg) return [];
|
||||
@@ -53,16 +64,20 @@ function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
|
||||
const onClickOrg = (org: OrgListItemType) => {
|
||||
setOrgStack([...orgStack, org]);
|
||||
setSearchKey('');
|
||||
};
|
||||
|
||||
const {
|
||||
data: members = [],
|
||||
ScrollData: MemberScrollData,
|
||||
refreshList: refetchMembers
|
||||
} = useScrollPagination(getOrgMembers, {
|
||||
} = useScrollPagination(getTeamMembers, {
|
||||
pageSize: 20,
|
||||
params: {
|
||||
orgPath: path
|
||||
orgId: currentOrg._id,
|
||||
withOrgs: false,
|
||||
withPermission: true,
|
||||
status: 'active'
|
||||
},
|
||||
refreshDeps: [path]
|
||||
});
|
||||
@@ -70,6 +85,7 @@ function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
const onPathClick = (path: string) => {
|
||||
const pathIds = path.split('/');
|
||||
setOrgStack(orgStack.filter((org) => pathIds.includes(org.pathId)));
|
||||
setSearchKey('');
|
||||
};
|
||||
|
||||
const refresh = () => {
|
||||
@@ -101,7 +117,9 @@ function useOrg({ getPermission = true }: { getPermission?: boolean } = {}) {
|
||||
MemberScrollData,
|
||||
onPathClick,
|
||||
refresh,
|
||||
updateCurrentOrg
|
||||
updateCurrentOrg,
|
||||
searchKey,
|
||||
setSearchKey
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user