Skip to content

Commit

Permalink
commenting some code (will update later)
Browse files Browse the repository at this point in the history
  • Loading branch information
faatima30 committed Apr 24, 2024
1 parent f0efb39 commit ade8748
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 47 deletions.
Binary file added Backend/ProductImage/20210314_202117.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/ProductImage/about-us1.jfif
Binary file not shown.
Binary file added Backend/ProductImage/call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Backend/ProductImage/iphone15.png
Binary file not shown.
Binary file removed Backend/ProductImage/sofa.png
Binary file not shown.
15 changes: 8 additions & 7 deletions Backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const LoginModel = require("./model/LoginModel");
app.use(express.json());
app.use(cors());
const multer = require("multer");
const path = require("path");

mongoose
.connect("mongodb://0.0.0.0:27017/InventoryDatabase")
Expand Down Expand Up @@ -96,28 +97,28 @@ app.get("/Product/single/:id", async (req, res) => {

res.send(data);
});

const imageLocation = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "ProductImage");
},

filename: (req, file, cb) => {
// console.log(file);
// cb(null, Date.now() +path.extname(file.originalname));
cb(null, file.originalname);
},
});
const uploadimg = multer({ storage: imageLocation });

const uploadImage = multer({
storage: imageLocation,
});

app.post("/AddProduct", uploadImage.single("image"), async (req, res) => {
app.post("/AddProduct", uploadimg.single("image"), async (req, res) => {
const newData = ProductModel({
name: req.body.name,
description: req.body.description,
category: req.body.category,
location: req.body.location,
price: req.body.price,
quantity: req.body.quantity,
image: req.file.filename,
// image: req.file.filename,
});
const saveData = await newData.save();
res.send(saveData);
Expand Down
4 changes: 4 additions & 0 deletions Backend/model/ProductModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const ProductModel = mongoose.Schema({
type: String,
// required: true,
},
location: {
type: String,
// required: true,
},
price: {
type: Number,
// required: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
width: calc(100% - 300px);
}
.dash {
margin-top: 120px;
margin-top: 50px;
width: 100%;
position: absolute;
left: 250px;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ function Sidenav() {
</span>
</NavLink>
</li>
<li>
{/* <li>
<NavLink to="/Gallery">
{" "}
<TfiGallery />{" "}
<span style={{ display: isOpen === false ? "block" : "none" }}>
Gallery
</span>
</NavLink>
</li>
</li> */}
<li>
<NavLink to="/Warehouses">
<FaLocationDot />{" "}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/Customer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from "react";
import axios from "axios";
// import MetaTags from "react-meta-tags"
import useSWR, { mutate } from "swr";
import { MDBDataTable } from "mdbreact";
import {
Expand Down Expand Up @@ -186,6 +187,11 @@ export default function Customer() {
}),
};
return (
// <React.Fragment>
// <div className="page-content">
// <MetaTags>
// <title>Customers</title>
// </MetaTags>
<div className="d-flex">
<Sidenav />

Expand Down Expand Up @@ -370,5 +376,7 @@ export default function Customer() {
</div>
<Footer />
</div>
// </div>
// </React.Fragment>
);
}
12 changes: 1 addition & 11 deletions frontend/src/pages/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Dashbaord() {
getTotalPrice();
getTotalWarehouse();
protectRoute();
});
},[]);

return (
<div className="d-flex ">
Expand All @@ -83,16 +83,6 @@ function Dashbaord() {
</li>
</ol>
</Col>
<Col md="4">
<div
className="float-end d-none d-md-block btn text-white pt-3"
style={{ backgroundColor: "rgb(43, 141, 141)" }}
>
<h6>
<AiFillSetting style={{ fontSize: "20px" }} /> Setting
</h6>
</div>
</Col>
</Row>
<Row>
<Col xl={3} md={6}>
Expand Down
100 changes: 75 additions & 25 deletions frontend/src/pages/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ export default function Product() {
const endpoint = "http://localhost:4000";
const [isedit, setisedit] = useState(false);
const [isopen, setisopen] = useState(false);
const [setImage] = useState(null)
// const [image, setImage] = useState();
const [productObj, setproductObj] = useState({
name: "",
description: "",
category: "",
location: "",
price: "",
quantity: "",
image: null,
// image: null,
});

let token = localStorage.getItem("token");
const headers = {
headers: {
"content-type": "multipart/form-data",
"Content-Type": "multipart/form-data",
token: token,
},
};
Expand All @@ -60,17 +61,25 @@ export default function Product() {
const HandelSubmit = async (e) => {
try {
if (isedit) {
let obj = {
name: productObj.name,
description: productObj.description,
category: productObj.category,
price: productObj.price,
quantity: productObj.quantity,
image: productObj.image,
};
// let obj = {
// name: productObj.name,
// description: productObj.description,
// category: productObj.category,
// price: productObj.price,
// quantity: productObj.quantity,
// image: productObj.image,
// };
const formData = new FormData();
formData.append("name", productObj.name);
formData.append("description", productObj.description);
formData.append("category", productObj.category);
formData.append("location", productObj.location);
formData.append("price", productObj.price);
formData.append("quantity", productObj.quantity);
// formData.append("image", productObj.image);
let updatedEndPoint = `${endpoint}/Product/update/${productObj._id}`;
await axios
.put(updatedEndPoint, obj, headers)
.put(updatedEndPoint, formData, headers)
.then((response) => {
alert("Product has been updated successfully");
mutate(endpoint, fetcher);
Expand Down Expand Up @@ -98,8 +107,18 @@ export default function Product() {
}
};

// const handelChange = (e) => {
// setproductObj({ ...productObj, [e.target.name]: e.target.value });
// };
const handelChange = (e) => {
setproductObj({ ...productObj, [e.target.name]: e.target.value });
if (e.target.type === "file") {
// Handle file input separately
// setImage(e.target.files[0]);
setproductObj({ ...productObj, [e.target.name]: e.target.files[0] });
} else {
// Handle text inputs
setproductObj({ ...productObj, [e.target.name]: e.target.value });
}
};

const tog_standard = () => {
Expand Down Expand Up @@ -133,6 +152,12 @@ export default function Product() {
sort: "asc",
width: 100,
},
{
label: "Store",
field: "location",
sort: "asc",
width: 100,
},
{
label: "Price",
field: "price",
Expand All @@ -145,12 +170,12 @@ export default function Product() {
sort: "asc",
width: 100,
},
{
label: "Image",
field: "image",
sort: "asc",
width: 200,
},
// {
// label: "Image",
// field: "image",
// sort: "asc",
// width: 200,
// },

{
label: "date created",
Expand Down Expand Up @@ -189,6 +214,14 @@ export default function Product() {
>
<MdDeleteSweep />
</button>
{/* Check if image data is available */}
{/* {data.image && (
<img
src={`data:image/png;base64, ${data.image}`} // Update the server endpoint
alt="Product"
style={{ width: "50px", height: "50px", objectFit: "cover" }}
/>
)} */}
</div>
);
return data;
Expand Down Expand Up @@ -223,6 +256,7 @@ export default function Product() {
</button>
</div>
<AvForm
encType="multipart/form-data"
className="needs-validation"
onValidSubmit={(e, v) => {
HandelSubmit();
Expand Down Expand Up @@ -280,6 +314,22 @@ export default function Product() {
/>
</FormGroup>
</Col>
<Col sm="12" md="6" lg="12">
<FormGroup className="mb-3">
<Label htmlFor="validationCustom02">Store:</Label>
<AvField
name="location"
placeholder="Enter store location"
type="text"
value={productObj.location}
onChange={(e) => handelChange(e)}
errorMessage="Enter category"
className="form-control"
validate={{ required: { value: true } }}
id="validationCustom02"
/>
</FormGroup>
</Col>
<Col sm="12" md="6" lg="12">
<FormGroup className="mb-3">
<Label htmlFor="validationCustom02">Price:</Label>
Expand Down Expand Up @@ -312,24 +362,24 @@ export default function Product() {
/>
</FormGroup>
</Col>
<Col sm="12" md="6" lg="12">
{/* <Col sm="12" md="6" lg="12">
<FormGroup className="mb-3">
<Label htmlFor="validationCustom02">
Choose image:
</Label>
<AvField
name="totalamount"
placeholder="Enter total amount"
name="image"
type="file"
value={productObj.image}
onChange={(event) => {setImage(event.target.files[0])}}
// accept="image/*"
// value={productObj.image}
onChange={(e) => handelChange(e)}
errorMessage="Choose image"
className="form-control"
validate={{ required: { value: true } }}
id="validationCustom02"
/>
</FormGroup>
</Col>
</Col> */}
</Row>
</div>
<div className="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default function Sale() {
}),
};
return (
<div className="d-flex">
<div className="d-flex" >
<Sidenav />

<div className="dash">
Expand Down

0 comments on commit ade8748

Please sign in to comment.