Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create UploadDropZone and ProjectImport compomnents
* render ProjectImport in Modal * add dropzone styles * fix gettext statements * add constants
- Loading branch information
Showing
9 changed files
with
134 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useDropzone } from 'react-dropzone' | ||
|
||
const UploadDropZone = ({ acceptedTypes, onImportFile }) => { | ||
const [errorMessage, setErrorMessage] = useState('') | ||
|
||
const { getRootProps, getInputProps } = useDropzone({ | ||
accept: acceptedTypes, | ||
onDropAccepted: acceptedFiles => { | ||
if (acceptedFiles.length > 0) { | ||
onImportFile(acceptedFiles[0]) | ||
setErrorMessage('') | ||
} | ||
}, | ||
onDropRejected: rejectedFiles => { | ||
console.log(rejectedFiles) | ||
setErrorMessage(interpolate(gettext('%s has unsupported file type'), [rejectedFiles[0].path])) | ||
} | ||
}) | ||
|
||
return ( | ||
<section className="dropzone-container"> | ||
<div {...getRootProps({className: 'dropzone'})}> | ||
<input {...getInputProps()} /> | ||
<p>{gettext('Drag and drop a file here or click to select a file')}</p> | ||
{errorMessage && <div className="alert alert-danger mt-2">{errorMessage}</div>} | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
UploadDropZone.propTypes = { | ||
acceptedTypes: PropTypes.arrayOf(PropTypes.string), | ||
onImportFile: PropTypes.func.isRequired, | ||
} | ||
|
||
export default UploadDropZone |
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
24 changes: 24 additions & 0 deletions
24
rdmo/projects/assets/js/components/helper/ProjectImport.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,24 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { UploadDropZone } from 'rdmo/core/assets/js/components' | ||
|
||
const ProjectImport = ({ allowedTypes, handleImport}) => { | ||
return ( | ||
<> | ||
<UploadDropZone | ||
acceptedTypes={allowedTypes} | ||
onImportFile={handleImport} /> | ||
<hr /> | ||
<h2>{gettext('Direct import')}</h2> | ||
to do: display links | ||
</> | ||
) | ||
} | ||
|
||
ProjectImport.propTypes = { | ||
allowedTypes: PropTypes.arrayOf(PropTypes.string), | ||
handleImport: PropTypes.func.isRequired, | ||
} | ||
|
||
export default ProjectImport |
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,3 +1,4 @@ | ||
export { default as PendingInvitations } from './PendingInvitations' | ||
export { default as ProjectFilters } from './ProjectFilters' | ||
export { default as ProjectImport } from './ProjectImport' | ||
export { default as Table } from './Table' |
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