-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ai chat | api trail feature (#611)
* feat: api trial added * feat: ai chat | fix issues --------- Co-authored-by: Kabir <[email protected]>
- Loading branch information
1 parent
bab72bf
commit 132becd
Showing
7 changed files
with
239 additions
and
9 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
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,92 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { getApiUrl } from "../../../../features/apiUrl"; | ||
import axios from "axios"; | ||
import { useSelector } from "react-redux"; | ||
import { toast } from "react-toastify"; | ||
|
||
export default function SettingsForm() { | ||
const { user } = useSelector((state) => state.auth); | ||
const API_BASE_URL = getApiUrl("api/aiChat"); | ||
|
||
const [geminiProApiKey, setApiKey] = useState({ | ||
value: "", | ||
error: "", | ||
}); | ||
|
||
useEffect(() => { | ||
fetchApiKey(); | ||
}, []); | ||
|
||
async function fetchApiKey() { | ||
const response = await axios.get( | ||
`${API_BASE_URL}/getApiKey`, | ||
|
||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${user.token}`, | ||
}, | ||
}, | ||
); | ||
setApiKey({ | ||
value: response.data, | ||
error: "", | ||
}); | ||
} | ||
|
||
async function handleSubmit(e) { | ||
e.preventDefault(); | ||
|
||
if (!geminiProApiKey.value) { | ||
return setApiKey((curr) => ({ | ||
...curr, | ||
error: "Api Key required!", | ||
})); | ||
} | ||
|
||
const response = await axios.post( | ||
`${API_BASE_URL}/createApiKey`, | ||
{ | ||
geminiProApiKey: geminiProApiKey.value, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${user.token}`, | ||
}, | ||
}, | ||
); | ||
|
||
if (response.data.geminiProApiKey) { | ||
toast("Successfully updated API Key"); | ||
} | ||
} | ||
|
||
function handleChange(e, setState) { | ||
setState(() => ({ | ||
value: e.target.value, | ||
error: "", | ||
})); | ||
} | ||
console.log(geminiProApiKey); | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} className="settings-profile-form"> | ||
<div className="settings-profile-input-wrapper"> | ||
<label htmlFor="geminiProApiKey">Api Key</label> | ||
<br /> | ||
<input | ||
type="text" | ||
value={geminiProApiKey.value || ""} | ||
id="geminiProApiKey" | ||
name="geminiProApiKey" | ||
placeholder="Your API key" | ||
onChange={(e) => handleChange(e, setApiKey)} | ||
/> | ||
</div> | ||
<button type="submit" className="settings-profile-form-submitbtn"> | ||
Submit | ||
</button> | ||
</form> | ||
); | ||
} |
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,64 @@ | ||
.api { | ||
border-bottom: 1px solid #27272a; | ||
max-width: 672px; | ||
padding-block: 1em; | ||
} | ||
|
||
.api-heading { | ||
margin-bottom: 0; | ||
} | ||
|
||
.api-info { | ||
font-size: 14px; | ||
color: #a1a1a1; | ||
} | ||
|
||
.api-form { | ||
padding: 1.75em 0; | ||
max-width: 672px; | ||
} | ||
|
||
.api-input-wrapper { | ||
margin-bottom: 1em; | ||
} | ||
|
||
.api-form input { | ||
background-color: #000000; | ||
outline: none; | ||
border: 1px solid #27272a; | ||
height: 40px; | ||
padding-inline-start: 1em; | ||
border-radius: 6px; | ||
letter-spacing: 0.7px; | ||
color: #ffffff; | ||
width: 100%; | ||
margin-top: 0.5em; | ||
transition: 300ms; | ||
} | ||
|
||
.api-form input:is(:hover, :focus) { | ||
border: 1px solid #ffffff; | ||
} | ||
|
||
.api-form input::placeholder { | ||
color: #a1a1a1; | ||
} | ||
|
||
.newApibtn { | ||
background-color: #ff6b08; | ||
color: #000000; | ||
font-family: Roboto, sans-serif; | ||
/* width: 100%; */ | ||
height: 30px; | ||
border-radius: 6px; | ||
border: 2px solid #ff6b08; | ||
transition: 300ms; | ||
font-weight: 500; | ||
font-size: 16px; | ||
} | ||
|
||
.newApibtn:is(:hover, :focus) { | ||
background-color: #000000; | ||
color: #ff6b08; | ||
cursor: pointer; | ||
} |
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,32 @@ | ||
import React from "react"; | ||
import SettingsForm from "./ApiForm"; | ||
import "./api.css"; | ||
|
||
export default function Api() { | ||
return ( | ||
<section style={{ width: "100%" }}> | ||
<div> | ||
<div className="api"> | ||
<h3 className="api-heading">Api</h3> | ||
<p className="api-info">Entter Your gemini AI Api key.</p> | ||
</div> | ||
|
||
<div className="flex flex-row mt-2"> | ||
<p>Get your API Key:</p> | ||
<a | ||
className="text-white" | ||
href="https://makersuite.google.com/app/apikey" | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<button className="newApibtn ml-2 pl-4 pr-4">Click here</button> | ||
</a> | ||
</div> | ||
|
||
<div> | ||
<SettingsForm /> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} |
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