diff --git a/app/assets/v2/js/grants/_new.js b/app/assets/v2/js/grants/_new.js index 96ba3c9d13d..ad3ffa9bd9d 100644 --- a/app/assets/v2/js/grants/_new.js +++ b/app/assets/v2/js/grants/_new.js @@ -92,10 +92,10 @@ Vue.mixin({ if (!vm.form.twitter_handle_1.length) { vm.$set(vm.errors, 'twitter_handle_1', 'Please enter twitter handle of your project'); } - if (vm.form.twitter_handle_1 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.form.twitter_handle_1)) { + if (vm.form.twitter_handle_1 && !(/^@?[a-zA-Z0-9_]{4,15}$/).test(vm.form.twitter_handle_1)) { vm.$set(vm.errors, 'twitter_handle_1', 'Please enter a valid twitter handle of your project e.g @humanfund'); } - if (vm.form.twitter_handle_2 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.form.twitter_handle_2)) { + if (vm.form.twitter_handle_2 && !(/^@?[a-zA-Z0-9_]{4,15}$/).test(vm.form.twitter_handle_2)) { vm.$set(vm.errors, 'twitter_handle_2', 'Please enter your twitter handle e.g @georgecostanza'); } @@ -277,7 +277,15 @@ Vue.mixin({ _alert(err.message, 'danger'); } }); - } + }, + handleTwitterUsername(event) { + const inputField = event.target; + const matchResult = inputField.value.match(/https:\/\/twitter.com\/(\w{4,15})/); + + const extracted = matchResult ? `@${matchResult[1]}` : inputField.value; + + this.$set(this.form, inputField.id, extracted); + }, }, watch: { deep: true, @@ -378,7 +386,7 @@ if (document.getElementById('gc-new-grant')) { ] }, theme: 'snow', - placeholder: 'Give a detailed desciription about your Grant' + placeholder: 'Give a detailed description about your Grant' } }; }, diff --git a/app/grants/templates/grants/_new.html b/app/grants/templates/grants/_new.html index 87cced1b799..2370adb0bb9 100644 --- a/app/grants/templates/grants/_new.html +++ b/app/grants/templates/grants/_new.html @@ -155,7 +155,7 @@

Create a Grant

Required - +
[[errors.twitter_handle_1]] @@ -166,7 +166,7 @@

Create a Grant

- +
[[errors.twitter_handle_2]] diff --git a/cypress/integration/grants/test_grant_creation.js b/cypress/integration/grants/test_grant_creation.js index a2d3b767c26..7b0a0acebf3 100644 --- a/cypress/integration/grants/test_grant_creation.js +++ b/cypress/integration/grants/test_grant_creation.js @@ -24,6 +24,19 @@ describe('Creating a new grant', () => { }); describe('creation:success - required fields only', () => { + it('extracts the user\'s Twitter handle when the full Twitter URL is entered into the form', () => { + const orgTwitterURL = 'https://twitter.com/gitcoin' + const userTwitterURL = 'https://twitter.com/gitcoinbot' + + cy.visit('grants/new'); + + cy.get('input[name=twitter_handle_1]').type(orgTwitterURL).blur(); + cy.get('input[name=twitter_handle_2]').type(userTwitterURL).blur(); + + cy.get('input[name=twitter_handle_1]').should('have.value', '@gitcoin'); + cy.get('input[name=twitter_handle_2]').should('have.value', '@gitcoinbot'); + }); + it('submits a grant for review', () => { cy.visit('grants/new');