Skip to content

Commit

Permalink
Frontend and api's
Browse files Browse the repository at this point in the history
  • Loading branch information
caiquejjx committed Mar 27, 2020
1 parent 2c804d8 commit fe69f02
Show file tree
Hide file tree
Showing 30 changed files with 11,597 additions and 15 deletions.
Binary file added assets/heroes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions backend/src/controllers/IncidentController.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/OngController.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const connection = require("./database/connection");
const connection = require("../database/connection");
const crypto = require("crypto");

module.exports = {
async create(req, res) {
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,
Expand All @@ -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("*");
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/ProfileController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const connection = require("./database/connection");
const connection = require("../database/connection");

module.exports = {
async index(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/SessionController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const connection = require("./database/connection");
const connection = require("../database/connection");

module.exports = {
async login(req, res) {
Expand Down
Binary file modified backend/src/database/db.sqlite
Binary file not shown.
4 changes: 2 additions & 2 deletions backend/src/database/migrations/20200324201452_create_ongs.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -10,5 +10,5 @@ exports.up = function(knex) {
};

exports.down = function(knex) {
knex.schema.dropTable("ongs");
return knex.schema.dropTable("ongs");
};
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -15,5 +15,5 @@ exports.up = function(knex) {
};

exports.down = function(knex) {
knex.schema.dropTable("incidents");
return knex.schema.dropTable("incidents");
};
4 changes: 2 additions & 2 deletions backend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -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*
37 changes: 37 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Binary file added frontend/public/favicon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />

<title>Be The Hero</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
10 changes: 10 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";

import Routes from "./routes";
import "./global.css";

function App() {
return <Routes></Routes>;
}

export default App;
Binary file added frontend/src/assets/heroes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions frontend/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions frontend/src/global.css
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";

import App from "./App";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
54 changes: 54 additions & 0 deletions frontend/src/pages/Logon/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="logon-container">
<section className="form">
<img src={logoImg} alt="Be The Hero"></img>

<form onSubmit={handleLogin}>
<h1> Faça seu logon</h1>

<input
placeholder="Sua ID"
value={id}
onChange={e => setId(e.target.value)}
></input>

<button className="button" type="submit">
Entrar
</button>
<Link className="back-link" to="/register">
<FiLogIn size={16} color="#e02041"></FiLogIn>
Não tenho cadastro
</Link>
</form>
</section>

<img src={heroesImg} alt="Heroes"></img>
</div>
);
}
24 changes: 24 additions & 0 deletions frontend/src/pages/Logon/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit fe69f02

Please sign in to comment.