diff --git a/resources/assets/js/store/modules/dashboard/actions.js b/resources/assets/js/store/modules/dashboard/actions.js index 4561e11c..83bac228 100644 --- a/resources/assets/js/store/modules/dashboard/actions.js +++ b/resources/assets/js/store/modules/dashboard/actions.js @@ -3,7 +3,7 @@ import * as types from './mutation-types' export const loadData = ({ commit, dispatch, state }, params) => { return new Promise((resolve, reject) => { - window.axios.get(`/api/dashboard`, {params}).then((response) => { + window.axios.get(`/api/dashboard`, { params }).then((response) => { commit(types.SET_INITIAL_DATA, response.data) commit(types.GET_INITIAL_DATA, true) resolve(response) @@ -23,3 +23,108 @@ export const getChart = ({ commit, dispatch, state }) => { }) }) } + +export const sendEmail = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/invoices/send`, data).then((response) => { + commit(types.UPDATE_INVOICE_STATUS, { id: data.id, status: 'SENT' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + + +export const markAsSent = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/invoices/mark-as-sent`, data).then((response) => { + commit(types.UPDATE_INVOICE_STATUS, { id: data.id, status: 'SENT' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const deleteInvoice = ({ commit, dispatch, state }, id) => { + return new Promise((resolve, reject) => { + window.axios.delete(`/api/invoices/${id}`).then((response) => { + if (response.data.error) { + resolve(response) + } else { + commit(types.DELETE_INVOICE, id) + resolve(response) + } + }).catch((err) => { + reject(err) + }) + }) +} + + +export const sendEstimateEmail = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/estimates/send`, data).then((response) => { + commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const markAsAccepted = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/estimates/accept`, data).then((response) => { + commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'ACCEPTED' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const markAsRejected = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/estimates/reject`, data).then((response) => { + commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'REJECTED' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const markEstimateAsSent = ({ commit, dispatch, state }, data) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/estimates/mark-as-sent`, data).then((response) => { + commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const convertToInvoice = ({ commit, dispatch, state }, id) => { + return new Promise((resolve, reject) => { + window.axios.post(`/api/estimates/${id}/convert-to-invoice`).then((response) => { + // commit(types.UPDATE_INVOICE, response.data) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} + +export const deleteEstimate = ({ commit, dispatch, state }, id) => { + return new Promise((resolve, reject) => { + window.axios.delete(`/api/estimates/${id}`).then((response) => { + commit(types.DELETE_ESTIMATE, id) + resolve(response) + }).catch((err) => { + reject(err) + }) + }) +} \ No newline at end of file diff --git a/resources/assets/js/store/modules/dashboard/mutation-types.js b/resources/assets/js/store/modules/dashboard/mutation-types.js index aae91da8..079dec9f 100644 --- a/resources/assets/js/store/modules/dashboard/mutation-types.js +++ b/resources/assets/js/store/modules/dashboard/mutation-types.js @@ -1,2 +1,6 @@ export const SET_INITIAL_DATA = 'SET_INITIAL_DATA' export const GET_INITIAL_DATA = 'GET_INITIAL_DATA' +export const DELETE_INVOICE = 'DELETE_INVOICE' +export const UPDATE_INVOICE_STATUS = 'UPDATE_INVOICE_STATUS' +export const DELETE_ESTIMATE = 'DELETE_ESTIMATE' +export const UPDATE_ESTIMATE_STATUS = 'UPDATE_ESTIMATE_STATUS' \ No newline at end of file diff --git a/resources/assets/js/store/modules/dashboard/mutations.js b/resources/assets/js/store/modules/dashboard/mutations.js index 12d2b8d1..64271f42 100644 --- a/resources/assets/js/store/modules/dashboard/mutations.js +++ b/resources/assets/js/store/modules/dashboard/mutations.js @@ -1,7 +1,7 @@ import * as types from './mutation-types' export default { - [types.SET_INITIAL_DATA] (state, data) { + [types.SET_INITIAL_DATA](state, data) { state.contacts = data.customersCount state.invoices = data.invoicesCount state.estimates = data.estimatesCount @@ -30,7 +30,29 @@ export default { state.netProfit = data.netProfit }, - [types.GET_INITIAL_DATA] (state, data) { + [types.GET_INITIAL_DATA](state, data) { state.isDataLoaded = data - } + }, + + [types.UPDATE_INVOICE_STATUS](state, data) { + let pos = state.dueInvoices.findIndex(invoice => invoice.id === data.id) + + state.dueInvoices[pos].status = data.status + }, + + [types.DELETE_INVOICE](state, id) { + let index = state.dueInvoices.findIndex(invoice => invoice.id === id) + state.dueInvoices.splice(index, 1) + }, + + [types.DELETE_ESTIMATE](state, id) { + let index = state.recentEstimates.findIndex(estimate => estimate.id === id) + state.recentEstimates.splice(index, 1) + }, + + [types.UPDATE_ESTIMATE_STATUS](state, data) { + let pos = state.recentEstimates.findIndex(estimate => estimate.id === data.id) + + state.recentEstimates[pos].status = data.status + }, } diff --git a/resources/assets/js/views/dashboard/Dashboard.vue b/resources/assets/js/views/dashboard/Dashboard.vue index 568a62bf..fac1dfd0 100644 --- a/resources/assets/js/views/dashboard/Dashboard.vue +++ b/resources/assets/js/views/dashboard/Dashboard.vue @@ -160,7 +160,7 @@