|
@@ -0,0 +1,174 @@
|
|
|
+"use client"
|
|
|
+
|
|
|
+import Link from "next/link"
|
|
|
+import { zodResolver } from "@hookform/resolvers/zod"
|
|
|
+import { useFieldArray, useForm } from "react-hook-form"
|
|
|
+import { z } from "zod"
|
|
|
+
|
|
|
+import { cn } from "@/lib/utils"
|
|
|
+import { toast } from "@/hooks/use-toast"
|
|
|
+
|
|
|
+import { Button } from "@/components/ui/button"
|
|
|
+import {
|
|
|
+ Form,
|
|
|
+ FormControl,
|
|
|
+ FormDescription,
|
|
|
+ FormField,
|
|
|
+ FormItem,
|
|
|
+ FormLabel,
|
|
|
+ FormMessage,
|
|
|
+} from "@/components/ui/form"
|
|
|
+import { Input } from "@/components/ui/input"
|
|
|
+import {
|
|
|
+ Select,
|
|
|
+ SelectContent,
|
|
|
+ SelectItem,
|
|
|
+ SelectTrigger,
|
|
|
+ SelectValue,
|
|
|
+} from "@/components/ui/select"
|
|
|
+import { Textarea } from "@/components/ui/textarea"
|
|
|
+import { useSiteContext } from "@app/hooks/useSiteContext"
|
|
|
+import api from "@app/api"
|
|
|
+
|
|
|
+const GeneralFormSchema = z.object({
|
|
|
+ name: z.string()
|
|
|
+ // email: z
|
|
|
+ // .string({
|
|
|
+ // required_error: "Please select an email to display.",
|
|
|
+ // })
|
|
|
+ // .email(),
|
|
|
+ // bio: z.string().max(160).min(4),
|
|
|
+ // urls: z
|
|
|
+ // .array(
|
|
|
+ // z.object({
|
|
|
+ // value: z.string().url({ message: "Please enter a valid URL." }),
|
|
|
+ // })
|
|
|
+ // )
|
|
|
+ // .optional(),
|
|
|
+})
|
|
|
+
|
|
|
+type GeneralFormValues = z.infer<typeof GeneralFormSchema>
|
|
|
+
|
|
|
+export function GeneralForm() {
|
|
|
+ const { site, updateSite } = useSiteContext();
|
|
|
+
|
|
|
+ const form = useForm<GeneralFormValues>({
|
|
|
+ resolver: zodResolver(GeneralFormSchema),
|
|
|
+ defaultValues: {
|
|
|
+ name: site?.name
|
|
|
+ },
|
|
|
+ mode: "onChange",
|
|
|
+ })
|
|
|
+
|
|
|
+ // const { fields, append } = useFieldArray({
|
|
|
+ // name: "urls",
|
|
|
+ // control: form.control,
|
|
|
+ // })
|
|
|
+
|
|
|
+ async function onSubmit(data: GeneralFormValues) {
|
|
|
+ await updateSite({ name: data.name });
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <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 {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormDescription>
|
|
|
+ This is the display name of the site.
|
|
|
+ </FormDescription>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ {/* <FormField
|
|
|
+ control={form.control}
|
|
|
+ name="email"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>Email</FormLabel>
|
|
|
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
|
|
|
+ <FormControl>
|
|
|
+ <SelectTrigger>
|
|
|
+ <SelectValue placeholder="Select a verified email to display" />
|
|
|
+ </SelectTrigger>
|
|
|
+ </FormControl>
|
|
|
+ <SelectContent>
|
|
|
+ <SelectItem value="m@example.com">m@example.com</SelectItem>
|
|
|
+ <SelectItem value="m@google.com">m@google.com</SelectItem>
|
|
|
+ <SelectItem value="m@support.com">m@support.com</SelectItem>
|
|
|
+ </SelectContent>
|
|
|
+ </Select>
|
|
|
+ <FormDescription>
|
|
|
+ You can manage verified email addresses in your{" "}
|
|
|
+ <Link href="/examples/forms">email settings</Link>.
|
|
|
+ </FormDescription>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ <FormField
|
|
|
+ control={form.control}
|
|
|
+ name="bio"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel>Bio</FormLabel>
|
|
|
+ <FormControl>
|
|
|
+ <Textarea
|
|
|
+ placeholder="Tell us a little bit about yourself"
|
|
|
+ className="resize-none"
|
|
|
+ {...field}
|
|
|
+ />
|
|
|
+ </FormControl>
|
|
|
+ <FormDescription>
|
|
|
+ You can <span>@mention</span> other users and organizations to
|
|
|
+ link to them.
|
|
|
+ </FormDescription>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ <div>
|
|
|
+ {fields.map((field, index) => (
|
|
|
+ <FormField
|
|
|
+ control={form.control}
|
|
|
+ key={field.id}
|
|
|
+ name={`urls.${index}.value`}
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ <FormLabel className={cn(index !== 0 && "sr-only")}>
|
|
|
+ URLs
|
|
|
+ </FormLabel>
|
|
|
+ <FormDescription className={cn(index !== 0 && "sr-only")}>
|
|
|
+ Add links to your website, blog, or social media profiles.
|
|
|
+ </FormDescription>
|
|
|
+ <FormControl>
|
|
|
+ <Input {...field} />
|
|
|
+ </FormControl>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ <Button
|
|
|
+ type="button"
|
|
|
+ variant="outline"
|
|
|
+ size="sm"
|
|
|
+ className="mt-2"
|
|
|
+ onClick={() => append({ value: "" })}
|
|
|
+ >
|
|
|
+ Add URL
|
|
|
+ </Button>
|
|
|
+ </div> */}
|
|
|
+ <Button type="submit">Update Site</Button>
|
|
|
+ </form>
|
|
|
+ </Form>
|
|
|
+ )
|
|
|
+}
|