mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
Changed the way is cleared the childrens of the clockify form
This commit is contained in:
@@ -116,7 +116,6 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
||||
const response = await fetch(`https://api.clockify.me/api/v1/workspaces/${e}/projects`, request)
|
||||
const data = await response.json()
|
||||
|
||||
console.log(data);
|
||||
changeClockifyData({projects: data})
|
||||
|
||||
} catch (error) {
|
||||
@@ -127,8 +126,6 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
||||
async function getTasks(projectID) {
|
||||
|
||||
if (projectID === "0") {
|
||||
changeClockifyData({projectID: undefined})
|
||||
changeClockifyData({tasks: undefined})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -226,13 +223,7 @@ const ClockifyTaskForm = ({timerOn, setTimerOn, signedIn, apiKey, setApiKey, tas
|
||||
</select>
|
||||
|
||||
<select
|
||||
onChange={(e) => {
|
||||
if (e.target.value === "0") {
|
||||
changeClockifyData({taskID: undefined})
|
||||
} else {
|
||||
changeClockifyData({taskID: e.target.value})
|
||||
}
|
||||
}}
|
||||
onChange={(e) => changeClockifyData({taskID: e.target.value})}
|
||||
className={`project-selector ${(!clockifyData.projectID || (clockifyData.tasks && clockifyData.tasks.length === 0)) && 'disabled'}`}
|
||||
>
|
||||
<option value="0">Select a Task</option>
|
||||
|
||||
@@ -11,6 +11,34 @@ const Main = ({signedIn, darkMode, setKonamiCodeActive, KonamiCodeActive, notifi
|
||||
const [clockifyData, setClockifyData] = useState({})
|
||||
|
||||
function changeClockifyData(obj) {
|
||||
|
||||
//* Module for clean the children propierties if father propierty changes
|
||||
|
||||
// Select all propierties of user
|
||||
const propierties = ["workspaces", "workspaceID", "projects", "projectID", "tasks", "taskID"]
|
||||
|
||||
propierties.forEach((propierty, index) => {
|
||||
|
||||
// If obj have some of the propierties, create a subarray selecting all childrens
|
||||
if (obj.hasOwnProperty(propierty)) {
|
||||
|
||||
const subArray = propierties.slice(index + 1)
|
||||
|
||||
// Undefine all childrens
|
||||
subArray.forEach(subPropierty => {
|
||||
obj[subPropierty] = undefined
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
//* Module for undefine the propierty if value is "0": string
|
||||
|
||||
propierties.forEach(propierty => {
|
||||
if (obj[propierty] === "0") {
|
||||
obj[propierty] = undefined
|
||||
}
|
||||
})
|
||||
|
||||
setClockifyData(clockifyData => ({
|
||||
...clockifyData,
|
||||
...obj
|
||||
|
||||
Reference in New Issue
Block a user