* Split permissions for reading documents from updating collection * fix: Admins should have collection read permission, tests * tsc * Add admin option to permission selector * Combine publish and create permissions, update -> createDocuments where appropriate * Plural -> singular * wip * Quick version of collection structure loading, will revisit * Remove documentIds method * stash * fixing tests to account for admin creation * Add self-hosted migration * fix: Allow groups to have admin permission * Prefetch collection documents * fix: Document explorer (move/publish) not working with async documents * fix: Cannot re-parent document to collection by drag and drop * fix: Cannot drag to import into collection item without admin permission * Remove unused isEditor getter
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
import { CollectionPermission } from "@shared/types";
|
|
import Membership from "~/models/Membership";
|
|
import User from "~/models/User";
|
|
import Avatar from "~/components/Avatar";
|
|
import Badge from "~/components/Badge";
|
|
import Button from "~/components/Button";
|
|
import Flex from "~/components/Flex";
|
|
import ListItem from "~/components/List/Item";
|
|
import Time from "~/components/Time";
|
|
import MemberMenu from "~/menus/MemberMenu";
|
|
import InputMemberPermissionSelect from "./InputMemberPermissionSelect";
|
|
|
|
type Props = {
|
|
user: User;
|
|
membership?: Membership | undefined;
|
|
canEdit: boolean;
|
|
onAdd?: () => void;
|
|
onRemove?: () => void;
|
|
onUpdate?: (permission: CollectionPermission) => void;
|
|
};
|
|
|
|
const MemberListItem = ({
|
|
user,
|
|
membership,
|
|
onRemove,
|
|
onUpdate,
|
|
onAdd,
|
|
canEdit,
|
|
}: Props) => {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<ListItem
|
|
title={user.name}
|
|
subtitle={
|
|
<>
|
|
{user.lastActiveAt ? (
|
|
<Trans>
|
|
Active <Time dateTime={user.lastActiveAt} /> ago
|
|
</Trans>
|
|
) : (
|
|
t("Never signed in")
|
|
)}
|
|
{user.isInvited && <Badge>{t("Invited")}</Badge>}
|
|
{user.isAdmin && <Badge primary={user.isAdmin}>{t("Admin")}</Badge>}
|
|
</>
|
|
}
|
|
image={<Avatar model={user} size={32} />}
|
|
actions={
|
|
<Flex align="center" gap={8}>
|
|
{onUpdate && (
|
|
<InputMemberPermissionSelect
|
|
value={membership ? membership.permission : undefined}
|
|
onChange={onUpdate}
|
|
disabled={!canEdit}
|
|
/>
|
|
)}
|
|
{canEdit && (
|
|
<>
|
|
{onRemove && <MemberMenu onRemove={onRemove} />}
|
|
{onAdd && (
|
|
<Button onClick={onAdd} neutral>
|
|
{t("Add")}
|
|
</Button>
|
|
)}
|
|
</>
|
|
)}
|
|
</Flex>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default observer(MemberListItem);
|