From 4c649063ec0ce0e5f0822a47dcf84546ad1d1c5c Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Mon, 11 May 2020 21:27:48 -0700 Subject: error print --- frontend/src/components/NewPaste.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'frontend/src/components/NewPaste.js') diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index 2ad9533..29ae9ca 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -3,6 +3,21 @@ import { TitleInput, PasteInput } from './Inputs' import OptionsContainer from './Options' import axios from 'axios'; import { Redirect } from 'react-router-dom' +import styled from 'styled-components' + +const ErrMsg = styled.p` + display: inline-block; + font-weight: 700; + margin-left: 2em; + color: #ff3333 +` + +const Error = (props) => { + const msg = props.msg.toString().toLowerCase() + return ( + { msg } + ); +} class NewPaste extends React.Component { constructor(props) { @@ -13,12 +28,20 @@ class NewPaste extends React.Component { pass: '', expiry: '', hash: '', + error: '', }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } + newErr(msg) { + this.setState({ error: msg }) + setTimeout(() => { + this.setState({ error: '' }) + }, 3000); + } + renderRedirect = () => { if (this.state.hash !== '') { const redirUrl = `/${this.state.hash}` @@ -86,12 +109,10 @@ class NewPaste extends React.Component { data: bodyFormData, headers: { 'Content-Type': 'multipart/form-data' }, }).then((response) => { - // on success, redir this.setState({ hash: response.data.hash }) }).catch((response) => { - // TODO: handle error - console.log(response); + this.newErr(response) }); event.preventDefault(); @@ -112,6 +133,7 @@ class NewPaste extends React.Component { maxLength="100000" id="pasteInput" /> +