diff --git a/packages/cozy-sharing/src/components/Recipient/LinkRecipientPermissions.jsx b/packages/cozy-sharing/src/components/Recipient/LinkRecipientPermissions.jsx index 7d3f8d5d88..e34bb94223 100644 --- a/packages/cozy-sharing/src/components/Recipient/LinkRecipientPermissions.jsx +++ b/packages/cozy-sharing/src/components/Recipient/LinkRecipientPermissions.jsx @@ -1,156 +1,47 @@ +import PropTypes from 'prop-types' import React, { useState, useRef } from 'react' import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton' -import Icon from 'cozy-ui/transpiled/react/Icon' -import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash' -import Spinner from 'cozy-ui/transpiled/react/Spinner' -import Typography from 'cozy-ui/transpiled/react/Typography' -import ActionMenu, { - ActionMenuItem, - ActionMenuRadio -} from 'cozy-ui/transpiled/react/deprecated/ActionMenu' -import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' -import { isOnlyReadOnlyLinkAllowed } from '../../helpers/link' import { checkIsReadOnlyPermissions } from '../../helpers/permissions' -import logger from '../../logger' +import { ShareRestrictionModal } from '../ShareRestrictionModal/ShareRestrictionModal' -const LinkRecipientPermissions = ({ - className, - document, - documentType, - permissions, - onChangePermissions, - onDisable -}) => { +const LinkRecipientPermissions = ({ className, document, permissions }) => { const { t } = useI18n() const buttonRef = useRef() - const [menuIsOpen, setMenuIsOpen] = useState(false) - const [loading, setLoading] = useState(false) + const [openShareRestrictionModal, setOpenShareRestrictionModal] = + useState(false) const isReadOnlyPermissions = checkIsReadOnlyPermissions(permissions) - const toggleMenu = () => { - setMenuIsOpen(!menuIsOpen) - } - - const deleteShareLink = async () => { - try { - setLoading(true) - await onDisable(document) - } catch (e) { - Alerter.error(t(`${documentType}.share.error.revoke`)) - logger.log(e) - } finally { - setLoading(false) - } - } - - const updateLinkPermissions = ({ isReadOnly }) => { - const verbs = isReadOnly ? ['GET'] : ['GET', 'POST', 'PUT', 'PATCH'] - try { - onChangePermissions(document, verbs) - } catch (err) { - Alerter.error(t(`${documentType}.share.shareByLink.permserror`)) - logger.log(err) - } - } return (
- {loading && } - {!loading && ( - <> - - {t( - `Share.type.${isReadOnlyPermissions ? 'one-way' : 'two-way'}` - ).toLowerCase()} - - {menuIsOpen && ( - - - } - onClick={() => { - toggleMenu() - updateLinkPermissions({ isReadOnly: true }) - }} - > - <> - {document?.type === 'directory' - ? t(`Share.permissionLink.seeFolder`) - : t(`Share.permissionLink.seeFile`)} - - {t('Share.permissionLink.readDescription')} - - - - {!isOnlyReadOnlyLinkAllowed({ documentType }) && ( - - } - onClick={() => { - toggleMenu() - updateLinkPermissions({ isReadOnly: false }) - }} - > - <> - {document?.type === 'directory' - ? t(`Share.permissionLink.modifyFolder`) - : t(`Share.permissionLink.modifyFile`)} - - {t('Share.permissionLink.writeDescription')} - - - - )} -
- } - onClick={() => { - toggleMenu() - deleteShareLink() - }} - > - - {t('Share.permissionLink.deactivate')} - - -
- )} - - )} + <> + setOpenShareRestrictionModal(true)} + > + {t( + `Share.type.${isReadOnlyPermissions ? 'one-way' : 'two-way'}` + ).toLowerCase()} + + {openShareRestrictionModal && ( + setOpenShareRestrictionModal(false)} + /> + )} +
) } +LinkRecipientPermissions.propTypes = { + className: PropTypes.string, + document: PropTypes.object.isRequired, + permissions: PropTypes.object.isRequired +} + export default LinkRecipientPermissions