Skip to content

Commit

Permalink
Server working with new upload middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
kianz20 committed Sep 5, 2024
1 parent 146c096 commit df793e0
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 67 deletions.
4 changes: 4 additions & 0 deletions client/src/models/ProductDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ export interface ProductDetails {
description: string;
price: number;
_id: string;
imgPath: string;
stockCount: number;
franchise: string;
rating?: string;
}
61 changes: 56 additions & 5 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Input, Typography } from "@mui/material";
import { useEffect, useState } from "react";
import { Navigate } from "react-router-dom";
import * as api from "../api/productController";
Expand All @@ -23,8 +24,13 @@ const Dashboard = (): JSX.Element => {
price: 0,
description: "",
_id: "",
imgPath: "",
stockCount: 0,
franchise: "",
});

const [productImg, setProductImg] = useState<File | null>(null);

const [productDetails, setProductDetails] = useState<ProductDetails[]>();

const getProductData = async () => {
Expand Down Expand Up @@ -79,10 +85,13 @@ const Dashboard = (): JSX.Element => {
getProductData();
setNewProductDetails({
name: "",
price: 0,
category: "",
description: "",
price: 0,
_id: "",
category: "",
imgPath: "",
stockCount: 0,
franchise: "",
});
}
} catch (error) {
Expand All @@ -101,6 +110,10 @@ const Dashboard = (): JSX.Element => {
}));
};

const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setProductImg(e.target.files ? e.target.files[0] : null);
};

const handlePageChange = (page: string) => {
setPage(page);
clearAlert();
Expand Down Expand Up @@ -151,13 +164,13 @@ const Dashboard = (): JSX.Element => {
onChange={handleFormChange}
/>
<ThemedInput
label="Price"
label="Category"
variant="outlined"
fullWidth
margin="normal"
required
name="price"
value={newProductDetails.price}
name="category"
value={newProductDetails.category}
onChange={handleFormChange}
/>
<ThemedInput
Expand All @@ -172,6 +185,44 @@ const Dashboard = (): JSX.Element => {
value={newProductDetails.description}
onChange={handleFormChange}
/>
<ThemedInput
label="Price"
variant="outlined"
fullWidth
margin="normal"
required
name="price"
value={newProductDetails.price}
onChange={handleFormChange}
/>
<Typography> Picture of product: </Typography>
<Input
type="file"
fullWidth
disableUnderline
name="picture"
onChange={handleFileChange}
></Input>
<ThemedInput
label="Stock Count"
variant="outlined"
fullWidth
margin="normal"
required
name="stockCount"
value={newProductDetails.stockCount}
onChange={handleFormChange}
/>
<ThemedInput
label="Franchise"
variant="outlined"
fullWidth
margin="normal"
required
name="franchise"
value={newProductDetails.franchise}
onChange={handleFormChange}
/>
<ThemedButton text="Add Product" type="submit" />
</form>
<br />
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/SingleSearchResult.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const defaultProps: ProductDetails = {
description: "Test Description",
price: 3.99,
_id: "",
imgPath: "",
stockCount: 0,
franchise: "",
};

test("renders the result with the correct title", () => {
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/ThinProductDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const defaultProps: ThinProductDetailsProps = {
description: "Test Description",
price: 3.99,
_id: "",
imgPath: "",
stockCount: 0,
franchise: "",
color: "#aea3ff",
onRemove: jest.fn(),
};
Expand Down
Loading

0 comments on commit df793e0

Please sign in to comment.