import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { I18nKey } from "#/i18n/declaration"; import { BrandButton } from "#/components/features/settings/brand-button"; import { SettingsInput } from "#/components/features/settings/settings-input"; import { LoadingSpinner } from "#/components/shared/loading-spinner"; import { CreateApiKeyResponse } from "#/api/api-keys"; import { displayErrorToast, displaySuccessToast, } from "#/utils/custom-toast-handlers"; import { ApiKeyModalBase } from "./api-key-modal-base"; import { useCreateApiKey } from "#/hooks/mutation/use-create-api-key"; interface CreateApiKeyModalProps { isOpen: boolean; onClose: () => void; onKeyCreated: (newKey: CreateApiKeyResponse) => void; } export function CreateApiKeyModal({ isOpen, onClose, onKeyCreated, }: CreateApiKeyModalProps) { const { t } = useTranslation(); const [newKeyName, setNewKeyName] = useState(""); const createApiKeyMutation = useCreateApiKey(); const handleCreateKey = async () => { if (!newKeyName.trim()) { displayErrorToast(t(I18nKey.ERROR$REQUIRED_FIELD)); return; } try { const newKey = await createApiKeyMutation.mutateAsync(newKeyName); onKeyCreated(newKey); displaySuccessToast(t(I18nKey.SETTINGS$API_KEY_CREATED)); setNewKeyName(""); } catch (error) { displayErrorToast(t(I18nKey.ERROR$GENERIC)); } }; const handleCancel = () => { setNewKeyName(""); onClose(); }; const modalFooter = ( <> {createApiKeyMutation.isPending ? ( ) : ( t(I18nKey.BUTTON$CREATE) )} {t(I18nKey.BUTTON$CANCEL)} ); return (

{t(I18nKey.SETTINGS$CREATE_API_KEY_DESCRIPTION)}

setNewKeyName(value)} className="w-full mt-4" type="text" />
); }