2026-02-13 15:52:13 +07:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type { CreateServerRequest } from "@minikura/api";
|
|
|
|
|
import { ArrowLeft } from "lucide-react";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { ServerForm, type ServerFormData } from "@/components/server-form";
|
2026-08-13 01:58:15 +07:00
|
|
|
import { PageHeader, PageShell } from "@/components/page-layout";
|
|
|
|
|
import { SectionCard } from "@/components/section-card";
|
2026-02-13 15:52:13 +07:00
|
|
|
import { Button } from "@/components/ui/button";
|
2026-02-17 18:12:02 +07:00
|
|
|
import { api } from "@/lib/api-client";
|
2026-08-13 01:58:15 +07:00
|
|
|
import { toCommonServerRequestFields } from "@/lib/server-form/mappings";
|
2026-02-13 15:52:13 +07:00
|
|
|
|
|
|
|
|
export default function CreateServerPage() {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async (data: ServerFormData) => {
|
|
|
|
|
const payload: CreateServerRequest = {
|
|
|
|
|
id: data.id.trim(),
|
|
|
|
|
type: "STATEFUL",
|
2026-08-13 01:58:15 +07:00
|
|
|
...toCommonServerRequestFields(data),
|
2026-02-13 15:52:13 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await api.api.servers.post(payload);
|
|
|
|
|
|
|
|
|
|
if (response.error) {
|
|
|
|
|
const errorMsg =
|
|
|
|
|
typeof response.error === "object" &&
|
|
|
|
|
response.error &&
|
|
|
|
|
"value" in response.error &&
|
|
|
|
|
typeof response.error.value === "object" &&
|
|
|
|
|
response.error.value &&
|
|
|
|
|
"message" in response.error.value
|
|
|
|
|
? String(response.error.value.message)
|
|
|
|
|
: "Failed to create server";
|
|
|
|
|
throw new Error(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
router.push("/dashboard/servers");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-08-13 01:58:15 +07:00
|
|
|
<PageShell>
|
|
|
|
|
<PageHeader
|
|
|
|
|
eyebrow="Compute / Provision"
|
|
|
|
|
title="Create Server"
|
|
|
|
|
description="Define the runtime, world, resources, and network contract."
|
|
|
|
|
leading={
|
|
|
|
|
<Button variant="ghost" size="icon" onClick={() => router.push("/dashboard/servers")}>
|
|
|
|
|
<ArrowLeft className="size-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
className="flex-row items-center justify-start"
|
|
|
|
|
/>
|
2026-02-13 15:52:13 +07:00
|
|
|
|
2026-08-13 01:58:15 +07:00
|
|
|
<SectionCard
|
|
|
|
|
title="Server Configuration"
|
|
|
|
|
description="Complete configuration for the itzg/minecraft-server workload."
|
|
|
|
|
>
|
2026-02-13 15:52:13 +07:00
|
|
|
<ServerForm
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
onCancel={() => router.push("/dashboard/servers")}
|
|
|
|
|
submitLabel="Create Server"
|
|
|
|
|
/>
|
2026-08-13 01:58:15 +07:00
|
|
|
</SectionCard>
|
|
|
|
|
</PageShell>
|
2026-02-13 15:52:13 +07:00
|
|
|
);
|
|
|
|
|
}
|