Skip to content

Commit 2861a23

Browse files
CodeepCodeep
Codeep
authored and
Codeep
committed
Set Deadline for todos, update README
1 parent 7f2157e commit 2861a23

File tree

11 files changed

+106
-60
lines changed

11 files changed

+106
-60
lines changed

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# REACT EXPRESS Boilerplate
2-
A React Express Mongo Boilerplate to get started to development.
2+
3+
This is a sophisticated boilerplate that uses React on front-end and Node.js (Express) on back-end.
4+
5+
It implements useful tools, such as redux, sagas, mongoose, material-ui, to make the project as professional as possible.
6+
7+
It's already a usable CRUD app, using todos to illustrate that.
8+
9+
Follow the steps below to get started using this boilerplate for your project!
10+
311
### Prerequisites
4-
node version >= 7 and an npm version >= 4.
12+
• Node - version >= 7
13+
• npm version >= 4
14+
• Mongo DB
15+
516
## Install
6-
First, clone the repo via git:
17+
18+
First, clone the repository via git:
719
```bash
820
git clone https://github.com/codeep/React-Express-Boilerplate.git
921
```
10-
And then install dependencies with npm.
22+
Then, install dependencies using npm.
1123
```bash
1224
$ cd React-Express-Boilerplate
1325
$ npm install
@@ -17,4 +29,4 @@ $ npm install
1729
Start the app:
1830
```bash
1931
$ npm start
20-
```
32+
```

app/actionTypes/todoActionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export const EDIT_TODO = 'EDIT_TODO';
77
export const DELETE_TODO = 'DELETE_TODO';
88
export const CHANGE_TODO_NAME = 'CHANGE_TODO_NAME';
99
export const CHANGE_TODO_DESCRIPTION = "CHANGE_TODO_DESCRIPTION";
10+
export const CHANGE_TODO_DEADLINE = "CHANGE_TODO_DEADLINE";
1011
export const CLEAR_TODO_DATA = "CLEAR_TODO_DATA";

app/actions/todoActions.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as actionTypes from '../actionTypes/todoActionTypes';
22

3-
export const create_todo = (name = '', description = '') => {
3+
export const create_todo = (name = '', description = '', deadline) => {
44
return {
55
type: actionTypes.CREATE_TODO,
6-
name: name,
7-
description: description
6+
name,
7+
description,
8+
deadline
89
}
910
};
1011

@@ -21,11 +22,12 @@ export const get_todo_by_id = (id) => {
2122
}
2223
};
2324

24-
export const edit_todo = (name, description, id) => {
25+
export const edit_todo = (name, description, deadline, id) => {
2526
return {
2627
type: actionTypes.EDIT_TODO,
2728
name,
2829
description,
30+
deadline,
2931
id
3032
}
3133
};
@@ -51,6 +53,13 @@ export const change_todo_description = (description) => {
5153
}
5254
};
5355

