1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { FileUpload } from '~/components/file-upload/file-upload';
7 import { connect } from 'react-redux';
8 import { RootState } from '~/store/store';
9 import { FileUploadProps } from '../../components/file-upload/file-upload';
10 import { Dispatch } from 'redux';
11 import { fileUploaderActions } from '~/store/file-uploader/file-uploader-actions';
12 import { WrappedFieldProps } from 'redux-form';
13 import { Typography } from '@material-ui/core';
15 export type FileUploaderProps = Pick<FileUploadProps, 'disabled' | 'onDrop'>;
17 const mapStateToProps = (state: RootState, { disabled }: FileUploaderProps): Pick<FileUploadProps, 'files' | 'disabled'> => ({
19 files: state.fileUploader,
22 const mapDispatchToProps = (dispatch: Dispatch, { onDrop }: FileUploaderProps): Pick<FileUploadProps, 'onDrop'> => ({
24 if (files.length > 0) {
25 dispatch(fileUploaderActions.SET_UPLOAD_FILES(files));
31 export const FileUploader = connect(mapStateToProps, mapDispatchToProps)(FileUpload);
33 export const FileUploaderField = (props: WrappedFieldProps & { label?: string }) =>
35 <Typography variant='caption'>{props.label}</Typography>
36 <FileUploader disabled={props.meta.submitting} onDrop={props.input.onChange} />