Skip to content

Commit

Permalink
feat: Add the ability update/edit locale in portal (#5377)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Sep 2, 2022
1 parent a1663e4 commit 403ff1a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
12 changes: 12 additions & 0 deletions app/javascript/dashboard/i18n/locale/en/helpCenter.json
Expand Up @@ -249,6 +249,18 @@
"SUCCESS_MESSAGE": "Locale added successfully",
"ERROR_MESSAGE": "Unable to add locale. Try again."
}
},
"CHANGE_DEFAULT_LOCALE": {
"API": {
"SUCCESS_MESSAGE": "Default locale updated successfully",
"ERROR_MESSAGE": "Unable to update default locale. Try again."
}
},
"DELETE_LOCALE": {
"API": {
"SUCCESS_MESSAGE": "Locale removed from portal successfully",
"ERROR_MESSAGE": "Unable to remove locale from portal. Try again."
}
}
},
"TABLE": {
Expand Down
Expand Up @@ -165,8 +165,8 @@
<locale-item-table
:locales="locales"
:selected-locale-code="portal.meta.default_locale"
@swap="swapLocale"
@delete="deleteLocale"
@change-default-locale="changeDefaultLocale"
@delete="deletePortalLocale"
/>
</div>
</div>
Expand Down Expand Up @@ -223,14 +223,17 @@ export default {
return 'success';
}
},
// Delete portal modal
deleteMessageValue() {
return ` ${this.selectedPortalForDelete.name}?`;
},
locales() {
return this.portal ? this.portal.config.allowed_locales : [];
},
allowedLocales() {
return Object.keys(this.locales).map(key => {
return this.locales[key].code;
});
},
},
methods: {
addLocale() {
Expand Down Expand Up @@ -270,11 +273,54 @@ export default {
this.showAlert(this.alertMessage);
}
},
swapLocale() {
this.$emit('swap');
changeDefaultLocale({ localeCode }) {
this.updatePortalLocales({
allowedLocales: this.allowedLocales,
defaultLocale: localeCode,
successMessage: this.$t(
'HELP_CENTER.PORTAL.CHANGE_DEFAULT_LOCALE.API.SUCCESS_MESSAGE'
),
errorMessage: this.$t(
'HELP_CENTER.PORTAL.CHANGE_DEFAULT_LOCALE.API.ERROR_MESSAGE'
),
});
},
deletePortalLocale({ localeCode }) {
const updatedLocales = this.allowedLocales.filter(
code => code !== localeCode
);
const defaultLocale = this.portal.meta.default_locale;
this.updatePortalLocales({
allowedLocales: updatedLocales,
defaultLocale,
successMessage: this.$t(
'HELP_CENTER.PORTAL.DELETE_LOCALE.API.SUCCESS_MESSAGE'
),
errorMessage: this.$t(
'HELP_CENTER.PORTAL.DELETE_LOCALE.API.ERROR_MESSAGE'
),
});
},
deleteLocale() {
this.$emit('delete');
async updatePortalLocales({
allowedLocales,
defaultLocale,
successMessage,
errorMessage,
}) {
try {
await this.$store.dispatch('portals/update', {
portalSlug: this.portal.slug,
config: {
default_locale: defaultLocale,
allowed_locales: allowedLocales,
},
});
this.alertMessage = successMessage;
} catch (error) {
this.alertMessage = error?.message || errorMessage;
} finally {
this.showAlert(this.alertMessage);
}
},
navigateToPortalEdit() {
this.$router.push({
Expand Down
Expand Up @@ -73,7 +73,7 @@
icon="arrow-swap"
color-scheme="primary"
:disabled="locale.code === selectedLocaleCode"
@click="swapLocale"
@click="changeDefaultLocale(locale.code)"
/>
<woot-button
v-tooltip.top-end="
Expand All @@ -85,7 +85,8 @@
variant="smooth"
icon="delete"
color-scheme="secondary"
@click="deleteLocale"
:disabled="locale.code === selectedLocaleCode"
@click="deleteLocale(locale.code)"
/>
</td>
</tr>
Expand Down Expand Up @@ -113,11 +114,11 @@ export default {
},
methods: {
swapLocale() {
this.$emit('swap');
changeDefaultLocale(localeCode) {
this.$emit('change-default-locale', { localeCode });
},
deleteLocale() {
this.$emit('delete');
deleteLocale(localeCode) {
this.$emit('delete', { localeCode });
},
},
};
Expand Down

0 comments on commit 403ff1a

Please sign in to comment.