Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify place the up work button by employees #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/components/Member/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Member extends Component {
return { __html: rawMarkup }
}

handleUpWork(e) {
this.props.actions.up_work(this.props.id)
}

render() {
return (
<div className={style.member}>
Expand All @@ -21,6 +25,7 @@ class Member extends Component {
<span className="memberCheckoutTime">
{this.props.checkout_time}
</span>
<input type="button" value={`${this.props.at_work ? '退勤' : '出勤'}`} onClick={this.handleUpWork.bind(this)} />
</div>
)
}
Expand Down
3 changes: 3 additions & 0 deletions app/components/MemberList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class MemberList extends Component {
<Member name={member.name}
checkin_time={member.checkin_time}
checkout_time={member.checkout_time}
at_work={member.at_work}
actions={this.props.actions}
id={member.id}
key={member.id}>
</Member>
)
Expand Down
5 changes: 0 additions & 5 deletions app/components/RecorderForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class RecorderForm extends Component {
this.setState({author: '', text: ''})
}

handleUpWork(e) {
this.props.actions.up_work()
}

render() {
return (
<form className="recorderForm" onSubmit={this.handleSubmit.bind(this)}>
Expand All @@ -45,7 +41,6 @@ class RecorderForm extends Component {
onChange={this.handleTextChange.bind(this)}
/>
<input type="submit" value="Post" />
<input type="button" value={`${this.props.data.at_work ? '退勤' : '出勤'}`} onClick={this.handleUpWork.bind(this)} />
</form>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/TimeRecorder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TimeRecorder extends Component {
<div className={style.normal}>
<h1>Time Recorder</h1>
{this.timeFormat()}
<MemberList data={this.props.data} />
<MemberList data={this.props.data} actions={this.props.actions} />
<RecorderForm
onRecorderSubmit={this.handleRecorderSubmit.bind(this)}
actions={this.props.actions}
Expand Down
16 changes: 11 additions & 5 deletions app/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { handleActions } from 'redux-actions'

const initialState = {
members: [
{id: 1, name: "高垣 楓", checkin_time: "2016/06/25 09:00", checkout_time: "2016/06/25 15:00"},
{id: 2, name: "速水 奏", checkin_time: "2016/06/25 09:20", checkout_time: "2016/06/25 17:00"}
],
at_work: false
{id: 1, name: "高垣 楓", checkin_time: "2016/06/25 09:00", checkout_time: "2016/06/25 15:00", at_work: false},
{id: 2, name: "速水 奏", checkin_time: "2016/06/25 09:20", checkout_time: "2016/06/25 17:00", at_work: false}
]
}

const reducerMap = {
Expand All @@ -16,9 +15,16 @@ const reducerMap = {
return state.concat([action.payload])
},
up_work(state, action) {
let target_member = state.members.find((element, index, array) => {return element.id === action.payload})
let today = new Date()
let now = `${today.getFullYear()}/${('0' + (today.getMonth() + 1)).slice(-2)}/${('0' + today.getDate()).slice(-2)} ${('0' + today.getHours()).slice(-2)}:${('0' + today.getMinutes()).slice(-2)}`
target_member.checkin_time = (!target_member.at_work ? now : target_member.checkin_time)
target_member.checkout_time = (!target_member.at_work ? "" : now)
target_member.at_work = !target_member.at_work

return {
...state,
at_work: !state.at_work
members: state.members.map((element) => {return (element.id === target_member.id ? target_member : element)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduxのチュートリアルと同じように、members と member のReducerを作ればいいんじゃないニャ?

[参考]
http://redux.js.org/docs/basics/ExampleTodoList.html

}
}
}
Expand Down