Skip to content

Commit 71e75f5

Browse files
committed
Fix: download buttons
1 parent e6de163 commit 71e75f5

File tree

4 files changed

+73
-58
lines changed

4 files changed

+73
-58
lines changed

client/src/components/invoices/InvoiceComponents.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ function InvoicesTable({ filteredInvoices, isPaidColor, seasonColor, sortKey, so
13911391
</Td>
13921392
{/* <Td>
13931393
<Flex ml="18px">
1394-
<PDFButtonInvoice onlyIcon={true} id={invoice.id} invoiceMonth={invoice.month} invoiceYear={invoice.year} programName={invoice.eventName} />
1394+
<PDFButtonInvoice onlyIcon={true} id={invoice.id} />
13951395
</Flex>
13961396
</Td> */}
13971397
<td>

client/src/components/invoices/PDFButtonInvoice.jsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import { getPastDue } from "../../utils/pastDueCalc"
2626
const PDFButtonInvoice = ({
2727
id,
2828
onlyIcon = false,
29-
hasUnsavedChanges = null,
30-
handleOtherButtonClick = null,
3129
}) => {
3230
const [loading, setLoading] = useState(false);
3331
const [invoice, setInvoice] = useState(null);
@@ -158,16 +156,7 @@ const PDFButtonInvoice = ({
158156
<Box>
159157
{onlyIcon ? (
160158
<IconButton
161-
onClick={(e) => {
162-
e.stopPropagation();
163-
if (hasUnsavedChanges) {
164-
handleOtherButtonClick(() => {
165-
handleDownload();
166-
});
167-
} else {
168-
handleDownload();
169-
}
170-
}}
159+
onClick={handleDownload}
171160
bg="transparent"
172161
icon={
173162
loading ? <Spinner size="sm" /> : <DownloadIcon boxSize="20px" />

client/src/components/invoices/SingleInvoice.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,6 @@ export const SingleInvoice = () => {
438438
>
439439
<PDFButtonInvoice
440440
id={id}
441-
hasUnsavedChanges={hasUnsavedChanges}
442-
handleOtherButtonClick={handleOtherButtonClick}
443441
/>
444442
<Button
445443
height={"40px"}

client/src/components/programs/ProgramComponents.jsx

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,33 @@ export const ProgramSummary = ({
350350

351351
const { nextSession, nextRoom } = safeBookingInfo;
352352

353+
const [invoiceId, setInvoiceId] = useState(null);
354+
const [isLoadingInvoiceId, setIsLoadingInvoiceId] = useState(true);
355+
const { id } = useParams();
356+
357+
useEffect(() => {
358+
const fetchData = async () => {
359+
try {
360+
const invoiceResponse = await backend.get(`/invoices/event/${id}`)
361+
// Get the invoice with the most recent start_date
362+
if (invoiceResponse.data && invoiceResponse.data.length > 0) {
363+
const mostRecentInvoice = invoiceResponse.data.reduce((latest, current) => {
364+
const latestDate = new Date(latest.startDate);
365+
const currentDate = new Date(current.startDate);
366+
return currentDate > latestDate ? current : latest;
367+
});
368+
369+
setInvoiceId(mostRecentInvoice.id);
370+
}
371+
} catch (err) {
372+
console.error("Error fetching bookings:", err);
373+
} finally {
374+
setIsLoadingInvoiceId(false);
375+
}
376+
};
377+
fetchData();
378+
}, [id]);
379+
353380
return (
354381
<Box
355382
minH="10vh"
@@ -400,12 +427,10 @@ export const ProgramSummary = ({
400427
align="center"
401428
gap={2}
402429
>
403-
<PDFButton
404-
leftIcon={<Icon as={DownloadIcon} />}
405-
fontWeight={"700"}
406-
>
407-
Invoice
408-
</PDFButton>
430+
<PDFButtonInvoice
431+
id={invoiceId}
432+
onlyIcon={true}
433+
/>
409434
{!isArchived ? (
410435
<EditCancelPopup
411436
handleEdit={handleEdit}
@@ -2246,40 +2271,43 @@ const MyDocument = ({ bookingData }) => {
22462271
);
22472272
};
22482273

2249-
const PDFButton = () => {
2250-
const { backend } = useBackendContext();
2251-
// const [bookingData, setBookingData] = useState(null);
2252-
const [isLoading, setIsLoading] = useState(true);
2253-
const { id } = useParams();
2254-
2255-
useEffect(() => {
2256-
const fetchData = async () => {
2257-
try {
2258-
// const response = await backend.get("/bookings");
2259-
// setBookingData(Array.isArray(response.data) ? response.data : []);
2260-
2261-
// console.log("id", id)
2262-
const eventsResponse = await backend.get(`/events/${id}`)
2263-
console.log("eventsResponse", eventsResponse);
2264-
} catch (err) {
2265-
console.error("Error fetching bookings:", err);
2266-
} finally {
2267-
setIsLoading(false);
2268-
}
2269-
};
2270-
fetchData();
2271-
}, [backend]);
2272-
2273-
// if (isLoading) return <div>Loading...</div>;
2274-
2275-
2276-
2277-
return (
2278-
<div>
2279-
{/* <PDFButtonInvoice
2280-
id={id}
2281-
onlyIcon={true}
2282-
/> */}
2283-
</div>
2284-
);
2285-
};
2274+
// const PDFButton = () => {
2275+
// const { backend } = useBackendContext();
2276+
// const [invoiceId, setInvoiceId] = useState(null);
2277+
// // const [isLoading, setIsLoading] = useState(true);
2278+
// const { id } = useParams();
2279+
2280+
// useEffect(() => {
2281+
// const fetchData = async () => {
2282+
// try {
2283+
// const invoiceResponse = await backend.get(`/invoices/event/${id}`)
2284+
2285+
// // Get the invoice with the most recent start_date
2286+
// if (invoiceResponse.data && invoiceResponse.data.length > 0) {
2287+
// const mostRecentInvoice = invoiceResponse.data.reduce((latest, current) => {
2288+
// const latestDate = new Date(latest.start_date);
2289+
// const currentDate = new Date(current.start_date);
2290+
// return currentDate > latestDate ? current : latest;
2291+
// });
2292+
2293+
// setInvoiceId(mostRecentInvoice.id);
2294+
// }
2295+
// } catch (err) {
2296+
// console.error("Error fetching bookings:", err);
2297+
// }
2298+
// };
2299+
// fetchData();
2300+
// }, [backend, id]);
2301+
2302+
// // if (isLoading) return <div>Loading...</div>;
2303+
2304+
2305+
2306+
// return (
2307+
// <div>
2308+
// <PDFButtonInvoice
2309+
// id={invoiceId}
2310+
// />
2311+
// </div>
2312+
// );
2313+
// };

0 commit comments

Comments
 (0)