-
Notifications
You must be signed in to change notification settings - Fork 1
/
logic.js
66 lines (65 loc) · 1.53 KB
/
logic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import axios from "axios";
import React, { useEffect, useState } from "react";
import { useLogin } from "../LoginContext";
export default function Cart() {
let [info, setInfo] = useState(null);
let { token } = useLogin();
useEffect(() => {
(async () => {
try {
let { data } = await axios.get(
"https://del-now.naveenkamath.repl.co/user",
{
headers: {
authorization: token
}
}
);
setInfo(data);
} catch (error) {
setInfo("error");
console.log("error is--> ", error);
}
})();
}, []);
return (
<div>
<h2>This is cart</h2>
{info === null && <p>Loading</p>}
{info === "error" && <p>Error occured : need to login</p>}
{info?.name && (
<p>
{info.name} || {info.pincode}
</p>
)}
</div>
);
}
export default function Category() {
let { login } = useLogin();
return (
<div>
<h2>Category page</h2>
{phonesDB.data.map(({ name, price }, index) => {
return (
<div
key={index}
style={{
border: "1px solid blue",
margin: "0.5rem",
borderRadius: "0.5rem"
}}
>
<h2>{name}</h2>
<h3>Rs: {price}</h3>
{login ? (
<Link to={`/product/${name}`}> View Details </Link>
) : (
<h3>Login to view more details</h3>
)}
</div>
);
})}
</div>
);
}