forked from mattermost/mattermost-plugin-msteams
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MI-3833]: Link channel modal integration (#43)
* [MI-3833]: Link Channel Modal integration * [MI-3833]: Add constants * [MI-3833]: Update constants * [MI-3837]: Integrate webhooks and enhancements (#47) * [MI-3837]: Integrate webhooks and enhancements * [MI-3837]: Remove yarn lock * [MI-3834] Add unlink button on hover state on linked channel list (#45) * [MI-3834] Add unlink button on hover state on linked channel list * [MI-3834] Update style and props of unlink button * [MI-3836] Integrate API to unlink channels and websocket event (#46) * [MI-3836] Integrate API to unlink channels and websocket event * [MI-3836] Fix issue of alert not visible * [MI-3836] Update dialog component * [MI-3836] Minor review fixes and revert some changes --------- Co-authored-by: Ayush Thakur <[email protected]>
- Loading branch information
1 parent
606c6d5
commit 4d5aad8
Showing
29 changed files
with
506 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,16 @@ | ||
import React from 'react'; | ||
import {useDispatch} from 'react-redux'; | ||
|
||
import {Dialog as MMDialog, LinearProgress, DialogProps} from '@brightscout/mattermost-ui-library'; | ||
|
||
import usePluginApi from 'hooks/usePluginApi'; | ||
import {getDialogState} from 'selectors'; | ||
import {closeDialog} from 'reducers/dialog'; | ||
|
||
export const Dialog = ({onCloseHandler, onSubmitHandler}: Pick<DialogProps, 'onCloseHandler' | 'onSubmitHandler'>) => { | ||
const dispatch = useDispatch(); | ||
const {state} = usePluginApi(); | ||
const {show, title, description, destructive, primaryButtonText, secondaryButtonText, isLoading} = getDialogState(state); | ||
|
||
const handleClose = () => dispatch(closeDialog()); | ||
|
||
return ( | ||
<MMDialog | ||
description={description} | ||
destructive={destructive} | ||
show={show} | ||
primaryButtonText={primaryButtonText} | ||
secondaryButtonText={secondaryButtonText} | ||
onCloseHandler={() => { | ||
handleClose(); | ||
onCloseHandler(); | ||
}} | ||
onSubmitHandler={onSubmitHandler} | ||
className='disconnect-dialog' | ||
title={title} | ||
> | ||
{isLoading && <LinearProgress/>} | ||
</MMDialog> | ||
); | ||
}; | ||
export const Dialog = ({ | ||
children, | ||
isLoading = false, | ||
...rest | ||
}: DialogProps & {isLoading?: boolean, children: React.ReactNode}) => ( | ||
<MMDialog | ||
{...rest} | ||
> | ||
{isLoading && <LinearProgress className='absolute w-full left-0 top-62'/>} | ||
{children} | ||
</MMDialog> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 111 additions & 36 deletions
147
webapp/src/components/LinkChannelModal/LinkChannelModal.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,130 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import React, {useState} from 'react'; | ||
|
||
import {LinearProgress, Modal} from '@brightscout/mattermost-ui-library'; | ||
|
||
import {useDispatch} from 'react-redux'; | ||
|
||
import usePluginApi from 'hooks/usePluginApi'; | ||
|
||
import {getCurrentTeam, getLinkModalState} from 'selectors'; | ||
|
||
import {SearchMMChannels} from './SearchMMChannels'; | ||
import {SearchMSTeams} from './SearchMSTeams'; | ||
import {Dialog} from 'components/Dialog'; | ||
import {pluginApiServiceConfigs} from 'constants/apiService.constant'; | ||
import useApiRequestCompletionState from 'hooks/useApiRequestCompletionState'; | ||
import {hideLinkModal, preserveState, resetState, setLinkModalLoading, showLinkModal} from 'reducers/linkModal'; | ||
import useAlert from 'hooks/useAlert'; | ||
|
||
import {refetch} from 'reducers/refetchState'; | ||
|
||
import {SearchMSChannels} from './SearchMSChannels'; | ||
import {SearchMSTeams} from './SearchMSTeams'; | ||
import {SearchMMChannels} from './SearchMMChannels'; | ||
|
||
export const LinkChannelModal = ({onClose}: {onClose: () => void}) => { | ||
const {state} = usePluginApi(); | ||
export const LinkChannelModal = () => { | ||
const dispatch = useDispatch(); | ||
const showAlert = useAlert(); | ||
const {state, makeApiRequestWithCompletionStatus} = usePluginApi(); | ||
const {show = false, isLoading} = getLinkModalState(state); | ||
const currentTeam = getCurrentTeam(state); | ||
const {currentTeamId} = getCurrentTeam(state); | ||
|
||
// Show retry dialog component | ||
const [showRetryDialog, setShowRetryDialog] = useState(false); | ||
|
||
const [mmChannel, setMMChannel] = useState<MMTeamOrChannel | null>(null); | ||
const [msTeam, setMSTeam] = useState<MSTeamOrChannel | null>(null); | ||
const [msChannel, setMSChannel] = useState<MSTeamOrChannel | null>(null); | ||
const [linkChannelsPayload, setLinkChannelsPayload] = useState<LinkChannelsPayload | null>(null); | ||
|
||
const handleModalClose = () => { | ||
setMMChannel(null); | ||
setMSTeam(null); | ||
setMSChannel(null); | ||
onClose(); | ||
const handleModalClose = (preserve?: boolean) => { | ||
if (!preserve) { | ||
setMMChannel(null); | ||
setMSTeam(null); | ||
setMSChannel(null); | ||
} | ||
dispatch(resetState()); | ||
dispatch(hideLinkModal()); | ||
}; | ||
|
||
const handleChannelLinking = () => { | ||
const payload: LinkChannelsPayload = { | ||
mattermostTeamID: currentTeamId || '', | ||
mattermostChannelID: mmChannel?.id || '', | ||
msTeamsTeamID: msTeam?.ID || '', | ||
msTeamsChannelID: msChannel?.ID || '', | ||
}; | ||
setLinkChannelsPayload(payload); | ||
makeApiRequestWithCompletionStatus(pluginApiServiceConfigs.linkChannels.apiServiceName, payload); | ||
dispatch(setLinkModalLoading(true)); | ||
}; | ||
|
||
useApiRequestCompletionState({ | ||
serviceName: pluginApiServiceConfigs.linkChannels.apiServiceName, | ||
payload: linkChannelsPayload as LinkChannelsPayload, | ||
handleSuccess: () => { | ||
dispatch(setLinkModalLoading(false)); | ||
handleModalClose(); | ||
dispatch(refetch()); | ||
showAlert({ | ||
message: 'Successfully linked channels', | ||
severity: 'success', | ||
}); | ||
}, | ||
handleError: () => { | ||
dispatch(setLinkModalLoading(false)); | ||
handleModalClose(true); | ||
setShowRetryDialog(true); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Modal | ||
show={show} | ||
title='Link a channel' | ||
subtitle='Link a channel in Mattermost with a channel in Microsoft Teams' | ||
primaryActionText='Link Channels' | ||
secondaryActionText='Cancel' | ||
onFooterCloseHandler={handleModalClose} | ||
onHeaderCloseHandler={handleModalClose} | ||
isPrimaryButtonDisabled={!mmChannel || !msChannel || !msTeam} | ||
onSubmitHandler={() => { | ||
// TODO: handle channel linking | ||
}} | ||
> | ||
{isLoading && <LinearProgress className='fixed w-full left-0 top-100'/>} | ||
<SearchMMChannels | ||
setChannel={setMMChannel} | ||
teamId={currentTeam} | ||
/> | ||
<hr className='w-full my-32'/> | ||
<SearchMSTeams setMSTeam={setMSTeam}/> | ||
<SearchMSChannels | ||
setChannel={setMSChannel} | ||
teamId={msTeam?.ID} | ||
/> | ||
</Modal> | ||
<> | ||
<Modal | ||
show={show} | ||
className='msteams-sync-modal' | ||
title='Link a channel' | ||
subtitle='Link a channel in Mattermost with a channel in Microsoft Teams' | ||
primaryActionText='Link Channels' | ||
secondaryActionText='Cancel' | ||
onFooterCloseHandler={handleModalClose} | ||
onHeaderCloseHandler={handleModalClose} | ||
isPrimaryButtonDisabled={!mmChannel || !msChannel || !msTeam} | ||
onSubmitHandler={handleChannelLinking} | ||
backdrop={true} | ||
> | ||
{isLoading && <LinearProgress className='fixed w-full left-0 top-100'/>} | ||
<SearchMMChannels | ||
setChannel={setMMChannel} | ||
teamId={currentTeamId} | ||
/> | ||
<hr className='w-full my-32'/> | ||
<SearchMSTeams setMSTeam={setMSTeam}/> | ||
<SearchMSChannels | ||
setChannel={setMSChannel} | ||
teamId={msTeam?.ID} | ||
/> | ||
</Modal> | ||
<Dialog | ||
show={showRetryDialog} | ||
destructive={true} | ||
primaryButtonText='Try Again' | ||
secondaryButtonText='Cancel' | ||
title='Unable to link channels' | ||
onSubmitHandler={() => { | ||
dispatch(preserveState({ | ||
mmChannel: mmChannel?.displayName ?? '', | ||
msChannel: msChannel?.DisplayName ?? '', | ||
msTeam: msTeam?.DisplayName ?? '', | ||
})); | ||
setShowRetryDialog(false); | ||
dispatch(showLinkModal()); | ||
}} | ||
onCloseHandler={() => { | ||
setShowRetryDialog(false); | ||
dispatch(resetState()); | ||
}} | ||
> | ||
{'We were not able to link the selected channels. Please try again.'} | ||
</Dialog> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.