⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat(web): add create api key dialog component
Andrej Acevski2a1ea9b38253
diff --git a/apps/web/src/components/settings/create-api-key-dialog.tsx b/apps/web/src/components/settings/create-api-key-dialog.tsxnew file mode 100644index 000000000..8646b6296--- /dev/null+++ b/apps/web/src/components/settings/create-api-key-dialog.tsx@@ -0,0 +1,144 @@+import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";+import { useState } from "react";+import { useForm } from "react-hook-form";+import { toast } from "sonner";+import { z } from "zod";+import useCreateApiKey from "@/hooks/mutations/api-key/use-create-api-key";+import type { CreateApiKeyResponse } from "@/types/api-key";+import { Button } from "../ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "../ui/dialog";+import {+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "../ui/form";+import { Input } from "../ui/input";++const createApiKeySchema = z.object({+ name: z+ .string()+ .min(1, "Name is required")+ .min(3, "Name must be at least 3 characters"),+});++type FormValues = z.infer<typeof createApiKeySchema>;++interface CreateApiKeyDialogProps {+ open: boolean;+ onClose: () => void;+ onSuccess: (data: CreateApiKeyResponse) => void;+}++export function CreateApiKeyDialog({+ open,+ onClose,+ onSuccess,+}: CreateApiKeyDialogProps) {+ const { mutateAsync: createApiKey } = useCreateApiKey();+ const [isSubmitting, setIsSubmitting] = useState(false);++ const form = useForm<FormValues>({+ resolver: standardSchemaResolver(createApiKeySchema),+ defaultValues: {+ name: "",+ },+ });++ const onSubmit = async (data: FormValues) => {+ setIsSubmitting(true);+ try {+ const result = await createApiKey({+ name: data.name,+ });++ form.reset();+ onSuccess(result);+ onClose();+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to create API key",+ );+ } finally {+ setIsSubmitting(false);+ }+ };++ const handleClose = () => {+ if (!isSubmitting) {+ form.reset();+ onClose();+ }+ };++ return (+ <Dialog open={open} onOpenChange={handleClose}>+ <DialogContent className="sm:max-w-md">+ <DialogHeader>+ <DialogTitle>Create API Key</DialogTitle>+ <DialogDescription>+ Create a new API key to access the Kaneo API programmatically.+ </DialogDescription>+ </DialogHeader>++ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(onSubmit)}+ className="space-y-4 px-6"+ >+ <FormField+ control={form.control}+ name="name"+ render={({ field }) => (+ <FormItem>+ <FormLabel className="text-xs">Name</FormLabel>+ <FormControl>+ <Input+ placeholder="My API Key"+ {...field}+ disabled={isSubmitting}+ className="h-8 text-sm"+ />+ </FormControl>+ <FormDescription className="text-xs">+ A descriptive name for this API key+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />++ <DialogFooter className="gap-2 sm:gap-2">+ <Button+ type="button"+ variant="outline"+ onClick={handleClose}+ disabled={isSubmitting}+ className="h-8 text-xs"+ >+ Cancel+ </Button>+ <Button+ type="submit"+ disabled={isSubmitting}+ className="h-8 text-xs"+ >+ {isSubmitting ? "Creating..." : "Create"}+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}