-
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
7a085ac
commit 8b9073b
Showing
11 changed files
with
296 additions
and
185 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
67 changes: 56 additions & 11 deletions
67
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 |
---|---|---|
@@ -1,17 +1,62 @@ | ||
import { SelectSupplier } from '../../../common/components/SelectSupplier'; | ||
import { useSelector } from 'react-redux'; | ||
import { useState } from 'react'; | ||
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, []); | ||
const [selectedSupplier, setSelectedSupplier] = useState(); | ||
const suppliers = useSelector( | ||
state => state.SuppliersReducer.data, | ||
shallowEqual | ||
); | ||
|
||
return null; | ||
{ | ||
/* | ||
<SelectSupplier | ||
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> | ||
); | ||
}; |
Oops, something went wrong.