Skip to content

Commit

Permalink
fix: catch error if user tries to join meeting twice (#10320)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkrick authored Oct 9, 2024
1 parent 3476051 commit 887abd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/client/hooks/useAutoCheckIn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import graphql from 'babel-plugin-relay/macro'
import {useEffect} from 'react'
import {useEffect, useRef} from 'react'
import {readInlineData} from 'relay-runtime'
import {useAutoCheckIn_meeting$key} from '~/__generated__/useAutoCheckIn_meeting.graphql'
import JoinMeetingMutation from '../mutations/JoinMeetingMutation'
Expand All @@ -12,6 +12,7 @@ const useAutoCheckIn = (meetingRef: useAutoCheckIn_meeting$key) => {
const {history, location} = useRouter()
const router = {history, location}
const queryKey = 'useAutoCheckIn'
const hasCalledJoinedRef = useRef(false)
useEffect(() => {
const meeting = readInlineData(
graphql`
Expand All @@ -33,7 +34,8 @@ const useAutoCheckIn = (meetingRef: useAutoCheckIn_meeting$key) => {
}
if (viewerMeetingMember) {
subscribeToMeeting()
} else if (!endedAt) {
} else if (!endedAt && !hasCalledJoinedRef.current) {
hasCalledJoinedRef.current = true
JoinMeetingMutation(
atmosphere,
{meetingId},
Expand Down
7 changes: 6 additions & 1 deletion packages/server/graphql/mutations/joinMeeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ const joinMeeting = {
const teamMemberId = toTeamMemberId(teamId, viewerId)
const teamMember = await dataLoader.get('teamMembers').loadNonNull(teamMemberId)
const meetingMember = createMeetingMember(meeting, teamMember)
await pg.insertInto('MeetingMember').values(meetingMember).execute()
try {
await pg.insertInto('MeetingMember').values(meetingMember).execute()
} catch {
return {error: {message: 'Could not join meeting'}}
}

const addStageToPhase = async (
stage: CheckInStage | UpdatesStage | TeamPromptResponseStage,
phaseType: NewMeetingPhase['phaseType']
Expand Down

0 comments on commit 887abd4

Please sign in to comment.