(false);
watch(isInBufor, (val) => {
if(val && val == isOutOfBuffer.value) {
@@ -34,11 +35,13 @@ function viewOrder(uuid : string) {
async function fetchOrders(event : Event) {
event.preventDefault();
+ areOrdersLoading.value = true;
if(isInBufor.value) {
orders.value = await ordersStore.fetchOrdersInBuffer();
} else if (isOutOfBuffer.value) {
orders.value = await ordersStore.fetchOrdersOutOfBuffer();
}
+ areOrdersLoading.value = false;
}
@@ -70,7 +73,7 @@ async function fetchOrders(event : Event) {
-
+
diff --git a/src/main.ts b/src/main.ts
index 97a8084..483615a 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -10,13 +10,14 @@ import ConfirmedForm from '@/components/ConfirmedForm.vue'
import LoadingComponent from '@/components/LoadingComponent.vue'
import axios from 'axios'
import LoginModal from '@/components/LoginModal.vue'
-import { createPinia } from 'pinia'
+import { createPinia, storeToRefs } from 'pinia'
import VueCookies from 'vue3-cookies'
import { router } from '@/router/router'
import { useSiteControlStore } from '@/stores/siteControl.store'
import { useCategoriesStore } from '@/stores/categories.store'
import { useOrdersStore } from '@/stores/orders.store'
import { useContractorsStore } from '@/stores/contractors.store'
+import { useUserStore } from '@/stores/user.store'
const app = createApp(App);
const pinia = createPinia();
@@ -34,6 +35,16 @@ export const axiosInstance = axios.create({
withCredentials: true
});
+axiosInstance.interceptors.response.use( (response) => {
+ return response;
+}, (error) => {
+ if (error.response.status == 401) {
+ const userStore = useUserStore();
+ storeToRefs(userStore).username.value = undefined;
+ router.push('/login');
+ }
+});
+
app.component('VueDatePicker', VueDatePicker);
app.component('ConfirmationModal', ConfirmationModal);
app.component('LoginModal', LoginModal);
diff --git a/src/stores/user.store.ts b/src/stores/user.store.ts
new file mode 100644
index 0000000..93d60b4
--- /dev/null
+++ b/src/stores/user.store.ts
@@ -0,0 +1,9 @@
+import { defineStore } from 'pinia'
+import { ref } from 'vue'
+
+
+export const useUserStore = defineStore('user', () => {
+ const username = ref();
+
+ return {username};
+})
\ No newline at end of file
diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue
index 791e6ed..bbd2406 100644
--- a/src/views/LoginView.vue
+++ b/src/views/LoginView.vue
@@ -3,6 +3,8 @@ import { Form, Field } from 'vee-validate';
import * as Yup from 'yup';
import { axiosInstance } from '@/main'
import { router } from '@/router/router'
+import { useUserStore } from '@/stores/user.store'
+import { storeToRefs } from 'pinia'
const schema = Yup.object().shape({
username: Yup.string().required('Nazwa użytkownika jest wymagana'),
@@ -25,6 +27,8 @@ async function onSubmit(values : any, { setErrors } : any) {
}
});
if(body != undefined && body.status == 200) {
+ const userStore = useUserStore();
+ localStorage.setItem("username", username);
await router.push('/');
}
diff --git a/src/views/MainView.vue b/src/views/MainView.vue
index 094072b..40d6aa9 100644
--- a/src/views/MainView.vue
+++ b/src/views/MainView.vue
@@ -24,22 +24,28 @@ import { storeToRefs } from 'pinia'
import { useCategoriesStore } from '@/stores/categories.store'
import { useOrdersStore } from '@/stores/orders.store'
import { useSiteControlStore } from '@/stores/siteControl.store'
+import { useUserStore } from '@/stores/user.store'
const contractorsStore = useContractorsStore();
const categoriesStore = useCategoriesStore();
const ordersStore = useOrdersStore();
const siteControlStore = useSiteControlStore();
+const userStore = useUserStore();
const contractors = storeToRefs(contractorsStore).contractors;
const contractor = storeToRefs(contractorsStore).contractor;
const categories = storeToRefs(categoriesStore).categories;
-
const { uuid, order } = storeToRefs(ordersStore);
-
+const { username } = storeToRefs(userStore);
const { isForm, isOrders, showConfirmationModal, isLoading } = storeToRefs(siteControlStore);
+
async function fetchData() {
await categoriesStore.fetchCategories();
await contractorsStore.fetchContractors();
+ const usernameString = localStorage.getItem("username");
+ if(usernameString != null) {
+ username.value = usernameString;
+ }
isLoading.value = false;
}