-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kudos): display notification when kudos received (#9199)
* chore(kudos): add kudos team settings * store emoji id * chore(kudos): add kudos record when adding emoji reaction * Fix snackbar * quick fix for types * Dynamic emoji * del console log * feat(kudos): display notification when kudos received * Remove comment * Update notification text * Remove unused kudos field * expose senderUser * Fix reactable type * Fix table name * remove unused fields * Don't check feature flag * Fix analytics * Add snackbar events * fix typescript * Fix type * Fix type * add notification status analytics * Fix type * fix type * Fix table name caused by wrong merge * add snackbar clicked event to kudosReceived snackbar
- Loading branch information
1 parent
cecdbe4
commit 8f0e72f
Showing
12 changed files
with
228 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import graphql from 'babel-plugin-relay/macro' | ||
import {Link} from 'react-router-dom' | ||
import React, {useEffect} from 'react' | ||
import {useFragment} from 'react-relay' | ||
import {KudosReceivedNotification_notification$key} from '~/__generated__/KudosReceivedNotification_notification.graphql' | ||
import NotificationTemplate from './NotificationTemplate' | ||
import useAtmosphere from '../hooks/useAtmosphere' | ||
import SendClientSideEvent from '../utils/SendClientSideEvent' | ||
import getReactji from '~/utils/getReactji' | ||
|
||
interface Props { | ||
notification: KudosReceivedNotification_notification$key | ||
} | ||
|
||
const KudosReceivedNotification = (props: Props) => { | ||
const atmosphere = useAtmosphere() | ||
const {notification: notificationRef} = props | ||
const notification = useFragment( | ||
graphql` | ||
fragment KudosReceivedNotification_notification on NotifyKudosReceived { | ||
...NotificationTemplate_notification | ||
id | ||
type | ||
name | ||
picture | ||
meetingName | ||
meetingId | ||
emoji | ||
status | ||
} | ||
`, | ||
notificationRef | ||
) | ||
const {type, name, picture, meetingName, emoji, meetingId, status} = notification | ||
|
||
const {unicode} = getReactji(emoji) | ||
|
||
useEffect(() => { | ||
SendClientSideEvent(atmosphere, 'Notification Viewed', { | ||
notificationType: type, | ||
notificationStatus: status | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<NotificationTemplate | ||
message={ | ||
<> | ||
{unicode} {name} gave you kudos in{' '} | ||
<Link to={`/meet/${meetingId}`} className='font-semibold text-sky-500 underline'> | ||
{meetingName} | ||
</Link> | ||
</> | ||
} | ||
notification={notification} | ||
avatar={picture} | ||
/> | ||
) | ||
} | ||
|
||
export default KudosReceivedNotification |
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
49 changes: 49 additions & 0 deletions
49
packages/client/mutations/toasts/mapKudosReceivedToToast.ts
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,49 @@ | ||
import graphql from 'babel-plugin-relay/macro' | ||
import {Snack} from '../../components/Snackbar' | ||
import {mapKudosReceivedToToast_notification$data} from '../../__generated__/mapKudosReceivedToToast_notification.graphql' | ||
import makeNotificationToastKey from './makeNotificationToastKey' | ||
import {OnNextHistoryContext} from '../../types/relayMutations' | ||
import SendClientSideEvent from '../../utils/SendClientSideEvent' | ||
import getReactji from '~/utils/getReactji' | ||
|
||
graphql` | ||
fragment mapKudosReceivedToToast_notification on NotifyKudosReceived { | ||
id | ||
name | ||
meetingName | ||
meetingId | ||
emoji | ||
} | ||
` | ||
|
||
const mapKudosReceivedToToast = ( | ||
notification: mapKudosReceivedToToast_notification$data, | ||
{atmosphere, history}: OnNextHistoryContext | ||
): Snack => { | ||
const {id: notificationId, meetingName, name, emoji, meetingId} = notification | ||
const {unicode} = getReactji(emoji) | ||
return { | ||
autoDismiss: 5, | ||
showDismissButton: true, | ||
key: makeNotificationToastKey(notificationId), | ||
message: `${unicode} ${name} gave you kudos in`, | ||
action: { | ||
label: meetingName, | ||
callback: () => { | ||
history.push(`/meet/${meetingId}`) | ||
} | ||
}, | ||
onShow: () => { | ||
SendClientSideEvent(atmosphere, 'Snackbar Viewed', { | ||
snackbarType: 'kudosReceived' | ||
}) | ||
}, | ||
onManualDismiss: () => { | ||
SendClientSideEvent(atmosphere, 'Snackbar Clicked', { | ||
snackbarType: 'kudosReceived' | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export default mapKudosReceivedToToast |
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
32 changes: 32 additions & 0 deletions
32
packages/server/database/types/NotificationKudosReceived.ts
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,32 @@ | ||
import Notification from './Notification' | ||
|
||
interface Input { | ||
userId: string | ||
name: string | ||
picture: string | ||
senderUserId: string | ||
meetingName: string | ||
meetingId: string | ||
emoji: string | ||
} | ||
|
||
export default class NotificationKudosReceived extends Notification { | ||
readonly type = 'KUDOS_RECEIVED' | ||
name: string | ||
picture: string | ||
senderUserId: string | ||
meetingName: string | ||
meetingId: string | ||
emoji: string | ||
|
||
constructor(input: Input) { | ||
const {userId, name, picture, senderUserId, meetingName, meetingId, emoji} = input | ||
super({userId, type: 'KUDOS_RECEIVED'}) | ||
this.name = name | ||
this.picture = picture | ||
this.senderUserId = senderUserId | ||
this.meetingName = meetingName | ||
this.meetingId = meetingId | ||
this.emoji = emoji | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
packages/server/graphql/public/typeDefs/NotifyKudosReceived.graphql
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,47 @@ | ||
type NotifyKudosReceived implements Notification { | ||
""" | ||
A shortid for the notification | ||
""" | ||
id: ID! | ||
|
||
""" | ||
UNREAD if new, READ if viewer has seen it, CLICKED if viewed clicked it | ||
""" | ||
status: NotificationStatusEnum! | ||
|
||
""" | ||
The datetime to activate the notification & send it to the client | ||
""" | ||
createdAt: DateTime! | ||
type: NotificationEnum! | ||
|
||
""" | ||
The userId that should see this notification | ||
""" | ||
userId: ID! | ||
|
||
""" | ||
Sender name | ||
""" | ||
name: String! | ||
|
||
""" | ||
Sender picture | ||
""" | ||
picture: URL! | ||
|
||
""" | ||
Meeting name | ||
""" | ||
meetingName: String! | ||
|
||
""" | ||
Meeting id | ||
""" | ||
meetingId: String! | ||
|
||
""" | ||
Kudos emoji | ||
""" | ||
emoji: String! | ||
} |
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,7 @@ | ||
import {NotifyKudosReceivedResolvers} from '../resolverTypes' | ||
|
||
const NotifyKudosReceived: NotifyKudosReceivedResolvers = { | ||
__isTypeOf: ({type}) => type === 'KUDOS_RECEIVED' | ||
} | ||
|
||
export default NotifyKudosReceived |
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