allow createTask without projectId
This commit is contained in:
parent
47d9ab355a
commit
13bade9e81
@ -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}`)
|
||||
|
Loading…
Reference in New Issue
Block a user