2019-01-13 03:41:45 +00:00
|
|
|
|
// @flow
|
2021-06-10 00:42:14 +00:00
|
|
|
|
import { formatDistanceToNow } from "date-fns";
|
2020-12-03 04:48:24 +00:00
|
|
|
|
import { observer } from "mobx-react";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import { EditIcon } from "outline-icons";
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import * as React from "react";
|
2020-11-30 04:04:58 +00:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2021-10-20 05:12:20 +00:00
|
|
|
|
import { useHistory } from "react-router-dom";
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import User from "models/User";
|
|
|
|
|
import Avatar from "components/Avatar";
|
|
|
|
|
import Badge from "components/Badge";
|
|
|
|
|
import Button from "components/Button";
|
2020-07-10 05:33:07 +00:00
|
|
|
|
import Flex from "components/Flex";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import HelpText from "components/HelpText";
|
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
import PaginatedDocumentList from "components/PaginatedDocumentList";
|
|
|
|
|
import Subheading from "components/Subheading";
|
2020-12-03 04:48:24 +00:00
|
|
|
|
import useCurrentUser from "hooks/useCurrentUser";
|
|
|
|
|
import useStores from "hooks/useStores";
|
2021-10-24 19:30:27 +00:00
|
|
|
|
import { settingsPath } from "utils/routeHelpers";
|
2019-01-13 03:41:45 +00:00
|
|
|
|
|
2021-01-30 05:36:09 +00:00
|
|
|
|
type Props = {|
|
2019-01-13 03:41:45 +00:00
|
|
|
|
user: User,
|
2019-08-09 06:09:09 +00:00
|
|
|
|
onRequestClose: () => void,
|
2021-01-30 05:36:09 +00:00
|
|
|
|
|};
|
2019-01-13 03:41:45 +00:00
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
function UserProfile(props: Props) {
|
|
|
|
|
const { t } = useTranslation();
|
2020-12-03 04:48:24 +00:00
|
|
|
|
const { documents } = useStores();
|
|
|
|
|
const currentUser = useCurrentUser();
|
2021-10-20 05:12:20 +00:00
|
|
|
|
const history = useHistory();
|
2020-12-03 04:48:24 +00:00
|
|
|
|
const { user, ...rest } = props;
|
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
if (!user) return null;
|
2020-12-03 04:48:24 +00:00
|
|
|
|
const isCurrentUser = currentUser.id === user.id;
|
2019-01-13 03:41:45 +00:00
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
title={
|
|
|
|
|
<Flex align="center">
|
2021-10-20 05:12:20 +00:00
|
|
|
|
<Avatar src={user.avatarUrl} size={38} alt={t("Profile picture")} />
|
2020-11-30 04:04:58 +00:00
|
|
|
|
<span> {user.name}</span>
|
2019-01-13 03:41:45 +00:00
|
|
|
|
</Flex>
|
2020-11-30 04:04:58 +00:00
|
|
|
|
}
|
|
|
|
|
{...rest}
|
|
|
|
|
>
|
|
|
|
|
<Flex column>
|
|
|
|
|
<Meta>
|
|
|
|
|
{isCurrentUser
|
|
|
|
|
? t("You joined")
|
|
|
|
|
: user.lastActiveAt
|
|
|
|
|
? t("Joined")
|
|
|
|
|
: t("Invited")}{" "}
|
|
|
|
|
{t("{{ time }} ago.", {
|
2021-06-16 14:54:56 +00:00
|
|
|
|
time: formatDistanceToNow(Date.parse(user.createdAt)),
|
2020-11-30 04:04:58 +00:00
|
|
|
|
})}
|
|
|
|
|
{user.isAdmin && (
|
2021-02-13 01:34:40 +00:00
|
|
|
|
<StyledBadge primary={user.isAdmin}>{t("Admin")}</StyledBadge>
|
2020-11-30 04:04:58 +00:00
|
|
|
|
)}
|
2021-02-13 01:34:40 +00:00
|
|
|
|
{user.isSuspended && <StyledBadge>{t("Suspended")}</StyledBadge>}
|
2020-11-30 04:04:58 +00:00
|
|
|
|
{isCurrentUser && (
|
|
|
|
|
<Edit>
|
|
|
|
|
<Button
|
2021-10-24 19:30:27 +00:00
|
|
|
|
onClick={() => history.push(settingsPath())}
|
2020-11-30 04:04:58 +00:00
|
|
|
|
icon={<EditIcon />}
|
|
|
|
|
neutral
|
|
|
|
|
>
|
|
|
|
|
{t("Edit Profile")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Edit>
|
|
|
|
|
)}
|
|
|
|
|
</Meta>
|
|
|
|
|
<PaginatedDocumentList
|
|
|
|
|
documents={documents.createdByUser(user.id)}
|
|
|
|
|
fetch={documents.fetchOwned}
|
|
|
|
|
options={{ user: user.id }}
|
|
|
|
|
heading={<Subheading>{t("Recently updated")}</Subheading>}
|
|
|
|
|
empty={
|
|
|
|
|
<HelpText>
|
|
|
|
|
{t("{{ userName }} hasn’t updated any documents yet.", {
|
|
|
|
|
userName: user.name,
|
|
|
|
|
})}
|
|
|
|
|
</HelpText>
|
|
|
|
|
}
|
|
|
|
|
showCollection
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
2019-01-13 03:41:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-10-20 05:12:20 +00:00
|
|
|
|
export default observer(UserProfile);
|