/* * Copyright (c) 2021 - 2025, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { Fragment } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { XMarkIcon } from "@heroicons/react/24/solid"; import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react"; import type { FieldProps } from "formik"; import { Field, Form, Formik, FormikErrors, FormikValues } from "formik"; import { APIClient } from "@api/APIClient"; import { ApiKeys } from "@api/query_keys"; import { DEBUG } from "@components/debug"; import { toast } from "@components/hot-toast"; import Toast from "@components/notifications/Toast"; import { AddFormProps } from "@forms/_shared"; export function APIKeyAddForm({ isOpen, toggle }: AddFormProps) { const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: (apikey: APIKey) => APIClient.apikeys.create(apikey), onSuccess: (_, key) => { queryClient.invalidateQueries({ queryKey: ApiKeys.lists() }); toast.custom((t) => ); toggle(); } }); const handleSubmit = (data: unknown) => mutation.mutate(data as APIKey); const validate = (values: FormikValues) => { const errors = {} as FormikErrors; if (!values.name) { errors.name = "Required"; } return errors; }; return (
{({ values }) => (
Create API key

Add new API key.

{({ field, meta }: FieldProps) => (
{meta.touched && meta.error && {meta.error}}
)}
)}
); }