source: CookCraft-FrontEnd/CookCraft-FrontEnd-master/cookcraft-app/src/components/AdminViewComponents/AdminRecipeApplicationModal.jsx@ d7b7f00

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

Add project

  • Property mode set to 100644
File size: 3.2 KB
Line 
1import styles from "../../css/AdminPanelCss/modal-style.module.css";
2
3const AdminRecipeApplicationModal = ({ isOpen, onClose, setReload, recipeApplicationData }) => {
4 if(!isOpen) return null;
5
6 const { recipeName, recipeDesc, recipeCategory, recipeOrigin, recipeMealThumb, recipeYoutubeURL, ingredients } = recipeApplicationData
7
8 const handleAccept = async () => {
9 const token = localStorage.getItem("token");
10 const { id } = recipeApplicationData;
11
12 try {
13 const response = await fetch(`http://localhost:8080/api/admin/recipeapplication/accept/${id}`, {
14 method: 'POST',
15 headers: {
16 'Authorization': `Bearer ${token}`,
17 'Content-Type': 'application/json'
18 }
19 })
20
21 if(response.ok)
22 {
23 await handleDecline();
24 }
25 else
26 {
27 alert(response.status);
28 }
29 }
30 catch (error) {
31 console.log("some error occured bruv")
32 console.error(error);
33 }
34 }
35
36 const handleDecline = async () => {
37 const token = localStorage.getItem("token");
38 const { id } = recipeApplicationData;
39
40 try {
41 const response = await fetch(`http://localhost:8080/api/admin/recipeapplication/decline/${id}`, {
42 method: 'DELETE',
43 headers: {
44 'Authorization': `Bearer ${token}`,
45 'Content-Type': 'application/json'
46 },
47 });
48 if(response.ok) {
49 setReload(true);
50 onClose();
51 }
52 else
53 {
54 alert(response.status);
55 }
56 }
57 catch (error)
58 {
59 console.error(error);
60 alert("Some error occurred while connecting with the server")
61 }
62 }
63
64 return (
65 <div className={styles.modalOverlay}>
66 <div className={styles.modalContent}>
67 <button className={styles.closeButton} onClick={onClose}>&times;</button>
68 <h2>Recipe Details</h2>
69
70 <p><strong>Name:</strong> {recipeName} </p>
71 <p><strong>Category:</strong> {recipeCategory} </p>
72 <p><strong>Origin:</strong> {recipeOrigin}</p>
73 <p><strong>Youtube Video URL:</strong> {recipeYoutubeURL} </p>
74 <p><strong>Image URL:</strong> {recipeMealThumb}</p>
75 <p><strong>Description:</strong> {recipeDesc} </p>
76 <h3>Recipe Ingredients:</h3>
77 <ul>
78 {ingredients.map(ingredient => {
79 return (
80 <li>
81 {ingredient.ingredient} - {ingredient.dose}
82 </li>
83 )
84 })}
85 </ul>
86 <div className={styles.buttons}>
87 <button className={styles.buttonAccept} onClick={handleAccept}>Accept</button>
88 <button className={styles.buttonDecline} onClick={handleDecline}>Decline</button>
89 </div>
90 </div>
91 </div>
92 );
93}
94
95export default AdminRecipeApplicationModal;
Note: See TracBrowser for help on using the repository browser.