|
@@ -1,12 +1,14 @@
|
|
|
import React from 'react'
|
|
|
-import { Panel, FormGroup, ControlLabel, FormControl, HelpBlock } from 'react-bootstrap'
|
|
|
+import { FormGroup, ControlLabel, FormControl, HelpBlock } from 'react-bootstrap'
|
|
|
+import { fileSize, date2s, time2s } from '../../helpers'
|
|
|
|
|
|
-function FieldGroup ({ id, label, help, ...props }) {
|
|
|
+function FieldGroup ({ id, label, help, file, ...props }) {
|
|
|
return (
|
|
|
<FormGroup controlId={id}>
|
|
|
<ControlLabel>{label}</ControlLabel>
|
|
|
<FormControl {...props} />
|
|
|
{help && <HelpBlock>{help}</HelpBlock>}
|
|
|
+ {file && <div>{fileSize(file.size)} {date2s(file.lastModified)} {time2s(file.lastModified)}</div>}
|
|
|
</FormGroup>
|
|
|
)
|
|
|
}
|
|
@@ -17,28 +19,37 @@ class PlayerForm extends React.Component {
|
|
|
this.handleFileUpload = this.handleFileUpload.bind(this)
|
|
|
}
|
|
|
|
|
|
- handleFileUpload () {
|
|
|
- const file = this.playerListFile
|
|
|
+ handleFileUpload (event) {
|
|
|
+ event.preventDefault()
|
|
|
const { fileUploadStart } = this.props.actions
|
|
|
+ const { alertAdd } = this.props.alerts
|
|
|
+ const { files } = this.playerListFile
|
|
|
+ if (files.length === 0) {
|
|
|
+ alertAdd({ type: 'info', text: 'Datei entfernt' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (files.length > 1) {
|
|
|
+ alertAdd({ type: 'warning', text: 'Mehrere Dateien gesendet. Nur die erste wird verarbeitet.' })
|
|
|
+ }
|
|
|
+ const file = files[0]
|
|
|
fileUploadStart(file)
|
|
|
}
|
|
|
|
|
|
render () {
|
|
|
- const { fileUpload } = this.props.state
|
|
|
+ const { fileUpload, file } = this.props.state
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
- {fileUpload === 'failure'
|
|
|
- ? (<Panel header='Fehler'>Fehler beim laden.</Panel>)
|
|
|
- : ''}
|
|
|
<form>
|
|
|
<FieldGroup
|
|
|
id='playerListFile'
|
|
|
- type='file'
|
|
|
label='PlayerList.xls File'
|
|
|
help='Die Datei wird von der Swisstennis Turniersoftware generiert.'
|
|
|
- ref={input => { this.playerListFile = input }}
|
|
|
+ type='file'
|
|
|
+ file={file}
|
|
|
+ inputRef={input => { this.playerListFile = input }}
|
|
|
onChange={this.handleFileUpload}
|
|
|
+ disabled={(fileUpload === 'started')}
|
|
|
/>
|
|
|
</form>
|
|
|
</div>
|