mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 07:52:34 +00:00
Export and Import vito settings (#606)
* Export and Import vito settings * fix tests
This commit is contained in:
15
resources/js/pages/vito-settings/components/export.tsx
Normal file
15
resources/js/pages/vito-settings/components/export.tsx
Normal file
@ -0,0 +1,15 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DownloadIcon } from 'lucide-react';
|
||||
|
||||
export default function ExportVito() {
|
||||
const submit = () => {
|
||||
window.open(route('vito-settings.export'), '_blank');
|
||||
};
|
||||
|
||||
return (
|
||||
<Button onClick={submit}>
|
||||
<DownloadIcon />
|
||||
Export
|
||||
</Button>
|
||||
);
|
||||
}
|
70
resources/js/pages/vito-settings/components/import.tsx
Normal file
70
resources/js/pages/vito-settings/components/import.tsx
Normal file
@ -0,0 +1,70 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircleIcon, UploadIcon } from 'lucide-react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { FormEvent } from 'react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
|
||||
export default function ImportVito() {
|
||||
const form = useForm({
|
||||
backup_file: null as File | null,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.post(route('vito-settings.import'));
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<UploadIcon />
|
||||
Import
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Import</DialogTitle>
|
||||
<DialogDescription className="sr-only">Import settings to Vito</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="import-vito-form" className="p-4" onSubmit={submit}>
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="backup_file">Backup file</Label>
|
||||
<Input
|
||||
type="file"
|
||||
id="backup_file"
|
||||
name="backup_file"
|
||||
accept=".zip"
|
||||
onChange={(e) => form.setData('backup_file', e.target.files?.[0] || null)}
|
||||
/>
|
||||
<InputError message={form.errors.backup_file} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button form="import-vito-form" disabled={form.processing}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
Import
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
37
resources/js/pages/vito-settings/index.tsx
Normal file
37
resources/js/pages/vito-settings/index.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import SettingsLayout from '@/layouts/settings/layout';
|
||||
import { Head } from '@inertiajs/react';
|
||||
import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Card, CardContent, CardRow } from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import React from 'react';
|
||||
import ExportVito from '@/pages/vito-settings/components/export';
|
||||
import ImportVito from '@/pages/vito-settings/components/import';
|
||||
|
||||
export default function Users() {
|
||||
return (
|
||||
<SettingsLayout>
|
||||
<Head title="Vito Settings" />
|
||||
|
||||
<Container className="max-w-5xl">
|
||||
<div className="flex items-start justify-between">
|
||||
<Heading title="Vito Settings" description="Here you can manage general Vito settings" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent>
|
||||
<CardRow>
|
||||
<span>Export all data</span>
|
||||
<ExportVito />
|
||||
</CardRow>
|
||||
<Separator />
|
||||
<CardRow>
|
||||
<span>Import</span>
|
||||
<ImportVito />
|
||||
</CardRow>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Container>
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user