From 3134ff3343ea0fc7ae25852459d2764717c3dfda Mon Sep 17 00:00:00 2001 From: "Gustavo S. de Paula" Date: Sun, 29 Mar 2020 12:43:51 -0300 Subject: [PATCH] Front end developed --- backend/src/controllers/ProfileController.js | 2 +- backend/src/database/db.sqlite | Bin 28672 -> 28672 bytes frontend/src/global.css | 4 +- frontend/src/pages/Logon/index.js | 33 ++++- frontend/src/pages/NewIncident/index.js | 58 ++++++++- frontend/src/pages/Profile/index.js | 120 +++++++++---------- frontend/src/pages/Register/index.js | 74 ++++++++++-- frontend/src/services/api.js | 7 ++ 8 files changed, 212 insertions(+), 86 deletions(-) create mode 100644 frontend/src/services/api.js diff --git a/backend/src/controllers/ProfileController.js b/backend/src/controllers/ProfileController.js index d95fc66..5c64f4b 100644 --- a/backend/src/controllers/ProfileController.js +++ b/backend/src/controllers/ProfileController.js @@ -4,7 +4,7 @@ module.exports = { async index (req, res) { const ong_id = req.headers.authorization - + console.log(ong_id) const incidents = await connection('incidents') .where('ong_id', ong_id) .select('*') diff --git a/backend/src/database/db.sqlite b/backend/src/database/db.sqlite index 930031aa517062fc4d035440201c62396e280f8a..beab6d50f7c8506a53b608b42a02993135c5588f 100644 GIT binary patch delta 650 zcmZp8z}WDBae_3X+e8^>Mz@U#h5C#Nn=k1b3GlG+{bAtW#b3MCkksOmREH7}sh6CeYhr3 zoS3f=kXV|N9~@xF%qc6bEh!2#!`#r^GS$SwI3*)7B^|64WI$?(UVd_}iHVtsxk*M^ zMp|)!D-%$Qv96*3P>-pRd5VRhaU$5h$rt_gC-3t2;$h)G%fSDf{}%rj{a;6z2rzE9Vr1A2`GBEKvG4ML^-{y595vud@@OKml~O@^&Y>tm`6>&E8-|3$I7;H+f;S*RB`k!&4L2rdNf}wV0Y1{L z;RbMYz?DH3N5YOI{_ W0%E`!5CtN@DPRI&zyMBw&=LP%uvn!4 diff --git a/frontend/src/global.css b/frontend/src/global.css index 9476253..692ec42 100644 --- a/frontend/src/global.css +++ b/frontend/src/global.css @@ -21,7 +21,7 @@ input, button, textarea { form input { width: 100%; height: 60px; - color: #3333; + color: rgba(146, 138, 138); border: 1px solid #ececd6; border-radius: 8px; padding: 0 24px @@ -30,7 +30,7 @@ form textarea { width: 100%; min-height: 140px; height: 60px; - color: #3333; + color: rgba(146, 138, 138); border: 1px solid #ececd6; border-radius: 8px; padding: 16px 24px; diff --git a/frontend/src/pages/Logon/index.js b/frontend/src/pages/Logon/index.js index c85b1bc..b6a53c7 100644 --- a/frontend/src/pages/Logon/index.js +++ b/frontend/src/pages/Logon/index.js @@ -1,20 +1,45 @@ -import React from 'react'; +import React, {useState} from 'react'; import {FiLogIn} from 'react-icons/fi'; -import { Link } from 'react-router-dom' +import { Link, useHistory } from 'react-router-dom' import './styles.css'; +import api from '../../services/api' + import heroesImg from '../../assets/heroes.png' import logoImg from '../../assets/logo.svg' export default function Logon(){ + + const [id, set_id] = useState(''); + const history = useHistory() + + async function handleLogin (e) { + e.preventDefault(); + + try { + const response = await api.post('/session',{id}) + + localStorage.setItem('ongId', id); + localStorage.setItem('ongName', response.data.name); + history.push('/profile') + + } catch (error) { + alert(`Erro ao realizar login. ${error}`) + } + } return(
Be The Hero -
+

Faça seu login

- + set_id(e.target.value)} + + > diff --git a/frontend/src/pages/NewIncident/index.js b/frontend/src/pages/NewIncident/index.js index 946a02d..6f0539d 100644 --- a/frontend/src/pages/NewIncident/index.js +++ b/frontend/src/pages/NewIncident/index.js @@ -1,13 +1,47 @@ -import React from 'react'; +import React, {useState} from 'react'; import {FiArrowLeft} from 'react-icons/fi'; -import { Link } from 'react-router-dom' +import { Link, useHistory } from 'react-router-dom' import './styles.css'; import heroesImg from '../../assets/heroes.png' import logoImg from '../../assets/logo.svg' +import api from '../../services/api' + export default function NewIncident(){ + + const history = useHistory(); + + const ongId = localStorage.getItem('ongId'); + + const [title, set_title] = useState('') + const [description, set_description] = useState('') + const [value, set_value] = useState('') + + async function handleNewincident (e) { + e.preventDefault(); + + const data = { + title, + description, + value + } + + try { + await api.post('/incidents', data, { + headers: { + Authorization: ongId + } + } ) + history.push('/profile') + } catch (error) { + alert(`Erro ao cadastrar novo caso. ${error}`) + } + + + } + return(
@@ -21,10 +55,22 @@ export default function NewIncident(){
- - -