pleroma/app/soapbox/hooks/api/groups/useGroupMembershipRequests.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Entities } from 'soapbox/entity-store/entities';
2023-03-22 17:45:02 -07:00
import { useEntities, useIncrementEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks/useApi';
import { accountSchema } from 'soapbox/schemas';
import type { ExpandedEntitiesPath } from 'soapbox/entity-store/hooks/types';
function useGroupMembershipRequests(groupId: string) {
const api = useApi();
const path: ExpandedEntitiesPath = [Entities.ACCOUNTS, 'membership_requests', groupId];
const { entities, invalidate, ...rest } = useEntities(
path,
`/api/v1/groups/${groupId}/membership_requests`,
{ schema: accountSchema },
);
2023-03-22 17:45:02 -07:00
const authorize = useIncrementEntity(path, -1, (accountId: string) => {
return api
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`)
.then(invalidate);
2023-03-22 17:45:02 -07:00
});
2023-03-22 17:45:02 -07:00
const reject = useIncrementEntity(path, -1, (accountId: string) => {
return api
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`)
.then(invalidate);
2023-03-22 17:45:02 -07:00
});
return {
accounts: entities,
authorize,
reject,
...rest,
};
}
export { useGroupMembershipRequests };