Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vinit717 committed Aug 24, 2024
1 parent 42dbd1a commit fcdaebe
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 63 deletions.
17 changes: 13 additions & 4 deletions app/constants/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,42 @@ 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,
];

export const LABEL_TEXT = {
firstName: 'What is your first name?',
lastName: 'And what is your last name?',
username: 'Now choose your awesome username!',
role: 'Select your role',
};

export const ERROR_MESSAGES = {
userName: 'username already taken!',
others: 'something went wrong',
usernameGeneration: 'Username cannot be generated',
};

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
32 changes: 10 additions & 22 deletions app/controllers/new-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import { ERROR_MESSAGES, NEW_SIGNUP_STEPS } from '../constants/new-signup';
import checkUserName from '../utils/check-username';
import ENV from 'website-my/config/environment';
import { toastNotificationTimeoutOptions } from '../constants/toast-notification';

export default class NewSignUpController extends Controller {
@service analytics;
@service featureFlag;
@service toast;

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

@tracked isLoading = false;
@tracked isButtonDisabled = true;
@tracked error = '';
Expand All @@ -25,28 +22,28 @@ export default class NewSignUpController extends Controller {
SECOND_STEP = NEW_SIGNUP_STEPS[1];
THIRD_STEP = NEW_SIGNUP_STEPS[2];
FOURTH_STEP = NEW_SIGNUP_STEPS[3];
LAST_STEP = NEW_SIGNUP_STEPS[4];

FIFTH_STEP = NEW_SIGNUP_STEPS[4];
LAST_STEP = NEW_SIGNUP_STEPS[5];
get isDevMode() {
return this.featureFlag.isDevMode;
}
@tracked signupDetails = {
firstName: '',
lastName: '',
username: '',
roles: {},
};

@action changeStepToTwo() {
this.currentStep = this.SECOND_STEP;
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_GETTING_STARTED);
}

async generateUsername(firstname, lastname) {
if (typeof firstname !== 'string' || typeof lastname !== 'string') {
throw new Error('Invalid input: firstname and lastname must be strings');
}
try {
const sanitizedFirstname = firstname.toLowerCase();
const sanitizedLastname = lastname.toLowerCase();

const response = await fetch(
`${ENV.BASE_API_URL}/users/username?dev=true&firstname=${sanitizedFirstname}&lastname=${sanitizedLastname}`,
{
Expand All @@ -58,7 +55,6 @@ export default class NewSignUpController extends Controller {
}
);
const user = await response.json();

if (user && user.username) {
return user;
}
Expand All @@ -74,45 +70,40 @@ export default class NewSignUpController extends Controller {
throw new Error(ERROR_MESSAGES.usernameGeneration);
}
}

@action changeStepToThree() {
this.currentStep = this.THIRD_STEP;
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_FIRST_NAME);
this.isButtonDisabled = true;
}

@action changeStepToFour() {
this.currentStep = this.FOURTH_STEP;
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_LAST_NAME);
this.isButtonDisabled = true;
}

@action changeStepToFive() {
this.currentStep = this.FIFTH_STEP;
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_USERNAME);
this.isButtonDisabled = true;
}

@action register() {
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USER_ROLE);
this.isButtonDisabled = true;
this.signup();
}

@action completeSignUp() {
console.log('click');
this.analytics.trackEvent(NEW_SIGNUP_FLOW.NEW_SIGNUP_FLOW_DONE);

window.open(GOTO_URL, '_self');
if (this.isDevMode) {
window.open('https://realdevsquad.com/goto?dev=true', '_self');
} else {
window.open(GOTO_URL, '_self');
}
}

@action handleInputChange(key, value) {
this.error = '';
set(this.signupDetails, key, value);
if (this.signupDetails[key] > '') this.isButtonDisabled = false;
else this.isButtonDisabled = true;
}

