Skip to content

Commit

Permalink
feat: clean up donation tracking (wip: backend is bad)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Aug 9, 2024
1 parent 46d977d commit 40020a4
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 302 deletions.
15 changes: 6 additions & 9 deletions src/components/AdminDashboard/BusinessTable/BusinessTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { BiCheck, BiEnvelope, BiPlus, BiTimeFive, BiX } from 'react-icons/bi';
import { useNavigate } from 'react-router-dom';

import { useBackend } from '../../../contexts/BackendContext';
import DownloadCSV from '../../../utils/downloadCSV';
import downloadCSV from '../../../utils/downloadCSV';
import BusinessTableModal from './BusinessTableModal';

const TABLE_HEADERS = ['Business Name', 'Location', 'Email', 'Form Status', 'Last Submitted'];
Expand Down Expand Up @@ -149,8 +149,7 @@ export const BusinessTable = () => {
};

const handleSendReminders = async () => {
for (const businessId of selectedBusinessIds) {
// ! FIX ME
selectedBusinessIds.forEach(async (businessId) => {
try {
const requestData = {
businessId: businessId,
Expand All @@ -164,7 +163,8 @@ export const BusinessTable = () => {
} catch (error) {
console.error('Error sending reminders:', error);
}
}
});

const message = `To ${selectedBusinessIds.size} ${
selectedBusinessIds.size > 1 ? `businesses` : ` business`
}.`;
Expand All @@ -184,7 +184,7 @@ export const BusinessTable = () => {
headers.push(TABLE_HEADERS[i].toLowerCase().replace(' ', '_'));
}
try {
DownloadCSV(ids);
downloadCSV(ids);
const message = `For ${ids.length} ${ids.length > 1 ? `businesses` : ` business`}.`;
toast({
title: 'Downloaded CSV',
Expand Down Expand Up @@ -246,10 +246,7 @@ export const BusinessTable = () => {

console.log(businessResponse);

if (
true ||
(currentTab === 'All' && search === '' && businessCountResponse.data[0]['count'] === 0)
) {
if (currentTab === 'All' && search === '' && businessCountResponse.data[0]['count'] === 0) {
onOpen();
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/BusinessTablePending/BusinessTablePending.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FaPlus } from 'react-icons/fa6';
import { useNavigate } from 'react-router-dom';

import { useBackend } from '../../contexts/BackendContext';
import DownloadCSV from '../../utils/downloadCSV';
import downloadCSV from '../../utils/downloadCSV';
import { BusinessForm } from '../BusinessForm/BusinessForm.1';
import ViewBusiness from '../ViewBusiness/ViewBusiness';

Expand Down Expand Up @@ -120,7 +120,7 @@ const BusinessTablePending = (businessData) => {
for (var i = 0; i < TABLE_HEADERS.length; i++) {
headers.push(TABLE_HEADERS[i].toLowerCase().replace(' ', '_'));
}
DownloadCSV(headers, ids, 'business');
downloadCSV(headers, ids, 'business');
};

const handleSendReminders = async () => {
Expand Down
90 changes: 0 additions & 90 deletions src/components/DonationTrackingTable/DonationSite.jsx

This file was deleted.

92 changes: 92 additions & 0 deletions src/components/DonationTrackingTable/DonationSite.tsx
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>
);
};

This file was deleted.

Loading

0 comments on commit 40020a4

Please sign in to comment.