From c176b3b77de659d16b6284612e4192eff8aff152 Mon Sep 17 00:00:00 2001 From: anggaalfiansah Date: Tue, 5 Oct 2021 10:22:30 +0700 Subject: [PATCH] add feature - random company --- src/contributor/index.js | 2 ++ src/contributor/random-company.js | 55 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/contributor/random-company.js diff --git a/src/contributor/index.js b/src/contributor/index.js index be3dfb4..f3f2b24 100644 --- a/src/contributor/index.js +++ b/src/contributor/index.js @@ -15,6 +15,7 @@ import RandomKanji from "./random-kanji"; import RandomPixelMonstersImage from "./random-pixel-monsters-image"; import RandomAiArtImage from "./random-ai-art"; import RandomQuotesApi from "./random-quote"; +import RandomCompany from "./random-company"; export const data_contributor = [ RandomFoxImage, @@ -34,4 +35,5 @@ export const data_contributor = [ RandomPixelMonstersImage, RandomAiArtImage, RandomQuotesApi, + RandomCompany, ]; diff --git a/src/contributor/random-company.js b/src/contributor/random-company.js new file mode 100644 index 0000000..9a259c2 --- /dev/null +++ b/src/contributor/random-company.js @@ -0,0 +1,55 @@ +import { useState, useEffect } from "react"; +import axios from "axios"; +// components +import { Card } from "../components"; +// baseurl api's +const BASE_URL = "https://random-data-api.com/api/company/random_company"; + +const RandomCompany = () => { + const [dispatching, setDispatching] = useState(false); + const [data, setData] = useState(); + + const getRandomCompany = async () => { + setDispatching(true); + const response = await axios.get(BASE_URL); + if (response.status !== 200) { + throw new Error("Fetching err"); + } + setData(response.data); + setDispatching(false); + }; + + useEffect(() => { + getRandomCompany(); + return () => { + setDispatching(false); + }; + }, []); + + return ( + + {dispatching ? ( +

Loading...

+ ) : data && ( +
+ techImage +
{data.business_name}
+
{data.bs_company_statement}
+
+
{data.full_address}
+
{data.phone_number}
+
+ )} +
+ ); +}; + +export default RandomCompany;