-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcd05c8
commit 663fb9b
Showing
11 changed files
with
319 additions
and
154 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import Dropzone from 'react-dropzone'; | ||
import Button from 'muicss/lib/react/button'; | ||
import { Line as Progress } from 'rc-progress'; | ||
|
||
export const FileUpload = ({ fileUploadProgress, handleFileUpload }) => { | ||
const [files, setFiles] = useState([]); | ||
const [showSuccess, setShowSuccess] = useState(false); | ||
const [uploadProgress, setUploadProgress] = useState(0); | ||
|
||
useEffect(() => { | ||
if (fileUploadProgress === 100) { | ||
setFiles([]); | ||
setShowSuccess(true); | ||
} | ||
}, [fileUploadProgress]); | ||
|
||
useEffect(() => { | ||
let showSuccessTimer = setTimeout(() => resetProgress(), 3000); | ||
return () => { | ||
clearTimeout(showSuccessTimer); | ||
}; | ||
}, [showSuccess]); | ||
|
||
useEffect(() => { | ||
if (!showSuccess) { | ||
setUploadProgress(fileUploadProgress); | ||
} | ||
}, [fileUploadProgress]); | ||
|
||
const resetProgress = () => { | ||
setShowSuccess(false); | ||
setUploadProgress(0); | ||
}; | ||
|
||
const handleOnDrop = files => { | ||
if (files.length) { | ||
setFiles(files); | ||
} | ||
}; | ||
|
||
const dropStyle = { | ||
height: '150px', | ||
borderWidth: 1, | ||
borderColor: '#666', | ||
borderStyle: 'dashed', | ||
borderRadius: 2, | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
cursor: 'pointer' | ||
}; | ||
|
||
const filesStyle = { | ||
marginTop: '5%', | ||
minHeight: '300px', | ||
maxHeight: '300px' | ||
}; | ||
|
||
const uploadButtonStyle = { | ||
width: 100, | ||
fontSize: '0.8em', | ||
textAlign: 'center', | ||
marginLeft: 'auto', | ||
marginTop: 10 | ||
}; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column' | ||
}} | ||
> | ||
<Dropzone | ||
style={dropStyle} | ||
accept="application/zip, | ||
application/octet-stream, | ||
application/x-zip, | ||
application/x-rar, | ||
application/x-zip-compressed, | ||
application/x-rar-compressed, | ||
compressed/rar, | ||
application/rar, | ||
application/xml, | ||
text/xml" | ||
onDrop={(files, rejected) => { | ||
handleOnDrop(files); | ||
console.warn('rejected', rejected); | ||
}} | ||
> | ||
<div style={{ textAlign: 'center' }}> | ||
Try dropping some files here, or click to select files to upload. | ||
</div> | ||
</Dropzone> | ||
{files.length ? ( | ||
<select style={filesStyle} multiple> | ||
{files.map((file, index) => { | ||
return <option key={'file-' + index}>{file.name}</option>; | ||
})} | ||
</select> | ||
) : ( | ||
<div style={{ marginTop: '5%' }}>No files added</div> | ||
)} | ||
<Progress strokeColor="#8dcc91" percent={uploadProgress} /> | ||
<Button | ||
disabled={!files.length} | ||
style={uploadButtonStyle} | ||
color="primary" | ||
onClick={() => files.length && handleFileUpload(files)} | ||
> | ||
Upload | ||
</Button> | ||
{showSuccess && ( | ||
<div style={{ color: 'green' }}>Files successfully uploaded</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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,49 @@ | ||
import SelectField from 'material-ui/SelectField'; | ||
import MenuItem from 'material-ui/MenuItem'; | ||
import React from 'react'; | ||
|
||
export const SelectSupplier = ({ | ||
suppliers, | ||
selectSupplier, | ||
selectedSupplierId, | ||
errorText | ||
}) => { | ||
return ( | ||
<> | ||
<SelectField | ||
id="select-supplier" | ||
floatingLabelFixed={true} | ||
style={{ minWidth: 350 }} | ||
floatingLabelText={'Provider'} | ||
onChange={(e, k, v) => selectSupplier(v)} | ||
autoWidth={true} | ||
value={Number(selectedSupplierId) || -1} | ||
iconStyle={{ fill: 'rgba(22, 82, 149, 0.69)' }} | ||
> | ||
{suppliers.map(supplier => { | ||
const isLevel1Provider = | ||
(supplier.chouetteInfo && | ||
supplier.chouetteInfo.migrateDataToProvider) || | ||
supplier.id === -1; | ||
return ( | ||
<MenuItem | ||
key={supplier.id} | ||
value={supplier.id} | ||
label={supplier.name} | ||
primaryText={ | ||
<span | ||
style={{ | ||
color: isLevel1Provider ? 'intial' : '#d9a51b' | ||
}} | ||
> | ||
{supplier.name} | ||
</span> | ||
} | ||
/> | ||
); | ||
})} | ||
</SelectField> | ||
{errorText && <div style={{ color: 'red' }}>{errorText}</div>} | ||
</> | ||
); | ||
}; |
62 changes: 62 additions & 0 deletions
62
src/screens/geocoder/components/tariffZonesImport/TariffZonesImport.js
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,62 @@ | ||
import { SelectSupplier } from '../../../common/components/SelectSupplier'; | ||
import { useSelector, shallowEqual, useDispatch } from 'react-redux'; | ||
import React, { useState } from 'react'; | ||
import { FileUpload } from '../../../common/components/FileUpload'; | ||
import SuppliersActions from '../../../../actions/SuppliersActions'; | ||
|
||
export const TariffZonesImport = () => { | ||
const suppliers = useSelector( | ||
state => state.SuppliersReducer.data, | ||
shallowEqual | ||
); | ||
|
||
const tariffZoneFileUploadProgress = useSelector( | ||
state => state.SuppliersReducer.tariffZoneFileUploadProgress, | ||
shallowEqual | ||
); | ||
|
||
const [selectedSupplier, setSelectedSupplier] = useState(null); | ||
const [noSupplierSelected, setNoSupplierSelected] = useState(null); | ||
const dispatch = useDispatch(); | ||
|
||
const handleFileUpload = files => { | ||
if (selectedSupplier === null) { | ||
setNoSupplierSelected(true); | ||
} else { | ||
dispatch( | ||
SuppliersActions.uploadTariffZonesFiles(files, selectedSupplier) | ||
); | ||
} | ||
}; | ||
|
||
const onSelectSupplier = selectedSupplierId => { | ||
setNoSupplierSelected(false); | ||
setSelectedSupplier( | ||
suppliers.find(supplier => supplier.id === selectedSupplierId) | ||
); | ||
}; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
backgroundColor: '#fff', | ||
padding: '20px', | ||
display: 'flex', | ||
flexDirection: 'column' | ||
}} | ||
> | ||
<SelectSupplier | ||
suppliers={suppliers} | ||
selectSupplier={onSelectSupplier} | ||
selectedSupplierId={selectedSupplier && selectedSupplier.id} | ||
errorText={noSupplierSelected === true && 'No Supplier selected'} | ||
/> | ||
<div style={{ width: '50%', marginTop: '20px' }}> | ||
<FileUpload | ||
fileUploadProgress={tariffZoneFileUploadProgress} | ||
handleFileUpload={handleFileUpload} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.