diff --git a/tdrs-frontend/src/components/STTComboBox/STTComboBox.jsx b/tdrs-frontend/src/components/STTComboBox/STTComboBox.jsx index a4e2b0de3..4f8adf0f2 100644 --- a/tdrs-frontend/src/components/STTComboBox/STTComboBox.jsx +++ b/tdrs-frontend/src/components/STTComboBox/STTComboBox.jsx @@ -1,8 +1,10 @@ -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' +import Modal from '../Modal' /** * @param {function} selectStt - Function to reference and change the @@ -12,36 +14,72 @@ 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 sttListRequest = useSelector((state) => state?.stts) const dispatch = useDispatch() + const [numTries, setNumTries] = useState(0) + const [reachedMaxTries, setReachedMaxTries] = useState(false) useEffect(() => { - if (sttList.length === 0) { + if ( + sttListRequest.sttList.length === 0 && + numTries <= 3 && + !sttListRequest.loading + ) { dispatch(fetchSttList()) + setNumTries(numTries + 1) + } else if ( + sttListRequest.sttList.length === 0 && + numTries > 3 && + !reachedMaxTries + ) { + setReachedMaxTries(true) } - }, [dispatch, sttList]) + }, [dispatch, sttListRequest.sttList, numTries, reachedMaxTries]) + + const modalRef = useRef() + const headerRef = useRef() + const onSignOut = () => { + window.location.href = `${process.env.REACT_APP_BACKEND_URL}/logout/oidc` + } return ( - - - {sttList.map((stt) => ( - + ))} + + { + onSignOut() + }, + }, + ]} + /> + ) }