Skip to content

Commit

Permalink
added feature flag in signup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsinghbundela committed Jul 14, 2023
1 parent b1ae836 commit 2ef89cd
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 62 deletions.
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}}
>
Next
</Button>
{{#if this.dev}}
<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>
101 changes: 63 additions & 38 deletions app/controllers/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 @@ -93,10 +93,12 @@ export default class NewSignUpController extends Controller {
@action async signup() {
let roles;

if (this.developer) {
roles = { developer: this.developer };
} else {
roles = { designer: this.designer };
if (this.dev) {
if (this.developer) {
roles = { developer: this.developer };
} else {
roles = { designer: this.designer };
}
}
const signupDetails = {
first_name: this.signupDetails.firstName,
Expand All @@ -113,41 +115,64 @@ export default class NewSignUpController extends Controller {
return (this.error = ERROR_MESSAGES.userName);
}

fetch(`${BASE_API_URL}/users/self`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
})
.then((getResponse) => getResponse.json())
.then((userData) => {
return registerUser({
...signupDetails,
roles: {
...userData.roles,
...roles,
},
});
if (this.dev) {
fetch(`${BASE_API_URL}/users/self`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
})
.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);
.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;
});
}
}
}
45 changes: 29 additions & 16 deletions app/templates/new-signup.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,37 @@
{{/if}}

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

0 comments on commit 2ef89cd

Please sign in to comment.