Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshayman committed Aug 18, 2024
1 parent 0394616 commit a14eda8
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions app/controllers/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default class NewSignUpController extends Controller {
@action async signup() {
try {
let user;
this.isLoading = true;
if (!this.isDevMode)
user = await this.generateUsername(
this.signupDetails.firstName,
Expand All @@ -149,8 +150,6 @@ export default class NewSignUpController extends Controller {
}
});

this.isLoading = true;

const isUsernameAvailable = await checkUserName(signupDetails.username);
if (!isUsernameAvailable) {
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USERNAME_NOT_AVAILABLE);
Expand All @@ -159,29 +158,17 @@ export default class NewSignUpController extends Controller {
return (this.error = ERROR_MESSAGES.userName);
}

if (this.isDevMode) {
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;
}
const res = this.isDevMode
? await newRegisterUser(signupDetails, roles)
: await registerUser(signupDetails);
if (res.status === 204) {
this.analytics.identifyUser();
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_REGISTERED);
this.currentStep = this.LAST_STEP;
} else {
//this will get removed after removing feature flag
const res = await registerUser(signupDetails);
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;
}
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);
Expand Down

0 comments on commit a14eda8

Please sign in to comment.