|
| 1 | +import React from "react" |
| 2 | +import {connect} from "react-redux" |
| 3 | +import {Link} from "react-router" |
| 4 | +import {Field, reduxForm} from "redux-form" |
| 5 | +import withStyles from "isomorphic-style-loader/lib/withStyles" |
| 6 | +import Tooltip from "react-tooltip" |
| 7 | + |
| 8 | +import Button from "../Button" |
| 9 | + |
| 10 | +import {joinExisting} from "../../actions/user" |
| 11 | + |
| 12 | +import s from "./Login.scss" |
| 13 | + |
| 14 | +const JoinForm = reduxForm({form: "joinExisting"})(withStyles(s)(props => ( |
| 15 | + <form className={s.form} method="post" onSubmit={props.handleSubmit}> |
| 16 | + <Tooltip place="top" type="dark" effect="float" /> |
| 17 | + <div className={s.card}> |
| 18 | + <input |
| 19 | + data-tip="ชื่อผู้ใช้" |
| 20 | + style={{width: "100%", color: "darkgrey"}} |
| 21 | + className={s.field} |
| 22 | + type="text" |
| 23 | + value={`ชื่อผู้ใช้: ${props.user.username}`} |
| 24 | + disabled |
| 25 | + /> |
| 26 | + {props.code ? ( |
| 27 | + <input |
| 28 | + data-tip="รหัสห้องเรียน" |
| 29 | + style={{width: "100%", color: "darkgrey"}} |
| 30 | + className={s.field} |
| 31 | + type="text" |
| 32 | + value={`รหัสเข้าห้องเรียนถูกป้อนโดยอัตโนมัติ: ${props.code}`} |
| 33 | + disabled |
| 34 | + /> |
| 35 | + ) : ( |
| 36 | + <Field |
| 37 | + name="code" |
| 38 | + data-tip="คัดลอกรหัส 24 หลักที่ท่านได้รับจากผู้สอน" |
| 39 | + placeholder="รหัสเข้าห้องเรียน" |
| 40 | + style={{width: "100%"}} |
| 41 | + component="input" |
| 42 | + className={s.field} |
| 43 | + type="text" |
| 44 | + autoFocus |
| 45 | + /> |
| 46 | + )} |
| 47 | + </div> |
| 48 | + <Button className={s.login} type="submit" light> |
| 49 | + เข้าร่วมห้องเรียน |
| 50 | + </Button> |
| 51 | + <p className={s.message}> |
| 52 | + ท่านสามารถเข้าร่วมห้องเรียนใหม่โดยใช้บัญชีนี้ได้ทันที |
| 53 | + </p> |
| 54 | + </form> |
| 55 | +))) |
| 56 | + |
| 57 | +const ConnectedJoinForm = props => ( |
| 58 | + <JoinForm onSubmit={props.handleJoin} code={props.code} user={props.user} /> |
| 59 | +) |
| 60 | + |
| 61 | +const mapStateToProps = state => ({ |
| 62 | + user: state.user || {} |
| 63 | +}) |
| 64 | + |
| 65 | +const mapDispatchToProps = (dispatch, props) => ({ |
| 66 | + handleJoin: ({code = props.code}) => { |
| 67 | + dispatch(joinExisting(code)) |
| 68 | + } |
| 69 | +}) |
| 70 | + |
| 71 | +export default connect(mapStateToProps, mapDispatchToProps)(ConnectedJoinForm) |
0 commit comments