({ compact = false, onSaved })
| 4 | import './MapsKeySetup.css'; |
| 5 | |
| 6 | export default function MapsKeySetup({ compact = false, onSaved }) { |
| 7 | const { setGoogleMapsApiKey, googleMapsApiKeySource, setMapProvider } = |
| 8 | useAppConfig(); |
| 9 | const [value, setValue] = useState(''); |
| 10 | const [error, setError] = useState(''); |
| 11 | |
| 12 | const handleUseOSM = async () => { |
| 13 | await setMapProvider('osm'); |
| 14 | onSaved?.(); |
| 15 | }; |
| 16 | |
| 17 | const handleSubmit = (e) => { |
| 18 | e.preventDefault(); |
| 19 | const trimmed = value.trim(); |
| 20 | if (!trimmed) { |
| 21 | setError('Paste your Google Maps API key first.'); |
| 22 | return; |
| 23 | } |
| 24 | setGoogleMapsApiKey(trimmed); |
| 25 | setValue(''); |
| 26 | setError(''); |
| 27 | onSaved?.(); |
| 28 | }; |
| 29 | |
| 30 | return ( |
| 31 | <div className={`maps-setup ${compact ? 'compact' : ''}`}> |
| 32 | <div className="maps-setup-card"> |
| 33 | <div className="maps-setup-icon"> |
| 34 | <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"> |
| 35 | <path d="M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 1 1 18 0z" /> |
| 36 | <circle cx="12" cy="10" r="3" /> |
| 37 | </svg> |
| 38 | </div> |
| 39 | <h2>Connect Google Maps</h2> |
| 40 | <p className="maps-setup-sub"> |
| 41 | The map needs a Google Maps JavaScript API key. Your key stays on this |
| 42 | device — it never gets sent anywhere or stored in project files. |
| 43 | </p> |
| 44 | |
| 45 | <form onSubmit={handleSubmit} className="maps-setup-form"> |
| 46 | <label htmlFor="gmaps-key">Google Maps API key</label> |
| 47 | <input |
| 48 | id="gmaps-key" |
| 49 | type="text" |
| 50 | autoComplete="off" |
| 51 | spellCheck="false" |
| 52 | value={value} |
| 53 | onChange={(e) => setValue(e.target.value)} |
| 54 | placeholder="AIza..." |
| 55 | /> |
| 56 | {error && <div className="maps-setup-error">{error}</div>} |
| 57 | <div className="maps-setup-actions"> |
| 58 | <button type="submit" className="btn btn-primary"> |
| 59 | Save key |
| 60 | </button> |
| 61 | </div> |
| 62 | </form> |
| 63 |
nothing calls this directly
no test coverage detected