build version 400

This commit is contained in:
Mohit Panjwani
2020-12-02 17:54:08 +05:30
parent 326508e567
commit 89ee58590c
963 changed files with 62887 additions and 48868 deletions

View File

@ -1,70 +1,108 @@
import * as types from './mutation-types'
import * as searchTypes from '../search/mutation-types'
export const fetchCustomers = ({ commit, dispatch, state }, params) => {
return new Promise((resolve, reject) => {
window.axios.get(`/api/customers`, {params}).then((response) => {
commit(types.BOOTSTRAP_CUSTOMERS, response.data.customers.data)
commit(types.SET_TOTAL_CUSTOMERS, response.data.customers.total)
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.get(`/api/v1/customers`, { params })
.then((response) => {
commit(types.BOOTSTRAP_CUSTOMERS, response.data.customers.data)
commit(types.SET_TOTAL_CUSTOMERS, response.data.customerTotalCount)
commit(
'search/' + searchTypes.SET_CUSTOMER_LISTS,
response.data.customers.data,
{ root: true }
)
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const fetchCustomer = ({ commit, dispatch }, id) => {
export const fetchCustomer = ({ commit, dispatch, state }, params) => {
return new Promise((resolve, reject) => {
window.axios.get(`/api/customers/${id}/edit`).then((response) => {
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.get(`/api/v1/customers/${params.id}`)
.then((response) => {
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const fetchViewCustomer = ({ commit, dispatch }, params) => {
return new Promise((resolve, reject) => {
window.axios
.get(`/api/v1/customers/${params.id}/stats`, { params })
.then((response) => {
commit(types.SET_SELECTED_VIEW_CUSTOMER, response.data)
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const addCustomer = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.post('/api/customers', data).then((response) => {
commit(types.ADD_CUSTOMER, response.data)
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.post('/api/v1/customers', data)
.then((response) => {
commit(types.ADD_CUSTOMER, response.data)
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const updateCustomer = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => {
window.axios.put(`/api/customers/${data.id}`, data).then((response) => {
if(response.data.success){
commit(types.UPDATE_CUSTOMER, response.data)
}
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.put(`/api/v1/customers/${data.id}`, data)
.then((response) => {
if (response.data.success) {
commit(types.UPDATE_CUSTOMER, response.data)
}
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const deleteCustomer = ({ commit, dispatch, state }, id) => {
return new Promise((resolve, reject) => {
window.axios.delete(`/api/customers/${id}`).then((response) => {
commit(types.DELETE_CUSTOMER, id)
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.post(`/api/v1/customers/delete`, id)
.then((response) => {
commit(types.DELETE_CUSTOMER, id)
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
export const deleteMultipleCustomers = ({ commit, dispatch, state }, id) => {
return new Promise((resolve, reject) => {
window.axios.post(`/api/customers/delete`, {'id': state.selectedCustomers}).then((response) => {
commit(types.DELETE_MULTIPLE_CUSTOMERS, state.selectedCustomers)
resolve(response)
}).catch((err) => {
reject(err)
})
window.axios
.post(`/api/v1/customers/delete`, { ids: state.selectedCustomers })
.then((response) => {
commit(types.DELETE_MULTIPLE_CUSTOMERS, state.selectedCustomers)
resolve(response)
})
.catch((err) => {
reject(err)
})
})
}
@ -77,7 +115,7 @@ export const selectAllCustomers = ({ commit, dispatch, state }) => {
commit(types.SET_SELECTED_CUSTOMERS, [])
commit(types.SET_SELECT_ALL_STATE, false)
} else {
let allCustomerIds = state.customers.map(cust => cust.id)
let allCustomerIds = state.customers.map((cust) => cust.id)
commit(types.SET_SELECTED_CUSTOMERS, allCustomerIds)
commit(types.SET_SELECT_ALL_STATE, true)
}

View File

@ -2,3 +2,8 @@ export const customers = (state) => state.customers
export const selectAllField = (state) => state.selectAllField
export const selectedCustomers = (state) => state.selectedCustomers
export const totalCustomers = (state) => state.totalCustomers
export const getCustomer = (state) => (id) => {
let CstId = parseInt(id)
return state.customers.find((customer) => customer.id === CstId)
}
export const selectedViewCustomer = (state) => state.selectedViewCustomer

View File

@ -6,7 +6,8 @@ const initialState = {
customers: [],
totalCustomers: 0,
selectAllField: false,
selectedCustomers: []
selectedCustomers: [],
selectedViewCustomer: {},
}
export default {
@ -18,5 +19,5 @@ export default {
actions: actions,
mutations: mutations
mutations: mutations,
}

View File

@ -7,3 +7,4 @@ export const SET_SELECTED_CUSTOMERS = 'SET_SELECTED_CUSTOMERS'
export const SET_TOTAL_CUSTOMERS = 'SET_TOTAL_CUSTOMERS'
export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER'
export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE'
export const SET_SELECTED_VIEW_CUSTOMER = 'SET_SELECTED_VIEW_CUSTOMER'

View File

@ -1,48 +1,53 @@
import * as types from './mutation-types'
export default {
[types.BOOTSTRAP_CUSTOMERS] (state, customers) {
[types.BOOTSTRAP_CUSTOMERS](state, customers) {
state.customers = customers
},
[types.SET_TOTAL_CUSTOMERS] (state, totalCustomers) {
[types.SET_TOTAL_CUSTOMERS](state, totalCustomers) {
state.totalCustomers = totalCustomers
},
[types.ADD_CUSTOMER] (state, data) {
[types.ADD_CUSTOMER](state, data) {
state.customers.push(data.customer)
},
[types.UPDATE_CUSTOMER] (state, data) {
let pos = state.customers.findIndex(customer => customer.id === data.customer.id)
[types.UPDATE_CUSTOMER](state, data) {
let pos = state.customers.findIndex(
(customer) => customer.id === data.customer.id
)
state.customers[pos] = data.customer
},
[types.DELETE_CUSTOMER] (state, id) {
let index = state.customers.findIndex(customer => customer.id === id)
[types.DELETE_CUSTOMER](state, id) {
let index = state.customers.findIndex((customer) => customer.id === id)
state.customers.splice(index, 1)
},
[types.DELETE_MULTIPLE_CUSTOMERS] (state, selectedCustomers) {
[types.DELETE_MULTIPLE_CUSTOMERS](state, selectedCustomers) {
selectedCustomers.forEach((customer) => {
let index = state.customers.findIndex(_cust => _cust.id === customer.id)
let index = state.customers.findIndex((_cust) => _cust.id === customer.id)
state.customers.splice(index, 1)
})
state.selectedCustomers = []
},
[types.SET_SELECTED_CUSTOMERS] (state, data) {
[types.SET_SELECTED_CUSTOMERS](state, data) {
state.selectedCustomers = data
},
[types.RESET_SELECTED_CUSTOMER] (state, data) {
[types.RESET_SELECTED_CUSTOMER](state, data) {
state.selectedCustomer = null
},
[types.SET_SELECT_ALL_STATE] (state, data) {
[types.SET_SELECT_ALL_STATE](state, data) {
state.selectAllField = data
}
},
[types.SET_SELECTED_VIEW_CUSTOMER](state, selectedViewCustomer) {
state.selectedViewCustomer = selectedViewCustomer
},
}