2023-03-20 13:54:06 -07:00
|
|
|
import { Entities } from 'soapbox/entity-store/entities';
|
2023-03-22 14:31:49 -07:00
|
|
|
import { useDismissEntity, 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 14:31:49 -07:00
|
|
|
const authorize = useDismissEntity(path, (accountId) => {
|
2023-03-20 15:46:10 -07:00
|
|
|
return api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/authorize`);
|
2023-03-22 14:31:49 -07:00
|
|
|
});
|
2023-03-20 15:46:10 -07:00
|
|
|
|
2023-03-22 14:31:49 -07:00
|
|
|
const reject = useDismissEntity(path, (accountId) => {
|
2023-03-20 15:46:10 -07:00
|
|
|
return api.post(`/api/v1/groups/${groupId}/membership_requests/${accountId}/reject`);
|
2023-03-22 14:31:49 -07:00
|
|
|
});
|
2023-03-20 15:46:10 -07:00
|
|
|
|
|
|
|
const { entities, ...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
|
|
|
|
|
|
|
return {
|
|
|
|
accounts: entities,
|
|
|
|
authorize,
|
|
|
|
reject,
|
|
|
|
...rest,
|
|
|
|
};
|
2023-03-20 13:54:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export { useGroupMembershipRequests };
|