Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit feead9e

Browse files
author
Brandon Lawrence
committed
clean up requests
1 parent 2083212 commit feead9e

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/scenes/home/mentor/mentorRequestsTable/mentorRequestsTable.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
import _ from 'lodash';
2-
import axios from 'axios';
1+
import { Redirect } from 'react-router-dom';
32
import React, { Component } from 'react';
43
import ReactTable from 'react-table';
5-
import Cookies from 'universal-cookie';
6-
import config from 'config/environment';
74
import MENTOR_REQUEST_COLUMNS from 'shared/constants/table';
5+
import * as ApiHelpers from 'shared/utils/apiHelper';
86
import Heading from 'shared/components/heading/heading';
97

108
class MentorRequestsTable extends Component {
119
state = {
12-
requests: []
10+
requests: [],
11+
loggedIn: true
1312
}
1413

1514
componentDidMount() {
16-
const cookies = new Cookies();
17-
const token = cookies.get('token');
18-
axios.get(`${config.backendUrl}/requests`,
19-
{ headers: { Authorization: `bearer ${token}` } }
20-
).then(({ data }) => {
15+
ApiHelpers.getRequests()
16+
.then((data) => {
2117
this.setState({ requests: data });
22-
}).catch((response) => {
23-
const error = _.get(response, 'response.data.error');
24-
this.setState({ error });
25-
});
18+
}).catch(this.setFetchError);
19+
}
20+
21+
setFetchError = ({ response }) => {
22+
// The 500 means you the user is not a mentor, should
23+
// update that later
24+
if (response.status === 401 || response.status === 500) {
25+
this.setState({ loggedIn: false });
26+
}
2627
}
2728

2829
rowClickHandler = (state, rowInfo) => ({
@@ -32,7 +33,10 @@ class MentorRequestsTable extends Component {
3233
})
3334

3435
render() {
35-
const { requests } = this.state;
36+
const { loggedIn, requests } = this.state;
37+
if (!loggedIn) {
38+
return <Redirect to="/login" />;
39+
}
3640
return (
3741
<div style={{ width: '100%' }} >
3842
<Heading text="Pending Requests" style={{ margin: '4rem auto', lineHeight: 0 }} />

src/shared/utils/apiHelper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export const getServices = () => makeGenericGet('services');
2020

2121
export const getMentors = () => makeGenericGet('mentors');
2222

23+
export const getRequests = () => makeGenericGet('requests');
24+
2325
export function postRequest({ language, additionalDetails, mentor, service }) {
2426
const authHeader = setAuthorizationHeader();
2527

0 commit comments

Comments
 (0)