@action handleCheckboxInputChange(key, value) {
set(this.signupDetails.roles, key, value);
if (Object.values(this.signupDetails.roles).includes(true)) {
Expand All @@ -121,7 +112,6 @@ export default class NewSignUpController extends Controller {
this.isButtonDisabled = true;
}
}

@action async signup() {
try {
let user;
Expand All @@ -142,15 +132,13 @@ export default class NewSignUpController extends Controller {
roles[key] = value;
}
});

const isUsernameAvailable = await checkUserName(signupDetails.username);
if (!isUsernameAvailable) {
this.analytics.trackEvent(NEW_SIGNUP_FLOW.USERNAME_NOT_AVAILABLE);
this.isLoading = false;
this.isButtonDisabled = false;
return (this.error = ERROR_MESSAGES.userName);
}

const res = this.isDevMode
? await newRegisterUser(signupDetails, roles)
: await registerUser(signupDetails);
Expand Down
4 changes: 2 additions & 2 deletions app/templates/discord.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Spinner />
</div>
{{else}}
{{#if (or @model.userData.discordId (eq this.linkStatus 'linked'))}}
{{#if (and @model.userData.discordId (not @model.userData.roles.archived))}}
<div class='discord__success'>
<p class='success__text'>Your Discord account has been successfully
linked.</p>
Expand Down Expand Up @@ -130,4 +130,4 @@
{{/if}}
{{/if}}
{{/if}}
</section>
</section>
18 changes: 5 additions & 13 deletions app/templates/new-signup.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{{page-title 'New Sign Up'}}

{{#if (eq this.currentStep this.FIRST_STEP)}}
<NewSignup::Info
@onClick={{this.changeStepToTwo}}
@currentStep={{this.currentStep}}
/>
{{/if}}

{{#if (eq this.currentStep this.SECOND_STEP)}}
<NewSignup::Input
@onClick={{this.changeStepToThree}}
Expand All @@ -16,7 +7,6 @@
@isLoading={{this.isLoading}}
/>
{{/if}}

{{#if (eq this.currentStep this.THIRD_STEP)}}
{{#if this.isDevMode}}
<NewSignup::Input
Expand All @@ -30,10 +20,12 @@
<NewSignup::Input
@onClick={{this.register}}
@currentStep={{this.currentStep}}
@onChange={{this.handleCheckboxInputChange}}
@onChange={{this.handleInputChange}}
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
@error={{this.error}}
/>
{{/if}}
{{/if}}

{{#if this.isDevMode}}
Expand All @@ -48,7 +40,6 @@
@error={{this.error}}
/>
{{/if}}

{{#if (eq this.currentStep this.FIFTH_STEP)}}
<NewSignup::Checkbox
@onClick={{this.register}}
Expand All @@ -57,7 +48,8 @@
@isButtonDisabled={{this.isButtonDisabled}}
@isLoading={{this.isLoading}}
/>
{{/if}} --}}
{{/if}}
{{/if}}

{{#if (eq this.currentStep this.LAST_STEP)}}
<NewSignup::Info
Expand Down
25 changes: 7 additions & 18 deletions app/utils/check-username.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import ENV from 'website-my/config/environment';

const BASE_URL = ENV.BASE_API_URL;

export default async function checkUserName(firstname, lastname) {
export default async function checkUserName(userName) {
try {
const sanitizedFirstname = firstname.toLowerCase();
const sanitizedLastname = lastname.toLowerCase();
const lowerCaseUsername = userName.toLowerCase();
const response = await fetch(
`${BASE_URL}/users/username?firstname=${sanitizedFirstname}&lastname=${sanitizedLastname}&dev=true`,
`${BASE_URL}/users/isUsernameAvailable/${lowerCaseUsername}`,
{
method: 'GET',
headers: {
Expand All @@ -17,19 +16,9 @@ export default async function checkUserName(firstname, lastname) {
}
);
const data = await response.json();
if (response.status === 200) {
return data;
} else if (response.status === 401) {
console.error('401');
// this.toast.error(
// 'Please login to continue.',
// '',
// toastNotificationTimeoutOptions
// );
}
} catch (err) {
console.error('40111111111111', err);

// this.toast.error('Something went wrong!', 'error!', TOAST_OPTIONS);
const { isUsernameAvailable } = data;
return isUsernameAvailable;
} catch (error) {
console.error('Error : ', error);
}
}
18 changes: 14 additions & 4 deletions app/utils/register-api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ENV from 'website-my/config/environment';

const { BASE_API_URL } = ENV;

const registerUser = (user) =>
fetch(`${BASE_API_URL}/users/self`, {
method: 'PATCH',
Expand All @@ -12,13 +10,25 @@ const registerUser = (user) =>
credentials: 'include',
});

const newRegisterUser = async (signupDetail, roles) => {
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 res = await registerUser({
...signupDetail,
...signupDetails,
roles: {
...userData.roles,
...roles,
},
});

return res;
};

Expand Down

0 comments on commit fcdaebe

Please sign in to comment.