mirror of
https://github.com/SkalaraAI/beta.git
synced 2025-04-09 15:00:20 -04:00
102 lines
2.4 KiB
TypeScript
102 lines
2.4 KiB
TypeScript
"use client";
|
|
import * as z from "zod";
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from "@/components/ui/form";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
const formSchema = z.object({
|
|
name: z.string().min(2, {
|
|
message: "Name must be at least 2 characters.",
|
|
}),
|
|
description: z
|
|
.string()
|
|
.min(2, {
|
|
message: "Description must be at least 2 characters.",
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
export function CreateFeature({
|
|
workspaceID,
|
|
projectID,
|
|
}: {
|
|
workspaceID: string;
|
|
projectID: string;
|
|
}) {
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
name: "",
|
|
description: "",
|
|
},
|
|
});
|
|
|
|
async function onSubmit(values: z.infer<typeof formSchema>) {
|
|
try {
|
|
const res = await fetch(`/w/${workspaceID}/p/${projectID}/feature`, {
|
|
method: "POST",
|
|
body: JSON.stringify(values),
|
|
});
|
|
|
|
console.log("===>", res);
|
|
|
|
if (!res.ok) throw new Error("Something went wrong.");
|
|
|
|
return res;
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Name</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="" {...field} />
|
|
</FormControl>
|
|
<FormDescription>This is your feature name.</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="description"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Description</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="" {...field} />
|
|
</FormControl>
|
|
<FormDescription>
|
|
This is your feature description.
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<Button type="submit">Submit</Button>
|
|
</form>
|
|
</Form>
|
|
</div>
|
|
);
|
|
}
|