import {events} from '@/bus' import axios from "axios" import Vue from "vue" const defaultState = {} const actions = { getRegularInvoices: ({commit, getters}) => { commit('LOADING_STATE', {loading: true, data: []}) commit('STORE_CURRENT_FOLDER', { name: 'Invoices', id: undefined, location: 'regular-invoice', }) axios .get('/api/oasis/invoices/regular') .then(response => { commit('LOADING_STATE', {loading: false, data: response.data}) }) .catch(() => { Vue.prototype.$isSomethingWrong() }) .finally(() => { events.$emit('scrollTop') }) }, getAdvanceInvoices: ({commit, getters}) => { commit('LOADING_STATE', {loading: true, data: []}) commit('STORE_CURRENT_FOLDER', { name: 'Advance Invoices', id: undefined, location: 'advance-invoice', }) axios .get('/api/oasis/invoices/advance') .then(response => { commit('LOADING_STATE', {loading: false, data: response.data}) }) .catch(() => { Vue.prototype.$isSomethingWrong() }) .finally(() => { events.$emit('scrollTop') }) }, getClients: ({commit, getters}) => { commit('LOADING_STATE', {loading: true, data: []}) commit('STORE_CURRENT_FOLDER', { name: 'Clients', id: undefined, location: 'clients', }) axios .get('/api/oasis/clients') .then(response => { commit('LOADING_STATE', {loading: false, data: response.data}) }) .catch(() => { Vue.prototype.$isSomethingWrong() }) .finally(() => { events.$emit('scrollTop') }) }, getSearchResultForInvoices: ({commit, getters}, query) => { commit('LOADING_STATE', {loading: true, data: []}) commit('CHANGE_SEARCHING_STATE', true) axios .get('/api/oasis/invoices/search', { params: { query: query, type: getters.currentFolder.location, } }) .then(response => { commit('LOADING_STATE', {loading: false, data: response.data}) }) .catch(() => Vue.prototype.$isSomethingWrong()) }, getSearchResultForClients: ({commit, getters}, query) => { commit('LOADING_STATE', {loading: true, data: []}) commit('CHANGE_SEARCHING_STATE', true) axios .get('/api/oasis/clients/search', { params: {query: query} }) .then(response => { commit('LOADING_STATE', {loading: false, data: response.data}) }) .catch(() => Vue.prototype.$isSomethingWrong()) }, deleteClient: ({commit, getters}, payload) => { // }, deleteInvoice: ({commit, getters}, payload) => { // }, deleteAdvanceInvoice: ({commit, getters}, payload) => { // }, sendInvoice: ({commit, getters}, payload) => { // }, } const mutations = {} const getters = {} export default { state: defaultState, getters, actions, mutations }