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

Update useSignup.tsx to send capitalized name and surname to backend #801

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open
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
40 changes: 31 additions & 9 deletions apps/web/hooks/auth/useSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function useSignup() {
});
handleRouteBasedOnScreenResponse(data.screen as SCREENS, push);
},
onError(error) {
onError(error:any) {
if (error.error === 'EmailAlreadyExists') {
setError('email', {
type: 'manual',
Expand All @@ -62,16 +62,38 @@ export function useSignup() {
},
});

const onSignup = (data: ISignupFormData) => {
const signupData: ISignupData = {
firstName: data.fullName.split(' ')[0],
lastName: data.fullName.split(' ')[1],
email: data.email,
password: data.password,
};
signup(signupData);
/**
* Name formater to capitalize the first letter
* @param name string to capitalize
* @returns a string with the name with capital letter at char position 0
*/
const formatName = (name: string): string => {
if (!name) return '';
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
};


/**
* Now we can send the info in the right format to the back end
*/
const onSignup = (data: ISignupFormData) => {
const nameParts = data.fullName.trim().split(' ');// We save the name parts as an array with the fristName and the lastName


const firstName = formatName(nameParts[0]);
const lastName = nameParts.length > 1 ? formatName(nameParts.slice(1).join(' ')) : '';

const signupData: ISignupData = {
firstName: firstName,
lastName: lastName,
email: data.email,
password: data.password,
};

signup(signupData);
};


return {
errors,
register,
Expand Down