Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: sonner toast (#555)
Maximilian Kaske6e6cce2b1c03
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 1d9186388..fdeef5ae7 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -62,7 +62,7 @@"react-day-picker": "8.8.2","react-dom": "18.2.0","react-hook-form": "7.47.0",- "react-tweet": "^3.1.1",+ "react-tweet": "3.1.1","reading-time": "1.5.0","rehype-pretty-code": "0.10.0","rehype-react": "7.2.0",@@ -70,6 +70,7 @@"remark-rehype": "10.1.0","resend": "1.1.0","shiki": "0.14.4",+ "sonner": "1.3.1","stripe": "13.8.0","superjson": "1.13.3","svix": "1.12.0",diff --git a/apps/web/src/app/_components/hero-form.tsx b/apps/web/src/app/_components/hero-form.tsxindex 49760f19f..d119ee83b 100644--- a/apps/web/src/app/_components/hero-form.tsx+++ b/apps/web/src/app/_components/hero-form.tsx@@ -1,7 +1,8 @@"use client";-import { Input, toast } from "@openstatus/ui";+import { Input } from "@openstatus/ui";+import { toast } from "@/lib/toast";import { addToWaitlist, sendWaitingListEmail } from "../action";import { SubmitButton } from "./submit-button";@@ -12,17 +13,15 @@ export const HeroForm = () => {try {const number = await addToWaitlist(data);const formattedNumber = Intl.NumberFormat().format(Number(number));- toast({- description: `Thank you, you're number ${formattedNumber} on the list.`,+ toast.message("Thank you", {+ description: `You're number ${formattedNumber} on the list.`,});const email = data.get("email");if (email) {sendWaitingListEmail(String(email));}} catch (e) {- toast({- description: "Something went wrong",- });+ toast.error("Something went wrong");}}}className="flex gap-1.5"diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/pause-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/pause-button.tsxindex fa5eff034..92db95519 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/pause-button.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/pause-button.tsx@@ -8,13 +8,12 @@ import type { Monitor } from "@openstatus/db/src/schema";import { Button } from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";export function PauseButton({ monitor }: { monitor: Monitor }) {const [isPending, startTransition] = useTransition();const router = useRouter();- const { toast } = useToastAction();async function toggle() {startTransition(async () => {@@ -23,10 +22,10 @@ export function PauseButton({ monitor }: { monitor: Monitor }) {...monitor,active: !monitor.active,});- toast("success");+ toastAction("success");router.refresh();} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsxindex fe9ae8dc5..7cccf831e 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsx@@ -14,7 +14,7 @@ import {} from "@openstatus/ui";import { Icons } from "@/components/icons";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { copyToClipboard } from "@/lib/utils";import { create } from "./actions";import { SubmitButton } from "./submit-button";@@ -23,7 +23,6 @@ export function CreateForm({ ownerId }: { ownerId: number }) {const [rawKey, setRawKey] = React.useState<string | undefined>();const router = useRouter();const [hasCopied, setHasCopied] = React.useState(false);- const { toast } = useToastAction();React.useEffect(() => {if (hasCopied) {@@ -40,7 +39,7 @@ export function CreateForm({ ownerId }: { ownerId: number }) {setRawKey(res.result.key);}} catch {- toast("error");+ toastAction("error");}}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsxindex fee6f7f24..9c60a30fe 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsx@@ -17,14 +17,13 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { revoke } from "./actions";export function RevokeButton({ keyId }: { keyId: string }) {const [open, setOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();const router = useRouter();- const { toast } = useToastAction();async function onRevoke() {startTransition(async () => {@@ -32,9 +31,9 @@ export function RevokeButton({ keyId }: { keyId: string }) {await revoke(keyId);router.refresh();setOpen(false);- toast("deleted");+ toastAction("deleted");} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/change-plan-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/change-plan-button.tsxindex 295336141..cb7ca76f2 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/change-plan-button.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/change-plan-button.tsx@@ -15,10 +15,10 @@ import {DialogHeader,DialogTitle,DialogTrigger,- toast,} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";+import { toast } from "@/lib/toast";import { api } from "@/trpc/client";export function ChangePlanButton({ workspace }: { workspace: Workspace }) {@@ -32,10 +32,7 @@ export function ChangePlanButton({ workspace }: { workspace: Workspace }) {await api.workspace.changePlan.mutate({ plan });} catch (e) {if (e instanceof TRPCClientError) {- toast({- description: e.message,- variant: "destructive",- });+ toast.error(e.message);}} finally {setOpen(false);diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsxindex 31213779d..44c95de3b 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsx@@ -26,7 +26,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { wait } from "@/lib/utils";import { api } from "@/trpc/client";@@ -47,17 +47,16 @@ export function InviteButton({});const router = useRouter();const [isPending, startTransition] = useTransition();- const { toast } = useToastAction();async function onSubmit(data: Schema) {startTransition(async () => {try {wait(2000);api.invitation.create.mutate(data);- toast("saved");+ toastAction("saved");router.refresh();} catch {- toast("error");+ toastAction("error");} finally {setOpen(false);}diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsxindex fe5bacf1e..0ec6036a9 100644--- a/apps/web/src/app/layout.tsx+++ b/apps/web/src/app/layout.tsx@@ -43,7 +43,7 @@ export default function RootLayout({<body className={`${inter.className} ${calSans.variable}`}><ThemeProvider attribute="class" defaultTheme="light" enableSystem><Background>{children}</Background>- <Toaster />+ <Toaster richColors /><TailwindIndicator /></ThemeProvider></body>diff --git a/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx b/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsxindex 3733da314..9457c1608 100644--- a/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx+++ b/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx@@ -10,10 +10,10 @@ import {Popover,PopoverContent,PopoverTrigger,- useToast,} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";+import { toast } from "@/lib/toast";import { handleSubscribe } from "./actions";interface Props {@@ -21,8 +21,6 @@ interface Props {}export function SubscribeButton({ slug }: Props) {- const { toast } = useToast();-return (<Popover><PopoverTrigger asChild>@@ -46,15 +44,12 @@ export function SubscribeButton({ slug }: Props) {action={async (formData) => {const res = await handleSubscribe(formData);if (res?.error) {- toast({- title: "Something went wrong",+ toast.error("Something went wrong", {description: res.error,- variant: "destructive",});return;}- toast({- title: "Success",+ toast.message("Success", {description: "Please confirm your email.",});}}diff --git a/apps/web/src/components/data-table/incident/data-table-row-actions.tsx b/apps/web/src/components/data-table/incident/data-table-row-actions.tsxindex 7a5063096..db4908a1c 100644--- a/apps/web/src/components/data-table/incident/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/incident/data-table-row-actions.tsx@@ -15,7 +15,7 @@ import {DropdownMenuTrigger,} from "@openstatus/ui";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -27,7 +27,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const incident = selectIncidentSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [_isPending, startTransition] = React.useTransition();async function resolved() {@@ -35,10 +34,10 @@ export function DataTableRowActions<TData>({try {if (!incident.id) return;await api.incident.resolvedIncident.mutate({ id: incident.id });- toast("success");+ toastAction("success");router.refresh();} catch {- toast("error");+ toastAction("error");}});}@@ -54,10 +53,10 @@ export function DataTableRowActions<TData>({// });if (!incident.id) return;await api.incident.acknowledgeIncident.mutate({ id: incident.id });- toast("success");+ toastAction("success");router.refresh();} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/invitation/data-table-row-actions.tsx b/apps/web/src/components/data-table/invitation/data-table-row-actions.tsxindex 30add013d..3b337d7d4 100644--- a/apps/web/src/components/data-table/invitation/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/invitation/data-table-row-actions.tsx@@ -19,7 +19,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -31,7 +31,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const invitation = selectInvitationSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -40,11 +39,11 @@ export function DataTableRowActions<TData>({try {if (!invitation.id) return;await api.invitation.delete.mutate({ id: invitation.id });- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx b/apps/web/src/components/data-table/monitor/data-table-row-actions.tsxindex a3993b452..e8f7be172 100644--- a/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/monitor/data-table-row-actions.tsx@@ -28,7 +28,7 @@ import {import type { RegionChecker } from "@/app/play/checker/[id]/utils";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -42,7 +42,6 @@ export function DataTableRowActions<TData>({.object({ monitor: selectMonitorSchema }).parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -51,11 +50,11 @@ export function DataTableRowActions<TData>({try {if (!monitor.id) return;await api.monitor.delete.mutate({ id: monitor.id });- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}@@ -69,10 +68,10 @@ export function DataTableRowActions<TData>({...rest,active: !monitor.active,});- toast("success");+ toastAction("success");router.refresh();} catch {- toast("error");+ toastAction("error");}});}@@ -92,12 +91,12 @@ export function DataTableRowActions<TData>({const data = (await res.json()) as RegionChecker;if (data.status >= 200 && data.status < 300) {- toast("test-success");+ toastAction("test-success");} else {- toast("test-error");+ toastAction("test-error");}} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/notification/data-table-row-actions.tsx b/apps/web/src/components/data-table/notification/data-table-row-actions.tsxindex 2631fe59f..94bc1cc78 100644--- a/apps/web/src/components/data-table/notification/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/notification/data-table-row-actions.tsx@@ -25,7 +25,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -37,7 +37,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const notification = selectNotificationSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -48,11 +47,11 @@ export function DataTableRowActions<TData>({await api.notification.deleteNotification.mutate({id: notification.id,});- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/page-subscriber/data-table-row-actions.tsx b/apps/web/src/components/data-table/page-subscriber/data-table-row-actions.tsxindex 0a6a4e528..cba3d8b03 100644--- a/apps/web/src/components/data-table/page-subscriber/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/page-subscriber/data-table-row-actions.tsx@@ -24,7 +24,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -36,7 +36,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const subscriber = selectPageSubscriberSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -47,11 +46,11 @@ export function DataTableRowActions<TData>({await api.pageSubscriber.unsubscribeById.mutate({id: subscriber.id,});- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}@@ -63,10 +62,10 @@ export function DataTableRowActions<TData>({await api.pageSubscriber.acceptSubscriberById.mutate({id: subscriber.id,});- toast("success");+ toastAction("success");router.refresh();} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/status-page/data-table-row-actions.tsx b/apps/web/src/components/data-table/status-page/data-table-row-actions.tsxindex b6182945c..cb5dd76a8 100644--- a/apps/web/src/components/data-table/status-page/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/status-page/data-table-row-actions.tsx@@ -25,7 +25,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -37,7 +37,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const page = selectPageSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -46,11 +45,11 @@ export function DataTableRowActions<TData>({try {if (!page.id) return;await api.page.delete.mutate({ id: page.id });- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/status-report/data-table-row-actions.tsx b/apps/web/src/components/data-table/status-report/data-table-row-actions.tsxindex 2f8dba69c..ed8623dc7 100644--- a/apps/web/src/components/data-table/status-report/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/status-report/data-table-row-actions.tsx@@ -25,7 +25,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -37,7 +37,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const statusReport = selectStatusReportSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -48,11 +47,11 @@ export function DataTableRowActions<TData>({await api.statusReport.deleteStatusReport.mutate({id: statusReport.id,});- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/data-table/user/data-table-row-actions.tsx b/apps/web/src/components/data-table/user/data-table-row-actions.tsxindex 7abbd673a..40f3ef38f 100644--- a/apps/web/src/components/data-table/user/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/user/data-table-row-actions.tsx@@ -24,7 +24,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface DataTableRowActionsProps<TData> {@@ -36,7 +36,6 @@ export function DataTableRowActions<TData>({}: DataTableRowActionsProps<TData>) {const user = selectUserSchema.parse(row.original);const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -45,11 +44,11 @@ export function DataTableRowActions<TData>({try {if (!user.id) return;await api.workspace.removeWorkspaceUser.mutate({ id: user.id });- toast("removed");+ toastAction("removed");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/forms/custom-domain-form.tsx b/apps/web/src/components/forms/custom-domain-form.tsxindex 0d1c7b9e6..a4f6b4ada 100644--- a/apps/web/src/components/forms/custom-domain-form.tsx+++ b/apps/web/src/components/forms/custom-domain-form.tsx@@ -20,7 +20,7 @@ import {} from "@openstatus/ui";import { useDomainStatus } from "@/hooks/use-domain-status";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import DomainConfiguration from "../domains/domain-configuration";import DomainStatusIcon from "../domains/domain-status-icon";@@ -42,7 +42,6 @@ export function CustomDomainForm({ defaultValues }: { defaultValues: Schema }) {});const router = useRouter();const [isPending, startTransition] = useTransition();- const { toast } = useToastAction();const domainStatus = useDomainStatus(defaultValues?.customDomain);const { status } = domainStatus || {};@@ -76,10 +75,10 @@ export function CustomDomainForm({ defaultValues }: { defaultValues: Schema }) {domain: defaultValues.customDomain,});}- toast("saved");+ toastAction("saved");router.refresh();} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/forms/monitor-form.tsx b/apps/web/src/components/forms/monitor-form.tsxindex ce9c16ba7..972db44d2 100644--- a/apps/web/src/components/forms/monitor-form.tsx+++ b/apps/web/src/components/forms/monitor-form.tsx@@ -65,7 +65,8 @@ import { flyRegionsDict } from "@openstatus/utils";import type { RegionChecker } from "@/app/play/checker/[id]/utils";import { LoadingAnimation } from "@/components/loading-animation";import { FailedPingAlertConfirmation } from "@/components/modals/failed-ping-alert-confirmation";-import { useToastAction } from "@/hooks/use-toast-action";+import useUpdateSearchParams from "@/hooks/use-update-search-params";+import { toastAction } from "@/lib/toast";import { cn } from "@/lib/utils";import { api } from "@/trpc/client";import type { Writeable } from "@/types/utils";@@ -117,7 +118,6 @@ export function MonitorForm({const [isTestPending, startTestTransition] = React.useTransition();const [pingFailed, setPingFailed] = React.useState(false);const [openDialog, setOpenDialog] = React.useState(false);- const { toast } = useToastAction();const watchMethod = form.watch("method");const { fields, append, remove } = useFieldArray({@@ -136,9 +136,9 @@ export function MonitorForm({router.push(nextUrl);}router.refresh();- toast("saved");+ toastAction("saved");} catch (error) {- toast("error");+ toastAction("error");}};@@ -195,7 +195,7 @@ export function MonitorForm({}const { url } = form.getValues();if (!url) {- toast("test-warning-empty-url");+ toastAction("test-warning-empty-url");return;}@@ -203,12 +203,12 @@ export function MonitorForm({try {const data = await pingEndpoint();if (data.status >= 200 && data.status < 300) {- toast("test-success");+ toastAction("test-success");} else {- toast("test-error");+ toastAction("test-error");}} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/monitor/form.tsx b/apps/web/src/components/forms/monitor/form.tsxindex d27794392..d8a3821a9 100644--- a/apps/web/src/components/forms/monitor/form.tsx+++ b/apps/web/src/components/forms/monitor/form.tsx@@ -23,7 +23,7 @@ import {TabsTrigger,} from "@/components/dashboard/tabs";import { FailedPingAlertConfirmation } from "@/components/modals/failed-ping-alert-confirmation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import type { Writeable } from "@/types/utils";import { SaveButton } from "../shared/save-button";@@ -75,7 +75,6 @@ export function MonitorForm({const pathname = usePathname();const [isPending, startTransition] = React.useTransition();const [pingFailed, setPingFailed] = React.useState(false);- const { toast } = useToastAction();const handleDataUpdateOrInsertion = async (props: InsertMonitor) => {try {@@ -90,9 +89,9 @@ export function MonitorForm({// to reset the `isDirty` state of them form while keeping the values for optimistic UIform.reset(undefined, { keepValues: true });router.refresh();- toast("saved");+ toastAction("saved");} catch (error) {- toast("error");+ toastAction("error");}};@@ -107,7 +106,7 @@ export function MonitorForm({}await handleDataUpdateOrInsertion(props);} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/monitor/request-test-button.tsx b/apps/web/src/components/forms/monitor/request-test-button.tsxindex 554c61172..01aa0f36d 100644--- a/apps/web/src/components/forms/monitor/request-test-button.tsx+++ b/apps/web/src/components/forms/monitor/request-test-button.tsx@@ -26,7 +26,7 @@ import { RegionInfo } from "@/app/play/checker/[id]/_components/region-info";import { ResponseDetailTabs } from "@/app/play/checker/[id]/_components/response-detail-tabs";import type { RegionChecker } from "@/app/play/checker/[id]/utils";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";interface Props {form: UseFormReturn<InsertMonitor>;@@ -36,7 +36,6 @@ interface Props {export function RequestTestButton({ form, pingEndpoint }: Props) {const [check, setCheck] = React.useState<RegionChecker | undefined>();const [value, setValue] = React.useState<MonitorFlyRegion>(flyRegions[0]);- const { toast } = useToastAction();const [isPending, startTransition] = React.useTransition();const onClick = () => {@@ -45,7 +44,7 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {const { url } = form.getValues();if (!url) {- toast("test-warning-empty-url");+ toastAction("test-warning-empty-url");return;}@@ -55,12 +54,12 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {setCheck(data);const isOk = data.status >= 200 && data.status < 300;if (isOk) {- toast("test-success");+ toastAction("test-success");} else {- toast("test-error");+ toastAction("test-error");}} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/monitor/section-danger.tsx b/apps/web/src/components/forms/monitor/section-danger.tsxindex 8a21f53e9..3cb31af47 100644--- a/apps/web/src/components/forms/monitor/section-danger.tsx+++ b/apps/web/src/components/forms/monitor/section-danger.tsx@@ -17,7 +17,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface Props {@@ -26,7 +26,6 @@ interface Props {export function SectionDanger({ monitorId }: Props) {const router = useRouter();- const { toast } = useToastAction();const [open, setOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -34,11 +33,11 @@ export function SectionDanger({ monitorId }: Props) {startTransition(async () => {try {await api.monitor.delete.mutate({ id: monitorId });- toast("deleted");+ toastAction("deleted");router.refresh();setOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/forms/notification-form.tsx b/apps/web/src/components/forms/notification-form.tsxindex 003f851f3..2ca87c6c9 100644--- a/apps/web/src/components/forms/notification-form.tsx+++ b/apps/web/src/components/forms/notification-form.tsx@@ -35,7 +35,7 @@ import {} from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { toCapitalize } from "@/lib/utils";import { api } from "@/trpc/client";@@ -112,7 +112,6 @@ export function NotificationForm({}: Props) {const [isPending, startTransition] = useTransition();const [isTestPending, startTestTransition] = useTransition();- const { toast } = useToastAction();const router = useRouter();const form = useForm<InsertNotification>({resolver: zodResolver(insertNotificationSchema),@@ -153,9 +152,9 @@ export function NotificationForm({router.push(nextUrl);}router.refresh();- toast("saved");+ toastAction("saved");} catch {- toast("error");+ toastAction("error");} finally {onExternalSubmit?.();}@@ -168,9 +167,9 @@ export function NotificationForm({startTestTransition(async () => {const isSuccessfull = await providerMetaData.sendTest?.(webhookUrl);if (isSuccessfull) {- toast("test-success");+ toastAction("test-success");} else {- toast("test-error");+ toastAction("test-error");}});}diff --git a/apps/web/src/components/forms/notification/form.tsx b/apps/web/src/components/forms/notification/form.tsxindex cbd566826..affe6dde4 100644--- a/apps/web/src/components/forms/notification/form.tsx+++ b/apps/web/src/components/forms/notification/form.tsx@@ -13,7 +13,7 @@ import { insertNotificationSchema } from "@openstatus/db/src/schema";import { Button, Form } from "@openstatus/ui";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import { SaveButton } from "../shared/save-button";import {@@ -38,7 +38,6 @@ export function NotificationForm({}: Props) {const [isPending, startTransition] = useTransition();const [isTestPending, startTestTransition] = useTransition();- const { toast } = useToastAction();const router = useRouter();const form = useForm<InsertNotification>({resolver: zodResolver(insertNotificationSchema),@@ -79,9 +78,9 @@ export function NotificationForm({router.push(nextUrl);}router.refresh();- toast("saved");+ toastAction("saved");} catch {- toast("error");+ toastAction("error");} finally {onExternalSubmit?.();}@@ -94,9 +93,9 @@ export function NotificationForm({startTestTransition(async () => {const isSuccessfull = await providerMetaData.sendTest?.(webhookUrl);if (isSuccessfull) {- toast("test-success");+ toastAction("test-success");} else {- toast("test-error");+ toastAction("test-error");}});}diff --git a/apps/web/src/components/forms/status-page-form.tsx b/apps/web/src/components/forms/status-page-form.tsxindex 80a283038..627f36313 100644--- a/apps/web/src/components/forms/status-page-form.tsx+++ b/apps/web/src/components/forms/status-page-form.tsx@@ -26,12 +26,11 @@ import {FormMessage,Input,InputWithAddons,- useToast,} from "@openstatus/ui";import { useDebounce } from "@/hooks/use-debounce";-import { useToastAction } from "@/hooks/use-toast-action";import useUpdateSearchParams from "@/hooks/use-update-search-params";+import { toast, toastAction } from "@/lib/toast";import { slugify } from "@/lib/utils";import { api } from "@/trpc/client";import { LoadingAnimation } from "../loading-animation";@@ -77,8 +76,6 @@ export function StatusPageForm({const watchSlug = form.watch("slug");const watchTitle = form.watch("title");const debouncedSlug = useDebounce(watchSlug, 1000); // using debounce to not exhaust the server- const { toast } = useToastAction();- const { toast: defaultToast } = useToast();const updateSearchParams = useUpdateSearchParams();const checkUniqueSlug = useCallback(async () => {@@ -124,23 +121,21 @@ export function StatusPageForm({router.replace(`?${updateSearchParams({ id })}`); // to stay on same page and enable 'Advanced' tab}- defaultToast({- title: "Saved successfully.",+ toast.success("Saved successfully.", {description: "Your status page is ready to go.",- action: (- <Button variant="outline">- <a href={`https://${props.slug}.openstatus.dev`} target="_blank">- Visit- </a>- </Button>- ),+ action: {+ label: "Visit",+ onClick: () =>+ window.open(`https://${props.slug}.openstatus.dev`, "_blank")+ ?.location,+ },});if (nextUrl) {router.push(nextUrl);}router.refresh();} catch {- toast("error");+ toastAction("error");}});};@@ -169,7 +164,7 @@ export function StatusPageForm({const isUnique = await checkUniqueSlug();if (!isUnique) {// the user will already have the "error" message - we include a toast as well- toast("unique-slug");+ toastAction("unique-slug");} else {if (onSubmit) {void form.handleSubmit(onSubmit)(e);diff --git a/apps/web/src/components/forms/status-page/form.tsx b/apps/web/src/components/forms/status-page/form.tsxindex 912f0dc19..3cfcb3537 100644--- a/apps/web/src/components/forms/status-page/form.tsx+++ b/apps/web/src/components/forms/status-page/form.tsx@@ -8,7 +8,7 @@ import { useForm } from "react-hook-form";import { insertPageSchema } from "@openstatus/db/src/schema";import type { InsertPage, Monitor } from "@openstatus/db/src/schema";-import { Badge, Button, Form, useToast } from "@openstatus/ui";+import { Badge, Form } from "@openstatus/ui";import {Tabs,@@ -17,8 +17,8 @@ import {TabsTrigger,} from "@/components/dashboard/tabs";import { useDebounce } from "@/hooks/use-debounce";-import { useToastAction } from "@/hooks/use-toast-action";import useUpdateSearchParams from "@/hooks/use-update-search-params";+import { toast, toastAction } from "@/lib/toast";import { slugify } from "@/lib/utils";import { api } from "@/trpc/client";import { SaveButton } from "../shared/save-button";@@ -69,8 +69,6 @@ export function StatusPageForm({const watchSlug = form.watch("slug");const watchTitle = form.watch("title");const debouncedSlug = useDebounce(watchSlug, 1000); // using debounce to not exhaust the server- const { toast } = useToastAction();- const { toast: defaultToast } = useToast();const updateSearchParams = useUpdateSearchParams();const checkUniqueSlug = useCallback(async () => {@@ -116,23 +114,21 @@ export function StatusPageForm({router.replace(`?${updateSearchParams({ id })}`); // to stay on same page and enable 'Advanced' tab}- defaultToast({- title: "Saved successfully.",+ toast.success("Saved successfully.", {description: "Your status page is ready to go.",- action: (- <Button variant="outline">- <a href={`https://${props.slug}.openstatus.dev`} target="_blank">- Visit- </a>- </Button>- ),+ action: {+ label: "Visit",+ onClick: () =>+ window.open(`https://${props.slug}.openstatus.dev`, "_blank")+ ?.location,+ },});if (nextUrl) {router.push(nextUrl);}router.refresh();} catch {- toast("error");+ toastAction("error");}});};@@ -153,7 +149,7 @@ export function StatusPageForm({const isUnique = await checkUniqueSlug();if (!isUnique) {// the user will already have the "error" message - we include a toast as well- toast("unique-slug");+ toastAction("unique-slug");} else {if (onSubmit) {void form.handleSubmit(onSubmit)(e);diff --git a/apps/web/src/components/forms/status-report-form.tsx b/apps/web/src/components/forms/status-report-form.tsxindex 698ceb229..8a588ea82 100644--- a/apps/web/src/components/forms/status-report-form.tsx+++ b/apps/web/src/components/forms/status-report-form.tsx@@ -44,7 +44,7 @@ import { Preview } from "@/components/content/preview";import { Icons } from "@/components/icons";import { LoadingAnimation } from "@/components/loading-animation";import { statusDict } from "@/data/incidents-dictionary";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { cn } from "@/lib/utils";import { api } from "@/trpc/client";@@ -81,7 +81,6 @@ export function StatusReportForm({});const router = useRouter();const [isPending, startTransition] = React.useTransition();- const { toast } = useToastAction();const onSubmit = ({ ...props }: InsertStatusReport) => {startTransition(async () => {@@ -111,9 +110,9 @@ export function StatusReportForm({router.push(nextUrl);}router.refresh();- toast("saved");+ toastAction("saved");} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/status-report-update-form.tsx b/apps/web/src/components/forms/status-report-update-form.tsxindex f91656ff8..75b87dd87 100644--- a/apps/web/src/components/forms/status-report-update-form.tsx+++ b/apps/web/src/components/forms/status-report-update-form.tsx@@ -34,7 +34,7 @@ import { Preview } from "@/components/content/preview";import { Icons } from "@/components/icons";import { LoadingAnimation } from "@/components/loading-animation";import { statusDict } from "@/data/incidents-dictionary";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";interface Props {@@ -60,7 +60,6 @@ export function StatusReportUpdateForm({});const router = useRouter();const [isPending, startTransition] = React.useTransition();- const { toast } = useToastAction();const handleSubmit = ({ ...props }: InsertStatusReportUpdate) => {startTransition(async () => {@@ -70,11 +69,11 @@ export function StatusReportUpdateForm({} else {await api.statusReport.createStatusReportUpdate.mutate({ ...props });}- toast("saved");+ toastAction("saved");onSubmit?.();router.refresh();} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/status-report-update/form.tsx b/apps/web/src/components/forms/status-report-update/form.tsxindex b28bb29d6..fd095160b 100644--- a/apps/web/src/components/forms/status-report-update/form.tsx+++ b/apps/web/src/components/forms/status-report-update/form.tsx@@ -16,7 +16,7 @@ import {TabsTrigger,} from "@/components/dashboard/tabs";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import { General } from "./general";import { SectionDate } from "./section-date";@@ -45,7 +45,6 @@ export function StatusReportUpdateForm({});const router = useRouter();const [isPending, startTransition] = React.useTransition();- const { toast } = useToastAction();const handleSubmit = ({ ...props }: InsertStatusReportUpdate) => {startTransition(async () => {@@ -55,11 +54,11 @@ export function StatusReportUpdateForm({} else {await api.statusReport.createStatusReportUpdate.mutate({ ...props });}- toast("saved");+ toastAction("saved");onSubmit?.();router.refresh();} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/status-report/form.tsx b/apps/web/src/components/forms/status-report/form.tsxindex 828b0be3d..b76c80e2c 100644--- a/apps/web/src/components/forms/status-report/form.tsx+++ b/apps/web/src/components/forms/status-report/form.tsx@@ -19,7 +19,7 @@ import {TabsList,TabsTrigger,} from "@/components/dashboard/tabs";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import { SaveButton } from "../shared/save-button";import { General } from "./general";@@ -62,7 +62,6 @@ export function StatusReportForm({const pathname = usePathname();const router = useRouter();const [isPending, startTransition] = React.useTransition();- const { toast } = useToastAction();const onSubmit = ({ ...props }: InsertStatusReport) => {startTransition(async () => {@@ -92,9 +91,9 @@ export function StatusReportForm({router.push(nextUrl);}router.refresh();- toast("saved");+ toastAction("saved");} catch {- toast("error");+ toastAction("error");}});};diff --git a/apps/web/src/components/forms/workspace-form.tsx b/apps/web/src/components/forms/workspace-form.tsxindex ea93661d4..61df99031 100644--- a/apps/web/src/components/forms/workspace-form.tsx+++ b/apps/web/src/components/forms/workspace-form.tsx@@ -18,7 +18,7 @@ import {Input,} from "@openstatus/ui";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";import { LoadingAnimation } from "../loading-animation";@@ -35,16 +35,15 @@ export function WorkspaceForm({ defaultValues }: { defaultValues: Schema }) {});const router = useRouter();const [isPending, startTransition] = useTransition();- const { toast } = useToastAction();async function onSubmit(data: Schema) {startTransition(async () => {try {await api.workspace.updateWorkspace.mutate(data);- toast("saved");+ toastAction("saved");router.refresh();} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/components/status-update/delete-status-update.tsx b/apps/web/src/components/status-update/delete-status-update.tsxindex 29ffa4ebb..815390e3f 100644--- a/apps/web/src/components/status-update/delete-status-update.tsx+++ b/apps/web/src/components/status-update/delete-status-update.tsx@@ -18,12 +18,11 @@ import {import { Icons } from "@/components/icons";import { LoadingAnimation } from "@/components/loading-animation";-import { useToastAction } from "@/hooks/use-toast-action";+import { toastAction } from "@/lib/toast";import { api } from "@/trpc/client";export function DeleteStatusReportUpdateButtonIcon({ id }: { id: number }) {const router = useRouter();- const { toast } = useToastAction();const [alertOpen, setAlertOpen] = React.useState(false);const [isPending, startTransition] = React.useTransition();@@ -31,11 +30,11 @@ export function DeleteStatusReportUpdateButtonIcon({ id }: { id: number }) {startTransition(async () => {try {await api.statusReport.deleteStatusReportUpdate.mutate({ id });- toast("deleted");+ toastAction("deleted");router.refresh();setAlertOpen(false);} catch {- toast("error");+ toastAction("error");}});}diff --git a/apps/web/src/hooks/use-toast-action.tsx b/apps/web/src/hooks/use-toast-action.tsxdeleted file mode 100644index b59bb514d..000000000--- a/apps/web/src/hooks/use-toast-action.tsx+++ /dev/null@@ -1,51 +0,0 @@-import { Button, useToast } from "@openstatus/ui";-import type { ToastType } from "@openstatus/ui";--const config = {- error: {- title: "Something went wrong",- description: "Please try again",- variant: "destructive",- action: (- <Button variant="outline" asChild className="text-foreground">- <a href="/discord" target="_blank" rel="noreferrer">- Discord- </a>- </Button>- ),- },- "unique-slug": {- title: "Slug is already taken",- description: "Please select another slug. Every slug is unique.",- variant: "warning",- },- success: { title: "Success" },- deleted: { title: "Deleted successfully" }, // TODO: we are not informing the user besides the visual changes when an entry has been deleted- removed: { title: "Removed successfully" },- saved: { title: "Saved successfully" },- "test-error": {- title: "Connection Failed",- // description: "Be sure to include the auth headers.",- variant: "destructive",- },- "test-warning-empty-url": {- title: "URL is Empty",- description: "Please enter a valid, non-empty URL",- variant: "warning",- },- "test-success": {- title: "Connection Established",- },-} as const satisfies Record<string, ToastType>;--type ToastAction = keyof typeof config;--export function useToastAction() {- const { toast: defaultToast } = useToast();-- function toast(action: ToastAction) {- return defaultToast(config[action]);- }-- return { toast };-}diff --git a/apps/web/src/lib/toast.tsx b/apps/web/src/lib/toast.tsxnew file mode 100644index 000000000..33ca9b18d--- /dev/null+++ b/apps/web/src/lib/toast.tsx@@ -0,0 +1,69 @@+import type { ExternalToast } from "sonner";+import { toast } from "sonner";++type ToastType =+ | "default"+ | "description"+ | "success"+ | "warning"+ | "info"+ | "error"+ | "promise";++const config = {+ error: {+ type: "error",+ title: "Something went wrong",+ description: "Please try again",+ action: {+ label: "Discord",+ onClick: () => window.open("/discord", "_blank")?.location,+ },+ },+ "unique-slug": {+ type: "warning",+ title: "Slug is already taken",+ description: "Please select another slug. Every slug is unique.",+ },+ success: { type: "success", title: "Success" },+ deleted: { type: "success", title: "Deleted successfully" }, // TODO: we are not informing the user besides the visual changes when an entry has been deleted+ removed: { type: "success", title: "Removed successfully" },+ saved: { type: "success", title: "Saved successfully" },+ "test-error": {+ type: "error",+ title: "Connection Failed",+ description: "Please enter a correct URL",+ },+ "test-warning-empty-url": {+ type: "warning",+ title: "URL is Empty",+ description: "Please enter a valid, non-empty URL",+ },+ "test-success": {+ type: "success",+ title: "Connection Established",+ },+} as const;++const _config: Record<+ string,+ Pick<ExternalToast, "action" | "description"> & {+ type: ToastType;+ title: string;+ }+> = config;++type ToastAction = keyof typeof config;++export function toastAction(action: ToastAction) {+ const { title, type, ...props } = _config[action];++ if (type === "default") return toast(title, props);+ if (type === "success") return toast.success(title, props);+ if (type === "error") return toast.error(title, props);+ if (type === "warning") return toast.warning(title, props);+ if (type === "description") return toast.message(title, props);+ if (type === "info") return toast.info(title, props);+}++export { toast };diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex ca02aed48..8e2fbf66d 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -37,7 +37,6 @@"@radix-ui/react-slot": "1.0.2","@radix-ui/react-switch": "1.0.3","@radix-ui/react-tabs": "1.0.4",- "@radix-ui/react-toast": "1.1.5","@radix-ui/react-toggle": "^1.0.3","@radix-ui/react-tooltip": "1.0.7","class-variance-authority": "0.7.0",@@ -51,5 +50,9 @@"react-hook-form": "7.47.0","tailwind-merge": "1.14.0","zod": "3.22.2"+ },+ "peerDependencies": {+ "next-themes": "0.2.1",+ "sonner": "1.3.1"}}diff --git a/packages/ui/src/components/sonner.tsx b/packages/ui/src/components/sonner.tsxnew file mode 100644index 000000000..549cf8413--- /dev/null+++ b/packages/ui/src/components/sonner.tsx@@ -0,0 +1,31 @@+"use client";++import { useTheme } from "next-themes";+import { Toaster as Sonner } from "sonner";++type ToasterProps = React.ComponentProps<typeof Sonner>;++const Toaster = ({ ...props }: ToasterProps) => {+ const { theme = "system" } = useTheme();++ return (+ <Sonner+ theme={theme as ToasterProps["theme"]}+ className="toaster group"+ toastOptions={{+ classNames: {+ toast:+ "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",+ description: "group-[.toast]:text-muted-foreground",+ actionButton:+ "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",+ cancelButton:+ "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",+ },+ }}+ {...props}+ />+ );+};++export { Toaster };diff --git a/packages/ui/src/components/toast.tsx b/packages/ui/src/components/toast.tsxdeleted file mode 100644index 566e1b0f0..000000000--- a/packages/ui/src/components/toast.tsx+++ /dev/null@@ -1,172 +0,0 @@-"use client";--import * as React from "react";-import { useMemo } from "react";-import * as ToastPrimitives from "@radix-ui/react-toast";-import { cva } from "class-variance-authority";-import type { VariantProps } from "class-variance-authority";-import { Check, ShieldAlert, X } from "lucide-react";--import { cn } from "../lib/utils";--const ToastProvider = ToastPrimitives.Provider;--const ToastViewport = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Viewport>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>->(({ className, ...props }, ref) => (- <ToastPrimitives.Viewport- ref={ref}- className={cn(- "fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",- className,- )}- {...props}- />-));-ToastViewport.displayName = ToastPrimitives.Viewport.displayName;--const toastVariants = cva(- "data-[swipe=move]:transition-none group relative pointer-events-auto flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full bg-background",- {- variants: {- variant: {- // REMINDER: same keys as toastIconVariant- default: "",- destructive: "",- warning: "",- },- },- defaultVariants: {- variant: "default",- },- },-);--const toastIconVariant = cva("", {- variants: {- variant: {- default: "bg-green-500",- destructive: "bg-destructive",- warning: "bg-amber-500",- },- },- defaultVariants: {- variant: "default",- },-});--const Toast = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Root>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &- VariantProps<typeof toastVariants>->(({ className, variant, ...props }, ref) => {- return (- <ToastPrimitives.Root- ref={ref}- className={cn(toastVariants({ variant }), className)}- {...props}- />- );-});-Toast.displayName = ToastPrimitives.Root.displayName;--const ToastIcon = ({ variant }: VariantProps<typeof toastIconVariant>) => {- const Icon = useMemo(() => {- switch (variant) {- case "destructive":- return X;-- case "warning":- return ShieldAlert;-- default:- return Check;- }- }, [variant]);-- return (- <div- className={cn(- "h-fit w-fit rounded-full p-2",- toastIconVariant({ variant }),- )}- >- <Icon className="text-background h-4 w-4" />- </div>- );-};--const ToastAction = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Action>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>->(({ className, ...props }, ref) => (- <ToastPrimitives.Action- ref={ref}- className={cn(- "ring-offset-background hover:bg-secondary focus:ring-ring group-[.destructive]:border-destructive/30 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",- className,- )}- {...props}- />-));-ToastAction.displayName = ToastPrimitives.Action.displayName;--const ToastClose = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Close>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>->(({ className, ...props }, ref) => (- <ToastPrimitives.Close- ref={ref}- className={cn(- "text-foreground/50 hover:text-foreground absolute right-2 top-2 rounded-md p-1 opacity-0 transition-opacity focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",- className,- )}- toast-close=""- {...props}- >- <X className="h-4 w-4" />- </ToastPrimitives.Close>-));-ToastClose.displayName = ToastPrimitives.Close.displayName;--const ToastTitle = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Title>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>->(({ className, ...props }, ref) => (- <ToastPrimitives.Title- ref={ref}- className={cn("text-sm font-semibold", className)}- {...props}- />-));-ToastTitle.displayName = ToastPrimitives.Title.displayName;--const ToastDescription = React.forwardRef<- React.ElementRef<typeof ToastPrimitives.Description>,- React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>->(({ className, ...props }, ref) => (- <ToastPrimitives.Description- ref={ref}- className={cn("text-sm opacity-90", className)}- {...props}- />-));-ToastDescription.displayName = ToastPrimitives.Description.displayName;--type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;--type ToastActionElement = React.ReactElement<typeof ToastAction>;--export {- type ToastProps,- type ToastActionElement,- ToastProvider,- ToastViewport,- Toast,- ToastTitle,- ToastDescription,- ToastClose,- ToastAction,- ToastIcon,-};diff --git a/packages/ui/src/components/toaster.tsx b/packages/ui/src/components/toaster.tsxdeleted file mode 100644index 11fd73899..000000000--- a/packages/ui/src/components/toaster.tsx+++ /dev/null@@ -1,39 +0,0 @@-"use client";--import {- Toast,- ToastClose,- ToastDescription,- ToastIcon,- ToastProvider,- ToastTitle,- ToastViewport,-} from "../components/toast";-import { useToast } from "../components/use-toast";--export function Toaster() {- const { toasts } = useToast();-- return (- <ToastProvider>- {toasts.map(function ({ id, title, description, action, ...props }) {- return (- <Toast key={id} {...props} duration={1000000}>- <div className="flex w-fit items-center gap-3">- <ToastIcon variant={props.variant} />- <div className="grid gap-1">- {title && <ToastTitle>{title}</ToastTitle>}- {description && (- <ToastDescription>{description}</ToastDescription>- )}- </div>- {action}- <ToastClose />- </div>- </Toast>- );- })}- <ToastViewport />- </ToastProvider>- );-}diff --git a/packages/ui/src/components/use-toast.ts b/packages/ui/src/components/use-toast.tsdeleted file mode 100644index 5515fce1f..000000000--- a/packages/ui/src/components/use-toast.ts+++ /dev/null@@ -1,192 +0,0 @@-"use client";--// Inspired by react-hot-toast library-import type { ReactNode } from "react";-import { useEffect, useState } from "react";--import type { ToastActionElement, ToastProps } from "../components/toast";--const TOAST_LIMIT = 1;-const TOAST_REMOVE_DELAY = 1000000;--type ToasterToast = ToastProps & {- id: string;- title?: ReactNode;- description?: ReactNode;- action?: ToastActionElement;-};--const actionTypes = {- ADD_TOAST: "ADD_TOAST",- UPDATE_TOAST: "UPDATE_TOAST",- DISMISS_TOAST: "DISMISS_TOAST",- REMOVE_TOAST: "REMOVE_TOAST",-} as const;--let count = 0;--function genId() {- count = (count + 1) % Number.MAX_VALUE;- return count.toString();-}--type ActionType = typeof actionTypes;--type Action =- | {- type: ActionType["ADD_TOAST"];- toast: ToasterToast;- }- | {- type: ActionType["UPDATE_TOAST"];- toast: Partial<ToasterToast>;- }- | {- type: ActionType["DISMISS_TOAST"];- toastId?: ToasterToast["id"];- }- | {- type: ActionType["REMOVE_TOAST"];- toastId?: ToasterToast["id"];- };--interface State {- toasts: ToasterToast[];-}--const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();--const addToRemoveQueue = (toastId: string) => {- if (toastTimeouts.has(toastId)) {- return;- }-- const timeout = setTimeout(() => {- toastTimeouts.delete(toastId);- dispatch({- type: "REMOVE_TOAST",- toastId: toastId,- });- }, TOAST_REMOVE_DELAY);-- toastTimeouts.set(toastId, timeout);-};--export const reducer = (state: State, action: Action): State => {- switch (action.type) {- case "ADD_TOAST":- return {- ...state,- toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),- };-- case "UPDATE_TOAST":- return {- ...state,- toasts: state.toasts.map((t) =>- t.id === action.toast.id ? { ...t, ...action.toast } : t,- ),- };-- case "DISMISS_TOAST": {- const { toastId } = action;-- // ! Side effects ! - This could be extracted into a dismissToast() action,- // but I'll keep it here for simplicity- if (toastId) {- addToRemoveQueue(toastId);- } else {- state.toasts.forEach((toast) => {- addToRemoveQueue(toast.id);- });- }-- return {- ...state,- toasts: state.toasts.map((t) =>- t.id === toastId || toastId === undefined- ? {- ...t,- open: false,- }- : t,- ),- };- }- case "REMOVE_TOAST":- if (action.toastId === undefined) {- return {- ...state,- toasts: [],- };- }- return {- ...state,- toasts: state.toasts.filter((t) => t.id !== action.toastId),- };- }-};--const listeners: Array<(state: State) => void> = [];--let memoryState: State = { toasts: [] };--function dispatch(action: Action) {- memoryState = reducer(memoryState, action);- listeners.forEach((listener) => {- listener(memoryState);- });-}--export type ToastType = Omit<ToasterToast, "id">;--function toast({ ...props }: ToastType) {- const id = genId();-- const update = (props: ToasterToast) =>- dispatch({- type: "UPDATE_TOAST",- toast: { ...props, id },- });- const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });-- dispatch({- type: "ADD_TOAST",- toast: {- ...props,- id,- open: true,- onOpenChange: (open) => {- if (!open) dismiss();- },- },- });-- return {- id: id,- dismiss,- update,- };-}--function useToast() {- const [state, setState] = useState<State>(memoryState);-- useEffect(() => {- listeners.push(setState);- return () => {- const index = listeners.indexOf(setState);- if (index > -1) {- listeners.splice(index, 1);- }- };- }, [state]);-- return {- ...state,- toast,- dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),- };-}--export { useToast, toast };diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsxindex d1f3e0add..87fda1c42 100644--- a/packages/ui/src/index.tsx+++ b/packages/ui/src/index.tsx@@ -27,15 +27,12 @@ export * from "./components/skeleton";export * from "./components/switch";export * from "./components/table";export * from "./components/textarea";-export * from "./components/toast";-export * from "./components/toaster";-export * from "./components/use-toast";export * from "./components/tooltip";export * from "./components/tabs";export * from "./components/date-time-picker";export * from "./components/date-time-picker-popover";export * from "./components/sheet";-export * from "./components/use-toast";export * from "./components/multi-select";export * from "./components/toggle";export * from "./components/collabsible";+export * from "./components/sonner";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 336200bb3..bef285d2c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -264,7 +264,7 @@ importers:specifier: 7.47.0version: 7.47.0([email protected])react-tweet:- specifier: ^3.1.1+ specifier: 3.1.1version: 3.1.1([email protected])([email protected])reading-time:specifier: 1.5.0@@ -287,6 +287,9 @@ importers:shiki:specifier: 0.14.4version: 0.14.4+ sonner:+ specifier: 1.3.1+ version: 1.3.1([email protected])([email protected])stripe:specifier: 13.8.0version: 13.8.0@@ -825,9 +828,6 @@ importers:'@radix-ui/react-tabs':specifier: 1.0.4version: 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-toast':- specifier: 1.1.5- version: 1.1.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])'@radix-ui/react-toggle':specifier: ^1.0.3version: 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])@@ -852,6 +852,9 @@ importers:luxon:specifier: 3.3.0version: 3.3.0+ next-themes:+ specifier: 0.2.1react:specifier: 18.2.0version: 18.2.0@@ -861,6 +864,9 @@ importers:react-hook-form:specifier: 7.47.0version: 7.47.0([email protected])+ sonner:+ specifier: 1.3.1+ version: 1.3.1([email protected])([email protected])tailwind-merge:specifier: 1.14.0version: 1.14.0@@ -4149,38 +4155,6 @@ packages:react-dom: 18.2.0([email protected])dev: false- /@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):- resolution: {integrity: sha512-fRLn227WHIBRSzuRzGJ8W+5YALxofH23y0MlPLddaIpLpCDqdE0NZlS2NRQDRiptfxDeeCjgFIpexB1/zkxDlw==}- peerDependencies:- '@types/react': '*'- '@types/react-dom': '*'- react: ^16.8 || ^17.0 || ^18.0- react-dom: ^16.8 || ^17.0 || ^18.0- peerDependenciesMeta:- '@types/react':- optional: true- '@types/react-dom':- optional: true- dependencies:- '@babel/runtime': 7.23.2- '@radix-ui/primitive': 1.0.1- '@radix-ui/react-collection': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])- '@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])- '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-portal': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-presence': 1.0.1(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@radix-ui/react-use-callback-ref': 1.0.1(@types/[email protected])([email protected])- '@radix-ui/react-use-controllable-state': 1.0.1(@types/[email protected])([email protected])- '@radix-ui/react-use-layout-effect': 1.0.1(@types/[email protected])([email protected])- '@radix-ui/react-visually-hidden': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])- '@types/react': 18.2.24- '@types/react-dom': 18.2.19- react: 18.2.0- react-dom: 18.2.0([email protected])- dev: false-/@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected])([email protected]):resolution: {integrity: sha512-Pkqg3+Bc98ftZGsl60CLANXQBBQ4W3mTFS9EJvNxKMZ7magklKV69/id1mlAlOFDDfHvlCms0fx8fA4CMKDJHg==}peerDependencies:@@ -12089,6 +12063,16 @@ packages:smart-buffer: 4.2.0dev: true+ resolution: {integrity: sha512-+rOAO56b2eI3q5BtgljERSn2umRk63KFIvgb2ohbZ5X+Eb5u+a/7/0ZgswYqgBMg8dyl7n6OXd9KasA8QF9ToA==}+ peerDependencies:+ react: ^18.0.0+ react-dom: ^18.0.0+ dependencies:+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ dev: false+resolution: {integrity: sha512-Pdz01AvCAottHTPQGzndktFNdbRA75BgOfeT1hH+AMnJFv8lynkPi42rfeEhpx1saTEI3YNMWxfqu0sFD1G8pw==}engines: {node: '>=12'}