Move Group mutations to entities
This commit is contained in:
21
app/soapbox/hooks/api/groups/useCancelMembershipRequest.ts
Normal file
21
app/soapbox/hooks/api/groups/useCancelMembershipRequest.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { useOwnAccount } from 'soapbox/hooks';
|
||||
|
||||
import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||
|
||||
function useCancelMembershipRequest(group: Group) {
|
||||
const me = useOwnAccount();
|
||||
|
||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||
{ post: `/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject` },
|
||||
);
|
||||
|
||||
return {
|
||||
mutate: createEntity,
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
export { useCancelMembershipRequest };
|
||||
20
app/soapbox/hooks/api/groups/useJoinGroup.ts
Normal file
20
app/soapbox/hooks/api/groups/useJoinGroup.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { groupRelationshipSchema } from 'soapbox/schemas';
|
||||
|
||||
import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||
|
||||
function useJoinGroup(group: Group) {
|
||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||
{ post: `/api/v1/groups/${group.id}/join` },
|
||||
{ schema: groupRelationshipSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
mutate: createEntity,
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
export { useJoinGroup };
|
||||
18
app/soapbox/hooks/api/groups/useLeaveGroup.ts
Normal file
18
app/soapbox/hooks/api/groups/useLeaveGroup.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { Group, GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas';
|
||||
|
||||
function useLeaveGroup(group: Group) {
|
||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||
{ post: `/api/v1/groups/${group.id}/leave` },
|
||||
{ schema: groupRelationshipSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
mutate: createEntity,
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
export { useLeaveGroup };
|
||||
Reference in New Issue
Block a user