The objective of this project is to provide a front end example to consume I Soft Bet Bank API
It's a project bootstrapped with Create React App, which provides an out of the box React scaffolding structure to quickly set up a React app.
For time and details purposes, some of the official doc was replicated here, as it's already perfectly and thoroughly explained.
I used React for the FE for the following reasons:
- It's a new, up to date & popular library supported by Facebook
- Provides an easy way to structure a web project, allowing the developer think in components, each one as atomic or wide as desired
- Allows each component to be created independently, and communicate with other ones in a straightforward way
- As each component could be thought independently, tests are easier, as there are only one thing to test
- Easier to design a site thinking in separated pieces
Clone the repo and run npm install to install all the dependencies.
After having set all the project, run npm start or yarn start for start a local server in port 3000
After cloning, the project should look like this:
my-app/
README.md
node_modules/
package.json
public/
index.html
favicon.ico
src/
components/
Auth/
Login.jsx
Logout.jsx
NotFoundRoute.jsx
Home.jsx
Transaction.jsx
TransactionList.jsx
css/
util/
App.css
App.js
App.test.js
index.css
index.js
logo.svg
For the project to build, these files must exist with exact filenames:
public/index.htmlis the page template;src/index.jsis the JavaScript entry point.
You can delete or rename the other files.
You may create subdirectories inside src. For faster rebuilds, only files inside src are processed by Webpack.
You need to put any JS and CSS files inside src, otherwise Webpack won’t see them.
Only files inside public can be used from public/index.html.
Read instructions below for using assets from JavaScript and HTML.
You can, however, create more top-level directories.
They will not be included in the production build so you can use them for things like documentation.
The basic components for the project are the following:
Home.jsxIt provides the page for loading the transactions list. It performs the HTTP GET request for fetching all the data from the back end, and pass it to the transaction list component.TransactionList.jsxWraps the each transaction item, providing a context for themTransaction.jsxIt renders the single transactions, one item per transactionAuth\Login.jsxHandles the rendering and processing of the user authentication by performing a POST request to the back end for credentials.Auth\Logout.jsxDeletes the credentials from the local storage (Done like that for scoping purposes)Auth\NotFoundRoute.jsxDefault route
The project basically fetches all the transactions from the API, passing through the top Home component to TransactionList, which itself passes to a Transaction.
The flow is top down, no interaction from the user in this stage.
when accesing the page, the user is first asked for credentials, then, if valid, the API returns an access token which is saved in the local storage of the client in a hash table.
When performing any private operation, the system first checks that the access is present and if it is, allows the user to continue.
This is not the suitable way of doing in production, it was only did this way for timing and scoping constraints
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
This project setup uses Webpack for handling all assets. Webpack offers a custom way of “extending” the concept of import beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to import the CSS from the JavaScript file:
.Button {
padding: 20px;
}import React, { Component } from 'react';
import './Button.css'; // Tell Webpack that Button.js uses these styles
class Button extends Component {
render() {
// You can use them as regular CSS styles
return <div className="Button" />;
}
}This project setup minifies your CSS and adds vendor prefixes to it automatically through Autoprefixer so you don’t need to worry about it.
For example, this:
.App {
display: flex;
flex-direction: row;
align-items: center;
}becomes this:
.App {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}If you need to disable autoprefixing for some reason, follow this section.
You don’t have to use React Bootstrap together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps:
Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well:
npm install --save react-bootstrap bootstrap@3Alternatively you may use yarn:
yarn add react-bootstrap bootstrap@3Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your src/index.js file:
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
// Put any other imports below so that CSS from your
// components takes precedence over default styles.Import required React Bootstrap components within src/App.js file or your custom component files:
import { Navbar, Jumbotron, Button } from 'react-bootstrap';Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example App.js redone using React Bootstrap.
Test were included as a way to show how to primarily test some components.
Tests could be as detailed as possible, and for scoping reasons, only 2 simple tests were provided.
- Transaction.test.js
- TransactionList.test.js
Both tests the correct render of the component, via a describe and it statements.
Basically they render the component with mock data and checks that the elements were rendered correctly both in lenght and type.
For running the test execute yarn test