From caeb48e36abda59a8afb777fda14fce1f3665b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20V=C3=A9lez?= Date: Wed, 4 Sep 2024 13:59:52 +0200 Subject: [PATCH 1/2] Update useSignup.tsx --- apps/web/hooks/auth/useSignup.tsx | 36 ++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/apps/web/hooks/auth/useSignup.tsx b/apps/web/hooks/auth/useSignup.tsx index 99edb230..1a64640b 100644 --- a/apps/web/hooks/auth/useSignup.tsx +++ b/apps/web/hooks/auth/useSignup.tsx @@ -62,16 +62,36 @@ 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, From 402bd6b20c24174d400860658008fc64850fdd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20V=C3=A9lez?= Date: Fri, 20 Sep 2024 13:07:02 +0200 Subject: [PATCH 2/2] Fix tab spaces on document --- apps/web/hooks/auth/useSignup.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/hooks/auth/useSignup.tsx b/apps/web/hooks/auth/useSignup.tsx index 1a64640b..b0af49ff 100644 --- a/apps/web/hooks/auth/useSignup.tsx +++ b/apps/web/hooks/auth/useSignup.tsx @@ -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', @@ -67,7 +67,7 @@ export function useSignup() { * @param name string to capitalize * @returns a string with the name with capital letter at char position 0 */ - const formatName = (name: string): string => { +const formatName = (name: string): string => { if (!name) return ''; return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); }; @@ -92,6 +92,8 @@ const onSignup = (data: ISignupFormData) => { signup(signupData); }; + + return { errors, register,