Skip to content

Commit

Permalink
Merge pull request #188 from kossiitkgp/26-nov-sprint
Browse files Browse the repository at this point in the history
Show email and college field in frontend
  • Loading branch information
chirag-ghosh authored Nov 26, 2023
2 parents c73b527 + 7d75f91 commit 6e81c31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/pages/OAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function OAuth() {
name: auth.name,
email: auth.email,
type: auth.type,
college: auth.college,
},
});

Expand Down
23 changes: 11 additions & 12 deletions src/pages/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down Expand Up @@ -81,6 +84,7 @@ function RegistrationForm({ isStudent }: { isStudent: boolean }) {
username: authContext.userData.username,
name: responses.name,
email: responses.email,
college: responses.college,
};

try {
Expand All @@ -92,28 +96,23 @@ 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);
} else {
authContext.updateUserData(responses.name, responses.email);
authContext.updateUserData(
responses.name,
responses.email,
responses?.college,
);
setInfo("Information successfully changed.");
}

setLoading(false);
}

setLoading(false);
return res.is_ok;
} catch (e) {
setError("Error sending the request. Please try again later.");
Expand Down
15 changes: 13 additions & 2 deletions src/util/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IUserAuthData {
name: string;
email: string;
type: UserType;
college: string | undefined;
}

interface ILocalStorageAuthObj {
Expand All @@ -30,6 +31,7 @@ const DEFAULT_AUTH_OBJ: ILocalStorageAuthObj = {
name: "",
email: "",
type: "mentor",
college: "",
},
};

Expand All @@ -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;
Expand Down Expand Up @@ -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,
},
});
};
Expand Down
1 change: 1 addition & 0 deletions src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IEndpointTypes {
name: string;
type: UserType;
username: string;
college: string | undefined;
};
};
"student/form": {
Expand Down

0 comments on commit 6e81c31

Please sign in to comment.