forked from naturalcrit/homebrewery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add User look up function to Admin page
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require('./userLookup.less'); | ||
const React = require('react'); | ||
const createClass = require('create-react-class'); | ||
const cx = require('classnames'); | ||
const _ = require('lodash'); | ||
|
||
const request = require('superagent'); | ||
const Moment = require('moment'); | ||
|
||
|
||
const UserLookup = createClass({ | ||
getDefaultProps() { | ||
return {}; | ||
}, | ||
getInitialState() { | ||
return { | ||
query : '', | ||
foundUser : null, | ||
searching : false, | ||
error : null | ||
}; | ||
}, | ||
handleChange(e){ | ||
this.setState({ query: e.target.value }); | ||
}, | ||
lookup(){ | ||
this.setState({ searching: true, error: null }); | ||
|
||
request.get(`/admin/userlookup/${this.state.query}`) | ||
.then((res)=>this.setState({ foundUser: res.body })) | ||
.catch((err)=>this.setState({ error: err })) | ||
.finally(()=>this.setState({ searching: false })); | ||
}, | ||
|
||
renderFoundUser(){ | ||
const user = this.state.foundUser; | ||
return <div className='foundUser'> | ||
<dl> | ||
<dt>Username</dt> | ||
<dd>{user.username}</dd> | ||
|
||
<dt>Last Activity</dt> | ||
<dd>{user.lastActivity} : {Moment(user.lastActivity).fromNow()}</dd> | ||
|
||
<dt>Options</dt> | ||
{Object.entries(user.options).map((opt, idx)=>{ | ||
return <dd key={idx}>- {opt.join(' : ')}</dd>; | ||
})} | ||
</dl> | ||
</div>; | ||
}, | ||
|
||
render(){ | ||
return <div className='userLookup'> | ||
<h2>User Lookup</h2> | ||
<input type='text' value={this.state.query} onChange={this.handleChange} placeholder='username' /> | ||
<button onClick={this.lookup}> | ||
<i className={cx('fas', { | ||
'fa-search' : !this.state.searching, | ||
'fa-spin fa-spinner' : this.state.searching, | ||
})} /> | ||
</button> | ||
|
||
{this.state.error | ||
&& <div className='error'>{this.state.error.toString()}</div> | ||
} | ||
|
||
{this.state.foundUser | ||
? this.renderFoundUser() | ||
: <div className='noUser'>No user found.</div> | ||
} | ||
</div>; | ||
} | ||
}); | ||
|
||
module.exports = UserLookup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
.userLookup{ | ||
input{ | ||
height : 33px; | ||
margin-bottom : 20px; | ||
padding : 0px 10px; | ||
font-family : monospace; | ||
} | ||
button{ | ||
vertical-align : middle; | ||
height : 37px; | ||
} | ||
dl{ | ||
@maxItemWidth : 132px; | ||
dt{ | ||
float : left; | ||
clear : left; | ||
width : @maxItemWidth; | ||
text-align : right; | ||
&::after { | ||
content: " : "; | ||
} | ||
} | ||
dd{ | ||
height : 1em; | ||
margin-left : @maxItemWidth + 6px; | ||
padding : 0 0 0.5em 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters