[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
1.1 KiB

import { Dispatch } from 'redux'
import { connect } from 'react-redux'
import { unauthenticate } from 'src/actions/authentication'
import { getAuthenticated, getChecked, getAuthenticatedUser } from 'src/selectors/authentication'
import { AppState, User } from 'src/types'
import Self from './self'
import { initForm, initField, setFieldValue } from 'src/actions/forms'
const mapStateToProps = (state: AppState) => ({
checked: getChecked(state),
authenticated: getAuthenticated(state),
user: getAuthenticatedUser(state),
})
const mapDispatchToProps = (dispatch: Dispatch) => ({
initForm: (user: User) => {
dispatch(initForm())
dispatch(initField('name'))
dispatch(initField('about'))
dispatch(setFieldValue('name', user.name as string))
dispatch(setFieldValue('about', user.about as string))
},
logout: async () => {
localStorage.clear()
dispatch(unauthenticate())
window.location.href = '/'
},
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(Self)