Skip to content

Commit

Permalink
Merge pull request #118 from Gather307/ItemsPageButtons
Browse files Browse the repository at this point in the history
Adds items page buttons
  • Loading branch information
SilveerDusk authored May 29, 2024
2 parents ff5b9b0 + 20ff47f commit a7626bd
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 190 deletions.
47 changes: 0 additions & 47 deletions backend/itemSchema.ts

This file was deleted.

14 changes: 0 additions & 14 deletions backend/routes/basketRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ router.get("/", async (req: Request, res: Response) => {
res.status(500).send("Internal Server Error"); // Handle any unexpected errors
}
});
router.get("/:bid", async (req: Request, res: Response) => {
connectDB();
// Use findById correctly with the id parameter from the request
const basket = await Basket.findById(req.params.bid).maxTimeMS(2000);

// Check if group is null or undefined
if (!basket) {
return res.status(404).send("No basket found."); // Use return to exit the function after sending the response
}

// Send the found user
res.send(basket);
console.log("Sent Group");
});

router.get("/:basketid", async (req: Request, res: Response) => {
// Ensure the database connection
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ function App() {
{/* added route for individual group page */}
<Route
path="/items"
element={<ItemsPage stateVariable={{ user, token }} />}
element={<ItemsPage
stateVariable={{ user, token }}
/>
}
/>
<Route
path="/groups"
Expand Down
35 changes: 15 additions & 20 deletions frontend/src/components/CompactItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Button,
IconButton,
Popover,
PopoverContent,
PopoverTrigger,
Expand All @@ -9,38 +9,33 @@ import {
PopoverBody,
VStack,
Box,
IconButton,
} from "@chakra-ui/react";
import { EditIcon } from "@chakra-ui/icons";

interface Props {
name: string;
desc: string;
quant: number;
price: number;
pub: boolean;
assigned: boolean;
}
import { EditIcon, SearchIcon } from "@chakra-ui/icons";
import { IItem } from "../../../backend/models/itemSchema";

const CompactItem = ({ name, desc, quant, price, pub }: Props) => {
const CompactItem = ({ item }: { item: IItem }) => {
// Note: Colors not added yet, just basic structure
return (
<Popover>
<PopoverTrigger>
<Button>Some clickable item component / more button</Button>
<IconButton aria-label="More" icon={<SearchIcon />} />
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverHeader>{name}</PopoverHeader>
<PopoverHeader>{item.name}</PopoverHeader>
<PopoverBody>
<VStack alignItems="flex-end">
<VStack alignItems="flex-start">
<Box>Description: {desc}</Box>
<Box>Quantity: {quant}</Box>
<Box>Price (per item): {price}</Box>
{quant > 1 ? <Box>{`\nTotal price: ${price * quant}`}</Box> : ""}
<Box>Viewability: {pub ? "Public" : "Private"}</Box>
<Box>Description: {item.notes}</Box>
<Box>Quantity: {item.quantity}</Box>
<Box>Price (per item): {item.price}</Box>
{item.quantity > 1 ? (
<Box>{`\nTotal price: ${item.price * item.quantity}`}</Box>
) : (
""
)}
<Box>Viewability: {item.isPrivate ? "Public" : "Private"}</Box>
</VStack>
<IconButton aria-label="Edit item" icon={<EditIcon />} />
</VStack>
Expand Down
42 changes: 10 additions & 32 deletions frontend/src/components/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
Radio,
RadioGroup,
Text,
IconButton,
} from "@chakra-ui/react";
import { SearchIcon } from "@chakra-ui/icons";
import React, { useState, useEffect } from "react";
import {} from "@chakra-ui/react";

Expand Down Expand Up @@ -87,20 +89,6 @@ const EditItem: React.FC<Props> = ({ itemId }) => {
const format = (val: any) => `$` + val;
const parse = (val: any) => val.replace(/^\$/, "");

const handleDelete = async () => {
try {
const response = await fetch(`http://localhost:3001/items/${itemId}`, {
method: "DELETE",
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
console.log("Item deleted successfully");
} catch (error) {
console.error("There was an error deleting the item", error);
}
};

const handleSaveChanges = async () => {
try {
const updatedItem = {
Expand Down Expand Up @@ -134,6 +122,7 @@ const EditItem: React.FC<Props> = ({ itemId }) => {
} else {
console.error("Failed to update profile");
}
window.location.reload();
} catch (error) {
console.error("Error updating profile:", error);
}
Expand All @@ -142,9 +131,7 @@ const EditItem: React.FC<Props> = ({ itemId }) => {
return (
<Popover>
<PopoverTrigger>
<Button onClick={() => setIsEditing(false)}>
Some clickable item component / more button
</Button>
<IconButton aria-label="More" icon={<SearchIcon />} />
</PopoverTrigger>

<PopoverContent
Expand Down Expand Up @@ -266,7 +253,7 @@ const EditItem: React.FC<Props> = ({ itemId }) => {
</RadioGroup>
</FormControl>
<FormControl>
<FormLabel fontWeight="bold">Is this sharable?</FormLabel>
<FormLabel fontWeight="bold">Sharable?</FormLabel>
<RadioGroup
onChange={setEditedSharable}
value={editedSharable}
Expand Down Expand Up @@ -315,36 +302,27 @@ const EditItem: React.FC<Props> = ({ itemId }) => {
</Stack>
</RadioGroup>
</FormControl>
<HStack width="100%" spacing={4}>
<HStack
display={"flex"}
width="100%"
justifyContent="space-around"
>
<Button
bgColor="var(--col-secondary)"
color="white"
_hover={{
bg: "var(--col-tertiary)",
color: "var(--col-dark)",
}}
mt={2}
ml="auto"
onClick={handleSaveChanges}
>
Save
</Button>
<Button
colorScheme="red"
_hover={{ bg: "#ff8366", color: "var(--col-dark)" }}
mt={2}
ml="auto"
onClick={handleDelete}
>
Delete
</Button>
<Button
mt={2}
_hover={{
bg: "var(--col-tertiary)",
color: "var(--col-dark)",
}}
ml="auto"
onClick={() => setIsEditing(false)}
>
Cancel
Expand Down
Loading

0 comments on commit a7626bd

Please sign in to comment.