From e0f81e3c3ca496e793052540cd9292d090bf5134 Mon Sep 17 00:00:00 2001 From: pepper Date: Tue, 3 Nov 2020 16:27:58 +1100 Subject: [PATCH] This may be the last commit from this machine --- src/components/Migrations/Migrations.js | 72 +++++++++++---------- src/components/Migrations/SideMigrations.js | 34 ++++------ src/components/actions/requests.js | 25 ++++--- src/components/root/Home.js | 34 +++++++++- src/services/API.js | 7 ++ 5 files changed, 100 insertions(+), 72 deletions(-) create mode 100644 src/services/API.js diff --git a/src/components/Migrations/Migrations.js b/src/components/Migrations/Migrations.js index 38537c6..0b4c6cc 100644 --- a/src/components/Migrations/Migrations.js +++ b/src/components/Migrations/Migrations.js @@ -2,40 +2,41 @@ import React, { Component } from "react"; import axios from "axios"; import MigrationSingle from "./MigrationSingle"; +import { getMigrations } from "../actions/requests"; import Error from "../actions/Error"; class Migrations extends Component { - constructor(props) { - super(props); - this.state = { - migs: [], - migs1: [], - error: false, - }; - } - - componentDidMount() { - const url = `https://devapi.benjamyn.love/migrations/`; - - axios - .get(url) - .then((response) => { - this.setState({ - migs: response.data, - migs1: response.data.migration_status, - }); - }) - - .catch((error) => { - this.setState({ - error: true, - }); - }); - } + // constructor(props) { + // super(props); + // this.state = { + // migs: [], + // migs1: [], + // error: false, + // }; + // } + // + // componentDidMount() { + // const url = `https://devapi.benjamyn.love/migrations/`; + // + // axios + // .get(url) + // .then((response) => { + // this.setState({ + // migs: response.data, + // migs1: response.data.migration_status, + // }); + // }) + // + // .catch((error) => { + // this.setState({ + // error: true, + // }); + // }); + // } renderItems() { - if (!this.state.error) { - return this.state.migs.map((item) => ( + if (!this.props.error) { + return this.props.migs.map((item) => ( )); } else { @@ -44,17 +45,17 @@ class Migrations extends Component { } bookedMig() { - return this.state.migs.filter( + return this.props.migs.filter( (booked) => booked.migration_status === "Booked" ).length; } waitingMig() { - return this.state.migs.filter( + return this.props.migs.filter( (waiting) => waiting.migration_status === "Waiting Termination" ).length; } completedMig() { - return this.state.migs.filter( + return this.props.migs.filter( (complete) => complete.migration_status === "Completed" ).length; } @@ -66,7 +67,7 @@ class Migrations extends Component {
Booked Migrations -

{this.bookedMig()}

+ {this.bookedMig()}
View all... @@ -77,7 +78,8 @@ class Migrations extends Component {
Waiting Termination -

{this.waitingMig()}

+

+ {this.waitingMig()}
View all... @@ -89,7 +91,7 @@ class Migrations extends Component {
Completed -

{this.completedMig()}

+ {this.completedMig()}
View all... diff --git a/src/components/Migrations/SideMigrations.js b/src/components/Migrations/SideMigrations.js index 2440580..140159e 100644 --- a/src/components/Migrations/SideMigrations.js +++ b/src/components/Migrations/SideMigrations.js @@ -2,6 +2,7 @@ import React, { Component } from "react"; import axios from "axios"; import ReactTable from "react-table"; +import { callAPI } from "../../services/API"; import SingleSide from "./SingleSide"; import Error from "../actions/Error"; //import Table from "./Table"; @@ -14,30 +15,21 @@ class SideMigrations extends Component { e: false, }; } - async getMigrationData() { - const response = await axios.get( - "https://devapi.benjamyn.love/migrations/" - ); - this.setState({ - sidemigs: response.data, - e: false, - }); - } - componentDidMount() { - this.getMigrationData(); + callAPI + .get() + .then((request) => { + this.setState({ + sidemigs: request.data, + }); + }) + .catch((error) => { + this.setState({ + error: true, + }); + }); } - // renderItems() { - // if (!this.state.e) { - // return this.state.sidemigs.map((item) => ( - // - // )); - // } else { - // return ; - // } - // } - render() { const columns = [ { diff --git a/src/components/actions/requests.js b/src/components/actions/requests.js index 1177b0d..a58fa6e 100644 --- a/src/components/actions/requests.js +++ b/src/components/actions/requests.js @@ -1,19 +1,18 @@ -import axios from 'axios'; - -import Error from './Error'; +import axios from "axios"; const url = `https://devapi.benjamyn.love/migrations/`; export const getMigrations = () => (dispatch) => { - axios.get(url) + axios + .get(url) .then((response) => { - dispatch({ - migs: response.data, - }); - }) - .catch((error) => { - this.setState({ - error: true, - }); + dispatch({ + migs: response.data, }); - } + }) + .catch((error) => { + this.setState({ + error: true, + }); + }); +}; diff --git a/src/components/root/Home.js b/src/components/root/Home.js index 42052ff..b82b487 100644 --- a/src/components/root/Home.js +++ b/src/components/root/Home.js @@ -1,17 +1,45 @@ import React, { Component } from "react"; +import { getMigrations } from "../actions/requests"; +import { callAPI } from "../../services/API"; import Migrations from "../Migrations/Migrations"; +import Error from "../actions/Error"; import SideMigrations from "../Migrations/SideMigrations"; export class Home extends Component { + constructor(props) { + super(props); + this.state = { + migs: [], + error: false, + }; + } + + componentDidMount() { + callAPI + .get() + .then((request) => { + this.setState({ + migs: request.data, + }); + }) + .catch((error) => { + this.setState({ + error: true, + }); + }); + } render() { return (
- +
-

Side Migrations goes here

+

+ Side Migrations goes here + +

); @@ -21,4 +49,4 @@ export class Home extends Component { export default Home; // Broken -// +// diff --git a/src/services/API.js b/src/services/API.js new file mode 100644 index 0000000..281efb8 --- /dev/null +++ b/src/services/API.js @@ -0,0 +1,7 @@ +import axios from 'axios' + +export const callAPI = axios.create({ + baseURL: 'https://devapi.benjamyn.love/migrations/' +}) + +export default callAPI \ No newline at end of file