From 673eb10b7bb47c4aaaf64d4d05c98e921f18206e Mon Sep 17 00:00:00 2001 From: patrykb Date: Mon, 1 Jul 2024 17:29:57 +0200 Subject: [PATCH] Some changes --- src/components/MainForm.vue | 14 ++++++++------ src/components/NavBar.vue | 9 ++++++++- src/components/OrdersSelector.vue | 5 ++++- src/main.ts | 13 ++++++++++++- src/stores/user.store.ts | 9 +++++++++ src/views/LoginView.vue | 4 ++++ src/views/MainView.vue | 10 ++++++++-- 7 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/stores/user.store.ts diff --git a/src/components/MainForm.vue b/src/components/MainForm.vue index 46cdc2e..d889408 100644 --- a/src/components/MainForm.vue +++ b/src/components/MainForm.vue @@ -88,8 +88,8 @@ function setConfirmationModal(event : Event) { v-bind:dark = "isDarkTheme"/> - - + +
@@ -105,6 +105,7 @@ function setConfirmationModal(event : Event) { type="text" placeholder="Kwota" v-model="product.Twr_Cena" + v-bind:class="{ 'is-success has-background-light': product.Quantity != undefined && product.Quantity as unknown as string != '' }" />
@@ -115,20 +116,21 @@ function setConfirmationModal(event : Event) { type="text" placeholder="Kwota" v-model="product.Twr_CenaZ" + v-bind:class="{ 'is-success has-background-light': product.Quantity != undefined && product.Quantity as unknown as string != '' }" />

- +

- +

@@ -139,10 +141,10 @@ function setConfirmationModal(event : Event) {
- +
- +
diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index ffcd469..c843d14 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -6,6 +6,7 @@ import { useOrdersStore } from '@/stores/orders.store' import { useContractorsStore } from '@/stores/contractors.store' import { useCategoriesStore } from '@/stores/categories.store' import { storeToRefs } from 'pinia' +import { useUserStore } from '@/stores/user.store' const activator = ref(false); @@ -13,6 +14,9 @@ const siteControlStore = useSiteControlStore(); const ordersStore = useOrdersStore(); const contractorsStore = useContractorsStore(); const categoriesStore = useCategoriesStore(); +const userStore = useUserStore(); + +const { username } = storeToRefs(userStore); function makeBurger() { @@ -83,9 +87,12 @@ function newOrder() { - + diff --git a/src/components/OrdersSelector.vue b/src/components/OrdersSelector.vue index 28c66df..34ea1f4 100644 --- a/src/components/OrdersSelector.vue +++ b/src/components/OrdersSelector.vue @@ -11,6 +11,7 @@ const searchOrderDate = ref(); const isOutOfBuffer = ref(false); const isInBufor = ref(false); const { orders } = storeToRefs(ordersStore); +const areOrdersLoading = ref(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; }