-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
486 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
Oops, something went wrong.