Skip to content

Commit 6e2e2ec

Browse files
Create Profile Page (#84)
2 parents 1574503 + dc096c4 commit 6e2e2ec

File tree

18 files changed

+225
-423
lines changed

18 files changed

+225
-423
lines changed

.github/workflows/eslint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ jobs:
2323
- name: Run EsLint
2424
uses: sibiraj-s/action-eslint@v3
2525
with:
26-
eslint-args: "src/**/*.{js,jsx,ts,tsx} --max-warnings=0"
27-
extensions: "js,jsx,ts,tsx"
26+
eslint-args: "src/**/*.{ts,tsx} --max-warnings=0"
27+
extensions: "ts,tsx"
2828
annotations: true

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import StaffPage from "./staff/pages/Staff.tsx";
1010
import Department from "./staff/pages/Department.tsx";
1111
import CreatePost from "./staff/pages/CreatePost.tsx";
1212
import IndividualPost from "./opportunities/pages/IndividualPost.js";
13-
import ProfilePage from "./shared/pages/Profile.js";
13+
import ProfilePage from "./shared/pages/Profile.tsx";
1414
import LoginRedirection from "./auth/Login.tsx";
1515
import LogoutRedirection from "./auth/Logout.tsx";
1616
import StickyFooter from "./shared/components/Navigation/StickyFooter.tsx";

src/auth/Logout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function LogoutRedirection() {
3232
}
3333
}
3434
logoutUser();
35-
}, [auth, logout]);
35+
}, [logout, auth.token]);
3636

3737
return null; // Since this component doesn't need to render anything
3838
};

src/auth/Token.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useAuth } from "../context/AuthContext.tsx";
2+
import { useEffect } from "react";
23

34
export default function Token() {
45

@@ -7,26 +8,30 @@ export default function Token() {
78
const urlParams = new URLSearchParams(window.location.search);
89
const code = urlParams.get("code");
910

10-
if (code) {
11-
fetch(`${process.env.REACT_APP_BACKEND_SERVER}/token`, {
12-
method: "POST",
13-
headers: {
14-
"Content-Type": "application/json",
15-
},
16-
body: JSON.stringify({ code }),
17-
})
18-
.then((response) => response.json())
19-
.then((data) => {
20-
const token = data.token;
21-
if (token) {
22-
login(token);
23-
return null;
24-
}
11+
useEffect(() => {
12+
async function fetchToken(code: string) {
13+
fetch(`${process.env.REACT_APP_BACKEND_SERVER}/token`, {
14+
method: "POST",
15+
headers: {
16+
"Content-Type": "application/json",
17+
},
18+
body: JSON.stringify({ code }),
2519
})
26-
.catch((error) => console.error("Error fetching token:", error));
27-
} else {
28-
window.location.href = "/";
29-
}
20+
.then((response) => response.json())
21+
.then((data) => {
22+
const token = data.token;
23+
if (token) {
24+
login(token);
25+
window.location.href = "/";
26+
return null;
27+
}
28+
})
29+
.catch((error) => console.error("Error fetching token:", error));
30+
}
31+
if (code) {
32+
fetchToken(code);
33+
}
34+
}, [code, login]);
3035

3136
return null;
3237
}

src/context/AuthContext.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { createContext, useState, useContext } from 'react';
1+
import React, { createContext, useState, useContext, useEffect } from 'react';
2+
import { ReactNode } from 'react';
3+
24

35
const AuthContext = createContext<{
46
auth: { isAuthenticated: boolean; token: string | null };
@@ -11,9 +13,6 @@ const AuthContext = createContext<{
1113
logout: () => { },
1214
loadToken: () => { }
1315
});
14-
15-
import { ReactNode } from 'react';
16-
1716
interface AuthProviderProps {
1817
children: ReactNode;
1918
}
@@ -43,6 +42,10 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
4342
}
4443
};
4544

45+
useEffect(() => {
46+
loadToken();
47+
}, []);
48+
4649
return (
4750
<AuthContext.Provider value={{ auth, login, logout, loadToken }}>
4851
{children}

src/shared/components/Navigation/MainNavigation.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import React from "react";
22
import { Disclosure } from "@headlessui/react";
33
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline";
44
import { Link, NavLink, useLocation } from "react-router-dom";
5+
import { useAuth } from "../../../context/AuthContext.tsx";
56

6-
export default function MainNavigation(authenticated) {
7+
export default function MainNavigation() {
8+
9+
const { auth } = useAuth();
710

811
const location = useLocation().pathname;
9-
const routes = authenticated.authenticated[1]
12+
const routes = auth.isAuthenticated
1013
? [
1114
{ name: "Jobs", href: "/jobs", current: true },
1215
{ name: "Create", href: "/create", current: false },

src/shared/components/Navigation/StickyFooter.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from "react";
22
import { Link } from "react-router-dom";
33
import logo from "../../../images/LabConnect_Logo.webp";
4+
import { useAuth } from "../../../context/AuthContext.tsx";
45

5-
export default function StickyFooter(authenticated) {
6+
export default function StickyFooter() {
67

7-
const routes = authenticated.authenticated[1]
8+
const { auth } = useAuth();
9+
10+
const routes = auth.isAuthenticated
811
? [
912
{ name: "Jobs", href: "/jobs", current: true },
1013
{ name: "Create", href: "/create", current: false },
File renamed without changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from "react";
2+
import ProfileAvatar from "./ProfileAvatar.tsx";
3+
import ProfileDescription from "./ProfileDescription.tsx";
4+
import ProfileOpportunities from "./ProfileOpportunities.tsx";
5+
import SEO from "..//SEO.tsx";
6+
import Breadcrumb from "../UIElements/Breadcrumb.tsx";
7+
8+
interface Profile {
9+
name: string;
10+
image: string;
11+
department: string;
12+
description: string;
13+
website?: string;
14+
}
15+
16+
const ProfileComponents = ({ profile, id, staff }: { profile: Profile, id: string, staff: boolean }) => {
17+
return (
18+
<>
19+
<SEO title={`${profile.name} - Labconnect`} description={`${profile.department} page on labconnect`} />
20+
{staff && <Breadcrumb
21+
tree={[
22+
{
23+
link: "/staff",
24+
title: "Staff",
25+
},
26+
{
27+
link: `/staff/department/${profile.department}`,
28+
title: profile.department || "Unknown Department",
29+
}, {
30+
link: `/staff/${id}`,
31+
title: profile.name || "Unknown Staff",
32+
}
33+
]}
34+
/>}
35+
<section className="mt-5">
36+
<div className="flex gap-5">
37+
<ProfileAvatar name={profile.name} image={profile.image} />
38+
<ProfileDescription
39+
website={profile.website}
40+
{...profile}
41+
/>
42+
</div>
43+
{id && <ProfileOpportunities id={id} staff={staff} />}
44+
</section>
45+
</>
46+
);
47+
}
48+
49+
export default ProfileComponents;

src/staff/components/ProfileDescription.tsx renamed to src/shared/components/Profile/ProfileDescription.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ const ProfileDescription = ({ name, department, description, website }) => {
88
<h2 className="font-extrabold text-5xl">{name}</h2>
99
<h5 className="text-gray-700">{department}</h5>
1010
<p>{description}</p>
11-
<Link to={website} target="_blank">
12-
{website}
13-
</Link>
11+
{website && website.length && (
12+
<Link to={website} target="_blank">
13+
{website}
14+
</Link>
15+
)}
1416
</div>
1517
);
1618
};

0 commit comments

Comments
 (0)