Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.4 KB
Raw Blame
import { useState } from 'react';
import { OGDialog, OGDialogContent, OGDialogHeader, OGDialogTitle } from '@librechat/client';
import type { TAgentApiKeyCreateResponse } from 'librechat-data-provider';
import { useLocalize } from '~/hooks';
import Create from './Create';
import Reveal from './Reveal';

type CreateKeyDialogProps = {
  open: boolean;
  onOpenChange: (open: boolean) => void;
};

export default function CreateKeyDialog({ open, onOpenChange }: CreateKeyDialogProps) {
  const localize = useLocalize();
  const [createdKey, setCreatedKey] = useState<TAgentApiKeyCreateResponse | null>(null);
  const [prevOpen, setPrevOpen] = useState(open);

  if (open !== prevOpen) {
    setPrevOpen(open);
    if (open) {
      setCreatedKey(null);
    }
  }

  return (
    <OGDialog open={open} onOpenChange={onOpenChange}>
      <OGDialogContent
        showCloseButton={false}
        className="w-11/12 max-w-lg"
        aria-describedby={undefined}
      >
        <OGDialogHeader>
          <OGDialogTitle>
            {createdKey != null
              ? localize('com_ui_api_key_created')
              : localize('com_ui_create_api_key')}
          </OGDialogTitle>
        </OGDialogHeader>
        {createdKey != null ? (
          <Reveal createdKey={createdKey} onDone={() => onOpenChange(false)} />
        ) : (
          <Create onCreated={setCreatedKey} onCancel={() => onOpenChange(false)} />
        )}
      </OGDialogContent>
    </OGDialog>
  );
}