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

added feature flag on new-signup flow #447

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 19 additions & 8 deletions app/components/new-signup/input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@
</div>

<div class='signup-action__btn'>
<Button
@data-test-btn='signup'
@onClick={{@onClick}}
@disabled={{@isButtonDisabled}}
@isLoading={{@isLoading}}
>
{{if (eq @currentStep 'username') 'Submit' 'Next'}}
</Button>
{{#if @dev}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a correct naming convention for this? @dev don't justify the cause

<Button
@data-test-btn='signup'
@onClick={{@onClick}}
@disabled={{@isButtonDisabled}}
@isLoading={{@isLoading}}
>
Next
</Button>
{{else}}
<Button
@data-test-btn='signup'
@onClick={{@onClick}}
@disabled={{@isButtonDisabled}}
@isLoading={{@isLoading}}
>
Submit
</Button>
{{/if}}
</div>
</div>
89 changes: 70 additions & 19 deletions app/controllers/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { GOTO_URL } from '../constants/url';
import { NEW_SIGNUP_FLOW } from '../constants/analytics';
import { ERROR_MESSAGES, NEW_SIGNUP_STEPS } from '../constants/new-signup';
import checkUserName from '../utils/check-username';
import ENV from 'website-my/config/environment';

const { BASE_API_URL } = ENV;

export default class NewSignUpController extends Controller {
@service analytics;

queryParams = ['currentStep'];
queryParams = ['currentStep', 'dev'];

@tracked isLoading = false;
@tracked isButtonDisabled = true;
Expand Down Expand Up @@ -65,6 +68,15 @@ export default class NewSignUpController extends Controller {
}

@action async signup() {
let roles;

if (this.dev) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.dev) {
if (this.isDevMode) {

if (this.developer) {
roles = { developer: this.developer };
} else {
roles = { designer: this.designer };
}
}
const signupDetails = {
first_name: this.signupDetails.firstName,
last_name: this.signupDetails.lastName,
Expand All @@ -80,25 +92,64 @@ export default class NewSignUpController extends Controller {
return (this.error = ERROR_MESSAGES.userName);
}

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);
if (this.dev) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.dev) {
if (this.isDevMode) {

fetch(`${BASE_API_URL}/users/self`, {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not using Ember Data

method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
})
.then((getResponse) => getResponse.json())
.then((userData) => {
return registerUser({
...signupDetails,
roles: {
...userData.roles,
...roles,
},
});
})
.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;
}
})
.catch(() => {
this.analytics.trackEvent(NEW_SIGNUP_FLOW.UNABLE_TO_REGISTER);
this.error = ERROR_MESSAGES.others;
this.isButtonDisabled = false;
})
.finally(() => {
this.isLoading = false;
});
})
.finally(() => {
this.isLoading = false;
});
} else {
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;
});
}
}
}
46 changes: 36 additions & 10 deletions app/templates/new-signup.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "New Sign Up"}}
{{page-title 'New Sign Up'}}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change in quotes?

{{#if (eq this.currentStep this.FIRST_STEP)}}
<NewSignup::Info
Expand All @@ -11,6 +11,7 @@
<NewSignup::Input
@onClick={{this.changeStepToThree}}
@currentStep={{this.currentStep}}
@dev={{this.dev}}
@onChange={{this.handleInputChange}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name can be more precise

@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
Expand All @@ -21,21 +22,46 @@
<NewSignup::Input
@onClick={{this.changeStepToFour}}
@currentStep={{this.currentStep}}
@dev={{this.dev}}
@onChange={{this.handleInputChange}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
@isLoading={{this.isLoading}}
/>
{{/if}}

{{#if (eq this.currentStep this.FOURTH_STEP)}}
<NewSignup::Input
@onClick={{this.register}}
@currentStep={{this.currentStep}}
@onChange={{this.handleInputChange}}
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
@error={{this.error}}
/>
{{#if this.dev}}
<NewSignup::Input
@onClick={{this.changeStepToFive}}
@currentStep={{this.currentStep}}
@dev={{this.dev}}
@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.dev}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change @dev to some more meaningful name

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

{{#if (eq this.currentStep this.LAST_STEP)}}
Expand Down
Loading