Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.28 KB | None | 0 0
  1. // StyleSheets
  2. import './../../../vendor/dashboard/css/sweetalert.css';
  3. import './../../Shared/css/Error.css';
  4.  
  5. // Node modules
  6. import React from 'react';
  7. import { NavLink,
  8. Redirect
  9. } from 'react-router-dom';
  10. import SweetAlert from 'sweetalert-react';
  11. import TextUtils from '../../../utilities/TextUtils';
  12. import ValidationUtils from '../../../utilities/ValidationUtils';
  13.  
  14. // Common JS Style
  15. let Auth = require('j-toker');
  16. let AuthConfig = require('./../../../api/JtokerConfig');
  17.  
  18. const RenderErrors = (props) => {
  19. if (props.errors === null) {
  20.  
  21. }
  22. };
  23.  
  24. class SignUp extends React.Component {
  25. constructor(props) {
  26. super(props);
  27.  
  28. this.state = {
  29. currentUser: {},
  30. firstName: '',
  31. lastName: '',
  32. email: '',
  33. password: '',
  34. company: '',
  35. phone: '',
  36. sentEmail: null,
  37. submitBtnText: 'Create Account',
  38. errors: null,
  39. success: false
  40. };
  41.  
  42. this.handleInputFieldChange = this.handleInputFieldChange.bind(this);
  43. this.handleSubmit = this.handleSubmit.bind(this);
  44. }
  45.  
  46. componentDidMount() {
  47.  
  48. // Validate a user token
  49. Auth.validateToken()
  50. .then((user) => {
  51. this.setState(() => {
  52. return {
  53. currentUser: user
  54. }
  55. });
  56. });
  57.  
  58. }
  59.  
  60. handleSubmit(event) {
  61. let sanitizedFields = {};
  62. sanitizedFields['first_name'] = TextUtils.sanitize(this.state.firstName);
  63. sanitizedFields['last_name'] = TextUtils.sanitize(this.state.lastName);
  64. sanitizedFields['email'] = TextUtils.sanitize(this.state.email);
  65. sanitizedFields['password'] = this.state.password;
  66. sanitizedFields['company'] = TextUtils.sanitize(this.state.company);
  67. sanitizedFields['phone'] = TextUtils.sanitize(this.state.phone);
  68. sanitizedFields['password_confirmation'] = this.state.password.trim();
  69.  
  70. this.setState({
  71. submitBtnText: 'Loading...'
  72. });
  73.  
  74. // Post Email Registration data to the server
  75. Auth.emailSignUp(sanitizedFields)
  76. .then(() => {
  77. this.setState(function () {
  78. return {
  79. sentEmail: this.state.email,
  80. submitBtnText: 'Create Account',
  81. email: '',
  82. firstName: '',
  83. lastName: '',
  84. password: '',
  85. phone: '',
  86. company: '',
  87. errors: null,
  88. success: true
  89. }
  90. });
  91.  
  92. })
  93. .fail((response) => {
  94. this.setState(function () {
  95. return {
  96. submitBtnText: 'Create Account',
  97. errors: response.data.errors
  98. }
  99. });
  100. });
  101.  
  102. event.preventDefault();
  103. }
  104.  
  105. handleInputFieldChange(event) {
  106. const target = event.target;
  107. const name = target.name;
  108. this.setState(function () {
  109. return {
  110. [name]: target.value
  111. }
  112. });
  113. }
  114.  
  115. render() {
  116. let currentUser = this.state.currentUser;
  117. let firstName = this.state.firstName;
  118. let lastName = this.state.lastName;
  119. let email = this.state.email;
  120. let phone = this.state.phone;
  121. let password = this.state.password;
  122. let company = this.state.company;
  123. let errors = this.state.errors;
  124.  
  125. return(
  126. <div className="login">
  127. {/* Don't show the user the SignUp Page if a user token is already set */}
  128. { Object.keys(currentUser).length !== 0
  129. ? <Redirect to="/d/projects" />
  130. : null
  131. }
  132.  
  133. {/* Email Registration Success Message */}
  134. <SweetAlert
  135. show={this.state.success}
  136. type='success'
  137. title='Account created!!!'
  138. text={'Check your email: '+ this.state.sentEmail +' to activate your account'}
  139. onConfirm={() => this.setState({success: false})}
  140. />
  141.  
  142. <div className="login__block active" id="l-login">
  143. <div className="login__block__header">
  144. <i className="zmdi zmdi-account-circle" />
  145. Create a Bidimax account <br />
  146. Your account will be setup in less than a minute.
  147. </div>
  148.  
  149. <form onSubmit={this.handleSubmit} method="post">
  150. <div className="login__block__body">
  151.  
  152. <div className="form-group form-group--float form-group--centered">
  153. <input type="text"
  154. className={
  155. ValidationUtils.FieldLengthAndAddClass(firstName,
  156. 'form-control form-control--active',
  157. 'form-control')}
  158. name="firstName"
  159. onChange={this.handleInputFieldChange}
  160. value={firstName}
  161. autoComplete="off"
  162. autoFocus
  163. />
  164. <label>First Name</label>
  165. <i className="form-group__bar" />
  166. </div>
  167.  
  168.  
  169. <div className="form-group form-group--float form-group--centered">
  170. <input type="text"
  171. className={
  172. ValidationUtils.FieldLengthAndAddClass(lastName,
  173. 'form-control form-control--active',
  174. 'form-control')}
  175. onChange={this.handleInputFieldChange}
  176. name="lastName"
  177. value={lastName}
  178. autoComplete="off"
  179. />
  180. <label>Last Name</label>
  181. <i className="form-group__bar" />
  182. </div>
  183.  
  184. <div className="form-group form-group--float form-group--centered">
  185. <input type="text"
  186. className={
  187. ValidationUtils.FieldLengthAndAddClass(email,
  188. 'form-control form-control--active',
  189. 'form-control')}
  190. onChange={this.handleInputFieldChange}
  191. name="email"
  192. value={email}
  193. autoComplete="off"
  194. />
  195. <label>Email</label>
  196. <i className="form-group__bar" />
  197. </div>
  198. { errors !== null &&
  199. errors.email &&
  200. <div className="error-feedback">{'Email '+errors.email}</div>
  201. }
  202.  
  203. <div className="form-group form-group--float form-group--centered">
  204. <input type="password"
  205. className={
  206. ValidationUtils.FieldLengthAndAddClass(password,
  207. 'form-control form-control--active',
  208. 'form-control')}
  209. name="password"
  210. onChange={this.handleInputFieldChange}
  211. value={password}
  212. autoComplete="off"
  213. />
  214. <label>Password</label>
  215. <i className="form-group__bar" />
  216. </div>
  217. { errors !== null &&
  218. errors.password &&
  219. <div className="error-feedback">{'Password '+errors.password}</div>
  220. }
  221.  
  222.  
  223. <div className="form-group form-group--float form-group--centered">
  224. <input type="text"
  225. className={
  226. ValidationUtils.FieldLengthAndAddClass(company,
  227. 'form-control form-control--active',
  228. 'form-control')}
  229. name="company"
  230. onChange={this.handleInputFieldChange}
  231. value={company}
  232. autoComplete="off"
  233. />
  234. <label>Company</label>
  235. <i className="form-group__bar" />
  236. </div>
  237. { errors !== null &&
  238. errors.company &&
  239. <div className="error-feedback">{'Company '+errors.company}</div>
  240. }
  241.  
  242.  
  243. <div className="form-group form-group--float form-group--centered">
  244. <input type="text"
  245. className={
  246. ValidationUtils.FieldLengthAndAddClass(phone,
  247. 'form-control form-control--active',
  248. 'form-control')}
  249. name="phone"
  250. onChange={this.handleInputFieldChange}
  251. value={phone}
  252. autoComplete="off"
  253. />
  254. <label>Phone</label>
  255. <i className="form-group__bar" />
  256. </div>
  257. { errors !== null &&
  258. errors.phone &&
  259. <div className="error-feedback">{'Phone '+errors.phone}</div>
  260. }
  261.  
  262.  
  263. <div className="form-group form-group--float form-group--centered">
  264. <button type="submit"
  265. className="btn btn-block btn-primary bg-blue-grey btn-lg waves-effect"
  266. disabled={!firstName || !lastName || !email || !password || !phone || !company}>
  267. {this.state.submitBtnText}
  268. </button>
  269. </div>
  270.  
  271. <p>Have account already? &nbsp;
  272. <NavLink exact to="/login">Login</NavLink>
  273. </p>
  274. </div>
  275. </form>
  276. </div>
  277. </div>
  278. )
  279. }
  280. }
  281.  
  282. export default SignUp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement