Complete add locale feature

This commit is contained in:
Muhsin Keloth 2022-09-01 11:28:40 +05:30
parent a7a4352cad
commit e7a128e04a
2 changed files with 11 additions and 15 deletions

View file

@ -41,7 +41,6 @@
import Modal from 'dashboard/components/Modal'; import Modal from 'dashboard/components/Modal';
import alertMixin from 'shared/mixins/alertMixin'; import alertMixin from 'shared/mixins/alertMixin';
import { required } from 'vuelidate/lib/validators'; import { required } from 'vuelidate/lib/validators';
import { convertToPortalSlug } from 'dashboard/helper/commons.js';
import allLocales from 'shared/constants/locales.js'; import allLocales from 'shared/constants/locales.js';
export default { export default {
components: { components: {
@ -61,6 +60,7 @@ export default {
data() { data() {
return { return {
selectedLocale: '', selectedLocale: '',
isUpdating: false,
}; };
}, },
computed: { computed: {
@ -87,9 +87,6 @@ export default {
}, },
}, },
methods: { methods: {
onNameChange() {
this.slug = convertToPortalSlug(this.name);
},
async onCreate() { async onCreate() {
this.$v.$touch(); this.$v.$touch();
if (this.$v.$invalid) { if (this.$v.$invalid) {
@ -100,23 +97,23 @@ export default {
return allowedLocales[key].code; return allowedLocales[key].code;
}); });
addedLocales.push(this.selectedLocale); addedLocales.push(this.selectedLocale);
this.isUpdating = true; this.isUpdating = true;
try { try {
await this.$store.dispatch('portals/update', { await this.$store.dispatch('portals/update', {
portalId: this.selectedPortalSlug, portalSlug: this.portal.slug,
config: { allowed_locales: addedLocales }, config: { allowed_locales: addedLocales },
}); });
this.alertMessage = this.$t(
'HELP_CENTER.PORTAL.ADD_LOCALE.API.SUCCESS_MESSAGE'
);
this.onClose();
} catch (error) { } catch (error) {
this.alertMessage = this.alertMessage =
error?.message || error?.message ||
this.$t('HELP_CENTER.EDIT_ARTICLE.API.ERROR_MESSAGE'); this.$t('HELP_CENTER.PORTAL.ADD_LOCALE.API.ERROR_MESSAGE');
this.showAlert(this.alertMessage);
} finally { } finally {
setTimeout(() => { this.showAlert(this.alertMessage);
this.isUpdating = false; this.isUpdating = false;
this.isSaved = true;
}, 1500);
} }
}, },
onClose() { onClose() {

View file

@ -36,8 +36,7 @@ export const actions = {
} }
}, },
update: async ({ commit }, { portalObj }) => { update: async ({ commit }, { portalSlug, ...params }) => {
const portalSlug = portalObj.slug;
commit(types.SET_HELP_PORTAL_UI_FLAG, { commit(types.SET_HELP_PORTAL_UI_FLAG, {
uiFlags: { isUpdating: true }, uiFlags: { isUpdating: true },
portalSlug, portalSlug,
@ -45,7 +44,7 @@ export const actions = {
try { try {
const { data } = await portalAPIs.updatePortal({ const { data } = await portalAPIs.updatePortal({
portalSlug, portalSlug,
portalObj, params,
}); });
commit(types.UPDATE_PORTAL_ENTRY, data); commit(types.UPDATE_PORTAL_ENTRY, data);
} catch (error) { } catch (error) {