fix type of projectId in updateTask()
This commit is contained in:
parent
99b3101679
commit
4892efea27
27
src/App.js
27
src/App.js
@ -16,15 +16,16 @@ const api = process.env.REACT_APP_API || 'http://localhost:1337'
|
|||||||
console.log('Using api at ' + api)
|
console.log('Using api at ' + api)
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
user: { name: 'Scott' },
|
|
||||||
loading: true,
|
loading: true,
|
||||||
|
user: { name: 'Scott' },
|
||||||
tasks: [],
|
tasks: [],
|
||||||
|
projects: [],
|
||||||
|
component: 'projects',
|
||||||
|
// TODO try to get rid of:
|
||||||
search: '',
|
search: '',
|
||||||
newTask: '',
|
newTask: '',
|
||||||
newProject: '',
|
newProject: '',
|
||||||
project: {},
|
project: {},
|
||||||
projects: [],
|
|
||||||
component: 'projects',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
@ -89,6 +90,10 @@ class App extends React.Component {
|
|||||||
|
|
||||||
async addTask(e) {
|
async addTask(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
if (!this.state.selectedProjectId) {
|
||||||
|
alert('No project selected, silly!')
|
||||||
|
return
|
||||||
|
}
|
||||||
const newTask = {
|
const newTask = {
|
||||||
desc: this.state.newTask,
|
desc: this.state.newTask,
|
||||||
projectName: this.state.projects.find(
|
projectName: this.state.projects.find(
|
||||||
@ -124,11 +129,10 @@ class App extends React.Component {
|
|||||||
|
|
||||||
async updateTask(e, updatedTask) {
|
async updateTask(e, updatedTask) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
console.log('updatedTask:', updatedTask)
|
//console.log('updatedTask:', updatedTask)
|
||||||
const oldTask = this.state.tasks.find(
|
const oldTask = this.state.tasks.find(t => t.id === updatedTask.id)
|
||||||
t => t.id === this.state.selectedTaskId,
|
|
||||||
)
|
|
||||||
if (JSON.stringify(oldTask) === JSON.stringify(updatedTask)) return
|
if (JSON.stringify(oldTask) === JSON.stringify(updatedTask)) return
|
||||||
|
updatedTask['projectId'] = parseInt(updatedTask.projectId)
|
||||||
try {
|
try {
|
||||||
const { data, error } = await axios.put(
|
const { data, error } = await axios.put(
|
||||||
api + `/api/tasks/${oldTask.id}`,
|
api + `/api/tasks/${oldTask.id}`,
|
||||||
@ -271,14 +275,9 @@ class App extends React.Component {
|
|||||||
console.log('Trying to update user profile: ', user)
|
console.log('Trying to update user profile: ', user)
|
||||||
if (error) {
|
if (error) {
|
||||||
alert('Received error when updating user profile: ', 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)
|
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) {
|
} catch (e) {
|
||||||
alert(`Updating user profile failed: ${e}`)
|
alert(`Updating user profile failed: ${e}`)
|
||||||
|
@ -2,8 +2,7 @@ import React from 'react'
|
|||||||
|
|
||||||
const TaskRow = props => {
|
const TaskRow = props => {
|
||||||
const { task } = props
|
const { task } = props
|
||||||
const project = props.projects.find(p => p.id === task.projectId) || 'None'
|
const project = props.projects.find(p => p.id === task.projectId)
|
||||||
const projectName = project.name || 'None'
|
|
||||||
return (
|
return (
|
||||||
<li className="list-group-item" key={task.id} onClick={props.editTask}>
|
<li className="list-group-item" key={task.id} onClick={props.editTask}>
|
||||||
<button
|
<button
|
||||||
@ -14,12 +13,14 @@ const TaskRow = props => {
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<span onClick={() => props.selectTask(task.id)}>{task.desc}</span>
|
<span onClick={() => props.selectTask(task.id)}>{task.desc}</span>
|
||||||
{props.component === 'project' ? null : (
|
{props.component === 'project' ? (
|
||||||
|
''
|
||||||
|
) : (
|
||||||
<button
|
<button
|
||||||
className="btn btn-outline-dark ml-5"
|
className="btn btn-outline-dark ml-5"
|
||||||
onClick={() => props.selectProject(task.projectId)}
|
onClick={() => props.selectProject(task.projectId)}
|
||||||
>
|
>
|
||||||
{projectName}
|
{project.name}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ class UpdateTask extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
console.log('inside of the task form: ', this.state)
|
|
||||||
const oldDesc = this.props.tasks.find(t => t.id === this.state.id)['desc']
|
const oldDesc = this.props.tasks.find(t => t.id === this.state.id)['desc']
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -47,7 +46,7 @@ class UpdateTask extends React.Component {
|
|||||||
<div className="col-sm-10">
|
<div className="col-sm-10">
|
||||||
<select
|
<select
|
||||||
className="form-control col-sm-6"
|
className="form-control col-sm-6"
|
||||||
name="taskNewProjectId"
|
name="projectId"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
defaultValue={this.state.projectId}
|
defaultValue={this.state.projectId}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user