Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50d8662904 | |||
| 5a4457d369 | |||
| 4cc005d309 | |||
| 9d22027f23 | |||
| de41d2566c | |||
| 004ba49de3 | |||
| 3cf56b335c | |||
| b2f73a0b95 | |||
| 5360bb51c4 | |||
| 71fa228013 | |||
| 3c643d5dcc | |||
| c99eebde05 | |||
| 4f7705ec7c | |||
| 8a7299fba2 | |||
| db0b1491bd | |||
| 097d9d99fc | |||
| 14faaf87b7 | |||
| 9d240c3a80 | |||
| 374899e839 | |||
| da92ec72a7 | |||
| a5e50fe8b7 | |||
| 025c021896 | |||
| a4ff0a9339 | |||
| 45a67ebfb8 | |||
| 5a7485f654 | |||
| 710ac253e2 | |||
| 5c69ef716b | |||
| 1d13def6da | |||
| 2801f80b9a | |||
| 75d88257c8 | |||
| f8510c8db3 | |||
| e2f86fbcb6 | |||
| adf123f56a | |||
| 3ba68ac973 | |||
| 67a72f9a92 | |||
| 51c45ad4a9 | |||
| 61f0b69176 | |||
| 2976468c9f | |||
| d56a399e8e | |||
| 8dc8f98add | |||
| d8d008b5e8 | |||
| 51f45a806e |
0
.gitignore
vendored
Normal file → Executable file
0
.prettierignore
Normal file → Executable file
0
.prettierrc
Normal file → Executable file
0
Dockerfile
Normal file → Executable file
0
eslint.config.mjs
Normal file → Executable file
0
next.config.ts
Normal file → Executable file
0
package-lock.json
generated
Normal file → Executable file
2
package.json
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "acc-server-manager-web",
|
||||
"version": "0.20.2",
|
||||
"version": "0.23.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
|
||||
0
postcss.config.mjs
Normal file → Executable file
0
public/file.svg
Normal file → Executable file
|
Before Width: | Height: | Size: 391 B After Width: | Height: | Size: 391 B |
0
public/globe.svg
Normal file → Executable file
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
0
public/next.svg
Normal file → Executable file
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
0
public/vercel.svg
Normal file → Executable file
|
Before Width: | Height: | Size: 128 B After Width: | Height: | Size: 128 B |
0
public/window.svg
Normal file → Executable file
|
Before Width: | Height: | Size: 385 B After Width: | Height: | Size: 385 B |
23
src/app/dashboard/layout.tsx
Normal file → Executable file
@@ -3,19 +3,28 @@ import { SteamCMDProvider } from '@/lib/context/SteamCMDContext';
|
||||
import { ServerCreationPopupProvider } from '@/lib/context/ServerCreationPopupContext';
|
||||
import { ServerCreationPopupContainer } from '@/components/server/ServerCreationPopupContainer';
|
||||
import { requireAuth } from '@/lib/auth/server';
|
||||
import { AppShell } from '@/components/ui/AppShell';
|
||||
import { hasPermission } from '@/lib/schemas';
|
||||
import { checkHealth } from '@/lib/api/server/health';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default async function DashboardLayout({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
export default async function DashboardLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
||||
const session = await requireAuth();
|
||||
|
||||
const health = await checkHealth();
|
||||
if (!health.healthy) {
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
const showUsers = hasPermission(session.user!, 'membership.view');
|
||||
return (
|
||||
<WebSocketProvider openToken={session.openToken!}>
|
||||
<SteamCMDProvider>
|
||||
<ServerCreationPopupProvider>
|
||||
{children}
|
||||
<ServerCreationPopupContainer />
|
||||
<AppShell showUsers={showUsers}>
|
||||
{children}
|
||||
<ServerCreationPopupContainer />
|
||||
</AppShell>
|
||||
</ServerCreationPopupProvider>
|
||||
</SteamCMDProvider>
|
||||
</WebSocketProvider>
|
||||
|
||||
20
src/app/dashboard/membership/page.tsx
Normal file → Executable file
@@ -4,24 +4,26 @@ import type { UserListParams } from '@/lib/api/server/membership';
|
||||
import { UserManagementTable } from '@/components/membership/UserManagementTable';
|
||||
|
||||
interface MembershipPageProps {
|
||||
searchParams: {
|
||||
searchParams: Promise<{
|
||||
username?: string;
|
||||
role_name?: string;
|
||||
sort_by?: string;
|
||||
sort_desc?: string;
|
||||
page?: string;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
||||
export default async function MembershipPage({ searchParams }: MembershipPageProps) {
|
||||
const session = await requireAuth();
|
||||
|
||||
const resolvedParams = await searchParams;
|
||||
|
||||
const params: UserListParams = {
|
||||
username: searchParams.username,
|
||||
role_name: searchParams.role_name,
|
||||
sort_by: searchParams.sort_by || 'username',
|
||||
sort_desc: searchParams.sort_desc === 'true',
|
||||
page: parseInt(searchParams.page || '1'),
|
||||
username: resolvedParams.username,
|
||||
role_name: resolvedParams.role_name,
|
||||
sort_by: resolvedParams.sort_by || 'username',
|
||||
sort_desc: resolvedParams.sort_desc === 'true',
|
||||
page: parseInt(resolvedParams.page || '1'),
|
||||
limit: 20
|
||||
};
|
||||
|
||||
@@ -31,8 +33,6 @@ export default async function MembershipPage({ searchParams }: MembershipPagePro
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-900 text-white">
|
||||
<UserManagementTable initialData={userListData} roles={roles} currentUser={session.user!} />
|
||||
</div>
|
||||
<UserManagementTable initialData={userListData} roles={roles} currentUser={session.user!} />
|
||||
);
|
||||
}
|
||||
|
||||
43
src/app/dashboard/page.tsx
Normal file → Executable file
@@ -1,53 +1,16 @@
|
||||
import { requireAuth } from '@/lib/auth/server';
|
||||
import { getServers } from '@/lib/api/server/servers';
|
||||
import { hasPermission } from '@/lib/schemas';
|
||||
import Link from 'next/link';
|
||||
import { ServerListWithActions } from '@/components/server/ServerListWithActions';
|
||||
import { SteamCMDNotification } from '@/components/ui/SteamCMDNotification';
|
||||
import LogoutButton from '@/components/ui/LogoutButton';
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await requireAuth();
|
||||
const servers = await getServers(session.token!);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-900 text-white">
|
||||
<header className="bg-gray-800 shadow-md">
|
||||
<div className="mx-auto flex max-w-[120rem] items-center justify-between px-4 py-4 sm:px-6 lg:px-8">
|
||||
<h1 className="text-2xl font-bold">ACC Server Manager</h1>
|
||||
<div className="flex items-center space-x-4">
|
||||
{hasPermission(session.user!, 'membership.view') && (
|
||||
<Link
|
||||
href="/dashboard/membership"
|
||||
className="flex items-center text-gray-300 hover:text-white"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M15 21a6 6 0 00-9-5.197m0 0A5.975 5.975 0 0112 13a5.975 5.975 0 01-3-1.197"
|
||||
/>
|
||||
</svg>
|
||||
<span className="ml-1 hidden sm:inline">Users</span>
|
||||
</Link>
|
||||
)}
|
||||
<LogoutButton />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<SteamCMDNotification />
|
||||
|
||||
<main className="mx-auto max-w-[120rem] px-4 py-8 sm:px-6 lg:px-8">
|
||||
<ServerListWithActions servers={servers} user={session.user!} />
|
||||
</main>
|
||||
</div>
|
||||
<ServerListWithActions servers={servers} user={session.user!} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
26
src/app/dashboard/server/[id]/page.tsx
Normal file → Executable file
@@ -4,6 +4,7 @@ import { getServerConfigurations } from '@/lib/api/server/configuration';
|
||||
import { ServerConfigurationTabs } from '@/components/server/ServerConfigurationTabs';
|
||||
import { ServerHeader } from '@/components/server/ServerHeader';
|
||||
import { getServerStatistics } from '@/lib/api/server/statistics';
|
||||
import { getLeaderboard } from '@/lib/api/server/leaderboard';
|
||||
import { subDays, formatISO } from 'date-fns';
|
||||
import { UTCDate } from '@date-fns/utc';
|
||||
|
||||
@@ -19,25 +20,22 @@ export default async function ServerPage({ params }: ServerPageProps) {
|
||||
const endDate = formatISO(today);
|
||||
const startDate = formatISO(subDays(today, 30));
|
||||
|
||||
const [server, configurations, statistics] = await Promise.all([
|
||||
const [server, configurations, statistics, leaderboard] = await Promise.all([
|
||||
getServer(session.token!, id),
|
||||
getServerConfigurations(session.token!, id),
|
||||
getServerStatistics(session.token!, id, { startDate, endDate })
|
||||
getServerStatistics(session.token!, id, { startDate, endDate }),
|
||||
getLeaderboard(session.token!, id)
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-900 text-white">
|
||||
<div className="mx-auto max-w-[120rem] px-4 py-8 sm:px-6 lg:px-8">
|
||||
<ServerHeader server={server} user={session.user!} />
|
||||
|
||||
<div className="mt-8">
|
||||
<ServerConfigurationTabs
|
||||
serverId={id}
|
||||
configurations={configurations}
|
||||
statistics={statistics}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col overflow-hidden h-screen">
|
||||
<ServerHeader server={server} user={session.user!} />
|
||||
<ServerConfigurationTabs
|
||||
serverId={id}
|
||||
configurations={configurations}
|
||||
statistics={statistics}
|
||||
leaderboard={leaderboard}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 361 KiB |
30
src/app/globals.css
Normal file → Executable file
@@ -1,11 +1,35 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@theme {
|
||||
--color-base: #0d1117;
|
||||
--color-canvas: #161b22;
|
||||
--color-overlay: #21262d;
|
||||
--color-sidebar: #010409;
|
||||
--color-border: #30363d;
|
||||
--color-border-muted: #21262d;
|
||||
--color-hover: #1c2128;
|
||||
--color-primary: #e6edf3;
|
||||
--color-secondary: #c9d1d9;
|
||||
--color-muted: #8b949e;
|
||||
--color-subtle: #6e7681;
|
||||
--color-blue: #58a6ff;
|
||||
--color-blue-bg: #1f6feb33;
|
||||
--color-green: #3fb950;
|
||||
--color-green-bg: #3fb95022;
|
||||
--color-yellow: #d29922;
|
||||
--color-yellow-bg: #d2992220;
|
||||
--color-red: #f85149;
|
||||
--color-red-bg: #f8514920;
|
||||
--color-orange: #f78166;
|
||||
--color-btn-green: #238636;
|
||||
--color-btn-green-hover: #2ea043;
|
||||
}
|
||||
|
||||
@layer components {
|
||||
.form-input {
|
||||
@apply mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white placeholder-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500;
|
||||
@apply block w-full rounded-md border border-border bg-overlay px-3 py-2 text-sm text-primary placeholder-subtle focus:border-blue focus:outline-none focus:ring-1 focus:ring-blue;
|
||||
}
|
||||
|
||||
.form-select {
|
||||
@apply mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500;
|
||||
@apply block w-full rounded-md border border-border bg-overlay px-3 py-2 text-sm text-primary focus:border-blue focus:outline-none focus:ring-1 focus:ring-blue;
|
||||
}
|
||||
}
|
||||
|
||||
2
src/app/layout.tsx
Normal file → Executable file
@@ -13,7 +13,7 @@ export default function RootLayout({
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="bg-gray-900 text-white antialiased">{children}</body>
|
||||
<body className="bg-base text-primary antialiased">{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
7
src/app/login/page.tsx
Normal file → Executable file
@@ -1,15 +1,18 @@
|
||||
import { Suspense } from 'react';
|
||||
import LoginForm from '@/components/login/LoginForm';
|
||||
import { checkHealth } from '@/lib/api/server/health';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function LoginPage({
|
||||
export default async function LoginPage({
|
||||
searchParams
|
||||
}: {
|
||||
searchParams: Promise<{ expired: boolean | undefined }>;
|
||||
}) {
|
||||
const health = await checkHealth();
|
||||
|
||||
return (
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<LoginForm searchParams={searchParams} />
|
||||
<LoginForm searchParams={searchParams} health={health} />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
0
src/app/page.tsx
Normal file → Executable file
75
src/components/configuration/AssistRulesEditor.tsx
Normal file → Executable file
@@ -1,12 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { AssistRules } from '@/lib/schemas/config';
|
||||
import { updateAssistRulesAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface AssistRulesEditorProps {
|
||||
serverId: string;
|
||||
config: AssistRules;
|
||||
formData: AssistRules;
|
||||
disabled?: boolean;
|
||||
onFormDataChange: (data: AssistRules) => void;
|
||||
}
|
||||
|
||||
const assistFields = [
|
||||
@@ -57,50 +56,24 @@ const assistFields = [
|
||||
}
|
||||
];
|
||||
|
||||
export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps) {
|
||||
const [formData, setFormData] = useState<AssistRules>(config);
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
const formDataObj = new FormData();
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
formDataObj.append(key, value.toString());
|
||||
});
|
||||
if (restart) {
|
||||
formDataObj.append('restart', 'on');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateAssistRulesAction(serverId, formDataObj);
|
||||
if (!result.success) {
|
||||
console.error('Failed to update assist rules:', result.message);
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
export function AssistRulesEditor({ formData, disabled, onFormDataChange }: AssistRulesEditorProps) {
|
||||
const handleInputChange = (key: keyof AssistRules, value: string | number) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
[key]: typeof value === 'string' ? parseInt(value) : value
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-3xl space-y-6">
|
||||
<div className="max-w-3xl space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{assistFields.map(({ key, label, type }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
{type === 'number' ? (
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key]}
|
||||
onChange={(e) => handleInputChange(key, e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -109,10 +82,10 @@ export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps)
|
||||
/>
|
||||
) : (
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key]}
|
||||
onChange={(e) => handleInputChange(key, e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>Allowed</option>
|
||||
<option value={1}>Disabled</option>
|
||||
@@ -121,28 +94,6 @@ export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps)
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-600 bg-gray-700 text-green-600 focus:ring-green-500"
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-300">Restart server after saving</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
91
src/components/configuration/ConfigurationEditor.tsx
Normal file → Executable file
@@ -1,56 +1,29 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { Configuration } from '@/lib/schemas/config';
|
||||
import { updateConfigurationAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface ConfigurationEditorProps {
|
||||
serverId: string;
|
||||
config: Configuration;
|
||||
formData: Configuration;
|
||||
disabled?: boolean;
|
||||
onFormDataChange: (data: Configuration) => void;
|
||||
}
|
||||
|
||||
export function ConfigurationEditor({ serverId, config }: ConfigurationEditorProps) {
|
||||
const [formData, setFormData] = useState<Configuration>(config);
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
const formDataObj = new FormData();
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
formDataObj.append(key, value.toString());
|
||||
});
|
||||
if (restart) {
|
||||
formDataObj.append('restart', 'on');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateConfigurationAction(serverId, formDataObj);
|
||||
if (!result.success) {
|
||||
console.error('Failed to update configuration:', result.message);
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
export function ConfigurationEditor({ formData, disabled, onFormDataChange }: ConfigurationEditorProps) {
|
||||
const handleInputChange = (key: keyof Configuration, value: string | number) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
[key]: typeof value === 'string' ? parseInt(value) : value
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-3xl space-y-6">
|
||||
<div className="max-w-3xl space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">UDP Port</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">UDP Port</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.udpPort}
|
||||
onChange={(e) => handleInputChange('udpPort', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -58,10 +31,10 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">TCP Port</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">TCP Port</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.tcpPort}
|
||||
onChange={(e) => handleInputChange('tcpPort', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -69,10 +42,10 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">Max Connections</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">Max Connections</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.maxConnections}
|
||||
onChange={(e) => handleInputChange('maxConnections', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -80,12 +53,12 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">LAN Discovery</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">LAN Discovery</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.lanDiscovery}
|
||||
onChange={(e) => handleInputChange('lanDiscovery', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
@@ -93,40 +66,18 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">Register To Lobby</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">Register To Lobby</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.registerToLobby}
|
||||
onChange={(e) => handleInputChange('registerToLobby', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-600 bg-gray-700 text-green-600 focus:ring-green-500"
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-300">Restart server after saving</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
189
src/components/configuration/EventConfigEditor.tsx
Normal file → Executable file
@@ -1,12 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { EventConfig, Session } from '@/lib/schemas/config';
|
||||
import { updateEventConfigAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface EventConfigEditorProps {
|
||||
serverId: string;
|
||||
config: EventConfig;
|
||||
formData: EventConfig;
|
||||
disabled?: boolean;
|
||||
onFormDataChange: (data: EventConfig) => void;
|
||||
}
|
||||
|
||||
const sessionTypes = [
|
||||
@@ -15,49 +14,19 @@ const sessionTypes = [
|
||||
{ value: 'R', label: 'Race' }
|
||||
];
|
||||
|
||||
export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) {
|
||||
const [formData, setFormData] = useState<EventConfig>(config);
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
const formDataObj = new FormData();
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
if (key === 'sessions') {
|
||||
formDataObj.append(key, JSON.stringify(value));
|
||||
} else {
|
||||
formDataObj.append(key, value.toString());
|
||||
}
|
||||
});
|
||||
if (restart) {
|
||||
formDataObj.append('restart', 'on');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateEventConfigAction(serverId, formDataObj);
|
||||
if (!result.success) {
|
||||
console.error('Failed to update event config:', result.message);
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
export function EventConfigEditor({ formData, disabled, onFormDataChange }: EventConfigEditorProps) {
|
||||
const handleInputChange = (key: keyof EventConfig, value: string | number) => {
|
||||
if (key === 'sessions') return;
|
||||
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
onFormDataChange({
|
||||
...formData,
|
||||
[key]:
|
||||
typeof formData[key] === 'number'
|
||||
? typeof value === 'string'
|
||||
? parseFloat(value) || 0
|
||||
: value
|
||||
: value
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
const handleSessionChange = (index: number, field: keyof Session, value: string | number) => {
|
||||
@@ -67,11 +36,7 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
[field]:
|
||||
field === 'sessionType' ? value : typeof value === 'string' ? parseFloat(value) || 0 : value
|
||||
};
|
||||
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sessions: newSessions
|
||||
}));
|
||||
onFormDataChange({ ...formData, sessions: newSessions });
|
||||
};
|
||||
|
||||
const addSession = () => {
|
||||
@@ -82,63 +47,63 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
sessionType: 'P',
|
||||
sessionDurationMinutes: 20
|
||||
};
|
||||
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sessions: [...prev.sessions, newSession]
|
||||
}));
|
||||
onFormDataChange({ ...formData, sessions: [...formData.sessions, newSession] });
|
||||
};
|
||||
|
||||
const removeSession = (index: number) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sessions: prev.sessions.filter((_, i) => i !== index)
|
||||
}));
|
||||
onFormDataChange({ ...formData, sessions: formData.sessions.filter((_, i) => i !== index) });
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-4xl space-y-8">
|
||||
<div className="max-w-4xl space-y-8">
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Basic Event Settings
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">Track</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">Track</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.track}
|
||||
onChange={(e) => handleInputChange('track', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value="barcelona">Barcelona</option>
|
||||
<option value="brands_hatch">Brands Hatch</option>
|
||||
<option value="donington">Donington</option>
|
||||
<option value="cota">COTA</option>
|
||||
<option value="hungaroring">Hungaroring</option>
|
||||
<option value="imola">Imola</option>
|
||||
<option value="indianapolis">Indianapolis</option>
|
||||
<option value="kyalami">Kyalami</option>
|
||||
<option value="laguna_seca">Laguna Seca</option>
|
||||
<option value="misano">Misano</option>
|
||||
<option value="monza">Monza</option>
|
||||
<option value="mount_panorama">Mount Panorama</option>
|
||||
<option value="nurburgring">Nurburgring</option>
|
||||
<option value="nurburgring_24h">Nurburgring 24h</option>
|
||||
<option value="oulton_park">Oulton Park</option>
|
||||
<option value="paul_ricard">Paul Ricard</option>
|
||||
<option value="red_bull_ring">Red Bull Ring</option>
|
||||
<option value="silverstone">Silverstone</option>
|
||||
<option value="snetterton">Snetterton</option>
|
||||
<option value="spa">Spa-Francorchamps</option>
|
||||
<option value="suzuka">Suzuka</option>
|
||||
<option value="valencia">Valencia</option>
|
||||
<option value="zandvoort">Zandvoort</option>
|
||||
<option value="zolder">Zolder</option>
|
||||
<option value="watkins_glen">Watkins Glen</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Pre-Race Waiting Time (seconds)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.preRaceWaitingTimeSeconds}
|
||||
onChange={(e) => handleInputChange('preRaceWaitingTimeSeconds', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -147,12 +112,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Session Over Time (seconds)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.sessionOverTimeSeconds}
|
||||
onChange={(e) => handleInputChange('sessionOverTimeSeconds', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -161,12 +126,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Post Qualify Seconds
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.postQualySeconds}
|
||||
onChange={(e) => handleInputChange('postQualySeconds', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -175,12 +140,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Post Race Seconds
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.postRaceSeconds}
|
||||
onChange={(e) => handleInputChange('postRaceSeconds', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -191,17 +156,17 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Weather Settings
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Ambient Temperature (°C)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.ambientTemp}
|
||||
onChange={(e) => handleInputChange('ambientTemp', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -211,12 +176,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Cloud Level (0.0-1.0)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.cloudLevel}
|
||||
onChange={(e) => handleInputChange('cloudLevel', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -227,10 +192,10 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">Rain (0.0-1.0)</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">Rain (0.0-1.0)</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.rain}
|
||||
onChange={(e) => handleInputChange('rain', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -241,12 +206,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Weather Randomness
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.weatherRandomness}
|
||||
onChange={(e) => handleInputChange('weatherRandomness', e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -256,14 +221,14 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Simracer Weather Conditions
|
||||
</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.simracerWeatherConditions}
|
||||
onChange={(e) => handleInputChange('simracerWeatherConditions', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
@@ -271,14 +236,14 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Fixed Condition Qualification
|
||||
</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.isFixedConditionQualification}
|
||||
onChange={(e) => handleInputChange('isFixedConditionQualification', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
@@ -288,28 +253,28 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between border-b border-gray-700 pb-2">
|
||||
<h3 className="text-lg font-medium text-white">Sessions</h3>
|
||||
<div className="flex items-center justify-between border-b border-border-muted pb-2">
|
||||
<h3 className="text-sm font-semibold text-primary">Sessions</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={addSession}
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-blue-600 px-3 py-1 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
disabled={disabled}
|
||||
className="rounded-md border border-border bg-overlay px-3 py-1.5 text-xs font-medium text-secondary hover:bg-border disabled:opacity-40"
|
||||
>
|
||||
Add Session
|
||||
+ Add Session
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
{formData.sessions.map((session, index) => (
|
||||
<div key={index} className="rounded-lg bg-gray-800 p-4">
|
||||
<div key={index} className="rounded-lg border border-border bg-canvas p-4">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h4 className="text-sm font-medium text-white">Session {index + 1}</h4>
|
||||
<h4 className="text-sm font-medium text-primary">Session {index + 1}</h4>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeSession(index)}
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-red-600 px-2 py-1 text-xs font-medium text-white hover:bg-red-700 disabled:opacity-50"
|
||||
disabled={disabled}
|
||||
className="rounded px-2 py-1 text-xs text-red hover:bg-red-bg disabled:opacity-40"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
@@ -317,14 +282,14 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-5">
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-medium text-gray-400">
|
||||
<label className="mb-1 block text-xs font-medium text-muted">
|
||||
Session Type
|
||||
</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={session.sessionType}
|
||||
onChange={(e) => handleSessionChange(index, 'sessionType', e.target.value)}
|
||||
className="form-input w-full text-sm"
|
||||
className="form-select w-full text-sm"
|
||||
>
|
||||
{sessionTypes.map((type) => (
|
||||
<option key={type.value} value={type.value}>
|
||||
@@ -335,12 +300,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-medium text-gray-400">
|
||||
<label className="mb-1 block text-xs font-medium text-muted">
|
||||
Hour of Day
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={session.hourOfDay}
|
||||
onChange={(e) => handleSessionChange(index, 'hourOfDay', e.target.value)}
|
||||
className="form-input w-full text-sm"
|
||||
@@ -350,12 +315,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-medium text-gray-400">
|
||||
<label className="mb-1 block text-xs font-medium text-muted">
|
||||
Day of Weekend
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={session.dayOfWeekend}
|
||||
onChange={(e) => handleSessionChange(index, 'dayOfWeekend', e.target.value)}
|
||||
className="form-input w-full text-sm"
|
||||
@@ -365,12 +330,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-medium text-gray-400">
|
||||
<label className="mb-1 block text-xs font-medium text-muted">
|
||||
Time Multiplier
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={session.timeMultiplier}
|
||||
onChange={(e) => handleSessionChange(index, 'timeMultiplier', e.target.value)}
|
||||
className="form-input w-full text-sm"
|
||||
@@ -380,12 +345,12 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-xs font-medium text-gray-400">
|
||||
<label className="mb-1 block text-xs font-medium text-muted">
|
||||
Duration (minutes)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={session.sessionDurationMinutes}
|
||||
onChange={(e) =>
|
||||
handleSessionChange(index, 'sessionDurationMinutes', e.target.value)
|
||||
@@ -399,28 +364,6 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps)
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-600 bg-gray-700 text-green-600 focus:ring-green-500"
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-300">Restart server after saving</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
84
src/components/configuration/EventRulesEditor.tsx
Normal file → Executable file
@@ -1,12 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { EventRules } from '@/lib/schemas/config';
|
||||
import { updateEventRulesAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface EventRulesEditorProps {
|
||||
serverId: string;
|
||||
config: EventRules;
|
||||
formData: EventRules;
|
||||
disabled?: boolean;
|
||||
onFormDataChange: (data: EventRules) => void;
|
||||
}
|
||||
|
||||
const numberFields = [
|
||||
@@ -68,51 +67,22 @@ const booleanFields = [
|
||||
}
|
||||
];
|
||||
|
||||
export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) {
|
||||
const [formData, setFormData] = useState<EventRules>(config);
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
const formDataObj = new FormData();
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
formDataObj.append(key, value.toString());
|
||||
});
|
||||
if (restart) {
|
||||
formDataObj.append('restart', 'on');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateEventRulesAction(serverId, formDataObj);
|
||||
if (!result.success) {
|
||||
console.error('Failed to update event rules:', result.message);
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (key: keyof EventRules, value: string | number | boolean) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[key]: value
|
||||
}));
|
||||
export function EventRulesEditor({ formData, disabled, onFormDataChange }: EventRulesEditorProps) {
|
||||
const handleInputChange = (key: keyof EventRules, value: number) => {
|
||||
onFormDataChange({ ...formData, [key]: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-4xl space-y-8">
|
||||
<div className="max-w-4xl space-y-8">
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">Race Rules</h3>
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">Race Rules</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{numberFields.map(({ key, label, min, max }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key] as number}
|
||||
onChange={(e) => handleInputChange(key, parseInt(e.target.value) || 0)}
|
||||
className="form-input w-full"
|
||||
@@ -125,18 +95,18 @@ export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) {
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Pitstop & Refuelling Rules
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{booleanFields.map(({ key, label }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key] ? 'true' : 'false'}
|
||||
onChange={(e) => handleInputChange(key, e.target.value === 'true')}
|
||||
className="form-input w-full"
|
||||
onChange={(e) => handleInputChange(key, e.target.value === 'true' ? 1 : 0)}
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value="false">No</option>
|
||||
<option value="true">Yes</option>
|
||||
@@ -145,28 +115,6 @@ export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) {
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-600 bg-gray-700 text-green-600 focus:ring-green-500"
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-300">Restart server after saving</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
98
src/components/configuration/ServerSettingsEditor.tsx
Normal file → Executable file
@@ -1,12 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import type { ServerSettings } from '@/lib/schemas/config';
|
||||
import { updateServerSettingsAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface ServerSettingsEditorProps {
|
||||
serverId: string;
|
||||
config: ServerSettings;
|
||||
formData: ServerSettings;
|
||||
disabled?: boolean;
|
||||
onFormDataChange: (data: ServerSettings) => void;
|
||||
}
|
||||
|
||||
const textFields = [
|
||||
@@ -87,53 +86,24 @@ const selectFields = [
|
||||
}
|
||||
];
|
||||
|
||||
export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorProps) {
|
||||
const [formData, setFormData] = useState<ServerSettings>(config);
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
|
||||
const formDataObj = new FormData();
|
||||
Object.entries(formData).forEach(([key, value]) => {
|
||||
formDataObj.append(key, value.toString());
|
||||
});
|
||||
if (restart) {
|
||||
formDataObj.append('restart', 'on');
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await updateServerSettingsAction(serverId, formDataObj);
|
||||
if (!result.success) {
|
||||
console.error('Failed to update server settings:', result.message);
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
export function ServerSettingsEditor({ formData, disabled, onFormDataChange }: ServerSettingsEditorProps) {
|
||||
const handleInputChange = (key: keyof ServerSettings, value: string | number) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
[key]: value
|
||||
}));
|
||||
onFormDataChange({ ...formData, [key]: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-4xl space-y-8">
|
||||
<div className="max-w-4xl space-y-8">
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Basic Settings
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||
{textFields.map(({ key, label, type }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
<input
|
||||
type={type}
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key] as string}
|
||||
onChange={(e) => handleInputChange(key, e.target.value)}
|
||||
className="form-input w-full"
|
||||
@@ -142,12 +112,12 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP
|
||||
))}
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">Car Group</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">Car Group</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.carGroup}
|
||||
onChange={(e) => handleInputChange('carGroup', e.target.value)}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
{carGroups.map((group) => (
|
||||
<option key={group} value={group}>
|
||||
@@ -160,16 +130,16 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Requirements & Limits
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{numberFields.map(({ key, label, min, max }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key] as number}
|
||||
onChange={(e) => handleInputChange(key, parseInt(e.target.value) || 0)}
|
||||
className="form-input w-full"
|
||||
@@ -182,18 +152,18 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<h3 className="border-b border-gray-700 pb-2 text-lg font-medium text-white">
|
||||
<h3 className="border-b border-border-muted pb-2 text-sm font-semibold text-primary">
|
||||
Race Options
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{selectFields.map(({ key, label }) => (
|
||||
<div key={key}>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">{label}</label>
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">{label}</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData[key] as number}
|
||||
onChange={(e) => handleInputChange(key, parseInt(e.target.value))}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
@@ -202,14 +172,14 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP
|
||||
))}
|
||||
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Formation Lap Type
|
||||
</label>
|
||||
<select
|
||||
disabled={isSubmitting}
|
||||
disabled={disabled}
|
||||
value={formData.formationLapType}
|
||||
onChange={(e) => handleInputChange('formationLapType', parseInt(e.target.value))}
|
||||
className="form-input w-full"
|
||||
className="form-select w-full"
|
||||
>
|
||||
<option value={0}>Old Limiter Lap</option>
|
||||
<option value={1}>
|
||||
@@ -220,28 +190,6 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-gray-700 pt-6">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-gray-600 bg-gray-700 text-green-600 focus:ring-green-500"
|
||||
/>
|
||||
<span className="ml-2 text-sm text-gray-300">Restart server after saving</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? 'Saving...' : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
192
src/components/leaderboard/LeaderboardManager.tsx
Executable file
@@ -0,0 +1,192 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Leaderboard, LeaderboardDriver, FlPoints } from '@/lib/schemas/leaderboard';
|
||||
import { saveLeaderboardAction } from '@/lib/actions/leaderboard';
|
||||
import { LeaderboardStandings } from './LeaderboardStandings';
|
||||
import { DriversEditor } from './editors/DriversEditor';
|
||||
import { PointsTableEditor } from './editors/PointsTableEditor';
|
||||
import { FlPointsEditor } from './editors/FlPointsEditor';
|
||||
import { TracksEditor } from './editors/TracksEditor';
|
||||
|
||||
type Section = 'standings' | 'drivers' | 'points' | 'fl' | 'tracks';
|
||||
|
||||
const sections: { id: Section; label: string }[] = [
|
||||
{ id: 'standings', label: 'Standings' },
|
||||
{ id: 'drivers', label: 'Drivers' },
|
||||
{ id: 'points', label: 'Points Table' },
|
||||
{ id: 'fl', label: 'FL Points' },
|
||||
{ id: 'tracks', label: 'Tracks' }
|
||||
];
|
||||
|
||||
interface LeaderboardManagerProps {
|
||||
serverId: string;
|
||||
initialData: Leaderboard;
|
||||
}
|
||||
|
||||
// Extended type for internal UI state with full FL Points object
|
||||
type LeaderboardDraft = Leaderboard & { flPointsData: FlPoints };
|
||||
|
||||
function toApiFormat(draft: LeaderboardDraft): Leaderboard {
|
||||
return {
|
||||
...draft,
|
||||
flPoints: draft.flPointsData.points,
|
||||
flColor: draft.flPointsData.color,
|
||||
flTextColor: draft.flPointsData.textColor
|
||||
};
|
||||
}
|
||||
|
||||
function toUiFormat(api: Leaderboard): LeaderboardDraft {
|
||||
return {
|
||||
...api,
|
||||
flPointsData: {
|
||||
points: api.flPoints,
|
||||
label: 'FL +' + api.flPoints,
|
||||
color: api.flColor,
|
||||
textColor: api.flTextColor,
|
||||
priority: 3
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isDirty(a: LeaderboardDraft, b: LeaderboardDraft) {
|
||||
return JSON.stringify(a) !== JSON.stringify(b);
|
||||
}
|
||||
|
||||
export function LeaderboardManager({ serverId, initialData }: LeaderboardManagerProps) {
|
||||
const [draft, setDraft] = useState<LeaderboardDraft>(toUiFormat(initialData));
|
||||
const [saved, setSaved] = useState<LeaderboardDraft>(toUiFormat(initialData));
|
||||
const [activeSection, setActiveSection] = useState<Section>('standings');
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const dirty = isDirty(draft, saved);
|
||||
|
||||
const handleDriversChange = (newDrivers: LeaderboardDriver[]) => {
|
||||
const oldDriverIds = new Set(draft.drivers.map((d) => d.id));
|
||||
|
||||
// Remap tracks: keep results for drivers that still exist, remove results for deleted drivers
|
||||
const newTracks = draft.tracks.map((t) => ({
|
||||
...t,
|
||||
// Filter existing results to only include drivers still in newDrivers, add DNS for new drivers
|
||||
results: [
|
||||
// Keep existing results for drivers still in the list
|
||||
...t.results.filter((r) => newDrivers.some((d) => d.id === r.driverId)),
|
||||
// Add DNS for new drivers
|
||||
...newDrivers
|
||||
.filter((d) => !oldDriverIds.has(d.id))
|
||||
.map((d) => ({ driverId: d.id, score: 'DNS' as const }))
|
||||
]
|
||||
}));
|
||||
|
||||
setDraft({ ...draft, drivers: newDrivers, tracks: newTracks });
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSubmitting(true);
|
||||
setError(null);
|
||||
try {
|
||||
const apiData = toApiFormat(draft);
|
||||
const result = await saveLeaderboardAction(serverId, apiData);
|
||||
if (result.success) {
|
||||
setSaved(draft);
|
||||
} else {
|
||||
setError(result.message ?? 'Unknown error');
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to save');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const renderSection = () => {
|
||||
switch (activeSection) {
|
||||
case 'standings':
|
||||
return <LeaderboardStandings leaderboard={toApiFormat(draft)} />;
|
||||
case 'drivers':
|
||||
return <DriversEditor drivers={draft.drivers} onChange={handleDriversChange} />;
|
||||
case 'points':
|
||||
return (
|
||||
<PointsTableEditor
|
||||
pointsTable={draft.pointsTable}
|
||||
onChange={(pointsTable) => setDraft({ ...draft, pointsTable })}
|
||||
/>
|
||||
);
|
||||
case 'fl':
|
||||
return (
|
||||
<FlPointsEditor
|
||||
flPoints={draft.flPointsData}
|
||||
onChange={(flPointsData) => setDraft({ ...draft, flPointsData })}
|
||||
/>
|
||||
);
|
||||
case 'tracks':
|
||||
return (
|
||||
<TracksEditor
|
||||
tracks={draft.tracks}
|
||||
drivers={draft.drivers}
|
||||
pointsTable={draft.pointsTable}
|
||||
onChange={(tracks) => setDraft({ ...draft, tracks })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{dirty && (
|
||||
<div className="flex items-center justify-between rounded-lg border border-yellow/30 bg-yellow-bg px-4 py-2 text-sm text-yellow">
|
||||
<span>Unsaved changes</span>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => setDraft(saved)}
|
||||
className="rounded px-2 py-1 text-xs text-yellow hover:text-primary"
|
||||
>
|
||||
Discard
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isSubmitting}
|
||||
className="rounded bg-yellow px-3 py-1 text-xs font-semibold text-base hover:opacity-90 disabled:opacity-40"
|
||||
>
|
||||
{isSubmitting ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="rounded-lg border border-red/30 bg-red-bg px-4 py-2 text-sm text-red">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{sections.map((s) => (
|
||||
<button
|
||||
key={s.id}
|
||||
onClick={() => setActiveSection(s.id)}
|
||||
className={`rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${
|
||||
activeSection === s.id
|
||||
? 'bg-blue text-white'
|
||||
: 'bg-overlay text-secondary hover:bg-border'
|
||||
}`}
|
||||
>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div>{renderSection()}</div>
|
||||
|
||||
{!dirty && (
|
||||
<div className="flex justify-end">
|
||||
<Button variant="primary" size="md" onClick={handleSave} disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Saving…' : 'Save Leaderboard'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
112
src/components/leaderboard/LeaderboardStandings.tsx
Executable file
@@ -0,0 +1,112 @@
|
||||
'use client';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { Leaderboard, StandingsRow } from '@/lib/schemas/leaderboard';
|
||||
|
||||
interface LeaderboardStandingsProps {
|
||||
leaderboard: Leaderboard;
|
||||
}
|
||||
|
||||
export function LeaderboardStandings({ leaderboard }: LeaderboardStandingsProps) {
|
||||
const standings = useMemo<StandingsRow[]>(() => {
|
||||
return leaderboard.drivers
|
||||
.map((driver) => {
|
||||
const trackResults = leaderboard.tracks.map(
|
||||
(t) => t.results.find((r) => r.driverId === driver.id)?.score ?? 'DNS'
|
||||
);
|
||||
const fastestLapCount = leaderboard.tracks.filter(
|
||||
(t) => t.fastestLapDriverId === driver.id
|
||||
).length;
|
||||
const totalPoints =
|
||||
trackResults.reduce((sum: number, r) => sum + (typeof r === 'number' ? r : 0), 0) +
|
||||
fastestLapCount * leaderboard.flPoints;
|
||||
return { driver, driverId: driver.id, totalPoints, trackResults, fastestLapCount };
|
||||
})
|
||||
.sort((a, b) => b.totalPoints - a.totalPoints);
|
||||
}, [leaderboard]);
|
||||
|
||||
if (leaderboard.drivers.length === 0) {
|
||||
return (
|
||||
<div className="py-12 text-center">
|
||||
<div className="mb-2 text-4xl">🏆</div>
|
||||
<p className="text-gray-400">No drivers yet. Add drivers to see standings.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-max text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-gray-700">
|
||||
<th className="py-2 pr-4 text-left text-xs font-semibold text-gray-400">Pos</th>
|
||||
<th className="py-2 pr-4 text-left text-xs font-semibold text-gray-400">Driver</th>
|
||||
{leaderboard.tracks.map((track, i) => (
|
||||
<th
|
||||
key={i}
|
||||
className="px-2 py-2 text-center text-xs font-semibold text-gray-400"
|
||||
title={track.name}
|
||||
>
|
||||
{track.name}
|
||||
</th>
|
||||
))}
|
||||
<th className="px-2 py-2 text-center text-xs font-semibold text-gray-400">FL</th>
|
||||
<th className="px-2 py-2 text-center text-xs font-semibold text-yellow-400">Pts</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{standings.map((row, pos) => (
|
||||
<tr key={row.driver.id} className="border-b border-gray-700/50">
|
||||
<td className="py-2 pr-4 text-gray-400">{pos + 1}</td>
|
||||
<td className="py-2 pr-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className="h-3 w-3 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: row.driver.color }}
|
||||
/>
|
||||
<span className="font-medium text-white">{row.driver.name}</span>
|
||||
<span className="text-xs text-gray-500">{row.driver.initials}</span>
|
||||
</div>
|
||||
</td>
|
||||
{row.trackResults.map((result, ti) => {
|
||||
const track = leaderboard.tracks[ti];
|
||||
const isFl = track.fastestLapDriverId === row.driver.id;
|
||||
return (
|
||||
<td key={ti} className="px-2 py-2 text-center">
|
||||
<span
|
||||
className={`inline-block rounded px-1.5 py-0.5 text-xs font-semibold ${
|
||||
typeof result === 'number'
|
||||
? 'text-white'
|
||||
: result === 'DNF'
|
||||
? 'text-orange-400'
|
||||
: 'text-gray-500'
|
||||
}`}
|
||||
>
|
||||
{result}
|
||||
{isFl && (
|
||||
<span
|
||||
className="ml-0.5 rounded px-0.5 text-xs"
|
||||
style={{
|
||||
backgroundColor: leaderboard.flColor,
|
||||
color: leaderboard.flTextColor
|
||||
}}
|
||||
title="Fastest lap"
|
||||
>
|
||||
FL
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
<td className="px-2 py-2 text-center text-xs text-purple-400">
|
||||
{row.fastestLapCount > 0 ? `×${row.fastestLapCount}` : '—'}
|
||||
</td>
|
||||
<td className="px-2 py-2 text-center font-bold text-yellow-400">{row.totalPoints}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
126
src/components/leaderboard/editors/DriversEditor.tsx
Executable file
@@ -0,0 +1,126 @@
|
||||
'use client';
|
||||
|
||||
import { LeaderboardDriver } from '@/lib/schemas/leaderboard';
|
||||
|
||||
function randomColor(): string {
|
||||
return '#' + Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0');
|
||||
}
|
||||
|
||||
interface DriversEditorProps {
|
||||
drivers: LeaderboardDriver[];
|
||||
onChange: (drivers: LeaderboardDriver[]) => void;
|
||||
}
|
||||
|
||||
export function DriversEditor({ drivers, onChange }: DriversEditorProps) {
|
||||
const update = (index: number, patch: Partial<LeaderboardDriver>) => {
|
||||
const next = drivers.map((d, i) => (i === index ? { ...d, ...patch } : d));
|
||||
onChange(next);
|
||||
};
|
||||
|
||||
const moveUp = (index: number) => {
|
||||
if (index === 0) return;
|
||||
const next = [...drivers];
|
||||
[next[index - 1], next[index]] = [next[index], next[index - 1]];
|
||||
onChange(next);
|
||||
};
|
||||
|
||||
const moveDown = (index: number) => {
|
||||
if (index === drivers.length - 1) return;
|
||||
const next = [...drivers];
|
||||
[next[index], next[index + 1]] = [next[index + 1], next[index]];
|
||||
onChange(next);
|
||||
};
|
||||
|
||||
const remove = (index: number) => {
|
||||
onChange(drivers.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
const add = () => {
|
||||
onChange([...drivers, { id: crypto.randomUUID(), name: 'New Driver', initials: 'ND', color: randomColor() }]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{drivers.map((driver, i) => (
|
||||
<div key={driver.id} className="flex items-center gap-3 rounded-lg bg-gray-700 p-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<button
|
||||
onClick={() => moveUp(i)}
|
||||
disabled={i === 0}
|
||||
className="rounded px-1 py-0.5 text-xs text-gray-400 hover:text-white disabled:opacity-30"
|
||||
title="Move up"
|
||||
>
|
||||
▲
|
||||
</button>
|
||||
<button
|
||||
onClick={() => moveDown(i)}
|
||||
disabled={i === drivers.length - 1}
|
||||
className="rounded px-1 py-0.5 text-xs text-gray-400 hover:text-white disabled:opacity-30"
|
||||
title="Move down"
|
||||
>
|
||||
▼
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 flex-wrap gap-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Name</label>
|
||||
<input
|
||||
type="text"
|
||||
value={driver.name}
|
||||
onChange={(e) => update(i, { name: e.target.value })}
|
||||
className="rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Initials</label>
|
||||
<input
|
||||
type="text"
|
||||
value={driver.initials}
|
||||
maxLength={10}
|
||||
onChange={(e) => update(i, { initials: e.target.value })}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={driver.color}
|
||||
onChange={(e) => update(i, { color: e.target.value })}
|
||||
className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={driver.color}
|
||||
onChange={(e) => {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) {
|
||||
update(i, { color: e.target.value });
|
||||
}
|
||||
}}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => remove(i)}
|
||||
className="rounded px-2 py-1 text-sm text-red-400 hover:bg-red-900/30 hover:text-red-300"
|
||||
title="Remove driver"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<button
|
||||
onClick={add}
|
||||
className="w-full rounded-lg border border-dashed border-gray-600 py-2 text-sm text-gray-400 hover:border-gray-400 hover:text-gray-300"
|
||||
>
|
||||
+ Add Driver
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
98
src/components/leaderboard/editors/FlPointsEditor.tsx
Executable file
@@ -0,0 +1,98 @@
|
||||
'use client';
|
||||
|
||||
import { FlPoints } from '@/lib/schemas/leaderboard';
|
||||
|
||||
interface FlPointsEditorProps {
|
||||
flPoints: FlPoints;
|
||||
onChange: (flPoints: FlPoints) => void;
|
||||
}
|
||||
|
||||
export function FlPointsEditor({ flPoints, onChange }: FlPointsEditorProps) {
|
||||
const update = (patch: Partial<FlPoints>) => onChange({ ...flPoints, ...patch });
|
||||
|
||||
return (
|
||||
<div className="rounded-lg bg-gray-700 p-4">
|
||||
<p className="mb-4 text-sm text-gray-400">
|
||||
Points awarded to the driver who sets the fastest lap in each race.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Label</label>
|
||||
<input
|
||||
type="text"
|
||||
value={flPoints.label}
|
||||
onChange={(e) => update({ label: e.target.value })}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Points</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={flPoints.points}
|
||||
onChange={(e) => update({ points: parseInt(e.target.value) || 0 })}
|
||||
className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Priority</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={flPoints.priority}
|
||||
onChange={(e) => update({ priority: parseInt(e.target.value) || 0 })}
|
||||
className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Bg Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={flPoints.color}
|
||||
onChange={(e) => update({ color: e.target.value })}
|
||||
className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={flPoints.color}
|
||||
onChange={(e) => {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) update({ color: e.target.value });
|
||||
}}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Text Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={flPoints.textColor}
|
||||
onChange={(e) => update({ textColor: e.target.value })}
|
||||
className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={flPoints.textColor}
|
||||
onChange={(e) => {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) update({ textColor: e.target.value });
|
||||
}}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Preview</label>
|
||||
<span
|
||||
className="rounded px-2 py-1 text-sm font-semibold"
|
||||
style={{ backgroundColor: flPoints.color, color: flPoints.textColor }}
|
||||
>
|
||||
{flPoints.label}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
129
src/components/leaderboard/editors/PointsTableEditor.tsx
Executable file
@@ -0,0 +1,129 @@
|
||||
'use client';
|
||||
|
||||
import { PointsEntry } from '@/lib/schemas/leaderboard';
|
||||
|
||||
interface PointsTableEditorProps {
|
||||
pointsTable: PointsEntry[];
|
||||
onChange: (pointsTable: PointsEntry[]) => void;
|
||||
}
|
||||
|
||||
export function PointsTableEditor({ pointsTable, onChange }: PointsTableEditorProps) {
|
||||
const update = (index: number, patch: Partial<PointsEntry>) => {
|
||||
onChange(pointsTable.map((e, i) => (i === index ? { ...e, ...patch } : e)));
|
||||
};
|
||||
|
||||
const remove = (index: number) => {
|
||||
onChange(pointsTable.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
const add = () => {
|
||||
const pos = pointsTable.length + 1;
|
||||
onChange([
|
||||
...pointsTable,
|
||||
{ id: crypto.randomUUID(), points: 0, label: `P${pos}`, color: '#374151', textColor: '#ffffff', priority: pos }
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{pointsTable.map((entry, i) => (
|
||||
<div key={i} className="flex items-center gap-3 rounded-lg bg-gray-700 p-3">
|
||||
<div className="flex flex-1 flex-wrap gap-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Label</label>
|
||||
<input
|
||||
type="text"
|
||||
value={entry.label}
|
||||
onChange={(e) => update(i, { label: e.target.value })}
|
||||
className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Points</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={entry.points}
|
||||
onChange={(e) => update(i, { points: parseInt(e.target.value) || 0 })}
|
||||
className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Priority</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={entry.priority}
|
||||
onChange={(e) => update(i, { priority: parseInt(e.target.value) || 0 })}
|
||||
className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Bg Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={entry.color}
|
||||
onChange={(e) => update(i, { color: e.target.value })}
|
||||
className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={entry.color}
|
||||
onChange={(e) => {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) update(i, { color: e.target.value });
|
||||
}}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Text Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={entry.textColor}
|
||||
onChange={(e) => update(i, { textColor: e.target.value })}
|
||||
className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={entry.textColor}
|
||||
onChange={(e) => {
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(e.target.value))
|
||||
update(i, { textColor: e.target.value });
|
||||
}}
|
||||
className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<label className="text-xs text-gray-400">Preview</label>
|
||||
<span
|
||||
className="rounded px-2 py-1 text-sm font-semibold"
|
||||
style={{ backgroundColor: entry.color, color: entry.textColor }}
|
||||
>
|
||||
{entry.label}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => remove(i)}
|
||||
className="rounded px-2 py-1 text-sm text-red-400 hover:bg-red-900/30 hover:text-red-300"
|
||||
title="Remove entry"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<button
|
||||
onClick={add}
|
||||
className="w-full rounded-lg border border-dashed border-gray-600 py-2 text-sm text-gray-400 hover:border-gray-400 hover:text-gray-300"
|
||||
>
|
||||
+ Add Position
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
154
src/components/leaderboard/editors/TracksEditor.tsx
Executable file
@@ -0,0 +1,154 @@
|
||||
'use client';
|
||||
|
||||
import { LeaderboardDriver, LeaderboardTrack, PointsEntry, ResultValue } from '@/lib/schemas/leaderboard';
|
||||
|
||||
interface ResultInputProps {
|
||||
value: ResultValue;
|
||||
pointsTable: PointsEntry[];
|
||||
onChange: (value: ResultValue) => void;
|
||||
}
|
||||
|
||||
function ResultInput({ value, pointsTable, onChange }: ResultInputProps) {
|
||||
const knownPoints = Array.from(new Set(pointsTable.map((e) => e.points))).sort((a, b) => b - a);
|
||||
// Fallback 0 to DNS if 0 is not a valid points option
|
||||
const displayValue = value === 0 && !knownPoints.includes(0) ? 'DNS' : value;
|
||||
// Ensure the current numeric value is always included in options
|
||||
const allPoints = typeof displayValue === 'number'
|
||||
? Array.from(new Set([...knownPoints, displayValue])).sort((a, b) => b - a)
|
||||
: knownPoints;
|
||||
|
||||
const handleChange = (raw: string) => {
|
||||
if (raw === 'DNF') return onChange('DNF');
|
||||
if (raw === 'DNS') return onChange('DNS');
|
||||
const parsed = parseInt(raw);
|
||||
onChange(isNaN(parsed) ? 0 : parsed);
|
||||
};
|
||||
|
||||
return (
|
||||
<select
|
||||
value={String(displayValue)}
|
||||
onChange={(e) => handleChange(e.target.value)}
|
||||
className="w-full rounded bg-gray-600 px-1 py-1 text-xs text-white"
|
||||
>
|
||||
{allPoints.map((p) => (
|
||||
<option key={p} value={String(p)}>
|
||||
{p}
|
||||
</option>
|
||||
))}
|
||||
<option value="DNF">DNF</option>
|
||||
<option value="DNS">DNS</option>
|
||||
</select>
|
||||
);
|
||||
}
|
||||
|
||||
interface TracksEditorProps {
|
||||
tracks: LeaderboardTrack[];
|
||||
drivers: LeaderboardDriver[];
|
||||
pointsTable: PointsEntry[];
|
||||
onChange: (tracks: LeaderboardTrack[]) => void;
|
||||
}
|
||||
|
||||
export function TracksEditor({ tracks, drivers, pointsTable, onChange }: TracksEditorProps) {
|
||||
const updateTrack = (index: number, patch: Partial<LeaderboardTrack>) => {
|
||||
onChange(tracks.map((t, i) => (i === index ? { ...t, ...patch } : t)));
|
||||
};
|
||||
|
||||
const updateResult = (trackIndex: number, driverId: string, value: ResultValue) => {
|
||||
const newResults = [...tracks[trackIndex].results];
|
||||
const existingIndex = newResults.findIndex((r) => r.driverId === driverId);
|
||||
if (existingIndex >= 0) {
|
||||
newResults[existingIndex] = { driverId, score: value };
|
||||
} else {
|
||||
newResults.push({ driverId, score: value });
|
||||
}
|
||||
updateTrack(trackIndex, { results: newResults });
|
||||
};
|
||||
|
||||
const removeTrack = (index: number) => {
|
||||
onChange(tracks.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
const addTrack = () => {
|
||||
onChange([
|
||||
...tracks,
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
name: `Race ${tracks.length + 1}`,
|
||||
results: drivers.map((d) => ({ driverId: d.id, score: 'DNS' as const })),
|
||||
fastestLapDriverId: null
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{tracks.map((track, ti) => (
|
||||
<div key={ti} className="rounded-lg bg-gray-700 p-4">
|
||||
<div className="mb-3 flex items-center gap-3">
|
||||
<input
|
||||
type="text"
|
||||
value={track.name}
|
||||
onChange={(e) => updateTrack(ti, { name: e.target.value })}
|
||||
className="flex-1 rounded bg-gray-600 px-2 py-1 text-sm font-semibold text-white"
|
||||
placeholder="Track name"
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<label className="text-xs text-gray-400">FL Driver:</label>
|
||||
<select
|
||||
value={track.fastestLapDriverId ?? ''}
|
||||
onChange={(e) => updateTrack(ti, { fastestLapDriverId: e.target.value || null })}
|
||||
className="rounded bg-gray-600 px-2 py-1 text-sm text-white"
|
||||
>
|
||||
<option value="">—</option>
|
||||
{drivers.map((d) => (
|
||||
<option key={d.id} value={d.id}>
|
||||
{d.initials} ({d.name})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => removeTrack(ti)}
|
||||
className="rounded px-2 py-1 text-sm text-red-400 hover:bg-red-900/30 hover:text-red-300"
|
||||
title="Remove track"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{drivers.length === 0 ? (
|
||||
<p className="text-xs text-gray-500">Add drivers first to enter results.</p>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
{drivers.map((driver) => (
|
||||
<div key={driver.id} className="flex items-center gap-3">
|
||||
<div className="flex w-40 items-center gap-2">
|
||||
<div
|
||||
className="h-3 w-3 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: driver.color }}
|
||||
/>
|
||||
<span className="truncate text-sm text-gray-300">{driver.name}</span>
|
||||
</div>
|
||||
<div className="w-24">
|
||||
<ResultInput
|
||||
value={track.results.find((r) => r.driverId === driver.id)?.score ?? 'DNS'}
|
||||
pointsTable={pointsTable}
|
||||
onChange={(v) => updateResult(ti, driver.id, v)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
<button
|
||||
onClick={addTrack}
|
||||
className="w-full rounded-lg border border-dashed border-gray-600 py-2 text-sm text-gray-400 hover:border-gray-400 hover:text-gray-300"
|
||||
>
|
||||
+ Add Track / Race
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
37
src/components/login/LoginForm.tsx
Normal file → Executable file
@@ -2,6 +2,8 @@
|
||||
|
||||
import { clearExpiredSessionAction, loginAction, LoginResult } from '@/lib/actions/auth';
|
||||
import { use, useActionState, useEffect } from 'react';
|
||||
import type { HealthStatus } from '@/lib/api/server/health';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
|
||||
const initialState: LoginResult = {
|
||||
message: '',
|
||||
@@ -9,9 +11,11 @@ const initialState: LoginResult = {
|
||||
};
|
||||
|
||||
export default function LoginForm({
|
||||
searchParams
|
||||
searchParams,
|
||||
health
|
||||
}: {
|
||||
searchParams: Promise<{ expired: boolean | undefined }>;
|
||||
health: HealthStatus;
|
||||
}) {
|
||||
const params = use(searchParams);
|
||||
const expired = params.expired;
|
||||
@@ -23,26 +27,33 @@ export default function LoginForm({
|
||||
}, [expired]);
|
||||
const [state, formAction] = useActionState(loginAction, initialState);
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-900 px-4">
|
||||
<div className="w-full max-w-md space-y-8 rounded-lg bg-gray-800 p-8 shadow-lg">
|
||||
<div className="flex min-h-screen items-center justify-center bg-base px-4">
|
||||
<div className="w-full max-w-md space-y-6 rounded-lg border border-border bg-canvas p-8 shadow-xl">
|
||||
<div className="text-center">
|
||||
<h1 className="text-3xl font-bold text-white">ACC Server Manager</h1>
|
||||
<p className="mt-2 text-gray-400">Sign in to manage your servers</p>
|
||||
<h1 className="text-xl font-bold text-primary">ACC Server Manager</h1>
|
||||
<p className="mt-1 text-sm text-muted">Sign in to manage your servers</p>
|
||||
<div className="mt-2 flex justify-center">
|
||||
{health.healthy ? (
|
||||
<Badge variant="green">API v{health.version}</Badge>
|
||||
) : (
|
||||
<Badge variant="red">API unreachable</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{expired && (
|
||||
<div className="rounded-md border border-yellow-700 bg-yellow-900/50 p-3 text-sm text-yellow-200">
|
||||
<div className="rounded-md border border-yellow/30 bg-yellow-bg px-3 py-2 text-sm text-yellow">
|
||||
Your session has expired. Please sign in again.
|
||||
</div>
|
||||
)}
|
||||
{state?.success ? null : (
|
||||
<div className="rounded-md border border-red-700 bg-red-900/50 p-3 text-sm text-red-200">
|
||||
<div className="rounded-md border border-red/30 bg-red-bg px-3 py-2 text-sm text-red">
|
||||
{state?.message}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form action={formAction} className="space-y-6">
|
||||
<form action={formAction} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="username" className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label htmlFor="username" className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Username
|
||||
</label>
|
||||
<input
|
||||
@@ -51,12 +62,12 @@ export default function LoginForm({
|
||||
type="text"
|
||||
autoComplete="username"
|
||||
required
|
||||
className="form-input w-full"
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="password" className="mb-2 block text-sm font-medium text-gray-300">
|
||||
<label htmlFor="password" className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Password
|
||||
</label>
|
||||
<input
|
||||
@@ -65,13 +76,13 @@ export default function LoginForm({
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
className="form-input w-full"
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full rounded-md bg-blue-600 px-4 py-3 font-medium text-white transition-colors hover:bg-blue-700 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-800 focus:outline-none"
|
||||
className="w-full rounded-md bg-btn-green border border-btn-green px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-btn-green-hover focus:outline-none focus:ring-2 focus:ring-blue focus:ring-offset-2 focus:ring-offset-base"
|
||||
>
|
||||
Sign in
|
||||
</button>
|
||||
|
||||
51
src/components/membership/CreateUserModal.tsx
Normal file → Executable file
@@ -3,6 +3,7 @@
|
||||
import { useState } from 'react';
|
||||
import type { Role } from '@/lib/schemas';
|
||||
import { createUserAction } from '@/lib/actions/membership';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface CreateUserModalProps {
|
||||
roles: Role[];
|
||||
@@ -44,17 +45,22 @@ export function CreateUserModal({ roles, onClose }: CreateUserModalProps) {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-opacity-50 fixed inset-0 z-50 flex items-center justify-center bg-black">
|
||||
<div className="w-full max-w-md rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-semibold text-white">Create New User</h3>
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||
<div className="w-full max-w-md rounded-lg border border-border bg-canvas p-6 shadow-xl">
|
||||
<h2 className="mb-4 text-base font-semibold text-primary">Create New User</h2>
|
||||
|
||||
{error && (
|
||||
<div className="mb-4 rounded-md bg-red-900 p-3 text-sm text-red-300">{error}</div>
|
||||
<div className="mb-4 rounded-md border border-red/20 bg-red-bg p-3 text-sm text-red">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="mb-4">
|
||||
<label htmlFor="create-username" className="block text-sm font-medium text-gray-300">
|
||||
<label
|
||||
htmlFor="create-username"
|
||||
className="mb-1.5 block text-sm font-medium text-secondary"
|
||||
>
|
||||
Username
|
||||
</label>
|
||||
<input
|
||||
@@ -64,12 +70,15 @@ export function CreateUserModal({ roles, onClose }: CreateUserModalProps) {
|
||||
onChange={(e) => setFormData((prev) => ({ ...prev, username: e.target.value }))}
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none disabled:opacity-50"
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label htmlFor="create-password" className="block text-sm font-medium text-gray-300">
|
||||
<label
|
||||
htmlFor="create-password"
|
||||
className="mb-1.5 block text-sm font-medium text-secondary"
|
||||
>
|
||||
Password
|
||||
</label>
|
||||
<input
|
||||
@@ -79,12 +88,15 @@ export function CreateUserModal({ roles, onClose }: CreateUserModalProps) {
|
||||
onChange={(e) => setFormData((prev) => ({ ...prev, password: e.target.value }))}
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none disabled:opacity-50"
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<label htmlFor="create-role" className="block text-sm font-medium text-gray-300">
|
||||
<label
|
||||
htmlFor="create-role"
|
||||
className="mb-1.5 block text-sm font-medium text-secondary"
|
||||
>
|
||||
Role
|
||||
</label>
|
||||
<select
|
||||
@@ -93,7 +105,7 @@ export function CreateUserModal({ roles, onClose }: CreateUserModalProps) {
|
||||
onChange={(e) => setFormData((prev) => ({ ...prev, role: e.target.value }))}
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none disabled:opacity-50"
|
||||
className="form-input"
|
||||
>
|
||||
<option value="">Select a role...</option>
|
||||
{roles.map((role) => (
|
||||
@@ -104,22 +116,13 @@ export function CreateUserModal({ roles, onClose }: CreateUserModalProps) {
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-gray-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" onClick={onClose} disabled={isSubmitting}>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-green-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-green-700 disabled:opacity-50"
|
||||
>
|
||||
</Button>
|
||||
<Button type="submit" variant="primary" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Creating...' : 'Create User'}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
32
src/components/membership/DeleteUserModal.tsx
Normal file → Executable file
@@ -3,6 +3,7 @@
|
||||
import { useState } from 'react';
|
||||
import type { User } from '@/lib/schemas';
|
||||
import { deleteUserAction } from '@/lib/actions/membership';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface DeleteUserModalProps {
|
||||
user: User;
|
||||
@@ -37,36 +38,29 @@ export function DeleteUserModal({ user, onClose }: DeleteUserModalProps) {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-opacity-50 fixed inset-0 z-50 flex items-center justify-center bg-black">
|
||||
<div className="w-full max-w-md rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-semibold text-white">Delete User</h3>
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||
<div className="w-full max-w-md rounded-lg border border-border bg-canvas p-6 shadow-xl">
|
||||
<h2 className="mb-4 text-base font-semibold text-primary">Delete User</h2>
|
||||
|
||||
{error && (
|
||||
<div className="mb-4 rounded-md bg-red-900 p-3 text-sm text-red-300">{error}</div>
|
||||
<div className="mb-4 rounded-md border border-red/20 bg-red-bg p-3 text-sm text-red">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<p className="mb-6 text-gray-300">
|
||||
<p className="mb-6 text-sm text-secondary">
|
||||
Are you sure you want to delete the user "{user.username}"? This action cannot
|
||||
be undone.
|
||||
</p>
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="flex justify-end space-x-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-gray-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" onClick={onClose} disabled={isSubmitting}>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-red-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-red-700 disabled:opacity-50"
|
||||
>
|
||||
</Button>
|
||||
<Button type="submit" variant="danger-solid" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Deleting...' : 'Delete User'}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
267
src/components/membership/UserManagementTable.tsx
Normal file → Executable file
@@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import type { Role, User } from '@/lib/schemas';
|
||||
import { hasPermission } from '@/lib/schemas/user';
|
||||
import { CreateUserModal } from './CreateUserModal';
|
||||
import { DeleteUserModal } from './DeleteUserModal';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface UserManagementTableProps {
|
||||
initialData: User[];
|
||||
@@ -55,7 +55,7 @@ export function UserManagementTable({ initialData, roles, currentUser }: UserMan
|
||||
};
|
||||
|
||||
const getSortIcon = (field: string) => {
|
||||
if (sortBy !== field) return '↕️';
|
||||
if (sortBy !== field) return '↕';
|
||||
return sortDesc ? '↓' : '↑';
|
||||
};
|
||||
|
||||
@@ -79,163 +79,134 @@ export function UserManagementTable({ initialData, roles, currentUser }: UserMan
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="bg-gray-800 shadow-md">
|
||||
<div className="mx-auto flex max-w-[120rem] items-center justify-between px-4 py-4 sm:px-6 lg:px-8">
|
||||
<div className="flex items-center space-x-4">
|
||||
<Link href="/dashboard" className="text-gray-300 hover:text-white">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M10 19l-7-7m0 0l7-7m-7 7h18"
|
||||
/>
|
||||
</svg>
|
||||
</Link>
|
||||
<h1 className="text-2xl font-bold">User Management</h1>
|
||||
</div>
|
||||
{hasPermission(currentUser, 'membership.create') && (
|
||||
<button
|
||||
onClick={openCreateModal}
|
||||
className="rounded-md bg-green-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-green-700"
|
||||
>
|
||||
Create User
|
||||
</button>
|
||||
)}
|
||||
<header className="flex h-12 items-center justify-between border-b border-border-muted px-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm font-semibold text-primary">User Management</span>
|
||||
</div>
|
||||
{hasPermission(currentUser, 'membership.create') && (
|
||||
<Button variant="primary" size="sm" onClick={openCreateModal}>
|
||||
+ Create User
|
||||
</Button>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<main className="mx-auto max-w-[120rem] px-4 py-8 sm:px-6 lg:px-8">
|
||||
{/* Filters */}
|
||||
<div className="mb-6 rounded-lg border border-gray-700 bg-gray-800 p-4">
|
||||
<h2 className="mb-3 text-lg font-semibold">Filters</h2>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div>
|
||||
<label htmlFor="username" className="block text-sm font-medium text-gray-300">
|
||||
Username
|
||||
</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
value={usernameFilter}
|
||||
onChange={(e) => setUsernameFilter(e.target.value)}
|
||||
placeholder="Search by username..."
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white placeholder-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="role" className="block text-sm font-medium text-gray-300">
|
||||
Role
|
||||
</label>
|
||||
<input
|
||||
id="role"
|
||||
type="text"
|
||||
value={roleNameFilter}
|
||||
onChange={(e) => setRoleNameFilter(e.target.value)}
|
||||
placeholder="Filter by role..."
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white placeholder-gray-400 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
<div className="mx-5 mt-4 rounded-lg border border-border bg-canvas p-4">
|
||||
<div className="mb-3 text-sm font-semibold text-primary">Filters</div>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div>
|
||||
<label htmlFor="username" className="mb-1 block text-xs font-medium text-muted">
|
||||
Username
|
||||
</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
value={usernameFilter}
|
||||
onChange={(e) => setUsernameFilter(e.target.value)}
|
||||
placeholder="Search by username..."
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4 flex space-x-2">
|
||||
<button
|
||||
onClick={applyFilters}
|
||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-blue-700"
|
||||
>
|
||||
Apply Filters
|
||||
</button>
|
||||
<button
|
||||
onClick={resetFilters}
|
||||
className="rounded-md bg-gray-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-gray-700"
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
<div>
|
||||
<label htmlFor="role" className="mb-1 block text-xs font-medium text-muted">
|
||||
Role
|
||||
</label>
|
||||
<input
|
||||
id="role"
|
||||
type="text"
|
||||
value={roleNameFilter}
|
||||
onChange={(e) => setRoleNameFilter(e.target.value)}
|
||||
placeholder="Filter by role..."
|
||||
className="form-input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<Button variant="primary" size="sm" onClick={applyFilters}>
|
||||
Apply
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={resetFilters}>
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Results Summary */}
|
||||
<div className="mb-4 text-sm text-gray-400">Showing {initialData.length} users</div>
|
||||
<div className="mx-5 mt-3 text-xs text-muted">Showing {initialData.length} users</div>
|
||||
|
||||
{/* Users Table */}
|
||||
<div className="overflow-hidden rounded-lg border border-gray-700 bg-gray-800">
|
||||
<table className="min-w-full divide-y divide-gray-700">
|
||||
<thead className="bg-gray-900">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left">
|
||||
<button
|
||||
className="flex items-center space-x-1 text-xs font-medium tracking-wider text-gray-400 uppercase transition-colors hover:text-white"
|
||||
onClick={() => handleSort('username')}
|
||||
>
|
||||
<span>Username</span>
|
||||
<span>{getSortIcon('username')}</span>
|
||||
</button>
|
||||
<div className="mx-5 mt-2 mb-5 overflow-hidden rounded-lg border border-border bg-canvas">
|
||||
<table className="min-w-full">
|
||||
<thead>
|
||||
<tr className="border-b border-border-muted bg-base">
|
||||
<th className="px-4 py-2 text-left">
|
||||
<button
|
||||
onClick={() => handleSort('username')}
|
||||
className="flex items-center gap-1 text-xs font-medium uppercase tracking-wider text-subtle hover:text-primary"
|
||||
>
|
||||
Username <span>{getSortIcon('username')}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th className="px-4 py-2 text-left">
|
||||
<button
|
||||
onClick={() => handleSort('role')}
|
||||
className="flex items-center gap-1 text-xs font-medium uppercase tracking-wider text-subtle hover:text-primary"
|
||||
>
|
||||
Role <span>{getSortIcon('role')}</span>
|
||||
</button>
|
||||
</th>
|
||||
{hasPermission(currentUser, 'membership.edit') && (
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Actions
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left">
|
||||
<button
|
||||
className="flex items-center space-x-1 text-xs font-medium tracking-wider text-gray-400 uppercase transition-colors hover:text-white"
|
||||
onClick={() => handleSort('role')}
|
||||
>
|
||||
<span>Role</span>
|
||||
<span>{getSortIcon('role')}</span>
|
||||
</button>
|
||||
</th>
|
||||
{hasPermission(currentUser, 'membership.edit') && (
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
Actions
|
||||
</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-700 bg-gray-800">
|
||||
{initialData.length > 0 ? (
|
||||
initialData.map((user) => (
|
||||
<tr key={user.id} className="transition-colors hover:bg-gray-700">
|
||||
<td className="px-6 py-4 text-sm font-medium whitespace-nowrap text-white">
|
||||
{user.username}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap">
|
||||
<span className="inline-flex rounded-full bg-blue-900 px-2 py-1 text-xs font-semibold text-blue-300">
|
||||
{user.role.name}
|
||||
</span>
|
||||
</td>
|
||||
{hasPermission(currentUser, 'membership.edit') && (
|
||||
<td className="px-6 py-4 text-sm font-medium whitespace-nowrap">
|
||||
<div className="flex space-x-2">
|
||||
<button className="text-blue-400 transition-colors hover:text-blue-300">
|
||||
Edit
|
||||
</button>
|
||||
{hasPermission(currentUser, 'membership.delete') && (
|
||||
<button
|
||||
onClick={() => openDeleteModal(user)}
|
||||
className="text-red-400 transition-colors hover:text-red-300"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={3} className="px-6 py-4 text-center text-sm text-gray-400">
|
||||
No users found
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{initialData.length > 0 ? (
|
||||
initialData.map((user) => (
|
||||
<tr
|
||||
key={user.id}
|
||||
className="border-b border-border-muted transition-colors hover:bg-hover last:border-0"
|
||||
>
|
||||
<td className="px-4 py-3 text-sm font-medium text-primary">
|
||||
{user.username}
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<span className="inline-flex rounded-full border border-blue/20 bg-blue-bg px-2 py-0.5 text-xs font-medium text-blue">
|
||||
{user.role.name}
|
||||
</span>
|
||||
</td>
|
||||
{hasPermission(currentUser, 'membership.edit') && (
|
||||
<td className="px-4 py-3">
|
||||
<div className="flex gap-3">
|
||||
<button className="text-xs text-blue hover:underline">
|
||||
Edit
|
||||
</button>
|
||||
{hasPermission(currentUser, 'membership.delete') && (
|
||||
<button
|
||||
onClick={() => openDeleteModal(user)}
|
||||
className="text-xs text-red hover:underline"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={hasPermission(currentUser, 'membership.edit') ? 3 : 2}
|
||||
className="px-4 py-8 text-center text-sm text-muted"
|
||||
>
|
||||
No users found
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Modals */}
|
||||
{showCreateModal && <CreateUserModal roles={roles} onClose={closeCreateModal} />}
|
||||
|
||||
{showDeleteModal && selectedUser && (
|
||||
|
||||
0
src/components/providers/QueryProvider.tsx
Normal file → Executable file
23
src/components/server/CreateServerModal.tsx
Normal file → Executable file
@@ -3,6 +3,7 @@
|
||||
import { useState, useEffect, useActionState, useTransition } from 'react';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { LoadingSpinner } from '@/components/ui/LoadingSpinner';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { createServerAction, type ServerActionResult } from '@/lib/actions/server-management';
|
||||
import { useServerCreationPopup } from '@/lib/context/ServerCreationPopupContext';
|
||||
|
||||
@@ -58,12 +59,12 @@ export function CreateServerModal({ isOpen, onClose }: CreateServerModalProps) {
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={handleClose} title="Create New Server">
|
||||
{!state.success && state.message && (
|
||||
<div className="mb-4 rounded-md bg-red-900 p-3 text-sm text-red-300">{state.message}</div>
|
||||
<div className="mb-4 rounded-md border border-red/20 bg-red-bg p-3 text-sm text-red">{state.message}</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="mb-6">
|
||||
<label htmlFor="server-name" className="block text-sm font-medium text-gray-300">
|
||||
<label htmlFor="server-name" className="mb-1.5 block text-sm font-medium text-secondary">
|
||||
Server Name
|
||||
</label>
|
||||
<input
|
||||
@@ -73,34 +74,36 @@ export function CreateServerModal({ isOpen, onClose }: CreateServerModalProps) {
|
||||
onChange={(e) => setServerName(e.target.value)}
|
||||
required
|
||||
disabled={isSubmitting || isPending}
|
||||
className="mt-1 block w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-white focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none disabled:opacity-50"
|
||||
className="form-input"
|
||||
placeholder="Enter server name..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-2">
|
||||
<button
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="md"
|
||||
onClick={handleClose}
|
||||
disabled={isSubmitting || isPending}
|
||||
className="rounded-md bg-gray-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size="md"
|
||||
disabled={isSubmitting || !serverName.trim() || isPending}
|
||||
className="flex items-center rounded-md bg-green-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-green-700 disabled:opacity-50"
|
||||
>
|
||||
{isSubmitting ? (
|
||||
<>
|
||||
<LoadingSpinner className="mr-2 h-4 w-4" />
|
||||
<LoadingSpinner size="sm" />
|
||||
Creating...
|
||||
</>
|
||||
) : (
|
||||
'Create Server'
|
||||
)}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
23
src/components/server/DeleteServerModal.tsx
Normal file → Executable file
@@ -3,6 +3,7 @@
|
||||
import { useState, useTransition } from 'react';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { LoadingSpinner } from '@/components/ui/LoadingSpinner';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { deleteServerAction } from '@/lib/actions/server-management';
|
||||
import { Server } from '@/lib/schemas/server';
|
||||
|
||||
@@ -42,37 +43,39 @@ export function DeleteServerModal({ isOpen, onClose, server }: DeleteServerModal
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={handleClose} title="Delete Server">
|
||||
{error && <div className="mb-4 rounded-md bg-red-900 p-3 text-sm text-red-300">{error}</div>}
|
||||
{error && <div className="mb-4 rounded-md border border-red/20 bg-red-bg p-3 text-sm text-red">{error}</div>}
|
||||
|
||||
<div className="mb-6">
|
||||
<p className="text-gray-300">
|
||||
<p className="text-secondary">
|
||||
Are you sure you want to delete the server <strong>"{server.name}"</strong>?
|
||||
</p>
|
||||
<p className="mt-2 text-sm text-gray-400">This action cannot be undone.</p>
|
||||
<p className="mt-2 text-sm text-muted">This action cannot be undone.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-2">
|
||||
<button
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="md"
|
||||
onClick={handleClose}
|
||||
disabled={isPending}
|
||||
className="rounded-md bg-gray-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
</Button>
|
||||
<Button
|
||||
variant="danger-solid"
|
||||
size="md"
|
||||
onClick={handleDelete}
|
||||
disabled={isPending}
|
||||
className="flex items-center rounded-md bg-red-600 px-4 py-2 text-sm font-medium transition-colors hover:bg-red-700 disabled:opacity-50"
|
||||
>
|
||||
{isPending ? (
|
||||
<>
|
||||
<LoadingSpinner size="sm" className="mr-2" />
|
||||
<LoadingSpinner size="sm" />
|
||||
Deleting...
|
||||
</>
|
||||
) : (
|
||||
'Delete Server'
|
||||
)}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
138
src/components/server/ServerCard.tsx
Normal file → Executable file
@@ -1,17 +1,31 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { useTransition } from 'react';
|
||||
import { Server, ServiceStatus, getStatusColor, serviceStatusToString } from '@/lib/schemas';
|
||||
import { Server, ServiceStatus, serviceStatusToString } from '@/lib/schemas';
|
||||
import {
|
||||
startServerEventAction,
|
||||
restartServerEventAction,
|
||||
stopServerEventAction
|
||||
} from '@/lib/actions/servers';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { StatusDot } from '@/components/ui/StatusDot';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface ServerCardProps {
|
||||
server: Server;
|
||||
}
|
||||
|
||||
function statusBadgeVariant(status: ServiceStatus): 'green' | 'yellow' | 'gray' {
|
||||
if (status === ServiceStatus.Running) return 'green';
|
||||
if (
|
||||
[ServiceStatus.Starting, ServiceStatus.Restarting, ServiceStatus.Stopping].includes(status)
|
||||
)
|
||||
return 'yellow';
|
||||
return 'gray';
|
||||
}
|
||||
|
||||
export function ServerCard({ server }: ServerCardProps) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
@@ -36,82 +50,66 @@ export function ServerCard({ server }: ServerCardProps) {
|
||||
ServiceStatus.Restarting,
|
||||
ServiceStatus.Starting,
|
||||
ServiceStatus.Stopping,
|
||||
ServiceStatus.Unknown
|
||||
ServiceStatus.Unknown,
|
||||
].includes(server.status);
|
||||
const isRunning = server.status === ServiceStatus.Running;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="overflow-hidden rounded-lg border border-gray-700 bg-gray-800 shadow-lg">
|
||||
<Link href={`/dashboard/server/${server.id}`} className="block">
|
||||
<div className="p-6">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<h3 className="text-lg font-medium text-white">{server.name}</h3>
|
||||
<div className="mt-2 flex items-center">
|
||||
<span
|
||||
className={`inline-block h-2 w-2 rounded-full ${getStatusColor(server.status)} mr-2`}
|
||||
/>
|
||||
<span className="text-sm text-gray-300 capitalize">
|
||||
{serviceStatusToString(server.status)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className="text-gray-400 hover:text-white">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-5 w-5"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="overflow-hidden rounded-lg border border-border bg-canvas transition-colors hover:border-blue/40">
|
||||
<Link href={`/dashboard/server/${server.id}`} className="block p-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<span className="text-sm font-semibold text-primary">{server.name}</span>
|
||||
<StatusDot status={server.status} />
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid grid-cols-2 gap-4 text-sm text-gray-300">
|
||||
<div>
|
||||
<span className="text-gray-500">Track:</span>
|
||||
<span className="ml-2">{server.state?.track || 'N/A'}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-500">Players:</span>
|
||||
<span className="ml-2">{server.state?.playerCount || 0}</span>
|
||||
</div>
|
||||
<div className="mt-3 grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<div className="text-xs text-subtle">Players</div>
|
||||
<div className="text-sm font-semibold text-primary">
|
||||
{server.state?.playerCount ?? 0}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-subtle">Track</div>
|
||||
<div className="truncate text-sm font-semibold text-primary">
|
||||
{server.state?.track || 'N/A'}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<div className="flex justify-between gap-2 bg-gray-900 px-4 py-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={startServer}
|
||||
disabled={server.status === ServiceStatus.Running || isPending || disabled}
|
||||
className="rounded bg-green-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Start
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={restartServer}
|
||||
disabled={server.status === ServiceStatus.Stopped || isPending || disabled}
|
||||
className="rounded bg-yellow-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-yellow-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Restart
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={stopServer}
|
||||
disabled={server.status === ServiceStatus.Stopped || isPending || disabled}
|
||||
className="rounded bg-red-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Stop
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-3">
|
||||
<Badge variant={statusBadgeVariant(server.status)}>
|
||||
{serviceStatusToString(server.status)}
|
||||
</Badge>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<div className="flex gap-1.5 border-t border-border-muted bg-base px-4 py-2">
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={startServer}
|
||||
disabled={isRunning || disabled || isPending}
|
||||
>
|
||||
Start
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={restartServer}
|
||||
disabled={!isRunning || disabled || isPending}
|
||||
>
|
||||
Restart
|
||||
</Button>
|
||||
<Button
|
||||
variant="danger-outline"
|
||||
size="sm"
|
||||
onClick={stopServer}
|
||||
disabled={!isRunning || disabled || isPending}
|
||||
>
|
||||
Stop
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
176
src/components/server/ServerConfigurationTabs.tsx
Normal file → Executable file
@@ -7,13 +7,17 @@ import { EventConfigEditor } from '@/components/configuration/EventConfigEditor'
|
||||
import { EventRulesEditor } from '@/components/configuration/EventRulesEditor';
|
||||
import { ServerSettingsEditor } from '@/components/configuration/ServerSettingsEditor';
|
||||
import { StatisticsDashboard } from '@/components/statistics/StatisticsDashboard';
|
||||
import { LeaderboardManager } from '@/components/leaderboard/LeaderboardManager';
|
||||
import { useState } from 'react';
|
||||
import { StateHistoryStats } from '@/lib/schemas';
|
||||
import { Leaderboard } from '@/lib/schemas/leaderboard';
|
||||
import { bulkUpdateConfigurationsAction } from '@/lib/actions/configuration';
|
||||
|
||||
interface ServerConfigurationTabsProps {
|
||||
serverId: string;
|
||||
configurations: Configurations;
|
||||
statistics: StateHistoryStats;
|
||||
leaderboard: Leaderboard;
|
||||
}
|
||||
const tabs = [
|
||||
{ id: ServerTab.statistics, name: 'Statistics', icon: '📊' },
|
||||
@@ -21,35 +25,118 @@ const tabs = [
|
||||
{ id: ServerTab.assistRules, name: 'Assist Rules', icon: '🚗' },
|
||||
{ id: ServerTab.event, name: 'Event Config', icon: '🏁' },
|
||||
{ id: ServerTab.eventRules, name: 'Event Rules', icon: '📋' },
|
||||
{ id: ServerTab.settings, name: 'Server Settings', icon: '🔧' }
|
||||
{ id: ServerTab.settings, name: 'Server Settings', icon: '🔧' },
|
||||
{ id: ServerTab.leaderboard, name: 'Leaderboard', icon: '🏆' }
|
||||
];
|
||||
|
||||
const configTabs = new Set([
|
||||
ServerTab.configuration,
|
||||
ServerTab.assistRules,
|
||||
ServerTab.event,
|
||||
ServerTab.eventRules,
|
||||
ServerTab.settings
|
||||
]);
|
||||
|
||||
export function ServerConfigurationTabs({
|
||||
serverId,
|
||||
configurations,
|
||||
statistics
|
||||
statistics,
|
||||
leaderboard
|
||||
}: ServerConfigurationTabsProps) {
|
||||
const [currentTab, setCurrentTab] = useState(ServerTab.statistics);
|
||||
|
||||
const [configData, setConfigData] = useState(configurations.configuration);
|
||||
const [assistData, setAssistData] = useState(configurations.assistRules);
|
||||
const [eventData, setEventData] = useState(configurations.event);
|
||||
const [eventRulesData, setEventRulesData] = useState(configurations.eventRules);
|
||||
const [settingsData, setSettingsData] = useState(configurations.settings);
|
||||
|
||||
const [restart, setRestart] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
const [saveSuccess, setSaveSuccess] = useState(false);
|
||||
|
||||
const handleSaveAll = async () => {
|
||||
setIsSubmitting(true);
|
||||
setSaveError(null);
|
||||
setSaveSuccess(false);
|
||||
|
||||
const result = await bulkUpdateConfigurationsAction(
|
||||
serverId,
|
||||
{
|
||||
configuration: configData,
|
||||
assistRules: assistData,
|
||||
event: eventData,
|
||||
eventRules: eventRulesData,
|
||||
settings: settingsData
|
||||
},
|
||||
restart
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
setSaveSuccess(true);
|
||||
setTimeout(() => setSaveSuccess(false), 3000);
|
||||
} else {
|
||||
setSaveError(result.message);
|
||||
}
|
||||
|
||||
setIsSubmitting(false);
|
||||
};
|
||||
|
||||
const isConfigTab = configTabs.has(currentTab);
|
||||
|
||||
const renderTabContent = () => {
|
||||
switch (currentTab) {
|
||||
case ServerTab.statistics:
|
||||
return <StatisticsDashboard stats={statistics} />;
|
||||
|
||||
case ServerTab.configuration:
|
||||
return <ConfigurationEditor serverId={serverId} config={configurations.configuration} />;
|
||||
return (
|
||||
<ConfigurationEditor
|
||||
formData={configData}
|
||||
disabled={isSubmitting}
|
||||
onFormDataChange={setConfigData}
|
||||
/>
|
||||
);
|
||||
|
||||
case ServerTab.assistRules:
|
||||
return <AssistRulesEditor serverId={serverId} config={configurations.assistRules} />;
|
||||
return (
|
||||
<AssistRulesEditor
|
||||
formData={assistData}
|
||||
disabled={isSubmitting}
|
||||
onFormDataChange={setAssistData}
|
||||
/>
|
||||
);
|
||||
|
||||
case ServerTab.event:
|
||||
return <EventConfigEditor serverId={serverId} config={configurations.event} />;
|
||||
return (
|
||||
<EventConfigEditor
|
||||
formData={eventData}
|
||||
disabled={isSubmitting}
|
||||
onFormDataChange={setEventData}
|
||||
/>
|
||||
);
|
||||
|
||||
case ServerTab.eventRules:
|
||||
return <EventRulesEditor serverId={serverId} config={configurations.eventRules} />;
|
||||
return (
|
||||
<EventRulesEditor
|
||||
formData={eventRulesData}
|
||||
disabled={isSubmitting}
|
||||
onFormDataChange={setEventRulesData}
|
||||
/>
|
||||
);
|
||||
|
||||
case ServerTab.settings:
|
||||
return <ServerSettingsEditor serverId={serverId} config={configurations.settings} />;
|
||||
return (
|
||||
<ServerSettingsEditor
|
||||
formData={settingsData}
|
||||
disabled={isSubmitting}
|
||||
onFormDataChange={setSettingsData}
|
||||
/>
|
||||
);
|
||||
|
||||
case ServerTab.leaderboard:
|
||||
return <LeaderboardManager serverId={serverId} initialData={leaderboard} />;
|
||||
|
||||
default:
|
||||
return (
|
||||
@@ -63,30 +150,59 @@ export function ServerConfigurationTabs({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-lg bg-gray-800">
|
||||
<div className="border-b border-gray-700">
|
||||
<nav className="flex space-x-8 overflow-x-auto" aria-label="Tabs">
|
||||
{tabs.map((tab) => {
|
||||
const isActive = currentTab === tab.id;
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setCurrentTab(tab.id)}
|
||||
className={`flex items-center space-x-2 border-b-2 px-1 py-4 text-sm font-medium whitespace-nowrap transition-colors ${
|
||||
isActive
|
||||
? 'border-blue-500 text-blue-400'
|
||||
: 'border-transparent text-gray-400 hover:border-gray-300 hover:text-gray-300'
|
||||
} `}
|
||||
>
|
||||
<span className="text-base">{tab.icon}</span>
|
||||
<span>{tab.name}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<nav className="flex overflow-x-auto border-b border-border-muted px-5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" aria-label="Tabs">
|
||||
{tabs.map((tab) => {
|
||||
const isActive = currentTab === tab.id;
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setCurrentTab(tab.id)}
|
||||
className={`flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-3 text-sm font-medium whitespace-nowrap transition-colors ${
|
||||
isActive
|
||||
? 'border-orange text-primary'
|
||||
: 'border-transparent text-muted hover:text-primary'
|
||||
}`}
|
||||
>
|
||||
<span className="text-sm">{tab.icon}</span>
|
||||
<span>{tab.name}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<div className="p-6">{renderTabContent()}</div>
|
||||
{isConfigTab && (
|
||||
<div className="flex items-center justify-between border-b border-border-muted bg-overlay px-5 py-3">
|
||||
<div className="flex items-center gap-3">
|
||||
{saveError && (
|
||||
<p className="text-sm text-red">{saveError}</p>
|
||||
)}
|
||||
{saveSuccess && (
|
||||
<p className="text-sm text-green">All configurations saved.</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<label className="flex items-center gap-2 text-sm text-muted">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={restart}
|
||||
onChange={(e) => setRestart(e.target.checked)}
|
||||
className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue"
|
||||
/>
|
||||
Restart after saving
|
||||
</label>
|
||||
<button
|
||||
onClick={handleSaveAll}
|
||||
disabled={isSubmitting}
|
||||
className="rounded-md bg-btn-green border border-btn-green px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-btn-green-hover disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
{isSubmitting ? 'Saving…' : 'Save All'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-5">{renderTabContent()}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
10
src/components/server/ServerCreationPopup.tsx
Normal file → Executable file
@@ -78,15 +78,15 @@ export function ServerCreationPopup({
|
||||
setEntries((prev) => [...prev, newEntry]);
|
||||
}, []);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
const scrollToBottom = useCallback(() => {
|
||||
if (consoleRef.current && !isMinimized && isConsoleVisible) {
|
||||
consoleRef.current.scrollTop = consoleRef.current.scrollHeight;
|
||||
}
|
||||
};
|
||||
}, [isMinimized, isConsoleVisible]);
|
||||
|
||||
useEffect(() => {
|
||||
scrollToBottom();
|
||||
}, [entries, isMinimized, isConsoleVisible]);
|
||||
}, [entries, scrollToBottom]);
|
||||
|
||||
useEffect(() => {
|
||||
if (serverId && isOpen) {
|
||||
@@ -310,7 +310,7 @@ export function ServerCreationPopup({
|
||||
!isCompleted && Object.values(steps).some((step) => step.status === 'in_progress');
|
||||
|
||||
return (
|
||||
<div className="fixed right-4 bottom-4 z-40">
|
||||
<div className="fixed right-4 bottom-20 md:bottom-4 z-40">
|
||||
<button
|
||||
onClick={() => setIsMinimized(false)}
|
||||
className={`flex h-16 w-16 items-center justify-center rounded-full border-2 shadow-lg transition-all hover:scale-105 ${
|
||||
@@ -364,7 +364,7 @@ export function ServerCreationPopup({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed right-4 bottom-4 z-40 max-h-[600px] w-96 rounded-lg border border-gray-700 bg-gray-800 shadow-2xl select-none">
|
||||
<div className="fixed right-4 bottom-20 md:bottom-4 z-40 max-h-[600px] w-96 rounded-lg border border-gray-700 bg-gray-800 shadow-2xl select-none">
|
||||
<div className="flex items-center justify-between border-b border-gray-700 p-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-lg">🔧</span>
|
||||
|
||||
0
src/components/server/ServerCreationPopupContainer.tsx
Normal file → Executable file
138
src/components/server/ServerHeader.tsx
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
import Link from 'next/link';
|
||||
import { Server, getStatusColor, serviceStatusToString, ServiceStatus } from '@/lib/schemas/server';
|
||||
import { Server, serviceStatusToString, ServiceStatus } from '@/lib/schemas/server';
|
||||
import {
|
||||
startServerEventAction,
|
||||
restartServerEventAction,
|
||||
@@ -10,6 +10,8 @@ import { hasPermission, User } from '@/lib/schemas';
|
||||
import { useState, useTransition } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { DeleteServerModal } from './DeleteServerModal';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface ServerHeaderProps {
|
||||
server: Server;
|
||||
@@ -43,112 +45,42 @@ export function ServerHeader({ server, user }: ServerHeaderProps) {
|
||||
ServiceStatus.Stopping,
|
||||
ServiceStatus.Unknown
|
||||
].includes(server.status);
|
||||
|
||||
return (
|
||||
<div className="rounded-lg bg-gray-800 p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-4">
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="flex items-center text-gray-400 transition-colors hover:text-white"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="mr-2 h-5 w-5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M15 19l-7-7 7-7"
|
||||
/>
|
||||
</svg>
|
||||
Back to Dashboard
|
||||
</Link>
|
||||
<>
|
||||
<header className="flex h-12 items-center justify-between border-b border-border-muted px-5">
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Link href="/dashboard" className="text-blue hover:underline">Servers</Link>
|
||||
<span className="text-subtle">/</span>
|
||||
<span className="font-semibold text-primary">{server.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-white">{server.name}</h1>
|
||||
<div className="mt-2 flex items-center">
|
||||
<span
|
||||
className={`inline-block h-3 w-3 rounded-full ${getStatusColor(server.status)} mr-3`}
|
||||
/>
|
||||
<span className="text-lg text-gray-300 capitalize">
|
||||
{serviceStatusToString(server.status)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex space-x-3">
|
||||
{canDeleteServer && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setIsDeleteModalOpen(true);
|
||||
}}
|
||||
disabled={disabled || isPending}
|
||||
className="mr-3 rounded bg-red-800 px-4 py-2 font-medium text-white transition-colors hover:bg-red-900 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Remove Server
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={startServer}
|
||||
disabled={server.status === ServiceStatus.Running || disabled || isPending}
|
||||
className="rounded bg-green-600 px-4 py-2 font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Start
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={restartServer}
|
||||
disabled={server.status === ServiceStatus.Stopped || disabled || isPending}
|
||||
className="rounded bg-yellow-600 px-4 py-2 font-medium text-white transition-colors hover:bg-yellow-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Restart
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={stopServer}
|
||||
disabled={server.status === ServiceStatus.Stopped || disabled || isPending}
|
||||
className="rounded bg-red-600 px-4 py-2 font-medium text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
Stop
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant={
|
||||
server.status === ServiceStatus.Running ? 'green' :
|
||||
server.status === ServiceStatus.Stopped ? 'gray' : 'yellow'
|
||||
}>
|
||||
● {serviceStatusToString(server.status)}
|
||||
</Badge>
|
||||
<Button variant="ghost" size="sm" onClick={startServer} disabled={server.status === ServiceStatus.Running || disabled || isPending}>Start</Button>
|
||||
<Button variant="ghost" size="sm" onClick={restartServer} disabled={server.status === ServiceStatus.Stopped || disabled || isPending}>Restart</Button>
|
||||
<Button variant="danger-outline" size="sm" onClick={stopServer} disabled={server.status === ServiceStatus.Stopped || disabled || isPending}>Stop</Button>
|
||||
{canDeleteServer && (
|
||||
<Button variant="danger-solid" size="sm" onClick={() => setIsDeleteModalOpen(true)} disabled={disabled || isPending}>Remove</Button>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="mt-6 grid grid-cols-2 gap-6 md:grid-cols-4">
|
||||
<div>
|
||||
<div className="text-sm text-gray-500">Current Track</div>
|
||||
<div className="text-lg font-medium text-white">{server.state?.track || 'N/A'}</div>
|
||||
<div className="flex flex-wrap gap-6 border-b border-border-muted px-5 py-3">
|
||||
{[
|
||||
{ label: 'Track', value: server.state?.track ?? 'N/A' },
|
||||
{ label: 'Players', value: `${server.state?.playerCount ?? 0} / ${server.state?.maxConnections ?? 0}` },
|
||||
{ label: 'Session', value: server.state?.session ?? 'N/A' },
|
||||
].map(({ label, value }) => (
|
||||
<div key={label}>
|
||||
<div className="text-xs text-subtle">{label}</div>
|
||||
<div className="text-sm font-semibold text-primary">{value}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-gray-500">Players</div>
|
||||
<div className="text-lg font-medium text-white">
|
||||
{server.state?.playerCount || 0} / {server.state?.maxConnections || 0}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-gray-500">Session</div>
|
||||
<div className="text-lg font-medium text-white">{server.state?.session || 'N/A'}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-gray-500">Max Connections</div>
|
||||
<div className="text-lg font-medium text-white">
|
||||
{server.state?.maxConnections || 0}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<DeleteServerModal
|
||||
@@ -156,6 +88,6 @@ export function ServerHeader({ server, user }: ServerHeaderProps) {
|
||||
onClose={() => setIsDeleteModalOpen(false)}
|
||||
server={server}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
57
src/components/server/ServerListWithActions.tsx
Normal file → Executable file
@@ -1,12 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Server } from '@/lib/schemas/server';
|
||||
import { Server, ServiceStatus } from '@/lib/schemas/server';
|
||||
import { User, hasPermission } from '@/lib/schemas/user';
|
||||
import { ServerCard } from './ServerCard';
|
||||
import { ServerRow } from './ServerRow';
|
||||
import { CreateServerModal } from './CreateServerModal';
|
||||
import RefreshButton from '@/components/ui/RefreshButton';
|
||||
import { useSteamCMD } from '@/lib/context/SteamCMDContext';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
|
||||
interface ServerListWithActionsProps {
|
||||
servers: Server[];
|
||||
@@ -20,29 +23,55 @@ export function ServerListWithActions({ servers, user }: ServerListWithActionsPr
|
||||
const handleOnClose = useCallback(() => setIsCreateModalOpen(false), []);
|
||||
const canCreateServer = hasPermission(user, 'server.create');
|
||||
|
||||
const runningCount = servers.filter((s) => s.status === ServiceStatus.Running).length;
|
||||
const offlineCount = servers.filter((s) => s.status !== ServiceStatus.Running).length;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mb-6 flex items-center justify-between">
|
||||
<h2 className="text-xl font-semibold">Your Servers</h2>
|
||||
<div className="flex items-center space-x-4">
|
||||
<header className="border-border-muted flex h-12 items-center justify-between border-b px-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-primary text-sm font-semibold">Servers</span>
|
||||
<span className="text-muted text-xs">{servers.length} total</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<RefreshButton />
|
||||
{canCreateServer && (
|
||||
<button
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
disabled={isSteamCMDRunning}
|
||||
className="rounded-md bg-green-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
title={isSteamCMDRunning ? 'Server creation disabled while SteamCMD is running' : ''}
|
||||
title={isSteamCMDRunning ? 'Disabled while SteamCMD is running' : undefined}
|
||||
>
|
||||
Create Server
|
||||
</button>
|
||||
+ New Server
|
||||
</Button>
|
||||
)}
|
||||
<RefreshButton />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="flex items-center px-5 py-3">
|
||||
<div className="flex gap-2">
|
||||
{runningCount > 0 && <Badge variant="green">● {runningCount} running</Badge>}
|
||||
{offlineCount > 0 && <Badge variant="gray">{offlineCount} offline</Badge>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{servers.map((server) => (
|
||||
<ServerCard key={server.id} server={server} />
|
||||
))}
|
||||
<div className="px-5 pb-5">
|
||||
{/* Card grid — desktop only */}
|
||||
<div
|
||||
className="hidden gap-3 md:grid"
|
||||
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(360px, 1fr))' }}
|
||||
>
|
||||
{servers.map((server) => (
|
||||
<ServerCard key={server.id} server={server} />
|
||||
))}
|
||||
</div>
|
||||
{/* Row list — mobile only */}
|
||||
<div className="flex flex-col gap-2 md:hidden">
|
||||
{servers.map((server) => (
|
||||
<ServerRow key={server.id} server={server} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CreateServerModal isOpen={isCreateModalOpen} onClose={handleOnClose} />
|
||||
|
||||
86
src/components/server/ServerRow.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
'use client';
|
||||
|
||||
import { useTransition } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { Server, ServiceStatus } from '@/lib/schemas';
|
||||
import {
|
||||
startServerEventAction,
|
||||
restartServerEventAction,
|
||||
stopServerEventAction
|
||||
} from '@/lib/actions/servers';
|
||||
import { StatusDot } from '@/components/ui/StatusDot';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
interface ServerRowProps {
|
||||
server: Server;
|
||||
}
|
||||
|
||||
export function ServerRow({ server }: ServerRowProps) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
|
||||
const startServer = () =>
|
||||
startTransition(async () => {
|
||||
await startServerEventAction(server.id);
|
||||
router.refresh();
|
||||
});
|
||||
const restartServer = () =>
|
||||
startTransition(async () => {
|
||||
await restartServerEventAction(server.id);
|
||||
router.refresh();
|
||||
});
|
||||
const stopServer = () =>
|
||||
startTransition(async () => {
|
||||
await stopServerEventAction(server.id);
|
||||
router.refresh();
|
||||
});
|
||||
|
||||
const transitioning = [
|
||||
ServiceStatus.Restarting,
|
||||
ServiceStatus.Starting,
|
||||
ServiceStatus.Stopping,
|
||||
ServiceStatus.Unknown,
|
||||
].includes(server.status);
|
||||
const disabled = transitioning || isPending;
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-3 rounded-lg border border-border bg-canvas px-3 py-2.5 transition-colors hover:border-border/60">
|
||||
<Link href={`/dashboard/server/${server.id}`} className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<StatusDot status={server.status} />
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm font-semibold text-primary">{server.name}</div>
|
||||
<div className="truncate text-xs text-muted">
|
||||
{server.state?.track ?? 'No track'} · {server.state?.playerCount ?? 0} players
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
<div className="flex shrink-0 gap-1.5">
|
||||
{server.status === ServiceStatus.Stopped ? (
|
||||
<Button variant="primary" size="sm" onClick={startServer} disabled={disabled}>
|
||||
Start
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={restartServer}
|
||||
disabled={disabled}
|
||||
>
|
||||
Restart
|
||||
</Button>
|
||||
<Button
|
||||
variant="danger-outline"
|
||||
size="sm"
|
||||
onClick={stopServer}
|
||||
disabled={disabled}
|
||||
>
|
||||
Stop
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
14
src/components/statistics/DailyActivityChart.tsx
Normal file → Executable file
@@ -29,8 +29,8 @@ export function DailyActivityChart({ data }: DailyActivityChartProps) {
|
||||
{
|
||||
label: 'Sessions',
|
||||
data: data.map((item) => item.sessionsCount),
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.8)',
|
||||
borderColor: 'rgb(59, 130, 246)',
|
||||
backgroundColor: '#3fb950',
|
||||
borderColor: '#3fb950',
|
||||
borderWidth: 1
|
||||
}
|
||||
]
|
||||
@@ -43,27 +43,27 @@ export function DailyActivityChart({ data }: DailyActivityChartProps) {
|
||||
legend: {
|
||||
position: 'top' as const,
|
||||
labels: {
|
||||
color: '#e5e7eb'
|
||||
color: '#e6edf3'
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
ticks: {
|
||||
color: '#9ca3af'
|
||||
color: '#8b949e'
|
||||
},
|
||||
grid: {
|
||||
color: '#374151'
|
||||
color: '#21262d'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#9ca3af',
|
||||
color: '#8b949e',
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: '#374151'
|
||||
color: '#21262d'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/components/statistics/PlayerCountChart.tsx
Normal file → Executable file
@@ -43,8 +43,8 @@ export function PlayerCountChart({ data }: PlayerCountChartProps) {
|
||||
x: new Date(point.timestamp),
|
||||
y: point.count
|
||||
})),
|
||||
borderColor: 'rgb(59, 130, 246)',
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.1)',
|
||||
borderColor: '#58a6ff',
|
||||
backgroundColor: '#58a6ff1a',
|
||||
tension: 0.4
|
||||
}
|
||||
]
|
||||
@@ -57,7 +57,7 @@ export function PlayerCountChart({ data }: PlayerCountChartProps) {
|
||||
legend: {
|
||||
position: 'top' as const,
|
||||
labels: {
|
||||
color: '#e5e7eb'
|
||||
color: '#e6edf3'
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -68,20 +68,20 @@ export function PlayerCountChart({ data }: PlayerCountChartProps) {
|
||||
unit: 'hour' as const
|
||||
},
|
||||
ticks: {
|
||||
color: '#9ca3af'
|
||||
color: '#8b949e'
|
||||
},
|
||||
grid: {
|
||||
color: '#374151'
|
||||
color: '#21262d'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#9ca3af',
|
||||
color: '#8b949e',
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: '#374151'
|
||||
color: '#21262d'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
src/components/statistics/RecentSessions.tsx
Normal file → Executable file
@@ -29,51 +29,52 @@ export function RecentSessions({ sessions }: RecentSessionsProps) {
|
||||
|
||||
if (sessions.length === 0) {
|
||||
return (
|
||||
<div className="py-8 text-center">
|
||||
<div className="mb-2 text-4xl">📊</div>
|
||||
<p className="text-gray-400">No recent sessions found</p>
|
||||
</div>
|
||||
<div className="px-4 py-8 text-center text-sm text-muted">No recent sessions found</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full divide-y divide-gray-700">
|
||||
<table className="min-w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
<tr className="border-b border-border-muted bg-base">
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Date
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Type
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Track
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Duration
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium tracking-wider text-gray-400 uppercase">
|
||||
<th className="px-4 py-2 text-left text-xs font-medium uppercase tracking-wider text-subtle">
|
||||
Players
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-700">
|
||||
<tbody>
|
||||
{sessions.map((session) => (
|
||||
<tr key={session.id} className="transition-colors hover:bg-gray-700">
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap text-gray-300">
|
||||
<tr key={session.id} className="border-b border-border-muted transition-colors hover:bg-hover last:border-0">
|
||||
<td className="px-4 py-3 text-sm text-muted">
|
||||
{formatDate(session.date)}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap text-gray-300">
|
||||
<span className="inline-flex items-center rounded-full bg-blue-900 px-2.5 py-0.5 text-xs font-medium text-blue-300">
|
||||
{session.type}
|
||||
<td className="px-4 py-3">
|
||||
<span className={`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${
|
||||
session.type === 'R' ? 'bg-green-bg text-green' :
|
||||
session.type === 'Q' ? 'bg-yellow-bg text-yellow' :
|
||||
'bg-blue-bg text-blue'
|
||||
}`}>
|
||||
{session.type === 'R' ? 'Race' : session.type === 'Q' ? 'Qualify' : 'Practice'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap text-gray-300">{session.track}</td>
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap text-gray-300">
|
||||
<td className="px-4 py-3 text-sm text-secondary">{session.track}</td>
|
||||
<td className="px-4 py-3 text-sm text-muted">
|
||||
{formatDuration(session.duration)}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm whitespace-nowrap text-gray-300">
|
||||
<td className="px-4 py-3 text-sm text-secondary">
|
||||
{session.players}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
12
src/components/statistics/SessionTypesChart.tsx
Normal file → Executable file
@@ -15,12 +15,10 @@ interface SessionTypesChartProps {
|
||||
}
|
||||
|
||||
const colors = [
|
||||
'#3b82f6', // blue
|
||||
'#10b981', // emerald
|
||||
'#f59e0b', // amber
|
||||
'#ef4444', // red
|
||||
'#8b5cf6', // violet
|
||||
'#06b6d4' // cyan
|
||||
'#3fb950', // green
|
||||
'#58a6ff', // blue
|
||||
'#f78166', // red
|
||||
'#d29922' // yellow
|
||||
];
|
||||
|
||||
export function SessionTypesChart({ data }: SessionTypesChartProps) {
|
||||
@@ -43,7 +41,7 @@ export function SessionTypesChart({ data }: SessionTypesChartProps) {
|
||||
legend: {
|
||||
position: 'bottom' as const,
|
||||
labels: {
|
||||
color: '#e5e7eb',
|
||||
color: '#e6edf3',
|
||||
padding: 20
|
||||
}
|
||||
},
|
||||
|
||||
14
src/components/statistics/StatCard.tsx
Normal file → Executable file
@@ -6,16 +6,12 @@ interface StatCardProps {
|
||||
|
||||
export function StatCard({ title, value, icon }: StatCardProps) {
|
||||
return (
|
||||
<div className="rounded-lg bg-gray-800 p-6">
|
||||
<div className="flex items-center">
|
||||
<div className="flex-shrink-0">
|
||||
<span className="text-3xl">{icon}</span>
|
||||
</div>
|
||||
<div className="ml-4">
|
||||
<div className="text-2xl font-semibold text-white">{value}</div>
|
||||
<div className="text-sm text-gray-400">{title}</div>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border bg-canvas p-4">
|
||||
<div className="mb-1 flex items-center gap-2">
|
||||
<span className="text-base">{icon}</span>
|
||||
<span className="text-xs text-muted">{title}</span>
|
||||
</div>
|
||||
<div className="text-2xl font-bold text-primary">{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
35
src/components/statistics/StatisticsDashboard.tsx
Normal file → Executable file
@@ -14,21 +14,21 @@ interface StatisticsDashboardProps {
|
||||
export function StatisticsDashboard({ stats }: StatisticsDashboardProps) {
|
||||
if (!stats) {
|
||||
return (
|
||||
<div className="py-12 text-center">
|
||||
<div className="mb-4 text-6xl">📊</div>
|
||||
<h3 className="mb-2 text-xl font-semibold text-white">No Statistics Available</h3>
|
||||
<p className="text-gray-400">No data found for the selected date range.</p>
|
||||
<div className="py-16 text-center">
|
||||
<div className="mb-3 text-5xl">📊</div>
|
||||
<h3 className="mb-1 text-base font-semibold text-primary">No Statistics Available</h3>
|
||||
<p className="text-sm text-muted">No data found for the selected date range.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-4">
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<StatCard title="Total Sessions" value={stats.totalSessions ?? 0} icon="🏁" />
|
||||
<StatCard
|
||||
title="Total Playtime"
|
||||
value={`${Math.round(stats.totalPlaytime ?? 0 / 60)}h`}
|
||||
value={`${Math.round((stats.totalPlaytime ?? 0) / 60)}h`}
|
||||
icon="⏱️"
|
||||
/>
|
||||
<StatCard
|
||||
@@ -39,27 +39,24 @@ export function StatisticsDashboard({ stats }: StatisticsDashboardProps) {
|
||||
<StatCard title="Peak Players" value={stats.peakPlayers ?? 0} icon="🔥" />
|
||||
</div>
|
||||
|
||||
{/* Charts */}
|
||||
<div className="grid grid-cols-12 gap-4">
|
||||
<div className="col-span-9 rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-medium text-white">Player Count Over Time</h3>
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-3">
|
||||
<div className="lg:col-span-2 rounded-lg border border-border bg-canvas p-4">
|
||||
<h3 className="mb-3 text-sm font-semibold text-primary">Player Count Over Time</h3>
|
||||
<PlayerCountChart data={stats.playerCountOverTime ?? []} />
|
||||
</div>
|
||||
|
||||
<div className="col-span-3 rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-medium text-white">Session Types</h3>
|
||||
<div className="rounded-lg border border-border bg-canvas p-4">
|
||||
<h3 className="mb-3 text-sm font-semibold text-primary">Session Types</h3>
|
||||
<SessionTypesChart data={stats.sessionTypes ?? []} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-medium text-white">Daily Activity</h3>
|
||||
<div className="rounded-lg border border-border bg-canvas p-4">
|
||||
<h3 className="mb-3 text-sm font-semibold text-primary">Daily Activity</h3>
|
||||
<DailyActivityChart data={stats.dailyActivity ?? []} />
|
||||
</div>
|
||||
|
||||
{/* Recent Sessions */}
|
||||
<div className="rounded-lg bg-gray-800 p-6">
|
||||
<h3 className="mb-4 text-lg font-medium text-white">Recent Sessions</h3>
|
||||
<div className="overflow-hidden rounded-lg border border-border bg-canvas">
|
||||
<div className="border-b border-border-muted px-4 py-3 text-sm font-semibold text-primary">Recent Sessions</div>
|
||||
<RecentSessions sessions={stats.recentSessions ?? []} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
19
src/components/ui/AppShell.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
// NOTE: intentionally no 'use client' — must remain a Server Component
|
||||
import { Sidebar } from './Sidebar';
|
||||
|
||||
interface AppShellProps {
|
||||
children: React.ReactNode;
|
||||
showUsers: boolean;
|
||||
}
|
||||
|
||||
export function AppShell({ children, showUsers }: AppShellProps) {
|
||||
return (
|
||||
<div className="min-h-screen bg-base">
|
||||
<Sidebar showUsers={showUsers} />
|
||||
{/* Offset for sidebar (desktop: left margin, mobile: bottom padding) */}
|
||||
<div className="pb-14 md:pb-0 md:pl-14">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
31
src/components/ui/Badge.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
type BadgeVariant = 'green' | 'yellow' | 'red' | 'blue' | 'gray';
|
||||
|
||||
interface BadgeProps {
|
||||
variant: BadgeVariant;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const variantClasses: Record<BadgeVariant, string> = {
|
||||
green: 'bg-green-bg text-green border border-green/20',
|
||||
yellow: 'bg-yellow-bg text-yellow border border-yellow/20',
|
||||
red: 'bg-red-bg text-red border border-red/20',
|
||||
blue: 'bg-blue-bg text-blue border border-blue/20',
|
||||
gray: 'bg-overlay text-muted border border-border',
|
||||
};
|
||||
|
||||
export function Badge({ variant, children, className }: BadgeProps) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium',
|
||||
variantClasses[variant],
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,46 +1,49 @@
|
||||
import { forwardRef, ButtonHTMLAttributes } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { LoadingSpinner } from './LoadingSpinner';
|
||||
import { ButtonHTMLAttributes } from 'react';
|
||||
|
||||
type ButtonVariant = 'primary' | 'ghost' | 'danger-outline' | 'danger-solid';
|
||||
type ButtonSize = 'sm' | 'md' | 'logout';
|
||||
|
||||
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
isLoading?: boolean;
|
||||
variant?: ButtonVariant;
|
||||
size?: ButtonSize;
|
||||
}
|
||||
|
||||
const baseClasses =
|
||||
'inline-flex items-center justify-center font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed';
|
||||
|
||||
const variants = {
|
||||
primary: 'bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500',
|
||||
secondary: 'bg-gray-600 text-white hover:bg-gray-700 focus:ring-gray-500',
|
||||
danger: 'bg-red-600 text-white hover:bg-red-700 focus:ring-red-500',
|
||||
ghost: 'text-gray-300 hover:text-white hover:bg-gray-700 focus:ring-gray-500'
|
||||
const variantClasses: Record<ButtonVariant, string> = {
|
||||
primary: 'bg-btn-green border border-btn-green-hover text-white hover:bg-btn-green-hover',
|
||||
ghost: 'bg-transparent border border-border text-secondary hover:bg-overlay hover:text-primary',
|
||||
'danger-outline':
|
||||
'bg-transparent border border-border text-red hover:border-red/40 hover:bg-red-bg',
|
||||
'danger-solid': 'bg-overlay border border-red/20 text-red hover:bg-red-bg'
|
||||
};
|
||||
|
||||
const sizes = {
|
||||
sm: 'px-3 py-1 text-sm',
|
||||
const sizeClasses: Record<ButtonSize, string> = {
|
||||
sm: 'px-3 py-1.5 text-xs',
|
||||
md: 'px-4 py-2 text-sm',
|
||||
lg: 'px-6 py-3 text-base'
|
||||
logout: 'px-2 py-2 cursor-pointer hover:bg-red'
|
||||
};
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{ className, variant = 'primary', size = 'md', isLoading, children, disabled, ...props },
|
||||
ref
|
||||
) => {
|
||||
return (
|
||||
<button
|
||||
className={cn(baseClasses, variants[variant], sizes[size], className)}
|
||||
disabled={disabled || isLoading}
|
||||
ref={ref}
|
||||
{...props}
|
||||
>
|
||||
{isLoading && <LoadingSpinner size="sm" className="mr-2" />}
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Button.displayName = 'Button';
|
||||
export function Button({
|
||||
variant = 'ghost',
|
||||
size = 'md',
|
||||
className,
|
||||
children,
|
||||
disabled,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
return (
|
||||
<button
|
||||
{...props}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'focus:ring-blue focus:ring-offset-base inline-flex items-center justify-center gap-1.5 rounded-md font-medium transition-colors focus:ring-2 focus:ring-offset-1 focus:outline-none',
|
||||
'disabled:cursor-not-allowed disabled:opacity-40',
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
0
src/components/ui/Input.tsx
Normal file → Executable file
0
src/components/ui/LoadingSpinner.tsx
Normal file → Executable file
8
src/components/ui/LogoutButton.tsx
Normal file → Executable file
@@ -2,15 +2,16 @@
|
||||
|
||||
import { logoutAction } from '@/lib/actions/auth';
|
||||
import { useActionState } from 'react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
export default function LogoutButton() {
|
||||
const [, formAction] = useActionState(logoutAction, null);
|
||||
return (
|
||||
<form action={formAction}>
|
||||
<button type="submit" className="flex items-center text-gray-300 hover:text-white">
|
||||
<Button type="submit" title="Logout" variant="ghost" size="logout">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-6 w-6"
|
||||
className="h-5 w-5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
@@ -22,8 +23,7 @@ export default function LogoutButton() {
|
||||
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
|
||||
/>
|
||||
</svg>
|
||||
<span className="ml-1 hidden sm:inline">Logout</span>
|
||||
</button>
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
13
src/components/ui/Modal.tsx
Normal file → Executable file
@@ -33,17 +33,20 @@ export function Modal({ isOpen, onClose, title, children, className }: ModalProp
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
||||
<div className="bg-opacity-50 absolute inset-0 bg-black" onClick={onClose} />
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
|
||||
<div className="absolute inset-0" onClick={onClose} aria-label="Close" />
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="modal-title"
|
||||
className={cn(
|
||||
'relative mx-4 w-full max-w-md rounded-lg bg-gray-800 p-6 shadow-lg',
|
||||
'relative w-full max-w-md rounded-lg border border-border bg-canvas p-6 shadow-xl',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h3 className="text-lg font-semibold text-white">{title}</h3>
|
||||
<button onClick={onClose} className="text-gray-400 hover:text-white">
|
||||
<h3 id="modal-title" className="text-lg font-semibold text-primary">{title}</h3>
|
||||
<button onClick={onClose} className="text-muted hover:text-primary" aria-label="Close modal">
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
0
src/components/ui/Pagination.tsx
Normal file → Executable file
8
src/components/ui/RefreshButton.tsx
Normal file → Executable file
@@ -1,15 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
export default function RefreshButton() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<button
|
||||
onClick={() => router.refresh()}
|
||||
className="rounded-md bg-gray-700 px-3 py-1 text-sm hover:bg-gray-600"
|
||||
>
|
||||
<Button variant="ghost" size="sm" onClick={() => router.refresh()}>
|
||||
Refresh
|
||||
</button>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
0
src/components/ui/Select.tsx
Normal file → Executable file
122
src/components/ui/Sidebar.tsx
Normal file
@@ -0,0 +1,122 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import LogoutButton from './LogoutButton';
|
||||
|
||||
interface SidebarProps {
|
||||
showUsers: boolean; // true if user has membership.view permission
|
||||
}
|
||||
|
||||
function ServerIcon({ active }: { active: boolean }) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
className={cn('h-5 w-5', active ? 'text-blue' : 'text-subtle')}
|
||||
>
|
||||
<rect x="2" y="3" width="20" height="5" rx="1" />
|
||||
<rect x="2" y="10" width="20" height="5" rx="1" />
|
||||
<rect x="2" y="17" width="20" height="5" rx="1" />
|
||||
<circle cx="6" cy="5.5" r="1" fill="currentColor" />
|
||||
<circle cx="6" cy="12.5" r="1" fill="currentColor" />
|
||||
<circle cx="6" cy="19.5" r="1" fill="currentColor" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
function UsersIcon({ active }: { active: boolean }) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
className={cn('h-5 w-5', active ? 'text-blue' : 'text-subtle')}
|
||||
>
|
||||
<path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2" />
|
||||
<circle cx="9" cy="7" r="4" />
|
||||
<path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export function Sidebar({ showUsers }: SidebarProps) {
|
||||
const pathname = usePathname();
|
||||
const isServers = pathname === '/dashboard' || pathname.startsWith('/dashboard/server');
|
||||
const isUsers = pathname.startsWith('/dashboard/membership');
|
||||
|
||||
const navItems = [
|
||||
{
|
||||
href: '/dashboard',
|
||||
label: 'Servers',
|
||||
active: isServers,
|
||||
icon: <ServerIcon active={isServers} />
|
||||
},
|
||||
...(showUsers
|
||||
? [
|
||||
{
|
||||
href: '/dashboard/membership',
|
||||
label: 'Users',
|
||||
active: isUsers,
|
||||
icon: <UsersIcon active={isUsers} />
|
||||
}
|
||||
]
|
||||
: [])
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<aside className="border-border-muted bg-sidebar fixed inset-y-0 left-0 z-40 hidden w-14 flex-col items-center border-r py-3 md:flex">
|
||||
<div className="bg-blue mb-4 flex h-8 w-8 items-center justify-center rounded-lg">
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="#0d1117"
|
||||
strokeWidth={2.5}
|
||||
className="h-4 w-4"
|
||||
>
|
||||
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<nav className="flex flex-1 flex-col items-center gap-1">
|
||||
{navItems.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
title={item.label}
|
||||
className={cn(
|
||||
'flex h-9 w-9 items-center justify-center rounded-lg transition-colors',
|
||||
item.active ? 'bg-blue-bg' : 'hover:bg-overlay'
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<LogoutButton />
|
||||
</aside>
|
||||
|
||||
<nav className="border-border-muted bg-sidebar fixed inset-x-0 bottom-0 z-40 flex h-14 items-center justify-around border-t md:hidden">
|
||||
{navItems.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
'flex flex-col items-center justify-center gap-0.5 px-4 py-2 text-xs transition-colors',
|
||||
item.active ? 'text-blue' : 'text-subtle'
|
||||
)}
|
||||
>
|
||||
{item.icon}
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
</>
|
||||
);
|
||||
}
|
||||
28
src/components/ui/StatusDot.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ServiceStatus } from '@/lib/schemas/server';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface StatusDotProps {
|
||||
status: ServiceStatus;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function StatusDot({ status, className }: StatusDotProps) {
|
||||
const dotClass = {
|
||||
[ServiceStatus.Running]: 'bg-green shadow-[0_0_0_3px_#3fb95022]',
|
||||
[ServiceStatus.Starting]: 'bg-yellow animate-pulse',
|
||||
[ServiceStatus.Stopping]: 'bg-yellow animate-pulse',
|
||||
[ServiceStatus.Restarting]: 'bg-yellow animate-pulse',
|
||||
[ServiceStatus.Stopped]: 'bg-subtle',
|
||||
[ServiceStatus.Unknown]: 'bg-subtle',
|
||||
}[status] ?? 'bg-subtle';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
'inline-block h-2 w-2 rounded-full flex-shrink-0',
|
||||
dotClass,
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
10
src/components/ui/SteamCMDNotification.tsx
Normal file → Executable file
@@ -12,11 +12,11 @@ export function SteamCMDNotification() {
|
||||
const serverCount = runningSteamServers.size;
|
||||
|
||||
return (
|
||||
<div className="bg-yellow-600 border-l-4 border-yellow-400 p-4">
|
||||
<div className="border-l-4 border-yellow bg-yellow-bg px-4 py-3">
|
||||
<div className="flex items-center">
|
||||
<div className="flex-shrink-0">
|
||||
<svg
|
||||
className="h-5 w-5 text-yellow-50"
|
||||
className="h-5 w-5 text-yellow"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
>
|
||||
@@ -28,7 +28,7 @@ export function SteamCMDNotification() {
|
||||
</svg>
|
||||
</div>
|
||||
<div className="ml-3">
|
||||
<p className="text-sm text-yellow-50">
|
||||
<p className="text-sm text-yellow">
|
||||
<strong>SteamCMD is currently running</strong> for {serverCount} server{serverCount !== 1 ? 's' : ''}.
|
||||
Server actions are temporarily disabled to prevent conflicts.
|
||||
This will automatically resolve when the download completes.
|
||||
@@ -36,8 +36,8 @@ export function SteamCMDNotification() {
|
||||
</div>
|
||||
<div className="ml-auto flex-shrink-0">
|
||||
<div className="flex items-center">
|
||||
<div className="animate-spin h-4 w-4 border-2 border-yellow-50 border-t-transparent rounded-full mr-2"></div>
|
||||
<span className="text-xs text-yellow-50">Downloading...</span>
|
||||
<div className="animate-spin h-4 w-4 border-2 border-yellow border-t-transparent rounded-full mr-2"></div>
|
||||
<span className="text-xs text-yellow">Downloading...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
0
src/components/ui/Toast.tsx
Normal file → Executable file
0
src/components/websocket/WebSocketInitializer.tsx
Normal file → Executable file
0
src/lib/actions/auth.ts
Normal file → Executable file
29
src/lib/actions/configuration.ts
Normal file → Executable file
@@ -2,10 +2,11 @@
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { requireAuth } from '@/lib/auth/server';
|
||||
import { updateServerConfiguration } from '@/lib/api/server/configuration';
|
||||
import { updateServerConfiguration, bulkUpdateServerConfigurations } from '@/lib/api/server/configuration';
|
||||
import {
|
||||
assistRulesSchema,
|
||||
ConfigFile,
|
||||
configurationsSchema,
|
||||
eventConfigSchema,
|
||||
eventRulesSchema,
|
||||
serverSettingsSchema
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
import type {
|
||||
Configuration,
|
||||
AssistRules,
|
||||
Configurations,
|
||||
EventConfig,
|
||||
EventRules,
|
||||
ServerSettings
|
||||
@@ -232,3 +234,28 @@ export async function updateEventRulesAction(serverId: string, formData: FormDat
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function bulkUpdateConfigurationsAction(
|
||||
serverId: string,
|
||||
configs: Configurations,
|
||||
restart: boolean
|
||||
) {
|
||||
try {
|
||||
const session = await requireAuth();
|
||||
|
||||
const validated = configurationsSchema.safeParse(configs);
|
||||
if (!validated.success) {
|
||||
return { success: false, message: validated.error.message };
|
||||
}
|
||||
|
||||
await bulkUpdateServerConfigurations(session.token!, serverId, validated.data, restart);
|
||||
revalidatePath(`/dashboard/server/${serverId}`);
|
||||
|
||||
return { success: true, message: 'All configurations updated successfully' };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : 'Failed to update configurations'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
24
src/lib/actions/leaderboard.ts
Executable file
@@ -0,0 +1,24 @@
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { requireAuth } from '@/lib/auth/server';
|
||||
import { fetchServerAPI } from '@/lib/api/server/base';
|
||||
import { leaderboardSchema, type Leaderboard } from '@/lib/schemas/leaderboard';
|
||||
|
||||
export async function saveLeaderboardAction(serverId: string, data: Leaderboard) {
|
||||
try {
|
||||
const session = await requireAuth();
|
||||
const validated = leaderboardSchema.safeParse(data);
|
||||
if (!validated.success) {
|
||||
return { success: false, message: validated.error.message };
|
||||
}
|
||||
await fetchServerAPI(`/server/${serverId}/leaderboard`, session.token!, 'PUT', validated.data);
|
||||
revalidatePath(`/dashboard/server/${serverId}`);
|
||||
return { success: true, message: 'Leaderboard saved successfully' };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: error instanceof Error ? error.message : 'Failed to save leaderboard'
|
||||
};
|
||||
}
|
||||
}
|
||||
0
src/lib/actions/membership.ts
Normal file → Executable file
0
src/lib/actions/server-management.ts
Normal file → Executable file
0
src/lib/actions/servers.ts
Normal file → Executable file
0
src/lib/api/client/base.ts
Normal file → Executable file
0
src/lib/api/client/hooks.ts
Normal file → Executable file
0
src/lib/api/client/query-client.ts
Normal file → Executable file
0
src/lib/api/server/auth.ts
Normal file → Executable file
4
src/lib/api/server/base.ts
Normal file → Executable file
@@ -30,9 +30,7 @@ export async function fetchServerAPI<T>(
|
||||
if (response.status == 401) {
|
||||
redirect('/login?expired=true');
|
||||
}
|
||||
throw new Error(
|
||||
`API Error: ${response.statusText} - ${method} - ${BASE_URL}${endpoint} - ${token}`
|
||||
);
|
||||
throw new Error(`API Error: ${response.statusText} - ${method} - ${BASE_URL}${endpoint}`);
|
||||
}
|
||||
|
||||
if (response.headers.get('Content-Type')?.includes('application/json')) {
|
||||
|
||||
39
src/lib/api/server/configuration.ts
Normal file → Executable file
@@ -8,14 +8,23 @@ import {
|
||||
} from '@/lib/schemas/config';
|
||||
import * as z from 'zod';
|
||||
|
||||
export type ConfigAuditRecord = {
|
||||
id: string;
|
||||
serverId: string;
|
||||
configFile: string;
|
||||
oldConfig: string;
|
||||
newConfig: string;
|
||||
changedAt: string;
|
||||
};
|
||||
|
||||
const serverRoute = '/server';
|
||||
|
||||
export async function getServerConfigurations(
|
||||
token: string,
|
||||
serverId: string
|
||||
): Promise<Configurations> {
|
||||
const response = await fetchServerAPI<Configurations>(`${serverRoute}/${serverId}/config`, token);
|
||||
return configurationsSchema.parse(response.data);
|
||||
const response = await fetchServerAPI<Configurations>(`${serverRoute}/${serverId}/config`, token);
|
||||
return configurationsSchema.parse(response.data);
|
||||
}
|
||||
|
||||
export function validateConfig(
|
||||
@@ -45,8 +54,26 @@ export async function updateServerConfiguration(
|
||||
config: Config,
|
||||
restart = false
|
||||
): Promise<void> {
|
||||
await fetchServerAPI(`${serverRoute}/${serverId}/config/${configType}?override=true`, token, 'PUT', {
|
||||
...validateConfig(configType, config),
|
||||
restart
|
||||
});
|
||||
await fetchServerAPI(
|
||||
`${serverRoute}/${serverId}/config/${configType}?override=true&restart=${restart}`,
|
||||
token,
|
||||
'PUT',
|
||||
{
|
||||
...validateConfig(configType, config)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function bulkUpdateServerConfigurations(
|
||||
token: string,
|
||||
serverId: string,
|
||||
configs: Configurations,
|
||||
restart = false
|
||||
): Promise<void> {
|
||||
await fetchServerAPI<ConfigAuditRecord[]>(
|
||||
`${serverRoute}/${serverId}/config?override=true&restart=${restart}`,
|
||||
token,
|
||||
'PATCH',
|
||||
configs
|
||||
);
|
||||
}
|
||||
|
||||
17
src/lib/api/server/health.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
|
||||
|
||||
export type HealthStatus = { healthy: true; version: string } | { healthy: false; version: null };
|
||||
|
||||
export async function checkHealth(): Promise<HealthStatus> {
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/system/health`, {
|
||||
method: 'GET',
|
||||
next: { revalidate: 0 }
|
||||
});
|
||||
if (!response.ok) return { healthy: false, version: null };
|
||||
const version = await response.text();
|
||||
return { healthy: true, version: version.trim() || 'unknown' };
|
||||
} catch {
|
||||
return { healthy: false, version: null };
|
||||
}
|
||||
}
|
||||
8
src/lib/api/server/leaderboard.ts
Executable file
@@ -0,0 +1,8 @@
|
||||
import { fetchServerAPI } from './base';
|
||||
import { emptyLeaderboard, leaderboardSchema, type Leaderboard } from '@/lib/schemas/leaderboard';
|
||||
|
||||
export async function getLeaderboard(token: string, serverId: string): Promise<Leaderboard> {
|
||||
const response = await fetchServerAPI<Leaderboard>(`/server/${serverId}/leaderboard`, token);
|
||||
const parsed = leaderboardSchema.safeParse(response.data);
|
||||
return parsed.success ? parsed.data : emptyLeaderboard;
|
||||
}
|
||||
0
src/lib/api/server/lookups.ts
Normal file → Executable file
1
src/lib/api/server/membership.ts
Normal file → Executable file
@@ -1,4 +1,3 @@
|
||||
import { use } from 'react';
|
||||
import { fetchServerAPI } from './base';
|
||||
import { User, Role, userSchema, UserCreate, userCreateSchema, roleSchema } from '@/lib/schemas';
|
||||
|
||||
|
||||
0
src/lib/api/server/servers.ts
Normal file → Executable file
0
src/lib/api/server/statistics.ts
Normal file → Executable file
0
src/lib/auth/server.ts
Normal file → Executable file
0
src/lib/context/ServerCreationPopupContext.tsx
Normal file → Executable file
0
src/lib/context/SteamCMDContext.tsx
Normal file → Executable file
7
src/lib/schemas/config.ts
Normal file → Executable file
@@ -15,14 +15,15 @@ export enum ServerTab {
|
||||
assistRules = 'assistRules',
|
||||
event = 'event',
|
||||
eventRules = 'eventRules',
|
||||
settings = 'settings'
|
||||
settings = 'settings',
|
||||
leaderboard = 'leaderboard'
|
||||
}
|
||||
export const serverTabSchema = z.enum(ServerTab);
|
||||
|
||||
export const configurationSchema = z.object({
|
||||
udpPort: z.number().min(1025).max(65535),
|
||||
tcpPort: z.number().min(1025).max(65535),
|
||||
maxConnections: z.number().min(1).max(64),
|
||||
maxConnections: z.number().min(1).max(100),
|
||||
lanDiscovery: z.number().min(0).max(1),
|
||||
registerToLobby: z.number().min(0).max(2),
|
||||
configVersion: z.number().min(1).max(2).default(1).optional()
|
||||
@@ -46,7 +47,7 @@ export type AssistRules = z.infer<typeof assistRulesSchema>;
|
||||
|
||||
export const serverSettingsSchema = z.object({
|
||||
serverName: z.string().min(3).max(150),
|
||||
adminPassword: z.string().min(6).max(50),
|
||||
adminPassword: z.string().min(6).max(50).or(z.literal('').nullable()),
|
||||
carGroup: z.string().min(1).max(50),
|
||||
trackMedalsRequirement: z.number().min(-1).max(3),
|
||||
safetyRatingRequirement: z.number().min(-1).max(99),
|
||||
|
||||
1
src/lib/schemas/index.ts
Normal file → Executable file
@@ -3,3 +3,4 @@ export * from './user';
|
||||
export * from './config';
|
||||
export * from './statistics';
|
||||
export * from './lookups';
|
||||
export * from './leaderboard';
|
||||
|
||||
71
src/lib/schemas/leaderboard.ts
Executable file
@@ -0,0 +1,71 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
export const resultValueSchema = z.union([z.literal('DNF'), z.literal('DNS'), z.coerce.number().int().min(0)]);
|
||||
export type ResultValue = z.infer<typeof resultValueSchema>;
|
||||
|
||||
export const leaderboardDriverSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().min(1),
|
||||
color: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
initials: z.string().min(1).max(10)
|
||||
});
|
||||
export type LeaderboardDriver = z.infer<typeof leaderboardDriverSchema>;
|
||||
|
||||
const pointsEntryFields = {
|
||||
id: z.string(),
|
||||
points: z.number().int().min(0),
|
||||
label: z.string().min(1),
|
||||
color: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
textColor: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
priority: z.number().int().min(0)
|
||||
};
|
||||
|
||||
export const pointsEntrySchema = z.object(pointsEntryFields);
|
||||
export type PointsEntry = z.infer<typeof pointsEntrySchema>;
|
||||
|
||||
export const flPointsSchema = z.object({
|
||||
points: z.number().int().min(0),
|
||||
label: z.string().min(1),
|
||||
color: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
textColor: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
priority: z.number().int().min(0)
|
||||
});
|
||||
export type FlPoints = z.infer<typeof flPointsSchema>;
|
||||
|
||||
export const leaderboardTrackSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().min(1),
|
||||
results: z.array(z.object({ driverId: z.string(), score: resultValueSchema })),
|
||||
fastestLapDriverId: z.string().nullable()
|
||||
});
|
||||
export type LeaderboardTrack = z.infer<typeof leaderboardTrackSchema>;
|
||||
|
||||
export const leaderboardSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
serverId: z.string().optional(),
|
||||
drivers: z.array(leaderboardDriverSchema),
|
||||
pointsTable: z.array(pointsEntrySchema),
|
||||
flPoints: z.number().int().min(0),
|
||||
flColor: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
flTextColor: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
||||
tracks: z.array(leaderboardTrackSchema)
|
||||
});
|
||||
export type Leaderboard = z.infer<typeof leaderboardSchema>;
|
||||
|
||||
export const emptyLeaderboard: Leaderboard = {
|
||||
drivers: [],
|
||||
pointsTable: [],
|
||||
flPoints: 1,
|
||||
flColor: '#8b5cf6',
|
||||
flTextColor: '#000000',
|
||||
tracks: []
|
||||
};
|
||||
|
||||
// Client-side derived type — never sent to API
|
||||
export type StandingsRow = {
|
||||
driver: LeaderboardDriver;
|
||||
driverId: string;
|
||||
totalPoints: number;
|
||||
trackResults: ResultValue[];
|
||||
fastestLapCount: number;
|
||||
};
|
||||
0
src/lib/schemas/lookups.ts
Normal file → Executable file
2
src/lib/schemas/server.ts
Normal file → Executable file
@@ -57,7 +57,7 @@ export const serverSchema = z.object({
|
||||
id: z.uuid(),
|
||||
name: z.string().min(1),
|
||||
status: z.enum(ServiceStatus),
|
||||
state: stateSchema.optional()
|
||||
state: stateSchema.optional().nullable()
|
||||
});
|
||||
|
||||
export type Server = z.infer<typeof serverSchema>;
|
||||
|
||||
8
src/lib/schemas/statistics.ts
Normal file → Executable file
@@ -43,10 +43,10 @@ export const stateHistoryStatsSchema = z.object({
|
||||
peakPlayers: z.number(),
|
||||
totalSessions: z.number(),
|
||||
totalPlaytime: z.number(),
|
||||
playerCountOverTime: z.array(playerCountPointSchema),
|
||||
sessionTypes: z.array(sessionCountSchema),
|
||||
dailyActivity: z.array(dailyActivitySchema),
|
||||
recentSessions: z.array(recentSessionSchema)
|
||||
playerCountOverTime: z.array(playerCountPointSchema).nullable(),
|
||||
sessionTypes: z.array(sessionCountSchema).nullable(),
|
||||
dailyActivity: z.array(dailyActivitySchema).nullable(),
|
||||
recentSessions: z.array(recentSessionSchema).nullable()
|
||||
});
|
||||
export type StateHistoryStats = z.infer<typeof stateHistoryStatsSchema>;
|
||||
|
||||
|
||||
2
src/lib/schemas/user.ts
Normal file → Executable file
@@ -10,7 +10,7 @@ export type Permission = z.infer<typeof permissionSchema>;
|
||||
export const roleSchema = z.object({
|
||||
id: z.uuid(),
|
||||
name: z.string(),
|
||||
permissions: z.array(permissionSchema)
|
||||
permissions: z.array(permissionSchema).nullable()
|
||||
});
|
||||
|
||||
export type Role = z.infer<typeof roleSchema>;
|
||||
|
||||