Skip to content

Commit 8da0c33

Browse files
committed
Add toast to website
1 parent d30313a commit 8da0c33

6 files changed

Lines changed: 83 additions & 3 deletions

File tree

apps/website/app/providers.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import posthog from "posthog-js";
44
import { PostHogProvider as PHProvider } from "posthog-js/react";
5+
import { Toaster } from "@repo/ui/components/ui/sonner";
56
import { useEffect } from "react";
67
import PostHogPageView from "./PostHogPageView";
78

@@ -12,7 +13,11 @@ if (
1213
throw new Error("PostHog environment variables are not set");
1314
}
1415

15-
export function PostHogProvider({ children }: { children: React.ReactNode }) {
16+
export const PostHogProvider = ({
17+
children,
18+
}: {
19+
children: React.ReactNode;
20+
}) => {
1621
useEffect(() => {
1722
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
1823
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST!,
@@ -24,6 +29,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
2429
<PHProvider client={posthog}>
2530
<PostHogPageView />
2631
{children}
32+
<Toaster />
2733
</PHProvider>
2834
);
29-
}
35+
};

apps/website/app/utils/internalError.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useCallback } from "react";
44
import type { Properties } from "posthog-js";
55
import { usePostHog } from "posthog-js/react";
6+
import { toast } from "sonner";
67

78
const NON_WORD = /\W+/g;
89
export const useInternalError = () => {
@@ -11,11 +12,13 @@ export const useInternalError = () => {
1112
({
1213
error,
1314
type,
15+
userMessage,
1416
context,
1517
forceSendInDev = false,
1618
}: {
1719
error: unknown;
1820
type?: string;
21+
userMessage?: string;
1922
context?: Properties;
2023
forceSendInDev?: boolean;
2124
}): void => {
@@ -41,6 +44,9 @@ export const useInternalError = () => {
4144
}
4245
posthog.captureException(error, { ...context, type: slugType });
4346
}
47+
if (userMessage) {
48+
toast(userMessage, { duration: 5000 });
49+
}
4450
},
4551
[posthog],
4652
);

apps/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"react": "catalog:",
3131
"react-dom": "catalog:",
3232
"resend": "^4.0.1",
33+
"sonner": "^2.0.7",
3334
"zod": "^3.24.1"
3435
},
3536
"devDependencies": {

packages/ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
"class-variance-authority": "^0.7.1",
4040
"clsx": "^2.1.1",
4141
"lucide-react": "^0.468.0",
42+
"next-themes": "^0.4.6",
4243
"react": "^19",
4344
"react-dom": "^19",
4445
"shadcn": "2.10.0",
46+
"sonner": "^2.0.7",
4547
"tailwind-merge": "^3.3.1",
4648
"tailwindcss": "^3.1.0",
4749
"tailwindcss-animate": "^1.0.7",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use client";
2+
3+
import {
4+
CircleCheck,
5+
Info,
6+
LoaderCircle,
7+
OctagonX,
8+
TriangleAlert,
9+
} from "lucide-react";
10+
import { useTheme } from "next-themes";
11+
import { Toaster as Sonner } from "sonner";
12+
13+
type ToasterProps = React.ComponentProps<typeof Sonner>;
14+
15+
const Toaster = ({ ...props }: ToasterProps) => {
16+
const { theme = "system" } = useTheme();
17+
18+
return (
19+
<Sonner
20+
theme={theme as ToasterProps["theme"]}
21+
className="toaster group"
22+
icons={{
23+
success: <CircleCheck className="h-4 w-4" />,
24+
info: <Info className="h-4 w-4" />,
25+
warning: <TriangleAlert className="h-4 w-4" />,
26+
error: <OctagonX className="h-4 w-4" />,
27+
loading: <LoaderCircle className="h-4 w-4 animate-spin" />,
28+
}}
29+
toastOptions={{
30+
classNames: {
31+
toast:
32+
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
33+
description: "group-[.toast]:text-muted-foreground",
34+
actionButton:
35+
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
36+
cancelButton:
37+
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
38+
},
39+
}}
40+
{...props}
41+
/>
42+
);
43+
};
44+
45+
export { Toaster };

pnpm-lock.yaml

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)