Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member grid backend connection #49

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions client/src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import React, { useState, useEffect } from 'react';
import { AgGridReact } from 'ag-grid-react';

import columnDefs from '../../utils/tableHelpers';
import mockMemberData from '../../utils/mockMemberData';
import { getMembers } from '../../utils/apiWrapper';
import '../../css/Table.css';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';

const Table = () => {
const [members] = useState(mockMemberData);
const getMembers = async () => {
// TODO: replace with getMembers() api call
};

const [members, setMembers] = useState([]);
useEffect(() => {
getMembers();
const getAllMembers = async () => {
const allMembers = await getMembers()
setMembers(allMembers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ur super close!! the axios response object is actually formatted like this
Screen Shot 2021-01-22 at 8 58 02 PM

So you would need to access the actual member data like this: setMembers(allMembers.data.result)

};
getAllMembers();
}, []);



return (
<div className="ag-theme-alpine table-wrapper">
<AgGridReact
Expand Down
17 changes: 17 additions & 0 deletions client/src/utils/apiWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,20 @@ export const getMemberSchemaTypes = () => {
error,
}));
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep looks good! :D

// Retrieves all members
export const getMembers = () => {
const requestString = `${BACKEND_BASE_URL}/members`;
return axios
.get(requestString, {
headers: {
'Content-Type': 'application/JSON',
},
})
.catch((error) => ({
type: 'GET_MEMBERS_FAIL',
error,
}));
};