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

26 lines
693 B
TypeScript
Raw Normal View History

2023-03-20 10:27:22 -07:00
import { Entities } from 'soapbox/entity-store/entities';
import { useEntityActions } from 'soapbox/entity-store/hooks';
2023-03-28 08:52:41 -07:00
import { groupRelationshipSchema } from 'soapbox/schemas';
import { useGroups } from './useGroups';
import type { Group, GroupRelationship } from 'soapbox/schemas';
2023-03-20 10:27:22 -07:00
function useLeaveGroup(group: Group) {
2023-03-28 08:52:41 -07:00
const { invalidate } = useGroups();
const { createEntity, isSubmitting } = useEntityActions<GroupRelationship>(
2023-03-20 10:27:22 -07:00
[Entities.GROUP_RELATIONSHIPS, group.id],
{ post: `/api/v1/groups/${group.id}/leave` },
{ schema: groupRelationshipSchema },
);
return {
mutate: createEntity,
isSubmitting,
2023-03-28 08:52:41 -07:00
invalidate,
2023-03-20 10:27:22 -07:00
};
}
export { useLeaveGroup };