refactor dashboard actions and send email actions

This commit is contained in:
Jay_Makwana
2019-11-18 19:41:31 +05:30
parent 4a8ac36b3a
commit 94d48c76b8
12 changed files with 93 additions and 130 deletions

View File

@ -1,5 +1,5 @@
import * as types from './mutation-types'
// import moment from 'moment'
import * as dashboardTypes from '../dashboard/mutation-types'
export const fetchInvoices = ({ commit, dispatch, state }, params) => {
return new Promise((resolve, reject) => {
@ -47,7 +47,10 @@ export const fetchViewInvoice = ({ commit, dispatch, state }, id) => {
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'})
if (response.data.success) {
commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
commit('dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'}, { root: true })
}
resolve(response)
}).catch((err) => {
reject(err)
@ -83,6 +86,7 @@ export const deleteInvoice = ({ commit, dispatch, state }, id) => {
resolve(response)
} else {
commit(types.DELETE_INVOICE, id)
commit('dashboard/' + dashboardTypes.DELETE_INVOICE, id, { root: true })
resolve(response)
}
}).catch((err) => {
@ -123,6 +127,7 @@ 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'})
commit('dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'}, { root: true })
resolve(response)
}).catch((err) => {
reject(err)