Alejandra Ferreira
Full-Stack Developer
Microbiologist MSc.
Co-founder Magenta Codes
@aleja_ferre
https://github.com/ferreiraalejandra/interview-test
Create a simple web interface using React which allows users to:
a) Search for countries and display its full country name, capital, population, and currency.
b) Enter an amount in SEK and get the amount converted into local currency for each country.
The data can amongst others be retrieved from the following open APIs:
Heading
Dropdown
Card
Input
and more...
import React from 'react';
import './styles.css';
const Header = () => {
return (
<div className="Header">
<h1>CURRENCY CONVERTER</h1>
</div>
)
}
export default HeaderHeading
Dropdown
Card
Input
import React, { useState } from "react";
import "./styles.css";
const Search = ({ onSelect }) => {
const [query, setQuery] = useState("");
const [matchedCountries, setMatchedCountries] = useState([]);
const searchCountry = async (event) => {
const newQuery = event.target.value;
setQuery(newQuery);
const request = await fetch(
"https://restcountries.eu/rest/v2/name/" + event.target.value
).catch((error) => console.log(error));
if (request.status !== 200) return null;
const response = await request.json();
setMatchedCountries(response);
const country = matchedCountries.find(
(matchedCountry) => matchedCountry.name === newQuery
);
if (country) onSelect(country);
};
return (
<div className="Search">
<label className="label">Country</label>
<input
className="Input"
onChange={searchCountry}
list="countries"
value={query}
/>
<datalist id="countries">
{matchedCountries.map((country) => (
<option key={country.name} value={country.name} />
))}
</datalist>
</div>
);
};
export default Search;
Check for:
Heading
Dropdown
Card
Input
import React from "react";
import "./styles.css";
const CountryCard = ({ country }) => {
if (!country) return null;
const {
name,
capital,
population,
currencies,
altSpellings
} = country;
return (
<div className="Card">
<div className="cardName">{name}</div>
<h2>{altSpellings[1]}</h2>
<table className="table-data">
<tr>
<td>Capital</td>
<td>{capital}</td>
</tr>
<tr>
<td>Population</td>
<td>{population.toLocaleString()}</td>
</tr>
<tr>
<td>Currency</td>
<td>{currencies[0].code}</td>
</tr>
</table>
</div>
);
};
export default CountryCard;
import React, { useEffect, useState } from "react";
import "./styles.css";
const CurrencyCard = ({ currencies, currency }) => {
const [amountFrom, setAmountFrom] = useState(1);
const [rate, setRate] = useState(1);
const [currencyTo, setCurrencyTo] = useState();
const [currencyQuery, setCurrencyQuery] = useState("");
const selectCurrency = (evt) => {
setCurrencyQuery(evt.target.value);
const selectedCurrency = currencies.find(
(curr) => curr.code === evt.target.value
);
if (selectedCurrency) setCurrencyTo(selectedCurrency);
};
useEffect(() => {
if (currency && currencyTo) {
const API_KEY = process.env.REACT_APP_FIXER_API_KEY
fetch(
`http://data.fixer.io/api/latest?access_key=${API_KEY}&symbols=${currency.code},${currencyTo.code}`
)
.then((response) => response.json())
.then((data) => {
const rate = data.rates[currencyTo.code] / data.rates[currency.code];
setRate(rate);
});
}
});REACT_APP_FIXER_API_KEY=a23b4b30e3e7195694d00d392e11bd5e:root {
--white: #FFFFFF;
--platinum: #E5E5E5;
--orange-web: #FCA311;
--oxford-blue: #14213D;
}
.Search {
width: 100%;
display: inline-block;
margin: 1rem;
}
.Header {
font-family: Arial, Helvetica, sans-serif;
color: var(--platinum);
}
.Card {
width: 80%;
height: 300px;
background-color: var(--platinum);
color: var(--oxford-blue);
border-radius: 10px;
padding: 2rem;
margin: 1rem;
justify-content: center;
}thehub.io
jooble.org
indeed.com
glassdoor.com
stackoverflow.com
https://slides.com/alejandraferreira/magenta-codes
@aleja_ferre
Ask me any questions, any advice, any suggestions