diff --git a/assets/heroes.png b/assets/heroes.png new file mode 100644 index 0000000..c3e7f47 Binary files /dev/null and b/assets/heroes.png differ diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 0000000..a586316 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/backend/src/controllers/IncidentController.js b/backend/src/controllers/IncidentController.js index 5504f70..0606791 100644 --- a/backend/src/controllers/IncidentController.js +++ b/backend/src/controllers/IncidentController.js @@ -1,9 +1,9 @@ -const connection = require("./database/connection"); +const connection = require("../database/connection"); module.exports = { async create(req, res) { - const { title, description, value } = req.body; - const ong_id = request.headers.authorization; + const { title, description, value } = await req.body; + const ong_id = await req.headers.authorization; const [id] = await connection("incidents").insert({ title, diff --git a/backend/src/controllers/OngController.js b/backend/src/controllers/OngController.js index 841b7ee..89d2326 100644 --- a/backend/src/controllers/OngController.js +++ b/backend/src/controllers/OngController.js @@ -1,4 +1,4 @@ -const connection = require("./database/connection"); +const connection = require("../database/connection"); const crypto = require("crypto"); module.exports = { @@ -6,7 +6,7 @@ module.exports = { const { name, email, whatsapp, city, uf } = req.body; const id = crypto.randomBytes(4).toString("HEX"); - connection("ongs").insert({ + await connection("ongs").insert({ id, name, email, @@ -15,7 +15,7 @@ module.exports = { uf }); - return res.json(id); + return res.json({ id }); }, async index(req, res) { const ongs = await connection("ongs").select("*"); diff --git a/backend/src/controllers/ProfileController.js b/backend/src/controllers/ProfileController.js index d5778aa..2f91773 100644 --- a/backend/src/controllers/ProfileController.js +++ b/backend/src/controllers/ProfileController.js @@ -1,4 +1,4 @@ -const connection = require("./database/connection"); +const connection = require("../database/connection"); module.exports = { async index(req, res) { diff --git a/backend/src/controllers/SessionController.js b/backend/src/controllers/SessionController.js index 1e5d01a..0a54d1d 100644 --- a/backend/src/controllers/SessionController.js +++ b/backend/src/controllers/SessionController.js @@ -1,4 +1,4 @@ -const connection = require("./database/connection"); +const connection = require("../database/connection"); module.exports = { async login(req, res) { diff --git a/backend/src/database/db.sqlite b/backend/src/database/db.sqlite index ca2c427..6c541b0 100644 Binary files a/backend/src/database/db.sqlite and b/backend/src/database/db.sqlite differ diff --git a/backend/src/database/migrations/20200324201452_create_ongs.js b/backend/src/database/migrations/20200324201452_create_ongs.js index 19bde32..995ded6 100644 --- a/backend/src/database/migrations/20200324201452_create_ongs.js +++ b/backend/src/database/migrations/20200324201452_create_ongs.js @@ -1,5 +1,5 @@ exports.up = function(knex) { - knex.schema.createTable("ongs", function(table) { + return knex.schema.createTable("ongs", function(table) { table.string("id").primary(); table.string("name").notNullable(); table.string("email").notNullable(); @@ -10,5 +10,5 @@ exports.up = function(knex) { }; exports.down = function(knex) { - knex.schema.dropTable("ongs"); + return knex.schema.dropTable("ongs"); }; diff --git a/backend/src/database/migrations/20200324201936_create_incidents.js b/backend/src/database/migrations/20200324201936_create_incidents.js index 8d6f37b..ddc1cd6 100644 --- a/backend/src/database/migrations/20200324201936_create_incidents.js +++ b/backend/src/database/migrations/20200324201936_create_incidents.js @@ -1,6 +1,6 @@ exports.up = function(knex) { - knex.schema.createTable("incidents", function(table) { - table.incremetns(); + return knex.schema.createTable("incidents", function(table) { + table.increments(); table.string("title").notNullable(); table.string("description").notNullable(); table.decimal("value").notNullable(); @@ -15,5 +15,5 @@ exports.up = function(knex) { }; exports.down = function(knex) { - knex.schema.dropTable("incidents"); + return knex.schema.dropTable("incidents"); }; diff --git a/backend/src/routes.js b/backend/src/routes.js index e65908e..5c680e8 100644 --- a/backend/src/routes.js +++ b/backend/src/routes.js @@ -11,11 +11,11 @@ const routes = express.Router(); routes.get("/ongs", OngController.index); routes.post("/ongs", OngController.create); -routes.post("/incidents", IncidentsController.create); +routes.post("/incidents", IncidentController.create); routes.get("incidents", IncidentController.index); routes.delete("/incidents/:id", IncidentController.delete); -routes.get("profile", ProfileController.index); +routes.get("/profile", ProfileController.index); routes.post("/sessions", SessionController.login); module.exports = routes; diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..8f5eb2c --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,37 @@ +{ + "name": "frontend", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^4.2.4", + "@testing-library/react": "^9.3.2", + "@testing-library/user-event": "^7.1.2", + "axios": "^0.19.2", + "react": "^16.13.1", + "react-dom": "^16.13.1", + "react-icons": "^3.9.0", + "react-router-dom": "^5.1.2", + "react-scripts": "3.4.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico new file mode 100644 index 0000000..bcd5dfd Binary files /dev/null and b/frontend/public/favicon.ico differ diff --git a/frontend/public/index.html b/frontend/public/index.html new file mode 100644 index 0000000..21aa814 --- /dev/null +++ b/frontend/public/index.html @@ -0,0 +1,15 @@ + + + + + + + + + Be The Hero + + + +
+ + diff --git a/frontend/src/App.js b/frontend/src/App.js new file mode 100644 index 0000000..67d8cdf --- /dev/null +++ b/frontend/src/App.js @@ -0,0 +1,10 @@ +import React from "react"; + +import Routes from "./routes"; +import "./global.css"; + +function App() { + return ; +} + +export default App; diff --git a/frontend/src/assets/heroes.png b/frontend/src/assets/heroes.png new file mode 100644 index 0000000..c3e7f47 Binary files /dev/null and b/frontend/src/assets/heroes.png differ diff --git a/frontend/src/assets/logo.svg b/frontend/src/assets/logo.svg new file mode 100644 index 0000000..a586316 --- /dev/null +++ b/frontend/src/assets/logo.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/frontend/src/global.css b/frontend/src/global.css new file mode 100644 index 0000000..2e48674 --- /dev/null +++ b/frontend/src/global.css @@ -0,0 +1,83 @@ +@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap"); + +* { + margin: 0; + padding: 0; + outline: 0; + box-sizing: border-box; +} + +body { + font: 400 14px Roboto, sans-serif; + background: #f0f0f5; + -webkit-font-smoothing: antialised; +} + +input, +button, +textarea { + font: 400 18px Roboto, sans-serif; +} + +button { + cursor: pointer; +} + +form input { + width: 100%; + height: 60px; + color: #333; + border: 1px solid #dcdce6; + border-radius: 4px; + padding: 0 24px; +} + +form textarea { + width: 100%; + min-height: 140px; + height: 60px; + color: #333; + border: 1px solid #dcdce6; + border-radius: 4px; + padding: 16px 24px; + line-height: 24px; +} + +.button { + width: 100%; + height: 60px; + background: #e02041; + border: 0; + border-radius: 8px; + color: #fff; + font-weight: 700; + margin-top: 16px; + display: inline-block; + text-align: center; + text-decoration: none; + font-size: 18px; + line-height: 60px; + transition: filter 0.2s; +} + +.button:hover { + filter: brightness(90%); +} + +.back-link { + display: flex; + align-items: center; + margin-top: 40px; + color: #41414d; + font-size: 18px; + text-decoration: none; + font-weight: 500; + transition: opacity 0.2s; +} + +.back-link svg { + margin-right: 8px; +} +.back-link:hover { + opacity: 0.8; +} diff --git a/frontend/src/index.js b/frontend/src/index.js new file mode 100644 index 0000000..8db55ca --- /dev/null +++ b/frontend/src/index.js @@ -0,0 +1,11 @@ +import React from "react"; +import ReactDOM from "react-dom"; + +import App from "./App"; + +ReactDOM.render( + + + , + document.getElementById("root") +); diff --git a/frontend/src/pages/Logon/index.js b/frontend/src/pages/Logon/index.js new file mode 100644 index 0000000..244bafb --- /dev/null +++ b/frontend/src/pages/Logon/index.js @@ -0,0 +1,54 @@ +import React, { useState } from "react"; +import { Link, useHistory } from "react-router-dom"; + +import { FiLogIn } from "react-icons/fi"; +import api from "../../services/api"; +import "./styles.css"; + +import logoImg from "../../assets/logo.svg"; +import heroesImg from "../../assets/heroes.png"; + +export default function Logon() { + const [id, setId] = useState(""); + const history = useHistory(); + + async function handleLogin(e) { + e.preventDefault(); + + try { + const response = await api.post("sessions", { id }); + localStorage.setItem("ongId", id); + localStorage.setItem("ongName", response.data.name); + history.push("/profile"); + } catch (err) { + alert("Falha no login, tente novamente"); + } + } + return ( +
+
+ Be The Hero + +
+

Faça seu logon

+ + setId(e.target.value)} + > + + + + + Não tenho cadastro + +
+
+ + Heroes +
+ ); +} diff --git a/frontend/src/pages/Logon/styles.css b/frontend/src/pages/Logon/styles.css new file mode 100644 index 0000000..52fe483 --- /dev/null +++ b/frontend/src/pages/Logon/styles.css @@ -0,0 +1,24 @@ +.logon-container { + width: 100%; + max-width: 1120px; + height: 100vh; + margin: 0 auto; + + display: flex; + align-items: center; + justify-content: space-between; +} + +.logon-container section.form { + width: 100%; + max-width: 350px; + margin-right: 30px; +} + +.logon-container section.form form { + margin-top: 100px; +} +.logon-container section.form form h1 { + font-size: 32px; + margin-bottom: 32px; +} diff --git a/frontend/src/pages/NewIncident/index.js b/frontend/src/pages/NewIncident/index.js new file mode 100644 index 0000000..8e5d9f0 --- /dev/null +++ b/frontend/src/pages/NewIncident/index.js @@ -0,0 +1,73 @@ +import React, { useState } from "react"; +import logoImg from "../../assets/logo.svg"; +import { Link, useHistory } from "react-router-dom"; +import { FiArrowLeft } from "react-icons/fi"; +import "./styles.css"; +import api from "../../services/api"; +export default function NewIncident() { + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [value, setValue] = useState(" "); + const history = useHistory(); + const ongId = localStorage.getItem("ongId"); + async function handleNewIncident(e) { + e.preventDefault(); + + const data = { + title, + description, + value + }; + + try { + await api.post("incidents", data, { + headers: { + Authorization: ongId + } + }); + history.push("/profile"); + } catch (err) { + alert("erro ao cadastrar"); + } + } + + return ( +
+
+
+ Be The Hero +

Cadastrar novo caso

+

+ Descreva o caso detalhadamente para encontrar um herói para resolver + isso. +

+ + + Voltar para home + +
+
+ setTitle(e.target.value)} + placeholder="Titulo do caso" + /> +