Commit d3245d94 authored by Sumaiyya Burney's avatar Sumaiyya Burney

Adds imgUrl upload+changes field names to match DB

parent 3a3923b2
...@@ -4,13 +4,14 @@ import { useHistory, useLocation } from "react-router"; ...@@ -4,13 +4,14 @@ import { useHistory, useLocation } from "react-router";
const emptyForm = { const emptyForm = {
sku: "", sku: "",
upc: "", upc: "",
prodName: "", productName: "",
brand: "", brand: "",
category: "", category: "",
price: 0.0, price: 0.0,
stock: 0, availableStock: 0,
prodDesc: "", productDescription: "",
productImage: "", productImageUrl: "",
productImage: ""
}; };
ProductForm.defaultProps = { ProductForm.defaultProps = {
...@@ -33,7 +34,7 @@ export default function ProductForm(props) { ...@@ -33,7 +34,7 @@ export default function ProductForm(props) {
if (form.upc.length < 3) { if (form.upc.length < 3) {
errs.push("UPC must be at least 3 characters"); errs.push("UPC must be at least 3 characters");
} }
if (form.prodName.length === 0) { if (form.productName.length === 0) {
errs.push("Please enter a product name"); errs.push("Please enter a product name");
} }
if (form.brand.length === 0) { if (form.brand.length === 0) {
...@@ -45,7 +46,7 @@ export default function ProductForm(props) { ...@@ -45,7 +46,7 @@ export default function ProductForm(props) {
if (Number(form.price) <= 0) { if (Number(form.price) <= 0) {
errs.push("Price must be greater than 0"); errs.push("Price must be greater than 0");
} }
if (Number(form.stock) <= 0) { if (Number(form.availableStock) <= 0) {
errs.push("Stock must be greater than 0"); errs.push("Stock must be greater than 0");
} }
...@@ -126,17 +127,17 @@ export default function ProductForm(props) { ...@@ -126,17 +127,17 @@ export default function ProductForm(props) {
<div className="row mt-3"> <div className="row mt-3">
<div className="col-6"> <div className="col-6">
<div> <div>
<label htmlFor="prodName" className="form-label"> <label htmlFor="productName" className="form-label">
Name Name
</label> </label>
<input <input
required required
name="prodName" name="productName"
type="text" type="text"
className="form-control" className="form-control"
id="prodName" id="productName"
value={form.prodName} value={form.productName}
onChange={(e) => setForm({ ...form, prodName: e.target.value })} onChange={(e) => setForm({ ...form, productName: e.target.value })}
/> />
</div> </div>
<div> <div>
...@@ -169,17 +170,17 @@ export default function ProductForm(props) { ...@@ -169,17 +170,17 @@ export default function ProductForm(props) {
</div> </div>
</div> </div>
<div className="col-6"> <div className="col-6">
<label htmlFor="prodDesc" className="form-label"> <label htmlFor="productDescription" className="form-label">
Description Description
</label> </label>
<textarea <textarea
name="prodDesc" name="productDescription"
id="prodDesc" id="productDescription"
cols="40" cols="40"
rows="7" rows="7"
className="form-control" className="form-control"
value={form.prodDesc} value={form.productDescription}
onChange={(e) => setForm({ ...form, prodDesc: e.target.value })} onChange={(e) => setForm({ ...form, productDescription: e.target.value })}
></textarea> ></textarea>
</div> </div>
</div> </div>
...@@ -208,8 +209,8 @@ export default function ProductForm(props) { ...@@ -208,8 +209,8 @@ export default function ProductForm(props) {
type="number" type="number"
className="form-control" className="form-control"
id="stock" id="stock"
value={form.stock} value={form.availableStock}
onChange={(e) => setForm({ ...form, stock: e.target.value })} onChange={(e) => setForm({ ...form, availableStock: e.target.value })}
/> />
</div> </div>
</div> </div>
...@@ -217,13 +218,22 @@ export default function ProductForm(props) { ...@@ -217,13 +218,22 @@ export default function ProductForm(props) {
<label htmlFor="productImage" className="form-label"> <label htmlFor="productImage" className="form-label">
Product Image Product Image
</label> </label>
<input
id="productImageUrl"
name="productImageUrl"
className="form-control form-control-lg"
type="url"
placeholder="Enter image URL here or upload image below..."
value={form.productImageUrl}
onChange={(e) => setForm({ ...form, productImageUrl: e.target.value, productImage:""})}
></input>
<input <input
id="productImage" id="productImage"
name="productImage" name="productImage"
className="form-control form-control-lg" className="form-control form-control-lg"
type="file" type="file"
value={form.productImage} value={form.productImage}
onChange={(e) => setForm({ ...form, productImage: e.target.value })} onChange={(e) => setForm({ ...form, productImage: e.target.value, productImageUrl:"" })}
></input> ></input>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment