Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sample get random company profile #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/contributor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import RandomAnswerImage from "./random-answer-image";
import RandomDogImage from './random-dog-image';
import RandomMemeImage from "./random-meme-image";
import RandomUserProfile from './random-user-profile';
import RandomCompany from "./random-company";

export const data_contributor = [
RandomFoxImage,
Expand All @@ -24,4 +25,5 @@ export const data_contributor = [
RandomAnswerImage,
RandomDogImage,
RandomMemeImage,
RandomCompany,
];
51 changes: 51 additions & 0 deletions src/contributor/random-company.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useEffect, useState } from "react";
import axios from "axios";
import { Card } from "../components";

const BASE_URL = 'https://random-data-api.com/api/'

const RandomCompany = () => {
const [data, setData] = useState({ logo: '' });
const [loading, setLoading] = useState(false);

const get = async () => {
const { data } = await axios.get(`${BASE_URL}/company/random_company`);

data ? setLoading(false) : setLoading(true);
setData(data);
}

useEffect(() => {
get().finally();
return () => {
setLoading(false);
}
}, [])

return (
<Card
data={{
username: "Daniel",
avatar: "https://avatars.githubusercontent.com/u/28420302?v=4",
apiUrl: "https://random-data-api.com/api/",
apiName: "random-company",
apiDescription: "a random api for display random company",
}}
>
{
loading ? (
<p className="text-m my-3 text-center">Loading...</p>
) : (
<img
className="rounded-sm h-200 w-200 pt-2"
src={data?.logo}
alt="company-logo"
/>
)
}
</Card>
)
}


export default RandomCompany;