Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user signup #567

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/constants/new-signup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const GET_STARTED = 'get-started';
const FIRST_NAME = 'firstName';
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,
];
Expand All @@ -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!';
Expand Down
82 changes: 25 additions & 57 deletions app/controllers/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = '';
Expand All @@ -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: '',
Expand Down Expand Up @@ -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) {
Expand All @@ -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]) => {
Expand All @@ -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;
}
}
}
25 changes: 0 additions & 25 deletions app/templates/new-signup.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,13 @@
{{/if}}

{{#if (eq this.currentStep this.FOURTH_STEP)}}
{{#if this.isDevMode}}
<NewSignup::Input
@onClick={{this.changeStepToFive}}
@currentStep={{this.currentStep}}
@dev={{this.isDevMode}}
@onChange={{this.handleInputChange}}
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
@error={{this.error}}
/>
{{else}}
<NewSignup::Input
@onClick={{this.register}}
@currentStep={{this.currentStep}}
@onChange={{this.handleInputChange}}
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
@error={{this.error}}
/>
{{/if}}
{{/if}}

{{#if this.isDevMode}}
{{#if (eq this.currentStep this.FIFTH_STEP)}}
<NewSignup::Checkbox
@onClick={{this.register}}
@currentStep={{this.currentStep}}
@onChange={{this.handleCheckboxInputChange}}
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
/>
{{/if}}
{{/if}}

{{#if (eq this.currentStep this.LAST_STEP)}}
Expand Down
18 changes: 11 additions & 7 deletions app/utils/check-username.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
}
}
16 changes: 2 additions & 14 deletions app/utils/register-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading