├── backend ├── .gitignore ├── src │ ├── server.js │ ├── database │ │ ├── db.sqlite │ │ ├── test.sqlite │ │ ├── connection.js │ │ └── migrations │ │ │ ├── 20200325171231_create_ongs.js │ │ │ └── 20200325171726_create_incidentes.js │ ├── utils │ │ └── generateUniqueId.js │ ├── app.js │ ├── controllers │ │ ├── ProfileController.js │ │ ├── SessionController.js │ │ ├── OngController.js │ │ ├── middlewares │ │ │ └── validations.js │ │ └── IncidentController.js │ └── routes.js ├── tests │ └── unit │ │ ├── generateUnitId.spec.js │ │ └── integration │ │ ├── ong.spec.js │ │ └── session.spec.js ├── package.json ├── knexfile.js └── jest.config.js ├── Procfile ├── frontend ├── .env ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── assets │ │ ├── heroes.png │ │ └── logo.svg │ ├── services │ │ └── api.js │ ├── App.js │ ├── index.js │ ├── pages │ │ ├── Logon │ │ │ ├── styles.css │ │ │ └── index.js │ │ ├── NewIncident │ │ │ ├── styles.css │ │ │ └── index.js │ │ ├── Register │ │ │ ├── styles.css │ │ │ └── index.js │ │ └── Profile │ │ │ ├── styles.css │ │ │ └── index.js │ ├── routes.js │ └── global.css ├── .gitignore └── package.json ├── .github ├── Mobile.gif ├── Desktop.gif ├── preview.jpg ├── week-11.png └── logo.svg ├── mobile ├── assets │ ├── icon.png │ └── splash.png ├── src │ ├── assets │ │ ├── logo.png │ │ ├── logo@2x.png │ │ └── logo@3x.png │ ├── services │ │ └── api.js │ ├── routes.js │ └── pages │ │ ├── incidents │ │ ├── styles.js │ │ └── index.js │ │ └── Detail │ │ ├── styles.js │ │ └── index.js ├── babel.config.js ├── .expo-shared │ └── assets.json ├── .gitignore ├── App.js ├── app.json └── package.json ├── package.json ├── LICENSE.md ├── README.md └── Insomnia_2020-03-24.json /backend/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: npm install && npm start -------------------------------------------------------------------------------- /frontend/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true -------------------------------------------------------------------------------- /.github/Mobile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/.github/Mobile.gif -------------------------------------------------------------------------------- /.github/Desktop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/.github/Desktop.gif -------------------------------------------------------------------------------- /.github/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/.github/preview.jpg -------------------------------------------------------------------------------- /.github/week-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/.github/week-11.png -------------------------------------------------------------------------------- /backend/src/server.js: -------------------------------------------------------------------------------- 1 | const app = require("./app"); 2 | 3 | app.listen(process.env.PORT || 3000); 4 | -------------------------------------------------------------------------------- /mobile/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/mobile/assets/icon.png -------------------------------------------------------------------------------- /mobile/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/mobile/assets/splash.png -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/frontend/public/favicon.ico -------------------------------------------------------------------------------- /mobile/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/mobile/src/assets/logo.png -------------------------------------------------------------------------------- /backend/src/database/db.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/backend/src/database/db.sqlite -------------------------------------------------------------------------------- /frontend/src/assets/heroes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/frontend/src/assets/heroes.png -------------------------------------------------------------------------------- /mobile/src/assets/logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/mobile/src/assets/logo@2x.png -------------------------------------------------------------------------------- /mobile/src/assets/logo@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/mobile/src/assets/logo@3x.png -------------------------------------------------------------------------------- /backend/src/database/test.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tgmarinho/be-the-hero/HEAD/backend/src/database/test.sqlite -------------------------------------------------------------------------------- /mobile/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | api.cache(true); 3 | return { 4 | presets: ['babel-preset-expo'], 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /mobile/src/services/api.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const api = axios.create({ 4 | baseURL: "https://be-the-super-hero.herokuapp.com" 5 | }); 6 | 7 | export default api; 8 | -------------------------------------------------------------------------------- /backend/src/utils/generateUniqueId.js: -------------------------------------------------------------------------------- 1 | const crypto = require("crypto"); 2 | 3 | module.exports = function generateUniqueId() { 4 | return crypto.randomBytes(4).toString("HEX"); 5 | }; 6 | -------------------------------------------------------------------------------- /frontend/src/services/api.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const api = axios.create({ 4 | baseURL: "https://be-the-super-hero.herokuapp.com" 5 | }); 6 | 7 | export default api; 8 | -------------------------------------------------------------------------------- /mobile/.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "f9155ac790fd02fadcdeca367b02581c04a353aa6d5aa84409a59f6804c87acd": true, 3 | "89ed26367cdb9b771858e026f2eb95bfdb90e5ae943e716575327ec325f39c44": true 4 | } -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./global.css"; 3 | import Routes from "./routes"; 4 | 5 | function App() { 6 | return ; 7 | } 8 | 9 | export default App; 10 | -------------------------------------------------------------------------------- /mobile/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/**/* 2 | .expo/* 3 | npm-debug.* 4 | *.jks 5 | *.p8 6 | *.p12 7 | *.key 8 | *.mobileprovision 9 | *.orig.* 10 | web-build/ 11 | web-report/ 12 | 13 | # macOS 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /mobile/App.js: -------------------------------------------------------------------------------- 1 | import "intl"; 2 | import "intl/locale-data/jsonp/pt-BR"; 3 | 4 | import React from "react"; 5 | import Routes from "./src/routes"; 6 | 7 | export default function App() { 8 | return ; 9 | } 10 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ); 11 | -------------------------------------------------------------------------------- /backend/tests/unit/generateUnitId.spec.js: -------------------------------------------------------------------------------- 1 | const generateUniqueId = require("../../src/utils/generateUniqueId"); 2 | 3 | describe("Generate Unique ID", () => { 4 | it("should generate an unique ID", () => { 5 | const id = generateUniqueId(); 6 | expect(id).toHaveLength(8); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /backend/src/database/connection.js: -------------------------------------------------------------------------------- 1 | const knex = require("knex"); 2 | const configuration = require("../../knexfile"); 3 | 4 | const connection = 5 | process.env.NODE_ENV === "test" 6 | ? knex(configuration.test) 7 | : knex(configuration.development); 8 | 9 | module.exports = connection; 10 | -------------------------------------------------------------------------------- /backend/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const cors = require("cors"); 3 | const routes = require("./routes"); 4 | const { errors } = require("celebrate"); 5 | 6 | const app = express(); 7 | 8 | app.use(cors()); 9 | app.use(express.json()); 10 | app.use(routes); 11 | app.use(errors()); 12 | 13 | module.exports = app; 14 | -------------------------------------------------------------------------------- /backend/src/controllers/ProfileController.js: -------------------------------------------------------------------------------- 1 | const connection = require("../database/connection"); 2 | 3 | module.exports = { 4 | async index(request, response) { 5 | const ong_id = request.headers.authorization; 6 | console.log(ong_id); 7 | 8 | const incidents = await connection("incidents") 9 | .where("ong_id", ong_id) 10 | .select("*"); 11 | 12 | return response.json(incidents); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /backend/src/controllers/SessionController.js: -------------------------------------------------------------------------------- 1 | const connection = require("../database/connection"); 2 | 3 | module.exports = { 4 | async create(request, response) { 5 | const { id } = request.body; 6 | 7 | const ong = await connection("ongs") 8 | .where("id", id) 9 | .select("name") 10 | .first(); 11 | 12 | if (!ong) { 13 | return response.status(400).json({ error: "No Ong found with this ID" }); 14 | } 15 | 16 | return response.json(ong); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Be The Hero 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /backend/src/database/migrations/20200325171231_create_ongs.js: -------------------------------------------------------------------------------- 1 | exports.up = function(knex) { 2 | return knex.schema.createTable("ongs", function(table) { 3 | table.string("id").primary(); 4 | table.string("name").notNullable(); 5 | table.string("email").notNullable(); 6 | table.string("whatsapp").notNullable(); 7 | table.string("city").notNullable(); 8 | table.string("uf", 2).notNullable(); 9 | }); 10 | }; 11 | 12 | exports.down = function(knex) { 13 | return knex.schema.dropTable("ongs"); 14 | }; 15 | -------------------------------------------------------------------------------- /frontend/src/pages/Logon/styles.css: -------------------------------------------------------------------------------- 1 | .logon-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | 7 | display: flex; 8 | align-items: center; 9 | justify-content: space-between; 10 | } 11 | 12 | .logon-container section.form { 13 | width: 100%; 14 | max-width: 350px; 15 | margin-right: 30px; 16 | } 17 | 18 | .logon-container section.form form { 19 | margin-top: 100px; 20 | } 21 | 22 | .logon-container section.form form h1 { 23 | font-size: 32px; 24 | margin-bottom: 32px; 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bethehero", 3 | "version": "1.0.0", 4 | "description": "

