-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show more info in share modal about accesses
- Loading branch information
Showing
12 changed files
with
163 additions
and
54 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
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,87 @@ | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Loader } from '@graasp/ui'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import { Typography, Grid } from '@material-ui/core'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import { useTranslation } from 'react-i18next'; | ||
import InfoIcon from '@material-ui/icons/Info'; | ||
import { LayoutContext } from './LayoutContext'; | ||
import { hooks } from '../../config/queryClient'; | ||
import ItemMemberships from '../item/ItemMemberships'; | ||
import { hasItemLoginEnabled, isItemPublic } from '../../utils/itemTag'; | ||
import { SHARE_MODAL_AVATAR_GROUP_MAX_AVATAR } from '../../config/constants'; | ||
|
||
const AccessIndication = ({ itemId, onClick }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { data: tags, isLoading: isTagsLoading } = hooks.useTags(); | ||
const { data: itemTags, isLoading: isItemTagsLoading } = hooks.useItemTags( | ||
itemId, | ||
); | ||
const { setIsItemSettingsOpen } = useContext(LayoutContext); | ||
|
||
const isPublic = isItemPublic({ itemTags, tags }); | ||
const hasItemLogin = hasItemLoginEnabled({ itemTags, tags }); | ||
|
||
const openSettings = () => { | ||
onClick(); | ||
setIsItemSettingsOpen(true); | ||
}; | ||
|
||
if (isTagsLoading || isItemTagsLoading) { | ||
return <Loader />; | ||
} | ||
|
||
// check tags and display access methods' indications | ||
let accessText = null; | ||
let tooltipText = null; | ||
if (isPublic) { | ||
accessText = t('Public'); | ||
tooltipText = t('This item is public. Anyone can access this item.'); | ||
} else if (hasItemLogin) { | ||
accessText = t('Anyone authenticated with the link'); | ||
tooltipText = t( | ||
'This item enables item login. New users can access this item when they authenticate using the item login.', | ||
); | ||
} | ||
|
||
if (accessText && tooltipText) { | ||
return ( | ||
<Grid container justify="space-between" alignItems="center"> | ||
<Grid item> | ||
<Typography variant="body1"> | ||
{`${t('Access')}: ${accessText}`} | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<Tooltip title={tooltipText}> | ||
<IconButton | ||
aria-label="access information" | ||
color="primary" | ||
onClick={openSettings} | ||
> | ||
<InfoIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
// show memberships when the item is not public and does not allow iten login | ||
return ( | ||
<ItemMemberships | ||
onClick={openSettings} | ||
id={itemId} | ||
maxAvatar={SHARE_MODAL_AVATAR_GROUP_MAX_AVATAR} | ||
/> | ||
); | ||
}; | ||
|
||
AccessIndication.propTypes = { | ||
onClick: PropTypes.func.isRequired, | ||
itemId: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default AccessIndication; |
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
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
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
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
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