stash
This commit is contained in:
parent
7228ab05c0
commit
fb01b49bed
1 changed files with 10 additions and 0 deletions
|
@ -43,6 +43,7 @@ const store = createStore({
|
||||||
users: 0,
|
users: 0,
|
||||||
groups: 0,
|
groups: 0,
|
||||||
states: 0,
|
states: 0,
|
||||||
|
messageTemplates: 0,
|
||||||
shippingVouchers: 0,
|
shippingVouchers: 0,
|
||||||
},
|
},
|
||||||
persistent_loaded: false,
|
persistent_loaded: false,
|
||||||
|
@ -219,6 +220,7 @@ const store = createStore({
|
||||||
},
|
},
|
||||||
setMessageTemplates(state, templates) {
|
setMessageTemplates(state, templates) {
|
||||||
state.messageTemplates = templates;
|
state.messageTemplates = templates;
|
||||||
|
state.fetchedData = {...state.fetchedData, messageTemplates: Date.now()};
|
||||||
},
|
},
|
||||||
setMessageTemplateVariables(state, variables) {
|
setMessageTemplateVariables(state, variables) {
|
||||||
state.messageTemplateVariables = variables;
|
state.messageTemplateVariables = variables;
|
||||||
|
@ -443,6 +445,8 @@ const store = createStore({
|
||||||
commit('updateTicket', data);
|
commit('updateTicket', data);
|
||||||
},
|
},
|
||||||
async fetchMessageTemplates({commit, state}) {
|
async fetchMessageTemplates({commit, state}) {
|
||||||
|
if (!state.user.token) return;
|
||||||
|
if (state.messageTemplates.length > 0) return;
|
||||||
const {data, success} = await http.get('/2/message_templates/', state.user.token);
|
const {data, success} = await http.get('/2/message_templates/', state.user.token);
|
||||||
if (data && success) {
|
if (data && success) {
|
||||||
commit('setMessageTemplates', data);
|
commit('setMessageTemplates', data);
|
||||||
|
@ -452,10 +456,13 @@ const store = createStore({
|
||||||
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
|
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
|
||||||
{'message': template.message}, state.user.token);
|
{'message': template.message}, state.user.token);
|
||||||
if (data && success) {
|
if (data && success) {
|
||||||
|
state.fetchedData.messageTemplates = 0;
|
||||||
dispatch('fetchMessageTemplates');
|
dispatch('fetchMessageTemplates');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async fetchMessageTemplateVariables({commit, state}) {
|
async fetchMessageTemplateVariables({commit, state}) {
|
||||||
|
if (!state.user.token) return;
|
||||||
|
if (state.messageTemplateVariables.length > 0) return;
|
||||||
const {data, success} = await http.get('/2/message_template_variables/', state.user.token);
|
const {data, success} = await http.get('/2/message_template_variables/', state.user.token);
|
||||||
if (data && success) {
|
if (data && success) {
|
||||||
commit('setMessageTemplateVariables', data);
|
commit('setMessageTemplateVariables', data);
|
||||||
|
@ -481,6 +488,7 @@ const store = createStore({
|
||||||
},
|
},
|
||||||
async createShippingVoucher({dispatch, state}, code) {
|
async createShippingVoucher({dispatch, state}, code) {
|
||||||
const {data, success} = await http.post('/2/shipping_vouchers/', code, state.user.token);
|
const {data, success} = await http.post('/2/shipping_vouchers/', code, state.user.token);
|
||||||
|
if (data && success) {
|
||||||
state.fetchedData.shippingVouchers = 0;
|
state.fetchedData.shippingVouchers = 0;
|
||||||
dispatch('fetchShippingVouchers');
|
dispatch('fetchShippingVouchers');
|
||||||
}
|
}
|
||||||
|
@ -495,6 +503,8 @@ const store = createStore({
|
||||||
state.fetchedData.shippingVouchers = 0;
|
state.fetchedData.shippingVouchers = 0;
|
||||||
state.fetchedData.tickets = 0;
|
state.fetchedData.tickets = 0;
|
||||||
await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]);
|
await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
persistentStatePlugin({ // TODO change remember to some kind of enable field
|
||||||
|
|
Loading…
Reference in a new issue