mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22:34 +00:00
#591 - sites
This commit is contained in:
189
resources/js/pages/ssls/components/columns.tsx
Normal file
189
resources/js/pages/ssls/components/columns.tsx
Normal file
@ -0,0 +1,189 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircleIcon, LockIcon, LockOpenIcon, MoreVerticalIcon } from 'lucide-react';
|
||||
import React, { useState } from 'react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import DateTime from '@/components/date-time';
|
||||
import { SSL } from '@/types/ssl';
|
||||
import moment from 'moment';
|
||||
import { View } from '@/pages/server-logs/components/columns';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
|
||||
function Delete({ ssl }: { ssl: SSL }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
form.delete(route('ssls.destroy', { server: ssl.server_id, site: ssl.site_id, ssl: ssl.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 SSL</DialogTitle>
|
||||
<DialogDescription className="sr-only">Delete SSL</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>Are you sure you want to delete this certificate?</p>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
||||
function ToggleActivate({ ssl }: { ssl: SSL }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
const url = ssl.is_active
|
||||
? route('ssls.deactivate', { server: ssl.server_id, site: ssl.site_id, ssl: ssl.id })
|
||||
: route('ssls.activate', { server: ssl.server_id, site: ssl.site_id, ssl: ssl.id });
|
||||
form.post(url, {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>{ssl.is_active ? 'Deactivate' : 'Activate'}</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{ssl.is_active ? 'Deactivate' : 'Activate'} SSL</DialogTitle>
|
||||
<DialogDescription className="sr-only">{ssl.is_active ? 'Deactivate' : 'Activate'} SSL</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>Are you sure you want to {ssl.is_active ? 'deactivate' : 'activate'} this certificate?</p>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant={ssl.is_active ? 'destructive' : 'default'} disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
{ssl.is_active ? 'Deactivate' : 'Activate'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<SSL>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'Is active',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return row.original.is_active ? <LockIcon className="text-success" /> : <LockOpenIcon />;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'type',
|
||||
header: 'Type',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Created at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'expires_at',
|
||||
header: 'Expires at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
const targetDate = moment(row.original.expires_at);
|
||||
const today = moment();
|
||||
const daysRemaining = targetDate.diff(today, 'days');
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<DateTime date={row.original.expires_at} /> ({daysRemaining} days remaining)
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'status',
|
||||
header: 'Status',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <Badge variant={row.original.status_color}>{row.original.status}</Badge>;
|
||||
},
|
||||
},
|
||||
{
|
||||
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">
|
||||
<ToggleActivate ssl={row.original} />
|
||||
{row.original.log && (
|
||||
<>
|
||||
<View serverLog={row.original.log}>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>View Log</DropdownMenuItem>
|
||||
</View>
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
<Delete ssl={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
141
resources/js/pages/ssls/components/create-ssl.tsx
Normal file
141
resources/js/pages/ssls/components/create-ssl.tsx
Normal file
@ -0,0 +1,141 @@
|
||||
import React, { FormEvent, ReactNode, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Site } from '@/types/site';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
|
||||
type CreateForm = {
|
||||
type: string;
|
||||
email: string;
|
||||
certificate: string;
|
||||
private: string;
|
||||
expires_at: string;
|
||||
aliases: boolean;
|
||||
};
|
||||
|
||||
export default function CreateSSL({ site, children }: { site: Site; children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const form = useForm<CreateForm>({
|
||||
type: '',
|
||||
email: '',
|
||||
certificate: '',
|
||||
private: '',
|
||||
expires_at: '',
|
||||
aliases: false,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.post(route('ssls.store', { server: site.server_id, site: site.id }), {
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create SSL</DialogTitle>
|
||||
<DialogDescription className="sr-only">Create new SSL</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form className="p-4" id="create-ssl-form" onSubmit={submit}>
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="type">Type</Label>
|
||||
<Select onValueChange={(value) => form.setData('type', value)} defaultValue={form.data.type}>
|
||||
<SelectTrigger id="type">
|
||||
<SelectValue placeholder="Select type" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="letsencrypt">Let's Encrypt</SelectItem>
|
||||
<SelectItem value="custom">Custom</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<InputError message={form.errors.type} />
|
||||
</FormField>
|
||||
{form.data.type === 'letsencrypt' && (
|
||||
<>
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
<p>
|
||||
Let's Encrypt has rate limits. Read more about them{' '}
|
||||
<a href="https://letsencrypt.org/docs/rate-limits/" target="_blank" className="underline">
|
||||
here
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<FormField>
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input type="text" id="email" name="email" value={form.data.email} onChange={(e) => form.setData('email', e.target.value)} />
|
||||
<InputError message={form.errors.email} />
|
||||
</FormField>
|
||||
</>
|
||||
)}
|
||||
{form.data.type === 'custom' && (
|
||||
<>
|
||||
<FormField>
|
||||
<Label htmlFor="certificate">Certificate</Label>
|
||||
<Textarea
|
||||
id="certificate"
|
||||
name="certificate"
|
||||
value={form.data.certificate}
|
||||
onChange={(e) => form.setData('certificate', e.target.value)}
|
||||
/>
|
||||
<InputError message={form.errors.certificate} />
|
||||
</FormField>
|
||||
<FormField>
|
||||
<Label htmlFor="private">Private key</Label>
|
||||
<Textarea id="private" name="private" value={form.data.private} onChange={(e) => form.setData('private', e.target.value)} />
|
||||
<InputError message={form.errors.private} />
|
||||
</FormField>
|
||||
</>
|
||||
)}
|
||||
<FormField>
|
||||
<div className="flex items-center space-x-3">
|
||||
<Checkbox id="aliases" name="aliases" checked={form.data.aliases} onClick={() => form.setData('aliases', !form.data.aliases)} />
|
||||
<Label htmlFor="aliases">Set SSL for site's aliases as well</Label>
|
||||
</div>
|
||||
<InputError message={form.errors.aliases} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Create
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
59
resources/js/pages/ssls/components/force-ssl.tsx
Normal file
59
resources/js/pages/ssls/components/force-ssl.tsx
Normal file
@ -0,0 +1,59 @@
|
||||
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';
|
||||
import { Site } from '@/types/site';
|
||||
|
||||
export default function ToggleForceSSL({ site }: { site: Site }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
const url = site.force_ssl
|
||||
? route('ssls.disable-force-ssl', { server: site.server_id, site: site.id })
|
||||
: route('ssls.enable-force-ssl', { server: site.server_id, site: site.id });
|
||||
form.post(url, {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>{site.force_ssl ? 'Disable' : 'Enable'} Force-SSL</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{site.force_ssl ? 'Disable' : 'Enable'} Force-SSL</DialogTitle>
|
||||
<DialogDescription className="sr-only">{site.force_ssl ? 'Disable' : 'Enable'} Force-SSL</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>Are you sure you want to {site.force_ssl ? 'disable' : 'enable'} force-ssl?</p>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant={site.force_ssl ? 'destructive' : 'default'} disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
{site.force_ssl ? 'Disable' : 'Enable'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
64
resources/js/pages/ssls/index.tsx
Normal file
64
resources/js/pages/ssls/index.tsx
Normal file
@ -0,0 +1,64 @@
|
||||
import ServerLayout from '@/layouts/server/layout';
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import { Server } from '@/types/server';
|
||||
import { PaginatedData } from '@/types';
|
||||
import Container from '@/components/container';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { BookOpenIcon, MoreHorizontalIcon, PlusIcon } from 'lucide-react';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { columns } from '@/pages/ssls/components/columns';
|
||||
import { SSL } from '@/types/ssl';
|
||||
import CreateSSL from '@/pages/ssls/components/create-ssl';
|
||||
import { Site } from '@/types/site';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import React from 'react';
|
||||
import ToggleForceSSL from '@/pages/ssls/components/force-ssl';
|
||||
|
||||
export default function Ssls() {
|
||||
const page = usePage<{
|
||||
server: Server;
|
||||
site: Site;
|
||||
ssls: PaginatedData<SSL>;
|
||||
}>();
|
||||
|
||||
return (
|
||||
<ServerLayout>
|
||||
<Head title={`SSL - ${page.props.server.name}`} />
|
||||
|
||||
<Container className="max-w-5xl">
|
||||
<HeaderContainer>
|
||||
<Heading title="SSL" description="Here you can SSL certificates" />
|
||||
<div className="flex items-center gap-2">
|
||||
<a href="https://vitodeploy.com/docs/sites/ssl" target="_blank">
|
||||
<Button variant="outline">
|
||||
<BookOpenIcon />
|
||||
<span className="hidden lg:block">Docs</span>
|
||||
</Button>
|
||||
</a>
|
||||
<CreateSSL site={page.props.site}>
|
||||
<Button>
|
||||
<PlusIcon />
|
||||
<span className="hidden lg:block">New SSL</span>
|
||||
</Button>
|
||||
</CreateSSL>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontalIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<ToggleForceSSL site={page.props.site} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</HeaderContainer>
|
||||
|
||||
<DataTable columns={columns} paginatedData={page.props.ssls} />
|
||||
</Container>
|
||||
</ServerLayout>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user