add webapp config

This commit is contained in:
Stanislaw-Golebiewski 2020-01-18 10:58:37 +01:00
parent eb52c83829
commit 8cd3034018
6 changed files with 12 additions and 22 deletions

View File

@ -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': [

3
bk_webapp/src/config.js Normal file
View File

@ -0,0 +1,3 @@
export default {
api_url: "http://api.localhost.pl"
};

View File

@ -11,7 +11,6 @@ import "./AddReceipt.css";
function AddReceipt() {
const match = useRouteMatch();
console.log(match.url);
return (
<Switch>
<Route path={`${match.url}/list`}>

View File

@ -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() {
<Input fluid list="shops" placeholder="Wybierz sklep..." />
<datalist id="shops">
{shops.map((shop, index) => (
<option value={shop.name} />
<option key={index} value={shop.name} />
))}
</datalist>
</Container>

View File

@ -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 (
<div>
<Accordion.Title
@ -52,25 +48,21 @@ function Receipts() {
const [page, setPage] = useState(1);
const [activeIndex, setActiveIndex] = useState(-1);
const [globalState, globalActions] = useGlobal();
// console.log("TOKEN: ", globalState.auth_token);
const handleClick = (oldIndex, index) => {
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);

View File

@ -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());
})