Skip to content

Commit a758896

Browse files
KainoaNishidaColinK914arnavk377srukelmanCobby914
authored
created donors table, added routes, updated the backend, and created … (#143)
* created donors table, added routes, updated the backend, and created a component for donation filter * Got started Co-authored-by: Arnav Kanekar <arnavk377@users.noreply.github.com> * Finished Styling for Edit and Add Side Peaks * styling donations table * Fixed Styling of Add Drawer * fixed donations post * fixes * csv and some changes Co-authored-by: Colin Kwon <Cobby914@users.noreply.github.com> * filter and search work for regular get Co-authored-by: Colin Kwon <Cobby914@users.noreply.github.com> * add and edit modal styling filter and search changes * changing styling of table and input Co-authored-by: Colin Kwon <Cobby914@users.noreply.github.com> * Fixed the put route * fixed comments * Fixed the put route again * omg * fixed add donation failing --------- Co-authored-by: Colin Kwon <colink5@uci.edu> Co-authored-by: Arnav Kanekar <arnavk377@users.noreply.github.com> Co-authored-by: arnavk377 <arnavk1321@gmail.com> Co-authored-by: srukelman <seanrkelman@gmail.com> Co-authored-by: Colin Kwon <Cobby914@users.noreply.github.com>
1 parent b9f0ab0 commit a758896

File tree

10 files changed

+1549
-471
lines changed

10 files changed

+1549
-471
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import React, { useState, useMemo } from "react";
2+
import {
3+
Menu,
4+
MenuButton,
5+
MenuList,
6+
MenuItem,
7+
Button,
8+
Input,
9+
InputGroup,
10+
InputLeftElement,
11+
VStack,
12+
HStack,
13+
Text,
14+
Divider,
15+
IconButton,
16+
useDisclosure,
17+
} from "@chakra-ui/react";
18+
import { ChevronDownIcon, SearchIcon } from "@chakra-ui/icons";
19+
import { FaPlus } from "react-icons/fa";
20+
21+
type Props = {
22+
donors: string[];
23+
donor: string;
24+
setDonor: (d: string) => void;
25+
newDonor: string;
26+
setNewDonor: (n: string) => void;
27+
28+
addDonor: (name: string) => Promise<void>;
29+
};
30+
31+
export function DonationFilter({
32+
donors,
33+
donor,
34+
setDonor,
35+
newDonor,
36+
setNewDonor,
37+
handleAddDonor,
38+
}: {
39+
donors: string[];
40+
donor: string;
41+
setDonor: (d: string) => void;
42+
newDonor: string;
43+
setNewDonor: (n: string) => void;
44+
handleAddDonor: () => void;
45+
}) {
46+
const { isOpen, onOpen, onClose } = useDisclosure();
47+
const {
48+
isOpen: isAddOpen,
49+
onOpen: onAddOpen,
50+
onClose: onAddClose,
51+
} = useDisclosure();
52+
53+
const [searchTerm, setSearchTerm] = useState("");
54+
const filtered = useMemo(
55+
() =>
56+
donors.filter((d) =>
57+
typeof d === "string" &&
58+
d.toLowerCase().includes(searchTerm.toLowerCase())
59+
),
60+
[donors, searchTerm]
61+
);
62+
63+
const selectDonor = (d: string) => {
64+
setDonor(d);
65+
onClose();
66+
};
67+
68+
return (
69+
<Menu
70+
isOpen={isOpen}
71+
onOpen={onOpen}
72+
onClose={() => {
73+
onClose();
74+
onAddClose();
75+
setSearchTerm("");
76+
}}
77+
closeOnBlur
78+
closeOnSelect={false}
79+
>
80+
<MenuButton
81+
as={Button}
82+
rightIcon={<ChevronDownIcon />}
83+
variant="outline"
84+
w="300px"
85+
textAlign="left"
86+
>
87+
{donor || "Select Donor"}
88+
</MenuButton>
89+
90+
<MenuList w="300px" p={2} boxShadow="md">
91+
<InputGroup mb={2}>
92+
<InputLeftElement pointerEvents="none">
93+
<SearchIcon color="gray.400" />
94+
</InputLeftElement>
95+
<Input
96+
placeholder="Search donor"
97+
value={searchTerm}
98+
onChange={(e) => setSearchTerm(e.target.value)}
99+
/>
100+
</InputGroup>
101+
102+
<VStack align="stretch" spacing={0} maxH="100vh" overflowY="auto">
103+
{filtered.map((d) => (
104+
<MenuItem key={d} onClick={() => selectDonor(d)}>
105+
{d}
106+
</MenuItem>
107+
))}
108+
{filtered.length === 0 && (
109+
<Text px={2} color="gray.500" fontSize="sm">
110+
No donors found
111+
</Text>
112+
)}
113+
</VStack>
114+
115+
<Divider my={2} />
116+
117+
{!isAddOpen && (
118+
<MenuItem
119+
icon={<FaPlus color="gray" />}
120+
onClick={onAddOpen}
121+
color="gray.600"
122+
>
123+
Add New Donor
124+
</MenuItem>
125+
)}
126+
127+
{isAddOpen && (
128+
<HStack px={2} py={1}>
129+
<Input
130+
placeholder="New donor name"
131+
value={newDonor}
132+
onChange={(e) => setNewDonor(e.target.value)}
133+
onKeyDown={(e) => {
134+
if (e.key === "Enter") handleAdd();
135+
if (e.key === "Escape") onAddClose();
136+
}}
137+
/>
138+
<IconButton
139+
aria-label="Confirm add donor"
140+
icon={<FaPlus />}
141+
size="sm"
142+
onClick={handleAddDonor}
143+
/>
144+
</HStack>
145+
)}
146+
</MenuList>
147+
</Menu>
148+
);
149+
}

0 commit comments

Comments
 (0)