generated from ctc-uci/npo-frontend-vite-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clean up donation tracking (wip: backend is bad)
- Loading branch information
1 parent
46d977d
commit 40020a4
Showing
9 changed files
with
264 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Checkbox, Td, Tr } from '@chakra-ui/react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { useBackend } from '../../contexts/BackendContext'; | ||
import { Donation } from '../../types/donation'; | ||
|
||
interface DonationSiteProps { | ||
donation: Donation; | ||
checkedSet: Set<number>; | ||
allChecked: boolean; | ||
setCheckedSet: (set: Set<number>) => unknown; | ||
} | ||
|
||
export const DonationSite = ({ | ||
donation, | ||
checkedSet, | ||
allChecked, | ||
setCheckedSet, | ||
}: DonationSiteProps) => { | ||
const navigate = useNavigate(); | ||
const { backend } = useBackend(); | ||
|
||
const [isChecked, setIsChecked] = useState(allChecked || checkedSet.has(donation.business_id)); | ||
const [donationSiteName, setDonationSiteName] = useState(''); | ||
|
||
useEffect(() => { | ||
setIsChecked(allChecked); | ||
}, [allChecked]); | ||
|
||
useEffect(() => { | ||
const getDonationSiteName = async () => { | ||
try { | ||
const businessResponse = await backend.get(`business/${donation.business_id}`); | ||
setDonationSiteName(businessResponse.data[0].name); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
getDonationSiteName(); | ||
}, []); | ||
|
||
const cells = [ | ||
donationSiteName, | ||
donation?.donation_id, | ||
donation?.food_bank_donation, | ||
donation?.reporter, | ||
donation?.email, | ||
donation?.date ? new Date(donation.date).toLocaleDateString() : null, | ||
donation?.canned_dog_food_quantity !== null | ||
? `${donation.canned_dog_food_quantity} lb` | ||
: '0 lb', | ||
donation?.dry_dog_food_quantity !== null ? `${donation.dry_dog_food_quantity} lb` : '0 lb', | ||
donation?.canned_cat_food_quantity !== null | ||
? `${donation.canned_cat_food_quantity} lb` | ||
: '0 lb', | ||
donation?.dry_cat_food_quantity !== null ? `${donation.dry_cat_food_quantity} lb` : '0 lb', | ||
donation?.misc_items, | ||
donation?.volunteer_hours !== null ? `${donation.volunteer_hours} hrs` : '0 hrs', | ||
]; | ||
|
||
const handleClick = () => { | ||
const newCheckedState = !isChecked; | ||
setIsChecked(newCheckedState); | ||
|
||
const newSet = new Set(checkedSet); | ||
checkedSet.has(donation.donation_id) | ||
? newSet.delete(donation.donation_id) | ||
: newSet.add(donation.donation_id); | ||
|
||
setCheckedSet(newSet); | ||
}; | ||
|
||
const handleRowClick = async (id: number) => { | ||
navigate(`/ViewDonation/${id}`); | ||
}; | ||
|
||
return ( | ||
<Tr> | ||
<Td> | ||
<Checkbox isChecked={isChecked} onChange={handleClick} /> | ||
</Td> | ||
|
||
{cells.map((cell, index) => ( | ||
<Td key={index} onClick={() => handleRowClick(donation.donation_id)}> | ||
{cell} | ||
</Td> | ||
))} | ||
</Tr> | ||
); | ||
}; |
22 changes: 0 additions & 22 deletions
22
src/components/DonationTrackingTable/DonationTrackingTable.module.css
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.