'use strict'; import React, { useEffect, useRef } from 'react'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import { Form, Button, Toast } from '@douyinfe/semi-ui'; import { login, LOGIN_SUCCESS } from '../actions/auth'; import { IconLock, IconUser } from '@douyinfe/semi-icons'; import '../style.less' const Login = props => { const { dispatch, user, error, actions, apiRoot, isRequesting } = props const form = useRef(); useEffect(() => { if (error) { Toast.error(error); form.current.setValue('password', '') } }, [error]) useEffect(() => { if (user && user.authorized) { dispatch(push('/edgeGateway/gateway')); // localStorage.setItem('fs_iot_auth_selected_sider', JSON.stringify([])) // localStorage.setItem('fs_iot_auth_open_sider', JSON.stringify([])) } }, [user]) return (
{ dispatch(login(values.username, values.password)).then(res => { const data = res.payload.user // dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token })) }) }} getFormApi={formApi => form.current = formApi} > } style={{ background: 'rgba(24, 89, 193, 0.08)', height: 40, marginTop: 26 }} /> } style={{ background: 'rgba(24, 89, 193, 0.08)', height: 40 }} />
); } function mapStateToProps(state) { const { auth, global } = state; return { user: auth.user, error: auth.error, actions: global.actions, apiRoot: global.apiRoot, isRequesting: auth.isRequesting } } export default connect(mapStateToProps)(Login);