add webapp config
This commit is contained in:
parent
eb52c83829
commit
8cd3034018
@ -26,7 +26,7 @@ SECRET_KEY = 'i(12@f48%x!p8q^4gbn3++@^$g45!os)+3=8p0hf4g)j)5bqmf'
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
# ALLOWED_HOSTS = ["api.app.localhost.pl"]
|
# 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 = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES': [
|
'DEFAULT_PERMISSION_CLASSES': [
|
||||||
|
3
bk_webapp/src/config.js
Normal file
3
bk_webapp/src/config.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
api_url: "http://api.localhost.pl"
|
||||||
|
};
|
@ -11,7 +11,6 @@ import "./AddReceipt.css";
|
|||||||
|
|
||||||
function AddReceipt() {
|
function AddReceipt() {
|
||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
console.log(match.url);
|
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={`${match.url}/list`}>
|
<Route path={`${match.url}/list`}>
|
||||||
|
@ -15,6 +15,7 @@ import { useHistory } from "react-router-dom";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import useGlobal from "../../../../utils/global_state";
|
import useGlobal from "../../../../utils/global_state";
|
||||||
|
import config from "../../../../config";
|
||||||
import "./AddMetadata.css";
|
import "./AddMetadata.css";
|
||||||
|
|
||||||
function AddMetadata() {
|
function AddMetadata() {
|
||||||
@ -38,15 +39,13 @@ function AddMetadata() {
|
|||||||
|
|
||||||
//fetch shops data
|
//fetch shops data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Fetch data...");
|
|
||||||
setShopsLoading(true);
|
setShopsLoading(true);
|
||||||
axios
|
axios
|
||||||
.get("http://127.0.0.1:8000/api/shops/", {
|
.get(`${config.api_url}/api/shops/`, {
|
||||||
headers: { Authorization: `Token ${globalState.auth_token}` }
|
headers: { Authorization: `Token ${globalState.auth_token}` }
|
||||||
})
|
})
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(resp.data);
|
|
||||||
setShops(resp.data);
|
setShops(resp.data);
|
||||||
setShopsLoading(false);
|
setShopsLoading(false);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@ -84,7 +83,7 @@ function AddMetadata() {
|
|||||||
<Input fluid list="shops" placeholder="Wybierz sklep..." />
|
<Input fluid list="shops" placeholder="Wybierz sklep..." />
|
||||||
<datalist id="shops">
|
<datalist id="shops">
|
||||||
{shops.map((shop, index) => (
|
{shops.map((shop, index) => (
|
||||||
<option value={shop.name} />
|
<option key={index} value={shop.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -10,13 +10,9 @@ import {
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import useGlobal from "../../../../utils/global_state";
|
import useGlobal from "../../../../utils/global_state";
|
||||||
|
import config from "../../../../config";
|
||||||
|
|
||||||
function ReceiptEntery(props) {
|
function ReceiptEntery(props) {
|
||||||
// console.log(
|
|
||||||
// props.activeIndex,
|
|
||||||
// props.index,
|
|
||||||
// props.activeIndex === props.index
|
|
||||||
// );
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Accordion.Title
|
<Accordion.Title
|
||||||
@ -52,25 +48,21 @@ function Receipts() {
|
|||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [activeIndex, setActiveIndex] = useState(-1);
|
const [activeIndex, setActiveIndex] = useState(-1);
|
||||||
const [globalState, globalActions] = useGlobal();
|
const [globalState, globalActions] = useGlobal();
|
||||||
// console.log("TOKEN: ", globalState.auth_token);
|
|
||||||
|
|
||||||
const handleClick = (oldIndex, index) => {
|
const handleClick = (oldIndex, index) => {
|
||||||
console.log(oldIndex, index);
|
|
||||||
const newIndex = oldIndex === index ? -1 : index;
|
const newIndex = oldIndex === index ? -1 : index;
|
||||||
setActiveIndex(newIndex);
|
setActiveIndex(newIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
// load data on first render
|
// load data on first render
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Fetch data...");
|
|
||||||
setReceiptsLoading(true);
|
setReceiptsLoading(true);
|
||||||
axios
|
axios
|
||||||
.get("http://localhost:8000/api/receipts/", {
|
.get(`${config.api_url}/api/receipts/`, {
|
||||||
headers: { Authorization: `Token ${globalState.auth_token}` }
|
headers: { Authorization: `Token ${globalState.auth_token}` }
|
||||||
})
|
})
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(resp.data.results);
|
|
||||||
setReceipts(resp.data.results);
|
setReceipts(resp.data.results);
|
||||||
setReceiptsLoading(false);
|
setReceiptsLoading(false);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import globalHook from "use-global-hook";
|
import globalHook from "use-global-hook";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import config from "../config";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
auth_token: "",
|
auth_token: "",
|
||||||
@ -11,7 +12,6 @@ const initialState = {
|
|||||||
const getInitialState = () => {
|
const getInitialState = () => {
|
||||||
const auth_token = localStorage.getItem("user_auth_token");
|
const auth_token = localStorage.getItem("user_auth_token");
|
||||||
const is_authenticated = auth_token ? true : false;
|
const is_authenticated = auth_token ? true : false;
|
||||||
console.log(auth_token, is_authenticated);
|
|
||||||
return { ...initialState, auth_token, is_authenticated };
|
return { ...initialState, auth_token, is_authenticated };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,12 +19,11 @@ const actions = {
|
|||||||
login: (store, { username, password }) => {
|
login: (store, { username, password }) => {
|
||||||
console.log("Try to login...");
|
console.log("Try to login...");
|
||||||
axios
|
axios
|
||||||
.post("http://127.0.0.1:8000/api/auth/login/", {
|
.post(`${config.api_url}/api/auth/login/`, {
|
||||||
username: username,
|
username: username,
|
||||||
password: password
|
password: password
|
||||||
})
|
})
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
console.log(resp.data.token);
|
|
||||||
localStorage.setItem("user_auth_token", resp.data.token);
|
localStorage.setItem("user_auth_token", resp.data.token);
|
||||||
const newToken = resp.data.token;
|
const newToken = resp.data.token;
|
||||||
store.setState({
|
store.setState({
|
||||||
@ -42,17 +41,15 @@ const actions = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
logout: store => {
|
logout: store => {
|
||||||
console.log("store:", store.state.auth_token);
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
"http://127.0.0.1:8000/api/auth/logout/",
|
`${config.api_url}/api/auth/logout/`,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: { Authorization: `Token ${store.state.auth_token}` }
|
headers: { Authorization: `Token ${store.state.auth_token}` }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
console.log(resp.data);
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
store.setState(getInitialState());
|
store.setState(getInitialState());
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user