aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/Card.js80
1 files changed, 33 insertions, 47 deletions
diff --git a/src/components/Card.js b/src/components/Card.js
index fb11834..7b615ea 100644
--- a/src/components/Card.js
+++ b/src/components/Card.js
@@ -1,56 +1,42 @@
1import React from 'react'; 1import React, { useState, useEffect } from 'react';
2import QRCode from 'qrcode.react'; 2import QRCode from 'qrcode.react';
3import './style.css'; 3import './style.css';
4 4
5class Card extends React.Component { 5const Card = () => {
6 constructor(props) { 6 const [ssid, setSsid] = useState('');
7 super(props); 7 const [password, setPassword] = useState('');
8 this.state = {ssid: '', password: '', qrvalue: ''}; 8 const [qrvalue, setQrvalue] = useState('');
9 this.handleSSIDChange = this.handleSSIDChange.bind(this); 9
10 this.handlePasswordChange= this.handlePasswordChange.bind(this); 10 useEffect(() => {
11 } 11 setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`);
12 12 }, [ssid, password]);
13 handleSSIDChange(event) { 13
14 this.setState({ssid: event.target.value}, () => this.generateqr()); 14 return (
15 } 15 <div>
16 16 <fieldset id="print-area">
17 handlePasswordChange(event) { 17 <legend></legend>
18 this.setState({password: event.target.value}, () => this.generateqr()); 18
19 } 19 <h1>WiFi Login</h1>
20 20 <hr/>
21 generateqr() {
22 const qrcode = `WIFI:T:WPA;S:${this.state.ssid};P:${this.state.password};;`
23 this.setState({qrvalue: qrcode});
24 }
25
26 render() {
27 return (
28 <div>
29 <fieldset id="print-area">
30 <legend></legend>
31
32 <h1>WiFi Login</h1>
33 <hr/>
34
35 <div className="details">
36 <QRCode className="qrcode" value={this.state.qrvalue} size={175} />
37
38 <div className="text">
39 <label>Network name</label>
40 <input id="ssid" type="text" maxlength="32" placeholder="Enter your WiFi Network" value={this.state.ssid} onChange={this.handleSSIDChange}/>
41 <label>Password</label>
42 <input id="password" type="text" maxlength="64" placeholder="password" value={this.state.password} onChange={this.handlePasswordChange}/>
43 </div>
44 </div>
45 21
46 <p><span role="img" aria-label="mobile-phone">πŸ“ΈπŸ“±</span>Point your phone's camera at the QR Code to connect automatically</p> 22 <div className="details">
47 </fieldset> 23 <QRCode className="qrcode" value={qrvalue} size={175} />
48 <div className="print-btn"> 24
49 <button onClick={window.print}>Print</button> 25 <div className="text">
26 <label>Network name</label>
27 <input id="ssid" type="text" maxlength="32" placeholder="Enter your WiFi Network" value={ssid} onChange={event => setSsid(event.target.value)} />
28 <label>Password</label>
29 <input id="password" type="text" maxlength="64" placeholder="password" value={password} onChange={event => setPassword(event.target.value)} />
30 </div>
50 </div> 31 </div>
32
33 <p><span role="img" aria-label="mobile-phone">πŸ“ΈπŸ“±</span>Point your phone's camera at the QR Code to connect automatically</p>
34 </fieldset>
35 <div className="print-btn">
36 <button onClick={window.print}>Print</button>
51 </div> 37 </div>
52 ) 38 </div>
53 } 39 )
54} 40}
55 41
56export default Card; 42export default Card;