fix type of projectId in updateTask()

This commit is contained in:
data 2019-06-23 13:11:50 -04:00
parent 99b3101679
commit 4892efea27
3 changed files with 19 additions and 20 deletions

View File

@ -16,15 +16,16 @@ const api = process.env.REACT_APP_API || 'http://localhost:1337'
console.log('Using api at ' + api)
const defaultState = {
user: { name: 'Scott' },
loading: true,
user: { name: 'Scott' },
tasks: [],
projects: [],
component: 'projects',
// TODO try to get rid of:
search: '',
newTask: '',
newProject: '',
project: {},
projects: [],
component: 'projects',
}
class App extends React.Component {
@ -89,6 +90,10 @@ class App extends React.Component {
async addTask(e) {
e.preventDefault()
if (!this.state.selectedProjectId) {
alert('No project selected, silly!')
return
}
const newTask = {
desc: this.state.newTask,
projectName: this.state.projects.find(
@ -124,11 +129,10 @@ class App extends React.Component {
async updateTask(e, updatedTask) {
e.preventDefault()
console.log('updatedTask:', updatedTask)
const oldTask = this.state.tasks.find(
t => t.id === this.state.selectedTaskId,
)
//console.log('updatedTask:', updatedTask)
const oldTask = this.state.tasks.find(t => t.id === updatedTask.id)
if (JSON.stringify(oldTask) === JSON.stringify(updatedTask)) return
updatedTask['projectId'] = parseInt(updatedTask.projectId)
try {
const { data, error } = await axios.put(
api + `/api/tasks/${oldTask.id}`,
@ -271,14 +275,9 @@ class App extends React.Component {
console.log('Trying to update user profile: ', user)
if (error) {
alert('Received error when updating user profile: ', error)
} else if (data.desc && data.projectId) {
} else if (data) {
this.setState({ user: data })
console.log('Successfully updated user profile:', data)
// TODO this.setState({ tasks: this.state.tasks.concat(data), newTask: '' })
} else {
console.log(
'Received malformed data when updating user profile: ',
data,
)
}
} catch (e) {
alert(`Updating user profile failed: ${e}`)

View File

@ -2,8 +2,7 @@ import React from 'react'
const TaskRow = props => {
const { task } = props
const project = props.projects.find(p => p.id === task.projectId) || 'None'
const projectName = project.name || 'None'
const project = props.projects.find(p => p.id === task.projectId)
return (
<li className="list-group-item" key={task.id} onClick={props.editTask}>
<button
@ -14,12 +13,14 @@ const TaskRow = props => {
</button>
<span onClick={() => props.selectTask(task.id)}>{task.desc}</span>
{props.component === 'project' ? null : (
{props.component === 'project' ? (
''
) : (
<button
className="btn btn-outline-dark ml-5"
onClick={() => props.selectProject(task.projectId)}
>
{projectName}
{project.name}
</button>
)}

View File

@ -19,7 +19,6 @@ class UpdateTask extends React.Component {
}
render() {
console.log('inside of the task form: ', this.state)
const oldDesc = this.props.tasks.find(t => t.id === this.state.id)['desc']
return (
<div>
@ -47,7 +46,7 @@ class UpdateTask extends React.Component {
<div className="col-sm-10">
<select
className="form-control col-sm-6"
name="taskNewProjectId"
name="projectId"
onChange={this.handleChange}
defaultValue={this.state.projectId}
>