Added error and success messages for deletion
This commit is contained in:
parent
f0c9fd1182
commit
739dbd265e
6 changed files with 20 additions and 21 deletions
|
|
@ -7,7 +7,7 @@ export async function POST(req: Request) {
|
|||
|
||||
//TODO, Christ, maybe I'm not a dev
|
||||
if (!true) {
|
||||
return new NextResponse(JSON.stringify({"error": "An error has occurred. Please check for a valid body and retry."}), {
|
||||
return new NextResponse(JSON.stringify({error: true, message: "An error has occurred. Please check for a valid body and retry."}), {
|
||||
status: 400,
|
||||
headers: {
|
||||
'Content-Type': 'appliation/json',
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ export async function DELETE(req: Request) {
|
|||
let routesMap: Route[] = routes.map(r => r);
|
||||
let hostsMap = routesMap.map(r => r.match[0].host);
|
||||
|
||||
//CHANGE 1 TO 0
|
||||
let targetRoute: Route = routesMap.filter((r) => (JSON.stringify(r.match[0]) === JSON.stringify(route.match[0]))).values().next().value;
|
||||
|
||||
let index = routesMap.indexOf(targetRoute);
|
||||
|
||||
if(index == -1) return new NextResponse(JSON.stringify({error: 'Route not found'}), {
|
||||
if(index == -1) return new NextResponse(JSON.stringify({error: true, message: "Route not found"}), {
|
||||
status: 404,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
'use client'
|
||||
|
||||
export default function GlobalError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}) {
|
||||
return (
|
||||
<html>
|
||||
<body>
|
||||
<h2>Something went wrong!</h2>
|
||||
<button onClick={() => reset()}>Try again</button>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import type { Metadata } from 'next'
|
|||
import { Inter } from 'next/font/google'
|
||||
import './globals.css'
|
||||
import { ThemeProvider } from '@/components/theme-provider'
|
||||
import { Toaster } from '@/components/ui/toaster'
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ export default function RootLayout({
|
|||
disableTransitionOnChange
|
||||
>
|
||||
{children}
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -4,15 +4,28 @@ import { Button } from '@/components/ui/button';
|
|||
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./ui/card";
|
||||
import { getHosts, getRouteUpstreams } from '@/lib/utils';
|
||||
import { deleteRoute } from '@/lib/serverActions';
|
||||
import { toast } from './ui/use-toast';
|
||||
|
||||
export default function RouteCards({ routes }: { routes: Array<Route> }) {
|
||||
|
||||
const handleDelete = async (route: Route) => {
|
||||
let res = await deleteRoute(route);
|
||||
console.log(res);
|
||||
|
||||
if (res.error) return toast({
|
||||
title: "Error",
|
||||
description: res.message,
|
||||
variant: "destructive"
|
||||
});
|
||||
|
||||
return toast({
|
||||
title: "Success",
|
||||
description: "Route deleted successfully!",
|
||||
variant: "success"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
let handleClick = (route: Route) => {
|
||||
console.log(route);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"@radix-ui/react-icons": "^1.3.0",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-toast": "^1.1.5",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"next": "14.0.2",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue