mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
#591 - server-providers
This commit is contained in:
@ -3,14 +3,20 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\ServerProvider\CreateServerProvider;
|
||||
use App\Actions\ServerProvider\DeleteServerProvider;
|
||||
use App\Actions\ServerProvider\EditServerProvider;
|
||||
use App\Http\Resources\ServerProviderResource;
|
||||
use App\Models\ServerProvider;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Spatie\RouteAttributes\Attributes\Delete;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Patch;
|
||||
use Spatie\RouteAttributes\Attributes\Post;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
|
||||
@ -18,10 +24,18 @@
|
||||
#[Middleware(['auth'])]
|
||||
class ServerProviderController extends Controller
|
||||
{
|
||||
public function index(): void {}
|
||||
#[Get('/', name: 'server-providers')]
|
||||
public function index(): Response
|
||||
{
|
||||
$this->authorize('viewAny', ServerProvider::class);
|
||||
|
||||
#[Get('/', name: 'server-providers.all')]
|
||||
public function all(): ResourceCollection
|
||||
return Inertia::render('server-providers/index', [
|
||||
'serverProviders' => ServerProviderResource::collection(ServerProvider::getByProjectId(user()->current_project_id)->simplePaginate(config('web.pagination_size'))),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Get('/json', name: 'server-providers.json')]
|
||||
public function json(): ResourceCollection
|
||||
{
|
||||
$this->authorize('viewAny', ServerProvider::class);
|
||||
|
||||
@ -38,6 +52,16 @@ public function store(Request $request): RedirectResponse
|
||||
return back()->with('success', 'Server provider created.');
|
||||
}
|
||||
|
||||
#[Patch('/{serverProvider}', name: 'server-providers.update')]
|
||||
public function update(Request $request, ServerProvider $serverProvider): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $serverProvider);
|
||||
|
||||
app(EditServerProvider::class)->edit($serverProvider, user()->currentProject, $request->all());
|
||||
|
||||
return back()->with('success', 'Server provider updated.');
|
||||
}
|
||||
|
||||
#[Get('/{serverProvider}/regions', name: 'server-providers.regions')]
|
||||
public function regions(ServerProvider $serverProvider): JsonResponse
|
||||
{
|
||||
@ -53,4 +77,14 @@ public function plans(ServerProvider $serverProvider, string $region): JsonRespo
|
||||
|
||||
return response()->json($serverProvider->provider()->plans($region));
|
||||
}
|
||||
|
||||
#[Delete('{serverProvider}', name: 'server-providers.destroy')]
|
||||
public function destroy(ServerProvider $serverProvider): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $serverProvider);
|
||||
|
||||
app(DeleteServerProvider::class)->delete($serverProvider);
|
||||
|
||||
return to_route('server-providers')->with('success', 'Server provider deleted.');
|
||||
}
|
||||
}
|
||||
|
10
resources/js/components/form-successful.tsx
Normal file
10
resources/js/components/form-successful.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import { CheckIcon } from 'lucide-react';
|
||||
import { Transition } from '@headlessui/react';
|
||||
|
||||
export default function FormSuccessful({ successful }: { successful: boolean }) {
|
||||
return (
|
||||
<Transition show={successful} enter="transition ease-in-out" enterFrom="opacity-0" leave="transition ease-in-out" leaveTo="opacity-0">
|
||||
<CheckIcon />
|
||||
</Transition>
|
||||
);
|
||||
}
|
@ -5,7 +5,7 @@ import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const badgeVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-auto',
|
||||
'uppercase inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-auto',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { type BreadcrumbItem, type NavItem } from '@/types';
|
||||
import { ListIcon, UserIcon, UsersIcon } from 'lucide-react';
|
||||
import { CloudIcon, ListIcon, UserIcon, UsersIcon } from 'lucide-react';
|
||||
import { ReactNode } from 'react';
|
||||
import Layout from '@/layouts/app/layout';
|
||||
|
||||
@ -19,6 +19,11 @@ const sidebarNavItems: NavItem[] = [
|
||||
href: route('projects'),
|
||||
icon: ListIcon,
|
||||
},
|
||||
{
|
||||
title: 'Server Providers',
|
||||
href: route('server-providers'),
|
||||
icon: CloudIcon,
|
||||
},
|
||||
];
|
||||
|
||||
export default function SettingsLayout({ children, breadcrumbs }: { children: ReactNode; breadcrumbs?: BreadcrumbItem[] }) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { FormEventHandler, useRef } from 'react';
|
||||
|
||||
@ -8,7 +7,8 @@ import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { CheckIcon, LoaderCircleIcon } from 'lucide-react';
|
||||
import { LoaderCircleIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
|
||||
export default function UpdatePassword() {
|
||||
const passwordInput = useRef<HTMLInputElement>(null);
|
||||
@ -96,11 +96,9 @@ export default function UpdatePassword() {
|
||||
<CardFooter className="gap-2">
|
||||
<Button form="update-password-form" disabled={processing}>
|
||||
{processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={recentlySuccessful} />
|
||||
Save password
|
||||
</Button>
|
||||
<Transition show={recentlySuccessful} enter="transition ease-in-out" enterFrom="opacity-0" leave="transition ease-in-out" leaveTo="opacity-0">
|
||||
<CheckIcon className="text-success" />
|
||||
</Transition>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
|
@ -4,18 +4,18 @@ import { Input } from '@/components/ui/input';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import type { SharedData } from '@/types';
|
||||
import { FormEventHandler } from 'react';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { CheckIcon, LoaderCircleIcon } from 'lucide-react';
|
||||
import { LoaderCircleIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
|
||||
type ProfileForm = {
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
export default function UpdateUser() {
|
||||
export default function UpdateProfile() {
|
||||
const { auth } = usePage<SharedData>().props;
|
||||
|
||||
const { data, setData, patch, errors, processing, recentlySuccessful } = useForm<Required<ProfileForm>>({
|
||||
@ -71,11 +71,9 @@ export default function UpdateUser() {
|
||||
<CardFooter className="gap-2">
|
||||
<Button form="update-profile-form" disabled={processing}>
|
||||
{processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={recentlySuccessful} />
|
||||
Save
|
||||
</Button>
|
||||
<Transition show={recentlySuccessful} enter="transition ease-in-out" enterFrom="opacity-0" leave="transition ease-in-out" leaveTo="opacity-0">
|
||||
<CheckIcon className="text-success" />
|
||||
</Transition>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
@ -2,7 +2,7 @@ import { Head } from '@inertiajs/react';
|
||||
import SettingsLayout from '@/layouts/settings/layout';
|
||||
import Container from '@/components/container';
|
||||
import UpdatePassword from '@/pages/profile/components/update-password';
|
||||
import UpdateUser from '@/pages/profile/components/update-user';
|
||||
import UpdateProfile from '@/pages/profile/components/update-profile';
|
||||
import Heading from '@/components/heading';
|
||||
|
||||
export default function Profile() {
|
||||
@ -11,7 +11,7 @@ export default function Profile() {
|
||||
<Head title="Profile settings" />
|
||||
<Container className="max-w-5xl">
|
||||
<Heading title="Profile settings" description="Manage your profile settings." />
|
||||
<UpdateUser />
|
||||
<UpdateProfile />
|
||||
<UpdatePassword />
|
||||
</Container>
|
||||
</SettingsLayout>
|
||||
|
@ -10,14 +10,14 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { FormEventHandler, ReactNode, useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { CheckIcon, LoaderCircle } from 'lucide-react';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Project } from '@/types/project';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
|
||||
export default function ProjectForm({ project, children }: { project?: Project; children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@ -58,16 +58,7 @@ export default function ProjectForm({ project, children }: { project?: Project;
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter className="items-center">
|
||||
<Transition
|
||||
show={form.recentlySuccessful}
|
||||
enter="transition ease-in-out"
|
||||
enterFrom="opacity-0"
|
||||
leave="transition ease-in-out"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<CheckIcon className="text-success" />
|
||||
</Transition>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
@ -75,6 +66,7 @@ export default function ProjectForm({ project, children }: { project?: Project;
|
||||
</DialogClose>
|
||||
<Button form="project-form" type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
185
resources/js/pages/server-providers/components/columns.tsx
Normal file
185
resources/js/pages/server-providers/components/columns.tsx
Normal file
@ -0,0 +1,185 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import DateTime from '@/components/date-time';
|
||||
import { ServerProvider } from '@/types/server-provider';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
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 { Button } from '@/components/ui/button';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { FormEvent, useState } from 'react';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
|
||||
function Edit({ serverProvider }: { serverProvider: ServerProvider }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm({
|
||||
name: serverProvider.name,
|
||||
global: serverProvider.global,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.patch(route('server-providers.update', serverProvider.id));
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Edit</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit {serverProvider.name}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Edit server provider</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="edit-server-provider-form" className="p-4" onSubmit={submit}>
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input type="text" id="name" name="name" value={form.data.name} onChange={(e) => form.setData('name', e.target.value)} />
|
||||
<InputError message={form.errors.name} />
|
||||
</FormField>
|
||||
<FormField>
|
||||
<div className="flex items-center space-x-3">
|
||||
<Checkbox id="global" name="global" checked={form.data.global} onClick={() => form.setData('global', !form.data.global)} />
|
||||
<Label htmlFor="global">Is global (accessible in all projects)</Label>
|
||||
</div>
|
||||
<InputError message={form.errors.global} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button form="edit-server-provider-form" disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function Delete({ serverProvider }: { serverProvider: ServerProvider }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
form.delete(route('server-providers.destroy', serverProvider.id), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Delete {serverProvider.name}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Delete server provider</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>
|
||||
Are you sure you want to delete <strong>{serverProvider.name}</strong>?
|
||||
</p>
|
||||
<InputError message={form.errors.provider} />
|
||||
</div>
|
||||
<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} />
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<ServerProvider>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
enableHiding: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'provider',
|
||||
header: 'Provider',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Name',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'global',
|
||||
header: 'Global',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <div>{row.original.global ? <Badge variant="success">yes</Badge> : <Badge variant="danger">no</Badge>}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Created at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
enableColumnFilter: false,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex items-center justify-end">
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreVerticalIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<Edit serverProvider={row.original} />
|
||||
<DropdownMenuSeparator />
|
||||
<Delete serverProvider={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
@ -1,4 +1,4 @@
|
||||
import { LoaderCircle, PlusIcon, WifiIcon } from 'lucide-react';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
@ -11,7 +11,7 @@ import {
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
import { FormEventHandler, useEffect, useState } from 'react';
|
||||
import { FormEventHandler, ReactNode, useEffect, useState } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
@ -26,16 +26,16 @@ type ServerProviderForm = {
|
||||
global: boolean;
|
||||
};
|
||||
|
||||
export default function CreateServerProvider({
|
||||
trigger,
|
||||
export default function ConnectServerProvider({
|
||||
providers,
|
||||
defaultProvider,
|
||||
onProviderAdded,
|
||||
children,
|
||||
}: {
|
||||
trigger: 'icon' | 'button';
|
||||
providers: string[];
|
||||
defaultProvider?: string;
|
||||
onProviderAdded?: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
@ -65,21 +65,11 @@ export default function CreateServerProvider({
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button type="button" variant="outline">
|
||||
{trigger === 'icon' && <WifiIcon />}
|
||||
{trigger === 'button' && (
|
||||
<>
|
||||
<PlusIcon />
|
||||
Connect
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Connect</DialogTitle>
|
||||
<DialogDescription>Connect to a new server provider</DialogDescription>
|
||||
<DialogTitle>Connect to server provider</DialogTitle>
|
||||
<DialogDescription className="sr-only">Connect to a new server provider</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="create-server-provider-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
41
resources/js/pages/server-providers/index.tsx
Normal file
41
resources/js/pages/server-providers/index.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import SettingsLayout from '@/layouts/settings/layout';
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import React from 'react';
|
||||
import ConnectServerProvider from '@/pages/server-providers/components/connect-server-provider';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { columns } from '@/pages/server-providers/components/columns';
|
||||
import { ServerProvider } from '@/types/server-provider';
|
||||
|
||||
type Page = {
|
||||
serverProviders: {
|
||||
data: ServerProvider[];
|
||||
};
|
||||
configs: {
|
||||
server_providers: string[];
|
||||
};
|
||||
};
|
||||
|
||||
export default function ServerProviders() {
|
||||
const page = usePage<Page>();
|
||||
|
||||
return (
|
||||
<SettingsLayout>
|
||||
<Head title="Server Providers" />
|
||||
<Container className="max-w-5xl">
|
||||
<div className="flex items-start justify-between">
|
||||
<Heading title="Server Providers" description="Here you can manage all of the server provider connectinos" />
|
||||
<div className="flex items-center gap-2">
|
||||
<ConnectServerProvider providers={page.props.configs.server_providers}>
|
||||
<Button>Connect</Button>
|
||||
</ConnectServerProvider>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable columns={columns} data={page.props.serverProviders.data} />
|
||||
</Container>
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { ClipboardCheckIcon, ClipboardIcon, LoaderCircle, TriangleAlert } from 'lucide-react';
|
||||
import { ClipboardCheckIcon, ClipboardIcon, LoaderCircle, TriangleAlert, WifiIcon } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
@ -9,7 +9,7 @@ import InputError from '@/components/ui/input-error';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { ServerProvider } from '@/types/server-provider';
|
||||
import CreateServerProvider from '@/pages/server-providers/components/create-server-provider';
|
||||
import ConnectServerProvider from '@/pages/server-providers/components/connect-server-provider';
|
||||
import axios from 'axios';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import type { SharedData } from '@/types';
|
||||
@ -40,9 +40,9 @@ export default function CreateServer({ children }: { children: React.ReactNode }
|
||||
port: 22,
|
||||
region: '',
|
||||
plan: '',
|
||||
webserver: '',
|
||||
database: '',
|
||||
php: '',
|
||||
webserver: 'nginx',
|
||||
database: 'none',
|
||||
php: 'none',
|
||||
});
|
||||
|
||||
const submit: FormEventHandler = (e) => {
|
||||
@ -62,7 +62,7 @@ export default function CreateServer({ children }: { children: React.ReactNode }
|
||||
|
||||
const [serverProviders, setServerProviders] = useState<ServerProvider[]>([]);
|
||||
const fetchServerProviders = async () => {
|
||||
const serverProviders = await axios.get(route('server-providers.all'));
|
||||
const serverProviders = await axios.get(route('server-providers.json'));
|
||||
setServerProviders(serverProviders.data);
|
||||
};
|
||||
const selectProvider = (provider: string) => {
|
||||
@ -150,12 +150,15 @@ export default function CreateServer({ children }: { children: React.ReactNode }
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<CreateServerProvider
|
||||
trigger="icon"
|
||||
<ConnectServerProvider
|
||||
providers={page.props.configs.server_providers.filter((item) => item !== 'custom')}
|
||||
defaultProvider={form.data.provider}
|
||||
onProviderAdded={fetchServerProviders}
|
||||
/>
|
||||
>
|
||||
<Button variant="outline">
|
||||
<WifiIcon />
|
||||
</Button>
|
||||
</ConnectServerProvider>
|
||||
</div>
|
||||
<InputError />
|
||||
</FormField>
|
||||
|
@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { MoreVerticalIcon } from 'lucide-react';
|
||||
import DeleteUser from '@/pages/users/components/delete-user';
|
||||
import Projects from '@/pages/users/components/projects';
|
||||
import UserForm from '@/pages/users/components/form';
|
||||
import UserForm from '@/pages/users/components/user-form';
|
||||
|
||||
export default function UserActions({ user }: { user: User }) {
|
||||
return (
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { FormEventHandler, ReactNode, useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { CheckIcon, LoaderCircle } from 'lucide-react';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@ -18,7 +18,7 @@ import { Input } from '@/components/ui/input';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { User } from '@/types/user';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
|
||||
export default function UserForm({ user, children }: { user?: User; children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@ -100,15 +100,6 @@ export default function UserForm({ user, children }: { user?: User; children: Re
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter className="items-center">
|
||||
<Transition
|
||||
show={form.recentlySuccessful}
|
||||
enter="transition ease-in-out"
|
||||
enterFrom="opacity-0"
|
||||
leave="transition ease-in-out"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<CheckIcon className="text-success" />
|
||||
</Transition>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
@ -116,6 +107,7 @@ export default function UserForm({ user, children }: { user?: User; children: Re
|
||||
</DialogClose>
|
||||
<Button form="create-user-form" type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
@ -4,7 +4,7 @@ import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import UsersList from '@/pages/users/components/list';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import UserForm from '@/pages/users/components/form';
|
||||
import UserForm from '@/pages/users/components/user-form';
|
||||
|
||||
export default function Users() {
|
||||
return (
|
||||
|
3
resources/js/types/server-provider.d.ts
vendored
3
resources/js/types/server-provider.d.ts
vendored
@ -1,8 +1,9 @@
|
||||
export interface ServerProvider {
|
||||
id: number;
|
||||
user_id: number;
|
||||
name: string;
|
||||
provider: string;
|
||||
name: string;
|
||||
global: boolean;
|
||||
connected: boolean;
|
||||
project_id?: number;
|
||||
created_at: string;
|
||||
|
@ -3,11 +3,10 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Web\Pages\Settings\ServerProviders\Index;
|
||||
use App\Web\Pages\Settings\ServerProviders\Widgets\ServerProvidersList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerProvidersTest extends TestCase
|
||||
@ -15,7 +14,11 @@ class ServerProvidersTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*
|
||||
* @dataProvider data
|
||||
*
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_connect_provider(string $provider, array $input): void
|
||||
{
|
||||
@ -30,10 +33,8 @@ public function test_connect_provider(string $provider, array $input): void
|
||||
],
|
||||
$input
|
||||
);
|
||||
Livewire::test(Index::class)
|
||||
->callAction('create', $data)
|
||||
->assertHasNoActionErrors()
|
||||
->assertSuccessful();
|
||||
$this->post(route('server-providers.store'), $data)
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas('server_providers', [
|
||||
'provider' => $provider,
|
||||
@ -43,6 +44,8 @@ public function test_connect_provider(string $provider, array $input): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_cannot_connect_to_provider(string $provider, array $input): void
|
||||
@ -60,10 +63,8 @@ public function test_cannot_connect_to_provider(string $provider, array $input):
|
||||
],
|
||||
$input
|
||||
);
|
||||
Livewire::test(Index::class)
|
||||
->callAction('create', $data)
|
||||
->assertActionHalted('create')
|
||||
->assertNotified();
|
||||
$this->post(route('server-providers.store'), $data)
|
||||
->assertSessionHasErrors('provider');
|
||||
|
||||
$this->assertDatabaseMissing('server_providers', [
|
||||
'provider' => $provider,
|
||||
@ -75,17 +76,19 @@ public function test_see_providers_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$provider = \App\Models\ServerProvider::factory()->create([
|
||||
\App\Models\ServerProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$this->get(Index::getUrl())
|
||||
$this->get(route('server-providers'))
|
||||
->assertSuccessful()
|
||||
->assertSee($provider->profile);
|
||||
->assertInertia(fn (AssertableInertia $page) => $page->component('server-providers/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_delete_provider(string $provider): void
|
||||
{
|
||||
@ -96,9 +99,9 @@ public function test_delete_provider(string $provider): void
|
||||
'provider' => $provider,
|
||||
]);
|
||||
|
||||
Livewire::test(ServerProvidersList::class)
|
||||
->callTableAction('delete', $provider->id)
|
||||
->assertSuccessful();
|
||||
$this->delete(route('server-providers.destroy', $provider))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('server-providers'));
|
||||
|
||||
$this->assertDatabaseMissing('server_providers', [
|
||||
'id' => $provider->id,
|
||||
@ -121,15 +124,19 @@ public function test_cannot_delete_provider(string $provider): void
|
||||
'provider_id' => $provider->id,
|
||||
]);
|
||||
|
||||
Livewire::test(ServerProvidersList::class)
|
||||
->callTableAction('delete', $provider->id)
|
||||
->assertNotified('This server provider is being used by a server.');
|
||||
$this->delete(route('server-providers.destroy', $provider))
|
||||
->assertSessionHasErrors([
|
||||
'provider' => 'This server provider is being used by a server.',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('server_providers', [
|
||||
'id' => $provider->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, array<string, mixed>>>
|
||||
*/
|
||||
public static function data(): array
|
||||
{
|
||||
return [
|
||||
|
@ -6,7 +6,7 @@
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
@ -41,7 +41,7 @@ public function test_see_users_list(): void
|
||||
|
||||
$this->get(route('users'))
|
||||
->assertSuccessful()
|
||||
->assertInertia(fn (Assert $page) => $page->component('users/index'));
|
||||
->assertInertia(fn (AssertableInertia $page) => $page->component('users/index'));
|
||||
}
|
||||
|
||||
public function test_must_be_admin_to_see_users_list(): void
|
||||
|
Reference in New Issue
Block a user