Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
Style/toast (#408)
Arshdeep Kd1ec46d58328
diff --git a/.gitignore b/.gitignoreindex f67af55e3..0b90f592d 100644--- a/.gitignore+++ b/.gitignore@@ -54,3 +54,6 @@ apps/web/tsconfig.tsbuildinfoopenstatus-test.dbopenstatus-test.db-shmopenstatus-test.db-wal++#webstorm+.ideadiff --git a/apps/web/src/components/forms/monitor-form.tsx b/apps/web/src/components/forms/monitor-form.tsxindex fee802013..a569eabe1 100644--- a/apps/web/src/components/forms/monitor-form.tsx+++ b/apps/web/src/components/forms/monitor-form.tsx@@ -186,6 +186,15 @@ export function MonitorForm({};const sendTestPing = () => {+ if (isTestPending) {+ return;+ }+ const { url } = form.getValues();+ if (!url) {+ toast("test-warning-empty-url");+ return;+ }+startTestTransition(async () => {const isSuccessful = await pingEndpoint();if (isSuccessful) {diff --git a/apps/web/src/hooks/use-toast-action.tsx b/apps/web/src/hooks/use-toast-action.tsxindex f242a4021..bccd0de63 100644--- a/apps/web/src/hooks/use-toast-action.tsx+++ b/apps/web/src/hooks/use-toast-action.tsx@@ -17,6 +17,7 @@ const config = {"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@@ -26,6 +27,11 @@ const config = {// 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",},diff --git a/packages/ui/src/components/toast.tsx b/packages/ui/src/components/toast.tsxindex 70836db9e..566e1b0f0 100644--- a/packages/ui/src/components/toast.tsx+++ b/packages/ui/src/components/toast.tsx@@ -1,10 +1,11 @@"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 { X } from "lucide-react";+import { Check, ShieldAlert, X } from "lucide-react";import { cn } from "../lib/utils";@@ -26,13 +27,14 @@ const ToastViewport = React.forwardRef<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",+ "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: {- default: "bg-background border",- destructive:- "group destructive border-destructive bg-destructive text-destructive-foreground",+ // REMINDER: same keys as toastIconVariant+ default: "",+ destructive: "",+ warning: "",},},defaultVariants: {@@ -41,6 +43,19 @@ const toastVariants = cva(},);+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> &@@ -56,6 +71,32 @@ const Toast = React.forwardRef<});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>@@ -127,4 +168,5 @@ export {ToastDescription,ToastClose,ToastAction,+ ToastIcon,};diff --git a/packages/ui/src/components/toaster.tsx b/packages/ui/src/components/toaster.tsxindex b6f973c9b..11fd73899 100644--- a/packages/ui/src/components/toaster.tsx+++ b/packages/ui/src/components/toaster.tsx@@ -4,6 +4,7 @@ import {Toast,ToastClose,ToastDescription,+ ToastIcon,ToastProvider,ToastTitle,ToastViewport,@@ -17,15 +18,18 @@ export function Toaster() {<ToastProvider>{toasts.map(function ({ id, title, description, action, ...props }) {return (- <Toast key={id} {...props}>- <div className="grid gap-1">- {title && <ToastTitle>{title}</ToastTitle>}- {description && (- <ToastDescription>{description}</ToastDescription>- )}+ <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>- {action}- <ToastClose /></Toast>);})}