From 6ee97ae16ed79992dd5c54593310264d8b090f53 Mon Sep 17 00:00:00 2001 From: Rohan Barsagade Date: Sun, 26 Nov 2023 19:43:50 +0530 Subject: [PATCH 1/4] fix: send college in in the API request --- src/pages/RegistrationForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/RegistrationForm.tsx b/src/pages/RegistrationForm.tsx index d4223a70..5f10c86b 100644 --- a/src/pages/RegistrationForm.tsx +++ b/src/pages/RegistrationForm.tsx @@ -81,6 +81,7 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { username: authContext.userData.username, name: responses.name, email: responses.email, + college: responses.college || null, }; try { From 0600c100ab209b730566781271bdf6c021f9054a Mon Sep 17 00:00:00 2001 From: Rohan Barsagade Date: Sun, 26 Nov 2023 19:44:39 +0530 Subject: [PATCH 2/4] refactor: remove console logs --- src/pages/RegistrationForm.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pages/RegistrationForm.tsx b/src/pages/RegistrationForm.tsx index 5f10c86b..551f3655 100644 --- a/src/pages/RegistrationForm.tsx +++ b/src/pages/RegistrationForm.tsx @@ -93,17 +93,9 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { authContext.jwt, ); - console.log(res); - if (!res.is_ok) setError(res.response.message); else { if (isRegistering) { - console.log( - "lol", - userData, - userType, - authContext.userData.type, - ); authContext.onRegister({ ...userData, type: userType }); navigate(authContext.dashboardLink); From 865ffbab2be7780cca38bec0666fe89f7026f058 Mon Sep 17 00:00:00 2001 From: Rohan Barsagade Date: Sun, 26 Nov 2023 19:45:04 +0530 Subject: [PATCH 3/4] fix: always set loading to false in the end --- src/pages/RegistrationForm.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/RegistrationForm.tsx b/src/pages/RegistrationForm.tsx index 551f3655..124310af 100644 --- a/src/pages/RegistrationForm.tsx +++ b/src/pages/RegistrationForm.tsx @@ -103,10 +103,9 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { authContext.updateUserData(responses.name, responses.email); setInfo("Information successfully changed."); } - - setLoading(false); } + setLoading(false); return res.is_ok; } catch (e) { setError("Error sending the request. Please try again later."); From 7d75f9157661ae6bc3fc6d346977a3edc7a94e60 Mon Sep 17 00:00:00 2001 From: Rohan Barsagade Date: Mon, 27 Nov 2023 00:03:32 +0530 Subject: [PATCH 4/4] fix: fixed email and college field empty(#184) --- src/pages/OAuth.tsx | 1 + src/pages/RegistrationForm.tsx | 13 ++++++++++--- src/util/auth.tsx | 15 +++++++++++++-- src/util/types.ts | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/pages/OAuth.tsx b/src/pages/OAuth.tsx index 06ada1ea..4e282de8 100644 --- a/src/pages/OAuth.tsx +++ b/src/pages/OAuth.tsx @@ -31,6 +31,7 @@ function OAuth() { name: auth.name, email: auth.email, type: auth.type, + college: auth.college, }, }); diff --git a/src/pages/RegistrationForm.tsx b/src/pages/RegistrationForm.tsx index 124310af..adda36b7 100644 --- a/src/pages/RegistrationForm.tsx +++ b/src/pages/RegistrationForm.tsx @@ -45,12 +45,15 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { }, }; - if (isStudent) + if (isStudent) { fields["college"] = { field: "College (Optional)", placeholder: "IIT Kharagpur", type: "text", + defaultValue: authContext.userData?.college ?? "", + required: false, }; + } return ( <> @@ -81,7 +84,7 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { username: authContext.userData.username, name: responses.name, email: responses.email, - college: responses.college || null, + college: responses.college, }; try { @@ -100,7 +103,11 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) { navigate(authContext.dashboardLink); } else { - authContext.updateUserData(responses.name, responses.email); + authContext.updateUserData( + responses.name, + responses.email, + responses?.college, + ); setInfo("Information successfully changed."); } } diff --git a/src/util/auth.tsx b/src/util/auth.tsx index 0fc7000c..87bcfa43 100644 --- a/src/util/auth.tsx +++ b/src/util/auth.tsx @@ -14,6 +14,7 @@ interface IUserAuthData { name: string; email: string; type: UserType; + college: string | undefined; } interface ILocalStorageAuthObj { @@ -30,6 +31,7 @@ const DEFAULT_AUTH_OBJ: ILocalStorageAuthObj = { name: "", email: "", type: "mentor", + college: "", }, }; @@ -41,7 +43,11 @@ interface IAuthContext { formLink: ROUTER_PATHS.STUDENT_FORM | ROUTER_PATHS.MENTOR_FORM; dashboardLink: ROUTER_PATHS.STUDENT_DASHBOARD | ROUTER_PATHS.MENTOR_DASHBOARD; setUserType: (type: UserType) => void; - updateUserData: (name: string, email: string) => void; + updateUserData: ( + name: string, + email: string, + college: string | undefined, + ) => void; onLogin: (auth: ILocalStorageAuthObj) => void; onRegister: (auth: IUserAuthData) => void; onLogout: () => void; @@ -128,13 +134,18 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { ); }; - const updateUserData = (name: string, email: string) => { + const updateUserData = ( + name: string, + email: string, + college: string | undefined = undefined, + ) => { setUserAuth({ ...userAuth, userData: { ...userAuth.userData, name: name, email: email, + college: college, }, }); }; diff --git a/src/util/types.ts b/src/util/types.ts index 79f1409a..6d4595e5 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -18,6 +18,7 @@ export interface IEndpointTypes { name: string; type: UserType; username: string; + college: string | undefined; }; }; "student/form": {