1 Commits

Author SHA1 Message Date
Fran Jurmanović
bb0a5ab66d fix form actions 2025-08-27 21:52:35 +02:00
3 changed files with 28 additions and 32 deletions

View File

@@ -1,24 +1,16 @@
import Link from 'next/link'; import Link from 'next/link';
import { Server, ServiceStatus, getStatusColor, serviceStatusToString } from '@/lib/types'; import { Server, ServiceStatus, getStatusColor, serviceStatusToString } from '@/lib/types';
import { startServerAction, stopServerAction, restartServerAction } from '@/lib/actions/servers'; import {
startServerEventAction,
restartServerEventAction,
stopServerEventAction
} from '@/lib/actions/servers';
interface ServerCardProps { interface ServerCardProps {
server: Server; server: Server;
} }
export function ServerCard({ server }: ServerCardProps) { export function ServerCard({ server }: ServerCardProps) {
const handleStartServer = () => {
startServerAction(server.id);
};
const handleStopServer = () => {
stopServerAction(server.id);
};
const handleRestartServer = () => {
restartServerAction(server.id);
};
return ( return (
<div className="overflow-hidden rounded-lg border border-gray-700 bg-gray-800 shadow-lg"> <div className="overflow-hidden rounded-lg border border-gray-700 bg-gray-800 shadow-lg">
<Link href={`/dashboard/server/${server.id}`} className="block"> <Link href={`/dashboard/server/${server.id}`} className="block">
@@ -61,7 +53,7 @@ export function ServerCard({ server }: ServerCardProps) {
</Link> </Link>
<div className="flex justify-between gap-2 bg-gray-900 px-4 py-3"> <div className="flex justify-between gap-2 bg-gray-900 px-4 py-3">
<form action={handleStartServer}> <form action={startServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Running} disabled={server.status === ServiceStatus.Running}
@@ -71,7 +63,7 @@ export function ServerCard({ server }: ServerCardProps) {
</button> </button>
</form> </form>
<form action={handleRestartServer}> <form action={restartServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Stopped} disabled={server.status === ServiceStatus.Stopped}
@@ -81,7 +73,7 @@ export function ServerCard({ server }: ServerCardProps) {
</button> </button>
</form> </form>
<form action={handleStopServer}> <form action={stopServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Stopped} disabled={server.status === ServiceStatus.Stopped}

View File

@@ -1,24 +1,16 @@
import Link from 'next/link'; import Link from 'next/link';
import { Server, getStatusColor, serviceStatusToString, ServiceStatus } from '@/lib/types/server'; import { Server, getStatusColor, serviceStatusToString, ServiceStatus } from '@/lib/types/server';
import { startServerAction, stopServerAction, restartServerAction } from '@/lib/actions/servers'; import {
startServerEventAction,
restartServerEventAction,
stopServerEventAction
} from '@/lib/actions/servers';
interface ServerHeaderProps { interface ServerHeaderProps {
server: Server; server: Server;
} }
export function ServerHeader({ server }: ServerHeaderProps) { export function ServerHeader({ server }: ServerHeaderProps) {
const handleStartServer = () => {
startServerAction(server.id);
};
const handleStopServer = () => {
stopServerAction(server.id);
};
const handleRestartServer = () => {
restartServerAction(server.id);
};
return ( return (
<div className="rounded-lg bg-gray-800 p-6"> <div className="rounded-lg bg-gray-800 p-6">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
@@ -61,7 +53,7 @@ export function ServerHeader({ server }: ServerHeaderProps) {
</div> </div>
<div className="flex space-x-3"> <div className="flex space-x-3">
<form action={handleStartServer}> <form action={startServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Running} disabled={server.status === ServiceStatus.Running}
@@ -71,7 +63,7 @@ export function ServerHeader({ server }: ServerHeaderProps) {
</button> </button>
</form> </form>
<form action={handleRestartServer}> <form action={restartServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Stopped} disabled={server.status === ServiceStatus.Stopped}
@@ -81,7 +73,7 @@ export function ServerHeader({ server }: ServerHeaderProps) {
</button> </button>
</form> </form>
<form action={handleStopServer}> <form action={stopServerEventAction.bind(null, server.id)}>
<button <button
type="submit" type="submit"
disabled={server.status === ServiceStatus.Stopped} disabled={server.status === ServiceStatus.Stopped}

View File

@@ -18,6 +18,10 @@ export async function startServerAction(serverId: string) {
} }
} }
export async function startServerEventAction(serverId: string) {
await startServerAction(serverId);
}
export async function stopServerAction(serverId: string) { export async function stopServerAction(serverId: string) {
try { try {
const session = await requireAuth(); const session = await requireAuth();
@@ -32,6 +36,10 @@ export async function stopServerAction(serverId: string) {
} }
} }
export async function stopServerEventAction(serverId: string) {
await stopServerAction(serverId);
}
export async function restartServerAction(serverId: string) { export async function restartServerAction(serverId: string) {
try { try {
const session = await requireAuth(); const session = await requireAuth();
@@ -45,3 +53,7 @@ export async function restartServerAction(serverId: string) {
}; };
} }
} }
export async function restartServerEventAction(serverId: string) {
await restartServerAction(serverId);
}