-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Mattermost): Invite to Meeting (#10635)
- Loading branch information
1 parent
be72f7a
commit cf48ae2
Showing
16 changed files
with
240 additions
and
37 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
packages/mattermost-plugin/components/InviteToMeetingModal/InviteToMeetingModal.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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import graphql from 'babel-plugin-relay/macro' | ||
import {useEffect, useMemo, useState} from 'react' | ||
import {useDispatch, useSelector} from 'react-redux' | ||
import {useLazyLoadQuery} from 'react-relay' | ||
|
||
import {closeInviteToMeetingModal} from '../../reducers' | ||
|
||
import Select from '../Select' | ||
|
||
import {Client4} from 'mattermost-redux/client' | ||
import {getCurrentUser} from 'mattermost-redux/selectors/entities/common' | ||
import {Post} from 'mattermost-redux/types/posts' | ||
import {PALETTE} from '~/styles/paletteV3' | ||
import {InviteToMeetingModalQuery} from '../../__generated__/InviteToMeetingModalQuery.graphql' | ||
import {useCurrentChannel} from '../../hooks/useCurrentChannel' | ||
import useMassInvitationToken from '../../hooks/useMassInvitationToken' | ||
import LoadingSpinner from '../LoadingSpinner' | ||
import Modal from '../Modal' | ||
|
||
const InviteToMeetingModal = () => { | ||
const channel = useCurrentChannel() | ||
const data = useLazyLoadQuery<InviteToMeetingModalQuery>( | ||
graphql` | ||
query InviteToMeetingModalQuery($channel: ID!) { | ||
config { | ||
parabolUrl | ||
} | ||
linkedTeamIds(channel: $channel) | ||
viewer { | ||
teams { | ||
id | ||
name | ||
activeMeetings { | ||
id | ||
teamId | ||
name | ||
meetingType | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
channel: channel.id | ||
} | ||
) | ||
|
||
const {viewer, config, linkedTeamIds} = data | ||
const parabolUrl = config?.parabolUrl | ||
const {teams} = viewer | ||
const linkedTeams = useMemo( | ||
() => viewer.teams.filter((team) => !linkedTeamIds || linkedTeamIds.includes(team.id)), | ||
[viewer, linkedTeamIds] | ||
) | ||
const activeMeetings = useMemo( | ||
() => linkedTeams.flatMap((team) => team.activeMeetings), | ||
[linkedTeams] | ||
) | ||
|
||
const [selectedMeeting, setSelectedMeeting] = useState<(typeof activeMeetings)[number]>() | ||
|
||
useEffect(() => { | ||
if (!selectedMeeting && activeMeetings && activeMeetings.length > 0) { | ||
setSelectedMeeting(activeMeetings[0]) | ||
} | ||
}, [activeMeetings, selectedMeeting]) | ||
|
||
const getToken = useMassInvitationToken({ | ||
teamId: selectedMeeting?.teamId, | ||
meetingId: selectedMeeting?.id | ||
}) | ||
|
||
const currentUser = useSelector(getCurrentUser) | ||
|
||
const dispatch = useDispatch() | ||
const handleClose = () => { | ||
dispatch(closeInviteToMeetingModal()) | ||
} | ||
|
||
const handleStart = async () => { | ||
if (!selectedMeeting) { | ||
return | ||
} | ||
const {name: meetingName, id: meetingId} = selectedMeeting | ||
const token = await getToken() | ||
if (!token) { | ||
return | ||
} | ||
const team = linkedTeams.find((team) => team.id === selectedMeeting.teamId)! | ||
const teamName = team.name | ||
const inviteUrl = `${parabolUrl}/invitation-link/${token}` | ||
const meetingUrl = `${parabolUrl}/meet/${meetingId}` | ||
const {username, nickname, first_name, last_name} = currentUser | ||
const userName = nickname || username || `${first_name} ${last_name}` | ||
const props = { | ||
attachments: [ | ||
{ | ||
fallback: `${userName} invited you to join the meeting ${meetingName}`, | ||
title: `${userName} invited you to join a meeting in [Parabol](${meetingUrl})`, | ||
color: PALETTE.GRAPE_500, | ||
fields: [ | ||
{ | ||
short: true, | ||
title: 'Team', | ||
value: teamName | ||
}, | ||
{ | ||
short: true, | ||
title: 'Meeting', | ||
value: meetingName | ||
}, | ||
{ | ||
short: false, | ||
value: ` | ||
| [Join Meeting](${inviteUrl}) | | ||
|:--------------------:| | ||
||` | ||
} | ||
] | ||
} | ||
] | ||
} | ||
Client4.createPost({ | ||
channel_id: channel.id, | ||
props | ||
} as Partial<Post> as Post) | ||
handleClose() | ||
} | ||
|
||
return ( | ||
<Modal | ||
title='Invite Channel to Join Activity' | ||
commitButtonLabel='Share Invite' | ||
handleCommit={handleStart} | ||
handleClose={handleClose} | ||
> | ||
{teams ? ( | ||
<Select | ||
label='Activity' | ||
required={true} | ||
options={activeMeetings ?? []} | ||
value={selectedMeeting} | ||
onChange={setSelectedMeeting} | ||
/> | ||
) : ( | ||
<LoadingSpinner /> | ||
)} | ||
</Modal> | ||
) | ||
} | ||
|
||
export default InviteToMeetingModal |
22 changes: 22 additions & 0 deletions
22
packages/mattermost-plugin/components/InviteToMeetingModal/index.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {lazy, Suspense} from 'react' | ||
import {useSelector} from 'react-redux' | ||
|
||
import {isInviteToMeetingModalVisible} from '../../selectors' | ||
|
||
const InviteToMeetingModal = lazy( | ||
() => import(/* webpackChunkName: 'CreateTaskModal' */ './InviteToMeetingModal') | ||
) | ||
|
||
const InviteToMeetingModalRoot = () => { | ||
const isVisible = useSelector(isInviteToMeetingModalVisible) | ||
if (!isVisible) { | ||
return null | ||
} | ||
return ( | ||
<Suspense fallback={null}> | ||
<InviteToMeetingModal /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
export default InviteToMeetingModalRoot |
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
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
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
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.