-
Notifications
You must be signed in to change notification settings - Fork 64
/
UploadItem.jsx
47 lines (43 loc) · 1.33 KB
/
UploadItem.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from 'react'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { translate } from 'cozy-ui/transpiled/react'
import { ActionMenuItem } from 'cozy-ui/transpiled/react/ActionMenu'
import Icon from 'cozy-ui/transpiled/react/Icon'
import FileInput from 'cozy-ui/transpiled/react/FileInput'
import withSharingState from 'cozy-sharing/dist/hoc/withSharingState'
import { uploadFiles } from 'drive/web/modules/navigation/duck'
import toolbarContainer from '../toolbar'
const UploadItem = ({ t, isDisabled, onUpload }) => (
<FileInput
label={t('toolbar.menu_upload')}
disabled={isDisabled}
multiple
onChange={onUpload}
data-test-id="upload-btn"
value={[]}
// FileInput needs to stay rendered until the onChange event, so we prevent the event from bubbling
onClick={e => e.stopPropagation()}
>
<ActionMenuItem
left={<Icon icon="upload" />}
onClick={e => e.stopPropagation()}
>
{t('toolbar.menu_upload')}
</ActionMenuItem>
</FileInput>
)
const mapDispatchToProps = (dispatch, { displayedFolder, sharingState }) => ({
onUpload: files => {
dispatch(uploadFiles(files, displayedFolder.id, sharingState))
}
})
export default compose(
withSharingState,
toolbarContainer,
translate(),
connect(
null,
mapDispatchToProps
)
)(UploadItem)