This commit is contained in:
j3d1 2024-06-18 18:01:55 +02:00
parent 7228ab05c0
commit fb01b49bed

View file

@ -43,6 +43,7 @@ const store = createStore({
users: 0,
groups: 0,
states: 0,
messageTemplates: 0,
shippingVouchers: 0,
},
persistent_loaded: false,
@ -219,6 +220,7 @@ const store = createStore({
},
setMessageTemplates(state, templates) {
state.messageTemplates = templates;
state.fetchedData = {...state.fetchedData, messageTemplates: Date.now()};
},
setMessageTemplateVariables(state, variables) {
state.messageTemplateVariables = variables;
@ -443,6 +445,8 @@ const store = createStore({
commit('updateTicket', data);
},
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);
if (data && success) {
commit('setMessageTemplates', data);
@ -452,10 +456,13 @@ const store = createStore({
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
{'message': template.message}, state.user.token);
if (data && success) {
state.fetchedData.messageTemplates = 0;
dispatch('fetchMessageTemplates');
}
},
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);
if (data && success) {
commit('setMessageTemplateVariables', data);
@ -481,6 +488,7 @@ const store = createStore({
},
async createShippingVoucher({dispatch, state}, code) {
const {data, success} = await http.post('/2/shipping_vouchers/', code, state.user.token);
if (data && success) {
state.fetchedData.shippingVouchers = 0;
dispatch('fetchShippingVouchers');
}
@ -495,6 +503,8 @@ const store = createStore({
state.fetchedData.shippingVouchers = 0;
state.fetchedData.tickets = 0;
await Promise.all([dispatch('loadTickets'), dispatch('fetchShippingVouchers')]);
}
}
},
plugins: [
persistentStatePlugin({ // TODO change remember to some kind of enable field