-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
099bd31
commit 8e24534
Showing
11 changed files
with
306 additions
and
240 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
24 changes: 24 additions & 0 deletions
24
packages/commonwealth/client/scripts/hooks/useFetchNotifications.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,24 @@ | ||
import { | ||
useKnockClient, | ||
useNotifications, | ||
useNotificationStore, | ||
} from '@knocklabs/react'; | ||
import { useEffect } from 'react'; | ||
|
||
const KNOCK_IN_APP_FEED_ID = | ||
process.env.KNOCK_IN_APP_FEED_ID || 'fc6e68e5-b7b9-49c1-8fab-6dd7e3510ffb'; | ||
|
||
const useFetchNotifications = () => { | ||
const knockClient = useKnockClient(); | ||
const feedClient = useNotifications(knockClient, KNOCK_IN_APP_FEED_ID); | ||
|
||
const { items } = useNotificationStore(feedClient); | ||
|
||
useEffect(() => { | ||
feedClient.fetch(); | ||
}, [feedClient]); | ||
|
||
return { items }; | ||
}; | ||
|
||
export default useFetchNotifications; |
59 changes: 59 additions & 0 deletions
59
...ages/commonwealth/client/scripts/views/components/KnockNotifications/KnockFeedWrapper.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,59 @@ | ||
import Knock from '@knocklabs/client'; | ||
import { KnockFeedProvider, KnockProvider } from '@knocklabs/react'; | ||
import React, { ReactNode, useEffect } from 'react'; | ||
import useUserStore from 'state/ui/user'; | ||
|
||
const KNOCK_PUBLIC_API_KEY = | ||
process.env.KNOCK_PUBLIC_API_KEY || | ||
'pk_test_Hd4ZpzlVcz9bqepJQoo9BvZHokgEqvj4T79fPdKqpYM'; | ||
|
||
const KNOCK_IN_APP_FEED_ID = | ||
process.env.KNOCK_IN_APP_FEED_ID || 'fc6e68e5-b7b9-49c1-8fab-6dd7e3510ffb'; | ||
|
||
const knock = new Knock(KNOCK_PUBLIC_API_KEY); | ||
|
||
const getBrowserTimezone = (): string => { | ||
return Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
}; | ||
|
||
interface KnockFeedWrapperProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const KnockFeedWrapper = ({ children }: KnockFeedWrapperProps) => { | ||
const user = useUserStore(); | ||
|
||
useEffect(() => { | ||
if (!user.id || !user.isLoggedIn) return; | ||
if (!user.knockJWT) { | ||
console.warn('user knockJWT not set! Will not attempt to identify.'); | ||
return; | ||
} | ||
|
||
const timezone = getBrowserTimezone(); | ||
async function doAsync() { | ||
knock.authenticate(`${user.id}`, user.knockJWT); | ||
await knock.user.identify({ | ||
id: user.id, | ||
email: user.email, | ||
timezone, | ||
}); | ||
} | ||
|
||
doAsync().catch(console.error); | ||
}, [user.email, user.id, user.isLoggedIn, user.knockJWT]); | ||
|
||
if (!user.id || !user.isLoggedIn || !user.knockJWT) return null; | ||
|
||
return ( | ||
<KnockProvider | ||
apiKey={KNOCK_PUBLIC_API_KEY} | ||
userId={`${user.id}`} | ||
userToken={user.knockJWT} | ||
> | ||
<KnockFeedProvider feedId={KNOCK_IN_APP_FEED_ID} colorMode="light"> | ||
{children} | ||
</KnockFeedProvider> | ||
</KnockProvider> | ||
); | ||
}; |
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
31 changes: 31 additions & 0 deletions
31
packages/commonwealth/client/scripts/views/components/sidebar/sidebar_notification_icon.scss
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,31 @@ | ||
.notification-icon-container { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: inline-block; | ||
} | ||
|
||
.notification-icon { | ||
font-size: 24px; | ||
color: #333; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.notification-badge { | ||
position: absolute; | ||
top: 22px; | ||
right: -5px; | ||
background-color: red; | ||
color: white; | ||
font-size: 12px; | ||
font-weight: bold; | ||
padding: 2px 6px; | ||
border-radius: 12px; | ||
line-height: 1; | ||
border: 2px solid white; | ||
} | ||
|
||
.hidden-feed { | ||
display: none; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/commonwealth/client/scripts/views/components/sidebar/sidebar_notification_icon.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 '@knocklabs/react-notification-feed/dist/index.css'; | ||
import React from 'react'; | ||
import './sidebar_notification_icon.scss'; | ||
|
||
type SideBarNotificationIconProps = { | ||
unreadCount: number; | ||
}; | ||
|
||
export const SideBarNotificationIcon = ({ | ||
unreadCount, | ||
}: SideBarNotificationIconProps) => ( | ||
<div className="notification-icon-container"> | ||
<div className="notification-icon" style={{ cursor: 'pointer' }}> | ||
<i className="bell-icon" /> | ||
{unreadCount > 0 && ( | ||
<span className="notification-badge"> | ||
{unreadCount > 99 ? '99+' : unreadCount} | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
); |
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 |
---|---|---|
|
@@ -60,5 +60,9 @@ | |
&::-webkit-scrollbar { | ||
width: 4px; | ||
} | ||
|
||
.community-avatar-container { | ||
position: relative; | ||
} | ||
} | ||
} |
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.