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

View File

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