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) {
|
export async function createTask(e) {
|
||||||
e.preventDefault()
|
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!')
|
alert('No project selected, silly!')
|
||||||
return
|
return
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
const newTask = {
|
const newTask = {
|
||||||
desc: this.state.newTask,
|
desc: this.state.newTask,
|
||||||
projectName: this.state.projects.find(
|
projectId: this.state.selectedProjectId,
|
||||||
p => p.id === this.state.selectedProjectId,
|
|
||||||
)['name'],
|
|
||||||
// TODO
|
// TODO
|
||||||
// the backend expects projectName because it creates the project on the fly if none exists with that name
|
// 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
|
// 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 === '') {
|
if (newTask.desc === '') {
|
||||||
alert('Task description is empty.')
|
alert('Task description is empty.')
|
||||||
return
|
return
|
||||||
} else if (!newTask.projectName) {
|
}
|
||||||
|
{
|
||||||
|
/*} else if (!newTask.projectName) {
|
||||||
alert('Select a project for new task.')
|
alert('Select a project for new task.')
|
||||||
return
|
return
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
console.log('Adding task: ', newTask)
|
console.log('Adding task: ', newTask)
|
||||||
const { data, error } = await axios.post(API + '/api/tasks', newTask)
|
const { data, error } = await axios.post(API + '/api/tasks', newTask)
|
||||||
if (error) {
|
if (error) {
|
||||||
alert('Received error when adding task: ', error)
|
alert('Received error when adding task: ', error)
|
||||||
} else if (data.desc && data.projectId) {
|
} else if (data.desc) {
|
||||||
console.log('Successfully added task:', data)
|
console.log('Successfully added task:', data)
|
||||||
this.setState({ tasks: this.state.tasks.concat(data), newTask: '' })
|
this.setState({ tasks: this.state.tasks.concat(data), newTask: '' })
|
||||||
} else {
|
} else {
|
||||||
console.log('Received malformed data for added task: ', data)
|
alert('Received malformed data for added task: ', data)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(`Failed to add task: ${e}`)
|
alert(`Failed to add task: ${e}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user