-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RecipientList): Show recipient groups
- Loading branch information
Showing
11 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/cozy-sharing/src/components/Avatar/GroupAvatar.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
|
||
import Avatar from 'cozy-ui/transpiled/react/Avatar' | ||
import TeamIcon from 'cozy-ui/transpiled/react/Icons/Team' | ||
|
||
const GroupAvatar = ({ size }) => { | ||
return <Avatar icon={TeamIcon} size={size} /> | ||
} | ||
|
||
export { GroupAvatar } |
13 changes: 13 additions & 0 deletions
13
packages/cozy-sharing/src/components/Avatar/GroupAvatar.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { GroupAvatar } from './GroupAvatar' | ||
|
||
const meta = { | ||
component: GroupAvatar, | ||
args: {} | ||
} | ||
|
||
export default meta | ||
|
||
export const Default = { | ||
name: 'Default', | ||
args: {} | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/cozy-sharing/src/components/Recipient/GroupRecipient.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
|
||
import { useClient } from 'cozy-client' | ||
import Fade from 'cozy-ui/transpiled/react/Fade' | ||
import ListItem from 'cozy-ui/transpiled/react/ListItem' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import { GroupRecipientPermissions } from './GroupRecipientPermissions' | ||
import { FADE_IN_DURATION } from '../../helpers/recipients' | ||
import { GroupAvatar } from '../Avatar/GroupAvatar' | ||
|
||
const GroupRecipient = props => { | ||
const { name, members, fadeIn } = props | ||
const { t } = useI18n() | ||
const client = useClient() | ||
|
||
const nbMember = members.length | ||
const nbMemberReady = members.filter( | ||
member => !['revoked', 'mail-not-sent'].includes(member.status) | ||
).length | ||
const isCurrentInstanceInsideMembers = members.some( | ||
member => member.instance === client.options.uri | ||
) | ||
|
||
return ( | ||
<Fade in timeout={fadeIn ? FADE_IN_DURATION : 0}> | ||
<ListItem disableGutters> | ||
<ListItemIcon> | ||
<GroupAvatar size="small" /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={ | ||
<Typography className="u-ellipsis" variant="body1"> | ||
{name} | ||
</Typography> | ||
} | ||
secondary={ | ||
t('GroupRecipient.secondary', { nbMember, nbMemberReady }) + | ||
(isCurrentInstanceInsideMembers | ||
? ` (${t('GroupRecipient.secondary_you')})` | ||
: '') | ||
} | ||
/> | ||
<ListItemSecondaryAction> | ||
<GroupRecipientPermissions {...props} /> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
</Fade> | ||
) | ||
} | ||
|
||
export { GroupRecipient } |
38 changes: 38 additions & 0 deletions
38
packages/cozy-sharing/src/components/Recipient/GroupRecipient.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { GroupRecipient } from './GroupRecipient' | ||
|
||
const meta = { | ||
component: GroupRecipient, | ||
args: { | ||
name: 'Family', | ||
isOwner: true, | ||
read_only: false, | ||
members: [ | ||
{ status: 'ready' }, | ||
{ status: 'mail-not-sent' }, | ||
{ status: 'pending' }, | ||
{ status: 'revoked' } | ||
], | ||
groupIndex: 0 | ||
} | ||
} | ||
|
||
export default meta | ||
|
||
export const Default = { | ||
name: 'Default', | ||
args: {} | ||
} | ||
|
||
export const InstanceInsideMembers = { | ||
name: 'Instance inside members', | ||
args: { | ||
isOwner: false, | ||
instance: 'http://alice.cozy.localhost:8080', | ||
members: [ | ||
{ status: 'ready', instance: 'http://alice.cozy.localhost:8080' }, | ||
{ status: 'mail-not-sent' }, | ||
{ status: 'pending' }, | ||
{ status: 'revoked' } | ||
] | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/cozy-sharing/src/components/Recipient/GroupRecipientPermissions.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useRef } from 'react' | ||
|
||
import { useClient } from 'cozy-client' | ||
import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu' | ||
import { | ||
makeActions, | ||
divider | ||
} from 'cozy-ui/transpiled/react/ActionsMenu/Actions' | ||
import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import { permission } from './actions/permission' | ||
import { revokeGroup } from './actions/revokeGroup' | ||
|
||
const GroupRecipientPermissions = ({ | ||
isOwner, | ||
instance, | ||
read_only: isReadOnly = false, | ||
className | ||
}) => { | ||
const { t } = useI18n() | ||
const buttonRef = useRef() | ||
const client = useClient() | ||
|
||
const [isMenuDisplayed, setMenuDisplayed] = useState(false) | ||
|
||
const instanceMatchesClient = | ||
instance !== undefined && instance === client.options.uri | ||
const shouldShowMenu = (instanceMatchesClient && !isOwner) || isOwner | ||
|
||
const toggleMenu = () => setMenuDisplayed(!isMenuDisplayed) | ||
const hideMenu = () => setMenuDisplayed(false) | ||
|
||
const handleRevocation = () => { | ||
// TODO : Need to be implemented | ||
} | ||
|
||
const type = isReadOnly ? 'one-way' : 'two-way' | ||
|
||
const actions = makeActions([permission, divider, revokeGroup], { | ||
t, | ||
type, | ||
isOwner, | ||
handleRevocation | ||
}) | ||
|
||
return ( | ||
<div className={className}> | ||
{shouldShowMenu && ( | ||
<> | ||
<DropdownButton | ||
ref={buttonRef} | ||
aria-controls="simple-menu" | ||
aria-haspopup="true" | ||
onClick={toggleMenu} | ||
textVariant="body2" | ||
> | ||
{t(`Share.type.${type}`).toLowerCase()} | ||
</DropdownButton> | ||
<ActionsMenu | ||
ref={buttonRef} | ||
open={isMenuDisplayed} | ||
actions={actions} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'right' | ||
}} | ||
autoClose | ||
onClose={hideMenu} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export { GroupRecipientPermissions } |
41 changes: 41 additions & 0 deletions
41
packages/cozy-sharing/src/components/Recipient/GroupRecipientPermissions.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { GroupRecipientPermissions } from './GroupRecipientPermissions' | ||
|
||
const meta = { | ||
component: GroupRecipientPermissions, | ||
args: { | ||
onRevoke: () => {}, | ||
onRevokeSelf: () => {}, | ||
type: 'two-way', | ||
status: 'ready', | ||
groupIndex: 0 | ||
}, | ||
argTypes: { | ||
status: { | ||
control: 'select', | ||
options: ['ready', 'mail-not-sent', 'pending', 'seen', 'owner'], | ||
defaultValue: 'ready' | ||
}, | ||
type: { | ||
control: 'select', | ||
options: ['one-way', 'two-way'], | ||
defaultValue: 'two-way' | ||
} | ||
} | ||
} | ||
|
||
export default meta | ||
|
||
export const Owner = { | ||
name: 'Owner', | ||
args: { | ||
isOwner: true | ||
} | ||
} | ||
|
||
export const Self = { | ||
name: 'Self', | ||
args: { | ||
isOwner: false, | ||
instance: 'http://alice.cozy.localhost:8080' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/cozy-sharing/src/components/Recipient/actions/revokeGroup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { forwardRef } from 'react' | ||
|
||
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import ForbiddenIcon from 'cozy-ui/transpiled/react/Icons/Forbidden' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
|
||
const revokeGroup = ({ t, isOwner, handleRevocation }) => { | ||
const revokeType = isOwner ? 'revoke' : 'revokeSelf' | ||
const title = t(`RevokeGroupItem.${revokeType}.title`) | ||
const desc = t(`RevokeGroupItem.${revokeType}.desc`) | ||
|
||
const icon = ForbiddenIcon | ||
|
||
return { | ||
name: 'revokeMember', | ||
label: title, | ||
icon, | ||
action: () => { | ||
handleRevocation() | ||
}, | ||
Component: forwardRef(function RevokeMemberItem(props, ref) { | ||
return ( | ||
<ActionsMenuItem {...props} ref={ref}> | ||
<ListItemIcon> | ||
<Icon icon={icon} color="var(--errorColor)" /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={<Typography color="error">{title}</Typography>} | ||
secondary={desc} | ||
/> | ||
</ActionsMenuItem> | ||
) | ||
}) | ||
} | ||
} | ||
export { revokeGroup } |