diff --git a/bk_webapp/src/config.js b/bk_webapp/src/config.js
index 07df352..b0c88fc 100644
--- a/bk_webapp/src/config.js
+++ b/bk_webapp/src/config.js
@@ -1,3 +1,3 @@
export default {
- api_url: "http://api.localhost.pl"
+ api_url: "http://127.0.0.1:8000"
};
diff --git a/bk_webapp/src/screens/AddReceipt/components/ProductTile/ProductTile.jsx b/bk_webapp/src/screens/AddReceipt/components/ProductTile/ProductTile.jsx
index d9de41b..4c9af5d 100644
--- a/bk_webapp/src/screens/AddReceipt/components/ProductTile/ProductTile.jsx
+++ b/bk_webapp/src/screens/AddReceipt/components/ProductTile/ProductTile.jsx
@@ -10,7 +10,8 @@ function ProductTile(props) {
{
- setClicked(!clicked);
+ // setClicked(!clicked);
+ props.onClick();
}}
>
diff --git a/bk_webapp/src/screens/AddReceipt/components/index.js b/bk_webapp/src/screens/AddReceipt/components/index.js
index 169f9c1..13fdc24 100644
--- a/bk_webapp/src/screens/AddReceipt/components/index.js
+++ b/bk_webapp/src/screens/AddReceipt/components/index.js
@@ -1,4 +1,5 @@
import ProductTile from "./ProductTile/ProductTile";
import ModalConfirm from "./ModalConfirm/ModalConfirm";
+import ModalProduct from "./ModalProduct/ModalProduct";
-export { ProductTile, ModalConfirm };
+export { ProductTile, ModalConfirm, ModalProduct };
diff --git a/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx b/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx
index 954ff63..bf78cf8 100644
--- a/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx
+++ b/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx
@@ -26,6 +26,7 @@ function AddMetadata() {
const [shops, setShops] = useState([]);
const [shopsLoading, setShopsLoading] = useState(true);
const [globalState, globalActions] = useGlobal();
+ const [pickedShop, changePickedShop] = useState("");
const uploadPhoto = event => {
setSelectedFile(URL.createObjectURL(event.target.files[0]));
@@ -59,6 +60,11 @@ function AddMetadata() {
const handleDateChange = (event, { name, value }) => {
setPickedDate(value);
};
+
+ const handleShopChange = event => {
+ console.log(event.target.value);
+ changePickedShop(event.target.value);
+ };
return (
diff --git a/bk_webapp/src/screens/AddReceipt/subscreens/ProductsList/ProductsList.jsx b/bk_webapp/src/screens/AddReceipt/subscreens/ProductsList/ProductsList.jsx
index 85f5369..f74ec25 100644
--- a/bk_webapp/src/screens/AddReceipt/subscreens/ProductsList/ProductsList.jsx
+++ b/bk_webapp/src/screens/AddReceipt/subscreens/ProductsList/ProductsList.jsx
@@ -2,27 +2,63 @@ import React, { useState } from "react";
import { Button, Container, Icon, Menu } from "semantic-ui-react";
import { useHistory } from "react-router-dom";
+import axios from "axios";
+
import { fake_product } from "../../../../utils/gen_fake_data";
-import { ProductTile, ModalConfirm } from "../../components";
+import config from "../../../../config";
+import useGlobal from "../../../../utils/global_state";
+import { ProductTile, ModalConfirm, ModalProduct } from "../../components";
import "./ProductsList.css";
function ProductsList() {
const [products, setProducts] = useState([]);
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
+ const [productModalOpen, setProductModalOpen] = useState(false);
+ const [globalState, globalActions] = useGlobal();
+
+ // none, edit, add
+ const [productModalMode, setProductModalMode] = useState("none");
+ const [pickedProduct, setPickedProduct] = useState(-1);
const history = useHistory();
- console.log(history.location.state);
+ const meta_info = history.location.state;
const addItem = item => {
setProducts([...products, item]);
};
+ const updateItem = (item, index) => {
+ console.log(`Update item ${index} to ${item.name} ${item.price}`);
+ products[index] = item;
+ };
+
const removeItem = index => {
const new_products = [...products];
new_products.splice(index, 1);
setProducts([...new_products]);
};
+ const openProductModal = (mode, picked_index = -1) => {
+ setPickedProduct(picked_index);
+ setProductModalMode(mode);
+ setProductModalOpen(true);
+ };
+
+ const closeProductModal = () => {
+ setProductModalMode("none");
+ setProductModalOpen(false);
+ };
+
+ const handleConfirmProduct = (item, is_in_edit_mode) => {
+ if (is_in_edit_mode) {
+ updateItem(item, pickedProduct);
+ } else {
+ console.log("add new product!", item);
+ addItem(item);
+ }
+ setProductModalOpen(false);
+ };
+
const openConfirmModal = () => {
setConfirmModalOpen(true);
};
@@ -31,7 +67,23 @@ function ProductsList() {
};
const handleConfirm = () => {
- history.push("/home");
+ const new_receipt = {
+ date: meta_info.date,
+ shop: { name: meta_info.shop, tags: [] },
+ products
+ };
+ console.log(new_receipt);
+ axios
+ .post(`${config.api_url}/api/receipts/`, new_receipt, {
+ headers: { Authorization: `Token ${globalState.auth_token}` }
+ })
+ .then(resp => {
+ console.log(resp);
+ history.push("/home");
+ })
+ .catch(err => {
+ console.log(err);
+ });
};
return (
@@ -50,6 +102,9 @@ function ProductsList() {
number={index + 1}
name={product.name}
price={product.price}
+ onClick={() => {
+ openProductModal("edit", index);
+ }}
onRemove={() => {
removeItem(index);
}}
@@ -65,7 +120,8 @@ function ProductsList() {
icon
color="green"
onClick={() => {
- addItem(fake_product());
+ // addItem(fake_product());
+ openProductModal("add", -1);
}}
className="add-product-btn"
>
@@ -90,6 +146,19 @@ function ProductsList() {
onClose={closeConfirmModal}
onConfirm={handleConfirm}
/>
+
+
{
+ setPickedProduct(-1);
+ closeProductModal();
+ removeItem(pickedProduct);
+ }}
+ />
);
}
@@ -97,6 +166,7 @@ function ProductsList() {
function sum_products_prices(products) {
let sum = 0;
products.forEach(prod => (sum += prod.price));
+ sum.toFixed(2);
return sum;
}
diff --git a/bk_webapp/src/screens/Login/Login.jsx b/bk_webapp/src/screens/Login/Login.jsx
index 824777b..062e799 100644
--- a/bk_webapp/src/screens/Login/Login.jsx
+++ b/bk_webapp/src/screens/Login/Login.jsx
@@ -41,7 +41,7 @@ function Login() {
fluid
icon="user"
iconPosition="left"
- placeholder="Nawa użytkownika"
+ placeholder="Nazwa użytkownika"
onChange={e => {
setUsername(e.target.value);
}}