2023-03-20 13:54:06 -07:00
|
|
|
import { Entities } from 'soapbox/entity-store/entities';
|
2023-03-22 16:48:24 -07:00
|
|
|
import { useEntities } from 'soapbox/entity-store/hooks';
|
2023-03-20 15:46:10 -07:00
|
|
|
import { useApi } from 'soapbox/hooks/useApi';
|
2023-03-20 13:54:06 -07:00
|
|
|
import { accountSchema } from 'soapbox/schemas';
|
|
|
|
|
2023-03-22 14:31:49 -07:00
|
|
|
import type { ExpandedEntitiesPath } from 'soapbox/entity-store/hooks/types';
|
|
|
|
|
2023-03-20 13:54:06 -07:00
|
|
|
function useGroupMembershipRequests(groupId: string) {
|
2023-03-20 15:46:10 -07:00
|
|
|
const api = useApi();
|
2023-03-22 14:31:49 -07:00
|
|
|
const path: ExpandedEntitiesPath = [Entities.ACCOUNTS, 'membership_requests', groupId];
|
2023-03-20 15:46:10 -07:00
|
|
|
|
2023-03-22 16:48:24 -07:00
|
|
|
const { entities, invalidate, ...rest } = useEntities(
|
2023-03-22 14:31:49 -07:00
|
|
|
path,
|
2023-03-20 13:54:06 -07:00
|
|
|
`/api/v1/groups/${groupId}/membership_requests`,
|
|
|
|
{ schema: accountSchema },
|
|
|
|
);
|
2023-03-20 15:46:10 -07:00
|
|
|
|
2023-03-22 16:48:24 -07:00
|
|
|
function authorize(accountId: string) {
|
|
|
|
return api
|
|
|
|
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`)
|
|
|
|
.then(invalidate);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reject(accountId: string) {
|
|
|
|
return api
|
|
|
|
.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`)
|
|
|
|
.then(invalidate);
|
|
|
|
}
|
|
|
|
|
2023-03-20 15:46:10 -07:00
|
|
|
return {
|
|
|
|
accounts: entities,
|
|
|
|
authorize,
|
|
|
|
reject,
|
|
|
|
...rest,
|
|
|
|
};
|
2023-03-20 13:54:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export { useGroupMembershipRequests };
|