-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.jsx
46 lines (41 loc) · 1.04 KB
/
Card.jsx
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
import React from "react";
import { Link } from "react-router-dom";
import { useDoctorStates } from "./utils/DoctorContext";
import "../Routes/index.css";
import avatar from "./assets/images/doctor.jpg";
const Card = () => {
const { doctorState, doctorDispatch } = useDoctorStates();
const addFav = (doctor) => {
const isDoctorInFavorites = doctorState.favs
.map((favDoctor) => favDoctor.id)
.includes(doctor.id);
if (isDoctorInFavorites) {
alert("Ya está en favoritos");
} else {
doctorDispatch({
type: "ADD_FAV",
payload: doctor,
});
}
};
return (
<div className="card-grid">
{doctorState.doctorList.map((doctor) => (
<div className="card" key={doctor.id}>
<Link to={"/detail/" + doctor.id}>
<img src={avatar} alt="" />
<h3>Name: {doctor.name}</h3>
<h4>User: {doctor.username}</h4>
<h5>Id: {doctor.id}</h5>
</Link>
<button
onClick={() => addFav(doctor)}
className="favButton">
Add fav
</button>
</div>
))}
</div>
);
};
export default Card;