From a843f6707a4280697f6209618499af0adb723050 Mon Sep 17 00:00:00 2001 From: vinit717 Date: Thu, 8 Feb 2024 10:27:59 +0530 Subject: [PATCH 1/6] fix : signup --- app/constants/new-signup.js | 13 ------ app/controllers/new-signup.js | 80 +++++++++++------------------------ app/templates/new-signup.hbs | 24 +++-------- app/utils/check-username.js | 25 ++++++++--- app/utils/register-api.js | 18 ++------ 5 files changed, 50 insertions(+), 110 deletions(-) diff --git a/app/constants/new-signup.js b/app/constants/new-signup.js index 81fd0bc5..7779e304 100644 --- a/app/constants/new-signup.js +++ b/app/constants/new-signup.js @@ -9,7 +9,6 @@ export const NEW_SIGNUP_STEPS = [ GET_STARTED, FIRST_NAME, LAST_NAME, - USERNAME, ROLE, THANK_YOU, ]; @@ -31,18 +30,6 @@ export const CHECK_BOX_DATA = [ label: 'Developer', name: 'developer', }, - { - label: 'Designer', - name: 'designer', - }, - { - label: 'Maven', - name: 'maven', - }, - { - label: 'Product Manager', - name: 'productmanager', - }, ]; export const GET_STARTED_MAIN_HEADING = 'Thank you for connecting your GitHub!'; diff --git a/app/controllers/new-signup.js b/app/controllers/new-signup.js index 1c541ea5..03bedd7a 100644 --- a/app/controllers/new-signup.js +++ b/app/controllers/new-signup.js @@ -12,8 +12,6 @@ export default class NewSignUpController extends Controller { @service analytics; @service featureFlag; - queryParams = ['currentStep', 'dev']; - @tracked isLoading = false; @tracked isButtonDisabled = true; @tracked error = ''; @@ -22,12 +20,7 @@ export default class NewSignUpController extends Controller { SECOND_STEP = NEW_SIGNUP_STEPS[1]; THIRD_STEP = NEW_SIGNUP_STEPS[2]; FOURTH_STEP = NEW_SIGNUP_STEPS[3]; - FIFTH_STEP = NEW_SIGNUP_STEPS[4]; - LAST_STEP = NEW_SIGNUP_STEPS[5]; - - get isDevMode() { - return this.featureFlag.isDevMode; - } + LAST_STEP = NEW_SIGNUP_STEPS[4]; @tracked signupDetails = { firstName: '', @@ -66,12 +59,10 @@ export default class NewSignUpController extends Controller { } @action completeSignUp() { + console.log('click'); this.analytics.trackEvent(NEW_SIGNUP_FLOW.NEW_SIGNUP_FLOW_DONE); - if (this.isDevMode) { - window.open('https://realdevsquad.com/goto?dev=true', '_self'); - } else { - window.open(GOTO_URL, '_self'); - } + + window.open(GOTO_URL, '_self'); } @action handleInputChange(key, value) { @@ -94,7 +85,6 @@ export default class NewSignUpController extends Controller { const signupDetails = { first_name: this.signupDetails.firstName, last_name: this.signupDetails.lastName, - username: this.signupDetails.username, }; const roles = {}; Object.entries(this.signupDetails.roles).forEach(([key, value]) => { @@ -104,56 +94,34 @@ export default class NewSignUpController extends Controller { }); this.isLoading = true; - - const isUsernameAvailable = await checkUserName(signupDetails.username); - if (!isUsernameAvailable) { + const username = await checkUserName( + signupDetails.first_name, + signupDetails.last_name + ); + if (!username) { this.analytics.trackEvent(NEW_SIGNUP_FLOW.USERNAME_NOT_AVAILABLE); this.isLoading = false; this.isButtonDisabled = false; return (this.error = ERROR_MESSAGES.userName); } - - if (this.isDevMode) { - try { - const res = await newRegisterUser(signupDetails, roles); - if (res.status === 204) { - this.analytics.identifyUser(); - this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_REGISTERED); - this.currentStep = this.LAST_STEP; - } else { - this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_SIGNUP); - this.error = ERROR_MESSAGES.others; - this.isButtonDisabled = false; - } - } catch (error) { - this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_REGISTER); + signupDetails.username = username.username; + try { + const res = await newRegisterUser(signupDetail, roles); + if (res.status === 204) { + this.analytics.identifyUser(); + this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_REGISTERED); + this.currentStep = this.LAST_STEP; + } else { + this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_SIGNUP); this.error = ERROR_MESSAGES.others; this.isButtonDisabled = false; - } finally { - this.isLoading = false; } - } else { - //this will get removed after removing feature flag - registerUser(signupDetails) - .then((res) => { - if (res.status === 204) { - this.analytics.identifyUser(); - this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_REGISTERED); - this.currentStep = this.LAST_STEP; - } else { - this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_SIGNUP); - this.error = ERROR_MESSAGES.others; - this.isButtonDisabled = false; - } - }) - .catch(() => { - this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_REGISTER); - this.error = ERROR_MESSAGES.others; - this.isButtonDisabled = false; - }) - .finally(() => { - this.isLoading = false; - }); + } catch (error) { + this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_REGISTER); + this.error = ERROR_MESSAGES.others; + this.isButtonDisabled = false; + } finally { + this.isLoading = false; } } } diff --git a/app/templates/new-signup.hbs b/app/templates/new-signup.hbs index 3239b741..20c79924 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -28,30 +28,17 @@ {{/if}} {{#if (eq this.currentStep this.FOURTH_STEP)}} - {{#if this.isDevMode}} - - {{else}} - - {{/if}} {{/if}} -{{#if this.isDevMode}} - {{#if (eq this.currentStep this.FIFTH_STEP)}} + + {{!-- {{#if (eq this.currentStep this.FIFTH_STEP)}} - {{/if}} -{{/if}} +{{/if}} --}} {{#if (eq this.currentStep this.LAST_STEP)}} credentials: 'include', }); -const newRegisterUser = async (signupDetails, roles) => { - const getResponse = await fetch(`${BASE_API_URL}/users/self`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', - }); - - const userData = await getResponse.json(); - - const res = await registerUser({ - ...signupDetails, +const newRegisterUser = async (signupDetail, roles) => { + const res = await registerUser({ + ...signupDetail, roles: { - ...userData.roles, ...roles, }, }); - return res; }; From fcdaebeb7e78b4b939145ffec34499da7683ce83 Mon Sep 17 00:00:00 2001 From: vinit717 Date: Sat, 24 Aug 2024 14:06:53 +0530 Subject: [PATCH 2/6] resolve conflicts --- app/constants/new-signup.js | 17 +++++++++++++---- app/controllers/new-signup.js | 32 ++++++++++---------------------- app/templates/discord.hbs | 4 ++-- app/templates/new-signup.hbs | 18 +++++------------- app/utils/check-username.js | 25 +++++++------------------ app/utils/register-api.js | 18 ++++++++++++++---- 6 files changed, 51 insertions(+), 63 deletions(-) diff --git a/app/constants/new-signup.js b/app/constants/new-signup.js index 48e9344f..d975ff56 100644 --- a/app/constants/new-signup.js +++ b/app/constants/new-signup.js @@ -4,33 +4,42 @@ const LAST_NAME = 'lastName'; const USERNAME = 'username'; const ROLE = 'role'; const THANK_YOU = 'thank-you'; - export const NEW_SIGNUP_STEPS = [ GET_STARTED, FIRST_NAME, LAST_NAME, + USERNAME, ROLE, THANK_YOU, ]; - export const LABEL_TEXT = { firstName: 'What is your first name?', lastName: 'And what is your last name?', username: 'Now choose your awesome username!', role: 'Select your role', }; - export const ERROR_MESSAGES = { userName: 'username already taken!', others: 'something went wrong', usernameGeneration: 'Username cannot be generated', }; - export const CHECK_BOX_DATA = [ { label: 'Developer', name: 'developer', }, + { + label: 'Designer', + name: 'designer', + }, + { + label: 'Maven', + name: 'maven', + }, + { + label: 'Product Manager', + name: 'productmanager', + }, ]; export const GET_STARTED_MAIN_HEADING = 'Thank you for connecting your GitHub!'; diff --git a/app/controllers/new-signup.js b/app/controllers/new-signup.js index 08894040..0d7bbef3 100644 --- a/app/controllers/new-signup.js +++ b/app/controllers/new-signup.js @@ -9,14 +9,11 @@ import { ERROR_MESSAGES, NEW_SIGNUP_STEPS } from '../constants/new-signup'; import checkUserName from '../utils/check-username'; import ENV from 'website-my/config/environment'; import { toastNotificationTimeoutOptions } from '../constants/toast-notification'; - export default class NewSignUpController extends Controller { @service analytics; @service featureFlag; @service toast; - queryParams = ['currentStep', 'dev']; - @tracked isLoading = false; @tracked isButtonDisabled = true; @tracked error = ''; @@ -25,20 +22,21 @@ export default class NewSignUpController extends Controller { SECOND_STEP = NEW_SIGNUP_STEPS[1]; THIRD_STEP = NEW_SIGNUP_STEPS[2]; FOURTH_STEP = NEW_SIGNUP_STEPS[3]; - LAST_STEP = NEW_SIGNUP_STEPS[4]; - + FIFTH_STEP = NEW_SIGNUP_STEPS[4]; + LAST_STEP = NEW_SIGNUP_STEPS[5]; + get isDevMode() { + return this.featureFlag.isDevMode; + } @tracked signupDetails = { firstName: '', lastName: '', username: '', roles: {}, }; - @action changeStepToTwo() { this.currentStep = this.SECOND_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_GETTING_STARTED); } - async generateUsername(firstname, lastname) { if (typeof firstname !== 'string' || typeof lastname !== 'string') { throw new Error('Invalid input: firstname and lastname must be strings'); @@ -46,7 +44,6 @@ export default class NewSignUpController extends Controller { try { const sanitizedFirstname = firstname.toLowerCase(); const sanitizedLastname = lastname.toLowerCase(); - const response = await fetch( `${ENV.BASE_API_URL}/users/username?dev=true&firstname=${sanitizedFirstname}&lastname=${sanitizedLastname}`, { @@ -58,7 +55,6 @@ export default class NewSignUpController extends Controller { } ); const user = await response.json(); - if (user && user.username) { return user; } @@ -74,45 +70,40 @@ export default class NewSignUpController extends Controller { throw new Error(ERROR_MESSAGES.usernameGeneration); } } - @action changeStepToThree() { this.currentStep = this.THIRD_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_FIRST_NAME); this.isButtonDisabled = true; } - @action changeStepToFour() { this.currentStep = this.FOURTH_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_LAST_NAME); this.isButtonDisabled = true; } - @action changeStepToFive() { this.currentStep = this.FIFTH_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_USERNAME); this.isButtonDisabled = true; } - @action register() { this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_ROLE); this.isButtonDisabled = true; this.signup(); } - @action completeSignUp() { - console.log('click'); this.analytics.trackEvent(NEW_SIGNUP_FLOW.NEW_SIGNUP_FLOW_DONE); - - window.open(GOTO_URL, '_self'); + if (this.isDevMode) { + window.open('https://realdevsquad.com/goto?dev=true', '_self'); + } else { + window.open(GOTO_URL, '_self'); + } } - @action handleInputChange(key, value) { this.error = ''; set(this.signupDetails, key, value); if (this.signupDetails[key] > '') this.isButtonDisabled = false; else this.isButtonDisabled = true; } - @action handleCheckboxInputChange(key, value) { set(this.signupDetails.roles, key, value); if (Object.values(this.signupDetails.roles).includes(true)) { @@ -121,7 +112,6 @@ export default class NewSignUpController extends Controller { this.isButtonDisabled = true; } } - @action async signup() { try { let user; @@ -142,7 +132,6 @@ export default class NewSignUpController extends Controller { roles[key] = value; } }); - const isUsernameAvailable = await checkUserName(signupDetails.username); if (!isUsernameAvailable) { this.analytics.trackEvent(NEW_SIGNUP_FLOW.USERNAME_NOT_AVAILABLE); @@ -150,7 +139,6 @@ export default class NewSignUpController extends Controller { this.isButtonDisabled = false; return (this.error = ERROR_MESSAGES.userName); } - const res = this.isDevMode ? await newRegisterUser(signupDetails, roles) : await registerUser(signupDetails); diff --git a/app/templates/discord.hbs b/app/templates/discord.hbs index 8587af7d..70050d8a 100644 --- a/app/templates/discord.hbs +++ b/app/templates/discord.hbs @@ -10,7 +10,7 @@ {{else}} - {{#if (or @model.userData.discordId (eq this.linkStatus 'linked'))}} + {{#if (and @model.userData.discordId (not @model.userData.roles.archived))}}

Your Discord account has been successfully linked.

@@ -130,4 +130,4 @@ {{/if}} {{/if}} {{/if}} - \ No newline at end of file + diff --git a/app/templates/new-signup.hbs b/app/templates/new-signup.hbs index 5e4b80d3..fe63f92a 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -1,12 +1,3 @@ -{{page-title 'New Sign Up'}} - -{{#if (eq this.currentStep this.FIRST_STEP)}} - -{{/if}} - {{#if (eq this.currentStep this.SECOND_STEP)}} {{/if}} - {{#if (eq this.currentStep this.THIRD_STEP)}} {{#if this.isDevMode}} + {{/if}} {{/if}} {{#if this.isDevMode}} @@ -48,7 +40,6 @@ @error={{this.error}} /> {{/if}} - {{#if (eq this.currentStep this.FIFTH_STEP)}} -{{/if}} --}} + {{/if}} +{{/if}} {{#if (eq this.currentStep this.LAST_STEP)}} fetch(`${BASE_API_URL}/users/self`, { method: 'PATCH', @@ -12,13 +10,25 @@ const registerUser = (user) => credentials: 'include', }); -const newRegisterUser = async (signupDetail, roles) => { +const newRegisterUser = async (signupDetails, roles) => { + const getResponse = await fetch(`${BASE_API_URL}/users/self`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + }); + + const userData = await getResponse.json(); + const res = await registerUser({ - ...signupDetail, + ...signupDetails, roles: { + ...userData.roles, ...roles, }, }); + return res; }; From 5b14051b845a54cdedee4b21cf26ec3d8e9cb7c6 Mon Sep 17 00:00:00 2001 From: vinit717 Date: Sat, 24 Aug 2024 14:43:17 +0530 Subject: [PATCH 3/6] chore: fix discord verification condition --- app/templates/discord.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/discord.hbs b/app/templates/discord.hbs index 70050d8a..ef1fb62b 100644 --- a/app/templates/discord.hbs +++ b/app/templates/discord.hbs @@ -10,7 +10,7 @@
{{else}} - {{#if (and @model.userData.discordId (not @model.userData.roles.archived))}} + {{#if (and @model.userData.discordId (eq @model.userData.roles.archived false))}}

Your Discord account has been successfully linked.

@@ -20,7 +20,7 @@

Something went wrong. Please try again.

- {{else if (eq this.linkStatus 'not-linked')}} + {{else}}
Date: Sat, 24 Aug 2024 15:35:02 +0530 Subject: [PATCH 4/6] chore:remove unnecessary changes --- app/controllers/new-signup.js | 9 +++++++++ app/templates/new-signup.hbs | 8 ++++++++ app/utils/register-api.js | 2 ++ 3 files changed, 19 insertions(+) diff --git a/app/controllers/new-signup.js b/app/controllers/new-signup.js index 0d7bbef3..322cd4de 100644 --- a/app/controllers/new-signup.js +++ b/app/controllers/new-signup.js @@ -9,11 +9,14 @@ import { ERROR_MESSAGES, NEW_SIGNUP_STEPS } from '../constants/new-signup'; import checkUserName from '../utils/check-username'; import ENV from 'website-my/config/environment'; import { toastNotificationTimeoutOptions } from '../constants/toast-notification'; + export default class NewSignUpController extends Controller { @service analytics; @service featureFlag; @service toast; + queryParams = ['currentStep', 'dev']; + @tracked isLoading = false; @tracked isButtonDisabled = true; @tracked error = ''; @@ -24,19 +27,23 @@ export default class NewSignUpController extends Controller { FOURTH_STEP = NEW_SIGNUP_STEPS[3]; FIFTH_STEP = NEW_SIGNUP_STEPS[4]; LAST_STEP = NEW_SIGNUP_STEPS[5]; + get isDevMode() { return this.featureFlag.isDevMode; } + @tracked signupDetails = { firstName: '', lastName: '', username: '', roles: {}, }; + @action changeStepToTwo() { this.currentStep = this.SECOND_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_GETTING_STARTED); } + async generateUsername(firstname, lastname) { if (typeof firstname !== 'string' || typeof lastname !== 'string') { throw new Error('Invalid input: firstname and lastname must be strings'); @@ -44,6 +51,7 @@ export default class NewSignUpController extends Controller { try { const sanitizedFirstname = firstname.toLowerCase(); const sanitizedLastname = lastname.toLowerCase(); + const response = await fetch( `${ENV.BASE_API_URL}/users/username?dev=true&firstname=${sanitizedFirstname}&lastname=${sanitizedLastname}`, { @@ -55,6 +63,7 @@ export default class NewSignUpController extends Controller { } ); const user = await response.json(); + if (user && user.username) { return user; } diff --git a/app/templates/new-signup.hbs b/app/templates/new-signup.hbs index fe63f92a..462f7dcc 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -1,3 +1,11 @@ +{{page-title 'New Sign Up'}} + +{{#if (eq this.currentStep this.FIRST_STEP)}} + +{{/if}} {{#if (eq this.currentStep this.SECOND_STEP)}} fetch(`${BASE_API_URL}/users/self`, { method: 'PATCH', From bba28c3b35f1deed664c143a8f95c043f1823afe Mon Sep 17 00:00:00 2001 From: vinit717 Date: Sat, 24 Aug 2024 15:46:33 +0530 Subject: [PATCH 5/6] chore: remove extra spacing --- app/constants/new-signup.js | 4 ++++ app/controllers/new-signup.js | 10 ++++++++++ app/templates/new-signup.hbs | 2 ++ 3 files changed, 16 insertions(+) diff --git a/app/constants/new-signup.js b/app/constants/new-signup.js index d975ff56..e7a374cb 100644 --- a/app/constants/new-signup.js +++ b/app/constants/new-signup.js @@ -4,6 +4,7 @@ const LAST_NAME = 'lastName'; const USERNAME = 'username'; const ROLE = 'role'; const THANK_YOU = 'thank-you'; + export const NEW_SIGNUP_STEPS = [ GET_STARTED, FIRST_NAME, @@ -12,17 +13,20 @@ export const NEW_SIGNUP_STEPS = [ ROLE, THANK_YOU, ]; + export const LABEL_TEXT = { firstName: 'What is your first name?', lastName: 'And what is your last name?', username: 'Now choose your awesome username!', role: 'Select your role', }; + export const ERROR_MESSAGES = { userName: 'username already taken!', others: 'something went wrong', usernameGeneration: 'Username cannot be generated', }; + export const CHECK_BOX_DATA = [ { label: 'Developer', diff --git a/app/controllers/new-signup.js b/app/controllers/new-signup.js index 322cd4de..88677e83 100644 --- a/app/controllers/new-signup.js +++ b/app/controllers/new-signup.js @@ -79,26 +79,31 @@ export default class NewSignUpController extends Controller { throw new Error(ERROR_MESSAGES.usernameGeneration); } } + @action changeStepToThree() { this.currentStep = this.THIRD_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_FIRST_NAME); this.isButtonDisabled = true; } + @action changeStepToFour() { this.currentStep = this.FOURTH_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_LAST_NAME); this.isButtonDisabled = true; } + @action changeStepToFive() { this.currentStep = this.FIFTH_STEP; this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_USERNAME); this.isButtonDisabled = true; } + @action register() { this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_ROLE); this.isButtonDisabled = true; this.signup(); } + @action completeSignUp() { this.analytics.trackEvent(NEW_SIGNUP_FLOW.NEW_SIGNUP_FLOW_DONE); if (this.isDevMode) { @@ -107,12 +112,14 @@ export default class NewSignUpController extends Controller { window.open(GOTO_URL, '_self'); } } + @action handleInputChange(key, value) { this.error = ''; set(this.signupDetails, key, value); if (this.signupDetails[key] > '') this.isButtonDisabled = false; else this.isButtonDisabled = true; } + @action handleCheckboxInputChange(key, value) { set(this.signupDetails.roles, key, value); if (Object.values(this.signupDetails.roles).includes(true)) { @@ -121,6 +128,7 @@ export default class NewSignUpController extends Controller { this.isButtonDisabled = true; } } + @action async signup() { try { let user; @@ -141,6 +149,7 @@ export default class NewSignUpController extends Controller { roles[key] = value; } }); + const isUsernameAvailable = await checkUserName(signupDetails.username); if (!isUsernameAvailable) { this.analytics.trackEvent(NEW_SIGNUP_FLOW.USERNAME_NOT_AVAILABLE); @@ -148,6 +157,7 @@ export default class NewSignUpController extends Controller { this.isButtonDisabled = false; return (this.error = ERROR_MESSAGES.userName); } + const res = this.isDevMode ? await newRegisterUser(signupDetails, roles) : await registerUser(signupDetails); diff --git a/app/templates/new-signup.hbs b/app/templates/new-signup.hbs index 462f7dcc..82ea4d96 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -6,6 +6,7 @@ @currentStep={{this.currentStep}} /> {{/if}} + {{#if (eq this.currentStep this.SECOND_STEP)}} {{/if}} + {{#if (eq this.currentStep this.THIRD_STEP)}} {{#if this.isDevMode}} Date: Sat, 24 Aug 2024 15:47:49 +0530 Subject: [PATCH 6/6] chore: remove extra spacing --- app/templates/new-signup.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/templates/new-signup.hbs b/app/templates/new-signup.hbs index 82ea4d96..d208ed48 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -50,6 +50,7 @@ @error={{this.error}} /> {{/if}} + {{#if (eq this.currentStep this.FIFTH_STEP)}}