useGroupMembershipRequests: disable for non-staff roles

This commit is contained in:
Alex Gleason 2023-04-04 15:14:06 -05:00
parent 87fd56ffee
commit f08d23c055
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 2 deletions

View file

@ -2,6 +2,9 @@ import { Entities } from 'soapbox/entity-store/entities';
import { useEntities, useIncrementEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks/useApi';
import { accountSchema } from 'soapbox/schemas';
import { GroupRoles } from 'soapbox/schemas/group-member';
import { useGroupRelationship } from './useGroups';
import type { ExpandedEntitiesPath } from 'soapbox/entity-store/hooks/types';
@ -9,10 +12,15 @@ function useGroupMembershipRequests(groupId: string) {
const api = useApi();
const path: ExpandedEntitiesPath = [Entities.ACCOUNTS, 'membership_requests', groupId];
const { entity: relationship } = useGroupRelationship(groupId);
const { entities, invalidate, ...rest } = useEntities(
path,
() => api.get(`/api/v1/groups/${groupId}/membership_requests`),
{ schema: accountSchema },
{
schema: accountSchema,
enabled: relationship?.role === GroupRoles.OWNER || relationship?.role === GroupRoles.ADMIN,
},
);
const { incrementEntity: authorize } = useIncrementEntity(path, -1, async (accountId: string) => {

View file

@ -76,4 +76,4 @@ function useGroupRelationships(groupIds: string[]) {
};
}
export { useGroup, useGroups, useGroupRelationships };
export { useGroup, useGroups, useGroupRelationship, useGroupRelationships };