Skip to content

Commit

Permalink
fix(clerk-js): Mutate membership requests after accept or reject (#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef authored Aug 25, 2023
1 parent b2296d6 commit 21d8bee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .changeset/curly-carpets-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { handleError } from '../../utils';
import { DataTable, RowContainer } from './MemberListTable';

const ITEMS_PER_PAGE = 10;

const membershipRequestsParams = {
pageSize: ITEMS_PER_PAGE,
};
export const RequestToJoinList = () => {
const card = useCardState();
const { organization, membershipRequests } = useCoreOrganization({
membershipRequests: {
pageSize: ITEMS_PER_PAGE,
},
membershipRequests: membershipRequestsParams,
});

if (!organization) {
Expand Down Expand Up @@ -47,26 +49,24 @@ const RequestRow = withCardStateProvider(
(props: { request: OrganizationMembershipRequestResource; onError: ReturnType<typeof useCardState>['setError'] }) => {
const { request, onError } = props;
const card = useCardState();
const { membershipRequests } = useCoreOrganization();

const mutateSwrState = () => {
const unstable__mutate = (membershipRequests as any).unstable__mutate;
if (unstable__mutate && typeof unstable__mutate === 'function') {
unstable__mutate();
}
};
const { membershipRequests } = useCoreOrganization({
membershipRequests: membershipRequestsParams,
});

const onAccept = () => {
return card
.runAsync(request.accept, 'accept')
.then(mutateSwrState)
.runAsync(async () => {
await request.accept();
await (membershipRequests as any).unstable__mutate?.();
}, 'accept')
.catch(err => handleError(err, [], onError));
};

const onReject = () => {
return card
.runAsync(request.reject, 'reject')
.then(mutateSwrState)
.runAsync(async () => {
await request.reject();
await (membershipRequests as any).unstable__mutate?.();
}, 'reject')
.catch(err => handleError(err, [], onError));
};

Expand Down

0 comments on commit 21d8bee

Please sign in to comment.