mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
Added the integration with Clockify and validate the API key introduced
This commit is contained in:
@@ -5,6 +5,7 @@ import {getAuth, onAuthStateChanged} from 'firebase/auth'
|
||||
const Account = () => {
|
||||
|
||||
const [signIn, setSignIn] = useState('false')
|
||||
const [apiKey, setApiKey] = useState('')
|
||||
|
||||
const auth = getAuth()
|
||||
|
||||
@@ -16,12 +17,75 @@ const Account = () => {
|
||||
setSignIn(false)
|
||||
}
|
||||
})
|
||||
|
||||
const uploadApiKey = async (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
const data = await makeRequest()
|
||||
console.log(data)
|
||||
|
||||
if (await validateRequest(data)) {
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const makeRequest = async () => {
|
||||
try {
|
||||
const request = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'X-Api-Key': apiKey,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
const response = await fetch(`https://api.clockify.me/api/v1/workspaces/`, request)
|
||||
const data = await response.json()
|
||||
|
||||
return await data
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
const validateRequest = async (data) => {
|
||||
if (data.code !== 1000) {
|
||||
console.log('TODO BIEN')
|
||||
return true
|
||||
} else {
|
||||
console.log('TODO MAL')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
signIn ?
|
||||
<h1>Insert your Clockify API here</h1> :
|
||||
<div>
|
||||
<h1>One more step...</h1>
|
||||
<h2>Insert your Clockify API here</h2>
|
||||
<form
|
||||
onSubmit={uploadApiKey}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
onChange=
|
||||
{
|
||||
(e) => {setApiKey(e.target.value)}
|
||||
}
|
||||
/>
|
||||
|
||||
<input
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
</div>:
|
||||
<h1>Sign in before access to this page...</h1>
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user