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,4 +1,5 @@
import * as types from './mutation-types'
import * as dashboardTypes from '../dashboard/mutation-types'
export const fetchEstimates = ({ commit, dispatch, state }, params) => {
return new Promise((resolve, reject) => {
@ -56,7 +57,10 @@ export const fetchViewEstimate = ({ commit, dispatch, state }, id) => {
export const sendEmail = ({ 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'})
if (response.data.success) {
commit(types.UPDATE_ESTIMATE_STATUS, {id: data.id, status: 'SENT'})
commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }, { root: true })
}
resolve(response)
}).catch((err) => {
reject(err)
@ -80,6 +84,7 @@ 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)
commit('dashboard/' + dashboardTypes.DELETE_ESTIMATE, id, { root: true })
resolve(response)
}).catch((err) => {
reject(err)
@ -112,6 +117,7 @@ export const updateEstimate = ({ commit, dispatch, state }, data) => {
export const markAsAccepted = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.post(`/api/estimates/accept`, data).then((response) => {
commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'ACCEPTED' }, { root: true })
resolve(response)
}).catch((err) => {
reject(err)
@ -122,6 +128,7 @@ export const markAsAccepted = ({ commit, dispatch, state }, data) => {
export const markAsRejected = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.post(`/api/estimates/reject`, data).then((response) => {
commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'REJECTED' }, { root: true })
resolve(response)
}).catch((err) => {
reject(err)
@ -133,6 +140,7 @@ export const markAsSent = ({ 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'})
commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }, { root: true })
resolve(response)
}).catch((err) => {
reject(err)