2019-01-13 03:41:45 +00:00
|
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import distanceInWordsToNow from "date-fns/distance_in_words_to_now";
|
|
|
|
|
import { inject, observer } from "mobx-react";
|
|
|
|
|
import { withRouter, type RouterHistory } from "react-router-dom";
|
|
|
|
|
import { EditIcon } from "outline-icons";
|
|
|
|
|
import Flex from "shared/components/Flex";
|
|
|
|
|
import HelpText from "components/HelpText";
|
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
import Button from "components/Button";
|
|
|
|
|
import Avatar from "components/Avatar";
|
|
|
|
|
import Badge from "components/Badge";
|
|
|
|
|
import PaginatedDocumentList from "components/PaginatedDocumentList";
|
|
|
|
|
import Subheading from "components/Subheading";
|
|
|
|
|
import User from "models/User";
|
|
|
|
|
import DocumentsStore from "stores/DocumentsStore";
|
|
|
|
|
import AuthStore from "stores/AuthStore";
|
|
|
|
|
import { settings } from "shared/utils/routeHelpers";
|
2019-01-13 03:41:45 +00:00
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
user: User,
|
|
|
|
|
auth: AuthStore,
|
|
|
|
|
documents: DocumentsStore,
|
2019-08-09 06:09:09 +00:00
|
|
|
|
history: RouterHistory,
|
|
|
|
|
onRequestClose: () => void,
|
2019-01-13 03:41:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@observer
|
|
|
|
|
class UserProfile extends React.Component<Props> {
|
|
|
|
|
render() {
|
|
|
|
|
const { user, auth, documents, ...rest } = this.props;
|
|
|
|
|
if (!user) return null;
|
|
|
|
|
const isCurrentUser = auth.user && auth.user.id === user.id;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
title={
|
|
|
|
|
<Flex align="center">
|
|
|
|
|
<Avatar src={user.avatarUrl} size={38} />
|
|
|
|
|
<span> {user.name}</span>
|
|
|
|
|
</Flex>
|
|
|
|
|
}
|
|
|
|
|
{...rest}
|
|
|
|
|
>
|
|
|
|
|
<Flex column>
|
|
|
|
|
<Meta>
|
2020-05-30 20:01:26 +00:00
|
|
|
|
{isCurrentUser
|
2020-06-20 20:59:15 +00:00
|
|
|
|
? "You joined"
|
|
|
|
|
: user.lastActiveAt ? "Joined" : "Invited"}{" "}
|
2019-01-13 03:41:45 +00:00
|
|
|
|
{distanceInWordsToNow(new Date(user.createdAt))} ago.
|
|
|
|
|
{user.isAdmin && (
|
|
|
|
|
<StyledBadge admin={user.isAdmin}>Admin</StyledBadge>
|
|
|
|
|
)}
|
|
|
|
|
{user.isSuspended && <Badge>Suspended</Badge>}
|
|
|
|
|
{isCurrentUser && (
|
|
|
|
|
<Edit>
|
2019-08-09 05:07:29 +00:00
|
|
|
|
<Button
|
|
|
|
|
onClick={() => this.props.history.push(settings())}
|
|
|
|
|
icon={<EditIcon />}
|
|
|
|
|
neutral
|
|
|
|
|
>
|
2019-01-13 03:41:45 +00:00
|
|
|
|
Edit Profile
|
|
|
|
|
</Button>
|
|
|
|
|
</Edit>
|
|
|
|
|
)}
|
|
|
|
|
</Meta>
|
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
documents={documents.createdByUser(user.id)}
|
|
|
|
|
fetch={documents.fetchOwned}
|
|
|
|
|
options={{ user: user.id }}
|
2019-04-06 23:20:27 +00:00
|
|
|
|
heading={<Subheading>Recently updated</Subheading>}
|
2019-03-10 02:55:54 +00:00
|
|
|
|
empty={
|
|
|
|
|
<HelpText>{user.name} hasn’t updated any documents yet.</HelpText>
|
|
|
|
|
}
|
2019-01-13 03:41:45 +00:00
|
|
|
|
showCollection
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Edit = styled.span`
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 46px;
|
|
|
|
|
right: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledBadge = styled(Badge)`
|
|
|
|
|
position: relative;
|
|
|
|
|
top: -2px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Meta = styled(HelpText)`
|
|
|
|
|
margin-top: -12px;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
|
export default inject("documents", "auth")(withRouter(UserProfile));
|