-
-
Save DanyF-github/910e601a59d999d6e308eb8b8049ae27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// client/src/components/Students/StudentsList.tsx | |
import React from 'react'; | |
import { useQuery } from '@apollo/client'; | |
import { GET_STUDENTS } from '../../data/queries'; | |
import { Student, StudentListProps } from '../../models'; | |
const StudentsList = ({ actions = [] }: StudentListProps) => { | |
// create the query | |
const { data, loading, error } = useQuery(GET_STUDENTS); | |
// render the table | |
return ( | |
<> | |
{loading && <p>Loading...</p>} | |
{error && <p>Error!</p>} | |
{data && ( | |
<table> | |
<thead> | |
<tr> | |
<th>Phone Number</th> | |
<th>First Name</th> | |
<th>Last Name</th> | |
{actions.length > 0 && <th>Actions</th>} | |
</tr> | |
</thead> | |
<tbody> | |
{data.students.map((student: Student) => { | |
return ( | |
<tr key={student.phoneNumber}> | |
<td>{student.phoneNumber}</td> | |
<td>{student.firstName}</td> | |
<td>{student.lastName}</td> | |
<td> | |
{actions.map((action) => ( | |
<button key={action.actionName} onClick={() => action.onAction(student)}> | |
{action.actionName} | |
</button> | |
))} | |
</td> | |
</tr> | |
); | |
})} | |
</tbody> | |
</table> | |
)} | |
</> | |
); | |
}; | |
export default StudentsList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment