forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Infinite FETCH_STTS #2720
Merged
Merged
Infinite FETCH_STTS #2720
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d67d55
- Updated request to execute 5 times before throwing error
elipe17 f8c6131
- Adding error modal when stt list is empty
elipe17 dd311ba
- Not defaulting to show error modal
elipe17 590afbb
- Updated to use redux state instead of component state for request c…
elipe17 9e99a16
- Simplifying if block
elipe17 7384f0b
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 b23d59d
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 7b883c7
- Updated to use our pre-built modal instead of re-inventing the wheel
elipe17 3aaf5af
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 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 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React, { useEffect } from 'react' | ||
import React, { useEffect, useState, useRef } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { fetchSttList } from '../../actions/sttList' | ||
import ComboBox from '../ComboBox' | ||
import Button from '../Button' | ||
|
||
/** | ||
* @param {function} selectStt - Function to reference and change the | ||
|
@@ -12,36 +13,83 @@ import ComboBox from '../ComboBox' | |
* @param {function} handleBlur - Runs on blur of combo box element. | ||
* @param {function} error - Reference to stt errors object. | ||
*/ | ||
|
||
function STTComboBox({ selectStt, selectedStt, handleBlur, error }) { | ||
const sttList = useSelector((state) => state?.stts?.sttList) | ||
const sttReduction = useSelector((state) => state?.stts) | ||
const dispatch = useDispatch() | ||
const [numTries, setNumTries] = useState(0) | ||
const [reachedMaxTries, setReachedMaxTries] = useState(false) | ||
|
||
useEffect(() => { | ||
if (sttList.length === 0) { | ||
if ( | ||
sttReduction.sttList.length === 0 && | ||
numTries <= 3 && | ||
!sttReduction.loading | ||
) { | ||
dispatch(fetchSttList()) | ||
setNumTries(numTries + 1) | ||
} else if ( | ||
sttReduction.sttList.length === 0 && | ||
numTries > 3 && | ||
!reachedMaxTries | ||
) { | ||
setReachedMaxTries(true) | ||
} | ||
}, [dispatch, sttList]) | ||
}, [dispatch, sttReduction.sttList, numTries, reachedMaxTries]) | ||
|
||
const modalRef = useRef() | ||
const headerRef = useRef() | ||
const onSignOut = () => { | ||
window.location.href = `${process.env.REACT_APP_BACKEND_URL}/logout/oidc` | ||
} | ||
|
||
return ( | ||
<ComboBox | ||
name="stt" | ||
label="Associated State, Tribe, or Territory*" | ||
error={error ? 'A state, tribe, or territory is required' : undefined} | ||
handleSelect={selectStt} | ||
selected={selectedStt} | ||
handleBlur={handleBlur} | ||
placeholder="- Select or Search -" | ||
aria-required="true" | ||
> | ||
<option value="" disabled hidden> | ||
- Select or Search - | ||
</option> | ||
{sttList.map((stt) => ( | ||
<option className="sttOption" key={stt.id} value={stt.name}> | ||
{stt.name} | ||
<> | ||
<ComboBox | ||
name="stt" | ||
label="Associated State, Tribe, or Territory*" | ||
error={error ? 'A state, tribe, or territory is required' : undefined} | ||
handleSelect={selectStt} | ||
selected={selectedStt} | ||
handleBlur={handleBlur} | ||
placeholder="- Select or Search -" | ||
aria-required="true" | ||
> | ||
<option value="" disabled hidden> | ||
- Select or Search - | ||
</option> | ||
))} | ||
</ComboBox> | ||
{sttReduction.sttList.map((stt) => ( | ||
<option className="sttOption" key={stt.id} value={stt.name}> | ||
{stt.name} | ||
</option> | ||
))} | ||
</ComboBox> | ||
<div | ||
id="emptySttListModal" | ||
className={`modal ${ | ||
reachedMaxTries ? 'display-block' : 'display-none' | ||
}`} | ||
> | ||
<div className="modal-content" ref={modalRef}> | ||
<h1 | ||
className="font-serif-xl margin-4 margin-bottom-0 text-normal" | ||
tabIndex="-1" | ||
ref={headerRef} | ||
> | ||
TDP systems are currently experiencing technical difficulties. | ||
</h1> | ||
<p className="margin-4 margin-top-1"> | ||
Please sign out and try signing in again. If the issue persists | ||
contact support at [email protected]. | ||
</p> | ||
<div className="margin-x-4 margin-bottom-4"> | ||
<Button type="button" className="sign-out" onClick={onSignOut}> | ||
Sign Out Now | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
|
Oops, something went wrong.
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.
minor point but i'd go with something like
sttListRequest
for the variable name to indicate what's present in the data structure rather than where in the redux stack it comes from