diff --git a/client-app/src/Components/DonatedItemsList.tsx b/client-app/src/Components/DonatedItemsList.tsx index efabe586..95ce63fc 100644 --- a/client-app/src/Components/DonatedItemsList.tsx +++ b/client-app/src/Components/DonatedItemsList.tsx @@ -80,11 +80,27 @@ const DonatedItemsList: React.FC = () => { const filtered = donatedItems.filter( item => item.id.toString().includes(searchTerm) || - item.itemType.toLowerCase().includes(searchTerm) || - item.donor?.firstName.toLowerCase().includes(searchTerm) + item.itemType.toLowerCase().includes(searchTerm) || + item.donor?.firstName.toLowerCase().includes(searchTerm), ); setFilteredItems(filtered); }; + const handleSort = (event: React.ChangeEvent): void => { + const value = event.target.value; + const sorted = [...donatedItems].sort((a, b) => { + const dateA = new Date(a.dateDonated); + const dateB = new Date(b.dateDonated); + + if (value === 'dateAsc') { + return dateA.getTime() - dateB.getTime(); + } else if (value === 'dateDesc') { + return dateB.getTime() - dateA.getTime(); + } + return 0; + }); + setFilteredItems(sorted); + }; + const handleBarcodeClick = (itemId: number): void => { const selectedItem = donatedItems.find(item => item.id === itemId); if (selectedItem) { @@ -96,6 +112,50 @@ const DonatedItemsList: React.FC = () => { setModalIsOpen(true); }; + const handleFilterByItemName = ( + event: React.ChangeEvent, + ): void => { + if (!event.target.value) { + setFilteredItems([]); + return; + } + const filtered = donatedItems.filter( + item => + item.itemType.toLowerCase() === + event.target.value.toLowerCase(), + ); + setFilteredItems(filtered); + }; + + const handleFilterByProgram = ( + event: React.ChangeEvent, + ): void => { + if (!event.target.value) { + setFilteredItems([]); + return; + } + const programId = parseInt(event.target.value); + const filtered = donatedItems.filter( + item => item.programId === programId, + ); + setFilteredItems(filtered); + }; + + const handleFilterByStatus = ( + event: React.ChangeEvent, + ): void => { + if (!event.target.value) { + setFilteredItems([]); + return; + } + const filtered = donatedItems.filter( + item => + item.currentStatus.toLowerCase() === + event.target.value.toLowerCase(), + ); + setFilteredItems(filtered); + }; + const handleAddNewDonationClick = (): void => { navigate('/adddonation'); }; @@ -153,9 +213,56 @@ const DonatedItemsList: React.FC = () => { > - + +
+ + + + + + + +
- +