This commit is contained in:
Saeed Vaziry
2025-06-01 11:31:09 +02:00
parent 41388dafbf
commit 84476db764
23 changed files with 1517 additions and 1776 deletions

View File

@ -0,0 +1,63 @@
import { Service } from '@/types/service';
import React, { useState } from 'react';
import { useForm } from '@inertiajs/react';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
import { Button } from '@/components/ui/button';
import { LoaderCircleIcon } from 'lucide-react';
import FormSuccessful from '@/components/form-successful';
export function Action({ type, service }: { type: 'start' | 'stop' | 'restart' | 'enable' | 'disable'; service: Service }) {
const [open, setOpen] = useState(false);
const form = useForm();
const submit = () => {
form.post(route(`services.${type}`, { server: service.server_id, service: service }), {
onSuccess: () => {
setOpen(false);
},
});
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<DropdownMenuItem onSelect={(e) => e.preventDefault()} className="capitalize">
{type}
</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>
<span className="capitalize">{type}</span> service
</DialogTitle>
<DialogDescription className="sr-only">{type} service</DialogDescription>
</DialogHeader>
<p className="p-4">Are you sure you want to {type} the service?</p>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button
variant={['disable', 'stop'].includes(type) ? 'destructive' : 'default'}
disabled={form.processing}
onClick={submit}
className="capitalize"
>
{form.processing && <LoaderCircleIcon className="animate-spin" />}
<FormSuccessful successful={form.recentlySuccessful} />
{type}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}

View File

@ -1,119 +1,15 @@
import { ColumnDef } from '@tanstack/react-table';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
import { Button } from '@/components/ui/button';
import { useForm } from '@inertiajs/react';
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
import FormSuccessful from '@/components/form-successful';
import React, { useState } from 'react';
import { MoreVerticalIcon } from 'lucide-react';
import React from 'react';
import { Service } from '@/types/service';
import { Badge } from '@/components/ui/badge';
import DateTime from '@/components/date-time';
function Uninstall({ service }: { service: Service }) {
const [open, setOpen] = useState(false);
const form = useForm();
const submit = () => {
form.delete(route('services.destroy', { server: service.server_id, service: service }), {
onSuccess: () => {
setOpen(false);
},
});
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
Uninstall
</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Uninstall service</DialogTitle>
<DialogDescription className="sr-only">Uninstall service</DialogDescription>
</DialogHeader>
<p className="p-4">Are you sure you want to uninstall this service? This action cannot be undone.</p>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button variant="destructive" disabled={form.processing} onClick={submit}>
{form.processing && <LoaderCircleIcon className="animate-spin" />}
<FormSuccessful successful={form.recentlySuccessful} />
Uninstall
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
function Action({ type, service }: { type: 'start' | 'stop' | 'restart' | 'enable' | 'disable'; service: Service }) {
const [open, setOpen] = useState(false);
const form = useForm();
const submit = () => {
form.post(route(`services.${type}`, { server: service.server_id, service: service }), {
onSuccess: () => {
setOpen(false);
},
});
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<DropdownMenuItem onSelect={(e) => e.preventDefault()} className="capitalize">
{type}
</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>
<span className="capitalize">{type}</span> service
</DialogTitle>
<DialogDescription className="sr-only">{type} service</DialogDescription>
</DialogHeader>
<p className="p-4">Are you sure you want to {type} the service?</p>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button
variant={['disable', 'stop'].includes(type) ? 'destructive' : 'default'}
disabled={form.processing}
onClick={submit}
className="capitalize"
>
{form.processing && <LoaderCircleIcon className="animate-spin" />}
<FormSuccessful successful={form.recentlySuccessful} />
{type}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
import Uninstall from '@/pages/services/components/uninstall';
import { Action } from '@/pages/services/components/action';
export const columns: ColumnDef<Service>[] = [
// {
// accessorKey: 'id',
// header: 'Service',
// enableColumnFilter: true,
// enableSorting: true,
// cell: ({ row }) => {
// return <img src={row.original.icon} className="size-7 rounded-sm" alt={`${row.original.name} icon`} />;
// },
// },
{
accessorKey: 'name',
header: 'Name',

View File

@ -19,7 +19,7 @@ import { Button } from '@/components/ui/button';
import { LoaderCircleIcon } from 'lucide-react';
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
export default function InstallService({ children }: { children: ReactNode }) {
export default function InstallService({ name, children }: { name?: string; children: ReactNode }) {
const page = usePage<
{
server: Server;
@ -33,7 +33,7 @@ export default function InstallService({ children }: { children: ReactNode }) {
version: string;
}>({
type: '',
name: '',
name: name ?? '',
version: '',
});
@ -52,36 +52,38 @@ export default function InstallService({ children }: { children: ReactNode }) {
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>Install service</DialogTitle>
<DialogDescription className="sr-only">Install new service</DialogDescription>
<DialogTitle>Install {name ?? 'service'}</DialogTitle>
<DialogDescription className="sr-only">Install new {name ?? 'service'}</DialogDescription>
</DialogHeader>
<Form id="install-service-form" onSubmit={submit} className="p-4">
<FormFields>
{/*service*/}
<FormField>
<Label htmlFor="name">Name</Label>
<Select
value={form.data.name}
onValueChange={(value) => {
form.setData('name', value);
form.setData('version', '');
}}
>
<SelectTrigger id="name">
<SelectValue placeholder="Select a service" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{Object.entries(page.props.configs.service_types).map(([key]) => (
<SelectItem key={`service-${key}`} value={key}>
{key}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<InputError message={form.errors.type || form.errors.name} />
</FormField>
{!name && (
<FormField>
<Label htmlFor="name">Name</Label>
<Select
value={form.data.name}
onValueChange={(value) => {
form.setData('name', value);
form.setData('version', '');
}}
>
<SelectTrigger id="name">
<SelectValue placeholder="Select a service" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{Object.entries(page.props.configs.service_types).map(([key]) => (
<SelectItem key={`service-${key}`} value={key}>
{key}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<InputError message={form.errors.type || form.errors.name} />
</FormField>
)}
{/*version*/}
<FormField>

View File

@ -0,0 +1,56 @@
import { Service } from '@/types/service';
import React, { useState } from 'react';
import { useForm } from '@inertiajs/react';
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
import { Button } from '@/components/ui/button';
import { LoaderCircleIcon } from 'lucide-react';
import FormSuccessful from '@/components/form-successful';
export default function Uninstall({ service }: { service: Service }) {
const [open, setOpen] = useState(false);
const form = useForm();
const submit = () => {
form.delete(route('services.destroy', { server: service.server_id, service: service }), {
onSuccess: () => {
setOpen(false);
},
});
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
Uninstall
</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Uninstall service</DialogTitle>
<DialogDescription className="sr-only">Uninstall service</DialogDescription>
</DialogHeader>
<p className="p-4">Are you sure you want to uninstall this service? This action cannot be undone.</p>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button variant="destructive" disabled={form.processing} onClick={submit}>
{form.processing && <LoaderCircleIcon className="animate-spin" />}
<FormSuccessful successful={form.recentlySuccessful} />
Uninstall
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}