Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. import React from 'react';
  2. import {hashHistory} from 'react-router';
  3. import {geolocated} from 'react-geolocated';
  4. import Modal from '../Modal/Modal';
  5. import CSSTransitionGroup from 'react-addons-css-transition-group';
  6. import { appConfig } from '../../../config';
  7. import VoiceRecognition from '../../components/voiceHandling/VoiceRecognition';
  8.  
  9. let stickman = require('../Modal/img/stickman.png');
  10. let Logo = require('./img/mistral-20x10cm.png');
  11.  
  12. //fake coords
  13. let bosmalCoordinates = {
  14. latitude: 46.8469,
  15. longitude: 28.3742
  16. }
  17.  
  18. //real coords
  19. // let bosmalCoordinates = {
  20. // latitude: 43.8469,
  21. // longitude: 18.3742
  22. // }
  23.  
  24. require('./_style.scss');
  25.  
  26. const mockUser = {
  27. username: 'Isaac',
  28. password: 'mendez'
  29. }
  30.  
  31. class Login extends React.Component {
  32.  
  33. constructor(props){
  34. super(props);
  35. this.handleSubmit = this.handleSubmit.bind(this);
  36. this.handleClose = this.handleClose.bind(this);
  37. this.onEnd = this.onEnd.bind(this);
  38. this.onResult = this.onResult.bind(this);
  39.  
  40. this.state = {
  41. username: 'Isaac',
  42. password: 'mendez',
  43. isModalOpen: false,
  44. modalLate: {hours: 9, minutes: 15, desc: "Let your team know what is going on please choose an option"},
  45. start: false,
  46. stop: false
  47. }
  48. }
  49.  
  50. onEnd() {
  51. this.setState({ start: false, stop: false })
  52. this.props.action('end')()
  53. }
  54.  
  55. // onResult = ({ finalTranscript }) => {
  56. onResult({ finalTranscript }) {
  57. const result = finalTranscript
  58.  
  59. this.setState({ start: false })
  60. //this.props.action('result')(finalTranscript)
  61. console.log(finalTranscript)
  62. console.log(this.refs.personal)
  63. }
  64.  
  65. handleSubmit(e){
  66. e.preventDefault();
  67. let username = this.refs.username.value.trim();
  68. let password = this.refs.password.value.trim();
  69.  
  70.  
  71. //if credentials match
  72. if(username === this.state.username && password === this.state.password){
  73.  
  74. //if user is late
  75. if(appConfig.dateNow.getHours() > appConfig.modalLate.hours || (appConfig.dateNow.getHours() === appConfig.modalLate.hours && appConfig.dateNow.getMinutes() >= appConfig.modalLate.minutes)){
  76.  
  77. //if user is at Bosmal
  78. if(Math.abs(this.props.coords.latitude - bosmalCoordinates.latitude) < 0.001 && Math.abs(this.props.coords.longitude - bosmalCoordinates.longitude) < 0.001){
  79. hashHistory.push('/standup');
  80. }else {
  81. this.setState({isModalOpen: true});
  82. }
  83.  
  84. } else {
  85. hashHistory.push('/standup');
  86. }
  87.  
  88.  
  89.  
  90. }else {
  91. alert("error logging in!");
  92. }
  93. }
  94.  
  95. handleClose(){
  96. this.setState({
  97. isModalOpen: false
  98. });
  99.  
  100. setTimeout(() => {
  101. hashHistory.push('/tickets');
  102. },300)
  103. }
  104.  
  105. handleOpen(){
  106. this.setState({
  107. isModalOpen: true
  108. })
  109. }
  110.  
  111. render(){
  112. return(
  113. <div className="w-100 h-100 relative tc content login ph4">
  114.  
  115.  
  116. <CSSTransitionGroup
  117. transitionName='modal'
  118. transitionAppear={true}
  119. transitionAppearTimeout={400}
  120. transitionEnterTimeout={400}
  121. transitionLeaveTimeout={400}
  122. >
  123.  
  124. {
  125. this.state.isModalOpen && (
  126. <Modal onClose={this.handleClose}
  127. isOpen={this.state.isModalOpen}
  128. modalClassName="modal modal-late"
  129. backdropClassName="modal-backdrop">
  130. <div onClick={this.handleClose} className="tr">
  131. <svg id="closeModal" viewBox="0 0 80 50" className="modal-close" >
  132. <line x1="10" y1="10" x2="40" y2="40" />
  133. <line x1="70" y1="10" x2="40" y2="40" />
  134. </svg>
  135. </div>
  136. <div className="stickman mb2">
  137. <img src={stickman} alt="stickman img" />
  138. </div>
  139. <h4 className="f4 white measure lh-title">It is {appConfig.dateNow.getHours()}:{appConfig.dateNow.getMinutes()}</h4>
  140. <p className="o-60 white f6 measure lh-copy ph5 mb4">{appConfig.modalLate.desc}</p>
  141. <div className="buttons">
  142. <div className="modal-btn white ba f6 pv2" ref="late">I will be late</div>
  143. <div className="modal-btn white ba f6 pv2" ref="personal">Personal day</div>
  144. <div className="modal-btn white ba f6 pv2">Sick day</div>
  145. <div className="modal-btn white ba f6 pv2">Remote work</div>
  146. </div>
  147.  
  148. <div>
  149. <button onClick={() => this.setState({ start: true })}>start</button>
  150. <button onClick={() => this.setState({ stop: true })}>stop</button>
  151.  
  152. {this.state.start && (
  153. <VoiceRecognition
  154. onStart={console.log('start')}
  155. onEnd={console.log('end')}
  156. onResult={this.onResult}
  157. continuous={true}
  158. lang="en-US"
  159. stop={this.state.stop}
  160. />
  161. )}
  162. </div>
  163. </Modal>
  164. )
  165. }
  166. </CSSTransitionGroup>
  167.  
  168.  
  169. <div className="login__logo mb6" >
  170. <img src={Logo} alt="logo"/>
  171. </div>
  172.  
  173. <form onSubmit={this.handleSubmit}>
  174. <div className="login__form mb2">
  175. <input type="text" placeholder="username" name="username"
  176. className="input-reset mb2 ph2 pv2 white db" ref="username" />
  177. <input type="password" placeholder="password" name="password"
  178. className="input-reset ph2 pv2 white db" ref="password" />
  179. </div>
  180.  
  181. <div className="login__btn pv3 w-100">
  182. <input type="submit" className="link dim br-pill ph5 pv2 dib w-100" value="Login" />
  183. </div>
  184. </form>
  185.  
  186. </div>
  187. );
  188. };
  189. }
  190.  
  191.  
  192. export default geolocated({
  193. positionOptions: {
  194. enableHighAccuracy: true,
  195. },
  196. userDecisionTimeout: 5000
  197. })(Login);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement