mirror of
https://github.com/crater-invoice/crater.git
synced 2025-12-17 10:52:55 -05:00
refactor dashboard actions and send email actions
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -40,7 +40,9 @@ export default {
|
||||
[types.UPDATE_ESTIMATE_STATUS] (state, data) {
|
||||
let pos = state.estimates.findIndex(estimate => estimate.id === data.id)
|
||||
|
||||
state.estimates[pos].status = data.status
|
||||
if (state.estimates[pos]) {
|
||||
state.estimates[pos].status = data.status
|
||||
}
|
||||
},
|
||||
|
||||
[types.RESET_SELECTED_ESTIMATES] (state, data) {
|
||||
|
||||
Reference in New Issue
Block a user