Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kudos): show snackbar when reflection with kudos created #9334

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/client/mutations/CreateReflectionMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import clientTempId from '../utils/relay/clientTempId'
import createProxyRecord from '../utils/relay/createProxyRecord'
import {CreateReflectionMutation as TCreateReflectionMutation} from '../__generated__/CreateReflectionMutation.graphql'
import handleAddReflectionGroups from './handlers/handleAddReflectionGroups'
import SendClientSideEvent from '../utils/SendClientSideEvent'

graphql`
fragment CreateReflectionMutation_meeting on CreateReflectionPayload {
reflectionId
reflectionGroup {
meetingId
sortOrder
Expand All @@ -32,6 +34,12 @@ graphql`
id
isNavigableByFacilitator
}
draftKudoses {
receiverUser {
preferredName
}
emojiUnicode
}
}
`

Expand All @@ -58,7 +66,30 @@ const CreateReflectionMutation: StandardMutation<TCreateReflectionMutation> = (
return commitMutation<TCreateReflectionMutation>(atmosphere, {
mutation,
variables,
onCompleted,
onCompleted: (res, errors) => {
const draftKudoses = res.createReflection?.draftKudoses
if (draftKudoses && draftKudoses.length) {
const preferredNames = draftKudoses
.map((kudos) => kudos.receiverUser.preferredName)
.join(', ')
atmosphere.eventEmitter.emit('addSnackbar', {
key: `youGaveKudos:${res.createReflection.reflectionId}`,
message: `${preferredNames} will receive kudos at the end ot the meeting ${draftKudoses[0]?.emojiUnicode}`,
autoDismiss: 5,
onShow: () => {
SendClientSideEvent(atmosphere, 'Snackbar Viewed', {
snackbarType: 'kudosSent'
})
},
onManualDismiss: () => {
SendClientSideEvent(atmosphere, 'Snackbar Clicked', {
snackbarType: 'kudosSent'
})
}
})
}
onCompleted(res, errors)
},
onError,
updater: (store) => {
const payload = store.getRootField('createReflection')
Expand Down
36 changes: 35 additions & 1 deletion packages/server/graphql/mutations/createReflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import getReflectionEntities from './helpers/getReflectionEntities'
import getReflectionSentimentScore from './helpers/getReflectionSentimentScore'
import {analytics} from '../../utils/analytics/analytics'
import {getFeatureTier} from '../types/helpers/getFeatureTier'
import {RawDraftContentState} from 'draft-js'

export default {
type: CreateReflectionPayload,
Expand Down Expand Up @@ -66,6 +67,38 @@ export default {

// RESOLUTION
const plaintextContent = extractTextFromDraftString(normalizedContent)
const contentJson = JSON.parse(normalizedContent) as RawDraftContentState
const draftKudoses: {
id: string
receiverUserId: string
emoji: string
emojiUnicode: string
}[] = []

const {giveKudosWithEmoji, kudosEmojiUnicode, kudosEmoji} = team
if (
giveKudosWithEmoji &&
kudosEmojiUnicode &&
plaintextContent.includes(kudosEmojiUnicode) &&
contentJson.entityMap
) {
const mentions = Object.values(contentJson.entityMap).filter(
(entity) => entity.type === 'MENTION'
)
const userIds = [...new Set(mentions.map((mention) => mention.data.userId))].filter(
(userId) => userId !== viewerId
)

userIds.forEach((userId) => {
draftKudoses.push({
id: 'DRAFT_KUDOS_' + generateUID(),
receiverUserId: userId,
emoji: kudosEmoji,
emojiUnicode: kudosEmojiUnicode
})
})
}

const [entities, sentimentScore] = await Promise.all([
getReflectionEntities(plaintextContent),
getFeatureTier(team) !== 'starter'
Expand Down Expand Up @@ -122,7 +155,8 @@ export default {
meetingId,
reflectionId: reflection.id,
reflectionGroupId,
unlockedStageIds
unlockedStageIds,
draftKudoses
}
publish(SubscriptionChannel.MEETING, meetingId, 'CreateReflectionPayload', data, subOptions)
return data
Expand Down
5 changes: 5 additions & 0 deletions packages/server/graphql/public/typeDefs/_legacy.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6779,6 +6779,11 @@ type CreateReflectionPayload {
The stages that were unlocked by navigating
"""
unlockedStages: [NewMeetingStage!]

"""
Kudoses that might be sent by the end of the retro
"""
draftKudoses: [Kudos!]
}

input CreateReflectionInput {
Expand Down
Loading