├── .gitignore
├── frontend
├── src
│ ├── react-app-env.d.ts
│ ├── components
│ │ ├── Header.tsx
│ │ ├── Dropzone
│ │ │ ├── styles.css
│ │ │ └── index.tsx
│ │ ├── Map
│ │ │ └── index.tsx
│ │ └── Success
│ │ │ ├── styles.css
│ │ │ └── index.tsx
│ ├── App.tsx
│ ├── index.tsx
│ ├── pages
│ │ ├── routes.tsx
│ │ ├── Home
│ │ │ ├── index.tsx
│ │ │ └── style.css
│ │ └── CreatePoint
│ │ │ ├── style.css
│ │ │ └── index.tsx
│ ├── App.css
│ └── assets
│ │ ├── logo.svg
│ │ └── home-background.svg
├── .gitignore
├── tsconfig.json
├── public
│ └── index.html
├── package.json
└── README.md
├── mobile
├── src
│ ├── assets
│ │ ├── icon.png
│ │ ├── logo.png
│ │ ├── logo@1x.png
│ │ ├── logo@2x.png
│ │ ├── splash.png
│ │ ├── home-background.png
│ │ ├── home-background@2x.png
│ │ └── home-background@3x.png
│ ├── routes.tsx
│ └── pages
│ │ ├── Detail
│ │ ├── styles.ts
│ │ └── index.tsx
│ │ ├── Home
│ │ ├── styles.ts
│ │ └── index.tsx
│ │ └── Points
│ │ ├── style.ts
│ │ └── index.tsx
├── babel.config.js
├── .expo-shared
│ └── assets.json
├── .gitignore
├── tsconfig.json
├── app.json
├── App.tsx
└── package.json
├── backend
├── src
│ ├── controller
│ │ ├── index.ts
│ │ ├── ItemsController.ts
│ │ └── PointsController.ts
│ ├── database
│ │ ├── migrations
│ │ │ ├── 01_create_items.ts
│ │ │ ├── 02_create_points_items.ts
│ │ │ └── 00_create_points.ts
│ │ ├── seeds
│ │ │ └── default_items.ts
│ │ └── index.ts
│ ├── server.ts
│ └── routes.ts
├── index.d.ts
├── knexfile.ts
├── config
│ └── multer.ts
├── static
│ ├── papeis-papelao.svg
│ ├── baterias.svg
│ ├── lampadas.svg
│ ├── eletronicos.svg
│ ├── oleo.svg
│ └── organicos.svg
├── package.json
└── tsconfig.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
3 | *.sqlite
4 | uploads/*
--------------------------------------------------------------------------------
/frontend/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/mobile/src/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/icon.png
--------------------------------------------------------------------------------
/mobile/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/logo.png
--------------------------------------------------------------------------------
/mobile/src/assets/logo@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/logo@1x.png
--------------------------------------------------------------------------------
/mobile/src/assets/logo@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/logo@2x.png
--------------------------------------------------------------------------------
/mobile/src/assets/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/splash.png
--------------------------------------------------------------------------------
/mobile/src/assets/home-background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/home-background.png
--------------------------------------------------------------------------------
/mobile/src/assets/home-background@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/home-background@2x.png
--------------------------------------------------------------------------------
/mobile/src/assets/home-background@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reisdev/next-level-week/HEAD/mobile/src/assets/home-background@3x.png
--------------------------------------------------------------------------------
/mobile/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = function(api) {
2 | api.cache(true);
3 | return {
4 | presets: ['babel-preset-expo'],
5 | };
6 | };
7 |
--------------------------------------------------------------------------------
/mobile/.expo-shared/assets.json:
--------------------------------------------------------------------------------
1 | {
2 | "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3 | "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4 | }
5 |
--------------------------------------------------------------------------------
/frontend/src/components/Header.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const Header: React.FC = () => {
4 | return
7 | }
8 |
9 | export default Header;
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/frontend/src/App.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import './App.css';
3 | import Routes from './pages/routes';
4 |
5 | function App() {
6 | return (
7 |
8 |
9 |
10 | );
11 | }
12 |
13 | export default App;
14 |
--------------------------------------------------------------------------------
/frontend/src/index.tsx:
--------------------------------------------------------------------------------
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/src/controller/index.ts:
--------------------------------------------------------------------------------
1 | import { Request, Response } from 'express';
2 |
3 | export interface Controller {
4 | create?(req: Request, response: Response): any;
5 | delete?(req: Request, response: Response): any;
6 | index?(req: Request, response: Response): any;
7 | }
--------------------------------------------------------------------------------
/mobile/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowSyntheticDefaultImports": true,
4 | "jsx": "react-native",
5 | "lib": ["dom", "esnext"],
6 | "moduleResolution": "node",
7 | "noEmit": true,
8 | "skipLibCheck": true,
9 | "resolveJsonModule": true,
10 | "strict": true
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/backend/index.d.ts:
--------------------------------------------------------------------------------
1 | class Item {
2 | id: number;
3 | title: string;
4 | image: string;
5 | }
6 |
7 | class Point {
8 | id: number;
9 | name: string;
10 | image: string;
11 | email: string;
12 | latitude: number;
13 | longitude: number;
14 | uf: string;
15 | city: string;
16 | }
17 |
18 | class PointItems {
19 | point_id: number;
20 | item_id: number;
21 | }
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/frontend/src/pages/routes.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Route, BrowserRouter } from 'react-router-dom';
3 | import Home from './Home';
4 | import CreatePoint from './CreatePoint';
5 |
6 | const Routes = () => {
7 | return
8 |
9 |
10 |
11 | }
12 |
13 | export default Routes;
--------------------------------------------------------------------------------
/backend/src/database/migrations/01_create_items.ts:
--------------------------------------------------------------------------------
1 | import Knex from "knex";
2 |
3 | export async function up(knex: Knex) {
4 | return knex.schema.createTable("items", (table) => {
5 | table.increments("id").primary();
6 | table.string("image").notNullable();
7 | table.string("title").notNullable();
8 | })
9 | }
10 |
11 | export async function down(knex: Knex) {
12 | return knex.schema.dropTable("items")
13 | }
--------------------------------------------------------------------------------
/backend/knexfile.ts:
--------------------------------------------------------------------------------
1 | import path from "path";
2 |
3 | module.exports = {
4 | client: "sqlite3",
5 | useNullAsDefault: true,
6 | connection: {
7 | filename: path.resolve(__dirname, "src", "database", "database.sqlite")
8 | },
9 | migrations: {
10 | directory: path.resolve(__dirname, "src", "database", "migrations")
11 | },
12 | seeds: {
13 | directory: path.resolve(__dirname, "src", "database", "seeds")
14 | }
15 | }
--------------------------------------------------------------------------------
/backend/config/multer.ts:
--------------------------------------------------------------------------------
1 | import multer from "multer";
2 | import path from "path";
3 | import crypto from "crypto";
4 |
5 | export default {
6 | storage: multer.diskStorage({
7 | destination: path.resolve(__dirname, "..", "uploads"),
8 | filename: (request, file, callback) => {
9 | const hash = crypto.randomBytes(6).toString('hex');
10 | const filename = `${hash}-${file.originalname}`
11 | callback(null, filename);
12 | }
13 | })
14 | }
--------------------------------------------------------------------------------
/backend/src/database/migrations/02_create_points_items.ts:
--------------------------------------------------------------------------------
1 | import Knex from "knex";
2 |
3 | export async function up(knex: Knex) {
4 | return knex.schema.createTable("point_items", (table) => {
5 | table.increments("id").primary();
6 | table.integer("point_id").references("id").inTable("points");
7 | table.integer("item_id").references("id").inTable("items");
8 | })
9 | }
10 |
11 | export async function down(knex: Knex) {
12 | return knex.schema.dropTable("point_items")
13 | }
--------------------------------------------------------------------------------
/frontend/src/App.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --primary-color: #34CB79;
3 | --title-color: #322153;
4 | --text-color: #6C6C80;
5 | }
6 |
7 | * {
8 | margin: 0;
9 | padding: 0;
10 | box-sizing: border-box;
11 | }
12 |
13 | body {
14 | background: #F0F0F5;
15 | -webkit-font-smoothing: antialiased;
16 | color: var(--text-color);
17 | }
18 |
19 | body, input, button {
20 | font-family: Roboto, Arial, Helvetica, sans-serif;
21 | }
22 |
23 | h1, h2, h3, h4, h5, h6 {
24 | color: var(--title-color);
25 | font-family: Ubuntu;
26 | }
27 |
--------------------------------------------------------------------------------
/backend/src/database/seeds/default_items.ts:
--------------------------------------------------------------------------------
1 | import Knex from "knex";
2 |
3 | export async function seed(knex: Knex) {
4 | await knex("items").insert([
5 | { title: "Lâmpadas", image: "lampadas.svg" },
6 | { title: "Resíduos Orgânicos", image: "organicos.svg" },
7 | { title: "Resíduos Eletrônicos", image: "eletronicos.svg" },
8 | { title: "Papéis e Papelão", image: "papeis-papelao.svg" },
9 | { title: "Pilhas e Baterias", image: "baterias.svg" },
10 | { title: "Óleo de Cozinha", image: "oleo.svg" }
11 | ])
12 | }
--------------------------------------------------------------------------------
/backend/src/database/index.ts:
--------------------------------------------------------------------------------
1 | import knex from "knex";
2 | import path from "path";
3 | import dotenv from "dotenv";
4 |
5 | dotenv.config({
6 | path: path.resolve(__dirname, "../../.env")
7 | });
8 |
9 | export default knex({
10 | client: process.env.DATABASE_ENGINE,
11 | useNullAsDefault: true,
12 | connection: {
13 | filename: path.resolve(__dirname, "database.sqlite"),
14 | host: process.env.DATABASE_HOST,
15 | database: "ecoleta",
16 | user: process.env.DATABASE_USER,
17 | password: process.env.DATABASE_PASSWORD,
18 | }
19 | });
20 |
21 |
22 |
--------------------------------------------------------------------------------
/backend/static/papeis-papelao.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/frontend/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "module": "esnext",
16 | "moduleResolution": "node",
17 | "resolveJsonModule": true,
18 | "isolatedModules": true,
19 | "noEmit": true,
20 | "jsx": "react"
21 | },
22 | "include": [
23 | "src"
24 | ]
25 | }
--------------------------------------------------------------------------------
/backend/src/controller/ItemsController.ts:
--------------------------------------------------------------------------------
1 | import knex from "../database";
2 | import { Controller } from ".";
3 | import { Request, Response } from 'express';
4 |
5 | class ItemsControlller implements Controller {
6 | async index(req: Request, res: Response) {
7 | const items = await knex("items").select("*");
8 |
9 | const serialized = items.map((item: Item) => ({
10 | id: item.id, title: item.title, imageUrl: `${process.env.BASE_URL}:${process.env.PORT}/static/${item.image}`
11 | }))
12 | return res.json(serialized);
13 | }
14 | }
15 |
16 | export default ItemsControlller;
17 |
--------------------------------------------------------------------------------
/mobile/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "expo": {
3 | "name": "mobile",
4 | "slug": "mobile",
5 | "platforms": [
6 | "ios",
7 | "android",
8 | "web"
9 | ],
10 | "version": "1.0.0",
11 | "orientation": "portrait",
12 | "icon": "./src/assets/icon.png",
13 | "splash": {
14 | "image": "./src/assets/splash.png",
15 | "resizeMode": "contain",
16 | "backgroundColor": "#ffffff"
17 | },
18 | "updates": {
19 | "fallbackToCacheTimeout": 0
20 | },
21 | "assetBundlePatterns": [
22 | "**/*"
23 | ],
24 | "ios": {
25 | "supportsTablet": true
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/backend/src/database/migrations/00_create_points.ts:
--------------------------------------------------------------------------------
1 | import Knex from "knex";
2 |
3 | export async function up(knex: Knex) {
4 | return knex.schema.createTable("points", (table) => {
5 | table.increments("id").primary();
6 | table.string("image").notNullable();
7 | table.string("name").notNullable();
8 | table.string("email").notNullable()
9 | table.decimal("latitude").notNullable();
10 | table.decimal("longitude").notNullable();
11 | table.string("whatsapp").notNullable();
12 | table.string("city");
13 | table.string("uf", 2).notNullable();
14 | })
15 | }
16 |
17 | export async function down(knex: Knex) {
18 | return knex.schema.dropTable("points");
19 | }
--------------------------------------------------------------------------------
/frontend/src/components/Dropzone/styles.css:
--------------------------------------------------------------------------------
1 | .dropzone {
2 | height: 300px;
3 | background: #E1FAEC;
4 | border-radius: 10px;
5 |
6 | display: flex;
7 | justify-content: center;
8 | align-items: center;
9 | margin-top: 48px;
10 | outline: 0;
11 | }
12 |
13 | .dropzone img {
14 | width: 100%;
15 | height: 100%;
16 | object-fit: cover;
17 | }
18 |
19 | .dropzone p {
20 | width: calc(100% - 60px);
21 | height: calc(100% - 60px);
22 | border-radius: 10px;
23 | border: 1px dashed #4ECB79;
24 |
25 | display: flex;
26 | flex-direction: column;
27 | justify-content: center;
28 | align-items: center;
29 | color: #333;
30 | }
31 |
32 | .dropzone p svg {
33 | color: #4ECB79;
34 | width: 24px;
35 | height: 24px;
36 | margin-bottom: 8px;
37 | }
--------------------------------------------------------------------------------
/backend/static/baterias.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/backend/src/server.ts:
--------------------------------------------------------------------------------
1 | import express from "express";
2 | import cors from "cors";
3 | import dotenv from "dotenv";
4 | import path from "path";
5 | import morgan from "morgan";
6 | import router from "./routes";
7 | import { errors } from "celebrate";
8 |
9 | dotenv.config({
10 | path: path.resolve(__dirname, "../.env")
11 | });
12 |
13 | const app = express();
14 |
15 | app.use(express.json());
16 | app.use(morgan("combined"));
17 | app.use(cors());
18 | app.use(router);
19 |
20 | // Serve static files
21 | app.use("/static", express.static(path.resolve(__dirname, "../static")))
22 | app.use("/uploads", express.static(path.resolve(__dirname, "../uploads")))
23 |
24 | app.use(errors())
25 |
26 | app.listen(process.env.PORT || 8000, () => {
27 | console.log(`\nServer listening on PORT ${process.env.PORT}\n`)
28 | })
--------------------------------------------------------------------------------
/frontend/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Ecoleta
8 |
12 |
18 |
19 |
20 | You need to enable JavaScript to run this app.
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/mobile/App.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { AppLoading } from "expo"
3 | import { StyleSheet, StatusBar } from 'react-native';
4 |
5 | import { Roboto_400Regular, Roboto_500Medium } from '@expo-google-fonts/roboto';
6 | import { Ubuntu_700Bold, useFonts } from "@expo-google-fonts/ubuntu";
7 |
8 | import Routes from './src/routes';
9 |
10 | export default function App() {
11 | const [fontsLoaded] = useFonts({
12 | Roboto_400Regular,
13 | Roboto_500Medium,
14 | Ubuntu_700Bold
15 | });
16 | if (!fontsLoaded) return
17 | return (
18 | <>
19 |
20 |
21 | >
22 | );
23 | }
24 |
25 | const styles = StyleSheet.create({
26 | container: {
27 | flex: 1,
28 | backgroundColor: '#fff',
29 | alignItems: 'center',
30 | justifyContent: 'center',
31 | },
32 | });
33 |
--------------------------------------------------------------------------------
/frontend/src/components/Map/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 |
3 | import { Map, TileLayer, Popup, Marker } from 'react-leaflet';
4 | import { LeafletMouseEvent, LatLng } from 'leaflet';
5 |
6 | interface MapProps {
7 | onMark: Function;
8 | position: { latitude: number, longitude: number }
9 | }
10 |
11 | const MapComponent: React.FC = ({ onMark, position }) => {
12 | return {
13 | onMark(e.latlng.lat, e.latlng.lng);
14 | }}>
15 |
19 |
20 |
21 | }
22 |
23 | export default MapComponent
--------------------------------------------------------------------------------
/mobile/src/routes.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { NavigationContainer } from "@react-navigation/native"
3 | import { createStackNavigator } from "@react-navigation/stack";
4 |
5 | import Home from "./pages/Home"
6 | import Points from "./pages/Points";
7 | import Detail from "./pages/Detail";
8 |
9 | const AppStack = createStackNavigator()
10 |
11 | const Routes = () => {
12 | return
13 |
20 |
21 |
22 |
23 |
24 |
25 | }
26 |
27 | export default Routes;
--------------------------------------------------------------------------------
/frontend/src/components/Success/styles.css:
--------------------------------------------------------------------------------
1 | .success {
2 | display: none !important;
3 | position: fixed;
4 | left: 0;
5 | top: 0;
6 | background-color: rgb(0, 0, 0, .7);
7 | justify-content: center;
8 | align-items: center;
9 | display: flex;
10 | height: 100%;
11 | width: 100%;
12 | z-index: 1005;
13 | }
14 |
15 | .success .open {
16 | display: block;
17 | }
18 |
19 | .success section {
20 | font-size: 2.5rem;
21 | text-align: center;
22 | color: white
23 | }
24 |
25 | .success button {
26 | width: 200px;
27 | height: 40px;
28 | background: var(--primary-color);
29 | border-radius: 8px;
30 | color: #FFF;
31 | font-weight: bold;
32 | font-size: 16px;
33 | border: 0;
34 | align-self: flex-end;
35 | margin-top: 40px;
36 | transition: background-color 0.2s;
37 | cursor: pointer;
38 | }
39 |
40 | .success svg {
41 | font-size: 4rem;
42 | color: var(--primary-color);
43 | }
--------------------------------------------------------------------------------
/frontend/src/components/Success/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { FiCheckCircle, FiXCircle } from 'react-icons/fi'
3 |
4 | import "./styles.css"
5 | import { useHistory } from 'react-router-dom'
6 |
7 | interface Props {
8 | status: string;
9 | onClose: () => void
10 | }
11 |
12 | const Success: React.FC = ({ status, onClose }) => {
13 | const history = useHistory();
14 | return (
15 |
16 | {
17 | status === "success" ?
18 |
19 | Cadastrado com sucesso
20 | history.push("/")}>Continuar
21 |
22 | :
23 |
24 | Desculpe, tivemos um problema
25 | Continuar
26 |
27 | }
28 |
29 | )
30 | }
31 |
32 | export default Success;
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Matheus dos Reis de Jesus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/backend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nlw",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "ts-node-dev --transpileOnly --ignore-watch node_modules src/server.ts",
8 | "knex:migrate": "knex migrate:latest --knexfile knexfile.ts",
9 | "knex:seed": "knex seed:run --knexfile knexfile.ts",
10 | "test": "echo \"Error: no test specified\" && exit 1",
11 | "postinstall": "mkdir uploads"
12 | },
13 | "keywords": [],
14 | "author": "",
15 | "license": "ISC",
16 | "dependencies": {
17 | "@types/hapi__joi": "^17.1.2",
18 | "celebrate": "^12.1.1",
19 | "cors": "^2.8.5",
20 | "express": "^4.17.1",
21 | "knex": "^0.21.1",
22 | "morgan": "^1.10.0",
23 | "mouter": "^0.0.0-reserved",
24 | "multer": "^1.4.2",
25 | "sqlite3": "^4.2.0"
26 | },
27 | "devDependencies": {
28 | "@types/cors": "^2.8.6",
29 | "@types/express": "^4.17.6",
30 | "@types/morgan": "^1.9.0",
31 | "@types/multer": "^1.4.3",
32 | "@types/node": "^14.0.9",
33 | "dotenv": "^8.2.0",
34 | "ts-node": "^8.10.2",
35 | "ts-node-dev": "^1.0.0-pre.44",
36 | "typescript": "^3.9.3"
37 | }
38 | }
--------------------------------------------------------------------------------
/frontend/src/components/Dropzone/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useCallback, useState } from 'react'
2 | import { useDropzone } from 'react-dropzone'
3 | import { FiUpload } from "react-icons/fi"
4 |
5 | import "./styles.css";
6 |
7 | interface Props {
8 | onFileUploaded: (file: File) => void
9 | }
10 |
11 | const Dropzone: React.FC = ({ onFileUploaded }) => {
12 | const [selectedFileUrl, setSelectedFileUrl] = useState("")
13 | const onDrop = useCallback(acceptedFiles => {
14 | const file = acceptedFiles[0];
15 | setSelectedFileUrl(URL.createObjectURL(file))
16 | onFileUploaded(file)
17 | }, [])
18 | const { getRootProps, getInputProps, isDragActive } = useDropzone(
19 | { onDrop, accept: "image/*" })
20 |
21 | return (
22 |
31 | )
32 | }
33 |
34 | export default Dropzone;
--------------------------------------------------------------------------------
/frontend/src/pages/Home/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import logo from "../../assets/logo.svg";
4 | import { FiLogIn, FiPlus } from "react-icons/fi";
5 | import "./style.css";
6 | import { Link } from 'react-router-dom';
7 |
8 | const Home = () => {
9 | return (
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Cadastre um ponto de coleta
19 |
20 |
21 |
22 | Seu marketplace de coleta de resíduos.
23 | Ajudamos pessoas a encontrarem pontos de coleta de forma eficiente.
24 |
25 |
26 |
27 |
28 | Cadastre um ponto de coleta
29 |
30 |
31 |
32 | )
33 | }
34 |
35 | export default Home
--------------------------------------------------------------------------------
/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 | "@types/jest": "^24.0.0",
10 | "@types/node": "^12.0.0",
11 | "@types/react": "^16.9.0",
12 | "@types/react-dom": "^16.9.0",
13 | "@types/react-dropzone": "^5.1.0",
14 | "@types/react-leaflet": "^2.5.1",
15 | "@types/react-router-dom": "^5.1.5",
16 | "leaflet": "^1.6.0",
17 | "react": "^16.13.1",
18 | "react-dom": "^16.13.1",
19 | "react-dropzone": "^11.0.1",
20 | "react-icons": "^3.10.0",
21 | "react-leaflet": "^2.7.0",
22 | "react-router-dom": "^5.2.0",
23 | "react-scripts": "3.4.1",
24 | "typescript": "~3.7.2"
25 | },
26 | "scripts": {
27 | "start": "react-scripts start",
28 | "build": "react-scripts build",
29 | "test": "react-scripts test",
30 | "eject": "react-scripts eject"
31 | },
32 | "eslintConfig": {
33 | "extends": "react-app"
34 | },
35 | "browserslist": {
36 | "production": [
37 | ">0.2%",
38 | "not dead",
39 | "not op_mini all"
40 | ],
41 | "development": [
42 | "last 1 chrome version",
43 | "last 1 firefox version",
44 | "last 1 safari version"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/backend/src/routes.ts:
--------------------------------------------------------------------------------
1 | import express from "express";
2 | import { celebrate, Joi } from "celebrate"
3 |
4 | import multer from "multer";
5 | import multerConfig from "../config/multer";
6 |
7 | import ItemsControlller from "./controller/ItemsController";
8 | import PointsControlller from "./controller/PointsController";
9 |
10 | const router = express.Router();
11 | const upload = multer(multerConfig);
12 |
13 | router.get("/", (req, res) => res.json({ message: "Hello World" }));
14 |
15 | const pointsController = new PointsControlller()
16 | const itemsController = new ItemsControlller();
17 |
18 | router.get("/items", itemsController.index);
19 | router.post("/points",
20 | upload.single("image"),
21 | celebrate({
22 | body: Joi.object().keys({
23 | name: Joi.string().required(),
24 | email: Joi.string().required(),
25 | whatsapp: Joi.string().required(),
26 | latitude: Joi.number().required(),
27 | longitude: Joi.number().required(),
28 | city: Joi.string().required(),
29 | uf: Joi.string().max(2).required(),
30 | items: Joi.string().regex(/^([0-9],?)+$/).required()
31 | })
32 | }, { abortEarly: false }),
33 | pointsController.create
34 | );
35 | router.get("/points", pointsController.index);
36 | router.get("/points/:id", pointsController.show);
37 |
38 | export default router;
--------------------------------------------------------------------------------
/mobile/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "main": "node_modules/expo/AppEntry.js",
3 | "scripts": {
4 | "start": "expo start",
5 | "android": "expo start --android",
6 | "ios": "expo start --ios",
7 | "web": "expo start --web",
8 | "eject": "expo eject"
9 | },
10 | "dependencies": {
11 | "@expo-google-fonts/roboto": "^0.1.0",
12 | "@expo-google-fonts/ubuntu": "^0.1.0",
13 | "@react-native-community/masked-view": "0.1.6",
14 | "@react-navigation/native": "^5.5.0",
15 | "@react-navigation/stack": "^5.4.1",
16 | "expo": "~37.0.3",
17 | "expo-font": "~8.1.0",
18 | "expo-location": "~8.1.0",
19 | "expo-mail-composer": "^8.1.0",
20 | "react": "~16.9.0",
21 | "react-dom": "~16.9.0",
22 | "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
23 | "react-native-gesture-handler": "~1.6.0",
24 | "react-native-maps": "^0.27.1",
25 | "react-native-picker-select": "^7.0.0",
26 | "react-native-reanimated": "~1.7.0",
27 | "react-native-safe-area-context": "0.7.3",
28 | "react-native-screens": "~2.2.0",
29 | "react-native-svg": "11.0.1",
30 | "react-native-web": "~0.11.7"
31 | },
32 | "devDependencies": {
33 | "@babel/core": "^7.8.6",
34 | "@types/react": "~16.9.23",
35 | "@types/react-native": "~0.61.17",
36 | "babel-preset-expo": "~8.1.0",
37 | "typescript": "~3.8.3"
38 | },
39 | "private": true
40 | }
41 |
--------------------------------------------------------------------------------
/mobile/src/pages/Detail/styles.ts:
--------------------------------------------------------------------------------
1 |
2 | import { StyleSheet } from 'react-native'
3 |
4 | const styles = StyleSheet.create({
5 | container: {
6 | flex: 1,
7 | padding: 32,
8 | paddingTop: 20,
9 | },
10 |
11 | pointImage: {
12 | width: '100%',
13 | height: 120,
14 | resizeMode: 'cover',
15 | borderRadius: 10,
16 | marginTop: 32,
17 | },
18 |
19 | pointName: {
20 | color: '#322153',
21 | fontSize: 28,
22 | fontFamily: 'Ubuntu_700Bold',
23 | marginTop: 24,
24 | },
25 |
26 | pointItems: {
27 | fontFamily: 'Roboto_400Regular',
28 | fontSize: 16,
29 | lineHeight: 24,
30 | marginTop: 8,
31 | color: '#6C6C80'
32 | },
33 |
34 | address: {
35 | marginTop: 32,
36 | },
37 |
38 | addressTitle: {
39 | color: '#322153',
40 | fontFamily: 'Roboto_500Medium',
41 | fontSize: 16,
42 | },
43 |
44 | addressContent: {
45 | fontFamily: 'Roboto_400Regular',
46 | lineHeight: 24,
47 | marginTop: 8,
48 | color: '#6C6C80'
49 | },
50 |
51 | footer: {
52 | borderTopWidth: StyleSheet.hairlineWidth,
53 | borderColor: '#999',
54 | paddingVertical: 20,
55 | paddingHorizontal: 32,
56 | flexDirection: 'row',
57 | justifyContent: 'space-between'
58 | },
59 |
60 | button: {
61 | width: '48%',
62 | backgroundColor: '#34CB79',
63 | borderRadius: 10,
64 | height: 50,
65 | flexDirection: 'row',
66 | justifyContent: 'center',
67 | alignItems: 'center'
68 | },
69 |
70 | buttonText: {
71 | marginLeft: 8,
72 | color: '#FFF',
73 | fontSize: 16,
74 | fontFamily: 'Roboto_500Medium',
75 | },
76 | });
77 |
78 | export default styles
--------------------------------------------------------------------------------
/mobile/src/pages/Home/styles.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native'
2 |
3 | const styles = StyleSheet.create({
4 | container: {
5 | flex: 1,
6 | padding: 32,
7 | },
8 |
9 | main: {
10 | flex: 1,
11 | justifyContent: 'center',
12 | },
13 |
14 | title: {
15 | color: '#322153',
16 | fontSize: 32,
17 | fontFamily: 'Ubuntu_700Bold',
18 | maxWidth: 260,
19 | marginTop: 64,
20 | },
21 |
22 | description: {
23 | color: '#6C6C80',
24 | fontSize: 16,
25 | marginTop: 16,
26 | fontFamily: 'Roboto_400Regular',
27 | maxWidth: 260,
28 | lineHeight: 24,
29 | },
30 |
31 | footer: {},
32 |
33 | select: {},
34 |
35 | input: {
36 | height: 60,
37 | backgroundColor: '#FFF',
38 | borderRadius: 10,
39 | marginBottom: 8,
40 | paddingHorizontal: 24,
41 | fontSize: 16,
42 | },
43 |
44 | button: {
45 | backgroundColor: '#34CB79',
46 | height: 60,
47 | flexDirection: 'row',
48 | borderRadius: 10,
49 | overflow: 'hidden',
50 | alignItems: 'center',
51 | marginTop: 8,
52 | },
53 |
54 | buttonIcon: {
55 | height: 60,
56 | width: 60,
57 | backgroundColor: 'rgba(0, 0, 0, 0.1)',
58 | justifyContent: 'center',
59 | alignItems: 'center'
60 | },
61 |
62 | buttonText: {
63 | flex: 1,
64 | justifyContent: 'center',
65 | textAlign: 'center',
66 | color: '#FFF',
67 | fontFamily: 'Roboto_500Medium',
68 | fontSize: 16,
69 | }
70 | });
71 |
72 | export default styles;
--------------------------------------------------------------------------------
/mobile/src/pages/Points/style.ts:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from "react-native";
2 | import Constants from "expo-constants";
3 |
4 | const styles = StyleSheet.create({
5 | container: {
6 | flex: 1,
7 | paddingHorizontal: 32,
8 | paddingTop: 20 + Constants.statusBarHeight,
9 | },
10 |
11 | title: {
12 | fontSize: 20,
13 | fontFamily: 'Ubuntu_700Bold',
14 | marginTop: 24,
15 | },
16 |
17 | description: {
18 | color: '#6C6C80',
19 | fontSize: 16,
20 | marginTop: 4,
21 | fontFamily: 'Roboto_400Regular',
22 | },
23 |
24 | mapContainer: {
25 | flex: 1,
26 | width: '100%',
27 | borderRadius: 10,
28 | overflow: 'hidden',
29 | marginTop: 16,
30 | },
31 |
32 | map: {
33 | width: '100%',
34 | height: '100%',
35 | },
36 |
37 | mapMarker: {
38 | width: 90,
39 | height: 80,
40 | },
41 |
42 | mapMarkerContainer: {
43 | width: 90,
44 | height: 70,
45 | backgroundColor: '#34CB79',
46 | flexDirection: 'column',
47 | borderRadius: 8,
48 | overflow: 'hidden',
49 | alignItems: 'center'
50 | },
51 |
52 | mapMarkerImage: {
53 | width: 90,
54 | height: 45,
55 | resizeMode: 'cover',
56 | },
57 |
58 | mapMarkerTitle: {
59 | flex: 1,
60 | fontFamily: 'Roboto_400Regular',
61 | color: '#FFF',
62 | fontSize: 13,
63 | lineHeight: 23,
64 | },
65 |
66 | itemsContainer: {
67 | flexDirection: 'row',
68 | marginTop: 16,
69 | marginBottom: 32,
70 | },
71 |
72 | item: {
73 | backgroundColor: '#fff',
74 | borderWidth: 2,
75 | borderColor: '#eee',
76 | height: 120,
77 | width: 120,
78 | borderRadius: 8,
79 | paddingHorizontal: 16,
80 | paddingTop: 20,
81 | paddingBottom: 16,
82 | marginRight: 8,
83 | alignItems: 'center',
84 | justifyContent: 'space-between',
85 |
86 | textAlign: 'center',
87 | },
88 |
89 | selectedItem: {
90 | borderColor: '#34CB79',
91 | borderWidth: 2,
92 | },
93 |
94 | itemTitle: {
95 | fontFamily: 'Roboto_400Regular',
96 | textAlign: 'center',
97 | fontSize: 13,
98 | },
99 | });
100 |
101 | export default styles
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `yarn start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `yarn test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `yarn build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `yarn eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
--------------------------------------------------------------------------------
/frontend/src/pages/Home/style.css:
--------------------------------------------------------------------------------
1 | #page-home {
2 | height: 100vh;
3 |
4 | background: url("../../assets/home-background.svg") no-repeat 800px bottom;
5 | }
6 |
7 |
8 | #page-home header {
9 | margin-top: 48px;
10 | width: 100%;
11 | display: flex;
12 | justify-content: space-between;
13 | align-items: center;
14 | }
15 |
16 | #page-home header a {
17 | color: var(--title-color);
18 | font-weight: bold;
19 | text-decoration: none;
20 | display: flex;
21 | align-items: center;
22 | }
23 |
24 | #page-home header a svg {
25 | margin-right: 16px;
26 | margin-top: 5px;
27 | color: var(--primary-color);
28 | }
29 |
30 | #page-home .content {
31 | width: 100%;
32 | height: 100%;
33 | max-width: 1100px;
34 | margin: 0 auto;
35 | padding: 0 30px;
36 |
37 | display: flex;
38 | flex-direction: column;
39 | align-items: flex-start;
40 | }
41 |
42 | #page-home .content header {
43 | margin: 48px 0 0;
44 | }
45 |
46 | #page-home .content main {
47 | flex: 1;
48 | max-width: 560px;
49 |
50 | display: flex;
51 | flex-direction: column;
52 | justify-content: center;
53 | }
54 |
55 | #page-home .content main h1 {
56 | font-size: 54px;
57 | color: var(--title-color);
58 | }
59 |
60 | #page-home .content main p {
61 | font-size: 24px;
62 | margin-top: 24px;
63 | line-height: 38px;
64 | }
65 |
66 | #page-home .content main a {
67 | width: 100%;
68 | max-width: 360px;
69 | height: 72px;
70 | background: var(--primary-color);
71 | border-radius: 8px;
72 | text-decoration: none;
73 |
74 | display: flex;
75 | align-items: center;
76 | overflow: hidden;
77 |
78 | margin-top: 40px;
79 | }
80 |
81 | #page-home .content main a span {
82 | display: block;
83 | background: rgba(0, 0, 0, 0.08);
84 | width: 72px;
85 | height: 72px;
86 |
87 | display: flex;
88 | align-items: center;
89 | justify-content: center;
90 | transition: background-color 0.2s;
91 | }
92 |
93 | #page-home .content main a span svg {
94 | color: #fff;
95 | width: 20px;
96 | height: 20px;
97 | }
98 |
99 | #page-home .content main a strong {
100 | flex: 1;
101 | text-align: center;
102 | color: #fff;
103 | }
104 |
105 | #page-home .content main a:hover {
106 | background: #2fb86e;
107 | }
108 |
109 | @media (max-width: 900px) {
110 | #page-home .content {
111 | align-items: center;
112 | text-align: center;
113 | }
114 |
115 | #page-home .content header {
116 | margin: 48px auto 0;
117 | }
118 |
119 | #page-home .content main {
120 | align-items: center;
121 | }
122 |
123 | #page-home .content main h1 {
124 | font-size: 42px;
125 | }
126 |
127 | #page-home .content main p {
128 | font-size: 24px;
129 | }
130 | }
--------------------------------------------------------------------------------
/mobile/src/pages/Home/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useCallback, useEffect } from "react"
2 | import { View, Image, Text, ImageBackground } from "react-native";
3 | import { Feather as Icon } from "@expo/vector-icons"
4 | import { RectButton } from "react-native-gesture-handler";
5 | import RNPickerSelect, { PickerStyle } from 'react-native-picker-select';
6 |
7 | import styles from "./styles";
8 | import { useNavigation } from "@react-navigation/native";
9 |
10 | interface UF {
11 | sigla: string;
12 | }
13 |
14 | interface City {
15 | nome: string
16 | }
17 |
18 | const Home = () => {
19 | const navigation = useNavigation();
20 | const [ufs, setUFs] = useState([]);
21 | const [cities, setCities] = useState([]);
22 | const [params, setParams] = useState<{
23 | city: string,
24 | uf: string
25 | }>({ city: "", uf: "" });
26 |
27 | const getUFS = useCallback(
28 | async () => {
29 | const res = await fetch(`https://servicodados.ibge.gov.br/api/v1/localidades/estados?orderBy=nome`);
30 | setUFs(await res.json());
31 | }, [])
32 |
33 | const getCities = async () => {
34 | if (params.uf) {
35 | const res = await fetch(`https://servicodados.ibge.gov.br/api/v1/localidades/estados/${params.uf}/municipios`)
36 | setCities(await res.json());
37 | }
38 | }
39 |
40 | useEffect(() => {
41 | getCities()
42 | }, [params.uf])
43 |
44 | useEffect(() => {
45 | getUFS()
46 | }, [])
47 |
48 | return
54 |
55 |
58 |
59 | Seu marketplace de coleta de resíduos
60 |
61 |
62 | Ajudamos pessoas a encontrarem pontos de coleta de forma eficiente
63 |
64 |
65 |
66 | setParams({ uf: value, city: "" })}
77 | items={ufs.map(((uf: UF) =>
78 | ({ label: uf.sigla, value: uf.sigla }))
79 | )}
80 | />
81 | setParams({ ...params, city: value })}
84 | items={cities.map(((city: City) =>
85 | ({ label: city.nome, value: city.nome }))
86 | )}
87 | />
88 | navigation.navigate("points", params)}>
89 |
90 |
91 |
92 |
93 |
94 |
95 | Entrar
96 |
97 |
98 |
99 |
100 | }
101 |
102 | export default Home;
--------------------------------------------------------------------------------
/backend/src/controller/PointsController.ts:
--------------------------------------------------------------------------------
1 | import knex from "../database";
2 | import { Controller } from ".";
3 | import { Request, Response } from 'express';
4 | import { QueryBuilder } from "knex";
5 |
6 | class PointsControlller implements Controller {
7 | async index(req: Request, res: Response) {
8 | const { uf, city, items } = req.query;
9 | let points = [];
10 | const parsedItems = items ? String(items).split(",").map(item => Number(item.trim())) : [];
11 | points = await knex("points")
12 | .join("point_items", "points.id", "=", "point_items.point_id")
13 | .modify((qb: QueryBuilder) => {
14 | if (city)
15 | qb.where("city", String(city))
16 | if (uf)
17 | qb.where("uf", String(uf))
18 | if (parsedItems.length > 0)
19 | qb.whereIn("point_items.item_id", parsedItems)
20 | })
21 | .distinct()
22 | .select("points.*");
23 |
24 | const seriazedPoints = points.map(
25 | (point: Point) =>
26 | ({
27 | ...point, image: point.image.startsWith("http")
28 | ? point.image : `${process.env.BASE_URL}:${
29 | process.env.PORT}/uploads/${point.image}`
30 | })
31 | )
32 |
33 | return res.json(seriazedPoints);
34 | }
35 | async show(req: Request, res: Response) {
36 | const { id } = req.params;
37 | const point = await knex("points")
38 | .where("id", id).select("*").first();
39 | if (!point) return res.status(404)
40 | .json({ message: "Point not found" })
41 |
42 | const items = await knex("items")
43 | .join("point_items", "point_items.item_id", "=", "items.id")
44 | .where("point_items.point_id", "=", id)
45 | .select("items.title");
46 |
47 |
48 | return res.json(Object.assign({
49 | ...point,
50 | image: `${process.env.BASE_URL}:${
51 | process.env.PORT}/uploads/${point.image}`
52 | }, { items }));
53 | }
54 | async create(req: Request, res: Response) {
55 | const {
56 | name,
57 | image,
58 | email,
59 | whatsapp,
60 | city,
61 | uf,
62 | latitude,
63 | longitude,
64 | items
65 | } = req.body;
66 |
67 | const point = {
68 | name,
69 | image: req.file.filename || 'https://images.unsplash.com/photo-1542838132-92c53300491e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60',
70 | email,
71 | whatsapp,
72 | city,
73 | uf,
74 | latitude,
75 | longitude
76 | }
77 |
78 | const trx = await knex.transaction();
79 | const [id] = await trx("points").insert(point)
80 |
81 | const pointItems: PointItems[] = items.split(",")
82 | .map((item_id: string) =>
83 | ({ item_id: Number(item_id.trim()), point_id: id })
84 | )
85 | await trx("point_items").insert(pointItems);
86 | await trx.commit();
87 |
88 | return res.status(201).json({
89 | sucess: true
90 | });
91 | }
92 | }
93 |
94 | export default PointsControlller;
95 |
--------------------------------------------------------------------------------
/mobile/src/pages/Detail/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useCallback, useEffect, useState } from 'react';
2 |
3 | import { View, TouchableOpacity, Image, Text, SafeAreaView, Linking } from 'react-native'
4 | import { Feather as Icon, FontAwesome as Fa } from "@expo/vector-icons";
5 | import { useNavigation, useRoute } from '@react-navigation/native';
6 | import { RectButton } from 'react-native-gesture-handler';
7 | import * as MailComposer from "expo-mail-composer";
8 | import styles from "./styles";
9 |
10 |
11 | interface Params {
12 | id: number;
13 | }
14 |
15 | interface Item {
16 | title: string;
17 | }
18 |
19 | interface Point {
20 | name: string;
21 | whatsapp: string;
22 | image: string;
23 | email: string;
24 | city: string;
25 | uf: string;
26 | items: Item[]
27 | }
28 |
29 | export default function Detail() {
30 | const navigation = useNavigation()
31 | const route = useRoute();
32 | const [point, setPoint] = useState();
33 |
34 | const getPoint = useCallback(
35 | async () => {
36 | const params = route.params as Params;
37 | const res = await fetch(`http://192.168.1.3:3333/points/${params.id}`)
38 | setPoint(await res.json())
39 | }, [])
40 |
41 | const sendEmail = useCallback(() => {
42 | MailComposer.composeAsync({
43 | recipients: [point?.email || ""],
44 | subject: "Interesse em coleta de resíduos"
45 | })
46 | }, []);
47 |
48 | const sendWhatsAppMessage = useCallback(
49 | () => {
50 | Linking.openURL(`whatsapp://send?phone=${point?.whatsapp}&text=Tenho interesse em tornar meu estabelecimento um ponto de coleta de resíduos`)
51 | }, [])
52 |
53 | useEffect(() => {
54 | getPoint();
55 | }, [])
56 |
57 | return (
58 |
59 | {point &&
60 | <>
61 |
62 | navigation.goBack()}>
63 |
64 |
65 |
66 |
67 | {point.name}
68 |
69 |
70 | {point.items.map(item => item.title).join(", ")}
71 |
72 |
73 |
74 | Endereço
75 |
76 |
79 | {point.city}, {point.uf}
80 |
81 |
82 |
83 |
84 |
85 |
86 | WhatsApp
87 |
88 |
89 |
90 | E-mail
91 |
92 |
93 | >}
94 |
95 | )
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | :construction: Next Level Week 🚀 In progress.. :construction:
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | Next Level Week |
25 | Project |
26 | Technologies |
27 | Layout |
28 | How to use |
29 | How to contribute |
30 | License
31 |
32 |
33 | ## :information_source: What's Next Level Week?
34 |
35 | NLW is a practical week with lots of code, challenges, networking and a single objective: to take you to the next level.
36 | Through our method you will learn new tools, learn about new technologies and discover hacks that will boost your career.
37 | An online and completely free event that will help you take the next step in your evolution as a dev.
38 |
39 | ## 💻 Project
40 |
41 | Ecoleta is a project developed based on international environment week.
42 | That aims to connect people to companies that collect specific waste such as light bulbs, batteries, cooking oil, etc.
43 |
44 | Example
45 |
46 | ## :rocket: Technologies
47 |
48 | This project was developed with the following technologies:
49 |
50 | - [Node.js][nodejs]
51 | - [TypeScript][typescript]
52 | - [React][reactjs]
53 | - [React Native][rn]
54 | - [Expo][expo]
55 |
56 | ## 🔖 Layout
57 |
58 | To access the layout use [Figma](https://www.figma.com/file/1SxgOMojOB2zYT0Mdk28lB/).
59 |
60 | ## :information_source: How To Use
61 |
62 | To clone and run this application, you'll need [Git](https://git-scm.com), [Node.js][nodejs] + [Yarn][yarn] installed on your computer.
63 |
64 | From your command line:
65 |
66 | ### Install API In progress.. :construction:
67 | ```bash
68 | # Clone this repository
69 | $ git clone https://github.com/reisdev/next-level-week
70 |
71 | # Go into the repository
72 | $ cd next-level-week/backend
73 |
74 | # Install dependencies
75 | $ yarn install
76 | ```
77 |
78 | ## 🤔 How to contribute
79 |
80 | - Make a fork;
81 | - Create a branck with your feature: `git checkout -b my-feature`;
82 | - Commit changes: `git commit -m 'feat: My new feature'`;
83 | - Make a push to your branch: `git push origin my-feature`.
84 |
85 | After merging your receipt request to done, you can delete a branch from yours.
86 |
87 | ## :memo: License
88 |
89 | This project is under the MIT license. See the [LICENSE](LICENSE.md) for details.
90 |
91 | Made with ♥ by Matheus Reis :wave: [Get in touch!](https://www.linkedin.com/in/matheus-dos-reis-de-jesus-40a59570/)
92 |
93 | [nodejs]: https://nodejs.org/
94 | [typescript]: https://www.typescriptlang.org/
95 | [expo]: https://expo.io/
96 | [reactjs]: https://reactjs.org
97 | [rn]: https://facebook.github.io/react-native/
98 | [yarn]: https://yarnpkg.com/
99 | [vs]: https://code.visualstudio.com/
100 | [vceditconfig]: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
101 | [vceslint]: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
102 | [prettier]: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
103 |
104 | ## Credits
105 |
106 | Credits for the README template goes to [DanielObara](https://github.com/DanielObara)
--------------------------------------------------------------------------------
/frontend/src/pages/CreatePoint/style.css:
--------------------------------------------------------------------------------
1 | #page-create-point {
2 | width: 100%;
3 | max-width: 1100px;
4 |
5 | margin: 0 auto;
6 | }
7 |
8 | #page-create-point header {
9 | margin-top: 48px;
10 |
11 | display: flex;
12 | justify-content: space-between;
13 | align-items: center;
14 | }
15 |
16 | #page-create-point header a {
17 | color: var(--title-color);
18 | font-weight: bold;
19 | text-decoration: none;
20 |
21 | display: flex;
22 | align-items: center;
23 | }
24 |
25 | #page-create-point header a svg {
26 | margin-right: 16px;
27 | color: var(--primary-color);
28 | }
29 |
30 | #page-create-point form {
31 | margin: 80px auto;
32 | padding: 64px;
33 | max-width: 730px;
34 | background: #FFF;
35 | border-radius: 8px;
36 |
37 | display: flex;
38 | flex-direction: column;
39 | }
40 |
41 | #page-create-point form h1 {
42 | font-size: 36px;
43 | }
44 |
45 | #page-create-point form fieldset {
46 | margin-top: 64px;
47 | min-inline-size: auto;
48 | border: 0;
49 | }
50 |
51 | #page-create-point form legend {
52 | width: 100%;
53 | display: flex;
54 | justify-content: space-between;
55 | align-items: center;
56 | margin-bottom: 40px;
57 | }
58 |
59 | #page-create-point form legend h2 {
60 | font-size: 24px;
61 | }
62 |
63 | #page-create-point form legend span {
64 | font-size: 14px;
65 | font-weight: normal;
66 | color: var(--text-color);
67 | }
68 |
69 | #page-create-point form .field-group {
70 | flex: 1;
71 | display: flex;
72 | }
73 |
74 | #page-create-point form .field {
75 | flex: 1;
76 |
77 | display: flex;
78 | flex-direction: column;
79 | margin-bottom: 24px;
80 | }
81 |
82 | #page-create-point form .field input[type=text],
83 | #page-create-point form .field input[type=email],
84 | #page-create-point form .field input[type=number] {
85 | flex: 1;
86 | background: #F0F0F5;
87 | border-radius: 8px;
88 | border: 0;
89 | padding: 16px 24px;
90 | font-size: 16px;
91 | color: #6C6C80;
92 | }
93 |
94 | #page-create-point form .field select {
95 | -webkit-appearance: none;
96 | -moz-appearance: none;
97 | appearance: none;
98 | flex: 1;
99 | background: #F0F0F5;
100 | border-radius: 8px;
101 | border: 0;
102 | padding: 16px 24px;
103 | font-size: 16px;
104 | color: #6C6C80;
105 | }
106 |
107 | #page-create-point form .field input::placeholder {
108 | color: #A0A0B2;
109 | }
110 |
111 | #page-create-point form .field label {
112 | font-size: 14px;
113 | margin-bottom: 8px;
114 | }
115 |
116 | #page-create-point form .field :disabled {
117 | cursor: not-allowed;
118 | }
119 |
120 | #page-create-point form .field-group .field+.field {
121 | margin-left: 24px;
122 | }
123 |
124 | #page-create-point form .field-group input+input {
125 | margin-left: 24px;
126 | }
127 |
128 | #page-create-point form .field-check {
129 | flex-direction: row;
130 | align-items: center;
131 | }
132 |
133 | #page-create-point form .field-check input[type=checkbox] {
134 | background: #F0F0F5;
135 | }
136 |
137 | #page-create-point form .field-check label {
138 | margin: 0 0 0 8px;
139 | }
140 |
141 | #page-create-point form .leaflet-container {
142 | width: 100%;
143 | height: 350px;
144 | border-radius: 8px;
145 | margin-bottom: 24px;
146 | }
147 |
148 | #page-create-point form button {
149 | width: 260px;
150 | height: 56px;
151 | background: var(--primary-color);
152 | border-radius: 8px;
153 | color: #FFF;
154 | font-weight: bold;
155 | font-size: 16px;
156 | border: 0;
157 | align-self: flex-end;
158 | margin-top: 40px;
159 | transition: background-color 0.2s;
160 | cursor: pointer;
161 | }
162 |
163 | #page-create-point form button:hover {
164 | background: #2FB86E;
165 | }
166 |
167 | #page-create-point form button:disabled {
168 | border: solid 1px rgb(65, 155, 107);
169 | background-color: transparent;
170 | color: rgb(65, 155, 107);
171 | cursor: not-allowed;
172 | }
173 |
174 | .items-grid {
175 | display: grid;
176 | grid-template-columns: repeat(3, 1fr);
177 | gap: 16px;
178 | list-style: none;
179 | }
180 |
181 | .items-grid li {
182 | background: #f5f5f5;
183 | border: 2px solid #f5f5f5;
184 | height: 180px;
185 | border-radius: 8px;
186 | padding: 32px 24px 16px;
187 |
188 | display: flex;
189 | flex-direction: column;
190 | justify-content: space-between;
191 | align-items: center;
192 |
193 | text-align: center;
194 |
195 | cursor: pointer;
196 | }
197 |
198 | .items-grid li span {
199 | flex: 1;
200 | margin-top: 12px;
201 |
202 | display: flex;
203 | align-items: center;
204 | color: var(--title-color)
205 | }
206 |
207 | .items-grid li.selected {
208 | background: #E1FAEC;
209 | border: 2px solid #34CB79;
210 | }
--------------------------------------------------------------------------------
/backend/static/lampadas.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/backend/static/eletronicos.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/backend/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */
4 |
5 | /* Basic Options */
6 | // "incremental": true, /* Enable incremental compilation */
7 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9 | // "lib": [], /* Specify library files to be included in the compilation. */
10 | // "allowJs": true, /* Allow javascript files to be compiled. */
11 | // "checkJs": true, /* Report errors in .js files. */
12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */
14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15 | // "sourceMap": true, /* Generates corresponding '.map' file. */
16 | // "outFile": "./", /* Concatenate and emit output to single file. */
17 | // "outDir": "./", /* Redirect output structure to the directory. */
18 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19 | // "composite": true, /* Enable project compilation */
20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21 | // "removeComments": true, /* Do not emit comments to output. */
22 | // "noEmit": true, /* Do not emit outputs. */
23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26 |
27 | /* Strict Type-Checking Options */
28 | "strict": true, /* Enable all strict type-checking options. */
29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30 | // "strictNullChecks": true, /* Enable strict null checks. */
31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36 |
37 | /* Additional Checks */
38 | // "noUnusedLocals": true, /* Report errors on unused locals. */
39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */
40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42 |
43 | /* Module Resolution Options */
44 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48 | // "typeRoots": [], /* List of folders to include type definitions from. */
49 | // "types": [], /* Type declaration files to be included in compilation. */
50 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54 |
55 | /* Source Map Options */
56 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60 |
61 | /* Experimental Options */
62 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64 |
65 | /* Advanced Options */
66 | "skipLibCheck": true, /* Skip type checking of declaration files. */
67 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/mobile/src/pages/Points/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect, useCallback } from 'react'
2 |
3 | import styles from "./style";
4 | import { View, Text, Image, Alert, } from 'react-native';
5 | import { Feather as Icon } from "@expo/vector-icons";
6 | import { TouchableOpacity, ScrollView } from 'react-native-gesture-handler';
7 | import { useNavigation, useRoute } from '@react-navigation/native';
8 | import MapView, { Marker } from 'react-native-maps'
9 | import * as Location from "expo-location";
10 | import { SvgUri } from "react-native-svg";
11 |
12 | interface Item {
13 | id: number;
14 | title: string;
15 | imageUrl: string;
16 | }
17 |
18 | interface Point {
19 | id: number;
20 | name: string;
21 | image: string;
22 | latitude: number;
23 | longitude: number;
24 | }
25 |
26 | interface Params {
27 | uf: string;
28 | city: string;
29 | }
30 |
31 | export default function Points() {
32 | const navigation = useNavigation()
33 | const route = useRoute();
34 | const [items, setItems] = useState- ([])
35 | const [selectedItems, setSelectedItems] = useState
([])
36 | const [points, setPoints] = useState([])
37 | const [initialPosition, setInitialPosition] = useState<{
38 | latitude: number, longitude: number
39 | }>({ latitude: 0, longitude: 0 })
40 |
41 | const handleItemSelect = (id: number) => {
42 | const index = selectedItems.indexOf(id);
43 | if (index >= 0) setSelectedItems(selectedItems.filter(item => item != id))
44 | else setSelectedItems([...selectedItems, id])
45 | }
46 |
47 | const loadPosition = useCallback(async () => {
48 | const { status } = await Location.requestPermissionsAsync();
49 | if (status !== "granted") {
50 | Alert.alert("Ops! Precisamos da sua permissão para obter a localização");
51 | return;
52 | }
53 | const location = await Location.getCurrentPositionAsync();
54 | const { latitude, longitude } = location.coords;
55 | setInitialPosition({ latitude, longitude });
56 | }, [])
57 |
58 | const getItems = useCallback(
59 | async () => {
60 | const res = await fetch(`http://192.168.1.3:3333/items`)
61 | setItems(await res.json());
62 | }, [])
63 |
64 | const getPoints = useCallback(
65 | async () => {
66 | const params = route.params ? (route.params as Params) : null;
67 | const res = await fetch(`http://192.168.1.3:3333/points${selectedItems.length > 0 ? `?items=${selectedItems.join(",")}&` : "?"}${params ? params.city ? `city=${params.city}&` : "" : ""}${params ? params.uf ? `uf=${params.uf}` : "" : ""}`)
68 | setPoints(await res.json());
69 | }, [selectedItems, route.params]
70 | )
71 |
72 | useEffect(() => {
73 | getPoints()
74 | }, [selectedItems])
75 |
76 | useEffect(() => {
77 | getItems();
78 | getPoints();
79 | loadPosition();
80 | }, []);
81 |
82 | return (
83 | <>
84 |
85 | navigation.goBack()}>
86 |
87 |
88 |
89 | Boas Vindas
90 |
91 |
92 | Encontre no mapa um ponto de coleta
93 |
94 |
95 | {initialPosition.latitude !== 0 &&
96 |
104 | {points.map((point: Point) =>
105 | navigation.navigate("detail", { id: point.id })}
112 | key={point.id}
113 | >
114 |
117 |
121 |
124 | {point.name}
125 |
126 |
127 |
128 | )}
129 | }
130 |
131 |
132 |
133 |
140 | {items.map((item: Item) =>
141 | handleItemSelect(item.id)}
148 | key={item.id}>
149 |
153 | {item.title}
154 |
155 | )}
156 |
157 |
158 | >
159 | )
160 | }
161 |
--------------------------------------------------------------------------------
/backend/static/oleo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/frontend/src/pages/CreatePoint/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect, useCallback, ChangeEvent, FormEvent, useMemo } from 'react';
2 |
3 | import logo from "../../assets/logo.svg"
4 | import "./style.css"
5 | import { Link, useHistory } from 'react-router-dom';
6 | import { FiArrowLeft } from "react-icons/fi"
7 | import MapComponent from '../../components/Map';
8 | import Dropzone from '../../components/Dropzone';
9 | import Success from '../../components/Success';
10 |
11 | interface Item {
12 | id: number
13 | title: string;
14 | imageUrl: string;
15 | }
16 |
17 | interface UF {
18 | initials: string;
19 | }
20 |
21 | const CreatePoint = () => {
22 | const history = useHistory();
23 | const [status, setStatus] = useState('');
24 | const [items, setItems] = useState- ([]);
25 | const [selectedUF, setSelectedUF] = useState("0");
26 | const [selectedCity, setSelectedCity] = useState("0");
27 | const [selectedItems, setSelectedItems] = useState
([]);
28 | const [selectedFile, setSelectedFile] = useState();
29 | const [ufs, setUFs] = useState([]);
30 | const [cities, setCities] = useState([]);
31 | const [formData, setFormData] = useState({
32 | name: "",
33 | email: "",
34 | whatsapp: ""
35 | })
36 | const [position, setPosition] = useState<{ latitude: number, longitude: number }>({
37 | latitude: 0,
38 | longitude: 0
39 | });
40 |
41 | const getItems = async () => {
42 | const res = await fetch(`${process.env.REACT_APP_API_URL}/items`);
43 | setItems(await res.json());
44 |
45 | const res2 = await fetch(`https://servicodados.ibge.gov.br/api/v1/localidades/estados?orderBy=nome`);
46 | setUFs((await res2.json()).map((uf: any) => uf.sigla));
47 | }
48 |
49 | const createPoint = async (e: FormEvent) => {
50 | e.preventDefault()
51 | const payload = new FormData();
52 |
53 | payload.append("name", formData.name);
54 | payload.append("email", formData.email);
55 | payload.append("whatsapp", formData.whatsapp);
56 | payload.append("city", selectedCity);
57 | payload.append("uf", selectedUF);
58 | payload.append("items", selectedItems.join(","));
59 | payload.append("latitude", position.latitude.toString());
60 | payload.append("longitude", position.longitude.toString());
61 | if (selectedFile) payload.append("image", selectedFile)
62 |
63 | const res = await fetch(`${process.env.REACT_APP_API_URL}/points`, {
64 | method: "POST",
65 | body: payload
66 | });
67 | if (await res.status !== 200) setStatus("failure")
68 | else setStatus("success")
69 | history.push("/");
70 | }
71 |
72 | const handleImage = (file: File) => setSelectedFile(file)
73 |
74 | const handleInputChange = (e: ChangeEvent) => {
75 | setFormData({
76 | ...formData,
77 | [e.target.name]: e.target.value
78 | })
79 | }
80 |
81 | const handleItemSelect = (id: number) => {
82 | const index = selectedItems.indexOf(id);
83 | if (index >= 0) setSelectedItems(selectedItems.filter(item => item != id))
84 | else setSelectedItems([...selectedItems, id])
85 | }
86 |
87 | const getCities = useCallback(async () => {
88 | const res = await fetch(`https://servicodados.ibge.gov.br/api/v1/localidades/estados/${selectedUF}/municipios`)
89 | setCities((await res.json()).map((city: any) => city.nome));
90 | }, [selectedUF]);
91 |
92 | const isFormValid = useMemo(() => {
93 | if (!selectedUF || !selectedCity ||
94 | Object.values(formData).every(field => !field)
95 | || selectedItems.length === 0) return false;
96 | return true
97 | }, [selectedItems, selectedUF, selectedCity, formData]);
98 |
99 | useEffect(() => {
100 | if (selectedUF !== '0') getCities();
101 | navigator.geolocation.getCurrentPosition((p) => {
102 | setPosition({
103 | latitude: p.coords.latitude,
104 | longitude: p.coords.longitude
105 | })
106 | })
107 | }, [selectedUF])
108 |
109 | useEffect(() => {
110 | getItems();
111 | }, [])
112 |
113 | return
114 | setStatus("")} />
115 |
116 |
117 |
118 |
119 | Voltar para a Home
120 |
121 |
122 |
232 |
233 | }
234 |
235 | export default CreatePoint;
236 |
--------------------------------------------------------------------------------
/frontend/src/assets/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/backend/static/organicos.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/frontend/src/assets/home-background.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------