fix: mana axios deacoplate
gitea/salix-front/pipeline/pr-master There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2025-02-24 22:46:27 +01:00
parent 7096d6fb81
commit 2655e0a8e5
3 changed files with 37 additions and 54 deletions

View File

@ -1,32 +1,26 @@
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useI18n } from 'vue-i18n';
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { toCurrency } from 'src/filters';
import VnUsesMana from 'components/ui/VnUsesMana.vue';
const $props = defineProps({
mana: {
type: Number,
default: null,
},
newPrice: {
type: Number,
default: 0,
},
usesMana: {
type: Boolean,
default: false,
},
manaCode: {
type: String,
default: 'mana',
},
sale: {
type: Object,
default: null,
},
});
const route = useRoute();
const mana = ref(null);
const usesMana = ref(false);
const emit = defineEmits(['save', 'cancel']);
const { t } = useI18n();
@ -38,20 +32,35 @@ const save = (sale = $props.sale) => {
QPopupProxyRef.value.hide();
};
const getMana = async () => {
const { data } = await axios.get(`Tickets/${route.params.id}/getSalesPersonMana`);
mana.value = data;
await getUsesMana();
};
const getUsesMana = async () => {
const { data } = await axios.get('Sales/usesMana');
usesMana.value = data;
};
const cancel = () => {
emit('cancel');
QPopupProxyRef.value.hide();
};
const hasMana = computed(() => typeof mana.value === 'number');
defineExpose({ save });
</script>
<template>
<QPopupProxy ref="QPopupProxyRef" data-cy="ticketEditManaProxy">
<QPopupProxy
ref="QPopupProxyRef"
@before-show="getMana"
data-cy="ticketEditManaProxy"
>
<div class="container">
<QSpinner v-if="typeof mana === 'number' && mana" color="primary" size="md" />
<div v-else>
<div class="header">Mana: {{ toCurrency(mana) }}</div>
<div class="q-pa-md">
<QSpinner v-if="!hasMana" color="primary" size="md" />
<div class="q-pa-md" v-else>
<slot :popup="QPopupProxyRef" />
<div v-if="usesMana" class="column q-gutter-y-sm q-mt-sm">
<VnUsesMana :mana-code="manaCode" />
@ -63,7 +72,7 @@ defineExpose({ save });
</span>
</div>
</div>
</div>
<div class="row">
<QBtn
color="primary"

View File

@ -44,7 +44,6 @@ const isTicketEditable = ref(false);
const sales = ref([]);
const editableStatesOptions = ref([]);
const selectedSales = ref([]);
const mana = ref(null);
const manaCode = ref('mana');
const ticketState = computed(() => store.data?.ticketState?.state?.code);
const transfer = ref({
@ -258,18 +257,6 @@ const DEFAULT_EDIT = {
oldQuantity: null,
};
const edit = ref({ ...DEFAULT_EDIT });
const usesMana = ref(null);
const getUsesMana = async () => {
const { data } = await axios.get('Sales/usesMana');
usesMana.value = data;
};
const getMana = async () => {
const { data } = await axios.get(`Tickets/${route.params.id}/getSalesPersonMana`);
mana.value = data;
await getUsesMana();
};
const selectedValidSales = computed(() => {
if (!sales.value) return;
@ -277,7 +264,6 @@ const selectedValidSales = computed(() => {
});
const onOpenEditPricePopover = async (sale) => {
await getMana();
edit.value = {
sale: JSON.parse(JSON.stringify(sale)),
price: sale.price,
@ -285,7 +271,6 @@ const onOpenEditPricePopover = async (sale) => {
};
const onOpenEditDiscountPopover = async (sale) => {
await getMana();
if (isLocked.value) return;
if (sale) {
edit.value = {
@ -306,7 +291,6 @@ const changePrice = async (sale) => {
await confirmUpdate(() => updatePrice(sale, newPrice));
} else updatePrice(sale, newPrice);
}
await getMana();
};
const updatePrice = async (sale, newPrice) => {
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
@ -599,9 +583,7 @@ watch(
:is-ticket-editable="isTicketEditable"
:sales="selectedValidSales"
:disable="!hasSelectedRows"
:mana="mana"
:ticket-config="ticketConfig"
@get-mana="getMana()"
@update-discounts="updateDiscounts"
@refresh-table="resetChanges"
/>
@ -829,7 +811,6 @@ watch(
</QBtn>
<TicketEditManaProxy
ref="editPriceProxyRef"
:mana="mana"
:sale="row"
:new-price="getNewPrice"
@save="changePrice"
@ -852,10 +833,8 @@ watch(
<TicketEditManaProxy
ref="editManaProxyRef"
:mana="mana"
:sale="row"
:new-price="getNewPrice"
:uses-mana="usesMana"
:mana-code="manaCode"
@save="changeDiscount"
>

View File

@ -34,10 +34,6 @@ const props = defineProps({
type: Array,
default: () => [],
},
mana: {
type: Number,
default: null,
},
ticketConfig: {
type: Array,
default: () => [],
@ -220,7 +216,6 @@ const createRefund = async (withWarehouse) => {
<TicketEditManaProxy
ref="editManaProxyRef"
:sale="row"
:mana="props.mana"
@save="changeMultipleDiscount"
>
<VnInput