fix(create-repo): directory selection

This commit is contained in:
Nicolas Meienberger 2026-02-02 20:34:37 +01:00
parent cc081ca64c
commit 1e5921fa61

View file

@ -3,7 +3,7 @@ import type { UseFormReturn } from "react-hook-form";
import { Check, Pencil, X, AlertTriangle } from "lucide-react"; import { Check, Pencil, X, AlertTriangle } from "lucide-react";
import { REPOSITORY_BASE } from "~/client/lib/constants"; import { REPOSITORY_BASE } from "~/client/lib/constants";
import { Button } from "../../../../components/ui/button"; import { Button } from "../../../../components/ui/button";
import { FormItem, FormLabel, FormDescription } from "../../../../components/ui/form"; import { FormItem, FormLabel, FormDescription, FormField, FormControl } from "../../../../components/ui/form";
import { DirectoryBrowser } from "../../../../components/directory-browser"; import { DirectoryBrowser } from "../../../../components/directory-browser";
import { import {
AlertDialog, AlertDialog,
@ -26,18 +26,24 @@ export const LocalRepositoryForm = ({ form }: Props) => {
const [showPathWarning, setShowPathWarning] = useState(false); const [showPathWarning, setShowPathWarning] = useState(false);
return ( return (
<FormField
control={form.control}
name="path"
render={({ field }) => (
<> <>
<FormItem> <FormItem>
<FormLabel>Repository Directory</FormLabel> <FormLabel>Repository Directory</FormLabel>
<FormControl>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<div className="flex-1 text-sm font-mono bg-muted px-3 py-2 rounded-md border"> <div className="flex-1 text-sm font-mono bg-muted px-3 py-2 rounded-md border">
{form.watch("path") || REPOSITORY_BASE} {field.value || REPOSITORY_BASE}
</div> </div>
<Button type="button" variant="outline" onClick={() => setShowPathWarning(true)} size="sm"> <Button type="button" variant="outline" onClick={() => setShowPathWarning(true)} size="sm">
<Pencil className="h-4 w-4 mr-2" /> <Pencil className="h-4 w-4 mr-2" />
Change Change
</Button> </Button>
</div> </div>
</FormControl>
<FormDescription>The directory where the repository will be stored.</FormDescription> <FormDescription>The directory where the repository will be stored.</FormDescription>
</FormItem> </FormItem>
@ -54,8 +60,8 @@ export const LocalRepositoryForm = ({ form }: Props) => {
If the path is not a host mount, you will lose your repository data when the container restarts. If the path is not a host mount, you will lose your repository data when the container restarts.
</p> </p>
<p className="text-sm text-muted-foreground"> <p className="text-sm text-muted-foreground">
The default path <code className="bg-muted px-1 rounded">{REPOSITORY_BASE}</code> is safe to use if you The default path <code className="bg-muted px-1 rounded">{REPOSITORY_BASE}</code> is safe to use if
followed the recommended Docker Compose setup. you followed the recommended Docker Compose setup.
</p> </p>
</AlertDialogDescription> </AlertDialogDescription>
</AlertDialogHeader> </AlertDialogHeader>
@ -83,8 +89,10 @@ export const LocalRepositoryForm = ({ form }: Props) => {
</AlertDialogHeader> </AlertDialogHeader>
<div className="py-4"> <div className="py-4">
<DirectoryBrowser <DirectoryBrowser
onSelectPath={(path) => form.setValue("path", path)} onSelectPath={(path) => {
selectedPath={form.watch("path") || REPOSITORY_BASE} field.onChange(path);
}}
selectedPath={field.value || REPOSITORY_BASE}
/> />
</div> </div>
<AlertDialogFooter> <AlertDialogFooter>
@ -100,5 +108,7 @@ export const LocalRepositoryForm = ({ form }: Props) => {
</AlertDialogContent> </AlertDialogContent>
</AlertDialog> </AlertDialog>
</> </>
)}
/>
); );
}; };