"use client"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; 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 { READ_SCOPES, WRITE_SCOPES, ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES, } from "@/lib/utils"; import ScopeSection from "./ScopeSection"; export type MethodType = | "read" | "write" | "follow" | "crypto" | "follow" | "admin" | "push"; export interface ScopeInfo { method: MethodType; label: string; scopes?: string[] | string[][]; description: string; } const scopesInfo: ScopeInfo[] = [ { method: "read", label: 'Read', scopes: READ_SCOPES, description: "read account's data", }, { method: "write", label: 'Write', scopes: WRITE_SCOPES, description: "modify account's data", }, { method: "follow", label: 'Follow', description: "modify account relationships,deprecated in 3.5.0 and newer.", }, { method: "push", label: "Push", description: "receive push notifications", }, { method: "admin", label: 'Admin', scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES], description: "read all data on the server", }, { method: "crypto", label: "Crypto", description: "use end-to-end encryption", }, ]; const formSchema = z.object({ instance: z.string().trim(), clientName: z.string().trim(), redirectUris: z.string().url().trim(), scopes: z.string().array().nonempty().optional(), website: z.string().trim().optional(), }); const InputForm = () => { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { instance: "https://", clientName: "", redirectUris: "", }, }); function onSubmit(values: z.infer) { console.log(values); } return (
( Instance )} /> ( Application name )} /> ( Application Website )} /> ( Redirect URI Use{" "} urn:ietf:wg:oauth:2.0:oob {" "} for local tests )} /> ( Scopes (
{scopesInfo.map((info) => ( ))}
)} >
)} /> ); }; export default InputForm;