diff --git a/lib/actions/link-actions.js b/lib/actions/link-actions.js --- a/lib/actions/link-actions.js +++ b/lib/actions/link-actions.js @@ -6,6 +6,8 @@ InviteLinkVerificationResponse, CreateOrUpdatePublicLinkRequest, InviteLink, + DisableInviteLinkRequest, + DisableInviteLinkPayload, } from '../types/link-types.js'; import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; @@ -75,6 +77,26 @@ }; }; +const disableInviteLinkLinkActionTypes = Object.freeze({ + started: 'DISABLE_INVITE_LINK_STARTED', + success: 'DISABLE_INVITE_LINK_SUCCESS', + failed: 'DISABLE_INVITE_LINK_FAILED', +}); + +const disableInviteLink = + ( + callServerEndpoint: CallServerEndpoint, + ): (( + request: DisableInviteLinkRequest, + ) => Promise) => + async request => { + await callServerEndpoint('disable_invite_link', request); + return { + name: request.name, + communityID: request.communityID, + }; + }; + export { verifyInviteLinkActionTypes, verifyInviteLink, @@ -82,4 +104,6 @@ fetchPrimaryInviteLinks, createOrUpdatePublicLinkActionTypes, createOrUpdatePublicLink, + disableInviteLinkLinkActionTypes, + disableInviteLink, }; diff --git a/lib/reducers/invite-links-reducer.js b/lib/reducers/invite-links-reducer.js --- a/lib/reducers/invite-links-reducer.js +++ b/lib/reducers/invite-links-reducer.js @@ -2,6 +2,7 @@ import { createOrUpdatePublicLinkActionTypes, + disableInviteLinkLinkActionTypes, fetchPrimaryInviteLinkActionTypes, } from '../actions/link-actions.js'; import type { InviteLinksStore } from '../types/link-types.js'; @@ -34,6 +35,24 @@ }, }, }; + } else if (action.type === disableInviteLinkLinkActionTypes.success) { + const communityID = action.payload.communityID; + const currentPrimaryLink = state.links[communityID]?.primaryLink; + const communityLinks = { + ...state.links[communityID], + primaryLink: + currentPrimaryLink?.name === action.payload.name + ? null + : currentPrimaryLink, + }; + + return { + ...state, + links: { + ...state.links, + [communityID]: communityLinks, + }, + }; } return state; } diff --git a/lib/types/link-types.js b/lib/types/link-types.js --- a/lib/types/link-types.js +++ b/lib/types/link-types.js @@ -63,3 +63,8 @@ +name: string, +communityID: string, }; + +export type DisableInviteLinkPayload = { + +name: string, + +communityID: string, +}; diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -41,6 +41,7 @@ InviteLink, InviteLinksStore, InviteLinkVerificationResponse, + DisableInviteLinkPayload, } from './link-types.js'; import type { LoadingStatus, LoadingInfo } from './loading-types.js'; import type { UpdateMultimediaMessageMediaPayload } from './media-types.js'; @@ -1046,6 +1047,22 @@ +error: true, +payload: Error, +loadingInfo: LoadingInfo, + } + | { + +type: 'DISABLE_INVITE_LINK_STARTED', + +loadingInfo?: LoadingInfo, + +payload?: void, + } + | { + +type: 'DISABLE_INVITE_LINK_SUCCESS', + +payload: DisableInviteLinkPayload, + +loadingInfo: LoadingInfo, + } + | { + +type: 'DISABLE_INVITE_LINK_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, }; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string);