diff --git a/app/constants/new-signup.js b/app/constants/new-signup.js index 81fd0bc5..592df5b3 100644 --- a/app/constants/new-signup.js +++ b/app/constants/new-signup.js @@ -1,7 +1,6 @@ const GET_STARTED = 'get-started'; const FIRST_NAME = 'firstName'; const LAST_NAME = 'lastName'; -const USERNAME = 'username'; const ROLE = 'role'; const THANK_YOU = 'thank-you'; @@ -9,7 +8,6 @@ export const NEW_SIGNUP_STEPS = [ GET_STARTED, FIRST_NAME, LAST_NAME, - USERNAME, ROLE, THANK_YOU, ]; @@ -31,18 +29,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..46b91785 100644 --- a/app/controllers/new-signup.js +++ b/app/controllers/new-signup.js @@ -2,7 +2,7 @@ import Controller from '@ember/controller'; import { action, set } from '@ember/object'; import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; -import { registerUser, newRegisterUser } from '../utils/register-api'; +import { newRegisterUser } from '../utils/register-api'; import { GOTO_URL } from '../constants/url'; import { NEW_SIGNUP_FLOW } from '../constants/analytics'; import { ERROR_MESSAGES, NEW_SIGNUP_STEPS } from '../constants/new-signup'; @@ -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(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; - } 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..77fd9244 100644 --- a/app/templates/new-signup.hbs +++ b/app/templates/new-signup.hbs @@ -28,30 +28,6 @@ {{/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}} {{/if}} {{#if (eq this.currentStep this.LAST_STEP)}} diff --git a/app/utils/check-username.js b/app/utils/check-username.js index 394036d3..858cf0cf 100644 --- a/app/utils/check-username.js +++ b/app/utils/check-username.js @@ -2,11 +2,12 @@ import ENV from 'website-my/config/environment'; const BASE_URL = ENV.BASE_API_URL; -export default async function checkUserName(userName) { +export default async function checkUserName(firstname, lastname) { try { - const lowerCaseUsername = userName.toLowerCase(); + const sanitizedFirstname = firstname.toLowerCase(); + const sanitizedLastname = lastname.toLowerCase(); const response = await fetch( - `${BASE_URL}/users/isUsernameAvailable/${lowerCaseUsername}`, + `${BASE_URL}/users/username?firstname=${sanitizedFirstname}&lastname=${sanitizedLastname}&dev=true`, { method: 'GET', headers: { @@ -16,9 +17,12 @@ export default async function checkUserName(userName) { } ); const data = await response.json(); - const { isUsernameAvailable } = data; - return isUsernameAvailable; - } catch (error) { - console.error('Error : ', error); + if (response.status === 200) { + return data; + } else if (response.status === 400) { + console.error('400'); + } + } catch (err) { + console.error('40111111111111', err); } } diff --git a/app/utils/register-api.js b/app/utils/register-api.js index 705c3e10..dfeb2cfc 100644 --- a/app/utils/register-api.js +++ b/app/utils/register-api.js @@ -12,25 +12,13 @@ const registerUser = (user) => 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 newRegisterUser = async (signupDetail, roles) => { const res = await registerUser({ - ...signupDetails, + ...signupDetail, roles: { - ...userData.roles, ...roles, }, }); - return res; };