-
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(mespapiers): Split ScanResultWrapper component
And use the new components
- Loading branch information
Showing
6 changed files
with
213 additions
and
109 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanResultActions.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,53 @@ | ||
import cx from 'classnames' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
import Button, { ButtonLink } from 'cozy-ui/transpiled/react/Button' | ||
import DialogActions from 'cozy-ui/transpiled/react/DialogActions' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import useBreakpoints from 'cozy-ui/transpiled/react/hooks/useBreakpoints' | ||
|
||
import { PaperDefinitionsStepPropTypes } from '../../constants/PaperDefinitionsPropTypes' | ||
|
||
const ScanResultActions = ({ currentStep, onNextStep, onRepeatStep }) => { | ||
const { t } = useI18n() | ||
const { isMobile } = useBreakpoints() | ||
const { multipage } = currentStep | ||
|
||
return ( | ||
<DialogActions | ||
disableSpacing | ||
className={cx('columnLayout u-mb-1-half u-mt-0 cozyDialogActions', { | ||
'u-mh-1': !isMobile, | ||
'u-mh-0': isMobile | ||
})} | ||
> | ||
<Button | ||
className="u-db" | ||
data-testid="next-button" | ||
extension="full" | ||
label={t('common.next')} | ||
onClick={onNextStep} | ||
/> | ||
{multipage && ( | ||
<ButtonLink | ||
className="u-ml-0 u-mb-half" | ||
data-testid="repeat-button" | ||
extension="full" | ||
theme="secondary" | ||
icon="camera" | ||
label={t('Acquisition.repeat')} | ||
onClick={onRepeatStep} | ||
/> | ||
)} | ||
</DialogActions> | ||
) | ||
} | ||
|
||
ScanResultActions.propTypes = { | ||
onNextStep: PropTypes.func, | ||
onRepeatStep: PropTypes.func, | ||
currentStep: PaperDefinitionsStepPropTypes | ||
} | ||
|
||
export default ScanResultActions |
69 changes: 69 additions & 0 deletions
69
packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanResultCard.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,69 @@ | ||
import PropTypes from 'prop-types' | ||
import React, { useState, useRef } from 'react' | ||
|
||
import Card from 'cozy-ui/transpiled/react/Card' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
|
||
import ScanResultCardActions from './ScanResultCardActions' | ||
import { isSameFile } from './helpers' | ||
import RotateImage from './widgets/RotateImage' | ||
import { useFormData } from '../Hooks/useFormData' | ||
|
||
const isImageType = file => file.type.match(/image\/.*/) | ||
|
||
const ScanResultCard = ({ currentFile, setCurrentFile }) => { | ||
const imageRef = useRef(null) | ||
const { setFormData, formData } = useFormData() | ||
const [rotationImage, setRotationImage] = useState(0) | ||
|
||
const handleSelectedFile = () => { | ||
const newData = formData.data.filter( | ||
data => !isSameFile(currentFile, data.file) | ||
) | ||
|
||
setFormData(prev => ({ | ||
...prev, | ||
data: newData | ||
})) | ||
|
||
setCurrentFile(null) | ||
} | ||
|
||
const handleRotate = () => { | ||
setRotationImage(prev => prev - 90) | ||
} | ||
|
||
return ( | ||
<Card className="u-ta-center u-p-1"> | ||
<div className="u-mah-5"> | ||
{isImageType(currentFile) ? ( | ||
<RotateImage | ||
image={URL.createObjectURL(currentFile)} | ||
rotation={rotationImage} | ||
a11n={{ 'aria-hidden': true }} | ||
ref={imageRef} | ||
/> | ||
) : ( | ||
<> | ||
<Icon icon="file-type-pdf" size={80} aria-hidden="true" /> | ||
<Typography>{currentFile.name}</Typography> | ||
</> | ||
)} | ||
</div> | ||
<div style={{ display: 'flex', gap: '1rem', marginTop: '1rem' }}> | ||
<ScanResultCardActions | ||
onRotate={handleRotate} | ||
onCancel={handleSelectedFile} | ||
/> | ||
</div> | ||
</Card> | ||
) | ||
} | ||
|
||
ScanResultCard.propTypes = { | ||
currentFile: PropTypes.object.isRequired, | ||
setCurrentFile: PropTypes.func.isRequired | ||
} | ||
|
||
export default ScanResultCard |
52 changes: 52 additions & 0 deletions
52
packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanResultCardActions.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,52 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import IconButton from 'cozy-ui/transpiled/react/IconButton' | ||
import { makeStyles } from 'cozy-ui/transpiled/react/styles' | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
border: `1px solid ${theme.palette.border.main}`, | ||
borderRadius: 0, | ||
'&.small': { | ||
padding: '0 1rem' | ||
} | ||
} | ||
})) | ||
|
||
const ScanResultCardActions = ({ onRotate, onCancel }) => { | ||
const classes = useStyles() | ||
const { t } = useI18n() | ||
|
||
return ( | ||
<> | ||
<Button | ||
data-testid="retry-button" | ||
label={t('Acquisition.retry')} | ||
fullWidth | ||
variant="secondary" | ||
onClick={onCancel} | ||
/> | ||
<IconButton | ||
data-testid="rotate-button" | ||
classes={classes} | ||
size="small" | ||
onClick={onRotate} | ||
aria-label={t('Acquisition.rotate')} | ||
title={t('Acquisition.rotate')} | ||
> | ||
<Icon icon="rotate-left" /> | ||
</IconButton> | ||
</> | ||
) | ||
} | ||
|
||
ScanResultCardActions.propTypes = { | ||
onCancel: PropTypes.func, | ||
onRotate: PropTypes.func | ||
} | ||
|
||
export default ScanResultCardActions |
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