mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: fixed lint erros - destructuring-assignment
This commit is contained in:
parent
0529b8e7a9
commit
b3ea81e596
5 changed files with 22 additions and 14 deletions
|
@ -47,7 +47,7 @@
|
||||||
"prettier/prettier": ["error", null, "@prettier"],
|
"prettier/prettier": ["error", null, "@prettier"],
|
||||||
"react/no-deprecated": 1,
|
"react/no-deprecated": 1,
|
||||||
"react/jsx-no-target-blank": 1,
|
"react/jsx-no-target-blank": 1,
|
||||||
"react/destructuring-assignment": ["warn", "always"],
|
"react/destructuring-assignment": ["error", "always"],
|
||||||
"react/forbid-component-props": ["warn", { "forbid": ["style"] }],
|
"react/forbid-component-props": ["warn", { "forbid": ["style"] }],
|
||||||
"react/no-this-in-sfc": ["warn"],
|
"react/no-this-in-sfc": ["warn"],
|
||||||
"react/no-unsafe": ["warn"],
|
"react/no-unsafe": ["warn"],
|
||||||
|
|
|
@ -36,7 +36,8 @@ export default class App extends Component {
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
componentDidUpdate(_, prevState) {
|
componentDidUpdate(_, prevState) {
|
||||||
if (prevState.isUserLoggedIn !== this.state.isUserLoggedIn) {
|
const { isUserLoggedIn } = this.state;
|
||||||
|
if (prevState.isUserLoggedIn !== isUserLoggedIn) {
|
||||||
this.loadPackages();
|
this.loadPackages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,17 +91,19 @@ class Header extends Component<IProps, IState> {
|
||||||
* close/open popover menu for logged in users.
|
* close/open popover menu for logged in users.
|
||||||
*/
|
*/
|
||||||
handleToggleLogin = () => {
|
handleToggleLogin = () => {
|
||||||
|
const { onToggleLoginModal } = this.props;
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
anchorEl: null,
|
anchorEl: null,
|
||||||
},
|
},
|
||||||
this.props.onToggleLoginModal
|
onToggleLoginModal
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleToggleMNav = () => {
|
handleToggleMNav = () => {
|
||||||
|
const { showMobileNavBar } = this.state;
|
||||||
this.setState({
|
this.setState({
|
||||||
showMobileNavBar: !this.state.showMobileNavBar,
|
showMobileNavBar: !showMobileNavBar,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,12 @@ export default class LoginModal extends Component {
|
||||||
* Required to login
|
* Required to login
|
||||||
*/
|
*/
|
||||||
setCredentials = (name, e) => {
|
setCredentials = (name, e) => {
|
||||||
|
const { form } = this.state;
|
||||||
this.setState({
|
this.setState({
|
||||||
form: {
|
form: {
|
||||||
...this.state.form,
|
...form,
|
||||||
[name]: {
|
[name]: {
|
||||||
...this.state.form[name],
|
...form[name],
|
||||||
value: e.target.value,
|
value: e.target.value,
|
||||||
pristine: false,
|
pristine: false,
|
||||||
},
|
},
|
||||||
|
@ -76,30 +77,32 @@ export default class LoginModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
validateCredentials = (event) => {
|
validateCredentials = (event) => {
|
||||||
|
const { form } = this.state;
|
||||||
// prevents default submit behavior
|
// prevents default submit behavior
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
form: Object.keys(this.state.form).reduce((acc, key) => ({
|
form: Object.keys(form).reduce((acc, key) => ({
|
||||||
...acc,
|
...acc,
|
||||||
...{ [key]: {...this.state.form[key], pristine: false } },
|
...{ [key]: {...form[key], pristine: false } },
|
||||||
}), {}),
|
}), {}),
|
||||||
}, () => {
|
}, () => {
|
||||||
if (!Object.keys(this.state.form).some(id => !this.state.form[id])) {
|
if (!Object.keys(form).some(id => !form[id])) {
|
||||||
this.submitCredentials();
|
this.submitCredentials();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submitCredentials = async () => {
|
submitCredentials = async () => {
|
||||||
const { form: { username, password } } = this.state;
|
const { form } = this.state;
|
||||||
await this.props.onSubmit(username.value, password.value);
|
const { onSubmit } = this.props;
|
||||||
|
await onSubmit(form.username.value, form.password.value);
|
||||||
// let's wait for API response and then set
|
// let's wait for API response and then set
|
||||||
// username and password filed to empty state
|
// username and password filed to empty state
|
||||||
this.setState({
|
this.setState({
|
||||||
form: Object.keys(this.state.form).reduce((acc, key) => ({
|
form: Object.keys(form).reduce((acc, key) => ({
|
||||||
...acc,
|
...acc,
|
||||||
...{ [key]: {...this.state.form[key], value: "", pristine: true } },
|
...{ [key]: {...form[key], value: "", pristine: true } },
|
||||||
}), {}),
|
}), {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,15 @@ export function asyncComponent(getComponent) {
|
||||||
state = {Component: AsyncComponent.Component};
|
state = {Component: AsyncComponent.Component};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (!this.state.Component) {
|
const { Component } = this.state;
|
||||||
|
if (!Component) {
|
||||||
getComponent().then(({default: Component}) => {
|
getComponent().then(({default: Component}) => {
|
||||||
AsyncComponent.Component = Component;
|
AsyncComponent.Component = Component;
|
||||||
this.setState({Component});
|
this.setState({Component});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {Component} = this.state;
|
const {Component} = this.state;
|
||||||
if (Component) {
|
if (Component) {
|
||||||
|
|
Loading…
Reference in a new issue