Skip to content

Commit

Permalink
Extract notifications into new package
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbleasel committed Jan 6, 2025
1 parent 196fbe6 commit 7fadfa6
Show file tree
Hide file tree
Showing 10 changed files with 748 additions and 48 deletions.
2 changes: 0 additions & 2 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ NEXT_PUBLIC_POSTHOG_HOST=""
NEXT_PUBLIC_APP_URL="http://localhost:3000"
NEXT_PUBLIC_WEB_URL="http://localhost:3001"
NEXT_PUBLIC_DOCS_URL="http://localhost:3004"
NEXT_PUBLIC_KNOCK_FEED_CHANNEL_ID=""
NEXT_PUBLIC_KNOCK_API_KEY=""
30 changes: 0 additions & 30 deletions packages/design-system/components/knock-notification-feed.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions packages/design-system/lib/knock.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
},
"dependencies": {
"@hookform/resolvers": "^3.9.1",
"@knocklabs/node": "^0.6.13",
"@knocklabs/react": "^0.2.29",
"@radix-ui/react-accordion": "^1.2.2",
"@radix-ui/react-alert-dialog": "^1.1.4",
"@radix-ui/react-aspect-ratio": "^1.1.1",
Expand Down
29 changes: 29 additions & 0 deletions packages/notifications/components/feed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import {
NotificationFeedPopover,
NotificationIconButton,
} from '@knocklabs/react';
import { useRef, useState } from '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={() => setIsVisible(!isVisible)}
/>
<NotificationFeedPopover
buttonRef={notifButtonRef}
isVisible={isVisible}
onClose={() => setIsVisible(false)}
/>
</>
);
};
6 changes: 6 additions & 0 deletions packages/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Knock } from '@knocklabs/node';
import { keys } from './keys';

const key = keys().KNOCK_SECRET_API_KEY;

export const notifications = new Knock(key);
16 changes: 16 additions & 0 deletions packages/notifications/keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const keys = () =>
createEnv({
server: {
KNOCK_API_KEY: z.string().min(1).optional(),
KNOCK_FEED_CHANNEL_ID: z.string().min(1).optional(),
KNOCK_SECRET_API_KEY: z.string().min(1).optional(),
},
runtimeEnv: {
KNOCK_API_KEY: process.env.KNOCK_API_KEY,
KNOCK_FEED_CHANNEL_ID: process.env.KNOCK_FEED_CHANNEL_ID,
KNOCK_SECRET_API_KEY: process.env.KNOCK_SECRET_API_KEY,
},
});
23 changes: 23 additions & 0 deletions packages/notifications/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@repo/notifications",
"version": "0.0.0",
"private": true,
"scripts": {
"clean": "git clean -xdf .cache .turbo dist node_modules",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@knocklabs/node": "^0.6.13",
"@knocklabs/react": "^0.2.29",
"@t3-oss/env-nextjs": "^0.11.1",
"react": "^19.0.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@repo/typescript-config": "workspace:*",
"typescript": "^5.7.2",
"@types/node": "22.10.5",
"@types/react": "19.0.2",
"@types/react-dom": "^19.0.2"
}
}
8 changes: 8 additions & 0 deletions packages/notifications/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"baseUrl": "."
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 7fadfa6

Please sign in to comment.