-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FW-1818, FW-3934 list view for join requests and admin approve and ig…
…nore (#187) * remove padding from DashboardTable * Add reusable infiniteScroll hook * Use infiniteScroll hook in useJoinRequests * Increase max char for join message * FW-1818 Dashboard JoinRequests List * Add JoinRequest list to Dashboard homepage * Rename DashboardJoinRequests to List * Approve/Ignore mvp with button and select * Styling and copy adjustments * Add auth check to Join Requests list * Adjustments for smaller screens and styling tweaks * Sonar fix
- Loading branch information
1 parent
60c3bd6
commit ababdd7
Showing
14 changed files
with
487 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useRef } from 'react' | ||
import { useInfiniteQuery } from '@tanstack/react-query' | ||
|
||
// FPCC | ||
import useIntersectionObserver from 'common/hooks/useIntersectionObserver' | ||
import { useSiteStore } from 'context/SiteContext' | ||
|
||
/** | ||
* Calls API and provides results and infinite scroll info. | ||
*/ | ||
function useInfiniteScroll({ queryKey, queryFn, resultAdaptor }) { | ||
const { site } = useSiteStore() | ||
|
||
const pagesDataAdaptor = (pages) => | ||
pages.map((page, index) => singlePageDataAdaptor(page, index)) | ||
|
||
const singlePageDataAdaptor = (page, index) => { | ||
const formattedResult = page?.results?.map((result) => | ||
resultAdaptor ? resultAdaptor(result) : result, | ||
) | ||
return { | ||
...page, | ||
pageNumber: index + 1, | ||
results: formattedResult, | ||
} | ||
} | ||
|
||
// Fetch search results | ||
const response = useInfiniteQuery({ | ||
queryKey, | ||
queryFn, | ||
enabled: !!site?.sitename, | ||
getNextPageParam: (currentPage) => currentPage.next, | ||
select: (responseData) => ({ | ||
pages: pagesDataAdaptor(responseData.pages), | ||
pageParams: responseData.pageParams, | ||
}), | ||
}) | ||
|
||
const infiniteScroll = { | ||
fetchNextPage: response?.fetchNextPage, | ||
hasNextPage: response?.hasNextPage, | ||
isFetchingNextPage: response?.isFetchingNextPage, | ||
} | ||
|
||
const loadRef = useRef(null) | ||
useIntersectionObserver({ | ||
target: loadRef, | ||
onIntersect: response?.fetchNextPage, | ||
enabled: response?.hasNextPage, | ||
}) | ||
|
||
return { | ||
...response, | ||
infiniteScroll, | ||
loadRef, | ||
} | ||
} | ||
|
||
export default useInfiniteScroll |
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
25 changes: 25 additions & 0 deletions
25
src/components/DashboardJoinCard/DashboardJoinCardContainer.js
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,25 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
// FPCC | ||
import DashboardJoinCardData from 'components/DashboardJoinCard/DashboardJoinCardData' | ||
import DashboardJoinCardPresentation from 'components/DashboardJoinCard/DashboardJoinCardPresentation' | ||
|
||
function DashboardJoinCardContainer({ joinRequest }) { | ||
const { handleIgnore, handleApprove } = DashboardJoinCardData({ joinRequest }) | ||
return ( | ||
<DashboardJoinCardPresentation | ||
joinRequest={joinRequest} | ||
handleIgnore={handleIgnore} | ||
handleApprove={handleApprove} | ||
/> | ||
) | ||
} | ||
|
||
// PROPTYPES | ||
const { object } = PropTypes | ||
DashboardJoinCardContainer.propTypes = { | ||
joinRequest: object, | ||
} | ||
|
||
export default DashboardJoinCardContainer |
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,21 @@ | ||
// FPCC | ||
import { | ||
useJoinRequestApprove, | ||
useJoinRequestIgnore, | ||
} from 'common/dataHooks/useJoinRequests' | ||
|
||
function DashboardJoinCardData({ joinRequest }) { | ||
const { onSubmit: ignoreRequest } = useJoinRequestIgnore() | ||
const { onSubmit: approveRequest } = useJoinRequestApprove() | ||
|
||
const handleApprove = (roleToAssign) => { | ||
approveRequest({ id: joinRequest.id, role: roleToAssign }) | ||
} | ||
|
||
return { | ||
handleIgnore: () => ignoreRequest(joinRequest?.id), | ||
handleApprove, | ||
} | ||
} | ||
|
||
export default DashboardJoinCardData |
Oops, something went wrong.