-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
385 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useState } from 'react'; | ||
|
||
interface KeyFormProps { | ||
keyName: string; | ||
keyValue: string; | ||
setKeyValue: (key: string) => void; | ||
} | ||
|
||
import { CheckIcon } from '@heroicons/react/20/solid'; | ||
|
||
const KeyForm: React.FC<KeyFormProps> = ({ | ||
keyName, | ||
keyValue, | ||
setKeyValue, | ||
}) => { | ||
const [isFocused, setIsFocused] = useState(false); | ||
|
||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
setKeyValue(keyValue); | ||
}; | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setKeyValue(event.target.value); | ||
}; | ||
|
||
const handleFocus = () => { | ||
setIsFocused(true); | ||
}; | ||
|
||
const handleBlur = () => { | ||
setIsFocused(false); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<div className="relative"> | ||
<p className="text-white text-sm font-medium mb-2"> | ||
{keyName.charAt(0).toUpperCase() + keyName.slice(1)} | ||
</p> | ||
<div className="relative"> | ||
<input | ||
type="password" | ||
value={keyValue} | ||
onChange={handleChange} | ||
onFocus={handleFocus} | ||
onBlur={handleBlur} | ||
placeholder={`Enter ${keyName}`} | ||
className="w-full pr-10 py-3 text-sm text-gray-300 placeholder-gray-500 bg-gray-800 border border-gray-700 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" | ||
/> | ||
{isFocused && ( | ||
<button | ||
type="submit" | ||
className="absolute inset-y-0 right-0 flex items-center mr-2 focus:outline-none" | ||
> | ||
<CheckIcon className="h-5 w-5 text-green-500 hover:text-green-600 transition-colors duration-200" /> | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default KeyForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { getItem } from '@/libs/localStorageKeys'; | ||
|
||
interface Keys { | ||
openAIapiKey: string; | ||
setOpenAIapiKey: React.Dispatch<React.SetStateAction<string>>; | ||
pineconeApiKey: string; | ||
setPineconeApiKey: React.Dispatch<React.SetStateAction<string>>; | ||
pineconeEnvironment: string; | ||
setPineconeEnvironment: React.Dispatch<React.SetStateAction<string>>; | ||
pineconeIndexName: string; | ||
setPineconeIndexName: React.Dispatch<React.SetStateAction<string>>; | ||
} | ||
|
||
const useApiKeys = (): Keys => { | ||
const [openAIapiKey, setOpenAIapiKey] = useState<string>(''); | ||
const [pineconeApiKey, setPineconeApiKey] = useState<string>(''); | ||
const [pineconeEnvironment, setPineconeEnvironment] = useState<string>(''); | ||
const [pineconeIndexName, setPineconeIndexName] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
const storedOpenAIKey = getItem('openAIapiKey'); | ||
const storedPineconeKey = getItem('pineconeApiKey'); | ||
const storedPineconeEnvironment = getItem('pineconeEnvironment'); | ||
const storedPineconeIndexName = getItem('pineconeIndexName'); | ||
|
||
if (storedOpenAIKey) { | ||
setOpenAIapiKey(storedOpenAIKey); | ||
} | ||
if (storedPineconeKey) { | ||
setPineconeApiKey(storedPineconeKey); | ||
} | ||
if (storedPineconeEnvironment) { | ||
setPineconeEnvironment(storedPineconeEnvironment); | ||
} | ||
if (storedPineconeIndexName) { | ||
setPineconeIndexName(storedPineconeIndexName); | ||
} | ||
}, []); | ||
|
||
return { | ||
openAIapiKey, | ||
setOpenAIapiKey, | ||
pineconeApiKey, | ||
setPineconeApiKey, | ||
pineconeEnvironment, | ||
setPineconeEnvironment, | ||
pineconeIndexName, | ||
setPineconeIndexName, | ||
}; | ||
}; | ||
|
||
export default useApiKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const setItem = (key: string, value: string) => { | ||
window.localStorage.setItem(key, value); | ||
}; | ||
|
||
export const getItem = (key: string) => { | ||
return window.localStorage.getItem(key); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.