From c2db8a1fd7f2fa19c275053334eb996e3c2ba51c Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 15 Nov 2021 12:45:47 +0530 Subject: [PATCH] chore: Add the option to edit custom attribute display name (#3382) --- .../i18n/locale/en/attributesMgmt.json | 3 +- .../settings/attributes/AddAttribute.vue | 21 ++++++++++---- .../settings/attributes/EditAttribute.vue | 29 ++++++++++++------- .../dashboard/store/modules/attributes.js | 6 ++-- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json b/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json index 819b4cb66..0ea8af780 100644 --- a/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/attributesMgmt.json @@ -32,7 +32,8 @@ "KEY": { "LABEL": "Key", "PLACEHOLDER": "Enter custom attribute key", - "ERROR": "Key is required" + "ERROR": "Key is required", + "IN_VALID": "Invalid key" } }, "API": { diff --git a/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue b/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue index b5ab9622a..29f5c3fc8 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/attributes/AddAttribute.vue @@ -59,11 +59,7 @@ :label="$t('ATTRIBUTES_MGMT.ADD.FORM.KEY.LABEL')" type="text" :class="{ error: $v.attributeKey.$error }" - :error=" - $v.attributeKey.$error - ? $t('ATTRIBUTES_MGMT.ADD.FORM.KEY.ERROR') - : '' - " + :error="$v.attributeKey.$error ? keyErrorMessage : ''" :placeholder="$t('ATTRIBUTES_MGMT.ADD.FORM.KEY.PLACEHOLDER')" @blur="$v.attributeKey.$touch" /> @@ -122,6 +118,12 @@ export default { this.uiFlags.isCreating ); }, + keyErrorMessage() { + if (!this.$v.attributeKey.isKey) { + return this.$t('ATTRIBUTES_MGMT.ADD.FORM.KEY.IN_VALID'); + } + return this.$t('ATTRIBUTES_MGMT.ADD.FORM.KEY.ERROR'); + }, }, validations: { @@ -140,6 +142,9 @@ export default { }, attributeKey: { required, + isKey(value) { + return !(value.indexOf(' ') >= 0); + }, }, }, @@ -148,6 +153,10 @@ export default { this.attributeKey = convertToSlug(this.displayName); }, async addAttributes() { + this.$v.$touch(); + if (this.$v.$invalid) { + return; + } try { await this.$store.dispatch('attributes/create', { attribute_display_name: this.displayName, @@ -159,7 +168,7 @@ export default { this.alertMessage = this.$t('ATTRIBUTES_MGMT.ADD.API.SUCCESS_MESSAGE'); this.onClose(); } catch (error) { - const errorMessage = error?.response?.data?.message; + const errorMessage = error?.message; this.alertMessage = errorMessage || this.$t('ATTRIBUTES_MGMT.ADD.API.ERROR_MESSAGE'); } finally { diff --git a/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue b/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue index 49e5420c2..1acf8a4a3 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/attributes/EditAttribute.vue @@ -14,7 +14,6 @@ : '' " :placeholder="$t('ATTRIBUTES_MGMT.ADD.FORM.NAME.PLACEHOLDER')" - readonly @blur="$v.displayName.$touch" />