Commit d281331f authored by John Lam's avatar John Lam

fix to update forms and styles

parent 0b732f3a
...@@ -5,6 +5,7 @@ import ProductIndex from "./ProductIndex"; ...@@ -5,6 +5,7 @@ import ProductIndex from "./ProductIndex";
import SearchResults from "./SearchResults"; import SearchResults from "./SearchResults";
import PromotionNewFormComponent from "./promotionforms/PromotionNewFormComponent"; import PromotionNewFormComponent from "./promotionforms/PromotionNewFormComponent";
import PromotionIndexComponent from "./promo_index/PromotionsIndexComponent"; import PromotionIndexComponent from "./promo_index/PromotionsIndexComponent";
import PromotionUpdateFormComponent from "./promotionforms/UpdatePromotionForm";
export default function Main() { export default function Main() {
...@@ -22,6 +23,7 @@ export default function Main() { ...@@ -22,6 +23,7 @@ export default function Main() {
path="/promos/new" path="/promos/new"
component={PromotionNewFormComponent} component={PromotionNewFormComponent}
></AuthRoute> ></AuthRoute>
<AuthRoute exact path="/promos/:promoId/update" component={PromotionUpdateFormComponent}></AuthRoute>
<AuthRoute exact path="/products" component={ProductIndex}></AuthRoute> <AuthRoute exact path="/products" component={ProductIndex}></AuthRoute>
<AuthRoute path="/promos"> <AuthRoute path="/promos">
<PromotionIndexComponent /> <PromotionIndexComponent />
......
...@@ -15,7 +15,6 @@ export default function PromotionIndexComponent () { ...@@ -15,7 +15,6 @@ export default function PromotionIndexComponent () {
const response = await fetch(`${Config.promotionsUrl}`); const response = await fetch(`${Config.promotionsUrl}`);
const data = await response.json(); const data = await response.json();
setPromoData(data); setPromoData(data);
console.log(data);
} }
const deletePromotion = (promoId) => { const deletePromotion = (promoId) => {
...@@ -28,7 +27,7 @@ export default function PromotionIndexComponent () { ...@@ -28,7 +27,7 @@ export default function PromotionIndexComponent () {
return ( return (
<div> <div>
<div className="promo-container"> <div className="promo-list-container">
<div className="promo-list-container"> <div className="promo-list-container">
<div className="promo-header"> <div className="promo-header">
<h1 className="promo-title"> Promotions</h1> <h1 className="promo-title"> Promotions</h1>
......
...@@ -16,7 +16,6 @@ export default function PromotionNewFormComponent (props) { ...@@ -16,7 +16,6 @@ export default function PromotionNewFormComponent (props) {
const onSubmit = (data) => { const onSubmit = (data) => {
console.log(data)
fetch(`${Config.promotionsUrl}`, { fetch(`${Config.promotionsUrl}`, {
method: "POST", method: "POST",
...@@ -36,20 +35,14 @@ export default function PromotionNewFormComponent (props) { ...@@ -36,20 +35,14 @@ export default function PromotionNewFormComponent (props) {
const loadProducts = async (event) => { const loadProducts = async (event) => {
const data = await getAllProducts(); const data = await getAllProducts();
setproductData(data); setproductData(data);
} }
const onChange = (e, data) => { const onChange = (e, data) => {
console.log(data)
setValue('productSku', data.value) setValue('productSku', data.value)
console.log(productSku)
} }
const productSku = register('productSku', { required: true }) const productSku = register('productSku', { required: true })
return ( return (
<div> <div>
<div className="promo-container"> <div className="promo-container">
...@@ -136,7 +129,7 @@ export default function PromotionNewFormComponent (props) { ...@@ -136,7 +129,7 @@ export default function PromotionNewFormComponent (props) {
{...register("minimumQuantity", { {...register("minimumQuantity", {
valueAsNumber: true, valueAsNumber: true,
required: "minimum quantity is required", required: "minimum quantity is required",
min: { value: 1, message: "discount percentage must be greater than 0" }, min: { value: 1, message: "minimum quantity must be greater than 0" },
})} })}
id="minimumQuantity" id="minimumQuantity"
......
...@@ -16,8 +16,6 @@ export default function PromotionUpdateFormComponent(props) { ...@@ -16,8 +16,6 @@ export default function PromotionUpdateFormComponent(props) {
const [productData, setproductData] = useState([]); const [productData, setproductData] = useState([]);
const onSubmit = (data) => { const onSubmit = (data) => {
console.log(data)
fetch(`${Config.promotionsUrl}/${data.promotionId}`, { fetch(`${Config.promotionsUrl}/${data.promotionId}`, {
method: "PUT", method: "PUT",
headers: { headers: {
...@@ -88,7 +86,6 @@ export default function PromotionUpdateFormComponent(props) { ...@@ -88,7 +86,6 @@ export default function PromotionUpdateFormComponent(props) {
} }
})} /> })} />
{errors.productSku && <p className="form-error">{errors.productSku.message}</p>} {errors.productSku && <p className="form-error">{errors.productSku.message}</p>}
{errors.productSku && console.log(errors) && <p className="form-error">{errors.productSku.message}</p>}
<br></br> <br></br>
</div> </div>
...@@ -124,12 +121,11 @@ export default function PromotionUpdateFormComponent(props) { ...@@ -124,12 +121,11 @@ export default function PromotionUpdateFormComponent(props) {
valueAsNumber: true, valueAsNumber: true,
value: props.location.state.promo.minimumQuantity, value: props.location.state.promo.minimumQuantity,
required: "minimum quantity is required", required: "minimum quantity is required",
min: { value: 1, message: "discount percentage must be greater than 0" }, min: { value: 1, message: "minimum quantity must be greater than 0" },
})} })}
id="minimumQuantity" id="minimumQuantity"
className="form-control" className="form-control"
type="number" type="number"
min="1"
placeholder={props.location.state.promo.minimumQuantity} placeholder={props.location.state.promo.minimumQuantity}
/> />
{errors.minimumQuantity && <p className="form-error">{errors.minimumQuantity.message}</p>} {errors.minimumQuantity && <p className="form-error">{errors.minimumQuantity.message}</p>}
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
margin: 0px auto; margin: 0px auto;
padding: 50px; padding: 50px;
border-radius: 3px; border-radius: 3px;
max-width: 500px;
} }
......
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