From 13bade9e81077b40bdf6219dd41f7134ab67e042 Mon Sep 17 00:00:00 2001 From: notnull Date: Wed, 26 Jun 2019 07:37:44 -0400 Subject: [PATCH] allow createTask without projectId --- src/controllers/tasks.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/controllers/tasks.js b/src/controllers/tasks.js index 6a48a42..0c1b4fb 100644 --- a/src/controllers/tasks.js +++ b/src/controllers/tasks.js @@ -3,15 +3,19 @@ const API = process.env.REACT_APP_API || 'http://localhost:1337' export async function createTask(e) { e.preventDefault() - if (!this.state.selectedProjectId) { + if (this.state.newTask === '') { + alert("Why don't you enter a name for this task?") + return + } + { + /*if (!this.state.selectedProjectId) { alert('No project selected, silly!') return + }*/ } const newTask = { desc: this.state.newTask, - projectName: this.state.projects.find( - p => p.id === this.state.selectedProjectId, - )['name'], + projectId: this.state.selectedProjectId, // TODO // the backend expects projectName because it creates the project on the fly if none exists with that name // this feature comes at the price that there can't be two independent projects with the same name @@ -20,20 +24,23 @@ export async function createTask(e) { if (newTask.desc === '') { alert('Task description is empty.') return - } else if (!newTask.projectName) { + } + { + /*} else if (!newTask.projectName) { alert('Select a project for new task.') return + }*/ } try { console.log('Adding task: ', newTask) const { data, error } = await axios.post(API + '/api/tasks', newTask) if (error) { alert('Received error when adding task: ', error) - } else if (data.desc && data.projectId) { + } else if (data.desc) { console.log('Successfully added task:', data) this.setState({ tasks: this.state.tasks.concat(data), newTask: '' }) } else { - console.log('Received malformed data for added task: ', data) + alert('Received malformed data for added task: ', data) } } catch (e) { alert(`Failed to add task: ${e}`)