Skip to content

Commit 8c0a2db

Browse files
committed
Improve exception handling and toast layout
1 parent cc43232 commit 8c0a2db

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

src/components/sides/tailscale-side.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import { toast } from "@/hooks/use-toast";
2121
import { loadFromCache, saveToCache } from "@/lib/local-storage";
2222
import { ArrowRightToLineIcon, RefreshCw } from "lucide-react";
2323
import { Button } from "../ui/button";
24-
import { getDeepestSubdomain, getMatchedHosts, getUnmatchedHosts, handleForceRefresh } from "@/lib/utils";
24+
import {
25+
getDeepestSubdomain,
26+
getMatchedHosts,
27+
getUnmatchedHosts,
28+
handleForceRefresh,
29+
} from "@/lib/utils";
2530
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
2631
import { record } from "zod";
2732

@@ -111,12 +116,22 @@ export default function TailscaleSide() {
111116
toast({
112117
title: "Adding host to Cloudflare",
113118
});
119+
120+
if (!information.cloudflare.selectedZone) {
121+
toast({
122+
variant: "destructive",
123+
title: "Please select a Cloudflare zone first.",
124+
});
125+
return;
126+
}
127+
114128
const hostname = fqdn.split(".")[0];
115129
try {
116130
const res = await createCloudflareRecordInZone(tailflareState, {
117-
name: `${hostname}${information.cloudflare.subdomain &&
131+
name: `${hostname}${
132+
information.cloudflare.subdomain &&
118133
"." + information.cloudflare.subdomain
119-
}`,
134+
}`,
120135
content: fqdn,
121136
zone_id: information.cloudflare.selectedZone?.id ?? "",
122137
type: "CNAME",

src/components/ui/toast.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"use client"
1+
"use client";
22

3-
import * as React from "react"
4-
import * as ToastPrimitives from "@radix-ui/react-toast"
5-
import { cva, type VariantProps } from "class-variance-authority"
6-
import { X } from "lucide-react"
3+
import * as React from "react";
4+
import * as ToastPrimitives from "@radix-ui/react-toast";
5+
import { cva, type VariantProps } from "class-variance-authority";
6+
import { X } from "lucide-react";
77

8-
import { cn } from "@/lib/utils"
8+
import { cn } from "@/lib/utils";
99

10-
const ToastProvider = ToastPrimitives.Provider
10+
const ToastProvider = ToastPrimitives.Provider;
1111

1212
const ToastViewport = React.forwardRef<
1313
React.ElementRef<typeof ToastPrimitives.Viewport>,
@@ -16,16 +16,16 @@ const ToastViewport = React.forwardRef<
1616
<ToastPrimitives.Viewport
1717
ref={ref}
1818
className={cn(
19-
"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]",
19+
"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] gap-2",
2020
className
2121
)}
2222
{...props}
2323
/>
24-
))
25-
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
24+
));
25+
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
2626

2727
const toastVariants = cva(
28-
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
28+
"group data-[state=closed]:slide-out-to-right-full data-[state=open]:sm:slide-in-from-bottom-full relative flex justify-between items-center space-x-2 data-[state=open]:slide-in-from-top-full shadow-lg p-4 pr-6 border rounded-md w-full overflow-hidden transition-all data-[swipe=move]:transition-none data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out pointer-events-auto data-[state=closed]:fade-out-80",
2929
{
3030
variants: {
3131
variant: {
@@ -38,7 +38,7 @@ const toastVariants = cva(
3838
variant: "default",
3939
},
4040
}
41-
)
41+
);
4242

4343
const Toast = React.forwardRef<
4444
React.ElementRef<typeof ToastPrimitives.Root>,
@@ -51,9 +51,9 @@ const Toast = React.forwardRef<
5151
className={cn(toastVariants({ variant }), className)}
5252
{...props}
5353
/>
54-
)
55-
})
56-
Toast.displayName = ToastPrimitives.Root.displayName
54+
);
55+
});
56+
Toast.displayName = ToastPrimitives.Root.displayName;
5757

5858
const ToastAction = React.forwardRef<
5959
React.ElementRef<typeof ToastPrimitives.Action>,
@@ -67,8 +67,8 @@ const ToastAction = React.forwardRef<
6767
)}
6868
{...props}
6969
/>
70-
))
71-
ToastAction.displayName = ToastPrimitives.Action.displayName
70+
));
71+
ToastAction.displayName = ToastPrimitives.Action.displayName;
7272

7373
const ToastClose = React.forwardRef<
7474
React.ElementRef<typeof ToastPrimitives.Close>,
@@ -83,10 +83,10 @@ const ToastClose = React.forwardRef<
8383
toast-close=""
8484
{...props}
8585
>
86-
<X className="h-4 w-4" />
86+
<X className="w-4 h-4" />
8787
</ToastPrimitives.Close>
88-
))
89-
ToastClose.displayName = ToastPrimitives.Close.displayName
88+
));
89+
ToastClose.displayName = ToastPrimitives.Close.displayName;
9090

9191
const ToastTitle = React.forwardRef<
9292
React.ElementRef<typeof ToastPrimitives.Title>,
@@ -97,8 +97,8 @@ const ToastTitle = React.forwardRef<
9797
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
9898
{...props}
9999
/>
100-
))
101-
ToastTitle.displayName = ToastPrimitives.Title.displayName
100+
));
101+
ToastTitle.displayName = ToastPrimitives.Title.displayName;
102102

103103
const ToastDescription = React.forwardRef<
104104
React.ElementRef<typeof ToastPrimitives.Description>,
@@ -109,12 +109,12 @@ const ToastDescription = React.forwardRef<
109109
className={cn("text-sm opacity-90", className)}
110110
{...props}
111111
/>
112-
))
113-
ToastDescription.displayName = ToastPrimitives.Description.displayName
112+
));
113+
ToastDescription.displayName = ToastPrimitives.Description.displayName;
114114

115-
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
115+
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
116116

117-
type ToastActionElement = React.ReactElement<typeof ToastAction>
117+
type ToastActionElement = React.ReactElement<typeof ToastAction>;
118118

119119
export {
120120
type ToastProps,
@@ -126,4 +126,4 @@ export {
126126
ToastDescription,
127127
ToastClose,
128128
ToastAction,
129-
}
129+
};

src/components/ui/toaster.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
"use client"
1+
"use client";
22

3-
import { useToast } from "@/hooks/use-toast"
3+
import { useToast } from "@/hooks/use-toast";
44
import {
55
Toast,
66
ToastClose,
77
ToastDescription,
88
ToastProvider,
99
ToastTitle,
1010
ToastViewport,
11-
} from "@/components/ui/toast"
11+
} from "@/components/ui/toast";
1212

1313
export function Toaster() {
14-
const { toasts } = useToast()
14+
const { toasts } = useToast();
1515

1616
return (
1717
<ToastProvider>
1818
{toasts.map(function ({ id, title, description, action, ...props }) {
1919
return (
2020
<Toast key={id} {...props}>
21-
<div className="grid gap-1">
22-
{title && <ToastTitle>{title}</ToastTitle>}
21+
<div className="gap-1 grid">
22+
{title && <ToastTitle>{`${id}: ${title}`}</ToastTitle>}
2323
{description && (
2424
<ToastDescription>{description}</ToastDescription>
2525
)}
2626
</div>
2727
{action}
2828
<ToastClose />
2929
</Toast>
30-
)
30+
);
3131
})}
3232
<ToastViewport />
3333
</ToastProvider>
34-
)
34+
);
3535
}

0 commit comments

Comments
 (0)