import React from 'react'; import { withRouter, RouteComponentProps, Redirect, Switch, Route, } from 'react-router-dom'; import { connect } from 'react-redux'; import { compose } from 'recompose'; import { Tabs, Badge } from 'antd'; import { usersActions } from 'modules/users'; import { AppState } from 'store/reducers'; import HeaderDetails from 'components/HeaderDetails'; import ProfileUser from './ProfileUser'; import ProfileEdit from './ProfileEdit'; import ProfilePendingList from './ProfilePendingList'; import ProfileProposal from './ProfileProposal'; import ProfileContribution from './ProfileContribution'; import ProfileComment from './ProfileComment'; import ProfileInvite from './ProfileInvite'; import Placeholder from 'components/Placeholder'; import Loader from 'components/Loader'; import ExceptionPage from 'components/ExceptionPage'; import ContributionModal from 'components/ContributionModal'; import LinkableTabs from 'components/LinkableTabs'; import { UserContribution } from 'types'; import ProfileArbitrated from './ProfileArbitrated'; import './style.less'; interface StateProps { usersMap: AppState['users']['map']; authUser: AppState['auth']['user']; hasCheckedUser: AppState['auth']['hasCheckedUser']; } interface DispatchProps { fetchUser: typeof usersActions['fetchUser']; fetchUserInvites: typeof usersActions['fetchUserInvites']; } type Props = RouteComponentProps & StateProps & DispatchProps; interface State { activeContribution: UserContribution | null; } class Profile extends React.Component { state: State = { activeContribution: null, }; componentDidMount() { this.fetchData(); } componentDidUpdate(prevProps: Props) { const userLookupId = this.props.match.params.id; const prevUserLookupId = prevProps.match.params.id; if (userLookupId !== prevUserLookupId) { window.scrollTo(0, 0); this.fetchData(); } } render() { const { authUser, match, location, hasCheckedUser } = this.props; const { activeContribution } = this.state; const userLookupParam = match.params.id; if (!userLookupParam) { if (authUser && authUser.userid) { return ; } else { return ; } } const user = this.props.usersMap[userLookupParam]; const waiting = !user || !user.hasFetched || !hasCheckedUser; const isAuthedUser = user && authUser && user.userid === authUser.userid; if (waiting) { return ; } if (user.fetchError) { return ; } const { proposals, pendingProposals, contributions, comments, invites, arbitrated, } = user; const isLoading = user.isFetching; const nonePending = pendingProposals.length === 0; const noneCreated = proposals.length === 0; const noneFunded = contributions.length === 0; const noneCommented = comments.length === 0; const noneArbitrated = arbitrated.length === 0; const noneInvites = user.hasFetchedInvites && invites.length === 0; return (
} /> } />
{isAuthedUser && (
{nonePending && ( )}
)}
{noneCreated && ( )} {proposals.map(p => ( ))}
{noneFunded && ( )} {contributions.map(c => ( ))}
{noneCommented && ( )} {comments.map(c => ( ))}
{isAuthedUser && (
{noneInvites && ( )} {invites.map(invite => ( ))}
)} {isAuthedUser && ( {noneArbitrated && ( )} {arbitrated.map(arb => ( ))} )}
); } private fetchData() { const { match } = this.props; const userLookupId = match.params.id; if (userLookupId) { this.props.fetchUser(userLookupId); this.props.fetchUserInvites(userLookupId); } } private openContributionModal = (c: UserContribution) => this.setState({ activeContribution: c }); private closeContributionModal = () => this.setState({ activeContribution: null }); } const TabTitle = (disp: string, count: number) => (
{disp} 0 ? 'is-not-zero' : 'is-zero'}`} showZero={true} count={count} />
); const withConnect = connect( state => ({ usersMap: state.users.map, authUser: state.auth.user, hasCheckedUser: state.auth.hasCheckedUser, }), { fetchUser: usersActions.fetchUser, fetchUserInvites: usersActions.fetchUserInvites, }, ); export default compose( withRouter, withConnect, )(Profile);