mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
fix: Group membership addition UI shows incorrect options after pagination, closes #7875
This commit is contained in:
1 parent
fc333abb86
commit
d78eeaba84
3 files changed
+59
-29
No files matched your search
@@ -8,15 +8,18 @@ import User from "~/models/User";
|
||||
import Invite from "~/scenes/Invite";
|
||||
import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import ButtonLink from "~/components/ButtonLink";
|
||||
import DelayedMount from "~/components/DelayedMount";
|
||||
import Empty from "~/components/Empty";
|
||||
import Flex from "~/components/Flex";
|
||||
import Input from "~/components/Input";
|
||||
import PlaceholderList from "~/components/List/Placeholder";
|
||||
import Modal from "~/components/Modal";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import Text from "~/components/Text";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useRequest from "~/hooks/useRequest";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import GroupMemberListItem from "./components/GroupMemberListItem";
|
||||
|
||||
@@ -72,6 +75,14 @@ function AddPeopleToGroup(props: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
const { loading } = useRequest(
|
||||
React.useCallback(
|
||||
() => groupUsers.fetchAll({ id: group.id }),
|
||||
[groupUsers, group]
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
return (
|
||||
<Flex column>
|
||||
<Text as="p" type="secondary">
|
||||
@@ -99,24 +110,30 @@ function AddPeopleToGroup(props: Props) {
|
||||
autoFocus
|
||||
flex
|
||||
/>
|
||||
<PaginatedList
|
||||
empty={
|
||||
query ? (
|
||||
<Empty>{t("No people matching your search")}</Empty>
|
||||
) : (
|
||||
<Empty>{t("No people left to add")}</Empty>
|
||||
)
|
||||
}
|
||||
items={users.notInGroup(group.id, query)}
|
||||
fetch={query ? undefined : users.fetchPage}
|
||||
renderItem={(item: User) => (
|
||||
<GroupMemberListItem
|
||||
key={item.id}
|
||||
user={item}
|
||||
onAdd={() => handleAddUser(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{loading ? (
|
||||
<DelayedMount>
|
||||
<PlaceholderList count={5} />
|
||||
</DelayedMount>
|
||||
) : (
|
||||
<PaginatedList
|
||||
empty={
|
||||
query ? (
|
||||
<Empty>{t("No people matching your search")}</Empty>
|
||||
) : (
|
||||
<Empty>{t("No people left to add")}</Empty>
|
||||
)
|
||||
}
|
||||
items={users.notInGroup(group.id, query)}
|
||||
fetch={query ? undefined : users.fetchPage}
|
||||
renderItem={(item: User) => (
|
||||
<GroupMemberListItem
|
||||
key={item.id}
|
||||
user={item}
|
||||
onAdd={() => handleAddUser(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Modal
|
||||
title={t("Invite people")}
|
||||
onRequestClose={handleInviteModalClose}
|
||||
|
||||
@@ -5,7 +5,11 @@ import GroupUser from "~/models/GroupUser";
|
||||
import { PaginationParams } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import RootStore from "./RootStore";
|
||||
import Store, { RPCAction } from "./base/Store";
|
||||
import Store, {
|
||||
PaginatedResponse,
|
||||
PAGINATION_SYMBOL,
|
||||
RPCAction,
|
||||
} from "./base/Store";
|
||||
|
||||
export default class GroupUsersStore extends Store<GroupUser> {
|
||||
actions = [RPCAction.Create, RPCAction.Delete];
|
||||
@@ -17,20 +21,22 @@ export default class GroupUsersStore extends Store<GroupUser> {
|
||||
@action
|
||||
fetchPage = async (
|
||||
params: PaginationParams | undefined
|
||||
): Promise<GroupUser[]> => {
|
||||
): Promise<PaginatedResponse<GroupUser>> => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/groups.memberships`, params);
|
||||
invariant(res?.data, "Data not available");
|
||||
|
||||
let models: GroupUser[] = [];
|
||||
let response: PaginatedResponse<GroupUser> = [];
|
||||
runInAction(`GroupUsersStore#fetchPage`, () => {
|
||||
res.data.users.forEach(this.rootStore.users.add);
|
||||
models = res.data.groupMemberships.map(this.add);
|
||||
response = res.data.groupMemberships.map(this.add);
|
||||
this.isLoaded = true;
|
||||
});
|
||||
return models;
|
||||
|
||||
response[PAGINATION_SYMBOL] = res.pagination;
|
||||
return response;
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
}
|
||||
|
||||
@@ -209,13 +209,10 @@ router.post(
|
||||
};
|
||||
}
|
||||
|
||||
const groupUsers = await GroupUser.findAll({
|
||||
const options = {
|
||||
where: {
|
||||
groupId: id,
|
||||
},
|
||||
order: [["createdAt", "DESC"]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
include: [
|
||||
{
|
||||
model: User,
|
||||
@@ -224,10 +221,20 @@ router.post(
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
const [total, groupUsers] = await Promise.all([
|
||||
GroupUser.count(options),
|
||||
GroupUser.findAll({
|
||||
...options,
|
||||
order: [["createdAt", "DESC"]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
pagination: { ...ctx.state.pagination, total },
|
||||
data: {
|
||||
groupMemberships: groupUsers.map((groupUser) =>
|
||||
presentGroupUser(groupUser, { includeUser: true })
|
||||
|
||||
Reference in new issue
Block a user