From fcdaebeb7e78b4b939145ffec34499da7683ce83 Mon Sep 17 00:00:00 2001 From: vinit717 Date: Sat, 24 Aug 2024 14:06:53 +0530 Subject: [PATCH] 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; };