1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00

fix: minor UI bug fixes

This commit is contained in:
Juan Picado @jotadeveloper 2017-07-16 00:44:50 +02:00
parent 08c5358a8c
commit 84388ff1da
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
3 changed files with 34 additions and 16 deletions

@ -1,12 +1,14 @@
import React from 'react'; import React from 'react';
import {Button, Dialog, Input, MessageBox} from 'element-react'; import {Button, Dialog, Input, MessageBox} from 'element-react';
import API from '../../../utils/api';
import storage from '../../../utils/storage';
import isString from 'lodash/isString'; import isString from 'lodash/isString';
import get from 'lodash/get'; import get from 'lodash/get';
import isNumber from 'lodash/isNumber'; import isNumber from 'lodash/isNumber';
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import API from '../../../utils/api';
import storage from '../../../utils/storage';
import classes from './header.scss'; import classes from './header.scss';
import logo from './logo.png'; import logo from './logo.png';
@ -37,7 +39,7 @@ export default class Header extends React.Component {
async handleSubmit() { async handleSubmit() {
if (this.state.username === '' || this.state.password === '') { if (this.state.username === '' || this.state.password === '') {
return MessageBox.alert('Username or password can\'t be empty!'); return MessageBox.alert('Username or password can\'t be empty!', '');
} }
try { try {
@ -53,28 +55,40 @@ export default class Header extends React.Component {
location.reload(); location.reload();
} catch (e) { } catch (e) {
if (get(e, 'response.status', 0) === 401) { if (get(e, 'response.status', 0) === 401) {
MessageBox.alert(e.response.data.error); MessageBox.alert(e.response.data.error, 'Unable to login');
} else { } else {
MessageBox.alert('Unable to login:' + e.message); MessageBox.alert(e.message, 'Unable to login:');
} }
} }
} }
get isTokenExpire() { get isTokenExpire() {
let token = storage.getItem('token'); const token = storage.getItem('token');
if (!isString(token)) return true;
if (!isString(token)) {
return true;
}
let payload = token.split('.')[1]; let payload = token.split('.')[1];
if (!payload) return true;
if (!payload) {
return true;
}
try { try {
payload = JSON.parse(atob(payload)); payload = JSON.parse(atob(payload));
} catch (err) { } catch (err) {
console.error('Invalid token:', err, token); // eslint-disable-line console.error('Invalid token:', err, token); // eslint-disable-line
return false; return false;
} }
if (!payload.exp || !isNumber(payload.exp)) return true;
let jsTimestamp = (payload.exp * 1000) - 30000; // Report as expire before (real expire time - 30s)
let expired = Date.now() >= jsTimestamp; if (!payload.exp || !isNumber(payload.exp)) {
return true;
}
const jsTimestamp = (payload.exp * 1000) - 30000; // Report as expire before (real expire time - 30s)
const expired = Date.now() >= jsTimestamp;
if (expired) { if (expired) {
storage.clear(); storage.clear();
} }
@ -111,7 +125,7 @@ export default class Header extends React.Component {
<figure> <figure>
npm set registry { location.origin } npm set registry { location.origin }
<br/> <br/>
npm login npm adduser --registry { location.origin }
</figure> </figure>
{this.renderUserActionButton()} {this.renderUserActionButton()}
</div> </div>
@ -128,8 +142,12 @@ export default class Header extends React.Component {
<Input type="password" placeholder="Type your password" onChange={this.handleInput.bind(this, 'password')} /> <Input type="password" placeholder="Type your password" onChange={this.handleInput.bind(this, 'password')} />
</Dialog.Body> </Dialog.Body>
<Dialog.Footer className="dialog-footer"> <Dialog.Footer className="dialog-footer">
<Button onClick={ () => this.toggleLoginModal() }>Cancel</Button> <Button onClick={ () => this.toggleLoginModal() }>
<Button type="primary" onClick={ this.handleSubmit }>Login</Button> Cancel
</Button>
<Button type="primary" onClick={ this.handleSubmit }>
Login
</Button>
</Dialog.Footer> </Dialog.Footer>
</Dialog> </Dialog>
</header> </header>

@ -43,7 +43,7 @@ export default class Detail extends React.Component {
render() { render() {
return ( return (
<div> <div>
<h1 className={ classes.title }>Package: { this.props.match.params.package }</h1> <h1 className={ classes.title }>{ this.props.match.params.package }</h1>
<hr/> <hr/>
{this.renderReadMe()} {this.renderReadMe()}
</div> </div>

@ -8,7 +8,7 @@ @mixin container-size {
} }
$space-lg: 30px; $space-lg: 30px;
$font: "'Source Sans Pro', 'Lucida Grande', sans-serif"; $font: "Arial";
/* Colors */ /* Colors */
$primary-color: #de4136; $primary-color: #de4136;