From 989fb5c7dbba174f54f3ae69df788d6685fff46b Mon Sep 17 00:00:00 2001
From: jloup <jeanloup.jamet@gmail.com>
Date: Sat, 24 Feb 2018 17:06:57 +0100
Subject: Upgrade ReactJS. EC6 import modules.

---
 cmd/web/js/otp.jsx | 72 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 40 insertions(+), 32 deletions(-)

(limited to 'cmd/web/js/otp.jsx')

diff --git a/cmd/web/js/otp.jsx b/cmd/web/js/otp.jsx
index a0ee5cc..aecf032 100644
--- a/cmd/web/js/otp.jsx
+++ b/cmd/web/js/otp.jsx
@@ -1,9 +1,10 @@
-var Api        = require('./api.js').Api;
-var App        = require('./app.js');
-var classNames = require('classnames');
+import Api from './api.js';
+import App from './app.js';
+import classNames from 'classnames';
+import React from 'react';
 
-var OtpQrCode = React.createClass({
-  render: function() {
+class OtpQrCode extends React.Component {
+  render = () => {
     return (
       <div>
         <img src={this.props.img} />
@@ -11,13 +12,15 @@ var OtpQrCode = React.createClass({
       </div>
     );
   }
-});
+}
 
-module.exports.OtpEnrollForm = React.createClass({
-  getInitialState: function() {
-    return {'hideMsg': true, 'msg': '', 'msgOk': false, 'pass': ''};
-  },
-  handleSubmit: function(e) {
+class OtpEnrollForm extends React.Component {
+  constructor(props) {
+    super(props);
+    this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'pass': ''};
+  }
+
+  handleSubmit = (e) => {
     Api.Call('OTP_VALIDATE', {'pass': this.state.pass}, function(err, status, data) {
       if (err) {
         console.error(err, data);
@@ -31,40 +34,45 @@ module.exports.OtpEnrollForm = React.createClass({
     }.bind(this));
 
     e.preventDefault();
-  },
-  handlePassChange: function(event) {
+  }
+
+  handlePassChange = (event) => {
     this.setState({'pass': event.target.value});
-  },
-  hideMessage: function() {
+  }
+
+  hideMessage = () => {
     this.setState({'hideMsg': true});
-  },
-  displayMessage: function(msg, ok) {
+  }
+
+  displayMessage = (msg, ok) => {
     this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
-  },
-  render: function() {
+  }
+
+  render = () => {
     var cName  = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
     var qrCode = null;
 
     if (this.props.img) {
-      qrCode = (
-        <div className='row justify-content-center'>
+      qrCode =
+        <div className="row justify-content-center">
           <OtpQrCode img={this.props.img} secret={this.props.secret} />
-        </div>
-      );
-    }
+        </div>;
+}
     return (
-        <div className='row otp-enroll'>
-          <div className='offset-4 col-4 col-xs-offset-1 col-xs-10 text-center'>
+        <div className="row otp-enroll">
+          <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center">
             {qrCode}
-            <div className='row justify-content-center'>
-              <form role='form' onSubmit={this.handleSubmit}>
-                <input className='form-control' type='pass' placeholder='code' onChange={this.handlePassChange} />
-                <input className='form-control submit' type='submit' value='Validate' />
-                <div className={cName} ref='message'>{this.state.msg}</div>
+            <div className="row justify-content-center">
+              <form role="form" onSubmit={this.handleSubmit}>
+                <input className="form-control" type="pass" placeholder="code" onChange={this.handlePassChange} />
+                <input className="form-control submit" type="submit" value="Validate" />
+                <div className={cName}>{this.state.msg}</div>
               </form>
             </div>
           </div>
         </div>
        );
   }
-});
+}
+
+export default OtpEnrollForm;
-- 
cgit v1.2.3

