2020-03-15 03:48:32 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import * as React from "react";
|
2020-11-30 04:04:58 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-06-20 20:59:15 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
import CollectionGroupMembership from "models/CollectionGroupMembership";
|
2020-08-09 05:53:59 +00:00
|
|
|
import Group from "models/Group";
|
2020-06-20 20:59:15 +00:00
|
|
|
import { DropdownMenu, DropdownMenuItem } from "components/DropdownMenu";
|
2020-08-09 05:53:59 +00:00
|
|
|
import GroupListItem from "components/GroupListItem";
|
|
|
|
import InputSelect from "components/InputSelect";
|
2020-03-15 03:48:32 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
group: Group,
|
|
|
|
collectionGroupMembership: ?CollectionGroupMembership,
|
|
|
|
onUpdate: (permission: string) => void,
|
|
|
|
onRemove: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
const MemberListItem = ({
|
|
|
|
group,
|
|
|
|
collectionGroupMembership,
|
|
|
|
onUpdate,
|
|
|
|
onRemove,
|
|
|
|
}: Props) => {
|
2020-11-30 04:04:58 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const PERMISSIONS = React.useMemo(
|
|
|
|
() => [
|
|
|
|
{ label: t("Read only"), value: "read" },
|
|
|
|
{ label: t("Read & Edit"), value: "read_write" },
|
|
|
|
],
|
|
|
|
[t]
|
|
|
|
);
|
|
|
|
|
2020-03-15 03:48:32 +00:00
|
|
|
return (
|
|
|
|
<GroupListItem
|
|
|
|
group={group}
|
|
|
|
onRemove={onRemove}
|
|
|
|
onUpdate={onUpdate}
|
|
|
|
renderActions={({ openMembersModal }) => (
|
2020-08-09 16:48:04 +00:00
|
|
|
<>
|
2020-03-15 03:48:32 +00:00
|
|
|
<Select
|
2020-11-30 04:04:58 +00:00
|
|
|
label={t("Permissions")}
|
2020-03-15 03:48:32 +00:00
|
|
|
options={PERMISSIONS}
|
|
|
|
value={
|
|
|
|
collectionGroupMembership
|
|
|
|
? collectionGroupMembership.permission
|
|
|
|
: undefined
|
|
|
|
}
|
2020-08-09 01:53:11 +00:00
|
|
|
onChange={(ev) => onUpdate(ev.target.value)}
|
2020-03-15 03:48:32 +00:00
|
|
|
labelHidden
|
|
|
|
/>
|
|
|
|
<ButtonWrap>
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuItem onClick={openMembersModal}>
|
2020-12-15 05:16:02 +00:00
|
|
|
{t("Members")}…
|
2020-03-15 03:48:32 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
<hr />
|
2020-11-30 04:04:58 +00:00
|
|
|
<DropdownMenuItem onClick={onRemove}>
|
|
|
|
{t("Remove")}
|
|
|
|
</DropdownMenuItem>
|
2020-03-15 03:48:32 +00:00
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonWrap>
|
2020-08-09 16:48:04 +00:00
|
|
|
</>
|
2020-03-15 03:48:32 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Select = styled(InputSelect)`
|
|
|
|
margin: 0;
|
|
|
|
font-size: 14px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ButtonWrap = styled.div`
|
|
|
|
margin-left: 6px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default MemberListItem;
|