56+
export const change_todo_deadline = (deadline) => {
57+
return {
58+
type: actionTypes.CHANGE_TODO_DEADLINE,
59+
deadline
60+
}
61+
};
62+
5463
export const clear_todo_data = () => {
5564
return {
5665
type: actionTypes.CLEAR_TODO_DATA,

app/components/TodoForm/TodoForm.js

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
import React, { PureComponent } from 'react';
22
import RaisedButton from 'material-ui/RaisedButton';
33
import TextField from 'material-ui/TextField';
4+
import TimePicker from 'material-ui/TimePicker';
45
import style from './style.css';
56

67
class TodoForm extends PureComponent {
7-
constructor(props) {
8-
super(props);
9-
}
108

11-
render() {
12-
const { todo, onFormSubmit, onNameChange, onDescriptionChange } = this.props;
13-
return (
14-
<div className='create-todo-form'>
15-
{!todo.id && <h3>Create todo</h3>}
16-
{todo.id && <h3>Edit todo</h3>}
17-
<form onSubmit={(event) => onFormSubmit(event)}>
18-
<label>
19-
Name: &nbsp;
20-
<TextField
21-
name="name"
22-
className="form-input"
23-
value={todo.name}
24-
onChange={(event) => onNameChange(event)}
25-
required/>
26-
</label>
27-
<label>
28-
Description: &nbsp;
29-
<TextField
30-
name="description"
31-
value={todo.description}
32-
onChange={(event) => onDescriptionChange(event)}
33-
required/>
34-
</label>
35-
&nbsp;
36-
<RaisedButton
37-
label={todo.id ? 'Save' : 'Add'}
38-
primary={true}
39-
type='submit'/>
40-
</form>
41-
</div>
42-
)
43-
}
9+
render() {
10+
const { todo, onFormSubmit, onNameChange, onDescriptionChange, onDeadlineChange } = this.props;
11+
12+
return (
13+
<div className='create-todo-form'>
14+
{!todo.id && <h3>Create todo</h3>}
15+
{todo.id && <h3>Edit todo</h3>}
16+
<form onSubmit={(event) => onFormSubmit(event)}>
17+
<label>
18+
Name: &nbsp;
19+
<TextField
20+
name="name"
21+
className="form-input"
22+
value={todo.name}
23+
onChange={(event) => onNameChange(event)}
24+
required/>
25+
</label>
26+
<label>
27+
Description: &nbsp;
28+
<TextField
29+
name="description"
30+
value={todo.description}
31+
onChange={(event) => onDescriptionChange(event)}
32+
required/>
33+
</label>
34+
&nbsp;
35+
<label>
36+
Deadline: &nbsp;
37+
<TimePicker
38+
format="ampm"
39+
value={new Date(todo.deadline)}
40+
onChange={(e, time) => onDeadlineChange(time)}
41+
hintText="Set the time"
42+
autoOk={true}
43+
/>
44+
</label>
45+
&nbsp;
46+
<RaisedButton
47+
label={todo.id ? 'Save' : 'Add'}
48+
primary={true}
49+
type='submit'/>
50+
</form>
51+
</div>
52+
)
53+
}
4454
}
4555

4656

app/containers/TodoList/TodoList.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class TodoList extends Component {
4141
const { todoList } = this.props;
4242
const { header } = this.state;
4343

44-
console.log(this.props, "todo list")
4544
return (
4645
<Table selectable={false}>
4746
<TableHeader>

app/containers/TodoManage/TodoManage.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TodoManage extends Component {
1111
this.addTodo = this.addTodo.bind(this);
1212
this.changeName = this.changeName.bind(this);
1313
this.changeDescription = this.changeDescription.bind(this);
14+
this.changeDeadline = this.changeDeadline.bind(this);
1415
}
1516

1617
componentDidMount() {
@@ -33,25 +34,32 @@ class TodoManage extends Component {
3334
actions.change_todo_description(event.target.value);
3435
}
3536

37+
changeDeadline(time) {
38+
const { actions } = this.props;
39+
actions.change_todo_deadline(time);
40+
}
41+
3642
addTodo(event) {
3743
const {actions, history, todo} = this.props;
38-
const {name, description, id} = todo;
44+
const {name, description, deadline, id} = todo;
3945

4046
event.preventDefault();
4147
todo.id
42-
? actions.edit_todo(name, description, id)
43-
: actions.create_todo(name, description, id);
48+
? actions.edit_todo(name, description, deadline, id)
49+
: actions.create_todo(name, description, deadline, id);
4450
history.push('/');
4551
}
4652

4753
render() {
4854
const {todo} = this.props;
55+
4956
return (
5057
<TodoForm
5158
todo={todo}
5259
onFormSubmit={this.addTodo}
5360
onNameChange={this.changeName}
5461
onDescriptionChange={this.changeDescription}
62+
onDeadlineChange={this.changeDeadline}
5563
/>
5664
)
5765
}

app/fetch.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios'
22
import appConfig from '../config';
3-
console.log(appConfig, 'appConfig')
3+
44
const requestUrl = `${appConfig.apiHost}`;
55
const requestPort = `${appConfig.apiPort}`;
66

@@ -32,7 +32,6 @@ axios.interceptors.response.use((res) => {
3232
});
3333

3434
export const get = (url) => {
35-
console.log(url, 'url')
3635
return axios.get(url, config)
3736
};
3837

@@ -41,9 +40,8 @@ export const post = (url, data) => {
4140
};
4241

4342
export const update = (url, data) => {
44-
console.log(requestUrl, 'requestUrl')
4543
return axios.put(url, data, config)
4644
};
4745
export const remove = (url, data) => {
4846
return axios.delete(url, data, config)
49-
};
47+
};

app/reducers/todoReducer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TodoActionTypes } from '../actionTypes';
33
const initialState = {
44
name: '',
55
description: '',
6+
deadline: 'Wed Mar 25 2015 04:00:00 GMT+0400 (+04)',
67
id: null,
78
todos: []
89
}
@@ -22,18 +23,25 @@ export const todoReducer = (state = initialState, action) => {
2223
return {
2324
...state, description: action.description
2425
};
26+
case TodoActionTypes.CHANGE_TODO_DEADLINE:
27+
28+
return {
29+
...state, deadline: action.deadline
30+
};
2531
case TodoActionTypes.GET_TODO_BY_ID_RESPONSE:
2632
return {
2733
...state,
2834
name: action.data.name,
2935
description: action.data.description,
36+
deadline: action.data.deadline,
3037
id: action.data._id
3138
};
3239
case TodoActionTypes.CLEAR_TODO_DATA:
3340
return {
3441
...state,
3542
name: initialState.name,
3643
description: initialState.description,
44+
deadline: initialState.deadline,
3745
id: initialState.id
3846
};
3947
default:

app/sagas/newTodoSaga.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export function* getTodoFlow () {
4646
}
4747
}
4848

49-
export function* editTodo (id, name, description) {
49+
export function* editTodo (id, name, description, deadline) {
5050
yield put({type: IndexActionTypes.FETCH_START});
5151
try {
52-
return yield call(update, `/todo`, {id, name, description});
52+
return yield call(update, `/todo`, {id, name, description, deadline});
5353
} catch (err) {
5454
yield put({type: IndexActionTypes.SET_MESSAGE, msgContent: "Can't Get Todo List", msgType: 0});
5555
} finally {
@@ -60,7 +60,7 @@ export function* editTodo (id, name, description) {
6060
export function* editTodoFlow () {
6161
while (true){
6262
let req = yield take(TodoActionTypes.EDIT_TODO);
63-
let res = yield call(editTodo, req.id, req.name, req.description);
63+
let res = yield call(editTodo, req.id, req.name, req.description, req.deadline);
6464
if(res){
6565
yield put({type:TodoActionTypes.GET_TODOS_RESPONSE,data:res})
6666
}

schemas/todo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import mongoose from 'mongoose';
22

33
module.exports = new mongoose.Schema({
44
name: String,
5-
description: String
5+
description: String,
6+
deadline: Date
67
});
7-

server/api/handlers/todo.handler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ export const getOne = (req, res) => {
1515
export const createTodo = (req, res) => {
1616
Todo.create({
1717
name: req.body.name,
18-
description: req.body.description
18+
description: req.body.description,
19+
deadline: req.body.deadline
1920
}).then(todo => res.send(todo))
2021
.catch(err => res.end(err));
2122
};
2223

2324
export const updateTodo = (req, res) => {
24-
Todo.update({ _id: req.body.id }, { name: req.body.name, description: req.body.description })
25+
Todo.update({ _id: req.body.id }, { name: req.body.name, description: req.body.description, deadline: req.body.deadline })
2526
.then(updated => res.end())
2627
.catch(err => res.end(err));
2728
};

0 commit comments

Comments
 (0)