-
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: Display a modal before detaching a doc (#604)
* feat: Display a modal before detaching a doc * fix: Fix some reviews
- Loading branch information
Showing
3 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
80 changes: 60 additions & 20 deletions
80
packages/cozy-procedures/src/components/documents/DocumentHolder.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 |
---|---|---|
@@ -1,33 +1,73 @@ | ||
import React from 'react' | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { translate, Chip, Icon } from 'cozy-ui/transpiled/react/' | ||
import { | ||
translate, | ||
Chip, | ||
Icon, | ||
Modal, | ||
SubTitle, | ||
Text | ||
} from 'cozy-ui/transpiled/react/' | ||
import { CozyFile } from 'cozy-doctypes' | ||
|
||
import DocumentsDataFormContainer from '../../containers/DocumentsDataForm' | ||
|
||
const DocumentHolder = ({ document, unlinkDocument, documentId }) => { | ||
const splittedName = CozyFile.splitFilename(document) | ||
return ( | ||
<Chip variant="dashed" className="u-w-100"> | ||
<Icon icon={`file-type-${document.class}`} size={24} className="u-mr-1" /> | ||
<span className="u-flex-grow-1 u-ellipsis"> | ||
{splittedName.filename} | ||
<span className="u-coolGrey">{splittedName.extension}</span> | ||
</span> | ||
<Icon | ||
icon="cross" | ||
size={16} | ||
className="u-pr-1 u-c-pointer" | ||
onClick={() => unlinkDocument({ document, documentId })} | ||
/> | ||
</Chip> | ||
) | ||
class DocumentHolder extends Component { | ||
state = { | ||
isUnlinkConfirmationModalOpened: false | ||
} | ||
|
||
render() { | ||
const { document, unlinkDocument, documentId, t } = this.props | ||
const { isUnlinkConfirmationModalOpened } = this.state | ||
|
||
const splittedName = CozyFile.splitFilename(document) | ||
return ( | ||
<> | ||
{isUnlinkConfirmationModalOpened && ( | ||
<Modal | ||
primaryText={t('documents.unlink.unlink')} | ||
primaryAction={() => unlinkDocument({ document, documentId })} | ||
secondaryText={t('cancel')} | ||
secondaryAction={() => | ||
this.setState({ isUnlinkConfirmationModalOpened: false }) | ||
} | ||
title={t('documents.unlink.title')} | ||
description={ | ||
<> | ||
<SubTitle>{t('documents.unlink.subtitle')}</SubTitle> | ||
<Text className="u-mt-1">{t('documents.unlink.text')}</Text> | ||
</> | ||
} | ||
/> | ||
)} | ||
<Chip variant="dashed" className="u-w-100"> | ||
<Icon | ||
icon={`file-type-${document.class}`} | ||
size={24} | ||
className="u-mr-1" | ||
/> | ||
<span className="u-flex-grow-1 u-ellipsis"> | ||
{splittedName.filename} | ||
<span className="u-coolGrey">{splittedName.extension}</span> | ||
</span> | ||
<Icon | ||
icon="cross" | ||
size={16} | ||
className="u-pr-1 u-c-pointer" | ||
onClick={() => this.setState({ isModalOpened: true })} | ||
/> | ||
</Chip> | ||
</> | ||
) | ||
} | ||
} | ||
|
||
DocumentHolder.propTypes = { | ||
unlinkDocument: PropTypes.func.isRequired, | ||
documentId: PropTypes.string.isRequired, | ||
//io.cozy.files | ||
document: PropTypes.object.isRequired | ||
document: PropTypes.object.isRequired, | ||
t: PropTypes.func.isRequired | ||
} | ||
export default translate()(DocumentsDataFormContainer(DocumentHolder)) |
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