2020-02-18 18:05:52 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2020-02-18 18:37:14 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-02-18 18:05:52 +01:00
|
|
|
import { Button } from '@buffetjs/core';
|
2020-02-19 05:48:11 +01:00
|
|
|
import createMatrix from '../../utils/createMatrix';
|
2020-02-18 18:37:14 +01:00
|
|
|
import getTrad from '../../utils/getTrad';
|
2020-02-20 09:52:29 +01:00
|
|
|
import ContainerFluid from '../ContainerFluid';
|
|
|
|
|
import ModalSection from '../ModalSection';
|
|
|
|
|
import Text from '../Text';
|
|
|
|
|
import ButtonWrapper from './ButtonWrapper';
|
|
|
|
|
import TextWrapper from './TextWrapper';
|
2020-02-19 13:40:36 +01:00
|
|
|
import RowItem from './RowItem';
|
2020-02-20 09:52:29 +01:00
|
|
|
import ListWrapper from './ListWrapper';
|
2020-02-18 18:05:52 +01:00
|
|
|
|
2020-02-19 09:14:11 +01:00
|
|
|
const UploadList = ({
|
|
|
|
|
filesToUpload,
|
|
|
|
|
onClickCancelUpload,
|
|
|
|
|
onGoToAddBrowseFiles,
|
|
|
|
|
}) => {
|
2020-02-19 05:48:11 +01:00
|
|
|
const matrix = createMatrix(filesToUpload);
|
2020-02-18 18:37:14 +01:00
|
|
|
const filesToUploadLength = filesToUpload.length;
|
|
|
|
|
const titleId = `modal.upload-list.sub-header-title.${
|
|
|
|
|
filesToUploadLength > 1 ? 'plural' : 'singular'
|
|
|
|
|
}`;
|
|
|
|
|
|
2020-02-18 18:05:52 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2020-02-20 09:52:29 +01:00
|
|
|
<ModalSection justifyContent="space-between">
|
|
|
|
|
<TextWrapper>
|
|
|
|
|
<Text fontSize="md" fontWeight="bold">
|
2020-02-18 18:37:14 +01:00
|
|
|
<FormattedMessage
|
|
|
|
|
id={getTrad(titleId)}
|
|
|
|
|
values={{ number: filesToUploadLength }}
|
|
|
|
|
/>
|
2020-02-20 09:52:29 +01:00
|
|
|
</Text>
|
|
|
|
|
|
|
|
|
|
<Text fontSize="sm" color="grey">
|
2020-02-18 18:37:14 +01:00
|
|
|
<FormattedMessage
|
|
|
|
|
id={getTrad('modal.upload-list.sub-header-subtitle')}
|
|
|
|
|
values={{ number: filesToUploadLength }}
|
|
|
|
|
/>
|
2020-02-20 09:52:29 +01:00
|
|
|
</Text>
|
|
|
|
|
</TextWrapper>
|
|
|
|
|
<ButtonWrapper>
|
2020-02-18 18:37:14 +01:00
|
|
|
<FormattedMessage id={getTrad('modal.upload-list.sub-header.button')}>
|
|
|
|
|
{label => (
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
color="primary"
|
|
|
|
|
label={label}
|
|
|
|
|
onClick={onGoToAddBrowseFiles}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</FormattedMessage>
|
2020-02-20 09:52:29 +01:00
|
|
|
</ButtonWrapper>
|
|
|
|
|
</ModalSection>
|
|
|
|
|
|
|
|
|
|
<ModalSection>
|
|
|
|
|
<ContainerFluid>
|
|
|
|
|
<ListWrapper>
|
|
|
|
|
{matrix.map(({ key, rowContent }) => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="row" key={key}>
|
|
|
|
|
{rowContent.map(data => (
|
|
|
|
|
<RowItem
|
|
|
|
|
{...data}
|
|
|
|
|
onClick={onClickCancelUpload}
|
|
|
|
|
key={data.originalIndex}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ListWrapper>
|
|
|
|
|
</ContainerFluid>
|
|
|
|
|
</ModalSection>
|
2020-02-18 18:05:52 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UploadList.defaultProps = {
|
|
|
|
|
filesToUpload: [],
|
2020-02-19 09:14:11 +01:00
|
|
|
onClickCancelUpload: () => {},
|
2020-02-18 18:37:14 +01:00
|
|
|
onGoToAddBrowseFiles: () => {},
|
2020-02-18 18:05:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UploadList.propTypes = {
|
|
|
|
|
filesToUpload: PropTypes.array,
|
2020-02-19 09:14:11 +01:00
|
|
|
onClickCancelUpload: PropTypes.func,
|
2020-02-18 18:37:14 +01:00
|
|
|
onGoToAddBrowseFiles: PropTypes.func,
|
2020-02-18 18:05:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default UploadList;
|