source: CookCraft-FrontEnd/CookCraft-FrontEnd-master/cookcraft-app/src/components/AdminViewComponents/AdminApplicationModal.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: 3.6 KB
Line 
1import styles from "../../css/AdminPanelCss/modal-style.module.css";
2
3const ApplicationModal = ({ isOpen, onClose, applicationData, setReload }) => {
4 if (!isOpen || !applicationData) return null;
5
6 const { userData, motivationalLetter, cv } = applicationData;
7
8 const downloadCV = () => {
9 const base64String = applicationData.cv.startsWith('data:application/pdf;base64,')
10 ? cv
11 : 'data:application/pdf;base64,' + applicationData.cv;
12
13 const base64Data = base64String.split(',')[1];
14
15 const byteCharacters = atob(base64Data);
16 const byteNumbers = new Array(byteCharacters.length);
17
18 for (let i = 0; i < byteCharacters.length; i++) {
19 byteNumbers[i] = byteCharacters.charCodeAt(i);
20 }
21
22 const byteArray = new Uint8Array(byteNumbers);
23 const blob = new Blob([byteArray], { type: 'application/pdf' });
24
25 const link = document.createElement('a');
26 link.href = window.URL.createObjectURL(blob);
27 link.download = `CV_${userData.userName}_${userData.userSurname}.pdf`;
28 link.click();
29 };
30
31 const handleAccept = async () => {
32 const token = localStorage.getItem("token");
33 const { userId } = applicationData
34 try {
35 const response = await fetch(`http://localhost:8080/api/admin/accept/${userId}`, {
36 method: 'POST',
37 headers: {
38 'Content-Type': 'application/json',
39 'Authorization': `Bearer ${token}`
40 }
41 })
42
43 if(response.ok)
44 {
45 //alert("Updated user role successfully!");
46 await handleDecline()
47 }
48 else
49 {
50 alert(response.status)
51 }
52 }
53 catch (error) {
54 alert(error);
55 }
56 }
57
58 const handleDecline = async () => {
59 const token = localStorage.getItem("token");
60 const { id } = applicationData
61
62 try {
63 const response = await fetch(`http://localhost:8080/api/admin/decline/${id}`, {
64 method: 'DELETE',
65 headers: {
66 'Content-Type': 'application/json',
67 'Authorization': `Bearer ${token}`
68 }
69 })
70 if(response.ok)
71 {
72 //alert("Deleted user application successfully!");
73 setReload(true)
74 onClose();
75 }
76 else
77 {
78 alert(response.status)
79 }
80 }
81 catch (error) {
82 alert(error);
83 }
84 }
85
86 return (
87 <div className={styles.modalOverlay}>
88 <div className={styles.modalContent}>
89 <button className={styles.closeButton} onClick={onClose}>&times;</button>
90 <h2>Application Details</h2>
91 <p><strong>Name:</strong> {userData.userName} {userData.userSurname}</p>
92 <p><strong>Email:</strong> {userData.email}</p>
93 <p><strong>Phone Number:</strong> {userData.phoneNumber}</p>
94 <p><strong>Motivational Letter:</strong> {motivationalLetter}</p>
95 <button onClick={downloadCV} className={styles.downloadButton}>
96 Download CV
97 </button>
98 <div className={styles.buttons}>
99 <button className={styles.buttonAccept} onClick={handleAccept}>Accept</button>
100 <button className={styles.buttonDecline} onClick={handleDecline}>Decline</button>
101 </div>
102 </div>
103 </div>
104 );
105};
106
107export default ApplicationModal;
Note: See TracBrowser for help on using the repository browser.