Skip to content

Commit

Permalink
Collab on Notifications (#388)
Browse files Browse the repository at this point in the history
* update env vars

* update notif provider

* add secret key for server sdk

* create feed component

* make provider client

---------

Co-authored-by: Jeff Everhart <jeffeverhart383@gmail.com>
  • Loading branch information
haydenbleasel and JEverhart383 authored Jan 6, 2025
1 parent 521a948 commit a7ef7f6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
5 changes: 3 additions & 2 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ FLAGS_SECRET=""
ARCJET_KEY=""
SVIX_TOKEN=""
LIVEBLOCKS_SECRET=""
KNOCK_API_KEY=""
KNOCK_FEED_CHANNEL_ID=""
KNOCK_SECRET_API_KEY=""

# Client
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=""
Expand All @@ -29,3 +28,5 @@ NEXT_PUBLIC_APP_URL="http://localhost:3000"
NEXT_PUBLIC_WEB_URL="http://localhost:3001"
NEXT_PUBLIC_DOCS_URL="http://localhost:3004"
NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL="http://localhost:3000"
NEXT_PUBLIC_KNOCK_FEED_CHANNEL_ID=""
NEXT_PUBLIC_KNOCK_API_KEY=""
30 changes: 30 additions & 0 deletions packages/design-system/components/knock-notification-feed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import { useState, useRef } from "react";
import {
NotificationIconButton,
NotificationFeedPopover,
} from "@knocklabs/react";

// Required CSS import, unless you're overriding the styling
import "@knocklabs/react/dist/index.css";

export const KnockNotificationFeed = () => {
const [isVisible, setIsVisible] = useState(false);
const notifButtonRef = useRef(null);

return (

<>
<NotificationIconButton
ref={notifButtonRef}
onClick={(e) => setIsVisible(!isVisible)}
/>
<NotificationFeedPopover
buttonRef={notifButtonRef}
isVisible={isVisible}
onClose={() => setIsVisible(false)}
/>
</>
);
};
4 changes: 2 additions & 2 deletions packages/design-system/lib/knock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Knock } from '@knocklabs/node';

const knockApiKey = process.env.KNOCK_API_KEY;
const knockApiKey = process.env.KNOCK_SECRET_API_KEY;

if (!knockApiKey) {
throw new Error('KNOCK_API_KEY is not set');
throw new Error('KNOCK_SECRET_API_KEY is not set');
}

export const knock = new Knock(knockApiKey);
10 changes: 6 additions & 4 deletions packages/design-system/providers/notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use client';

import { KnockFeedProvider, KnockProvider } from '@knocklabs/react';
import type { ReactNode } from 'react';

const knockApiKey = process.env.KNOCK_API_KEY;
const knockFeedChannelId = process.env.KNOCK_FEED_CHANNEL_ID;
const knockApiKey = process.env.NEXT_PUBLIC_KNOCK_API_KEY;
const knockFeedChannelId = process.env.NEXT_PUBLIC_KNOCK_FEED_CHANNEL_ID;

if (!knockApiKey) {
throw new Error('KNOCK_API_KEY is not set');
throw new Error('NEXT_PUBLIC_KNOCK_API_KEY is not set');
}

if (!knockFeedChannelId) {
throw new Error('KNOCK_FEED_CHANNEL_ID is not set');
throw new Error('NEXT_PUBLIC_KNOCK_FEED_CHANNEL_ID is not set');
}

export const NotificationsProvider = ({
Expand Down

0 comments on commit a7ef7f6

Please sign in to comment.