add toasts for invalid player and invalid server
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 1m18s

This commit is contained in:
Lee
2024-04-17 18:26:53 +01:00
parent 347ee00c18
commit 6b96c3aedb
11 changed files with 537 additions and 42 deletions

View File

@ -1,7 +1,8 @@
"use client";
import { capitalizeFirstLetter } from "@/common/string-utils";
import { ServerPlatform } from "mcutils-library";
import { useToast } from "@/common/use-toast";
import { ServerPlatform, getServer } from "mcutils-library";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { Button } from "../ui/button";
@ -10,6 +11,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
export function LookupServer(): JSX.Element {
const router = useRouter();
const { toast } = useToast();
const [hostname, setHostname] = useState("");
/**
@ -26,10 +28,23 @@ export function LookupServer(): JSX.Element {
*
* @param platform the server platform
*/
const lookupServer = (platform: ServerPlatform) => {
const lookupServer = async (platform: ServerPlatform) => {
if (!hostname || hostname.length === 0) {
return;
}
try {
await getServer(platform, hostname);
} catch (err) {
toast({
title: "Error",
variant: "destructive",
description: (err as Error).message,
duration: 5000,
});
return;
}
router.push(`/server/${platform}/${hostname}`);
};
@ -38,7 +53,9 @@ export function LookupServer(): JSX.Element {
return (
<Tooltip>
<TooltipTrigger asChild>
<Button type="submit">{name}</Button>
<Button type="submit" onClick={() => lookupServer(platform)}>
{name}
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Click to lookup the server as a {name} server</p>
@ -48,7 +65,11 @@ export function LookupServer(): JSX.Element {
};
return (
<form className="flex gap-2 justify-center items-center mt-2 flex-col xs:flex-row">
<form
className="flex gap-2 justify-center items-center mt-2 flex-col xs:flex-row"
action=""
onSubmit={(event) => event.preventDefault()}
>
<Input className="w-fit" placeholder="Hostname" value={hostname} onChange={setHostnameValue} maxLength={128} />
<div className="flex gap-2 justify-center">
<LookupButton platform={ServerPlatform.Java} />