Skip to content

Commit ea582ce

Browse files
committed
feat: Add F2F Helper page and template
The code changes add a new F2F Helper page and template to the Hack Shack section of the project. This page displays a list of active participants and allows users to connect with them. The page makes API calls to retrieve the list of students and handles authentication using JWT tokens. The commit message follows the established convention of starting with a type (feat) followed by a concise description of the changes.
1 parent dce8d84 commit ea582ce

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
// eslint-disable-next-line max-len
3+
import GrommetThemeWrapper from '../../../components/hackshack/Grommet/GrommetThemeWrapper';
4+
import Student from './template';
5+
6+
const Students = (props) => {
7+
return (
8+
<GrommetThemeWrapper>
9+
<Student {...props} />
10+
</GrommetThemeWrapper>
11+
);
12+
};
13+
14+
export default Students;
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/* eslint-disable max-len */
2+
import React, { useEffect, useState } from 'react';
3+
import { Heading, Text, Box, Image, DataTable, Button } from 'grommet';
4+
import axios from 'axios';
5+
import PropTypes from 'prop-types';
6+
import { Layout, ScheduleCard, CardGrid } from '../../../components/hackshack';
7+
import { MainTitle } from '../../../components/hackshack/StyledComponents';
8+
import AuthService from '../../../services/auth.service';
9+
import { SEO } from '../../../components';
10+
11+
12+
13+
const Student = (props) => {
14+
const getStudentsApi = `${process.env.GATSBY_WORKSHOPCHALLENGE_API_ENDPOINT}/api/students`;
15+
const [students, setstudents] = useState([]);
16+
const [error, setError] = useState('');
17+
const arr = [];
18+
const [index, setIndex] = useState(0);
19+
const onActive = (nextIndex) => setIndex(nextIndex);
20+
21+
useEffect(() => {
22+
const getToken = () => {
23+
AuthService.login().then(
24+
() => {
25+
getStudents(AuthService.getCurrentUser().accessToken);
26+
},
27+
(err) => {
28+
console.log('Error: ', err);
29+
setError(
30+
'Oops..something went wrong. The HPE Developer team is addressing the problem. Please try again later!',
31+
);
32+
},
33+
);
34+
};
35+
36+
const getStudents = (token) => {
37+
axios({
38+
method: 'GET',
39+
url: getStudentsApi,
40+
headers: { 'x-access-token': token },
41+
})
42+
.then((response) => {
43+
console.log('response ++++', response.data.length);
44+
// Map created
45+
response.data.forEach((student) => {
46+
// Check is student is assigned
47+
if (student.assigned)
48+
arr.push({ ...student });
49+
});
50+
console.log('students ++++', arr.length, arr);
51+
if (arr.length <= 0)
52+
setError(
53+
'There are currently no active students. Stay tuned!',
54+
);
55+
setstudents(arr);
56+
})
57+
.catch((err) => {
58+
if (err.response.status === 401) {
59+
AuthService.login().then(() => getToken());
60+
} else {
61+
console.log('catch error', err);
62+
setError(
63+
'Oops..something went wrong. The HPE Developer team is addressing the problem. Please try again later!',
64+
);
65+
}
66+
});
67+
};
68+
getToken();
69+
70+
}, []);
71+
72+
console.log('students in students ', students);
73+
74+
const { title, description, badgeImg } = props.pageContext;
75+
76+
return (
77+
<Layout background="/img/hackshack/BackgroundImages/schedule-background.png">
78+
<SEO title={title} description={description} image={badgeImg} />
79+
<MainTitle>
80+
<Heading color="text-strong" margin={{ top: 'none', bottom: 'small' }}>
81+
Active Participants
82+
</Heading>
83+
</MainTitle>
84+
{}
85+
{students.length >= 0 ? (
86+
<tab>
87+
<DataTable
88+
columns={[
89+
{
90+
property: 'username',
91+
header: <Text>Username</Text>,
92+
primary: true,
93+
},
94+
{
95+
property: 'password',
96+
header: <Text>Password</Text>,
97+
},
98+
{
99+
property: 'url',
100+
header: <Text>URL</Text>,
101+
render: datum => (
102+
<Button
103+
href= {datum.url}
104+
target= "_blank"
105+
label="Connect"
106+
/>),
107+
},
108+
]}
109+
data={students}
110+
/* data={[
111+
{ username: 'Alan', password: '20' },
112+
{ username: 'Bryan', password: '30' },
113+
{ username: 'Chris', password: '40' },
114+
{ username: 'Eric', password: '80' },
115+
] } */
116+
/>
117+
</tab>
118+
) : (
119+
<Box
120+
pad="small"
121+
justify="center"
122+
margin={{ top: 'medium' }}
123+
direction="column"
124+
// background="status-critical"
125+
>
126+
{error ? (
127+
<>
128+
<Text size="large" color="status-critical" alignSelf="center">
129+
{error}
130+
</Text>
131+
<Image
132+
alt="gremlin rockin"
133+
src="/img/hackshack/gremlin-rockin.svg"
134+
/>
135+
</>
136+
) : (
137+
<Box height="medium" />
138+
)}
139+
</Box>
140+
)}
141+
</Layout>
142+
);
143+
};
144+
145+
Student.propTypes = {
146+
pageContext: PropTypes.shape({
147+
username: PropTypes.string,
148+
password: PropTypes.string,
149+
}),
150+
};
151+
152+
export default Student;

0 commit comments

Comments
 (0)