({ isOpen, onClose, onSubmit }: ApiKeyDialogProps)
| 13 | } |
| 14 | |
| 15 | export function ApiKeyDialog({ isOpen, onClose, onSubmit }: ApiKeyDialogProps) { |
| 16 | const [apiKey, setApiKey] = useState<string>(""); |
| 17 | |
| 18 | useEffect(() => { |
| 19 | const storedKey = localStorage.getItem("openai_key"); |
| 20 | if (storedKey) { |
| 21 | setApiKey(storedKey); |
| 22 | } |
| 23 | }, []); |
| 24 | |
| 25 | const handleSubmit = (e: React.FormEvent) => { |
| 26 | e.preventDefault(); |
| 27 | onSubmit(apiKey); |
| 28 | setApiKey(""); |
| 29 | }; |
| 30 | |
| 31 | const handleClear = () => { |
| 32 | localStorage.removeItem("openai_key"); |
| 33 | setApiKey(""); |
| 34 | }; |
| 35 | |
| 36 | return ( |
| 37 | <Dialog open={isOpen} onOpenChange={onClose}> |
| 38 | <DialogContent className="border-[3px] border-black bg-green-200 p-6 shadow-[8px_8px_0_0_#000000] sm:max-w-md"> |
| 39 | <DialogHeader> |
| 40 | <DialogTitle className="text-xl font-bold text-black"> |
| 41 | Enter OpenAI API Key |
| 42 | </DialogTitle> |
| 43 | </DialogHeader> |
| 44 | <form onSubmit={handleSubmit} className="space-y-4"> |
| 45 | <div className="text-sm"> |
| 46 | Solidity Visualizer requires an OpenAI API key to generate diagrams. |
| 47 | The diagrams will be generated using your API key and billed to your OpenAI account. |
| 48 | <br /> |
| 49 | <br /> |
| 50 | <span className="font-medium">Get your OpenAI API key </span> |
| 51 | <Link |
| 52 | href="https://platform.openai.com/api-keys" |
| 53 | className="font-medium text-green-600 transition-colors duration-200 hover:text-green-500" |
| 54 | > |
| 55 | here |
| 56 | </Link> |
| 57 | . |
| 58 | </div> |
| 59 | <details className="group text-sm [&>summary:focus-visible]:outline-none"> |
| 60 | <summary className="cursor-pointer font-medium text-green-700 hover:text-green-600"> |
| 61 | Data storage disclaimer |
| 62 | </summary> |
| 63 | <div className="animate-accordion-down mt-2 space-y-2 overflow-hidden pl-2"> |
| 64 | <p> |
| 65 | Your API key will be stored locally in your browser and used |
| 66 | only for generating diagrams. You can also self-host this app by |
| 67 | following the instructions in the{" "} |
| 68 | <Link |
| 69 | href="https://github.com/VGabriel45/solidityVisualizer" |
| 70 | className="text-green-600 transition-colors duration-200 hover:text-green-500" |
| 71 | > |
| 72 | README |
nothing calls this directly
no outgoing calls
no test coverage detected