diff --git a/resources/scripts/admin/views/estimates/View.vue b/resources/scripts/admin/views/estimates/View.vue index fc631891..ba4bad9a 100644 --- a/resources/scripts/admin/views/estimates/View.vue +++ b/resources/scripts/admin/views/estimates/View.vue @@ -23,7 +23,6 @@ estimateData.status === 'DRAFT' && userStore.hasAbilities(abilities.SEND_ESTIMATE) " - :disabled="isSendingEmail" :content-loading="isLoadingEstimate" variant="primary" class="text-sm" @@ -45,7 +44,7 @@ hidden h-full pt-16 - pb-4 + pb-[6.4rem] ml-56 bg-white xl:ml-64 @@ -156,18 +155,17 @@
-
+
- +
+

import { useI18n } from 'vue-i18n' -import { computed, reactive, ref, watch, inject } from 'vue' +import { computed, reactive, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' -import EstimateDropDown from '@/scripts/admin/components/dropdowns/EstimateIndexDropdown.vue' import { debounce } from 'lodash' + import { useEstimateStore } from '@/scripts/admin/stores/estimate' import { useModalStore } from '@/scripts/stores/modal' -import { useNotificationStore } from '@/scripts/stores/notification' import { useDialogStore } from '@/scripts/stores/dialog' import { useUserStore } from '@/scripts/admin/stores/user' + +import EstimateDropDown from '@/scripts/admin/components/dropdowns/EstimateIndexDropdown.vue' import SendEstimateModal from '@/scripts/admin/components/modal-components/SendEstimateModal.vue' import LoadingIcon from '@/scripts/components/icons/LoadingIcon.vue' + import abilities from '@/scripts/admin/stub/abilities' const modalStore = useModalStore() const estimateStore = useEstimateStore() -const notificationStore = useNotificationStore() const dialogStore = useDialogStore() const userStore = useUserStore() const { t } = useI18n() -const utils = inject('$utils') -const id = ref(null) -const count = ref(null) const estimateData = ref(null) -const currency = ref(null) const route = useRoute() const router = useRouter() -const status = ref([ - 'DRAFT', - 'SENT', - 'VIEWED', - 'EXPIRED', - 'ACCEPTED', - 'REJECTED', -]) const isMarkAsSent = ref(false) -const isSendingEmail = ref(false) -const isRequestOnGoing = ref(false) const isSearching = ref(false) const isLoading = ref(false) const isLoadingEstimate = ref(false) +const estimateList = ref(null) +const currentPageNumber = ref(1) +const lastPageNumber = ref(1) +const estimateListSection = ref(null) + const searchData = reactive({ orderBy: null, orderByField: null, @@ -374,14 +361,40 @@ function hasActiveUrl(id) { return route.params.id == id } -async function loadEstimates() { +async function loadEstimates(params, fromScrollListener = false) { + if (isLoading.value) { + return + } + isLoading.value = true - await estimateStore.fetchEstimates(route.params.id) + let response = await estimateStore.fetchEstimates(params) isLoading.value = false - setTimeout(() => { - scrollToEstimate() - }, 500) + estimateList.value = estimateList.value ? estimateList.value : [] + + estimateList.value = [...estimateList.value, ...response.data.data] + + currentPageNumber.value = params ? params.page : 1 + lastPageNumber.value = response.data.meta.last_page + let estimateFound = estimateList.value.find( + (est) => est.id == route.params.id + ) + + if ( + fromScrollListener == false && + !estimateFound && + currentPageNumber.value < lastPageNumber.value + ) { + loadEstimates({ page: ++currentPageNumber.value }) + } + + if (estimateFound) { + setTimeout(() => { + if (fromScrollListener == false) { + scrollToEstimate() + } + }, 500) + } } function scrollToEstimate() { @@ -389,9 +402,24 @@ function scrollToEstimate() { if (el) { el.scrollIntoView({ behavior: 'smooth' }) el.classList.add('shake') + addScrollListener() } } +function addScrollListener() { + estimateListSection.value.addEventListener('scroll', (ev) => { + if ( + ev.target.scrollTop > 0 && + ev.target.scrollTop + ev.target.clientHeight > + ev.target.scrollHeight - 200 + ) { + if (currentPageNumber.value < lastPageNumber.value) { + loadEstimates({ page: ++currentPageNumber.value }, true) + } + } + }) +} + async function loadEstimate() { isLoadingEstimate.value = true let response = await estimateStore.fetchEstimate(route.params.id) diff --git a/resources/scripts/admin/views/expenses/Create.vue b/resources/scripts/admin/views/expenses/Create.vue index a6908d04..1572196d 100644 --- a/resources/scripts/admin/views/expenses/Create.vue +++ b/resources/scripts/admin/views/expenses/Create.vue @@ -416,8 +416,8 @@ function onCurrencyChange(v) { async function searchCategory(search) { let res = await categoryStore.fetchCategories({ search }) if(res.data.data.length>0 && categoryStore.editCategory) { - let checkCategoryExist = res.data.data.find((c) => c.id==categoryStore.editCategory.id) - if(!checkCategoryExist) { + let categoryFound = res.data.data.find((c) => c.id==categoryStore.editCategory.id) + if(!categoryFound) { let edit_category = Object.assign({}, categoryStore.editCategory) res.data.data.unshift(edit_category) } @@ -428,8 +428,8 @@ async function searchCategory(search) { async function searchCustomer(search) { let res = await customerStore.fetchCustomers({ search }) if(res.data.data.length>0 && customerStore.editCustomer) { - let checkCustomerExist = res.data.data.find((c) => c.id==customerStore.editCustomer.id) - if(!checkCustomerExist) { + let customerFound = res.data.data.find((c) => c.id==customerStore.editCustomer.id) + if(!customerFound) { let edit_customer = Object.assign({}, customerStore.editCustomer) res.data.data.unshift(edit_customer) } @@ -463,7 +463,7 @@ async function loadData() { customerStore.editCustomer = expenseData.data.data.customer } } - + } else if (route.query.customer) { expenseStore.currentExpense.customer_id = route.query.customer } diff --git a/resources/scripts/admin/views/invoices/View.vue b/resources/scripts/admin/views/invoices/View.vue index 274cb62e..875b282d 100644 --- a/resources/scripts/admin/views/invoices/View.vue +++ b/resources/scripts/admin/views/invoices/View.vue @@ -1,6 +1,6 @@