feat: Adds URL validation for domain and home page links (#5761)

This commit is contained in:
Sivin Varghese 2022-10-28 06:21:38 +05:30 committed by GitHub
parent 3b09840d39
commit b20f5e5cef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 13 deletions

View file

@ -160,8 +160,7 @@
} }
}, },
"ADD": { "ADD": {
"CREATE_FLOW": [ "CREATE_FLOW": [{
{
"title": "Help center information", "title": "Help center information",
"route": "new_portal_information", "route": "new_portal_information",
"body": "Basic information about portal", "body": "Basic information about portal",
@ -212,20 +211,19 @@
"SLUG": { "SLUG": {
"LABEL": "Slug", "LABEL": "Slug",
"PLACEHOLDER": "Portal slug for urls", "PLACEHOLDER": "Portal slug for urls",
"ERROR": "Slug is required" "ERROR": "Slug is required"
}, },
"DOMAIN": { "DOMAIN": {
"LABEL": "Custom Domain", "LABEL": "Custom Domain",
"PLACEHOLDER": "Portal custom domain", "PLACEHOLDER": "Portal custom domain",
"HELP_TEXT": "Add only If you want to use a custom domain for your portals.", "HELP_TEXT": "Add only If you want to use a custom domain for your portals. Eg: https://example.com",
"ERROR": "Custom Domain is required" "ERROR": "Enter a valid domain URL"
}, },
"HOME_PAGE_LINK": { "HOME_PAGE_LINK": {
"LABEL": "Home Page Link", "LABEL": "Home Page Link",
"PLACEHOLDER": "Portal home page link", "PLACEHOLDER": "Portal home page link",
"HELP_TEXT": "The link used to return from the portal to the home page.", "HELP_TEXT": "The link used to return from the portal to the home page. Eg: https://example.com",
"ERROR": "Home Page Link is required" "ERROR": "Enter a valid home page URL"
}, },
"THEME_COLOR": { "THEME_COLOR": {
"LABEL": "Portal theme color", "LABEL": "Portal theme color",

View file

@ -35,11 +35,12 @@
<div class="form-item"> <div class="form-item">
<woot-input <woot-input
v-model.trim="name" v-model.trim="name"
:class="{ error: $v.slug.$error }" :class="{ error: $v.name.$error }"
:error="nameError" :error="nameError"
:label="$t('HELP_CENTER.PORTAL.ADD.NAME.LABEL')" :label="$t('HELP_CENTER.PORTAL.ADD.NAME.LABEL')"
:placeholder="$t('HELP_CENTER.PORTAL.ADD.NAME.PLACEHOLDER')" :placeholder="$t('HELP_CENTER.PORTAL.ADD.NAME.PLACEHOLDER')"
:help-text="$t('HELP_CENTER.PORTAL.ADD.NAME.HELP_TEXT')" :help-text="$t('HELP_CENTER.PORTAL.ADD.NAME.HELP_TEXT')"
@blur="$v.name.$touch"
@input="onNameChange" @input="onNameChange"
/> />
</div> </div>
@ -51,15 +52,18 @@
:label="$t('HELP_CENTER.PORTAL.ADD.SLUG.LABEL')" :label="$t('HELP_CENTER.PORTAL.ADD.SLUG.LABEL')"
:placeholder="$t('HELP_CENTER.PORTAL.ADD.SLUG.PLACEHOLDER')" :placeholder="$t('HELP_CENTER.PORTAL.ADD.SLUG.PLACEHOLDER')"
:help-text="domainHelpText" :help-text="domainHelpText"
@input="$v.slug.$touch" @blur="$v.slug.$touch"
/> />
</div> </div>
<div class="form-item"> <div class="form-item">
<woot-input <woot-input
v-model.trim="domain" v-model.trim="domain"
:class="{ error: $v.domain.$error }"
:label="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.LABEL')" :label="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.LABEL')"
:placeholder="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.PLACEHOLDER')" :placeholder="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.PLACEHOLDER')"
:help-text="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.HELP_TEXT')" :help-text="$t('HELP_CENTER.PORTAL.ADD.DOMAIN.HELP_TEXT')"
:error="domainError"
@blur="$v.domain.$touch"
/> />
</div> </div>
</div> </div>
@ -77,8 +81,8 @@
</template> </template>
<script> <script>
import { required, url, minLength } from 'vuelidate/lib/validators';
import thumbnail from 'dashboard/components/widgets/Thumbnail'; import thumbnail from 'dashboard/components/widgets/Thumbnail';
import { required, minLength } from 'vuelidate/lib/validators';
import { convertToCategorySlug } from 'dashboard/helper/commons.js'; import { convertToCategorySlug } from 'dashboard/helper/commons.js';
import { buildPortalURL } from 'dashboard/helper/portalHelper'; import { buildPortalURL } from 'dashboard/helper/portalHelper';
@ -116,6 +120,9 @@ export default {
slug: { slug: {
required, required,
}, },
domain: {
url,
},
}, },
computed: { computed: {
nameError() { nameError() {
@ -131,7 +138,10 @@ export default {
return ''; return '';
}, },
domainError() { domainError() {
return this.$v.domain.$error; if (this.$v.domain.$error) {
return this.$t('HELP_CENTER.PORTAL.ADD.DOMAIN.ERROR');
}
return '';
}, },
domainHelpText() { domainHelpText() {
return buildPortalURL(this.slug); return buildPortalURL(this.slug);

View file

@ -42,12 +42,23 @@
$t('HELP_CENTER.PORTAL.ADD.HOME_PAGE_LINK.PLACEHOLDER') $t('HELP_CENTER.PORTAL.ADD.HOME_PAGE_LINK.PLACEHOLDER')
" "
:help-text="$t('HELP_CENTER.PORTAL.ADD.HOME_PAGE_LINK.HELP_TEXT')" :help-text="$t('HELP_CENTER.PORTAL.ADD.HOME_PAGE_LINK.HELP_TEXT')"
:error="
$v.homePageLink.$error
? $t('HELP_CENTER.PORTAL.ADD.HOME_PAGE_LINK.ERROR')
: ''
"
:class="{ error: $v.homePageLink.$error }"
@blur="$v.homePageLink.$touch"
/> />
</div> </div>
</div> </div>
</div> </div>
<div class="flex-end"> <div class="flex-end">
<woot-button :is-loading="isSubmitting" @click="onSubmitClick"> <woot-button
:is-loading="isSubmitting"
:is-disabled="$v.$invalid"
@click="onSubmitClick"
>
{{ {{
$t( $t(
'HELP_CENTER.PORTAL.ADD.CREATE_FLOW_PAGE.CUSTOMIZATION_PAGE.UPDATE_PORTAL_BUTTON' 'HELP_CENTER.PORTAL.ADD.CREATE_FLOW_PAGE.CUSTOMIZATION_PAGE.UPDATE_PORTAL_BUTTON'
@ -59,6 +70,7 @@
</template> </template>
<script> <script>
import { url } from 'vuelidate/lib/validators';
import { getRandomColor } from 'dashboard/helper/labelColor'; import { getRandomColor } from 'dashboard/helper/labelColor';
import alertMixin from 'shared/mixins/alertMixin'; import alertMixin from 'shared/mixins/alertMixin';
@ -85,7 +97,11 @@ export default {
alertMessage: '', alertMessage: '',
}; };
}, },
computed: {}, validations: {
homePageLink: {
url,
},
},
mounted() { mounted() {
this.color = getRandomColor(); this.color = getRandomColor();
this.updateDataFromStore(); this.updateDataFromStore();
@ -102,6 +118,10 @@ export default {
} }
}, },
onSubmitClick() { onSubmitClick() {
this.$v.$touch();
if (this.$v.$invalid) {
return;
}
const portal = { const portal = {
id: this.portal.id, id: this.portal.id,
slug: this.portal.slug, slug: this.portal.slug,