diff --git a/package.json b/package.json index b5c8796c..1f4bc3e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arbor-frontend", - "version": "1.6.4", + "version": "1.6.5", "private": true, "dependencies": { "@brainhubeu/react-carousel": "1.19.26", diff --git a/src/assets/SvgComponents/dropFile.svg b/src/assets/SvgComponents/dropFile.svg new file mode 100644 index 00000000..cadc010f --- /dev/null +++ b/src/assets/SvgComponents/dropFile.svg @@ -0,0 +1,3 @@ + diff --git a/src/components/Dialog.js b/src/components/Dialog.js index a71536e4..e3190ac1 100644 --- a/src/components/Dialog.js +++ b/src/components/Dialog.js @@ -15,7 +15,7 @@ const DialogContent = withStyles({ '&:first-child': { paddingTop: '80px' }, - maxWidth: '800px' + maxWidth: '900px' } })(MuiDialogContent); diff --git a/src/components/DropTextFile.js b/src/components/DropTextFile.js new file mode 100644 index 00000000..31c52a7e --- /dev/null +++ b/src/components/DropTextFile.js @@ -0,0 +1,156 @@ +import React, { createRef, useRef, useState } from 'react'; +import { useDropzone } from 'react-dropzone'; +import { Grid, TextField, Button, Typography } from '@material-ui/core'; +import dropFileIcon from '../assets/SvgComponents/dropFile.svg'; + +import { makeStyles } from '@material-ui/core/styles'; + +const useStyles = makeStyles({ + dropArea: { + display: 'flex', + alignItems: 'center', + justifyContent: 'stretch', + flexDirection: 'column', + background: '#FAFAFA', + border: '1px dashed #D9D9D9', + boxSizing: 'border-box', + borderRadius: '8px', + padding: '22px', + textAlign: 'center' + }, + isDrag: { + background: 'rgba(250,250,250,0.5)', + border: '1px dashed #949494' + }, + dropAreaTitle: { + fontWeight: 500, + fontSize: '14px', + lineHeight: '16px', + color: '#8F999F' + }, + dropBottomText: { + fontWeight: 500, + fontSize: '14px', + lineHeight: '16px', + color: '#3E9693' + }, + dropAreaIcon: { + width: '25px', + height: '25px', + margin: '20px', + backgroundImage: `url(${dropFileIcon})`, + backgroundPosition: 'center', + backgroundRepeat: 'no-repeat', + backgroundSize: 'contain' + }, + textTitle: { + fontWeight: 'bold', + fontSize: '16px', + lineHeight: '20px', + color: '#8F999F', + margin: '26px 0 12px 0' + } +}); + +const DropTextFile = props => { + const inputRef = useRef(); + const classes = useStyles(); + const { + label, + name, + value = '', + helperText, + error, + onChange = () => {}, + onBlur = () => {}, + onError = () => {} + } = props; + + const { getRootProps, getInputProps, isDragActive } = useDropzone({ + accept: 'application/json', + multiple: false, + onDrop: async acceptedFiles => { + try { + window['file_0'] = acceptedFiles[0]; + if (!acceptedFiles[0]) { + throw new Error('Unable to get the file'); + } + const file = acceptedFiles[0]; + const reader = new FileReader(); + reader.onload = () => { + console.log(reader.result); + const nativeTextareaSetter = Object + .getOwnPropertyDescriptor( + window.HTMLTextAreaElement.prototype, + 'value' + ).set; + nativeTextareaSetter.call(inputRef.current, reader.result); + const inputEvent = new Event('input', { bubbles: true}); + console.log({inputRef}); + inputRef.current.dispatchEvent(inputEvent); + }; + reader.onerror = () => { + onError(reader.error); + }; + reader.readAsText(file); + } catch (error) { + onError(error); + } + } + }); + + return ( +