From 403ff1a679cb245d9f4500c8094a418891042f62 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Fri, 2 Sep 2022 11:45:03 +0530 Subject: [PATCH] feat: Add the ability update/edit locale in portal (#5377) --- .../dashboard/i18n/locale/en/helpCenter.json | 12 ++++ .../helpcenter/components/PortalListItem.vue | 62 ++++++++++++++++--- .../components/PortalListItemTable.vue | 13 ++-- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index 955122bdb..7e8b6a858 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -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": { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue index c77a70a90..20da37baa 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItem.vue @@ -165,8 +165,8 @@ @@ -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() { @@ -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' + ), + }); }, - deleteLocale() { - this.$emit('delete'); + 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' + ), + }); + }, + 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({ diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItemTable.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItemTable.vue index 08e1ee719..e57c7066d 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItemTable.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/PortalListItemTable.vue @@ -73,7 +73,7 @@ icon="arrow-swap" color-scheme="primary" :disabled="locale.code === selectedLocaleCode" - @click="swapLocale" + @click="changeDefaultLocale(locale.code)" /> @@ -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 }); }, }, };