Shoe locales in dropdown

This commit is contained in:
Muhsin Keloth 2022-08-31 20:16:59 +05:30
parent 6d817b2f02
commit 9efc37e85a
3 changed files with 54 additions and 46 deletions

View file

@ -202,7 +202,7 @@
}, },
"ADD_LOCALE": { "ADD_LOCALE": {
"TITLE": "Add a new locale", "TITLE": "Add a new locale",
"SUB_TITLE": "This adds a new locale to your available translation list. ", "SUB_TITLE": "This adds a new locale to your available translation list.",
"PORTAL": "Portal", "PORTAL": "Portal",
"LOCALE": { "LOCALE": {
"LABEL": "Locale", "LABEL": "Locale",
@ -214,8 +214,8 @@
"CANCEL": "Cancel" "CANCEL": "Cancel"
}, },
"API": { "API": {
"SUCCESS_MESSAGE": "Category created successfully", "SUCCESS_MESSAGE": "Locale added successfully",
"ERROR_MESSAGE": "Unable to create category" "ERROR_MESSAGE": "Unable to add locale. Try again."
} }
} }
}, },

View file

@ -14,7 +14,7 @@
:key="item.name" :key="item.name"
:value="item.id" :value="item.id"
> >
{{ item.name }} {{ item.name }}-{{ item.code }}
</option> </option>
</select> </select>
<span v-if="$v.selectedLocale.$error" class="message"> <span v-if="$v.selectedLocale.$error" class="message">
@ -53,9 +53,9 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
portalId: { portal: {
type: String, type: Object,
default: '', default: () => ({}),
}, },
}, },
data() { data() {
@ -65,12 +65,20 @@ export default {
}, },
computed: { computed: {
allLocales() { allLocales() {
return Object.keys(allLocales).map(key => { const addedLocales = this.portal.config.allowed_locales.map(
return { locale => locale.code
id: key, );
name: allLocales[key], return Object.keys(allLocales)
}; .map(key => {
}); return {
id: key,
name: allLocales[key],
code: key,
};
})
.filter(locale => {
return !addedLocales.includes(locale.code);
});
}, },
}, },
validations: { validations: {
@ -84,38 +92,32 @@ export default {
}, },
async onCreate() { async onCreate() {
this.$v.$touch(); this.$v.$touch();
// if (this.$v.$invalid) { if (this.$v.$invalid) {
// return; return;
// } }
// console.log('onCreate', this.selectedLocale); const { allowed_locales: allowedLocales } = this.portal.config;
const addedLocales = Object.keys(allowedLocales).map(key => {
return allowedLocales[key].code;
});
addedLocales.push(this.selectedLocale);
// try { this.isUpdating = true;
// await this.$store.dispatch('portals/create', { try {
// portal: { await this.$store.dispatch('portals/update', {
// name: this.name, portalId: this.selectedPortalSlug,
// slug: this.slug, config: { allowed_locales: addedLocales },
// custom_domain: this.domain, });
// // TODO: add support for choosing color } catch (error) {
// color: '#1f93ff', this.alertMessage =
// homepage_link: this.homePageLink, error?.message ||
// page_title: this.pageTitle, this.$t('HELP_CENTER.EDIT_ARTICLE.API.ERROR_MESSAGE');
// header_text: this.headerText, this.showAlert(this.alertMessage);
// config: { } finally {
// // TODO: add support for choosing locale setTimeout(() => {
// allowed_locales: ['en'], this.isUpdating = false;
// }, this.isSaved = true;
// }, }, 1500);
// }); }
// this.alertMessage = this.$t(
// 'HELP_CENTER.PORTAL.ADD.API.SUCCESS_MESSAGE'
// );
// this.$emit('cancel');
// } catch (error) {
// this.alertMessage =
// error?.message || this.$t('HELP_CENTER.PORTAL.ADD.API.ERROR_MESSAGE');
// } finally {
// this.showAlert(this.alertMessage);
// }
}, },
onClose() { onClose() {
this.$emit('cancel'); this.$emit('cancel');

View file

@ -30,7 +30,11 @@
:show.sync="isAddLocaleModalOpen" :show.sync="isAddLocaleModalOpen"
:on-close="closeAddLocaleModal" :on-close="closeAddLocaleModal"
> >
<add-locale :show="isAddLocaleModalOpen" @cancel="closeAddLocaleModal" /> <add-locale
:show="isAddLocaleModalOpen"
:portal="selectedPortal"
@cancel="closeAddLocaleModal"
/>
</woot-modal> </woot-modal>
</div> </div>
</template> </template>
@ -51,6 +55,7 @@ export default {
data() { data() {
return { return {
isAddLocaleModalOpen: false, isAddLocaleModalOpen: false,
selectedPortal: {},
}; };
}, },
computed: { computed: {
@ -73,8 +78,9 @@ export default {
closeAddLocaleModal() { closeAddLocaleModal() {
this.isAddLocaleModalOpen = false; this.isAddLocaleModalOpen = false;
}, },
addLocale() { addLocale(portalId) {
this.isAddLocaleModalOpen = true; this.isAddLocaleModalOpen = true;
this.selectedPortal = this.portals.find(portal => portal.id === portalId);
// this.$router.push({ name: 'new_portal_locale', params: { portalId } }); // this.$router.push({ name: 'new_portal_locale', params: { portalId } });
}, },
}, },