Skip to content

Commit

Permalink
done!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Emorgan12 committed Sep 25, 2024
1 parent c5114b4 commit 791b649
Show file tree
Hide file tree
Showing 11 changed files with 486 additions and 55 deletions.
13 changes: 13 additions & 0 deletions inventory-managment/buy-sell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="src/styles.css">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="src/buy-sell.jsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion inventory-managment/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" href="src/edit.jsx"></script>
<script type="module" src="src/edit.jsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion inventory-managment/inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" href="src/inventory.jsx"></script>
<script type="module" src="src/inventory.jsx"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion inventory-managment/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BASE_URL = 'http://localhost:5001/inventory';
const BASE_URL = 'http://127.0.0.1:5001/inventory';

export default BASE_URL;

13 changes: 13 additions & 0 deletions inventory-managment/reports.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="src/styles.css">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="src/reports.jsx"></script>
</body>
</html>
81 changes: 78 additions & 3 deletions inventory-managment/src/buy-sell.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
import BASE_URL from "../main";
import React from "react";
import reactDOM from "react-dom";
import { useState } from "react";
import BASE_URL from "../main";

function BuySell() {
const [products, setProducts] = useState([]);
const [error, setError] = useState('');
const [quantity, setQuantity] = useState(0);
const [id, setId] = useState('');

const handlePurchase = (e) => {
e.preventDefault();
fetch(`${BASE_URL}/${id}, ${quantity}/buy`, {
method: 'PUT',
})
.then((response) => {
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return response.json();
})
.then((data) => {
console.log('Success:', data);
alert('Purchase successful');
})
.catch((error) => {
console.error('Error:', error);
setError(error.message);
});
}

const handleSell = (e) => {
e.preventDefault();
fetch(`${BASE_URL}/${id}, ${quantity}/sell`, {
method: 'PUT',
})
.then((response) => {
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return response.json();
})
.then((data) => {
console.log('Success:', data);
alert('Sale successful');
})
.catch((error) => {
console.error('Error:', error);
setError(error.message);
});
}


return (
<div className="container">
<form>
<div>
<label htmlFor="id">Product ID:</label>
<input type="text" id="id" value={id} onChange={(e) => setId((e.target.value))} required />
</div>
<div>
<label htmlFor="quantity">Quantity:</label>
<input type="number" id="quantity" value={quantity} onChange={(e) => setQuantity(parseInt(e.target.value))} required />
</div>
<div className="container">
<button onClick={handlePurchase} className= "buy-sell-btn">Purchase</button>
<button onClick={handleSell} className= "buy-sell-btn">Sell</button>
</div>
</form>
<a href="index.html">Home</a>
</div>


)
}

reactDOM.render(<BuySell />, document.getElementById("app"));
Loading

0 comments on commit 791b649

Please sign in to comment.