Skip to content

Commit

Permalink
fixing #249 - delete implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
literakl committed Feb 6, 2022
1 parent 6ee2000 commit 283bc7d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spa/src/modules/vuex/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,12 @@ export default {
context.commit('CLEAR_CONTENT');
return response.data;
},
DELETE_SNIPPET: async (context, payload) => {
Vue.$log.debug('DELETE_SNIPPET');
const { itemId, code } = payload;
const response = await deleteApi('API',`/items/${itemId}/snippets/${code}`, {}, context);
context.commit('CLEAR_CONTENT');
return response.data;
},
},
};
23 changes: 23 additions & 0 deletions spa/src/views/item/EditSnippets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<div class="pt-3 centerbox m-auto" v-if="item">
<h2>{{ $t('page-title.snippets') }}</h2>

<div v-if="snippets" v-for="snippet in snippets" :key="snippet.code">
{{ snippet.code }}
{{ snippet.type }}
<b-button variant="post-btn" @click="deleteSnippet(snippet.code)">
{{ $t("generic.delete-button") }}
</b-button>
</div>

<div class="field-area">
<div>
<label class="d-label">{{ $t('cms.snippets.code') }}</label>
Expand Down Expand Up @@ -243,6 +251,21 @@ export default {
this.showError(result.errors);
}
},
async deleteSnippet(code) {
const body = {
itemId: this.item._id,
code,
};
this.errors = [];
let result = await this.$store.dispatch('DELETE_SNIPPET', body);
if (result.success) {
await this.$store.dispatch('FETCH_CONTENT', { slug: this.slug });
this.snippets = this.item.snippets;
} else {
this.showError(result.errors);
}
},
showError(errors) {
for (let i = 0; i < errors.length; i += 1) {
this.errors.push(this.$t(errors[i].messageKey));
Expand Down

0 comments on commit 283bc7d

Please sign in to comment.