From 8cd3034018a7f261710caa446aad7391740623ab Mon Sep 17 00:00:00 2001 From: Stanislaw-Golebiewski Date: Sat, 18 Jan 2020 10:58:37 +0100 Subject: [PATCH] add webapp config --- bk_api/bk_api/settings.py | 2 +- bk_webapp/src/config.js | 3 +++ bk_webapp/src/screens/AddReceipt/AddReceipt.jsx | 1 - .../subscreens/AddMetadata/AddMetadata.jsx | 7 +++---- .../screens/Digest/subscreens/Receipts/Receipts.jsx | 12 ++---------- bk_webapp/src/utils/global_state.js | 9 +++------ 6 files changed, 12 insertions(+), 22 deletions(-) create mode 100644 bk_webapp/src/config.js diff --git a/bk_api/bk_api/settings.py b/bk_api/bk_api/settings.py index d79fb4d..4533073 100644 --- a/bk_api/bk_api/settings.py +++ b/bk_api/bk_api/settings.py @@ -26,7 +26,7 @@ SECRET_KEY = 'i(12@f48%x!p8q^4gbn3++@^$g45!os)+3=8p0hf4g)j)5bqmf' DEBUG = True # ALLOWED_HOSTS = ["api.app.localhost.pl"] -ALLOWED_HOSTS = ["app.localhost.pl", "127.0.0.1", "localhost"] +ALLOWED_HOSTS = ["api.localhost.pl", "127.0.0.1", "localhost"] REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ diff --git a/bk_webapp/src/config.js b/bk_webapp/src/config.js new file mode 100644 index 0000000..07df352 --- /dev/null +++ b/bk_webapp/src/config.js @@ -0,0 +1,3 @@ +export default { + api_url: "http://api.localhost.pl" +}; diff --git a/bk_webapp/src/screens/AddReceipt/AddReceipt.jsx b/bk_webapp/src/screens/AddReceipt/AddReceipt.jsx index 4142725..388f753 100644 --- a/bk_webapp/src/screens/AddReceipt/AddReceipt.jsx +++ b/bk_webapp/src/screens/AddReceipt/AddReceipt.jsx @@ -11,7 +11,6 @@ import "./AddReceipt.css"; function AddReceipt() { const match = useRouteMatch(); - console.log(match.url); return ( diff --git a/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx b/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx index f5683f3..954ff63 100644 --- a/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx +++ b/bk_webapp/src/screens/AddReceipt/subscreens/AddMetadata/AddMetadata.jsx @@ -15,6 +15,7 @@ import { useHistory } from "react-router-dom"; import axios from "axios"; import useGlobal from "../../../../utils/global_state"; +import config from "../../../../config"; import "./AddMetadata.css"; function AddMetadata() { @@ -38,15 +39,13 @@ function AddMetadata() { //fetch shops data useEffect(() => { - console.log("Fetch data..."); setShopsLoading(true); axios - .get("http://127.0.0.1:8000/api/shops/", { + .get(`${config.api_url}/api/shops/`, { headers: { Authorization: `Token ${globalState.auth_token}` } }) .then(resp => { setTimeout(() => { - console.log(resp.data); setShops(resp.data); setShopsLoading(false); }, 1000); @@ -84,7 +83,7 @@ function AddMetadata() { {shops.map((shop, index) => ( - diff --git a/bk_webapp/src/screens/Digest/subscreens/Receipts/Receipts.jsx b/bk_webapp/src/screens/Digest/subscreens/Receipts/Receipts.jsx index c7afef8..5e42be7 100644 --- a/bk_webapp/src/screens/Digest/subscreens/Receipts/Receipts.jsx +++ b/bk_webapp/src/screens/Digest/subscreens/Receipts/Receipts.jsx @@ -10,13 +10,9 @@ import { import axios from "axios"; import useGlobal from "../../../../utils/global_state"; +import config from "../../../../config"; function ReceiptEntery(props) { - // console.log( - // props.activeIndex, - // props.index, - // props.activeIndex === props.index - // ); return (
{ - console.log(oldIndex, index); const newIndex = oldIndex === index ? -1 : index; setActiveIndex(newIndex); }; // load data on first render useEffect(() => { - console.log("Fetch data..."); setReceiptsLoading(true); axios - .get("http://localhost:8000/api/receipts/", { + .get(`${config.api_url}/api/receipts/`, { headers: { Authorization: `Token ${globalState.auth_token}` } }) .then(resp => { setTimeout(() => { - console.log(resp.data.results); setReceipts(resp.data.results); setReceiptsLoading(false); }, 1000); diff --git a/bk_webapp/src/utils/global_state.js b/bk_webapp/src/utils/global_state.js index 42737ce..7d3d091 100644 --- a/bk_webapp/src/utils/global_state.js +++ b/bk_webapp/src/utils/global_state.js @@ -1,6 +1,7 @@ import React from "react"; import globalHook from "use-global-hook"; import axios from "axios"; +import config from "../config"; const initialState = { auth_token: "", @@ -11,7 +12,6 @@ const initialState = { const getInitialState = () => { const auth_token = localStorage.getItem("user_auth_token"); const is_authenticated = auth_token ? true : false; - console.log(auth_token, is_authenticated); return { ...initialState, auth_token, is_authenticated }; }; @@ -19,12 +19,11 @@ const actions = { login: (store, { username, password }) => { console.log("Try to login..."); axios - .post("http://127.0.0.1:8000/api/auth/login/", { + .post(`${config.api_url}/api/auth/login/`, { username: username, password: password }) .then(resp => { - console.log(resp.data.token); localStorage.setItem("user_auth_token", resp.data.token); const newToken = resp.data.token; store.setState({ @@ -42,17 +41,15 @@ const actions = { }); }, logout: store => { - console.log("store:", store.state.auth_token); axios .post( - "http://127.0.0.1:8000/api/auth/logout/", + `${config.api_url}/api/auth/logout/`, {}, { headers: { Authorization: `Token ${store.state.auth_token}` } } ) .then(resp => { - console.log(resp.data); localStorage.clear(); store.setState(getInitialState()); })