File size: 2,398 Bytes
5f07a23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { useState } from 'react';

const ApiKeyModal = ({ isOpen, onClose, onSubmit, initialValue = '' }) => {
  const [apiKey, setApiKey] = useState(initialValue);
  
  if (!isOpen) return null;
  
  return (
    <div 
      className="fixed inset-0 bg-black bg-opacity-30 flex items-center justify-center z-50 modalBackdrop"
      onClick={(e) => {
        if (e.target.classList.contains('modalBackdrop')) {
          onClose();
        }
      }}
    >
      <div className="bg-white p-6 rounded-xl shadow-medium max-w-md w-full">
        <h2 className="text-xl font-medium text-gray-800 mb-4">API Key Required</h2>
        
        <p className="text-sm text-gray-600 mb-6">
          You've reached the limit of free Gemini API calls. To continue using this feature, please enter your own Gemini API key below.
          You can get a free API key from <a href="https://ai.google.dev/" target="_blank" rel="noopener noreferrer" className="text-blue-500 hover:underline">Google AI Studio</a>.
        </p>
        
        <form onSubmit={(e) => {
          e.preventDefault();
          onSubmit(apiKey);
        }}>
          <div className="mb-4">
            <label htmlFor="apiKey" className="block text-sm font-medium text-gray-700 mb-1">
              Gemini API Key
            </label>
            <input
              id="apiKey"
              type="text"
              value={apiKey}
              onChange={(e) => setApiKey(e.target.value)}
              className="w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
              placeholder="AIza..."
              required
            />
          </div>
          
          <div className="flex justify-end gap-3 mt-6">
            <button
              type="button"
              onClick={onClose}
              className="px-3 py-2 border border-gray-200 rounded-lg text-gray-600 hover:border-gray-300 hover:bg-gray-50 text-sm font-medium"
            >
              Cancel
            </button>
            <button
              type="submit"
              disabled={!apiKey.trim()}
              className="px-3 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 text-sm font-medium"
            >
              Save API Key
            </button>
          </div>
        </form>
      </div>
    </div>
  );
};

export default ApiKeyModal;