@@ -28,85 +28,6 @@ const ReturnPopup = ({ units = [], onSuccess, onClose }) => {
2828 } , [ units , currentPage ] ) ;
2929
3030 const handleReturn = async ( ) => {
31- //try {
32-
33- //EMAIL FOR RETURN ITEMS BELOW
34-
35- //const itemNames = units.map(item => item.name);
36-
37- // // Fetch the borrower's ID based on the first selected item
38- // const borrowerID = await fetch (`/api/fetchBorrowerId?id=${units[0].id}`);
39- // if (!borrowerId.ok) {
40- // throw new Error(`Failed to fetch borrower ID: ${borrowerId.status}`);
41- // }
42- // const { borrower_id: borrowerId } = await borrowerID.json();
43-
44- // // Fetch the borrower's email using the first item's borrower_id
45- // console.log("Borrower id:" + borrower_id);
46- // const borrowerEmailResponse = await fetch(`/api/fetchBorrowerEmail?id=${borrower_id}`);
47- // if (!borrowerEmailResponse.ok) {
48- // throw new Error(`Failed to fetch borrower email: ${borrowerEmailResponse.status}`);
49- // }
50- // const { borrower_email: borrowerEmail } = await borrowerEmailResponse.json();
51-
52- // const borrowerNameResponse = await fetch(`/api/fetchBorrowerName?id=${borrowerId}`);
53- // if (!borrowerNameResponse.ok) {
54- // throw new Error(`Failed to fetch borrower name: ${borrowerNameResponse.status}`);
55- // }
56- // const { borrower_first_name: borrowerFirstName, borrower_last_name: borrowerLastName } = await borrowerNameResponse.json();
57-
58- // Step 2: Call the groupReturnsByBorrowerHandler API
59-
60- ////////////////////////////////////////////////////
61-
62- // try {
63- // const response = await fetch('/api/borrowManagement?action=groupReturnsByBorrower', {
64- // method: 'POST',
65- // headers: { 'Content-Type': 'application/json' },
66- // body: JSON.stringify({ returnedItems: units.map(item => item.id) }),
67- // });
68-
69- // if (!response.ok) {
70- // throw new Error(`Group API error: ${response.status} - ${response.statusText}`);
71- // }
72-
73- // const result = await response.json();
74- // console.log(result.message); // Should log: Emails sent to all borrowers.
75-
76- // if (onSuccess) onSuccess();
77-
78- // location.reload();
79-
80- // } catch (error) {
81- // console.error("Error returning data:", error);
82- // }
83-
84- // try {
85- // const response = await fetch('../../api/borrowManagement?action=return', {
86- // method: 'PUT',
87- // headers: { 'Content-Type': 'application/json' },
88- // body: JSON.stringify({
89- // selectedItems: units.map(item => item.id),
90- // notes_id: Object.keys(notes),
91- // notes_content: Object.values(notes)
92- // })
93- // });
94-
95- // if (!response.ok) {
96- // throw new Error(`Fetch error: ${response.status} - ${response.statusText}`);
97- // }
98-
99- // const result = await response.json();
100- // if (result.message) alert(result.message);
101- // if (onSuccess) onSuccess();
102-
103- // location.reload();
104- // } catch (error) {
105- // console.error("Error returning data:", error);
106- // }
107- // if (selectedUnits == 0) {
108- // alert('No items selected.');
109- // } else {
11031
11132 try {
11233 // 1. Send Emails first
0 commit comments