Skip to content

Commit

Permalink
feat: Adds the ability to edit/delete category (#5385)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsivin committed Sep 2, 2022
1 parent a9801a3 commit d47a0ae
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 37 deletions.
7 changes: 5 additions & 2 deletions app/javascript/dashboard/api/helpCenter/categories.js
Expand Up @@ -15,8 +15,11 @@ class CategoriesAPI extends PortalsAPI {
return axios.post(`${this.url}/${portalSlug}/categories`, categoryObj);
}

update({ portalSlug, categoryObj }) {
return axios.patch(`${this.url}/${portalSlug}/categories`, categoryObj);
update({ portalSlug, categoryId, categoryObj }) {
return axios.patch(
`${this.url}/${portalSlug}/categories/${categoryId}`,
categoryObj
);
}

delete({ portalSlug, categoryId }) {
Expand Down
52 changes: 52 additions & 0 deletions app/javascript/dashboard/i18n/locale/en/helpCenter.json
Expand Up @@ -139,6 +139,21 @@
"TITLE": "Locales"
}
},
"CATEGORIES": {
"TITLE": "Categories in",
"NEW_CATEGORY": "New category",
"TABLE": {
"NAME": "Name",
"DESCRIPTION": "Description",
"LOCALE": "Locale",
"ARTICLE_COUNT": "No. of articles",
"ACTION_BUTTON": {
"EDIT": "Edit category",
"DELETE": "Delete category"
},
"EMPTY_TEXT": "No categories found"
}
},
"EDIT_BASIC_INFO": {
"BUTTON_TEXT": "Update basic settings"
}
Expand Down Expand Up @@ -353,6 +368,43 @@
"SUCCESS_MESSAGE": "Category created successfully",
"ERROR_MESSAGE": "Unable to create category"
}
},
"EDIT": {
"TITLE": "Edit a category",
"SUB_TITLE": "Editing a category will update the category in the public facing portal.",
"PORTAL": "Portal",
"LOCALE": "Locale",
"NAME": {
"LABEL": "Name",
"PLACEHOLDER": "Category name",
"HELP_TEXT": "The category name will be used in the public facing portal to categorize articles.",
"ERROR": "Name is required"
},
"SLUG": {
"LABEL": "Slug",
"PLACEHOLDER": "Category slug for urls",
"HELP_TEXT": "app.chatwoot.com/portal/my-portal/en-US/categories/my-slug",
"ERROR": "Slug is required"
},
"DESCRIPTION": {
"LABEL": "Description",
"PLACEHOLDER": "Give a short description about the category.",
"ERROR": "Description is required"
},
"BUTTONS": {
"CREATE": "Update category",
"CANCEL": "Cancel"
},
"API": {
"SUCCESS_MESSAGE": "Category updated successfully",
"ERROR_MESSAGE": "Unable to update category"
}
},
"DELETE": {
"API": {
"SUCCESS_MESSAGE": "Category deleted successfully",
"ERROR_MESSAGE": "Unable to delete category"
}
}
}
}
Expand Down
Expand Up @@ -37,6 +37,7 @@
/>
<add-category
v-if="showAddCategoryModal"
:show.sync="showAddCategoryModal"
:portal-name="selectedPortalName"
:locale="selectedPortalLocale"
@cancel="onClickCloseAddCategoryModal"
Expand All @@ -56,7 +57,7 @@ import CommandBar from 'dashboard/routes/dashboard/commands/commandbar.vue';
import WootKeyShortcutModal from 'dashboard/components/widgets/modal/WootKeyShortcutModal';
import NotificationPanel from 'dashboard/routes/dashboard/notifications/components/NotificationPanel';
import portalMixin from '../mixins/portalMixin';
import AddCategory from '../components/AddCategory.vue';
import AddCategory from '../pages/categories/AddCategory';
export default {
components: {
Expand Down Expand Up @@ -182,6 +183,7 @@ export default {
];
},
additionalSecondaryMenuItems() {
if (!this.selectedPortal) return [];
return [
{
icon: 'folder',
Expand Down
Expand Up @@ -243,6 +243,7 @@ export default {
this.$emit('open-site');
},
openSettings() {
this.fetchPortalsAndItsCategories();
this.navigateToPortalEdit();
},
onClickOpenDeleteModal(portal) {
Expand All @@ -252,6 +253,13 @@ export default {
closeDeletePopup() {
this.showDeleteConfirmationPopup = false;
},
fetchPortalsAndItsCategories() {
this.$store.dispatch('portals/index').then(() => {
this.$store.dispatch('categories/index', {
portalSlug: this.portal.slug,
});
});
},
async onClickDeletePortal() {
const { slug } = this.selectedPortalForDelete;
try {
Expand Down
Expand Up @@ -92,8 +92,16 @@ export default {
this.selectedLocale = this.locale || this.portal?.meta?.default_locale;
},
methods: {
fetchPortalsAndItsCategories() {
this.$store.dispatch('portals/index').then(() => {
this.$store.dispatch('categories/index', {
portalSlug: this.portal.slug,
});
});
},
onClick(event, code, portal) {
event.preventDefault();
this.fetchPortalsAndItsCategories();
this.$router.push({
name: 'list_all_locale_articles',
params: {
Expand Down
Expand Up @@ -77,6 +77,12 @@ const portalRoutes = [
component: EditPortalCustomization,
roles: ['administrator'],
},
{
path: getPortalRoute(':portalSlug/edit/:locale/categories'),
name: 'list_all_locale_categories',
roles: ['administrator', 'agent'],
component: ListAllCategories,
},
],
},
];
Expand Down Expand Up @@ -125,7 +131,7 @@ const articleRoutes = [
const categoryRoutes = [
{
path: getPortalRoute(':portalSlug/:locale/categories'),
name: 'list_all_locale_categories',
name: 'all_locale_categories',
roles: ['administrator', 'agent'],
component: ListAllCategories,
},
Expand Down
Expand Up @@ -132,11 +132,12 @@ export default {
},
async addCategory() {
const { name, slug, description } = this;
const { name, slug, description, locale } = this;
const data = {
name,
slug,
description,
locale,
};
this.$v.$touch();
if (this.$v.$invalid) {
Expand Down
@@ -0,0 +1,123 @@
<template>
<div>
<table>
<thead>
<tr>
<th scope="col">
{{ $t('HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.NAME') }}
</th>
<th scope="col">
{{ $t('HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.DESCRIPTION') }}
</th>
<th scope="col">
{{ $t('HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.LOCALE') }}
</th>
<th scope="col">
{{ $t('HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.ARTICLE_COUNT') }}
</th>
<th scope="col" />
</tr>
</thead>
<tr>
<td colspan="100%" class="horizontal-line" />
</tr>
<tbody>
<tr v-for="category in categories" :key="category.id">
<td>
<span>{{ category.name }}</span>
</td>
<td>
<span>{{ category.description }}</span>
</td>
<td>
<span>{{ category.locale }}</span>
</td>
<td>
<span>{{ category.meta.articles_count }}</span>
</td>
<td>
<woot-button
v-tooltip.top-end="
$t(
'HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.ACTION_BUTTON.EDIT'
)
"
size="tiny"
variant="smooth"
icon="edit"
color-scheme="secondary"
@click="editCategory(category)"
/>
<woot-button
v-tooltip.top-end="
$t(
'HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.ACTION_BUTTON.DELETE'
)
"
size="tiny"
variant="smooth"
icon="delete"
color-scheme="alert"
@click="deleteCategory(category.id)"
/>
</td>
</tr>
</tbody>
</table>
<p v-if="categories.length === 0" class="empty-text">
{{ $t('HELP_CENTER.PORTAL.EDIT.CATEGORIES.TABLE.EMPTY_TEXT') }}
</p>
</div>
</template>

<script>
export default {
props: {
categories: {
type: Array,
default: () => [],
},
},
methods: {
editCategory(category) {
this.$emit('edit', category);
},
deleteCategory(categoryId) {
this.$emit('delete', categoryId);
},
},
};
</script>

<style lang="scss" scoped>
table {
thead tr th {
font-size: var(--font-size-small);
font-weight: var(--font-weight-medium);
text-transform: none;
color: var(--s-600);
padding-left: 0;
padding-top: 0;
}
tbody tr {
border-bottom: 0;
td {
font-size: var(--font-size-small);
padding-left: 0;
}
}
}
.horizontal-line {
border-bottom: 1px solid var(--color-border);
}
.empty-text {
display: flex;
justify-content: center;
color: var(--s-500);
font-size: var(--font-size-default);
margin-top: var(--space-three);
}
</style>

0 comments on commit d47a0ae

Please sign in to comment.