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

Add Notifications #161

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ env:
NEXT_PUBLIC_POSTHOG_HOST: "test"
BETTERSTACK_API_KEY: "test"
BETTERSTACK_URL: "test"
KNOCK_API_KEY: "test"
KNOCK_FEED_CHANNEL_ID: "test"

# what the action will do
jobs:
Expand Down
4 changes: 4 additions & 0 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL="/"
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL="/"
CLERK_WEBHOOK_SECRET="••••••"

# Knock
KNOCK_API_KEY="••••••"
KNOCK_FEED_CHANNEL_ID="••••••"

# @repo/lib
RESEND_AUDIENCE_ID="••••••"
RESEND_FROM="••••••"
Expand Down
27 changes: 15 additions & 12 deletions apps/app/app/(authenticated)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { auth, currentUser } from '@clerk/nextjs/server';
import { SidebarProvider } from '@repo/design-system/components/ui/sidebar';
import { NotificationsProvider } from '@repo/design-system/providers/notifications';
import { showBetaFeature } from '@repo/feature-flags';
import type { ReactElement, ReactNode } from 'react';
import { PostHogIdentifier } from './components/posthog-identifier';
Expand All @@ -17,21 +18,23 @@ const AppLayout = async ({
const betaFeature = await showBetaFeature();

if (!user) {
redirectToSignIn();
return redirectToSignIn();
}

return (
<SidebarProvider>
<GlobalSidebar>
{betaFeature && (
<div className="m-4 rounded-full bg-success p-1.5 text-center text-sm text-success-foreground">
Beta feature now available
</div>
)}
{children}
</GlobalSidebar>
<PostHogIdentifier />
</SidebarProvider>
<NotificationsProvider userId={user.id}>
<SidebarProvider>
<GlobalSidebar>
{betaFeature && (
<div className="m-4 rounded-full bg-success p-1.5 text-center text-sm text-success-foreground">
Beta feature now available
</div>
)}
{children}
</GlobalSidebar>
<PostHogIdentifier />
</SidebarProvider>
</NotificationsProvider>
);
};

Expand Down
9 changes: 9 additions & 0 deletions packages/design-system/lib/knock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Knock } from '@knocklabs/node';

const knockApiKey = process.env.KNOCK_API_KEY;

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

export const knock = new Knock(knockApiKey);
2 changes: 2 additions & 0 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"@clerk/nextjs": "^6.1.0",
"@clerk/themes": "^2.1.40",
"@hookform/resolvers": "^3.9.1",
"@knocklabs/node": "^0.6.13",
"@knocklabs/react": "^0.2.29",
"@logtail/next": "^0.1.5",
"@next/third-parties": "^15.0.2",
"@radix-ui/react-accordion": "^1.2.1",
Expand Down
24 changes: 24 additions & 0 deletions packages/design-system/providers/notifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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;

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

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

export const NotificationsProvider = ({
children,
userId,
}: { children: ReactNode; userId: string }) => (
<KnockProvider apiKey={knockApiKey} userId={userId}>
<KnockFeedProvider feedId={knockFeedChannelId}>
{children}
</KnockFeedProvider>
</KnockProvider>
);
Loading
Loading