Form validation, navbar improvements, logout functionality, order cancelling
This commit is contained in:
@@ -4,6 +4,7 @@ import { useOrdersStore } from '@/stores/orders.store'
|
|||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useCategoriesStore } from '@/stores/categories.store'
|
import { useCategoriesStore } from '@/stores/categories.store'
|
||||||
import { useContractorsStore } from '@/stores/contractors.store'
|
import { useContractorsStore } from '@/stores/contractors.store'
|
||||||
|
import { axiosInstance } from '@/main'
|
||||||
|
|
||||||
const ordersStore = useOrdersStore();
|
const ordersStore = useOrdersStore();
|
||||||
const categoriesStore = useCategoriesStore();
|
const categoriesStore = useCategoriesStore();
|
||||||
@@ -17,6 +18,7 @@ const { contractor } = storeToRefs(contractorsStore);
|
|||||||
|
|
||||||
function cancelOrder(event: Event) {
|
function cancelOrder(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
axiosInstance.delete('/zamowienie/' + uuid.value);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ function cancelOrder(event: Event) {
|
|||||||
hide-input-icon/>
|
hide-input-icon/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button class="button is-primary" @click="cancelOrder">Anuluj zamówienie</button>
|
<button class="button is-danger" @click="cancelOrder">Anuluj zamówienie</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="category in categories" :key="category.Kod">
|
<div v-for="category in categories" :key="category.Kod">
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { useContractorsStore } from '@/stores/contractors.store'
|
|||||||
import { useOrdersStore } from '@/stores/orders.store'
|
import { useOrdersStore } from '@/stores/orders.store'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useSiteControlStore } from '@/stores/siteControl.store'
|
import { useSiteControlStore } from '@/stores/siteControl.store'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const categoriesStore = useCategoriesStore();
|
const categoriesStore = useCategoriesStore();
|
||||||
const contractorsStore = useContractorsStore();
|
const contractorsStore = useContractorsStore();
|
||||||
@@ -16,6 +17,7 @@ const { contractor, contractors } = storeToRefs(contractorsStore);
|
|||||||
const { deliveryDate, uuid } = storeToRefs(ordersStore);
|
const { deliveryDate, uuid } = storeToRefs(ordersStore);
|
||||||
const { categories } = storeToRefs(categoriesStore);
|
const { categories } = storeToRefs(categoriesStore);
|
||||||
const { showConfirmationModal, isDarkTheme } = storeToRefs(siteControlStore);
|
const { showConfirmationModal, isDarkTheme } = storeToRefs(siteControlStore);
|
||||||
|
const showErrorNotification = ref<boolean>(false);
|
||||||
|
|
||||||
function createJSON(event: Event) {
|
function createJSON(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -31,12 +33,16 @@ function createJSON(event: Event) {
|
|||||||
|
|
||||||
for (let category of categories.value) {
|
for (let category of categories.value) {
|
||||||
for (let product of category.Towary) {
|
for (let product of category.Towary) {
|
||||||
if(product.Quantity != null) {
|
if(product.Quantity != null && product.Quantity != '') {
|
||||||
|
if(isNaN(Number(product.Quantity)) || isNaN(Number(product.Twr_CenaZ)) || isNaN(Number(product.Twr_Cena))) {
|
||||||
|
showErrorNotification.value=true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const productObject : OrderProduct = {
|
const productObject : OrderProduct = {
|
||||||
MZE_TwrId: product.Twr_TwrId,
|
MZE_TwrId: product.Twr_TwrId,
|
||||||
MZE_TwrJm: product.ChosenOption,
|
MZE_TwrJm: product.ChosenOption,
|
||||||
MZE_TwrCena: product.ChosenOption == product.Twr_JMZ ? product.Twr_CenaZ : product.Twr_Cena,
|
MZE_TwrCena: product.ChosenOption == product.Twr_JMZ ? product.Twr_CenaZ : product.Twr_Cena,
|
||||||
MZE_TwrIlosc: product.Quantity.toString(),
|
MZE_TwrIlosc: product.Quantity,
|
||||||
MZE_TwrNazwa: product.Twr_Nazwa,
|
MZE_TwrNazwa: product.Twr_Nazwa,
|
||||||
MZE_MZNID: undefined,
|
MZE_MZNID: undefined,
|
||||||
MZE_MZEID: undefined,
|
MZE_MZEID: undefined,
|
||||||
@@ -46,6 +52,11 @@ function createJSON(event: Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(json.MZamElem.length == 0) {
|
||||||
|
showErrorNotification.value=true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showErrorNotification.value=false;
|
||||||
|
|
||||||
axiosInstance.post('/zamowienie', JSON.stringify(json)).then( response => {
|
axiosInstance.post('/zamowienie', JSON.stringify(json)).then( response => {
|
||||||
uuid.value = response.data.MZN_UUID;
|
uuid.value = response.data.MZN_UUID;
|
||||||
@@ -90,6 +101,10 @@ function setConfirmationModal(event : Event) {
|
|||||||
</div>
|
</div>
|
||||||
<button class="button is-info mt-5">Zapisz</button>
|
<button class="button is-info mt-5">Zapisz</button>
|
||||||
<button class="button is-success mt-5 ml-3" @click="setConfirmationModal">Potwierdź</button>
|
<button class="button is-success mt-5 ml-3" @click="setConfirmationModal">Potwierdź</button>
|
||||||
|
<div v-if="showErrorNotification==true" class="notification is-danger is-light mt-5">
|
||||||
|
<button class="delete" @click.prevent="showErrorNotification = false"></button>
|
||||||
|
W formularzu znajdują się pola, które nie są liczbami, lub wszystkie pola są puste.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="category in categories" :key="category.Kod">
|
<div v-for="category in categories" :key="category.Kod">
|
||||||
@@ -105,7 +120,7 @@ function setConfirmationModal(event : Event) {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Kwota"
|
placeholder="Kwota"
|
||||||
v-model="product.Twr_Cena"
|
v-model="product.Twr_Cena"
|
||||||
v-bind:class="{ 'is-success has-background-light': product.Quantity != undefined && product.Quantity as unknown as string != '' }"
|
v-bind:class="{ 'is-danger has-background-danger-90': product.Twr_Cena != undefined && isNaN(Number(product.Twr_Cena)),'is-success has-background-success-85': product.Quantity != undefined && product.Quantity as unknown as string != '' && !isNaN(Number(product.Quantity))}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -116,21 +131,22 @@ function setConfirmationModal(event : Event) {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Kwota"
|
placeholder="Kwota"
|
||||||
v-model="product.Twr_CenaZ"
|
v-model="product.Twr_CenaZ"
|
||||||
v-bind:class="{ 'is-success has-background-light': product.Quantity != undefined && product.Quantity as unknown as string != '' }"
|
v-bind:class="{ 'is-danger has-background-danger-90': product.Twr_CenaZ != undefined && isNaN(Number(product.Twr_CenaZ)), 'is-success has-background-success-90': product.Quantity != undefined && product.Quantity as unknown as string != '' && !isNaN(Number(product.Quantity))
|
||||||
|
}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<p class="control">
|
<p class="control">
|
||||||
<span class="select is-small" v-bind:class="{ 'is-success has-background-light': product.Quantity != undefined }">
|
<span class="select is-small" v-bind:class="{ 'is-danger has-background-danger-90': product.Quantity != undefined && isNaN(Number(product.Quantity)),'is-success has-background-success-90': product.Quantity != undefined && product.Quantity as unknown as string != '' && !isNaN(Number(product.Quantity))}">
|
||||||
<select v-model="product.ChosenOption" readonly>
|
<select v-model="product.ChosenOption" v-bind:class="{ 'is-danger has-background-danger-90': product.Quantity != undefined && isNaN(Number(product.Quantity)),'is-success has-background-success-90': product.Quantity != undefined && product.Quantity as unknown as string != '' && !isNaN(Number(product.Quantity))}">
|
||||||
<option v-for="option in product.Options" :key="option">{{ option }}</option>
|
<option v-for="option in product.Options" :key="option">{{ option }}</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="control is-expanded">
|
<p class="control is-expanded">
|
||||||
<input class="input is-small" type="text" placeholder="Ilość" v-model="product.Quantity" v-bind:class="{ 'is-success': product.Quantity != undefined }">
|
<input class="input is-small" type="text" placeholder="Ilość" v-model="product.Quantity" v-bind:class="{ 'is-danger has-background-danger-90': product.Quantity != undefined && isNaN(Number(product.Quantity)),'is-success has-background-success-90': product.Quantity != undefined && product.Quantity as unknown as string != '' && !isNaN(Number(product.Quantity))}">
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useContractorsStore } from '@/stores/contractors.store'
|
|||||||
import { useCategoriesStore } from '@/stores/categories.store'
|
import { useCategoriesStore } from '@/stores/categories.store'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useUserStore } from '@/stores/user.store'
|
import { useUserStore } from '@/stores/user.store'
|
||||||
|
import { axiosInstance } from '@/main'
|
||||||
|
|
||||||
const activator = ref(false);
|
const activator = ref(false);
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ function clickOrders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function routeLogin() {
|
function routeLogin() {
|
||||||
|
axiosInstance.post('/logout');
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,17 +61,17 @@ function newOrder() {
|
|||||||
<template>
|
<template>
|
||||||
<nav class="navbar" role="navigation" aria-label="main navigation">
|
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item">
|
<a class="navbar-item is-overflow-hidden" style="max-width: calc(100vw - 50px); white-space: nowrap; overflow: hidden">
|
||||||
<h3 class="title is-3">Mleczarnia</h3>
|
<h3 class="title is-4">Mleczarnia</h3>
|
||||||
|
<h4 v-if="username != undefined" class="subtitle is-4"> {{'- ' + username}}</h4>
|
||||||
</a>
|
</a>
|
||||||
<button @click="makeBurger" class="button navbar-burger" data-target="navMenu" v-bind:class="{ 'is-active': activator }">
|
<button @click="makeBurger" class="button navbar-burger is-pulled-right" data-target="navMenu" v-bind:class="{ 'is-active': activator }">
|
||||||
<span aria-hidden="true"></span>
|
<span aria-hidden="true"></span>
|
||||||
<span aria-hidden="true"></span>
|
<span aria-hidden="true"></span>
|
||||||
<span aria-hidden="true"></span>
|
<span aria-hidden="true"></span>
|
||||||
<span aria-hidden="true"></span>
|
<span aria-hidden="true"></span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="navbar-menu" id="navMenu" v-bind:class="{ 'is-active': activator }">
|
<div class="navbar-menu" id="navMenu" v-bind:class="{ 'is-active': activator }">
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
<a class="navbar-item" @click="clickForm">
|
<a class="navbar-item" @click="clickForm">
|
||||||
@@ -85,13 +87,10 @@ function newOrder() {
|
|||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="button is-info" @click="newOrder">
|
<button class="button is-info" @click="newOrder">
|
||||||
Nowe Zamówienie
|
Nowe Zamówienie
|
||||||
</button>
|
</button>
|
||||||
<button class="button is-light" @click="routeLogin" v-if="username == undefined">
|
<button class="button is-light" @click="routeLogin" >
|
||||||
Log in
|
Wyloguj
|
||||||
</button>
|
|
||||||
<button class="button is-light is-static" @click="routeLogin" v-if="username != undefined">
|
|
||||||
{{ username }}
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ async function fetchOrders(event : Event) {
|
|||||||
<div class="columns is-multiline">
|
<div class="columns is-multiline">
|
||||||
<div class="column is-4" v-for="order in orders" :key="order.MZN_UUID">
|
<div class="column is-4" v-for="order in orders" :key="order.MZN_UUID">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h1 class="mb-3 is-size-7"><b>{{ order.MZN_UUID }}</b></h1>
|
<!-- <h1 class="mb-3 is-size-7"><b>{{ order.MZN_UUID }}</b></h1>-->
|
||||||
<label class="label is-small">Klient</label>
|
<label class="label is-small">Klient</label>
|
||||||
<div class="field is-small mb-3">
|
<div class="field is-small mb-3">
|
||||||
<input class="input is-small is-static"
|
<input class="input is-small is-static"
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export interface Product {
|
|||||||
Twr_TwrId: number,
|
Twr_TwrId: number,
|
||||||
Options: Array<string>,
|
Options: Array<string>,
|
||||||
ChosenOption: string,
|
ChosenOption: string,
|
||||||
Quantity: number
|
Quantity: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Contractor {
|
export interface Contractor {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export const useSiteControlStore = defineStore('siteControl', () => {
|
|||||||
const isDarkTheme = ref<boolean>(false);
|
const isDarkTheme = ref<boolean>(false);
|
||||||
const isLoading = ref<boolean>(true);
|
const isLoading = ref<boolean>(true);
|
||||||
|
|
||||||
|
|
||||||
function switchToFrom() {
|
function switchToFrom() {
|
||||||
if(!isForm.value) {
|
if(!isForm.value) {
|
||||||
isForm.value = true;
|
isForm.value = true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ref } from 'vue'
|
|||||||
|
|
||||||
export const useUserStore = defineStore('user', () => {
|
export const useUserStore = defineStore('user', () => {
|
||||||
const username = ref<string>();
|
const username = ref<string>();
|
||||||
|
const logoutButtonText = ref<string>();
|
||||||
|
|
||||||
return {username};
|
return {username, logoutButtonText};
|
||||||
})
|
})
|
||||||
@@ -23,12 +23,13 @@ async function onSubmit(values : any, { setErrors } : any) {
|
|||||||
console.log(error.response);
|
console.log(error.response);
|
||||||
if(error.response.status == 401) {
|
if(error.response.status == 401) {
|
||||||
setErrors({ apiError: "unauthorized" })
|
setErrors({ apiError: "unauthorized" })
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(body != undefined && body.status == 200) {
|
if(body != undefined && body.status == 200) {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
localStorage.setItem("username", username);
|
localStorage.setItem("username", body.data.displayName);
|
||||||
|
storeToRefs(userStore).username = body.data.displayName;
|
||||||
|
storeToRefs(userStore).logoutButtonText = body.data.displayName;
|
||||||
await router.push('/');
|
await router.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user