-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve presentation scheduling logic
- Loading branch information
1 parent
7156a6e
commit ea72a07
Showing
15 changed files
with
172 additions
and
95 deletions.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
client/src/components/PublicPresentationsTable/PublicPresentationsTable.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import PresentationsTable from '../PresentationsTable/PresentationsTable' | ||
import React, { useEffect, useState } from 'react' | ||
import { PaginationResponse } from '../../requests/responses/pagination' | ||
import { IPublishedPresentation } from '../../requests/responses/thesis' | ||
import { doRequest } from '../../requests/request' | ||
import { showSimpleError } from '../../utils/notification' | ||
import { getApiResponseErrorMessage } from '../../requests/handler' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
interface IPublicPresentationsTableProps { | ||
includeDrafts?: boolean | ||
limit?: number | ||
reducedData?: boolean | ||
} | ||
|
||
const PublicPresentationsTable = (props: IPublicPresentationsTableProps) => { | ||
const { includeDrafts = false, limit = 10, reducedData = false } = props | ||
|
||
const navigate = useNavigate() | ||
|
||
const [presentations, setPresentations] = useState<PaginationResponse<IPublishedPresentation>>() | ||
const [page, setPage] = useState(0) | ||
|
||
useEffect(() => { | ||
setPresentations(undefined) | ||
|
||
return doRequest<PaginationResponse<IPublishedPresentation>>( | ||
`/v2/published-presentations`, | ||
{ | ||
method: 'GET', | ||
requiresAuth: false, | ||
params: { | ||
page, | ||
limit, | ||
includeDrafts, | ||
}, | ||
}, | ||
(res) => { | ||
if (res.ok) { | ||
setPresentations(res.data) | ||
} else { | ||
showSimpleError(getApiResponseErrorMessage(res)) | ||
} | ||
}, | ||
) | ||
}, [page, limit, includeDrafts]) | ||
|
||
return ( | ||
<PresentationsTable | ||
columns={ | ||
reducedData | ||
? [includeDrafts ? 'state' : '', 'students', 'location', 'scheduledAt'] | ||
: [ | ||
includeDrafts ? 'state' : '', | ||
'students', | ||
'type', | ||
'location', | ||
'streamUrl', | ||
'language', | ||
'scheduledAt', | ||
] | ||
} | ||
presentations={presentations?.content} | ||
onRowClick={(presentation) => navigate(`/presentations/${presentation.presentationId}`)} | ||
pagination={{ | ||
totalRecords: presentations?.totalElements ?? 0, | ||
recordsPerPage: limit, | ||
page: page + 1, | ||
onPageChange: (newPage) => setPage(newPage - 1), | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default PublicPresentationsTable |
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
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
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
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
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
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
Oops, something went wrong.