\"BeTheHero\"

", 5 | "scripts": { 6 | "start": "cd backend && npm install && npm run prod" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/tgmarinho/be-the-hero.git" 11 | }, 12 | "private": true, 13 | "bugs": { 14 | "url": "https://github.com/tgmarinho/be-the-hero/issues" 15 | }, 16 | "homepage": "https://github.com/tgmarinho/be-the-hero#readme" 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/controllers/OngController.js: -------------------------------------------------------------------------------- 1 | const connection = require("../database/connection"); 2 | const generateUniqueId = require("../utils/generateUniqueId"); 3 | 4 | module.exports = { 5 | async create(request, response) { 6 | const { name, email, whatsapp, city, uf } = request.body; 7 | 8 | const id = generateUniqueId(); 9 | 10 | await connection("ongs").insert({ id, name, email, whatsapp, city, uf }); 11 | 12 | return response.json({ id }); 13 | }, 14 | 15 | async index(_, response) { 16 | const ongs = await connection("ongs").select("*"); 17 | 18 | return response.json(ongs); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /backend/src/database/migrations/20200325171726_create_incidentes.js: -------------------------------------------------------------------------------- 1 | exports.up = function(knex) { 2 | return knex.schema.createTable("incidents", function(table) { 3 | table.increments(); 4 | 5 | table.string("title").notNullable(); 6 | table.string("description").notNullable(); 7 | table.decimal("value").notNullable(); 8 | 9 | table.string("ong_id").notNullable(); 10 | 11 | table 12 | .foreign("ong_id") 13 | .references("id") 14 | .inTable("ongs"); 15 | }); 16 | }; 17 | 18 | exports.down = function(knex) { 19 | return knex.schema.dropTable("incidents"); 20 | }; 21 | 22 | // https://youtu.be/GfnWvNSWMZE?t=3010 23 | -------------------------------------------------------------------------------- /mobile/src/routes.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { NavigationContainer } from "@react-navigation/native"; 3 | import { createStackNavigator } from "@react-navigation/stack"; 4 | 5 | import Incidents from "./pages/incidents"; 6 | import Detail from "./pages/Detail"; 7 | 8 | const AppStack = createStackNavigator(); 9 | 10 | export default function Routes() { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /frontend/src/routes.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { BrowserRouter, Route, Switch } from "react-router-dom"; 3 | 4 | import Logon from "./pages/Logon"; 5 | import Register from "./pages/Register"; 6 | import Profile from "./pages/Profile"; 7 | import NewIncident from "./pages/NewIncident"; 8 | 9 | export default function Routes() { 10 | return ( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "cross-env NODE_ENV=test jest", 8 | "start": "nodemon src/server.js", 9 | "prod": "node src/server.js" 10 | }, 11 | "keywords": [ 12 | "node" 13 | ], 14 | "author": "Thiago Marinho ", 15 | "license": "MIT", 16 | "dependencies": { 17 | "celebrate": "^12.0.1", 18 | "cors": "^2.8.5", 19 | "cross-env": "^7.0.2", 20 | "express": "^4.17.1", 21 | "jest": "^25.2.3", 22 | "knex": "^0.20.13", 23 | "sqlite3": "^4.1.1" 24 | }, 25 | "devDependencies": { 26 | "nodemon": "^2.0.2", 27 | "supertest": "^4.0.2" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mobile/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "name": "Be The Hero", 4 | "slug": "BeTheHero", 5 | "description": "Be The Hero, you can create ONGS and help what is important to you, saving the day solvind incidents!", 6 | "privacy": "public", 7 | "sdkVersion": "36.0.0", 8 | "platforms": ["ios", "android", "web"], 9 | "version": "1.0.0", 10 | "orientation": "portrait", 11 | "icon": "./assets/icon.png", 12 | "splash": { 13 | "image": "./assets/splash.png", 14 | "resizeMode": "contain", 15 | "backgroundColor": "#e02041" 16 | }, 17 | "updates": { 18 | "fallbackToCacheTimeout": 0 19 | }, 20 | "assetBundlePatterns": ["**/*"], 21 | "ios": { 22 | "supportsTablet": true 23 | }, 24 | "android": { 25 | "package": "com.bethesuperhero", 26 | "versionCode": 1 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /backend/tests/unit/integration/ong.spec.js: -------------------------------------------------------------------------------- 1 | const request = require("supertest"); 2 | const app = require("../../../src/app"); 3 | const connection = require("../../../src/database/connection"); 4 | 5 | describe("ONG", () => { 6 | beforeEach(async () => { 7 | await connection.migrate.rollback(); 8 | await connection.migrate.latest(); 9 | }); 10 | 11 | afterAll(async () => { 12 | await connection.destroy(); 13 | }); 14 | 15 | it("should be able to create a new ONG", async () => { 16 | const response = await request(app) 17 | .post("/ongs") 18 | .send({ 19 | name: "MY UNIQUE ONG", 20 | email: "lar@idosos.com.br", 21 | whatsapp: "12346718291", 22 | city: "Dourados", 23 | uf: "MS" 24 | }); 25 | 26 | console.log(response.body); 27 | 28 | expect(response.body).toHaveProperty("id"); 29 | expect(response.body.id).toHaveLength(8); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "axios": "^0.19.2", 10 | "react": "^16.13.1", 11 | "react-dom": "^16.13.1", 12 | "react-icons": "^3.9.0", 13 | "react-router-dom": "^5.1.2", 14 | "react-scripts": "3.4.1" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /backend/tests/unit/integration/session.spec.js: -------------------------------------------------------------------------------- 1 | const request = require("supertest"); 2 | const app = require("../../../src/app"); 3 | const connection = require("../../../src/database/connection"); 4 | 5 | describe("Logon/Session", () => { 6 | beforeEach(async () => { 7 | await connection.migrate.rollback(); 8 | await connection.migrate.latest(); 9 | }); 10 | 11 | afterAll(async () => { 12 | await connection.destroy(); 13 | }); 14 | 15 | it("should to logon", async () => { 16 | const createOngResponse = await request(app) 17 | .post("/ongs") 18 | .send({ 19 | name: "MY UNIQUE ONG", 20 | email: "lar@idosos.com.br", 21 | whatsapp: "12346718291", 22 | city: "Dourados", 23 | uf: "MS" 24 | }); 25 | 26 | const ongId = createOngResponse.body.id; 27 | 28 | const sessionResponse = await request(app) 29 | .post("/sessions") 30 | .send({ 31 | id: ongId 32 | }); 33 | 34 | expect(sessionResponse.body).toHaveProperty("name"); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /backend/src/routes.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const OngController = require("./controllers/OngController"); 3 | const IncidentController = require("./controllers/IncidentController"); 4 | const ProfileController = require("./controllers/ProfileController"); 5 | const SessionController = require("./controllers/SessionController"); 6 | const Validation = require("./controllers/middlewares/validations"); 7 | 8 | const routes = express.Router(); 9 | 10 | routes.post("/sessions", Validation.sessions, SessionController.create); 11 | 12 | routes.post("/ongs", Validation.createOngs, OngController.create); 13 | routes.get("/ongs", OngController.index); 14 | 15 | routes.get("/profile", Validation.profile, ProfileController.index); 16 | 17 | routes.post("/incidents", Validation.createIncident, IncidentController.create); 18 | routes.get("/incidents", Validation.indexIncidents, IncidentController.index); 19 | routes.delete( 20 | "/incidents/:id", 21 | Validation.deleteIncident, 22 | IncidentController.delete 23 | ); 24 | 25 | module.exports = routes; 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rocketseat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /frontend/src/pages/NewIncident/styles.css: -------------------------------------------------------------------------------- 1 | .new-incident-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | 7 | display: flex; 8 | align-items: center; 9 | justify-content: center; 10 | } 11 | 12 | .new-incident-container .content { 13 | width: 100%; 14 | padding: 96px; 15 | background: #f0f0f5; 16 | box-shadow: 0 0 100px rgba(0, 0, 0, 0.1); 17 | border-radius: 8px; 18 | 19 | display: flex; 20 | justify-content: space-between; 21 | align-items: center; 22 | } 23 | .new-incident-container .content section { 24 | width: 100%; 25 | max-width: 380px; 26 | } 27 | 28 | .new-incident-container .content section h1 { 29 | margin: 64px 0 32px; 30 | font-size: 32px; 31 | } 32 | 33 | .new-incident-container .content section p { 34 | font-size: 18px; 35 | color: #737380; 36 | line-height: 32px; 37 | } 38 | 39 | .new-incident-container .content form { 40 | width: 100%; 41 | max-width: 450px; 42 | } 43 | 44 | .new-incident-container .content form input, 45 | .new-incident-container .content form textarea { 46 | margin-top: 8px; 47 | } 48 | -------------------------------------------------------------------------------- /mobile/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "node_modules/expo/AppEntry.js", 3 | "name": "mobile", 4 | "version": "1.0.0", 5 | "scripts": { 6 | "start": "expo start", 7 | "android": "expo start --android", 8 | "ios": "expo start --ios", 9 | "web": "expo start --web", 10 | "eject": "expo eject" 11 | }, 12 | "dependencies": { 13 | "@react-native-community/masked-view": "0.1.5", 14 | "@react-navigation/native": "^5.1.3", 15 | "@react-navigation/stack": "^5.2.8", 16 | "axios": "^0.19.2", 17 | "expo": "~36.0.0", 18 | "expo-constants": "~8.0.0", 19 | "expo-mail-composer": "~8.0.0", 20 | "intl": "^1.2.5", 21 | "react": "~16.9.0", 22 | "react-dom": "~16.9.0", 23 | "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz", 24 | "react-native-gesture-handler": "~1.5.0", 25 | "react-native-reanimated": "~1.4.0", 26 | "react-native-safe-area-context": "0.6.0", 27 | "react-native-screens": "2.0.0-alpha.12", 28 | "react-native-web": "~0.11.7" 29 | }, 30 | "devDependencies": { 31 | "@babel/core": "^7.0.0", 32 | "babel-preset-expo": "~8.0.0" 33 | }, 34 | "private": true 35 | } 36 | -------------------------------------------------------------------------------- /frontend/src/pages/Register/styles.css: -------------------------------------------------------------------------------- 1 | .register-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | 7 | display: flex; 8 | align-items: center; 9 | justify-content: center; 10 | } 11 | 12 | .register-container .content { 13 | width: 100%; 14 | padding: 96px; 15 | background: #f0f0f5; 16 | box-shadow: 0 0 100px rgba(0, 0, 0, 0.1); 17 | border-radius: 8px; 18 | 19 | display: flex; 20 | justify-content: space-between; 21 | align-items: center; 22 | } 23 | .register-container .content section { 24 | width: 100%; 25 | max-width: 380px; 26 | } 27 | 28 | .register-container .content section h1 { 29 | margin: 64px 0 32px; 30 | font-size: 32px; 31 | } 32 | 33 | .register-container .content section p { 34 | font-size: 18px; 35 | color: #737380; 36 | line-height: 32px; 37 | } 38 | 39 | .register-container .content form { 40 | width: 100%; 41 | max-width: 450px; 42 | } 43 | 44 | .register-container .content form input { 45 | margin-top: 8px; 46 | } 47 | 48 | .register-container .content form .input-group { 49 | display: flex; 50 | } 51 | 52 | .register-container .content form .input-group input + input { 53 | margin-left: 8px; 54 | } 55 | -------------------------------------------------------------------------------- /mobile/src/pages/incidents/styles.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from "react-native"; 2 | import Constants from "expo-constants"; 3 | 4 | export default StyleSheet.create({ 5 | container: { 6 | flex: 1, 7 | paddingHorizontal: 24, 8 | paddingTop: Constants.statusBarHeight + 20 9 | }, 10 | header: { 11 | flexDirection: "row", 12 | justifyContent: "space-between", 13 | alignItems: "center" 14 | }, 15 | headerText: { 16 | fontSize: 15, 17 | color: "#737380" 18 | }, 19 | headerTextBold: { 20 | fontWeight: "bold" 21 | }, 22 | title: { 23 | fontSize: 30, 24 | marginBottom: 16, 25 | marginTop: 48, 26 | color: "#13131a", 27 | fontWeight: "bold" 28 | }, 29 | description: { 30 | fontSize: 16, 31 | lineHeight: 24, 32 | color: "#737380" 33 | }, 34 | 35 | incidentList: { 36 | marginTop: 32 37 | }, 38 | incident: { 39 | padding: 34, 40 | borderRadius: 8, 41 | backgroundColor: "#FFF", 42 | marginBottom: 16 43 | }, 44 | incidentProperty: { 45 | fontSize: 14, 46 | color: "#41414d", 47 | fontWeight: "bold" 48 | }, 49 | 50 | incidentValue: { 51 | marginTop: 8, 52 | fontSize: 15, 53 | marginBottom: 24, 54 | color: "#737380" 55 | }, 56 | detailsButton: { 57 | flexDirection: "row", 58 | justifyContent: "space-between", 59 | alignItems: "center" 60 | }, 61 | detailsButtonText: { 62 | color: "#e02041", 63 | fontSize: 15, 64 | fontWeight: "bold" 65 | } 66 | }); 67 | -------------------------------------------------------------------------------- /backend/knexfile.js: -------------------------------------------------------------------------------- 1 | // Update with your config settings. 2 | 3 | module.exports = { 4 | development: { 5 | client: "sqlite3", 6 | connection: { 7 | filename: "./src/database/db.sqlite" 8 | }, 9 | migrations: { 10 | directory: "./src/database/migrations" 11 | }, 12 | useNullAsDefault: true 13 | }, 14 | production: { 15 | client: "sqlite3", 16 | connection: { 17 | filename: "./src/database/db.sqlite" 18 | }, 19 | migrations: { 20 | directory: "./src/database/migrations" 21 | }, 22 | useNullAsDefault: true 23 | }, 24 | test: { 25 | client: "sqlite3", 26 | connection: { 27 | filename: "./src/database/test.sqlite" 28 | }, 29 | migrations: { 30 | directory: "./src/database/migrations" 31 | }, 32 | useNullAsDefault: true 33 | }, 34 | staging: { 35 | client: "postgresql", 36 | connection: { 37 | database: "my_db", 38 | user: "username", 39 | password: "password" 40 | }, 41 | pool: { 42 | min: 2, 43 | max: 10 44 | }, 45 | migrations: { 46 | tableName: "knex_migrations" 47 | } 48 | } 49 | 50 | // production: { 51 | // client: "postgresql", 52 | // connection: { 53 | // database: "my_db", 54 | // user: "username", 55 | // password: "password" 56 | // }, 57 | // pool: { 58 | // min: 2, 59 | // max: 10 60 | // }, 61 | // migrations: { 62 | // tableName: "knex_migrations" 63 | // } 64 | // } 65 | }; 66 | -------------------------------------------------------------------------------- /backend/src/controllers/middlewares/validations.js: -------------------------------------------------------------------------------- 1 | const { celebrate, Segments, Joi } = require("celebrate"); 2 | 3 | module.exports = { 4 | sessions: celebrate({ 5 | [Segments.BODY]: Joi.object().keys({ 6 | id: Joi.string().required() 7 | }) 8 | }), 9 | 10 | createOngs: celebrate({ 11 | [Segments.BODY]: Joi.object().keys({ 12 | name: Joi.string().required(), 13 | email: Joi.string() 14 | .required() 15 | .email(), 16 | whatsapp: Joi.string() 17 | .required() 18 | .min(10) 19 | .max(11), 20 | city: Joi.string().required(), 21 | uf: Joi.string() 22 | .required() 23 | .length(2) 24 | }) 25 | }), 26 | 27 | profile: celebrate({ 28 | [Segments.HEADERS]: Joi.object({ 29 | authorization: Joi.string().required() 30 | }).unknown() 31 | }), 32 | 33 | createIncident: celebrate({ 34 | [Segments.HEADERS]: Joi.object({ 35 | authorization: Joi.string().required() 36 | }).unknown(), 37 | [Segments.BODY]: Joi.object().keys({ 38 | title: Joi.string() 39 | .required() 40 | .min(3), 41 | description: Joi.string() 42 | .required() 43 | .min(3), 44 | value: Joi.number().required() 45 | }) 46 | }), 47 | 48 | indexIncidents: celebrate({ 49 | [Segments.QUERY]: Joi.object().keys({ 50 | page: Joi.number() 51 | }) 52 | }), 53 | 54 | deleteIncident: celebrate({ 55 | [Segments.PARAMS]: Joi.object().keys({ 56 | id: Joi.number().required() 57 | }) 58 | }) 59 | }; 60 | -------------------------------------------------------------------------------- /mobile/src/pages/Detail/styles.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from "react-native"; 2 | import Constants from "expo-constants"; 3 | 4 | export default StyleSheet.create({ 5 | container: { 6 | flex: 1, 7 | paddingHorizontal: 24, 8 | paddingTop: Constants.statusBarHeight + 20 9 | }, 10 | header: { 11 | flexDirection: "row", 12 | justifyContent: "space-between", 13 | alignItems: "center" 14 | }, 15 | incident: { 16 | marginTop: 48, 17 | padding: 34, 18 | borderRadius: 8, 19 | backgroundColor: "#FFF", 20 | marginBottom: 16 21 | }, 22 | incidentProperty: { 23 | fontSize: 14, 24 | color: "#41414d", 25 | fontWeight: "bold", 26 | marginTop: 24 27 | }, 28 | incidentValue: { 29 | marginTop: 8, 30 | fontSize: 15, 31 | color: "#737380" 32 | }, 33 | contactBox: { 34 | padding: 34, 35 | borderRadius: 8, 36 | backgroundColor: "#FFF", 37 | marginBottom: 16 38 | }, 39 | heroTitle: { 40 | fontWeight: "bold", 41 | fontSize: 20, 42 | color: "#13131a", 43 | lineHeight: 30 44 | }, 45 | heroDescription: { 46 | fontSize: 15, 47 | color: "#737380", 48 | marginTop: 16 49 | }, 50 | actions: { 51 | marginTop: 16, 52 | flexDirection: "row", 53 | justifyContent: "space-between" 54 | }, 55 | action: { 56 | backgroundColor: "#e02041", 57 | borderRadius: 8, 58 | height: 50, 59 | width: "48%", 60 | justifyContent: "center", 61 | alignItems: "center" 62 | }, 63 | actionText: { 64 | color: "#FFF", 65 | fontSize: 15, 66 | fontWeight: "bold" 67 | } 68 | }); 69 | -------------------------------------------------------------------------------- /frontend/src/global.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap"); 2 | 3 | * { 4 | margin: 0; 5 | padding: 0; 6 | outline: 0; 7 | box-sizing: border-box; 8 | } 9 | 10 | body { 11 | font: 400 14px Roboto, sans-serif; 12 | background: #f0f0f5; 13 | -webkit-font-smoothing: antialiased; 14 | } 15 | 16 | input, 17 | button, 18 | textarea { 19 | font: 400 18px Roboto, sans-serif; 20 | } 21 | 22 | button { 23 | cursor: pointer; 24 | } 25 | 26 | form input { 27 | width: 100%; 28 | height: 60px; 29 | color: #333; 30 | border: 1px solid #dcdce6; 31 | border-radius: 8px; 32 | padding: 0 24px; 33 | } 34 | 35 | form textarea { 36 | width: 100%; 37 | min-height: 140px; 38 | color: #333; 39 | border: 1px solid #dcdce6; 40 | border-radius: 8px; 41 | padding: 16px 24px; 42 | line-height: 24px; 43 | resize: vertical; 44 | } 45 | 46 | .button { 47 | width: 100%; 48 | height: 60px; 49 | background: #e02041; 50 | border: 0; 51 | border-radius: 8px; 52 | color: #fff; 53 | font-weight: bold; 54 | margin-top: 16px; 55 | display: inline-block; 56 | text-align: center; 57 | font-size: 18px; 58 | line-height: 60px; 59 | transition: filter 0.2s; 60 | } 61 | 62 | .button:hover { 63 | filter: brightness(90%); 64 | } 65 | 66 | .back-link { 67 | display: flex; 68 | align-items: center; 69 | margin-top: 40px; 70 | color: #41414d; 71 | font-size: 18px; 72 | text-decoration: none; 73 | font-weight: 500; 74 | transition: opacity 0.2s; 75 | } 76 | 77 | .back-link svg { 78 | margin-right: 8px; 79 | } 80 | 81 | .back-link:hover { 82 | opacity: 0.8; 83 | } 84 | -------------------------------------------------------------------------------- /frontend/src/pages/Logon/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { FiLogIn } from "react-icons/fi"; 3 | import "./styles.css"; 4 | import heroes from "../../assets/heroes.png"; 5 | import logo from "../../assets/logo.svg"; 6 | import { Link, useHistory } from "react-router-dom"; 7 | import api from "../../services/api"; 8 | 9 | export default function Logon() { 10 | const [id, setId] = useState(""); 11 | const history = useHistory(); 12 | 13 | async function handleLogin(e) { 14 | e.preventDefault(); 15 | 16 | try { 17 | const response = await api.post("sessions", { id }); 18 | localStorage.setItem("@bethehero/ongId", id); 19 | localStorage.setItem("@bethehero/ongName", response.data.name); 20 | history.push("/profile"); 21 | } catch (err) { 22 | alert("Falha no Login, tente novamente"); 23 | } 24 | } 25 | 26 | return ( 27 |
28 |
29 | Be The Hero 30 | 31 |
32 |

Faça seu logon

33 | 34 | setId(e.target.value)} 38 | /> 39 | 42 | 43 | 44 | 45 | Não tenho cadastro 46 | 47 | 48 |
49 | Heroes 50 |
51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /backend/src/controllers/IncidentController.js: -------------------------------------------------------------------------------- 1 | const connection = require("../database/connection"); 2 | 3 | module.exports = { 4 | async index(request, response) { 5 | const { page = 1 } = request.query; 6 | 7 | const [count] = await connection("incidents").count(); 8 | 9 | const incidentes = await connection("incidents") 10 | .join("ongs", "ongs.id", "=", "incidents.ong_id") 11 | .limit(5) 12 | .offset((page - 1) * 5) 13 | .select([ 14 | "incidents.*", 15 | "ongs.name", 16 | "ongs.email", 17 | "ongs.whatsapp", 18 | "ongs.city", 19 | "ongs.uf" 20 | ]); 21 | 22 | response.header("X-Total-Count", count["count(*)"]); 23 | 24 | return response.json(incidentes); 25 | }, 26 | 27 | async create(request, response) { 28 | const { title, description, value } = request.body; 29 | const ong_id = request.headers.authorization; 30 | 31 | const [id] = await connection("incidents").insert({ 32 | title, 33 | description, 34 | value, 35 | ong_id 36 | }); 37 | 38 | return response.json({ id }); 39 | }, 40 | 41 | async delete(request, response) { 42 | const { id } = request.params; 43 | const ong_id = request.headers.authorization; 44 | 45 | const incident = await connection("incidents") 46 | .where("id", id) 47 | .select("ong_id") 48 | .first(); 49 | 50 | if (incident.ong_id !== ong_id) { 51 | return response.status(401).json({ error: "Operation not permitted" }); 52 | } 53 | 54 | await connection("incidents") 55 | .where("id", id) 56 | .delete(); 57 | 58 | return response.status(204).send(); 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /frontend/src/pages/Profile/styles.css: -------------------------------------------------------------------------------- 1 | .profile-container { 2 | width: 100%; 3 | max-width: 1180px; 4 | padding: 0 30px; 5 | margin: 32px auto; 6 | } 7 | 8 | .profile-container header { 9 | display: flex; 10 | align-items: center; 11 | } 12 | 13 | .profile-container header span { 14 | font-size: 20px; 15 | margin-left: 24px; 16 | } 17 | 18 | .profile-container header img { 19 | height: 64px; 20 | } 21 | 22 | .profile-container header a { 23 | width: 260px; 24 | margin-left: auto; 25 | margin-top: 0; 26 | text-decoration: none; 27 | } 28 | 29 | .profile-container header button { 30 | height: 60px; 31 | width: 60px; 32 | border-radius: 4px; 33 | border: 1px solid #dcdce6; 34 | background: transparent; 35 | margin-left: 16px; 36 | transition: border-color 0.2s; 37 | } 38 | 39 | .profile-container header button:hover { 40 | border-color: #999; 41 | } 42 | 43 | .profile-container h1 { 44 | margin-top: 80px; 45 | margin-bottom: 24px; 46 | } 47 | 48 | .profile-container ul { 49 | display: grid; 50 | grid-template-columns: repeat(2, 1fr); 51 | grid-gap: 24px; 52 | list-style: none; 53 | } 54 | 55 | .profile-container ul li { 56 | background: #fff; 57 | padding: 24px; 58 | border-radius: 8px; 59 | position: relative; 60 | } 61 | 62 | .profile-container ul li button { 63 | position: absolute; 64 | right: 24px; 65 | top: 24px; 66 | border: 0; 67 | transition: opacity 0.2s; 68 | } 69 | 70 | .profile-container ul li button:hover { 71 | opacity: 0.8; 72 | } 73 | 74 | .profile-container ul li strong { 75 | display: block; 76 | margin-bottom: 16px; 77 | color: #41414d; 78 | } 79 | 80 | .profile-container ul li p + strong { 81 | margin-top: 32px; 82 | } 83 | 84 | .profile-container ul li p { 85 | color: #737380; 86 | line-height: 21px; 87 | font-size: 16px; 88 | } 89 | -------------------------------------------------------------------------------- /frontend/src/pages/NewIncident/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import logo from "../../assets/logo.svg"; 3 | import { Link, useHistory } from "react-router-dom"; 4 | import { FiArrowLeft } from "react-icons/fi"; 5 | import "./styles.css"; 6 | import api from "../../services/api"; 7 | 8 | export default function NewIncident() { 9 | const [title, setTitle] = useState(""); 10 | const [description, setDescription] = useState(""); 11 | const [value, setValue] = useState(""); 12 | 13 | const ongId = localStorage.getItem("@bethehero/ongId"); 14 | 15 | const history = useHistory(); 16 | 17 | async function handleNewIncident(e) { 18 | e.preventDefault(); 19 | 20 | const data = { 21 | title, 22 | description, 23 | value 24 | }; 25 | 26 | await api.post("/incidents", data, { 27 | headers: { 28 | Authorization: ongId 29 | } 30 | }); 31 | 32 | history.push("/profile"); 33 | 34 | try { 35 | } catch (error) { 36 | alert("Erro ao cadastrar caso, tente novamente."); 37 | } 38 | } 39 | 40 | return ( 41 |
42 |
43 |
44 | Be The Hero 45 |

Cadastrar novo caso

46 |

47 | Descreva o caso detalhadamente para encontrar um herói para resolver 48 | isso. 49 |

50 | 51 | 52 | Voltar para Home 53 | 54 |
55 |
56 | setTitle(e.target.value)} 60 | /> 61 |