mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
Merge pull request #2 from FranP-code/1-failure-on-multiple-clients
#1 failure on multiple clients
This commit is contained in:
@@ -102,9 +102,7 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
|||||||
changeClockifyData({workspaces: workspaces})
|
changeClockifyData({workspaces: workspaces})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getProjects = async (e) => {
|
const getProjects = async (e) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const request = {
|
const request = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -115,27 +113,22 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
|||||||
}
|
}
|
||||||
const response = await fetch(`https://api.clockify.me/api/v1/workspaces/${e}/projects`, request)
|
const response = await fetch(`https://api.clockify.me/api/v1/workspaces/${e}/projects`, request)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
data.clients = {}
|
||||||
data.forEach((project, index) => {
|
data.forEach((project) => {
|
||||||
if (project.clientName !== "" && !project.archived) {
|
if (project.clientName.length && !project.archived) {
|
||||||
|
const isClientDefined = !!data.clients[project.clientName]
|
||||||
if (!data.clients) {
|
if (!isClientDefined) {
|
||||||
data.clients = {[project.clientName]: [project]}
|
data.clients[project.clientName] = []
|
||||||
} else {
|
|
||||||
data.clients[project.clientName].push(project)
|
|
||||||
}
|
}
|
||||||
|
data.clients[project.clientName].push(project)
|
||||||
project.archived = true
|
project.hide = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
changeClockifyData({projects: data})
|
changeClockifyData({projects: data})
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTasks(projectID) {
|
async function getTasks(projectID) {
|
||||||
|
|
||||||
if (projectID === "0") {
|
if (projectID === "0") {
|
||||||
@@ -227,9 +220,8 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
|||||||
{
|
{
|
||||||
clockifyData.projects &&
|
clockifyData.projects &&
|
||||||
clockifyData.projects.map((project) => (
|
clockifyData.projects.map((project) => (
|
||||||
!project.archived ?
|
!project.archived && !project.hide &&
|
||||||
<option value={project.id} key={project.id} style={{color: project.color}}>{project.name}</option>
|
<option value={project.id} key={project.id} style={{color: project.color}}>{project.name}</option>
|
||||||
: null
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user