feat: added composable to confirm orders

This commit is contained in:
Jon Elias 2024-10-28 12:21:26 +01:00
parent 37b3affdbf
commit 17b1921af6
3 changed files with 44 additions and 27 deletions

View File

@ -0,0 +1,22 @@
import axios from 'axios';
import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
export function confirmOrder() {
const quasar = useQuasar();
const { t } = useI18n();
async function confirm(route) {
const { data } = await axios.post(`Orders/${route}/confirm`);
if (data) {
quasar.notify({
message: t('globals.confirm'),
type: 'positive',
});
return data;
}
return null;
}
return { confirm };
}

View File

@ -6,6 +6,7 @@ import { useQuasar } from 'quasar';
import axios from 'axios';
import { useStateStore } from 'stores/useStateStore';
import { useArrayData } from 'composables/useArrayData';
import { confirmOrder } from 'composables/confirmOrder';
import { toCurrency, toDate } from 'src/filters';
import VnConfirm from 'components/ui/VnConfirm.vue';
@ -31,7 +32,7 @@ const orderSummary = ref({
});
const getTotalRef = ref();
const getVATRef = ref();
const { confirm } = confirmOrder();
const lineFilter = ref({
include: [
{
@ -204,20 +205,17 @@ async function remove(item) {
getVATRef.value.fetch();
}
async function confirmOrder() {
await axios.post(`Orders/${route.params.id}/confirm`);
quasar.notify({
message: t('globals.confirm'),
type: 'positive',
});
router.push({
name: 'TicketList',
query: {
table: JSON.stringify({ clientFk: descriptorData.store.data.clientFk }),
},
});
async function handleConfirm() {
const result = await confirm(route.params.id);
if (result) {
router.push({
name: 'TicketList',
query: {
table: JSON.stringify({ clientFk: descriptorData.store.data.clientFk }),
},
});
}
}
watch(
() => router.currentRoute.value.params.id,
() => {
@ -314,7 +312,7 @@ watch(
</template>
</VnTable>
<QPageSticky :offset="[20, 20]" v-if="!order?.isConfirmed" style="z-index: 2">
<QBtn fab icon="check" color="primary" @click="confirmOrder()" />
<QBtn fab icon="check" color="primary" @click="handleConfirm()" />
<QTooltip>
{{ t('confirm') }}
</QTooltip>

View File

@ -2,10 +2,9 @@
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useQuasar } from 'quasar';
import axios from 'axios';
import { dashIfEmpty, toCurrency, toDateHourMinSec } from 'src/filters';
import { useArrayData } from 'composables/useArrayData';
import { confirmOrder } from 'composables/confirmOrder';
import VnLv from 'components/ui/VnLv.vue';
import CardSummary from 'components/ui/CardSummary.vue';
import CustomerDescriptorProxy from 'pages/Customer/Card/CustomerDescriptorProxy.vue';
@ -25,8 +24,8 @@ const $props = defineProps({
const entityId = computed(() => $props.id || route.params.id);
const summary = ref();
const quasar = useQuasar();
const descriptorData = useArrayData('orderData');
const { confirm } = confirmOrder();
const detailsColumns = ref([
{
name: 'item',
@ -56,14 +55,12 @@ const detailsColumns = ref([
},
]);
async function confirmOrder() {
await axios.post(`Orders/${route.params.id}/confirm`);
quasar.notify({
message: t('globals.confirm'),
type: 'positive',
});
summary.value.fetch({});
descriptorData.fetch({});
async function handleConfirm() {
const result = await confirm(route.params.id);
if (result) {
summary.value.fetch({});
descriptorData.fetch({});
}
}
</script>
@ -84,7 +81,7 @@ async function confirmOrder() {
text-color="white"
:disabled="isConfirmed"
:label="t('order.summary.confirm')"
@click="confirmOrder()"
@click="handleConfirm()"
>
<QTooltip>{{ t('order.summary.confirmLines') }}</QTooltip>
</QBtn>