Update entity in store after canceling request
This commit is contained in:
parent
e78bbf4e19
commit
f20dade50b
2 changed files with 14 additions and 9 deletions
|
@ -3,14 +3,14 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
|||
|
||||
import { openModal } from 'soapbox/actions/modals';
|
||||
import { Button } from 'soapbox/components/ui';
|
||||
import { deleteEntities } from 'soapbox/entity-store/actions';
|
||||
import { importEntities } from 'soapbox/entity-store/actions';
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useAppDispatch } from 'soapbox/hooks';
|
||||
import { useCancelMembershipRequest, useJoinGroup, useLeaveGroup } from 'soapbox/hooks/api';
|
||||
import { GroupRoles } from 'soapbox/schemas/group-member';
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
import type { Group } from 'soapbox/types/entities';
|
||||
import type { Group, GroupRelationship } from 'soapbox/types/entities';
|
||||
|
||||
interface IGroupActionButton {
|
||||
group: Group
|
||||
|
@ -66,7 +66,11 @@ const GroupActionButton = ({ group }: IGroupActionButton) => {
|
|||
|
||||
const onCancelRequest = () => cancelRequest.mutate({}, {
|
||||
onSuccess() {
|
||||
dispatch(deleteEntities([group.id], Entities.GROUP_RELATIONSHIPS));
|
||||
const entity = {
|
||||
...group.relationship as GroupRelationship,
|
||||
requested: false,
|
||||
};
|
||||
dispatch(importEntities([entity], Entities.GROUP_RELATIONSHIPS));
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { useOwnAccount } from 'soapbox/hooks';
|
||||
import { useCreateEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi, useOwnAccount } from 'soapbox/hooks';
|
||||
|
||||
import type { Group, GroupRelationship } from 'soapbox/schemas';
|
||||
import type { Group } from 'soapbox/schemas';
|
||||
|
||||
function useCancelMembershipRequest(group: Group) {
|
||||
const api = useApi();
|
||||
const me = useOwnAccount();
|
||||
|
||||
const { createEntity, isLoading } = useEntityActions<GroupRelationship>(
|
||||
[Entities.GROUP_RELATIONSHIPS, group.id],
|
||||
{ post: `/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject` },
|
||||
const { createEntity, isLoading } = useCreateEntity(
|
||||
[Entities.GROUP_RELATIONSHIPS],
|
||||
() => api.post(`/api/v1/groups/${group.id}/membership_requests/${me?.id}/reject`),
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue