-
Notifications
You must be signed in to change notification settings - Fork 39
Create Card Reader page for admin UI #1652
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a9afeec
Added Card Reader page to Admin UI - dummy page for now
adarshm11 a139027
syntax fixes
adarshm11 a120bdb
Implement server-sent events to track activity
adarshm11 a4f9794
Add API Token verification to /listen endpoint
adarshm11 775f53c
Connect /listen and /verify endpoints
adarshm11 15cb072
lint fixes
adarshm11 f732a01
Add API token verification to /listen
adarshm11 3a9d1b0
lint fixes
adarshm11 1d0faf9
Fixed scope of request response
adarshm11 f087c18
lint fixes
adarshm11 b124673
Fixed structure of response body
adarshm11 77c9c85
lint fixes
adarshm11 4ce35cd
add try/catch for data parsing
adarshm11 7c07f78
removed console log
adarshm11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { BASE_API_URL } from '../../Enums'; | ||
|
|
||
| export default function CardReader(props) { | ||
| const [logs, setLogs] = useState([]); | ||
| const [error, setError] = useState(''); | ||
| const token = props.user.token; | ||
|
|
||
| const buildLog = (data) => { | ||
| let date = new Date().toISOString().padEnd(30, ' '); | ||
| let endpoint = data.endpoint.padEnd(20, ' '); | ||
| let statusCode = String(data.statusCode).padEnd(8, ' '); | ||
| return [date, endpoint, statusCode, data.message].join(''); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const url = new URL('/api/OfficeAccessCard/listen', BASE_API_URL); | ||
| url.searchParams.append('token', token); | ||
| const eventSource = new EventSource(url.href); | ||
| eventSource.onmessage = (event) => { | ||
| try { | ||
| let data = JSON.parse(event.data); | ||
| let newLog = buildLog(data); | ||
| setLogs(currLogs => [newLog, ...currLogs]); // prepend the new log | ||
| } catch (error) { | ||
| setLogs( | ||
| (currLogs) => [ | ||
| '[error] unable to format response, check browser logs', | ||
| ...currLogs, | ||
| ] | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| eventSource.onerror = () => { | ||
| setError('Error connecting to SSE'); | ||
| }; | ||
|
|
||
| return () => { | ||
| eventSource.close(); | ||
| }; | ||
|
|
||
| }, []); | ||
|
|
||
| return ( | ||
| <div className='m-4'> | ||
| <h1 className='text-4xl font-bold text-white mb-4'>SCE Card Reader Activity</h1> | ||
| <pre> | ||
| {logs.join('\n')} | ||
| </pre> | ||
| {error && | ||
| <h2>{error}</h2> | ||
| } | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to dynamically get the endpoint from req?