-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
580 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import actionTypes from './actionTypes'; | ||
|
||
export const createTaskSuccess = (task, storyId) => ({ | ||
type: actionTypes.ADD_TASK, | ||
task, | ||
storyId | ||
}); | ||
|
||
export const deleteTaskSuccess = (task, storyId) => ({ | ||
type: actionTypes.REMOVE_TASK, | ||
task, | ||
storyId | ||
}); | ||
|
||
export const toggleTaskSuccess = (task, story) => ({ | ||
type: actionTypes.TOGGLE_TASK, | ||
task, | ||
story | ||
}); | ||
|
||
export const createTask = (projectId, storyId, task) => { | ||
return (dispatch, getState, { Task }) => { | ||
return Task.post(projectId, storyId, task) | ||
.then(task => { | ||
dispatch(createTaskSuccess(task, storyId)) | ||
}); | ||
}; | ||
}; | ||
|
||
export const deleteTask = (projectId, storyId, taskId) => { | ||
return (dispatch, getState, { Task }) => { | ||
return Task.destroy(projectId, storyId, taskId) | ||
.then(() => { | ||
dispatch(deleteTaskSuccess(taskId, storyId)) | ||
}); | ||
}; | ||
}; | ||
|
||
export const toggleTask = (projectId, story, task, status) => { | ||
return (dispatch, getState, { Task }) => { | ||
return Task.toggle(projectId, story.id, task.id, status) | ||
.then((task) => { | ||
dispatch(toggleTaskSuccess(task, story)) | ||
}); | ||
}; | ||
}; |
79 changes: 79 additions & 0 deletions
79
app/assets/javascripts/components/story/ExpandedStory/ExpandedStoryTask.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { Component } from 'react'; | ||
import TasksList from '../task/TasksList'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class ExpandedStoryTask extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
task: '' | ||
}; | ||
this.onInputChange = this.onInputChange.bind(this); | ||
this.onHandleSubmit = this.onHandleSubmit.bind(this); | ||
} | ||
|
||
onInputChange(e) { | ||
this.setState({ | ||
task: e.target.value | ||
}); | ||
} | ||
|
||
onHandleSubmit() { | ||
const { onSave } = this.props; | ||
|
||
const task = this.state.task; | ||
onSave(task); | ||
this.setState({ | ||
task: '' | ||
}); | ||
} | ||
|
||
render() { | ||
const { story, onToggle, onDelete } = this.props; | ||
|
||
return ( | ||
<div> | ||
<div className="Story__section"> | ||
<div className="Story__section-title"> | ||
<div className="Story__section-title"> | ||
{I18n.translate('story.tasks')} | ||
</div> | ||
</div> | ||
</div> | ||
<div className="Story__list-task" > | ||
<TasksList | ||
tasks={story.tasks} | ||
onDelete={onDelete} | ||
onToggle={onToggle} | ||
/> | ||
</div> | ||
<div className="Story__task-form"> | ||
<input | ||
value={this.state.task} | ||
className="form-control input-sm" | ||
onChange={this.onInputChange} | ||
/> | ||
<button | ||
type='submit' | ||
className='Story__add-task-button' | ||
onClick={this.onHandleSubmit} | ||
> | ||
{I18n.t('add task')} | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
ExpandedStoryTask.propTypes = { | ||
story: PropTypes.object.isRequired, | ||
story: PropTypes.shape({ | ||
tasks: PropTypes.array.isRequired | ||
}), | ||
onToggle: PropTypes.func.isRequired, | ||
onDelete: PropTypes.func.isRequired, | ||
onSave: PropTypes.func.isRequired | ||
}; | ||
|
||
export default ExpandedStoryTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Task = ({ task, onDelete, onToggle }) => ( | ||
<div className="Story__task"> | ||
<label> | ||
<input | ||
type='checkbox' | ||
defaultChecked={task.done} | ||
onClick={onToggle} | ||
/> | ||
{task.name} | ||
</label> | ||
<span | ||
title={I18n.t('delete')} | ||
className='delete-btn' | ||
onClick={onDelete} | ||
> | ||
{ I18n.t('delete') } | ||
</span> | ||
</div> | ||
); | ||
|
||
Task.propTypes = { | ||
task: PropTypes.shape({ | ||
id: PropTypes.number, | ||
done: PropTypes.bool, | ||
name: PropTypes.string | ||
}), | ||
onToggle: PropTypes.func.isRequired, | ||
onDelete: PropTypes.func.isRequired | ||
}; | ||
|
||
export default Task; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import Task from './Task' | ||
import PropTypes from 'prop-types'; | ||
|
||
const TasksList = ({ tasks, onDelete, onToggle }) => ( | ||
<div> | ||
{ | ||
tasks.map((task) => ( | ||
<Task | ||
key={task.id} | ||
task={task} | ||
onDelete={() => onDelete(task.id)} | ||
onToggle={() => onToggle(task, { done: !task.done })} | ||
/> | ||
)) | ||
} | ||
</div> | ||
) | ||
|
||
TasksList.propTypes = { | ||
tasks: PropTypes.array.isRequired, | ||
onDelete: PropTypes.func.isRequired, | ||
onToggle: PropTypes.func.isRequired | ||
}; | ||
|
||
export default TasksList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import httpService from '../../services/httpService'; | ||
import changeCase from 'change-object-case'; | ||
import { updateIfSameId } from '../../services/updateIfSameId'; | ||
|
||
export const post = (projectId, storyId, task) => { | ||
const newTask = { | ||
name: task, | ||
done: false | ||
} | ||
return httpService | ||
.post(`/projects/${projectId}/stories/${storyId}/tasks`, newTask) | ||
.then(({ data }) => changeCase.camelKeys(data, { recursive: true, arrayRecursive: true })) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
export const toggle = (projectId, storyId, taskId, status) => { | ||
const taskStatus = changeCase.snakeKeys(status); | ||
return httpService | ||
.put(`/projects/${projectId}/stories/${storyId}/tasks/${taskId}/`, taskStatus) | ||
.then(({ data }) => changeCase.camelKeys(data, { recursive: true, arrayRecursive: true })) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
export const destroy = (projectId, storyId, taskId) => { | ||
return httpService | ||
.delete(`/projects/${projectId}/stories/${storyId}/tasks/${taskId}`) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
export const addTask = (story, task) => ( | ||
{ | ||
...story, | ||
tasks: [ | ||
...story.tasks, | ||
task | ||
] | ||
} | ||
); | ||
|
||
export const toggleTask = (story, changedTask) => { | ||
return { | ||
...story, | ||
tasks: story.tasks.map( | ||
updateIfSameId(changedTask.id, task => { | ||
return { | ||
...task, | ||
...changedTask | ||
}; | ||
} | ||
)) | ||
}; | ||
}; | ||
|
||
export const deleteTask = (taskId, story) => ({ | ||
...story, | ||
tasks: story.tasks.filter((task) => task.id !== taskId) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.