source: CookCraft-FrontEnd/CookCraft-FrontEnd-master/cookcraft-app/src/components/AdminViewComponents/ApplicationCard.jsx

Last change on this file was d7b7f00, checked in by Gorazd Biskoski <gorazdbiskoskii@…>, 4 weeks ago

Add project

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d7b7f00]1import styles from "../../css/AdminPanelCss/admin-style.module.css";
2import { useEffect, useState } from "react";
3
4const ApplicationCard = ({ data, onClick }) => {
5 const [userData, setUserData] = useState({});
6
7 useEffect(() => {
8 if (!data || !data.userId) {
9 return;
10 }
11
12 const url = "http://localhost:8080/api";
13 const { userId } = data;
14 const token = localStorage.getItem("token");
15
16 const fetchUserData = async () => {
17 try {
18 const response = await fetch(`${url}/users/${userId}`, {
19 method: "GET",
20 headers: {
21 "Content-Type": "application/json",
22 Authorization: `Bearer ${token}`,
23 },
24 });
25
26 if (response.ok) {
27 const user_data = await response.json();
28 setUserData(user_data);
29 } else {
30 alert(response.status);
31 }
32 } catch (error) {
33 console.error(error);
34 alert("Error communicating with the server.");
35 }
36 };
37
38 fetchUserData();
39 }, [data]);
40
41 const handleClick = () => {
42 onClick({ ...data, userData });
43 };
44
45 return (
46 <div className={styles.card} onClick={handleClick}>
47 <div className={styles.cardContent}>
48 <h3 className={styles.cardTitle}>
49 {userData.userName} {userData.userSurname}
50 </h3>
51 <p><strong>Email:</strong> {userData.email}</p>
52 <p><strong>Phone Number:</strong> {userData.phoneNumber}</p>
53 </div>
54 </div>
55 );
56};
57
58export default ApplicationCard;
Note: See TracBrowser for help on using the repository browser.