mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
* Initial plan * Initial exploration - understanding the codebase Co-authored-by: nicotsx <47644445+nicotsx@users.noreply.github.com> * Add "Ironmount - " prefix to all route titles and version in sidebar Co-authored-by: nicotsx <47644445+nicotsx@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nicotsx <47644445+nicotsx@users.noreply.github.com>
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import { useMutation } from "@tanstack/react-query";
|
|
import { Database } from "lucide-react";
|
|
import { useId } from "react";
|
|
import { useNavigate } from "react-router";
|
|
import { toast } from "sonner";
|
|
import { createRepositoryMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
|
import { CreateRepositoryForm, type RepositoryFormValues } from "~/client/components/create-repository-form";
|
|
import { Button } from "~/client/components/ui/button";
|
|
import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card";
|
|
import { parseError } from "~/client/lib/errors";
|
|
import type { Route } from "./+types/create-repository";
|
|
import { Alert, AlertDescription } from "~/client/components/ui/alert";
|
|
|
|
export const handle = {
|
|
breadcrumb: () => [{ label: "Repositories", href: "/repositories" }, { label: "Create" }],
|
|
};
|
|
|
|
export function meta(_: Route.MetaArgs) {
|
|
return [
|
|
{ title: "Ironmount - Create Repository" },
|
|
{
|
|
name: "description",
|
|
content: "Create a new backup repository with encryption and compression.",
|
|
},
|
|
];
|
|
}
|
|
|
|
export default function CreateRepository() {
|
|
const navigate = useNavigate();
|
|
const formId = useId();
|
|
|
|
const createRepository = useMutation({
|
|
...createRepositoryMutation(),
|
|
onSuccess: (data) => {
|
|
toast.success("Repository created successfully");
|
|
navigate(`/repositories/${data.repository.name}`);
|
|
},
|
|
});
|
|
|
|
const handleSubmit = (values: RepositoryFormValues) => {
|
|
createRepository.mutate({
|
|
body: {
|
|
config: values,
|
|
name: values.name,
|
|
compressionMode: values.compressionMode,
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className="container mx-auto space-y-6">
|
|
<Card>
|
|
<CardHeader>
|
|
<div className="flex items-center gap-3">
|
|
<div className="flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10">
|
|
<Database className="w-5 h-5 text-primary" />
|
|
</div>
|
|
<CardTitle>Create Repository</CardTitle>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent className="space-y-6">
|
|
{createRepository.isError && (
|
|
<Alert variant="destructive">
|
|
<AlertDescription>
|
|
<strong>Failed to create repository:</strong>
|
|
<br />
|
|
{parseError(createRepository.error)?.message}
|
|
</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
<CreateRepositoryForm
|
|
mode="create"
|
|
formId={formId}
|
|
onSubmit={handleSubmit}
|
|
loading={createRepository.isPending}
|
|
/>
|
|
<div className="flex justify-end gap-2 pt-4 border-t">
|
|
<Button type="button" variant="secondary" onClick={() => navigate("/repositories")}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" form={formId} loading={createRepository.isPending}>
|
|
Create Repository
|
|
</Button>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|