forked from infiniflow/infinity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,077 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger | ||
} from '@/components/ui/dialog'; | ||
import React from 'react'; | ||
import { DatabaseCreatingForm } from './database-creating-form'; | ||
|
||
export function DatabaseCreatingDialog({ children }: React.PropsWithChildren) { | ||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild>{children}</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Create Database</DialogTitle> | ||
</DialogHeader> | ||
<div className="grid gap-4 py-4"> | ||
<DatabaseCreatingForm></DatabaseCreatingForm> | ||
</div> | ||
<DialogFooter> | ||
<Button type="submit" form="database-creating"> | ||
Save | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use client'; | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useForm } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
|
||
import { toast } from '@/components/hooks/use-toast'; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage | ||
} from '@/components/ui/form'; | ||
import { Input } from '@/components/ui/input'; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue | ||
} from '@/components/ui/select'; | ||
|
||
export const FormSchema = z.object({ | ||
database_name: z | ||
.string({ | ||
required_error: 'Please input name' | ||
}) | ||
.trim(), | ||
create_option: z.string() | ||
}); | ||
|
||
export function DatabaseCreatingForm() { | ||
const form = useForm<z.infer<typeof FormSchema>>({ | ||
resolver: zodResolver(FormSchema), | ||
defaultValues: { | ||
create_option: 'error' | ||
} | ||
}); | ||
|
||
function onSubmit(data: z.infer<typeof FormSchema>) { | ||
console.log('🚀 ~ onSubmit ~ data:', data); | ||
toast({ | ||
title: 'You submitted the following values:', | ||
description: ( | ||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> | ||
<code className="text-white">{JSON.stringify(data, null, 2)}</code> | ||
</pre> | ||
) | ||
}); | ||
} | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="w-2/3 space-y-6" | ||
id="database-creating" | ||
> | ||
<FormField | ||
control={form.control} | ||
name="database_name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Database name</FormLabel> | ||
<FormControl> | ||
<Input placeholder="name" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="create_option" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Create option</FormLabel> | ||
<Select onValueChange={field.onChange} defaultValue={field.value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select a verified email to display" /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
<SelectItem value="error">error</SelectItem> | ||
<SelectItem value="ignore_if_exists"> | ||
ignore_if_exists | ||
</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
</Form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.