-
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.
Merge pull request #10258 from hicommonwealth/salman/Issue#7989/inter…
…-community-navigation Inter-Community navigation
- Loading branch information
Showing
12 changed files
with
341 additions
and
117 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
32 changes: 32 additions & 0 deletions
32
packages/commonwealth/client/scripts/state/api/notifications/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,32 @@ | ||
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(() => { | ||
const fetchNotifications = async () => { | ||
try { | ||
await feedClient.fetch(); | ||
} catch (error) { | ||
console.error('Failed to fetch notifications:', error); | ||
} | ||
}; | ||
|
||
fetchNotifications(); // eslint-disable-line @typescript-eslint/no-floating-promises | ||
}, [feedClient]); | ||
|
||
return { items }; | ||
}; | ||
|
||
export default useFetchNotifications; |
57 changes: 57 additions & 0 deletions
57
...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,57 @@ | ||
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]); | ||
|
||
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
35 changes: 35 additions & 0 deletions
35
packages/commonwealth/client/scripts/views/components/sidebar/SidebarNotificationIcon.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,35 @@ | ||
@import '../../../styles/'; | ||
|
||
.SideBarNotificationIcon { | ||
.notification-icon-container { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: inline-block; | ||
} | ||
|
||
.notification-icon { | ||
font-size: 24px; | ||
color: $neutral-800; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.notification-badge { | ||
position: absolute; | ||
top: 22px; | ||
right: -5px; | ||
background-color: $rorange-400; | ||
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/commonwealth/client/scripts/views/components/sidebar/SidebarNotificationIcon.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,24 @@ | ||
import '@knocklabs/react-notification-feed/dist/index.css'; | ||
import React from 'react'; | ||
import './SidebarNotificationIcon.scss'; | ||
|
||
type SideBarNotificationIconProps = { | ||
unreadCount: number; | ||
}; | ||
|
||
export const SideBarNotificationIcon = ({ | ||
unreadCount, | ||
}: SideBarNotificationIconProps) => ( | ||
<div className="SideBarNotificationIcon"> | ||
<div className="notification-icon-container"> | ||
<div className="notification-icon"> | ||
<i className="bell-icon" /> | ||
{unreadCount > 0 && ( | ||
<span className="notification-badge"> | ||
{unreadCount > 99 ? '99+' : unreadCount} | ||
</span> | ||
)} | ||
</div> | ||
</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
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.