Skip to content

Commit

Permalink
Fix headers object y warning NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
hendaniel committed Sep 6, 2020
1 parent a3cf8eb commit ed11ec9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/components/Modals/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ button {
font-size: 0.9rem;
font-weight: 700;
border: none;
border-radius: 3px;
padding: 0.3rem 1rem;
margin-left: 0.5rem;
}
Expand Down
11 changes: 8 additions & 3 deletions src/components/Products/Product.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { UserContext } from "../../providers/index";
import { coin, buy } from "../../assets/index";
import { SuccessModal, FailureModal } from "../Modals/index";
import { useModal } from "../../hooks/index";
import { redeemProduct } from "../../services/productsService";
import "./products.scss";

const Product = ({
item: {
_id,
name,
category,
cost,
Expand All @@ -26,7 +28,10 @@ const Product = ({
const canBuy = cost <= points;

const openBuyModal = () => {
toggle();
redeemProduct(_id).then((res) => {
// toggle();
console.log(res);
});
};

return (
Expand Down Expand Up @@ -55,15 +60,15 @@ const Product = ({
) : (
<>
<div className="coins-left">
<span>You need: {cost - points}</span>
<span>You need: {cost - (points | 0)}</span>
<img src={coin} alt="coins left" />
</div>
<div
className="action-container"
style={{ backgroundColor: "#92a2a7da" }}
>
<div className="action">
<h3>{cost - points}</h3>
<h3>{cost - (points | 0)}</h3>
<img src={coin} alt="coin" />
<button>Get more coins</button>
</div>
Expand Down
13 changes: 6 additions & 7 deletions src/services/productsService.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as API from "../api/API";

const requestHeaders = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API.AUTH_TOKEN}`,
},
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${API.AUTH_TOKEN}`,
};

export const getProducts = async () => {
try {
const response = await fetch(API.PRODUCTS, requestHeaders);
const response = await fetch(API.PRODUCTS, { headers });
const json = await response.json();
return json;
} catch (error) {
Expand All @@ -22,11 +20,12 @@ export const redeemProduct = async (id) => {
const response = await fetch(API.REDEEEM, {
method: "POST",
body: { productId: id },
requestHeaders,
headers,
});
const json = await response.json();
return json;
} catch (error) {
console.log("errrooor", error);
return alert(JSON.stringify(error));
}
};
12 changes: 5 additions & 7 deletions src/services/userService.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as API from "../api/API";

const requestHeaders = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API.AUTH_TOKEN}`,
},
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${API.AUTH_TOKEN}`,
};

export const getUser = async () => {
try {
const response = await fetch(API.USER, requestHeaders);
const response = await fetch(API.USER, { headers });
const json = await response.json();
return json;
} catch (error) {
Expand All @@ -22,7 +20,7 @@ export const addPoints = async (coins) => {
const response = await fetch(API.ADD_POINTS, {
method: "POST",
body: { amount: coins },
requestHeaders,
headers,
});
const json = await response.json();
return json;
Expand Down

0 comments on commit ed11ec9

Please sign in to comment.